*
* Hostage
*
* (c) 1990, Infogrames / Mindscape
* (s) 2020, Antoine Vignau
*

*-----------------------
		
	 mx	%00
	 rel
	 lst	off

	 use	BASGIGN.E.S
	 use	BASGIGN.X.S
	 
*-----------------------

	use 	4/Event.Macs
	use	4/Locator.Macs
	use	4/Mem.Macs
	use	4/Misc.Macs
	use	4/Qd.Macs
	use	4/Util.Macs
	
*-----------------------

L050000  ENT
         PHD
         TSC
         SEC
         SBC   #$00DF
         TCD
         ADC   #$00D6
         TCS
         LDA   $E5
         LDX   #$0000
         STX   $DE
         ASL
         ROL   $DE
         ASL
         ROL   $DE
         LDX   $DE
         PHX
         PHA
         LDX   $F1
         LDA   $EF
         JSL   L010E15
         PLA
         PLX
         STA   $DA
         STX   $DC
         LDY   #$0002
         LDA   [$DA],Y
         TAX
         LDA   [$DA]
         PHX
         PHA
         LDX   $F1
         LDA   $EF
         JSL   L010E15
         PLA
         PLX
         STX   L020023
         STA   L020021
         LDX   L020023
         LDA   L020021
         PHX
         PHA
         CLC
         ADC   #$0001
         STA   L020021
         LDA   L020023
         BCC   L050059
         INC
L050059  STA   L020023
         PLA
         PLX
         STA   $DA
         STX   $DC
         LDA   [$DA]
         AND   #$00FF
         ASL
         ASL
         ASL
         STA   L02002D
         LDX   L020023
         LDA   L020021
         PHX
         PHA
         CLC
         ADC   #$0001
         STA   L020021
         LDA   L020023
         BCC   L050082
         INC
L050082  STA   L020023
         PLA
         PLX
         STA   $DA
         STX   $DC
         LDA   [$DA]
         AND   #$00FF
         STA   $D8
         LDA   $D8
         PHA
         LDA   L02002D
         CLC
         JSL   L010FAB
         LDX   L0200B4
         LDA   L0200B2
         PHX
         PHA
         LDX   L020023
         LDA   L020021
         PHX
         PHA
         JSL   L100887
         PLY
         PLY
         PLY
         PLY
         PLY
         STX   L020023
         STA   L020021
         LDA   $ED
         LDX   #$0000
         STX   $DE
         ASL
         ROL   $DE
         ASL
         ROL   $DE
         LDX   $DE
         PHX
         PHA
         LDX   $F1
         LDA   $EF
         JSL   L010E15
         PLA
         PLX
         STA   $DA
         STX   $DC
         LDY   #$0002
         LDA   [$DA],Y
         TAX
         LDA   [$DA]
         PHX
         PHA
         LDX   $F1
         LDA   $EF
         JSL   L010E15
         PLA
         PLX
         STX   L020027
         STA   L020025
         LDX   L020027
         LDA   L020025
         PHX
         PHA
         CLC
         ADC   #$0001
         STA   L020025
         LDA   L020027
         BCC   L05010A
         INC
L05010A  STA   L020027
         PLA
         PLX
         STA   $DA
         STX   $DC
         LDA   [$DA]
         AND   #$00FF
         ASL
         ASL
         ASL
         STA   L02002F
         LDX   L020027
         LDA   L020025
         STA   $DA
         STX   $DC
         LDA   [$DA]
         AND   #$00FF
         STA   L020031
         LDX   $FF
         LDA   $FD
         STX   L020027
         STA   L020025
         LDA   L02002D
         PHA
         LDA   $EB
         SEC
         SBC   L020031
         PHA
         LDA   $E9
         SEC
         SBC   $D8
         EOR   #$FFFF
         INC
         PLX
         STX   $DE
         CLC
         ADC   $DE
         SEC
         SBC   #$0003
         CLC
         JSL   L010FAB
         PLA
         LDX   #$0000
         PHX
         PHA
         LDX   L020023
         LDA   L020021
         JSL   L010E15
         PLA
         PLX
         STX   L020023
         STA   L020021
         LDA   $FB
         LSR
         STA   L020033
         LDX   $F5
         LDA   $F3
         STX   L020037
         STA   L020035
         LDX   $F9
         LDA   $F7
         STX   L02003B
         STA   L020039
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

L050197  ENT
         PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00D0
         TCS
         LDA   $FF
         SEC
         SBC   #$0003
         SEC
         SBC   L020031
         LDX   #$0000
         STX   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDA   #L033ED8
         LDX   #^L033ED8
         JSL   L010E15
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         STA   $EC
         LDA   $FD
         LSR
         STA   $FD
         LDA   L02002F
         SEC
         SBC   #$0002
         CLC
         ADC   $FD
         AND   #$FFFE
         STA   $EA
         LDA   $FD
         LDX   #$0000
         PHX
         PHA
         LDX   L020027
         LDA   L020025
         JSL   L010FA0
         PLA
         PLX
         STX   $E0
         STA   $DE
         LDA   $EC
         LDX   #$0000
         PHX
         PHA
         LDX   L02003B
         LDA   L020039
         JSL   L010E15
         PLA
         PLX
         STX   $DC
         STA   $DA
         LDA   $EC
         LDX   #$0000
         PHX
         PHA
         LDX   L020037
         LDA   L020035
         JSL   L010E15
         PLA
         PLX
         STX   $D8
         STA   $D6
         LDX   L020023
         LDA   L020021
         STX   $D4
         STA   $D2
         LDA   #$FFFF
         STA   L02003D
         LDA   L02002F
         LSR
         DEC
         ASL
         CLC
         ADC   #$0002
         STA   $F0
         LDA   L02002D
         LSR
         DEC
         ASL
         CLC
         ADC   #$0002
         STA   $E4
         LDA   #$0003
         STA   $EE
L050252  LDY   $EA
L050254  LDA   [$D6],Y
         STA   [$DA],Y
         DEY
         DEY
         CPY   #$001E
         BNE   L050254
         LDA   L02003D
         BEQ   L050285
L050264  LDA   [$D2],Y
         STA   $E6
         SEP   #$30
         XBA
         TAX
         LDAL  L032E3F,X
         XBA
         TAX
         LDAL  L032E3F,X
         REP   #$30
         AND   [$D6],Y
         ORA   $E6
         STA   [$DA],Y
         DEY
         DEY
         CPY   L020033
         BPL   L050264
L050285  CLC
         LDA   $DA
         ADC   #$00A0
         STA   $DA
         LDA   $D6
         ADC   #$00A0
         STA   $D6
         LDA   $D2
         ADC   $E4
         STA   $D2
         DEC   $EE
         BNE   L050252
         LDA   $D2
         STA   L020021
         LDA   L020031
         STA   $EE
L0502A8  LDY   $EA
L0502AA  LDA   [$DE],Y
         STA   $E6
         SEP   #$30
         XBA
         TAX
         LDAL  L032E3F,X
         XBA
         TAX
         LDAL  L032E3F,X
         REP   #$30
         AND   [$D6],Y
         ORA   $E6
         STA   [$DA],Y
         DEY
         DEY
         CPY   #$001E
         BNE   L0502AA
         LDA   L02003D
         BEQ   L05030B
L0502D0  LDA   [$DE],Y
         STA   $E6
         SEP   #$30
         XBA
         TAX
         LDAL  L032E3F,X
         XBA
         TAX
         LDAL  L032E3F,X
         REP   #$30
         AND   [$D6],Y
         ORA   $E6
         STA   $E2
         LDA   [$D2],Y
         STA   $E6
         SEP   #$30
         XBA
         TAX
         LDAL  L032E3F,X
         XBA
         TAX
         LDAL  L032E3F,X
         REP   #$30
         AND   $E2
         ORA   $E6
         STA   [$DA],Y
         DEY
         DEY
         CPY   L020033
         BPL   L0502D0
L05030B  CLC
         LDA   $DA
         ADC   #$00A0
         STA   $DA
         LDA   $D6
         ADC   #$00A0
         STA   $D6
         LDA   $DE
         ADC   $F0
         STA   $DE
         LDA   $D2
         ADC   $E4
         STA   $D2
         LDX   $FF
         INX
         CPX   #$00EA
         BMI   L050331
         STZ   L02003D
L050331  STX   $FF
         DEC   $EE
         BEQ   L05033A
         BRL   L0502A8
L05033A  TSC
         CLC
         ADC   #$0026
         TCS
         PLD
         RTL

L050342  ENT
         PHD
         TSC
         SEC
         SBC   #$00ED
         TCD
         ADC   #$00A2
         TCS
         PEA   ^L030195
         PEA   L030195
         PEA   $0000
         TDC
         CLC
         ADC   #$00C6
         PHA
         JSL   L011248
         PLY
         PLY
         PLY
         PLY
         PEI   $F5
         PEI   $F3
         PEA   $0000
         TDC
         CLC
         ADC   #$00C6
         PHA
         JSL   L01119D
         PLY
         PLY
         PLY
         PLY
         PEA   ^L03019C
         PEA   L03019C
         PEA   $0000
         TDC
         CLC
         ADC   #$00C6
         PHA
         JSL   L01119D
         PLY
         PLY
         PLY
         PLY
         PEA   $0000
         TDC
         CLC
         ADC   #$00C6
         PHA
         JSL   L1002E2
         PLY
         PLY
         STX   $E6
         STA   $E4
         JSL   L100429
         PEA   $7D00
         PEI   $F9
         PEI   $F7
         PEI   $E6
         PEI   $E4
         JSL   L1008F3
         PLY
         PLY
         PLY
         PLY
         PLY
         LDA   $FB
         AND   #$0004
         TAY
         BEQ   L0503D0
         PEI   $FB
         PEI   $E6
         PEI   $E4
         JSL   L10056D
         PLY
         PLY
         PLY
L0503D0  LDA   $FB
         AND   #$0002
         TAY
         BEQ   L0503F6
         PEI   $E6
         PEI   $E4
         PEI   $FF
         PEI   $FD
         PEA   $0000
         PEA   $0020
         _BlockMove
         BCS   L0503F2
         LDA   #$0000
L0503F2  STAL  L020010
L0503F6  PEI   $E6
         PEI   $E4
         JSL   L100210
         PLY
         PLY
         TSC
         CLC
         ADC   #$004A
         TCS
         PLD
         RTL

L050408  ENT
         PHD
         TSC
         SEC
         SBC   #$00F3
         TCD
         ADC   #$00EC
         TCS
         PEA   $0020
         PEI   $FF
         PEI   $FD
         PEI   $FB
         PEI   $F9
         JSL   L100282
         PLY
         PLY
         PLY
         PLY
         PLY
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L05042F  ENT
         PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00F0
         TCS
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L050442  PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00E4
         TCS
         LDY   #$000A
         LDA   [$FD],Y
         STA   $EC
         LDA   #$0001
         PHA
         LDY   #$0008
         LDA   [$FD],Y
         SEC
         JSL   L011179
         PLA
         STA   $EA
         LDA   $EC
         LDX   #$0000
         STX   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDA   #L033ED8
         LDX   #^L033ED8
         JSL   L010E15
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         CLC
         ADC   $EA
         STA   $F0
         JSL   L0104BA
         LDA   $EA
         AND   #$8000
         TAY
         BNE   L05049F
         LDA   $EA
         CMP   #$0096
         BEQ   L0504A2
         BCC   L0504A2
L05049F  BRL   L050539
L0504A2  LDA   $EA
         CLC
         ADC   #$0006
         CMP   L0200CE
         BEQ   L0504C6
         BCC   L0504C6
         LDA   $EA
         CLC
         ADC   #$0006
         PHA
         LDA   L0200CE
         CLC
         ADC   L0200D2
         PLX
         STX   $F2
         CMP   $F2
         BEQ   L0504C6
         BCS   L0504F3
L0504C6  LDA   $EA
         CLC
         ADC   #$0012
         CMP   L0200CE
         BNE   L0504D4
         BRL   L050539
L0504D4  BCS   L0504D9
         BRL   L050539
L0504D9  LDA   $EA
         CLC
         ADC   #$0012
         PHA
         LDA   L0200CE
         CLC
         ADC   L0200D2
         PLX
         STX   $F2
         CMP   $F2
         BNE   L0504F1
         BRL   L050539
L0504F1  BCC   L050539
L0504F3  LDA   $EC
         CLC
         ADC   #$0006
         CMP   L0200D0
         BCS   L050513
         LDA   $EC
         CLC
         ADC   #$0006
         PHA
         LDA   L0200D0
         SEC
         SBC   L0200D4
         PLX
         STX   $F2
         CMP   $F2
         BCC   L050533
L050513  LDA   $EC
         CLC
         ADC   #$0024
         CMP   L0200D0
         BCS   L050539
         LDA   $EC
         CLC
         ADC   #$0024
         PHA
         LDA   L0200D0
         SEC
         SBC   L0200D4
         PLX
         STX   $F2
         CMP   $F2
         BCS   L050539
L050533  LDA   #$FFFF
         STA   L02001F
L050539  TSC
         CLC
         ADC   #$0012
         TCS
         PLD
         RTL

L050541  ENT
         PHD
         TSC
         SEC
         SBC   #$00EF
         TCD
         ADC   #$00E8
         TCS
         LDA   $F7
         CLC
         ADC   #$0022
         STA   $F7
         LDA   $F7
         LDY   #$000A
         STA   [$FD],Y
         LDA   $F5
         SEC
         SBC   #$0114
         BVS   L050566
         EOR   #$8000
L050566  BMI   L0505A2
         LDA   $F5
         SEC
         SBC   #$FFE0
         BEQ   L0505A2
         BVS   L050575
         EOR   #$8000
L050575  BPL   L0505A2
         LDA   $F7
         SEC
         SBC   #$0010
         BEQ   L0505A2
         BVS   L050584
         EOR   #$8000
L050584  BPL   L0505A2
         LDA   $F7
         SEC
         SBC   #$0098
         BVS   L050591
         EOR   #$8000
L050591  BMI   L0505A2
         PEI   $FF
         PEI   $FD
         JSL   L050442
         PLY
         PLY
         LDA   #$0001
         BRA   L0505A5
L0505A2  LDA   #$0000
L0505A5  TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

L0505AF  ENT
         PHD
         TSC
         SEC
         SBC   #$00EF
         TCD
         ADC   #$00E2
         TCS
         LDX   $F7
         LDA   $F5
         SEC
         SBC   $F9
         PHA
         TXA
         SBC   $FB
         TAX
         PLA
         STX   $E8
         STA   $E6
         LDX   L020135
         LDA   L020133
         CLC
         ADC   $E6
         PHA
         TXA
         ADC   $E8
         TAX
         PLA
         STX   $FB
         STA   $F9
         LDY   #$0000
         STY   $E4
L0505E3  LDX   $FD
L0505E5  LDA   [$F5],Y
         AND   #$EEEE
         ORA   [$F9],Y
         STA   [$F5],Y
         INY
         INY
         LDA   [$F5],Y
         AND   #$EEEE
         ORA   [$F9],Y
         STA   [$F5],Y
         INY
         INY
         LDA   [$F5],Y
         AND   #$EEEE
         ORA   [$F9],Y
         STA   [$F5],Y
         INY
         INY
         LDA   [$F5],Y
         AND   #$EEEE
         ORA   [$F9],Y
         STA   [$F5],Y
         INY
         INY
         DEX
         BPL   L0505E5
         LDA   $E4
         CLC
         ADC   #$00A0
         STA   $E4
         TAY
         DEC   $FF
         BPL   L0505E3
         TSC
         CLC
         ADC   #$000C
         TCS
         PLD
         RTL

         PHD
         TSC
         SEC
         SBC   #$00E9
         TCD
         ADC   #$00C8
         TCS
         LDA   #$0000
         STA   $D8
         STA   $D0
         STA   $CE
         STA   $D4
L05063F  LDA   $F7
         STA   $D2
L050643  LDA   #$0000
         STA   $CC
         STA   $DA
         LDY   $D4
         LDA   [$EF],Y
         INY
         INY
         STY   $D4
         ASL
         ASL
         ASL
         ASL
         ASL
         STA   $CA
         ASL
         ROL   $CB
         ADC   $CA
         STA   $CA
         BCC   L050665
         INC   $CC
         CLC
L050665  LDA   $F3
         ADC   $CA
         STA   $CA
         LDA   $F5
         ADC   $CC
         STA   $CC
         LDA   #$0010
         STA   $D6
L050676  LDA   #$0000
         STA   $E2
         LDY   $DA
         LDA   [$CA],Y
         TAX
         AND   #$8888
         ORA   $E2
         STA   $E2
         LSR   $E2
         TXA
         AND   #$7777
         STA   $E0
         INY
         INY
         LDA   [$CA],Y
         TAX
         AND   #$8888
         ORA   $E2
         STA   $E2
         LSR   $E2
         TXA
         AND   #$7777
         STA   $DE
         INY
         INY
         LDA   [$CA],Y
         TAX
         AND   #$8888
         ORA   $E2
         STA   $E2
         LSR   $E2
         TXA
         AND   #$7777
         STA   $DC
         INY
         INY
         STY   $DA
         LDY   $D8
         LDA   [$FB],Y
         AND   #$8888
         ORA   $E0
         STA   [$FB],Y
         INY
         INY
         LDA   [$FB],Y
         AND   #$8888
         ORA   $DE
         STA   [$FB],Y
         INY
         INY
         LDA   [$FB],Y
         AND   #$8888
         ORA   $DC
         STA   [$FB],Y
         INY
         INY
         LDA   [$FB],Y
         AND   #$8888
         ORA   $E2
         STA   [$FB],Y
         TYA
         CLC
         ADC   #$009A
         STA   $D8
         DEC   $D6
         BNE   L050676
         SEC
         SBC   #$09F8
         STA   $D8
         DEC   $D2
         BMI   L0506FF
         BRL   L050643
L0506FF  LDA   $CE
         CLC
         ADC   #$0A00
         STA   $CE
         STA   $D8
         LDA   $D0
         CLC
         ADC   $FF
         STA   $D0
         STA   $D4
         DEC   $F9
         BMI   L050719
         BRL   L05063F
L050719  TSC
         CLC
         ADC   #$0020
         TCS
         PLD
         RTL

L050721  ENT
         PHD
         TSC
         SEC
         SBC   #$00ED
         TCD
         ADC   #$00D0
         TCS
         LDX   L02012D
         LDA   L02012B
         STX   $D4
         STA   $D2
         LDA   #$0000
         STA   $DA
         STA   $E2
         LDA   $FB
         STA   $DE
         STA   $DC
L050743  LDA   $F7
         STA   $E0
L050747  LDA   $DE
         STA   $FB
         LDY   $E2
         LDA   [$F3],Y
         INY
         INY
         STY   $E2
         CLC
         ADC   $D2
         STA   $D6
         LDA   #$0000
         ADC   $D4
         STA   $D8
         LDX   #$0010
         LDY   #$0000
L050765  LDA   [$D6],Y
         STA   [$FB],Y
         INY
         INY
         LDA   [$D6],Y
         STA   [$FB],Y
         INY
         INY
         LDA   [$D6],Y
         STA   [$FB],Y
         INY
         INY
         LDA   [$D6],Y
         STA   [$FB],Y
         INY
         INY
         CLC
         LDA   $FB
         ADC   #$0098
         STA   $FB
         DEX
         BNE   L050765
         LDA   $DE
         CLC
         ADC   #$0008
         STA   $DE
         DEC   $E0
         BPL   L050747
         LDA   $DC
         CLC
         ADC   #$0A00
         STA   $DC
         STA   $DE
         LDA   $DA
         CLC
         ADC   $FF
         STA   $DA
         STA   $E2
         DEC   $F9
         BPL   L050743
         TSC
         CLC
         ADC   #$001C
         TCS
         PLD
         RTL

L0507B3  ENT
         PHD
         TSC
         SEC
         SBC   #$00F1
         TCD
         ADC   #$00E0
         TCS
         LDX   $F9
         LDA   $F7
         STX   $EA
         STA   $E8
         INC   $F7
         BNE   L0507CC
         INC   $F9
L0507CC  LDA   $FD
         INC
         ASL
         ASL
         ASL
         DEC
         DEC
         STA   $E6
         PHB
         SEP   #$20
         LDA   #$16
         STAL  SHADOW
         REP   #$20
L0507E1  LDX   $F7
         LDY   $E8
         LDA   $E6
         MVN   $010000,$010000
         LDY   #$009E
         SEP   #$20
         LDA   #$00
         STA   [$F7],Y
         REP   #$20
         LDA   $F7
         CLC
         ADC   #$00A0
         STA   $F7
         DEC
         STA   $E8
         DEC   $FB
         BNE   L0507E1
         SEP   #$20
         LDA   #$1E
         STAL  SHADOW
         REP   #$20
         PLB
         TSC
         CLC
         ADC   #$0010
         TCS
         PLD
         RTL

L050817  ENT
         PHD
         TSC
         SEC
         SBC   #$00ED
         TCD
         ADC   #$00E4
         TCS
         LDA   $F9
         LDX   #$0000
         STX   $EC
         ASL
         ROL   $EC
         LDX   $EC
         PHX
         PHA
         LDA   #L033ED8
         LDX   #^L033ED8
         JSL   L010E15
         PLA
         PLX
         STA   $E8
         STX   $EA
         LDA   [$E8]
         LDX   #$0000
         PHX
         PHA
         LDX   $F5
         LDA   $F3
         JSL   L010E15
         PLA
         PLX
         STX   $F5
         STA   $F3
         LDA   $FD
         BEQ   L0508A4
         LDA   #$8888
         LDY   $F7
L05085E  CPY   #$0001
         BEQ   L050867
         LSR
         DEY
         BRA   L05085E
L050867  TAX
L050868  LDA   $FF
         STA   $E6
         LDY   #$0000
L05086F  TXA
         ORA   [$F3],Y
         STA   [$F3],Y
         INY
         INY
         TXA
         ORA   [$F3],Y
         STA   [$F3],Y
         INY
         INY
         TXA
         ORA   [$F3],Y
         STA   [$F3],Y
         INY
         INY
         TXA
         ORA   [$F3],Y
         STA   [$F3],Y
         INY
         INY
         DEC   $E6
         BNE   L05086F
         CLC
         LDA   $F3
         ADC   #$00A0
         STA   $F3
         LDA   $F5
         ADC   #$0000
         STA   $F5
         DEC   $FB
         BNE   L050868
         BRA   L0508F0
L0508A4  LDA   #$EEEE
         LDY   $F7
L0508A9  CPY   #$0001
         BEQ   L0508B5
         LSR
         ORA   #$1111
         DEY
         BRA   L0508A9
L0508B5  TAX
L0508B6  LDA   $FF
         STA   $E6
         LDY   #$0000
L0508BD  TXA
         AND   [$F3],Y
         STA   [$F3],Y
         INY
         INY
         TXA
         AND   [$F3],Y
         STA   [$F3],Y
         INY
         INY
         TXA
         AND   [$F3],Y
         STA   [$F3],Y
         INY
         INY
         TXA
         AND   [$F3],Y
         STA   [$F3],Y
         INY
         INY
         DEC   $E6
         BNE   L0508BD
         CLC
         LDA   $F3
         ADC   #$00A0
         STA   $F3
         LDA   $F5
         ADC   #$0000
         STA   $F5
         DEC   $FB
         BNE   L0508B6
L0508F0  TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

L0508F8  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00EE
         TCS
         LDX   #$00E1
         LDA   #$2000
         STX   $F4
         STA   $F2
         LDA   #$DDDD
         LDY   #$0000
L050913  STA   [$F2],Y
         INY
         INY
         CPY   #$0640
         BNE   L050913
         PEA   ^L0301A1
         PEA   L0301A1
         PEI   $F4
         PEI   $F2
         PEA   $0001
         PEA   $0001
         JSL   L0F0421
         TAY
         TSC
         CLC
         ADC   #$000C
         TCS
         TYA
         PEA   ^L0301A8
         PEA   L0301A8
         PEI   $F4
         PEI   $F2
         PEA   $0000
         PEA   $0000
         JSL   L0F0421
         TAY
         TSC
         CLC
         ADC   #$000C
         TCS
         TYA
         STZ   $F0
         BRA   L0509B2
L050958  PEI   $F0
         PEA   ^L0301AF
         PEA   L0301AF
         PEI   $F4
         PEI   $F2
         PEA   $0001
         LDA   $F0
         ASL
         ASL
         ASL
         ASL
         PHA
         LDA   #$0011
         PLX
         STX   $FA
         CLC
         ADC   $FA
         PHA
         JSL   L0F0421
         TAY
         TSC
         CLC
         ADC   #$000E
         TCS
         TYA
         PEI   $F0
         PEA   ^L0301B7
         PEA   L0301B7
         PEI   $F4
         PEI   $F2
         PEA   $0000
         LDA   $F0
         ASL
         ASL
         ASL
         ASL
         PHA
         LDA   #$0010
         PLX
         STX   $FA
         CLC
         ADC   $FA
         PHA
         JSL   L0F0421
         TAY
         TSC
         CLC
         ADC   #$000E
         TCS
         TYA
         INC   $F0
L0509B2  LDA   $F0
         CMP   #$000A
         BNE   L050958
         PEA   $000B
         PEA   $0000
         LDX   L020162
         LDA   L020160
         PHX
         PHA
         PEA   $0000
         PEI   $F4
         PEI   $F2
         JSL   L1007BF
         TAY
         TSC
         CLC
         ADC   #$000E
         TCS
         TYA
         TSC
         CLC
         ADC   #$000C
         TCS
         PLD
         RTL

L0509E2  ENT
         PHD
         TSC
         SEC
         SBC   #$00F3
         TCD
         ADC   #$00DE
         TCS
         LDX   L020162
         LDA   L020160
         STX   $EC
         STA   $EA
         LDA   $F9
         LSR
         PHA
         LDA   $FB
         SEC
         SBC   #$0003
         LDX   #$0000
         STX   $F2
         ASL
         ROL   $F2
         LDX   $F2
         PHX
         PHA
         LDA   #L033ED8
         LDX   #^L033ED8
         JSL   L010E15
         PLA
         PLX
         STA   $EE
         STX   $F0
         LDA   [$EE]
         PLX
         STX   $F2
         CLC
         ADC   $F2
         STA   $E2
L050A27  LDA   [$FD]
         AND   #$00FF
         BEQ   L050AA1
         LDX   $FF
         LDA   $FD
         INC   $FD
         BNE   L050A38
         INC   $FF
L050A38  STA   $EE
         STX   $F0
         LDA   [$EE]
         AND   #$00FF
         STA   $E4
         LDA   #$0009
         STA   $E0
         LDA   #$0016
         SEP   #$20
         STAL  SHADOW
         REP   #$20
         LDX   $E2
         LDA   $E4
         LDY   #$0000
         CMP   #$003A
         BEQ   L050A6F
         LDY   #$0058
         CMP   #$0020
         BEQ   L050A8C
         AND   #$000F
         INC
         ASL
         ASL
         ASL
         TAY
L050A6F  CLC
         LDA   [$EA],Y
         STAL  $012000,X
         INY
         INY
         LDA   [$EA],Y
         STAL  $012002,X
         TYA
         ADC   #$009E
         TAY
         TXA
         ADC   #$00A0
         TAX
         DEC   $E0
         BNE   L050A6F
L050A8C  LDA   #$001E
         SEP   #$20
         STAL  SHADOW
         REP   #$20
         LDA   $E2
         CLC
         ADC   #$0004
         STA   $E2
         BRA   L050A27
L050AA1  TSC
         CLC
         ADC   #$0014
         TCS
         PLD
         RTL

L050AA9  ENT
         PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00F2
         TCS
         LDA   $FF
         AND   #$00FF
         BRL   L050B1D
L050ABC  LDA   #$00C9
         BRL   L050B30
L050AC2  LDA   #$00CA
         BRL   L050B30
L050AC8  LDA   #$00CB
         BRL   L050B30
L050ACE  LDA   #$00CC
         BRL   L050B30
L050AD4  LDA   #$00CD
         BRL   L050B30
L050ADA  LDA   #$00CE
         BRL   L050B30
L050AE0  LDA   $FF
         AND   #$00FF
         BRL   L050B30
         BRL   L050B30
L050AEB  DA    L050AD4
         DA    L050AC8
         DA    L050ADA
         DA    L050ACE
         DA    L050AC2
         DA    L050ABC
         DA    L050AD4
         DA    L050AC8
         DA    L050ADA
         DA    L050ACE
         DA    L050AC2
         DA    L050ABC
         DA    L050AE0
L050B05  DW    $0042
         DW    $0043
         DW    $004E
         DW    $0056
         DW    $0058
         DW    $005A
         DW    $0062
         DW    $0063
         DW    $006E
         DW    $0076
         DW    $0078
         DW    $007A
L050B1D  TAX
         PEA   ^L050B05
         PEA   L050B05
         LDA   #$0016
         JSL   L0110FC
         PLA
         PLA
         JMP   (L050AEB,X)

L050B30  TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

L050B3A  ENT
         PHD
         TSC
         SEC
         SBC   #$00F5
         TCD
         ADC   #$00E7
         TCS
         STZ   $ED
         STZ   $EB
         STZ   $E9
         BRA   L050B6F
L050B4D  LDA   $E9
         LDX   #$0000
         PHX
         PHA
         LDA   #L03024C
         LDX   #^L03024C
         JSL   L010E15
         PLA
         PLX
         STA   $F0
         STX   $F2
         LDA   #$0000
         SEP   #$20
         STA   [$F0]
         REP   #$20
         INC   $E9
L050B6F  LDA   $E9
         CMP   #$001E
         BNE   L050B4D
         PEI   $FB
         PEI   $FD
         _MoveTo
         BCS   L050B86
         LDA   #$0000
L050B86  STAL  L020010
         PEA   ^L0301FF
         PEA   L0301FF
         _DrawCString
         BCS   L050B9C
         LDA   #$0000
L050B9C  STAL  L020010
         PHA
         PEA   $FFFF
         PEA   $0000
         _FlushEvents
         BCS   L050BB3
         LDA   #$0000
L050BB3  STAL  L020010
         PLA
L050BB8  PHA
         PEA   $0008
         PEA   ^L03002A
         PEA   L03002A
         _GetNextEvent
         BCS   L050BCE
         LDA   #$0000
L050BCE  STAL  L020010
         PLA
         TAY
         BNE   L050BD8
         BRA   L050BB8
L050BD8  LDAL  L03002E
         TAX
         LDAL  L03002C
         AND   #$00FF
         PHA
         TXA
         AND   #$0000
         TAX
         PLA
         SEP   #$20
         STA   $EF
         REP   #$20
         LDA   $EF
         AND   #$00FF
         CMP   #$007F
         BNE   L050C24
         LDA   $ED
         BEQ   L050C21
         DEC   $ED
         LDA   $ED
         LDX   #$0000
         PHX
         PHA
         LDA   #L03024C
         LDX   #^L03024C
         JSL   L010E15
         PLA
         PLX
         STA   $F0
         STX   $F2
         LDA   #$0000
         SEP   #$20
         STA   [$F0]
         REP   #$20
L050C21  BRL   L050CCC
L050C24  LDA   $EF
         AND   #$00FF
         SEC
         SBC   #$001F
         BNE   L050C32
         BRL   L050CBD
L050C32  BVS   L050C37
         EOR   #$8000
L050C37  BMI   L050C3C
         BRL   L050CBD
L050C3C  LDA   $ED
         CMP   $FF
         BCC   L050C45
         BRL   L050CBD
L050C45  LDA   $EF
         AND   #$00FF
         SEC
         SBC   #$0061
         BVS   L050C53
         EOR   #$8000
L050C53  BPL   L050C7A
         LDA   $EF
         AND   #$00FF
         SEC
         SBC   #$007A
         BEQ   L050C67
         BVS   L050C65
         EOR   #$8000
L050C65  BMI   L050C7A
L050C67  LDA   $EF
         AND   #$00FF
         CLC
         ADC   #$0041
         SEC
         SBC   #$0061
         SEP   #$20
         STA   $EF
         REP   #$20
L050C7A  LDA   $ED
         INC   $ED
         LDX   #$0000
         PHX
         PHA
         LDA   #L03024C
         LDX   #^L03024C
         JSL   L010E15
         PLA
         PLX
         STA   $F0
         STX   $F2
         LDA   $EF
         SEP   #$20
         STA   [$F0]
         REP   #$20
         LDA   $ED
         LDX   #$0000
         PHX
         PHA
         LDA   #L03024C
         LDX   #^L03024C
         JSL   L010E15
         PLA
         PLX
         STA   $F0
         STX   $F2
         LDA   #$0000
         SEP   #$20
         STA   [$F0]
         REP   #$20
         BRA   L050CCC
L050CBD  LDA   $EF
         AND   #$00FF
         CMP   #$000D
         BNE   L050CCC
         LDA   #$0001
         STA   $EB
L050CCC  PEI   $FB
         PEI   $FD
         _MoveTo
         BCS   L050CDC
         LDA   #$0000
L050CDC  STAL  L020010
         LDAL  L03024C
         AND   #$00FF
         BEQ   L050CFF
         PEA   ^L03024C
         PEA   L03024C
         _DrawCString
         BCS   L050CFB
         LDA   #$0000
L050CFB  STAL  L020010
L050CFF  PEA   ^L030202
         PEA   L030202
         _DrawCString
         BCS   L050D11
         LDA   #$0000
L050D11  STAL  L020010
         PEI   $FB
         PEI   $FD
         _MoveTo
         BCS   L050D25
         LDA   #$0000
L050D25  STAL  L020010
         LDAL  L03024C
         AND   #$00FF
         BEQ   L050D48
         PEA   ^L03024C
         PEA   L03024C
         _DrawCString
         BCS   L050D44
         LDA   #$0000
L050D44  STAL  L020010
L050D48  LDA   $EB
         BNE   L050D4F
         BRL   L050BB8
L050D4F  LDA   #L03024C
         LDX   #^L03024C
         TAY
         TSC
         CLC
         ADC   #$000D
         TCS
         TYA
         PLD
         RTL

L050D5F  PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         LDA   #$0053
         STA   L020061
         LDA   #$000C
         STA   L020063
         STZ   L020065
         LDA   #$0008
         STA   L020051
         LDA   #$000D
         STA   L020053
         LDA   #$0002
         STA   L020055
         LDA   #$000A
         STA   L020057
         LDA   #$0007
         STA   L020059
         LDA   #$0005
         STA   L02005B
         LDA   #$0008
         STA   L02005D
         LDA   #$001A
         STA   L02005F
         PEA   $00C8
         PEA   $0000
         LDX   L0200B4
         LDA   L0200B2
         PHX
         PHA
         PEA   $0000
         PEA   $00E1
         PEA   $2000
         JSL   L1007BF
         TAY
         TSC
         CLC
         ADC   #$000E
         TCS
         TYA
         LDA   L020055
         PHA
         LDA   L020053
         ASL
         ASL
         ASL
         CLC
         ADC   L020061
         CLC
         ADC   #$0001
         PHA
         LDA   L020063
         ASL
         ASL
         ASL
         ASL
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         PLX
         STX   $FA
         CLC
         ADC   $FA
         PHA
         LDA   L020053
         ASL
         ASL
         ASL
         SEC
         SBC   #$0001
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         SEC
         SBC   #$0001
         PHA
         JSL   L07052A
         PLY
         PLY
         PLY
         PLY
         PLY
         LDA   L020057
         PHA
         LDA   L020053
         ASL
         ASL
         ASL
         CLC
         ADC   L020061
         PHA
         LDA   L020063
         ASL
         ASL
         ASL
         ASL
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         PLX
         STX   $FA
         CLC
         ADC   $FA
         SEC
         SBC   #$0001
         PHA
         LDA   L020053
         ASL
         ASL
         ASL
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         PHA
         JSL   L07052A
         PLY
         PLY
         PLY
         PLY
         PLY
         LDA   #$0018
         STA   L020067
         LDA   #$0002
         STA   L020069
         LDA   #$0030
         STA   L02006B
L050E64  LDA   L020067
         PHA
         DEC
         STA   L020067
         PLA
         TAY
         BNE   L050E73
         BRL   L050F34
L050E73  PEA   $0000
         LDA   L020061
         CLC
         ADC   #$0001
         PHA
         LDA   L020053
         ASL
         ASL
         ASL
         PLX
         STX   $FA
         CLC
         ADC   $FA
         SEC
         SBC   L020069
         PHA
         LDA   L020063
         ASL
         ASL
         ASL
         ASL
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         PLX
         STX   $FA
         CLC
         ADC   $FA
         SEC
         SBC   L020069
         PHA
         LDA   L020053
         ASL
         ASL
         ASL
         SEC
         SBC   #$0001
         CLC
         ADC   L020069
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         SEC
         SBC   #$0001
         CLC
         ADC   L020069
         PHA
         JSL   L07052A
         PLY
         PLY
         PLY
         PLY
         PLY
         PEA   $0000
         LDA   L020053
         ASL
         ASL
         ASL
         CLC
         ADC   L020061
         SEC
         SBC   L02006B
         PHA
         LDA   L020063
         ASL
         ASL
         ASL
         ASL
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         PLX
         STX   $FA
         CLC
         ADC   $FA
         SEC
         SBC   #$0001
         SEC
         SBC   L02006B
         PHA
         LDA   L020053
         ASL
         ASL
         ASL
         CLC
         ADC   L02006B
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         CLC
         ADC   L02006B
         PHA
         JSL   L07052A
         PLY
         PLY
         PLY
         PLY
         PLY
         LDA   L020069
         CLC
         ADC   #$0002
         STA   L020069
         LDA   L02006B
         SEC
         SBC   #$0002
         STA   L02006B
         BRL   L050E64
L050F34  PEA   $0078
         PEA   $0046
         LDX   L0200B4
         LDA   L0200B2
         PHX
         PHA
         PEA   $0046
         PEA   $00E1
         PEA   $2000
         JSL   L1007BF
         TAY
         TSC
         CLC
         ADC   #$000E
         TCS
         TYA
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L050F5F  PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00F2
         TCS
         LDA   $FF
         CMP   #$0080
         BCS   L050F77
         LDA   $FF
         BRA   L050F7C
         BRA   L050F7C
L050F77  LDA   #$0F00
         ORA   $FF
L050F7C  TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

L050F86  PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         LDX   #$0000
         LDA   #$001A
         PHX
         PHA
         LDX   L02016E
         LDA   L02016C
         SEC
         JSL   L010EAF
         PLY
         PLY
         STA   L020071
         LDA   L020071
         AND   #$00FF
         STA   L020071
         LDA   L020071
         PHA
         JSL   L080726
         AND   #$3FFF
         CLC
         JSL   L010E20
         PLA
         STA   L020073
         LDA   L020073
         LDX   #$0000
         PEA   $0000
         PEA   $001A
         CLC
         JSL   L010FF0
         LDX   L02006F
         LDA   L02006D
         JSL   L010E15
         PLA
         PLX
         STX   L02006F
         STA   L02006D
         LDX   L02006F
         LDA   L02006D
         STA   $F6
         STX   $F8
         LDA   [$F6]
         STA   L02004B
         LDX   L02006F
         LDA   L02006D
         STA   $F6
         STX   $F8
         LDY   #$0002
         LDA   [$F6],Y
         STA   L02004D
         LDX   L02006F
         LDA   L02006D
         STA   $F6
         STX   $F8
         LDY   #$0004
         LDA   [$F6],Y
         STA   L02004F
         LDA   L02004B
         XBA
         STA   L02004B
         LDA   L02004D
         XBA
         STA   L02004D
         LDA   L02004F
         XBA
         STA   L02004F
         LDA   L02004F
         CMP   #$0008
         BNE   L05104F
         LDA   L02004D
         CMP   #$0006
         BNE   L05104F
         LDA   L02004B
         CMP   #$0006
         BNE   L05104F
         LDA   #$0005
         STA   L02004B
L05104F  TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L051057  PHD
         TSC
         SEC
         SBC   #$00F5
         TCD
         ADC   #$00E5
         TCS
         LDA   $FF
         SEP   #$20
         STA   $EB
         REP   #$20
L05106A  LDA   #L0301BF
         LDX   #^L0301BF
         STX   $EE
         STA   $EC
         LDA   [$FB]
         AND   #$00FF
         BNE   L05107E
         BRL   L05111C
L05107E  LDA   [$FB]
         AND   #$00FF
         AND   #$00DF
         SEP   #$20
         STA   [$FB]
         REP   #$20
         LDA   [$FB]
         AND   #$00FF
         STA   $E7
         LDA   $E7
         SEC
         SBC   #$0020
         STA   $E7
         LDA   $E7
         BEQ   L051113
         LDA   $E7
         SEC
         SBC   #$0000
         BVS   L0510AA
         EOR   #$8000
L0510AA  BMI   L0510B4
         LDA   $E7
         CLC
         ADC   #$0100
         STA   $E7
L0510B4  LDA   $E7
         BEQ   L051111
         LDA   [$FB]
         AND   #$00FF
         AND   #$0001
         TAY
         BEQ   L0510C8
         LDA   #$0080
         BRA   L0510CB
L0510C8  LDA   #$0000
L0510CB  SEP   #$20
         STA   $EA
         REP   #$20
         LDA   $EA
         AND   #$00FF
         PHA
         LDA   [$FB]
         AND   #$00FF
         PHA
         JSL   L050F5F
         PLY
         LSR
         AND   #$00FF
         PLX
         STX   $F4
         ORA   $F4
         SEP   #$20
         STA   [$FB]
         REP   #$20
         LDA   [$EC]
         AND   #$00FF
         PHA
         LDA   [$FB]
         AND   #$00FF
         PLX
         STX   $F4
         EOR   $F4
         SEP   #$20
         STA   [$FB]
         REP   #$20
         INC   $EC
         BNE   L05110D
         INC   $EE
L05110D  DEC   $E7
         BRA   L0510B4
L051111  BRA   L05111C
L051113  LDA   #$007F
         SEP   #$20
         STA   [$FB]
         REP   #$20
L05111C  INC   $FB
         BNE   L051122
         INC   $FD
L051122  SEP   #$20
         DEC   $EB
         REP   #$20
         LDA   $EB
         AND   #$00FF
         BEQ   L051132
         BRL   L05106A
L051132  TSC
         CLC
         ADC   #$000F
         TCS
         PLD
         RTL

L05113A  PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00EE
         TCS
         STZ   $F0
         BRA   L0511A1
L051149  LDA   $F0
         LDX   #$0000
         TAY
         BPL   L051152
         DEX
L051152  PHX
         PHA
         LDX   $FF
         LDA   $FD
         JSL   L010E15
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         AND   #$00FF
         PHA
         LDA   $F0
         LDX   #$0000
         PHX
         PHA
         LDX   L02006F
         LDA   L02006D
         STA   $F2
         STX   $F4
         LDX   $F4
         LDA   #$0006
         CLC
         ADC   $F2
         BCC   L051184
         INX
L051184  JSL   L010E15
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         AND   #$00FF
         PLX
         STX   $F2
         CMP   $F2
         BEQ   L05119F
         LDA   #$0000
         BRA   L0511AB
L05119F  INC   $F0
L0511A1  LDA   $F0
         CMP   #$0014
         BNE   L051149
         LDA   #$061D
L0511AB  TAY
         TSC
         CLC
         ADC   #$0008
         TCS
         TYA
         PLD
         RTL

L0511B5  PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F0
         TCS
         LDA   L020057
         PHA
         LDA   L020053
         ASL
         ASL
         ASL
         CLC
         ADC   #$0045
         PHA
         LDA   L020063
         ASL
         ASL
         ASL
         ASL
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         PLX
         STX   $FA
         CLC
         ADC   $FA
         SEC
         SBC   #$000F
         PHA
         LDA   L020053
         ASL
         ASL
         ASL
         CLC
         ADC   #$0037
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         CLC
         ADC   #$000F
         PHA
         JSL   L07052A
         PLY
         PLY
         PLY
         PLY
         PLY
         JSL   L01027C
         PEA   $000F
         LDA   L020053
         ASL
         ASL
         ASL
         CLC
         ADC   #$0043
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         CLC
         ADC   #$0012
         PHA
         JSL   L050B3A
         PLY
         PLY
         PLY
         STX   $F4
         STA   $F2
         JSL   L0102B8
         LDX   $F4
         LDA   $F2
         TAY
         TSC
         CLC
         ADC   #$000A
         TCS
         TYA
         PLD
         RTL

*
* Password protection routine
*

L051241  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F0
         TCS
         PEA   ^L030207
         PEA   L030207
         JSL   L1002E2
         PLY
         PLY
         STX   L02006F
         STA   L02006D
         JSL   L050D5F
         JSL   L050F86
         PEA   ^L03021C
         PEA   L03021C
         LDA   L020065
         PHA
         LDA   L020059
         PHA
         PEA   ^L030213
         PEA   L030213
         PEA   $00E1
         PEA   $2000
         LDA   L020053
         ASL
         ASL
         ASL
         CLC
         ADC   #$0014
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         CLC
         ADC   #$000A
         PHA
         JSL   L0F0421
         TAY
         TSC
         CLC
         ADC   #$0014
         TCS
         TYA
         LDA   L02004B
         PHA
         JSL   L0F0237
         PLY
         LDA   #$000A
         STA   L02001D
         PEA   ^L030239
         PEA   L030239
         LDA   L020065
         PHA
         LDA   L020059
         PHA
         PEA   ^L030230
         PEA   L030230
         PEA   $00E1
         PEA   $2000
         LDA   L020053
         ASL
         ASL
         ASL
         CLC
         ADC   #$0023
         PHA
         LDA   L020051
         ASL
         ASL
         ASL
         CLC
         ADC   #$000A
         PHA
         JSL   L0F0421
         TAY
         TSC
         CLC
         ADC   #$0014
         TCS
         TYA
         LDA   L02004D
         PHA
         JSL   L0F0237
         PLY
         PEA   ^L030242
         PEA   L030242
         _DrawCString
         BCS   L051308
         LDA   #$0000
L051308  STAL  L020010
         LDA   L02004F
         PHA
         JSL   L0F0237
         PLY
         PEA   $00C8
         PEA   $0000
         LDX   L0200B4
         LDA   L0200B2
         PHX
         PHA
         PEA   $0000
         PEA   $00E1
         PEA   $2000
         JSL   L1007BF
         TAY
         TSC
         CLC
         ADC   #$000E
         TCS
         TYA
L051338  JSL   L0511B5
         STX   $F4
         STA   $F2
         PEA   $0014
         PEI   $F4
         PEI   $F2
         JSL   L051057
         PLY
         PLY
         PLY
         PEI   $F4
         PEI   $F2
         JSL   L05113A
         PLY
         PLY
         TAY
         BNE   L051384
         PEA   $0000
         PEA   $0000
         PEA   ^L030587
         PEA   L030587
         JSL   L060719
         PLY
         PLY
         PLY
         PLY
         INC   L02001D
         LDA   L02001D
         CMP   #$000D
         BNE   L05137E
         BRA   L051398
         BRA   L051384
L05137E  JSL   L0E0062
         BRA   L051338
L051384  LDA   #$0076
         STA   L02001D
         LDX   L02006F
         LDA   L02006D
         PHX
         PHA
         JSL   L100210
         PLY
         PLY
L051398  TAY
         TSC
         CLC
         ADC   #$000A
         TCS
         TYA
         PLD
         RTL

L0513A2  ENT
         PHD
         TSC
         SEC
         SBC   #$00F3
         TCD
         ADC   #$00EC
         TCS
         BRA   L0513CC
L0513AF  LDA   [$F9]
         AND   #$00FF
         BNE   L0513B8
         BRA   L0513DE
L0513B8  LDX   $FB
         LDA   $F9
         INC   $F9
         BNE   L0513C2
         INC   $FB
L0513C2  LDX   $FF
         LDA   $FD
         INC   $FD
         BNE   L0513CC
         INC   $FF
L0513CC  LDA   [$F9]
         AND   #$00FF
         PHA
         LDA   [$FD]
         AND   #$00FF
         PLX
         STX   $EE
         CMP   $EE
         BEQ   L0513AF
L0513DE  LDA   [$FD]
         AND   #$00FF
         PHA
         LDA   [$F9]
         AND   #$00FF
         PLX
         STX   $F2
         SEC
         SBC   $F2
         TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

