*
* LemminGS
*
* (c) 1997, Brutal Deluxe
*

 lst off
 rel
 dsk Lemmings.l

 mx %00

*--------------------------------------

 use 4/Int.Macs
 use 4/Locator.Macs
 use 4/Mem.Macs
 use 4/Misc.Macs
 use 4/Sound.Macs
 use 4/MidiSyn.Macs
 use 4/Util.Macs

*----------------------------------------

nbBANCS = 12

lvlDISK3 = 50

*----------------------------------------

Debut = $00
Arrivee = $04

proDOS = $e100a8

*----------------------------------------

 phk
 plb

 brl msg01
 dw $7777
 asc 'Lemmings are here to share your nights'

msg01 _TLStartUp
 pha
 _MMStartUp
 pla
 sta myID

 tdc
 sta myDP

*----------------------------------------

 sep #$20

 ldal $e0c022
 sta save1
 ldal $e0c029
 sta save2
 ldal $e0c034
 sta save3
 ldal $e0c035
 sta save4

 lda #$f0
 stal $e0c022
 lda #$00
 stal $e0c034

 rep #$20

 jsr getSPEED
 jsr TWILIGHToff
 jsr setPREFIXES

*--------------------------------------
* RESERVATION MEMOIRE
*--------------------------------------

okINIT PushLong #0 ; Demande Ecran Shadowing
 PushLong #$8000
 PushWord myID
 PushWord #%11000000_00000011
 PushLong #$012000
 _NewHandle
 pla
 pla
 bcc okSCREEN

 PushWord #0
 PushLong #scrSTR1
 PushLong #endSTR
 PushLong #proSTR3
 PushLong #endSTR
 _TLTextMountVolume
 pla
 brl initOFF2

*---

okSCREEN PushLong #0
 PushLong #$10000
 PushWord myID
 PushWord #%11000000_00011100
 PushLong #0
 _NewHandle
 ldx temp
 phd
 tsc
 tcd
 lda [3]
 sta ptr04,x
 ldy #2
 lda [3],y
 sta ptr04+2,x
 pld
 pla
 pla
 jsr memERR
 inx
 inx
 inx
 inx
 stx temp
 cpx #nbBANCS*4 ; 12*4
 bne okSCREEN

*---

 ldx #0 ; Remplit les ptrXX_8000
]lp lda ptr04,x
 clc
 adc #$8000
 sta ptr04_8000,x
 lda ptr04+2,x
 adc #0
 sta ptr04_8000+2,x
 inx
 inx
 inx
 inx
 cpx #nbBANCS*4 ; 12*4
 bne ]lp

*---------------------------------------

 jsr musicMEMORY
 bcs noENSONIQ

 jsr initMIDI

 jsr loadSOUND

 jsr loadWAV
 bcs noENSONIQ
 jsr loadBNK

*---------------------------------------

noENSONIQ sep #$20

 lda #$c1
 stal $e0c029

 ldal $e0c035
 and #$f7
 stal $e0c035

 rep #$20

 ldx #0
]lp ldal $e12000,x
 stal $012000,x
 inx
 inx
 bpl ]lp

 jsr fadeOUT

*--------------------------------------
* CHARGEMENT DES FICHIERS
*--------------------------------------

debugLOAD lda #pLOADING ; LOADING
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE

 ldx ptr0A+2
 ldy ptr0A
 jsr unPACK

 ldx ptr0A+2
 ldy ptr0A
 jsr fadeIN

*--- Images de presentation

 lda #pPSYGNOSIS ; PSYGNOSIS
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx ptr0A_8000+2
 ldy ptr0A_8000
 jsr unPACK
 jsr advanceTHERMO

*--- Images de jeu

 lda #pCODE ; CODE
 ldx ptr03+2
 ldy ptr03
 jsr loadFILE
 jsr advanceTHERMO

 lda #pMAIN ; MAIN
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx ptr04+2
 ldy ptr04
 jsr unPACK
 jsr advanceTHERMO

 lda #pSPRITES ; SPRITES
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx ptr04_8000+2
 ldy ptr04_8000
 jsr unPACK
 jsr advanceTHERMO

 lda #pLITTLE ; LITTLE1
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx ptr06+2
 ldy ptr06
 jsr unPACK
 jsr advanceTHERMO

 lda #pPORTES ; PORTES
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx ptr07+2
 ldy ptr07
 jsr unPACK
 jsr advanceTHERMO

 lda #pLEVELS ; LEVELS
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx ptr05_8000+2
 ldy ptr05_8000
 jsr unPACK
 jsr advanceTHERMO

 lda #pLAVE ; LAVE1
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx ptr07_8000+2
 ldy ptr07_8000
 jsr unPACK
 jsr advanceTHERMO

 lda #pLEM1 ; LEM1
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx ptr08+2
 ldy ptr08
 jsr unPACK
 jsr advanceTHERMO

 lda #pLEM3 ; LEM3
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx ptr08_8000+2
 ldy ptr08_8000
 jsr unPACK
 jsr advanceTHERMO ; dernier thermometre

*--- Fade sur les images de presentation

 jsr fadeOUT

 ldx ptr0A_8000+2 ; PSYGNOSIS
 ldy ptr0A_8000
 jsr fadeIN

 lda #pLEMMINGS ; LEMMINGS CHARGEMENT
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx ptr0B+2
 ldy ptr0B
 jsr unPACK
 jsr fadeOUT
*-
 ldx ptr0B+2 ; LEMMINGS
 ldy ptr0B
 jsr fadeIN

 lda #2 ; ATTENTE 2 SEC
 jsr nowWAIT

*--- Creation des images de mask

 jsr createMASK

*--- Saute au code de SuperLemmings

 lda ptr03 ; Patch pour rejouer les musiques
 sta replayMUSIC1+1
 lda ptr03+1
 sta replayMUSIC1+2

 lda ptr03
 sta Debut
 lda ptr03+2
 sta Debut+2

 ldy #2
 lda fgMIDI
 sta [Debut],y
 iny
 iny
 lda fgSOUND
 sta [Debut],y
 iny
 iny
 lda realSPEED
 sta [Debut],y

 brl TONCODE

 asc 0d
 asc 'Psygnosis presents : ...nothing'0d
 asc 'They have never done anything for the IIgs'0d
 asc 'They have never answered to us for our Lemmings IIgs adaptation'0d

*--------------------------------------
* QUITTER
*--------------------------------------

initOFF ldx #0
 txa
]lp stal $012000,x
 inx
 inx
 bpl ]lp

*---

initOFF1 jsr stopMIDI

initOFF2 jsr TWILIGHTon

 sep #$20

 lda save4
 stal $e0c035
 lda save3
 stal $e0c034
 lda save2
 stal $e0c029
 lda save1
 stal $e0c022

 rep #$20

*---

 PushWord myID
 _DisposeAll

 PushWord myID
 _MMShutDown

 _TLShutDown

 jsl proDOS
 dw $2029
 adrl proQUIT

 brk
 brk

 asc 0d
 asc 'LemminGS does not support the SecondSight video board'0d
 asc 'but it does not disturb it :-)'0d

*--------------------------------------
* GS/OS
*--------------------------------------

lvl1 = $b0
lvl2 = $b4
lvl3 = $b8
lvl4 = $bc
lvl5 = $c0

*--- Charge les 5 images d'un niveau suivant le contenu de A

loadLVL phb
 phk
 plb

 pha ; Level number
 stx loadFROM
 sty loadTO

 ldx #3 ; disque 3
 cmp #lvlDISK3
 bcs loadLVL1
 dex ; sinon disque 2

loadLVL1 stx theDISK

*---

 tdc
 sta oldDP

 lda myDP
 tcd

 PushLong #strLEVEL
 PushWord #2
 PushWord #0 ; value is not signed
 _Int2Dec

 lda strLEVEL
 ora #'00'
 sta pLVL+25

 sep #$20

 lda loadFROM ; Premiere image
 ora #'0'
 sta pLVL+28

 rep #$20

*- Clear level buffers

 lda ptr0C
 sta lvl1
 lda ptr0C+2
 sta lvl1+2

 lda ptr0C_8000
 sta lvl2
 lda ptr0C_8000+2
 sta lvl2+2

 lda ptr0D
 sta lvl3
 lda ptr0D+2
 sta lvl3+2

 lda ptr0D_8000
 sta lvl4
 lda ptr0D_8000+2
 sta lvl4+2

 lda ptr0E
 sta lvl5
 lda ptr0E+2
 sta lvl5+2

 ldy #0
 tya
]lp sta [lvl1],y
 sta [lvl2],y
 sta [lvl3],y
 sta [lvl4],y
 sta [lvl5],y
 iny
 iny
 bpl ]lp

*-

]lp lda loadFROM
 dec
 asl
 tax
 ldy loadLIST,x

 lda\ $0000,y
 sta loadPTR
 lda\ $0002,y
 sta loadPTR+2

 lda #pLVL ; PICx
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE
 ldx loadPTR+2
 ldy loadPTR
 jsr unPACK

 inc pLVL+28

 inc loadFROM
 lda loadFROM
 cmp loadTO
 bcc ]lp
 beq ]lp ; Prend en compte loadTO

 lda oldDP
 tcd

 plb
 rtl

 asc 0d
 asc 'December 1996 : PlayBoy playmate is...'0d
 asc 'Oh sorry, we were so busy working on LemminGS that'0d
 asc 'we have forgotten to buy the magazine :-('0d

*--- Charge l'image pLITTLEx suivant le contenu de #A (1 OU 2)

loadLITTLE phb
 phk ; A=000x, AVEC x=1 OU 2
 plb

 xba
 clc
 adc #$3065 ; xe
 sta pLITTLE+23

 lda #1
 sta theDISK

 lda #pLITTLE
 ldx ptrUNPACK+2 ; LITTLEx
 ldy ptrUNPACK
 jsr loadFILE

 ldx ptr06+2
 ldy ptr06
 jsr unPACK

 plb
 rtl

 asc 0d
 asc 'Some advice for other Lemmings versions :'0d
 asc '  Atari ST   : Such poor musics and sounds !!'0d
 asc '  Macintosh  : 16-colors graphic screens...??'0d
 asc '  PC DOS     : Bad graphics, colors, musics !'0d
 asc '  PC Windows : Was it SO hard to add waters animations ?'0d
 asc '  Apple IIgs : Good luck at 2.8 mhz... :-0'0d

*--- Charge l'image pPIEGES

loadPIEGES phb
 phk ; POUR LES NIVEAUX 15 ET 17
 plb

 lda #1
 sta theDISK

 lda #pPIEGES
 ldx ptrUNPACK+2 ; PIEGES
 ldy ptrUNPACK
 jsr loadFILE

 ldx ptr0E_8000+2
 ldy ptr0E_8000
 jsr unPACK

 plb
 rtl

 asc 0d
 asc 'About System 6.0.2 :'0d
 asc 'It is right that we have lost the source code...'0d

*--- Charge l'image pLAVEx suivant le contenu de A (1,5 OU 6)

loadLAVE phb
 phk ; LAVE1, LAVE5 OU LAVE6
 plb  ; A=000x

 xba
 clc
 adc #$3065 ; Xe
 sta pLAVE+21 ; MET LE eX, AVEC X=1,5 OU 6

 lda #1
 sta theDISK

 lda #pLAVE
 ldx ptrUNPACK+2
 ldy ptrUNPACK
 jsr loadFILE

 ldx ptr07_8000+2
 ldy ptr07_8000
 jsr unPACK

 plb
 rtl

 asc 0d
 asc '...But it is right that we have recovered it entirely'0d

*---

loadFILE sta proOPEN+4
 sty proREAD+4
 stx proREAD+6

 sep #$20 ; Load from prefix 1
 lda #'1'
 sta pLVL+2
 rep #$20

 lda #$6038
 sta loadLOOP
 jsr loadFILE10
 bcc loadFILE1

 lda #$eaea
 sta loadLOOP

 sep #$20 ; Otherwise, load from prefix X
 lda theDISK
 ora #'0'
 sta pLVL+2
 rep #$20

 bra loadFILE10

*---

loadFILE1 lda #$eaea
 sta loadLOOP
 clc
 rts

*---

loadFILE10 stz proERR

 jsl proDOS
 dw $2010
 adrl proOPEN
 bcs loadERR

 lda proOPEN+2
 sta proREAD+2
 sta proCLOSE+2

 lda proEOF
 sta proREAD+8
 lda proEOF+2
 sta proREAD+10

 jsl proDOS
 dw $2012
 adrl proREAD
 bcs loadERR

loadFILE2 jsl proDOS
 dw $2014
 adrl proCLOSE

 clc
 rts

*--- Gestion des erreurs de chargement

loadERR sta proERR

 jsr loadFILE2

loadLOOP nop
 nop

 sep #$20
 lda theDISK
 ora #'0'
 sta proSTR1+20
 rep #$20

 PushWord #0
 PushLong #proSTR1
 PushLong #endSTR
 PushLong #proSTR2
 PushLong #proSTR3
 _TLTextMountVolume
 pla
 cmp #1
 bne loadPATCH
 brl loadFILE10

loadPATCH nop
 nop

 jmp initOFF

 asc 0d
 asc 'Olivier loves its Sega Saturn home arcade system'0d
 asc 'Sega Rally, Virtua Fighter II and Nights are wonderful'0d

*--------------------------------------
* ROUTINES GRAPHIQUES
*--------------------------------------

advanceTHERMO ldy #0
 ldx offTHERMO

]lp lda myTHERMO,y
 stal $012000,x
 iny
 iny
 lda myTHERMO,y
 stal $012002,x
 iny
 iny
 lda myTHERMO,y
 stal $012004,x
 iny
 iny
 lda myTHERMO,y
 stal $012006,x

 txa
 clc
 adc #160
 tax

 iny
 iny
 cpy #9*8 ; 9 lignes
 bne ]lp

 ldx offTHERMO
 inx
 inx
 inx
 inx
 stx offTHERMO
 rts

*--- Affiche l'image

fadeIN sty Debut
 stx Debut+2

 ldy #$2000
 sty Arrivee
 ldx #$0001
 stx Arrivee+2

 ldy #$7dfe
]lp lda [Debut],y
 sta [Arrivee],y
 dey
 dey
 bpl ]lp

fadeIN1 lda Debut
 clc
 adc #$7e00
 sta Debut
 lda Debut+2
 adc #0
 sta Debut+2

 lda Arrivee
 clc
 adc #$7e00
 sta Arrivee
 lda Arrivee+2
 adc #0
 sta Arrivee+2

 ldx #$000f
fadeIN2 ldy #$01fe
fadeIN3 lda [Arrivee],y
 and #$000f
 sta temp
 lda [Debut],y
 and #$000f
 cmp temp
 beq fadeIN4
 lda [Arrivee],y
 clc
 adc #$0001
 sta [Arrivee],y
fadeIN4 lda [Arrivee],y
 and #$00f0
 sta temp
 lda [Debut],y
 and #$00f0
 cmp temp
 beq fadeIN5
 lda [Arrivee],y
 clc
 adc #$0010
 sta [Arrivee],y
fadeIN5 lda [Arrivee],y
 and #$0f00
 sta temp
 lda [Debut],y
 and #$0f00
 cmp temp
 beq fadeIN6
 lda [Arrivee],y
 clc
 adc #$0100
 sta [Arrivee],y

fadeIN6 dey
 dey
 bpl fadeIN3
 jsr nextVBL
 dex
 bpl fadeIN2
 rts

 asc 0d
 asc 'Antoine wins at Sega Rally'0d
 asc 'but Olivier remains the best one at Virtua Fighter II'0d

*--- Efface l'image

fadeOUT lda #$9e00
 sta Debut
 lda #$0001
 sta Debut+2

 ldx #$000f
fadeOUT1 ldy #$01fe
fadeOUT2 lda [Debut],y
 and #$000f
 beq fadeOUT3
 lda [Debut],y
 sec
 sbc #$0001
 sta [Debut],y
fadeOUT3 lda [Debut],y
 and #$00f0
 beq fadeOUT4
 lda [Debut],y
 sec
 sbc #$0010
 sta [Debut],y
fadeOUT4 lda [Debut],y
 and #$0f00
 beq fadeOUT5
 lda [Debut],y
 sec
 sbc #$0100
 sta [Debut],y

fadeOUT5 dey
 dey
 bpl fadeOUT2
 jsr nextVBL
 dex
 bpl fadeOUT1

 ldx #0
 txa
]lp stal $012000,x
 inx
 inx
 bpl ]lp
 rts

*--- Routine de recopie rapide d'ecran

copySCREEN phb
 phk
 plb

 tdc
 sta oldDP

 ldal $e0c068
 sta saveC068
 ora #%00000000_00110000
 stal $e0c068

 lda #$2000
copySCREEN1 tcd

 lda #0
]copy = $00
 lup $80
 tsb ]copy
]copy = ]copy+2
 --^

 tdc
 ora #$0100
 tcd

 lda #0
]copy = $00
 lup $80
 tsb ]copy
]copy = ]copy+2
 --^

 tdc
 clc
 adc #$0100
 cmp #$8400
 beq copySCREEN2
 brl copySCREEN1

copySCREEN2 lda saveC068
 stal $e0c068

 lda oldDP
 tcd

 plb
 rtl

 asc 0d
 asc 'The sentence of the year : Oh! No More Lemmings !!!'0d

*--------------------------------------
* ROUTINES DIVERSES
*--------------------------------------

*--- Creation de masques

createMASK lda ptr08
 sta Debut
 lda ptr08+2
 sta Debut+2

 lda ptr09
 sta Arrivee
 lda ptr09+2
 sta Arrivee+2

 lda #0
 tax
 tay

 sep #$20

 ldy #0
]lp lda [Debut],y
 tax
 lda tblMASK,x
 sta [Arrivee],y
 iny
 bne ]lp

 rep #$20
 rts

*--- Get Apple IIgs speed

getSPEED sei ; Vitesse GS
 ldal $e0c035
 pha
 and #$ff00
 stal $e0c035

 ldx #0
getSPEED1 lda getSPEED,X
 inx
 inx
 cpx #$0110
 bcc getSPEED1

 ldy #12
 ldal $e0c02b
 and #$0010
 beq getSPEED2
 dey
 dey

getSPEED2 ldx #0
]lp ldal $e0c018
 bmi ]lp
]lp ldal $e0c018
 bpl ]lp
getSPEED3 nop
 nop
getSPEED4 inx
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 ldal $e0c018
 bmi getSPEED3
getSPEED5 inx
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 nop
 ldal $e0c018
 bpl getSPEED5
 dey
 bne getSPEED4

 txa
 lsr
 ldx #0
 txy
]lp cmp parmsSPEED,y
 bcc getSPEED6
 sbc parmsSPEED,y
 inc realSPEED,x
 bra ]lp
getSPEED6 iny
 iny
 inx
 cpy #10
 bne ]lp

 pla
 stal $e0c035
 cli
 rts

 asc 0d
 asc 'Hello Tony, Nice LemminGS Web Page'0d
 asc 'http://www.hypermall.com/~tdiaz'0d

*--- Twilight

TWILIGHToff ldal $e11600
 sta Debut
 ldal $e11602
 sta Debut+2

TWILIGHToff1 ldy #8
 lda [Debut],y
 cmp #$49bf
 bne TWILIGHToff2

 ldy #0
 lda [Debut],y
 sta Arrivee
 sta TWILIGHTad
 iny
 iny
 lda [Debut],y
 sta Arrivee+2
 sta TWILIGHTad+2

 ldy #$117a
 lda [Arrivee],y
 cmp #$0ef0
 bne TWILIGHToff2
 lda #$0e80
 sta [Arrivee],y
 inc TWILIGHTfg
 rts

TWILIGHToff2 ldy #16
 lda [Debut],y
 tax
 iny
 iny
 lda [Debut],y
 sta Debut+2
 txa
 sta Debut

 lda Debut
 ora Debut+2
 bne TWILIGHToff1
 rts

*- Twilight on

TWILIGHTon lda TWILIGHTfg
 bne TWILIGHTon1
 rts
TWILIGHTon1 lda TWILIGHTad
 sta Arrivee
 lda TWILIGHTad+2
 sta Arrivee+2
 ldy #$117a
 lda #$0ef0
 sta [Arrivee],y
 rts

*--- Les Prefixes

setPREFIXES jsl proDOS
 dw $2009
 adrl proPFX2

 jsl proDOS
 dw $2009
 adrl proPFX3

 rts

 asc 0d
 asc 'We love the WWW : World Wide Wait'0d

*--- Attente A secondes

nowWAIT dec
 tax
 lda #0
]lp clc
 adc #60
 cpx #0
 beq nowWAIT1
 dex
 bra ]lp

nowWAIT1 pha
 jsr waitVBL

]lp ldal $e0c018
 bmi ]lp

 pla
 dec
 bne nowWAIT1
 sec
 rts

 pla
 clc
 rts

*--- Synchronisation sur la VBL

nextVBL lda #75
 pha

]lp ldal $e0c02e
 and #$7f
 cmp 1,s
 blt ]lp
 cmp #100
 bge ]lp
 pla

waitVBL ldal $e0c018
 bpl waitVBL
 rts

 asc 0d
 asc 'Special Hello to Ian Brumby,'0d
 asc 'we are waiting for SuperConvert 4'0d
 asc 'thank your for having bought Convert 3200'0d
 asc 'and having asked for the source code'0d
 asc 'We hope that they will be useful for you'0d
 asc 'We have especially loved the greyscale JPEG support'0d

*--- Gestion des erreurs d'allocation memoire

memERR bcs memERR1 ; Erreur de memoire
 rts
memERR1 PushWord #0
 PushLong #memSTR
 PushLong #quiSTR
 PushLong #endSTR
 PushLong #endSTR
 _TLTextMountVolume
 pla
 jmp initOFF

*--- Decompression DreamGraphix
*--- Attention : Utilise ptrDG comme tampon temporaire

unPACK tdc
 sta oldDP

 lda myDP
 clc
 adc #$100
 tcd

 stx $06
 sty $04 ; Destination
 dey
 sty $0C

 lda ptrUNPACK ; Source
 sta $00
 lda ptrUNPACK+2
 sta $02

 lda ptrDG ; Tampons temporaires
 sta $1e
 clc
 adc #$2000
 sta $22
 lda ptrDG+2
 sta $20
 sta $24

 ldy #$3fff
 lda #0
]lp sta [$1e],y
 dey
 dey
 bpl ]lp

 lda #$0009
 sta L0517+1
 lda #$01FF
 sta L051E+1
 stz $1C
 pea $FFFF

L042C jsr L04E8
 cmp #$0101
 bne L042D
 brl L04A4
L042D cmp #$0100
 beq L0491
 sta $12
 cmp $14
 bcc L0443
 lda $10
 pei $0E
L0443 cmp #$0100
 bcc L0455
 asl
L0449 tay
 lda [$22],Y
 pha
 lda [$1E],Y
 cmp #$0200
 bcs L0449
 lsr
L0455 and #$00FF
 sta $0E
 sta $1A
 ldy #$0000
L045F sta [$04],Y
 iny
 pla
 bpl L045F
 pha
 tya
 clc
 adc $04
 sta $04

 lda $0C
 sec
 sbc $04
 bpl L04A4

 jsr L04D8
 lda $12
 sta $10
 lda $14
 cmp $18
 bcc L048F
 lda L0517+1
 cmp #$000C
 beq L048F
 inc
 sta L0517+1
 asl
 tax
 lda packMASK-$12,X
 sta L051E+1
 asl $18
L048F bra L042C
L0491 jsr L04C1
 jsr L04E8
 sta $10
 sta $1A
 sta $0E
 sta [$04]

 inc $04
 jmp L042C

L04A4 pla

 lda oldDP
 tcd
 rts

L04C1 lda #$0009
 sta L0517+1
 lda #$01FF
 sta L051E+1
 lda #$0200
 sta $18
 lda #$0102
 sta $14
 rts

L04D8 lda $14
 asl
 tay
 lda $1A
 sta [$22],Y
 lda $10
 asl
 sta [$1E],Y
 inc $14
 rts

L04E8 lda $1C
 and #$0007
 tax
 lda $1C
 lsr
 lsr
 lsr
 cmp #$03FD
 bcc L0502
 clc
 adc $00
 sta $00
 stx $1C
 lda #$0000
L0502 tay
 lda [$00],Y
 sta $08
 iny
 iny
 lda [$00],Y
 txy
 beq L0514
L050E lsr
L050F ror $08
 dex
 bne L050E
L0514 lda $1C
 clc
L0517 adc #$FFFF ; $0009 on beginning
 sta $1C
 lda $08
L051E and #$FFFF ; $01FF on beginning
 rts

 asc 0d
 asc 'There is an Apple IIgs in a Japanese Manga cartoon :'0d
 asc '               ROUJIN-Z'0d

*--------------------------------------
* DATA
*--------------------------------------

save1 ds 1
save2 ds 1
save3 ds 1
save4 ds 1
save5 ds 1
saveC068 ds 2

temp ds 2

*--- GS/OS

proERR ds 2

proQUIT dw 2
 ds 4
 ds 2

proOPEN dw 12
 ds 2
 adrl pLVL
 ds 2
 ds 2
 ds 2
 ds 2
 ds 4
 ds 2
 ds 8
 ds 8
 ds 4
proEOF ds 4

proREAD dw 4
 ds 2
 ds 4
 ds 4
 ds 4

proCLOSE dw 1
 ds 2

proSETMARK dw 3
 ds 2
 ds 2
 adrl $900 ; +$900 pour WAV

proPFX2 dw 2
 dw 2
 adrl pfxDISK2

proPFX3 dw 2
 dw 3
 adrl pfxDISK3

pfxDISK2 strl '/LemminGS.Disk2'
pfxDISK3 strl '/LemminGS.Disk3'

*--- Nom des fichiers

strLEVEL asc '  '

pLVL strl '1/Lemmings.Data/Lvl/Lvl01s1'
pLEM1 strl '1/Lemmings.Data/Lem1'
pLEM3 strl '1/Lemmings.Data/Lem3'
pLEMMINGS strl '1/Lemmings.Data/Lemmings'
pLAVE strl '1/Lemmings.Data/Lave1'   ; Lave1 ou Lave6
pLEVELS strl '1/Lemmings.Data/Levels'
pLITTLE strl '1/Lemmings.Data/Little1' ; Little1 ou Little2
pLOADING strl '1/Lemmings.Data/Loading'
pMAIN strl '1/Lemmings.Data/Main'
pPORTES strl '1/Lemmings.Data/Portes'
pPSYGNOSIS strl '1/Lemmings.Data/Psygnosis'
pSPRITES strl '1/Lemmings.Data/Sprites'
pPIEGES strl '1/Lemmings.Data/Pieges'
*pCODE strl '1/Lemmings.Data/Lemming'
pCODE strl '1/Lemming'

*--- Vitesse GS

parmsSPEED dw 10000
 dw 1000
 dw 100
 dw 10
 dw 1
realSPEED ds 5

*--- Twilight II

TWILIGHTad ds 4
TWILIGHTfg ds 2

*--- Decompression

packMASK dw $01ff
 dw $03ff
 dw $07ff
 dw $0fff
 dw $0000

*--- Levels

loadLIST da ptr0C,ptr0C_8000
 da ptr0D,ptr0D_8000
 da ptr0E

loadFROM ds 2
loadTO ds 2
loadPTR ds 4

*--- Textes

proSTR1 str 'Please insert disk 1'
proSTR2 str '[RET] Retry'
proSTR3 str '[ESC] Quit'

endSTR str ''
memSTR str 'Can'27't allocate memory'
quiSTR str 'Press a key to quit.'

aptkSTR1 str 'AppleTalk is active'
aptkSTR2 str 'May conflict with music'
aptkSTR3 str '[RET] Continue'
aptkSTR4 str '[ESC] No Music'

scrSTR1 str 'Unable to get screen memory'

theDISK dw 1

*--- Memoire

myID ds 2
myDP ds 2
oldDP ds 2

ptr04 ds 4 ;  1
ptrUNPACK ds 4 ;  2
ptr06 ds 4 ;  3
ptr07 ds 4 ;  4
ptr08 ds 4 ;  5
ptr09 ds 4 ;  6
ptr0A ds 4 ;  7
ptr0B ds 4 ;  8
ptr0C ds 4 ;  9
ptr0D ds 4 ; 10
ptr0E ds 4 ; 11
ptr03 ds 4 ; 3

ptrCODEGSOS ds 4 ; BANC DE CE CODE
ptrloadLVL ds 4 ; ADRESSE loadLVL
ptrloadLITTLE ds 4 ; ADRESSE loadLITTLE
ptrloadLAVE ds 4 ; ADRESSE loadLAVE

ptr04_8000 ds 4 ;  1+8000
ptr05_8000 ds 4 ;  2+8000
ptrDG ds 4 ;  3+8000
ptr07_8000 ds 4 ;  4+8000
ptr08_8000 ds 4 ;  5+8000
ptr09_8000 ds 4 ;  6+8000
ptr0A_8000 ds 4 ;  7+8000
 ds 4
ptr0C_8000 ds 4 ;  9+8000
ptr0D_8000 ds 4 ; 10+8000
ptr0E_8000 ds 4 ; 11+8000
 ds 4

*--- Thermometres

offTHERMO dw $32dd ; x : 122, y : 81

*- Thermo d'avancement

myTHERMO hex 4444444444441036
 hex 8888888888821036
 hex CCCCCCCCCCC21036
 hex FFFFFFFFFFC21036
 hex CCCCCCCCCCC21036
 hex 8888888888821036
 hex 4444444444421036
 hex 2222222222221036
 hex 1111111111111036

*--- Table de mask

tblMASK hex fff0f0f0f0f0f0f0f0f0f0f0f0f0f0f00f000000000000000000000000000000
 hex 0f0000000000000000000000000000000f000000000000000000000000000000
 hex 0f0000000000000000000000000000000f000000000000000000000000000000
 hex 0f0000000000000000000000000000000f000000000000000000000000000000
 hex 0f0000000000000000000000000000000f000000000000000000000000000000
 hex 0f0000000000000000000000000000000f000000000000000000000000000000
 hex 0f0000000000000000000000000000000f000000000000000000000000000000
 hex 0f0000000000000000000000000000000f000000000000000000000000000000

*--------------------------------------
* LES ZOLIES JIKS
*--------------------------------------

 put Lemmings.Midi

*--------------------------------------
* CODE OLIVIER
*--------------------------------------

* Mets des "put FichierSource" dans le ".S"
* tu quittes le programme en mettant "BRL initOFF"

TONCODE JSL BANCOURANT ; PASSE LES POINTEURS DES BANCS
 LDA TONCODE+2
 AND #$FF00
 STA ptrCODEGSOS+1 ; BANC CODE GS/OS

 LDA ptr03+1 ; TABLE DES ADRESSES BANCS
 STA TONCODE2+2
 STA TONCODE5+2
 LDX #$0100
 LDY #$0000
TONCODE1 LDA ptr04+1,Y
TONCODE2 STAL $030000,X
 INY
 INY
 INY
 INY
 INX
 INX
TONCODE3 CPX #$011A ; 26
 BNE TONCODE1

 LDA TONCODE3+1 ; TABLE DES ADRESSE ROUTINES
 STA TONCODE5+1
 LDX #$0000
TONCODE4 LDA ADRESSEROUTINE,X
 BEQ TONCODE6
TONCODE5 STAL $03011A,X
 INX
 INX
 BRA TONCODE4

TONCODE6 LDA ptr03+1 ; BANC 03
 ORA #$0002
 STA TONCODE7+2
 JSR VERIFCHECK
TONCODE7 JSL $030200 ; ON SAUTE AU CODE LEMMINGS
 PHK
 PLB
 brl initOFF ; ON QUITTE
BANCOURANT RTL

ADRESSEROUTINE DA loadLVL,loadLITTLE,loadLAVE,loadPIEGES,copySCREEN
 DA loadMUSIC,playMUSIC,stopMUSIC
 DA LEVELINFOS,LEVELTEXTS,JEUSLIDE,JEULEVEL,JEUVALEUR
 DA FIXETAB,ANIMTAB,ANIMDECTAB,SORTIEX0,SORTIEX1,SORTIEY
 DA INTROTAB,LAVETAB,DECORZONETAB,playSOUND
 HEX 0000

VERIFCHECK STZ VERIFCHECK3+1 ; LONGUEUR A VERIFIER
 LDY #$0000
VERIFCHECK2 LDA VERIFTAB,Y
 BEQ VERIFCHECK6 ; FIN DE TABLE
 SEC
 SBC VERIFTAB+2,Y
 LSR
 ASL
 STA VERIFCHECK5+1 ; LONGUEUR
 LDA VERIFTAB+2,Y
 STA VERIFCHECK4+1 ; ADRESSE DE DEBUT DE ZONE
 LDX #$0000
VERIFCHECK3 LDA #$A0A0 ; VALEUR INITIALE
VERIFCHECK4 EOR $A0A0,X ; ZONE A TESTER
 INX
 INX
VERIFCHECK5 CPX #$A0A0 ; LONGUEUR DE TEST
 BNE VERIFCHECK4
 STA VERIFCHECK3+1
 INY
 INY
 INY
 INY
 BRA VERIFCHECK2 ; ZONE SUIVANTE
VERIFCHECK6 LDA VERIFCHECK3+1
* STAL $000306
 CMP #$4250 ; VALEUR THEORIQUE DU CHECKSUM
* CMP #$F098 ; VALEUR DEMO
 BEQ VERIFCHECK7
 SEC  ; PROBLEME
 RTS
VERIFCHECK7 CLC  ; TOUT EST OK
 RTS

VERIFTAB DA LEVELTEXTS,LEVELINFOS,FIXETAB,LEVELTXT01,ANIMTAB,FIXE01,ANIMDECTAB,ANIM01
 DA LAVETAB,ANIMDEC01,DECORZONETAB,LAVETAB01,DECORZONE93,DECORZONE01
 HEX 0000

****************************************************************

CHECKFIRST asc 0d
 asc 'You can try to sector edit this software, change the scrolling text'0d
 asc 'but this time, I think you will have some problems...'0d

 PUT LEMMINGS.TBL

 asc 0d
 asc 'How many Easter Eggs have you found ?'0d

 PUT LEMMINGS.TBL2

 asc 0d
 asc 'Only 6 ? No, it'27's much more... :-)'0d

 PUT LEMMINGS.TBL3

 asc 0d
 asc ' 7 ? Not bad... but you can continue to hunt them...'0d

*---

 asc 0d0d
 asc '========== LemminGS =========='0d
 asc ' The program : Olivier Zardini'0d
 asc ' The remains : Antoine Vignau '0d
CHECKLAST asc '=============================='0d
 asc 0d0d
