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

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

	 use	INTE3.X.S
	 
*-----------------------

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

L0A0000  PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00E2
         TCS
         STZ   L0200B0
         STZ   L0200B2
         LDA   $FF
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$0002
         LDA   [$F4],Y
         STA   $F2
         LDA   #$0002
         PHA
         LDA   $FF
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$0008
         LDA   [$F4],Y
         SEC
         JSL   L01041B
         PLY
         STA   $EE
         LDA   $FF
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$0004
         LDA   [$F4],Y
         STA   $E4
         LDA   #L030636
         LDX   #^L030636
         STX   $E8
         STA   $E6
         LDA   #L0305E8
         LDX   #^L0305E8
         STX   $EC
         STA   $EA
         LDA   #$0003
         STA   $F0
         BRA   L0A00F3
L0A00AE  LDY   #$0002
         LDA   [$EA],Y
         CMP   $F2
         BNE   L0A00DA
         LDA   L0200B0
         PHA
         INC
         STA   L0200B0
         PLA
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L031B5F
         LDX   #^L031B5F
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   $F0
         STA   [$F4]
L0A00DA  LDX   $EC
         LDA   $EA
         PHX
         PHA
         CLC
         ADC   #$001A
         STA   $EA
         LDA   $EC
         BCC   L0A00EB
         INC
L0A00EB  STA   $EC
         PLA
         PLX
         LDA   $F0
         INC   $F0
L0A00F3  SEC
         LDA   $EA
         SBC   $E6
         BNE   L0A0100
         LDA   $EC
         SBC   $E8
         BRA   L0A0106
L0A0100  LDA   $EC
         SBC   $E8
         REP   #$02
L0A0106  BVS   L0A010B
         EOR   #$8000
L0A010B  BPL   L0A00AE
         LDA   #L0307A2
         LDX   #^L0307A2
         STX   $E8
         STA   $E6
         LDA   #L030636
         LDX   #^L030636
         STX   $EC
         STA   $EA
         BRA   L0A013B
L0A0123  LDY   #$0002
         LDA   [$EA],Y
         CMP   $F2
         BNE   L0A012F
         INC   L0200B2
L0A012F  LDA   $EA
         CLC
         ADC   #$001A
         STA   $EA
         BCC   L0A013B
         INC   $EC
L0A013B  SEC
         LDA   $EA
         SBC   $E6
         BNE   L0A0148
         LDA   $EC
         SBC   $E8
         BRA   L0A014E
L0A0148  LDA   $EC
         SBC   $E8
         REP   #$02
L0A014E  BVS   L0A0153
         EOR   #$8000
L0A0153  BPL   L0A0123
         TSC
         CLC
         ADC   #$0016
         TCS
         PLD
         RTL

L0A015D  PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00E6
         TCS
         LDA   #$0002
         STA   $E8
         LDA   $FD
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0002
         LDA   [$F2],Y
         STA   $F0
         LDA   #$0002
         PHA
         LDA   $FD
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0008
         LDA   [$F2],Y
         SEC
         JSL   L01041B
         PLY
         STA   $EC
         LDA   $FD
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0004
         LDA   [$F2],Y
         STA   $EA
         LDA   L0200B0
         BNE   L0A01F7
         BRL   L0A0541
L0A01F7  LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0006
         LDA   [$F2],Y
         CMP   $EA
         BNE   L0A021D
         BRL   L0A0541
L0A021D  STZ   $EE
         BRL   L0A02F1
L0A0222  LDA   $EE
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L031B5F
         LDX   #^L031B5F
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0004
         LDA   [$F2],Y
         PHA
         LDA   $EC
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   $EA
         PHA
         LDA   #$0016
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03082E
         LDX   #^L03082E
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDX   $F4
         LDA   #$0006
         CLC
         ADC   $F2
         BCC   L0A0295
         INX
L0A0295  JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         PLX
         STX   $F2
         CMP   $F2
         BNE   L0A02EF
         LDA   #$0001
         STA   $E8
         LDA   $EE
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L031B5F
         LDX   #^L031B5F
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         PHA
         LDA   $FD
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         PLA
         LDY   #$0012
         STA   [$F2],Y
L0A02EF  INC   $EE
L0A02F1  LDA   $EE
         SEC
         SBC   L0200B0
         BVS   L0A02FC
         EOR   #$8000
L0A02FC  BMI   L0A0308
         LDA   $E8
         CMP   #$0002
         BNE   L0A0308
         BRL   L0A0222
L0A0308  STZ   $EE
         BRL   L0A03A9
L0A030D  LDA   $EE
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   $EA
         PHA
         LDA   #$0016
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03082E
         LDX   #^L03082E
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDX   $F4
         LDA   #$0006
         CLC
         ADC   $F2
         BCC   L0A0341
         INX
L0A0341  JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         AND   #$8000
         TAY
         BEQ   L0A03A7
         LDA   $EE
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   $EA
         PHA
         LDA   #$0016
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03082E
         LDX   #^L03082E
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDX   $F4
         LDA   #$0006
         CLC
         ADC   $F2
         BCC   L0A0387
         INX
L0A0387  JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         CMP   #$FFFF
         BEQ   L0A03A7
         PEI   $FF
         PEI   $FD
         JSL   L0F0939
         PLY
         PLY
         LDA   #$0010
         STA   $E8
L0A03A7  INC   $EE
L0A03A9  LDA   $EE
         SEC
         SBC   #$0004
         BVS   L0A03B4
         EOR   #$8000
L0A03B4  BMI   L0A03B9
         BRL   L0A030D
L0A03B9  LDA   $E8
         CMP   #$0002
         BEQ   L0A03C3
         BRL   L0A053F
L0A03C3  LDA   $EC
         CLC
         ADC   #$0001
         AND   #$0003
         STA   $EC
         LDA   #$0006
         STA   $E8
         STZ   $EE
         BRL   L0A0465
L0A03D8  LDA   $EE
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L031B5F
         LDX   #^L031B5F
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0004
         LDA   [$F2],Y
         PHA
         LDA   $EC
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   $EA
         PHA
         LDA   #$0016
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03082E
         LDX   #^L03082E
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDX   $F4
         LDA   #$0006
         CLC
         ADC   $F2
         BCC   L0A044B
         INX
L0A044B  JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         PLX
         STX   $F2
         CMP   $F2
         BNE   L0A0463
         LDA   #$0002
         STA   $E8
L0A0463  INC   $EE
L0A0465  LDA   $EE
         SEC
         SBC   L0200B0
         BVS   L0A0470
         EOR   #$8000
L0A0470  BMI   L0A047C
         LDA   $E8
         CMP   #$0006
         BNE   L0A047C
         BRL   L0A03D8
L0A047C  LDA   $E8
         CMP   #$0002
         BEQ   L0A0486
         BRL   L0A053F
L0A0486  LDA   $EC
         SEC
         SBC   #$0002
         AND   #$0003
         STA   $EC
         LDA   #$0004
         STA   $E8
         STZ   $EE
         BRL   L0A0528
L0A049B  LDA   $EE
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L031B5F
         LDX   #^L031B5F
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0004
         LDA   [$F2],Y
         PHA
         LDA   $EC
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   $EA
         PHA
         LDA   #$0016
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03082E
         LDX   #^L03082E
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDX   $F4
         LDA   #$0006
         CLC
         ADC   $F2
         BCC   L0A050E
         INX
L0A050E  JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         PLX
         STX   $F2
         CMP   $F2
         BNE   L0A0526
         LDA   #$0002
         STA   $E8
L0A0526  INC   $EE
L0A0528  LDA   $EE
         SEC
         SBC   L0200B0
         BVS   L0A0533
         EOR   #$8000
L0A0533  BMI   L0A053F
         LDA   $E8
         CMP   #$0004
         BNE   L0A053F
         BRL   L0A049B
L0A053F  BRA   L0A0573
L0A0541  LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0006
         LDA   [$F2],Y
         CMP   $EA
         BNE   L0A0573
         PEI   $FF
         PEI   $FD
         JSL   L0F0939
         PLY
         PLY
         LDA   #$0010
         STA   $E8
L0A0573  LDA   $E8
         TAY
         TSC
         CLC
         ADC   #$0010
         TCS
         TYA
         PLD
         RTL

L0A057F  PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00D4
         TCS
         LDA   #$000C
         STA   $D6
         LDA   $FD
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STX   $DE
         STA   $DC
         LDA   $DC
         CLC
         ADC   #$000C
         LDX   $DE
         BCC   L0A05BB
         INX
L0A05BB  STX   $EC
         STA   $EA
         LDA   $DC
         CLC
         ADC   #$000A
         LDX   $DE
         BCC   L0A05CA
         INX
L0A05CA  STX   $F0
         STA   $EE
         LDA   [$EE]
         LDX   #$0000
         TAY
         BPL   L0A05D7
         DEX
L0A05D7  STX   $F6
         ASL
         ROL   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDA   #L030476
         LDX   #^L030476
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0002
         LDA   [$F2],Y
         TAX
         LDA   [$F2]
         STX   $E2
         STA   $E0
         LDY   #$0004
         LDA   [$DC],Y
         PHA
         LDA   #$0016
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03082E
         LDX   #^L03082E
         JSL   L010410
         PLA
         PLX
         STX   $DA
         STA   $D8
         JSL   L0703A5
         AND   #$0007
         STA   $E4
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         CMP   #$0003
         BEQ   L0A0650
         BRL   L0A0A9A
L0A0650  LDA   #$00BE
         CLC
         ADC   $E4
         LDY   #$000E
         STA   [$DC],Y
         LDA   #$0092
         LDY   #$0010
         STA   [$DC],Y
         LDA   [$EA]
         LDX   #$0000
         TAY
         BPL   L0A066C
         DEX
L0A066C  PEA   $0000
         PEA   $0006
         CLC
         JSL   L0105E1
         LDX   $E2
         LDA   $E0
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         BRL   L0A0A5F
L0A068A  BRL   L0A0A97
L0A068D  LDA   #$FFFF
         STA   [$EE]
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   #$0000
         LDY   #$0002
         STA   [$F2],Y
         LDA   #$0000
         LDY   #$0004
         STA   [$DC],Y
         LDA   #$0000
         STA   [$DC]
         LDA   #$0000
         LDY   #$0002
         STA   [$DC],Y
         PEI   $FD
         JSL   L0F085E
         PLY
         BRL   L0A0A97
L0A06D3  PEA   $0007
         PEI   $FD
         JSL   L0C0E26
         PLY
         PLY
         CMP   #$FFFF
         BEQ   L0A0706
         LDA   #$0005
         STA   [$EE]
         LDY   #$000E
         LDA   [$DC],Y
         SEC
         SBC   #$001E
         LDY   #$000E
         STA   [$DC],Y
         LDY   #$000E
         LDA   [$DC],Y
         CLC
         ADC   #$001E
         LDY   #$000E
         STA   [$DC],Y
         BRA   L0A0719
L0A0706  LDA   #$0007
         STA   [$EE]
         LDY   #$0010
         LDA   [$DC],Y
         CLC
         ADC   #$001E
         LDY   #$0010
         STA   [$DC],Y
L0A0719  BRL   L0A0A97
L0A071C  PEA   $0003
         PEI   $FD
         JSL   L0C0E26
         PLY
         PLY
         CMP   #$FFFF
         BEQ   L0A0741
         LDA   #$0007
         STA   [$EE]
         LDY   #$000E
         LDA   [$DC],Y
         CLC
         ADC   #$001E
         LDY   #$000E
         STA   [$DC],Y
         BRA   L0A0762
L0A0741  LDA   #$0005
         STA   [$EE]
         LDY   #$000E
         LDA   [$DC],Y
         SEC
         SBC   #$001E
         LDY   #$000E
         STA   [$DC],Y
         LDY   #$0010
         LDA   [$DC],Y
         CLC
         ADC   #$001E
         LDY   #$0010
         STA   [$DC],Y
L0A0762  BRL   L0A0A97
L0A0765  PEA   $0005
         PEI   $FD
         JSL   L0C0E26
         PLY
         PLY
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   #$0000
         LDY   #$0006
         STA   [$F2],Y
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         CMP   #$0003
         BNE   L0A07CA
         JSL   L0703A5
         AND   #$0001
         TAY
         BEQ   L0A07C2
         LDA   #$0004
         BRA   L0A07C5
L0A07C2  LDA   #$0006
L0A07C5  STA   [$EE]
         BRL   L0A0A97
L0A07CA  PEI   $FD
         JSL   L0A0000
         PLY
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         CMP   #$0004
         BEQ   L0A07F5
         BRL   L0A0892
L0A07F5  LDA   #$0008
         STA   [$EE]
         LDY   #$0004
         LDA   [$DC],Y
         PHA
         LDA   #$0016
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03082E
         LDX   #^L03082E
         JSL   L010410
         PLA
         PLX
         STX   $DA
         STA   $D8
         PEI   $FD
         JSL   L0802D8
         PLY
         LDY   #$0008
         STA   [$DC],Y
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   #$0000
         LDY   #$0006
         STA   [$F2],Y
         LDA   #$0002
         PHA
         LDY   #$0008
         LDA   [$DC],Y
         SEC
         JSL   L01041B
         PLY
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   $D8
         CLC
         ADC   #$0006
         LDX   $DA
         BCC   L0A086C
         INX
L0A086C  JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         PHA
         JSL   L081048
         PLY
         STA   $E6
         TAY
         BEQ   L0A088F
         LDA   #$0001
         STA   [$EE]
         LDA   $E6
         LDY   #$0012
         STA   [$DC],Y
L0A088F  BRL   L0A09C9
L0A0892  LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0006
         LDA   [$F2],Y
         BEQ   L0A08C2
         PEI   $FF
         PEI   $FD
         JSL   L0A015D
         PLY
         PLY
         STA   [$EE]
         BRL   L0A09C9
L0A08C2  LDA   L0200B0
         BNE   L0A08CA
         BRL   L0A0948
L0A08CA  PEA   $0000
         LDY   #$0004
         LDA   [$DC],Y
         PHA
         JSL   L0804DD
         PLY
         PLY
         PHA
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         PLA
         LDY   #$0006
         STA   [$F2],Y
         LDA   L0200B2
         SEC
         SBC   #$0001
         BEQ   L0A0939
         BVS   L0A0908
         EOR   #$8000
L0A0908  BPL   L0A0939
         PEI   $FF
         PEI   $FD
         JSL   L0A015D
         PLY
         PLY
         STA   $E6
         LDA   $E6
         CMP   #$0001
         BNE   L0A0924
         LDA   #$0001
         STA   [$EE]
         BRA   L0A0937
L0A0924  JSL   L0703A5
         AND   #$0001
         TAY
         BEQ   L0A0933
         LDA   #$0002
         BRA   L0A0935
L0A0933  LDA   $E6
L0A0935  STA   [$EE]
L0A0937  BRA   L0A0945
L0A0939  PEI   $FF
         PEI   $FD
         JSL   L0A015D
         PLY
         PLY
         STA   [$EE]
L0A0945  BRL   L0A09C9
L0A0948  LDA   #$0002
         STA   [$EE]
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   #$0000
         LDY   #$0006
         STA   [$F2],Y
         JSL   L0703A5
         AND   #$0007
         CMP   #$0000
         BNE   L0A09C9
         PEA   $0000
         LDY   #$0004
         LDA   [$DC],Y
         PHA
         JSL   L0804DD
         PLY
         PLY
         STZ   $E6
         BRA   L0A09BC
L0A098E  LDA   $E6
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L031B57
         LDX   #^L031B57
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         PHA
         LDY   #$0004
         LDA   [$DC],Y
         PLX
         STX   $F2
         CMP   $F2
         BNE   L0A09BA
         LDA   #$0006
         STA   [$EE]
L0A09BA  INC   $E6
L0A09BC  LDA   $E6
         SEC
         SBC   L0200AE
         BVS   L0A09C7
         EOR   #$8000
L0A09C7  BPL   L0A098E
L0A09C9  BRL   L0A0A97
L0A09CC  PEI   $FD
         JSL   L0A0000
         PLY
         PEI   $FF
         PEI   $FD
         JSL   L0A015D
         PLY
         PLY
         STA   $E6
         LDY   #$0012
         LDA   [$DC],Y
         CMP   $FF
         BNE   L0A09EE
         LDA   #$0001
         STA   L02003F
L0A09EE  LDA   $E6
         CMP   #$0001
         BNE   L0A0A21
         LDY   #$0012
         LDA   [$DC],Y
         PHA
         JSL   L0F0C8A
         PLY
         SEC
         SBC   #$0004
         BVS   L0A0A09
         EOR   #$8000
L0A0A09  BMI   L0A0A1B
         LDY   #$0012
         LDA   [$DC],Y
         PHA
         PEI   $FF
         JSL   L081B87
         PLY
         PLY
         STA   $D6
L0A0A1B  LDA   $E6
         STA   [$EE]
         BRA   L0A0A5B
L0A0A21  LDA   L0200B0
         BEQ   L0A0A2E
         LDA   L0200B2
         CMP   #$0001
         BNE   L0A0A57
L0A0A2E  LDA   #$0002
         STA   [$EE]
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   #$0000
         LDY   #$0006
         STA   [$F2],Y
         BRA   L0A0A5B
L0A0A57  LDA   $E6
         STA   [$EE]
L0A0A5B  BRA   L0A0A97
         BRA   L0A0A97
L0A0A5F  CMP   #$C001
         BNE   L0A0A67
         BRL   L0A068D
L0A0A67  CMP   #$C002
         BNE   L0A0A6F
         BRL   L0A07CA
L0A0A6F  CMP   #$C003
         BNE   L0A0A77
         BRL   L0A09CC
L0A0A77  CMP   #$C004
         BNE   L0A0A7F
         BRL   L0A071C
L0A0A7F  CMP   #$C005
         BNE   L0A0A87
         BRL   L0A06D3
L0A0A87  CMP   #$C007
         BNE   L0A0A8F
         BRL   L0A0765
L0A0A8F  CMP   #$FFFF
         BNE   L0A0A97
         BRL   L0A068A
L0A0A97  BRL   L0A0D56
L0A0A9A  LDA   [$EA]
         LDX   #$0000
         TAY
         BPL   L0A0AA3
         DEX
L0A0AA3  PEA   $0000
         PEA   $0006
         CLC
         JSL   L0105E1
         LDX   $E2
         LDA   $E0
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         BRL   L0A0D21
L0A0AC1  BRL   L0A0D56
L0A0AC4  LDA   #$FFFF
         STA   [$EE]
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   #$0000
         LDY   #$0002
         STA   [$F2],Y
         LDA   $FD
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   #$0000
         LDY   #$0004
         STA   [$F2],Y
         LDA   $FD
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   #$0000
         STA   [$F2]
         LDA   $FD
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   #$0000
         LDY   #$0002
         STA   [$F2],Y
         PEI   $FD
         JSL   L0F085E
         PLY
         BRL   L0A0D56
L0A0B6D  PEA   $0001
         PEI   $FD
         JSL   L0C0E26
         PLY
         PLY
         LDY   #$0004
         LDA   [$DC],Y
         PHA
         LDA   #$0016
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03082E
         LDX   #^L03082E
         JSL   L010410
         PLA
         PLX
         STX   $DA
         STA   $D8
         LDA   [$D8]
         CMP   #$0003
         BNE   L0A0BDC
         JSL   L0703A5
         AND   #$0001
         TAY
         BEQ   L0A0BB2
         LDA   #$0004
         BRA   L0A0BB5
L0A0BB2  LDA   #$0006
L0A0BB5  STA   [$EE]
         LDA   $FD
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   #$0000
         LDY   #$0006
         STA   [$F2],Y
         BRL   L0A0D56
L0A0BDC  STZ   $E4
         STZ   $E6
         BRL   L0A0C64
L0A0BE3  LDA   $E6
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   $D8
         CLC
         ADC   #$0006
         LDX   $DA
         BCC   L0A0BF6
         INX
L0A0BF6  JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         STA   $E8
         LDA   $E8
         CMP   #$FFFF
         BEQ   L0A0C62
         LDA   $E8
         AND   #$8000
         TAY
         BEQ   L0A0C62
         LDA   $E8
         AND   #$7FFF
         PHA
         LDA   #$0016
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03082E
         LDX   #^L03082E
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         CMP   #$0003
         BNE   L0A0C62
         JSL   L0703A5
         AND   #$0001
         TAY
         BEQ   L0A0C62
         LDA   $E6
         PHA
         LDA   #$0002
         SEC
         JSL   L01059C
         PLA
         CLC
         ADC   #$0001
         LDY   #$0008
         STA   [$DC],Y
         LDA   #$0001
         STA   $E4
L0A0C62  INC   $E6
L0A0C64  LDA   $E6
         SEC
         SBC   #$0004
         BVS   L0A0C6F
         EOR   #$8000
L0A0C6F  BMI   L0A0C78
         LDA   $E4
         BNE   L0A0C78
         BRL   L0A0BE3
L0A0C78  LDA   $E4
         BNE   L0A0C88
         PEI   $FD
         JSL   L0802D8
         PLY
         LDY   #$0008
         STA   [$DC],Y
L0A0C88  LDA   #$0008
         STA   [$EE]
         LDA   #$0002
         PHA
         LDY   #$0008
         LDA   [$DC],Y
         SEC
         JSL   L01041B
         PLY
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   $D8
         CLC
         ADC   #$0006
         LDX   $DA
         BCC   L0A0CAD
         INX
L0A0CAD  JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         PHA
         JSL   L081048
         PLY
         STA   $E6
         TAY
         BEQ   L0A0CD0
         LDA   #$0001
         STA   [$EE]
         LDA   $E6
         LDY   #$0012
         STA   [$DC],Y
L0A0CD0  BRL   L0A0D56
L0A0CD3  LDY   #$0012
         LDA   [$DC],Y
         CMP   $FF
         BNE   L0A0CE2
         LDA   #$0001
         STA   L02003F
L0A0CE2  PEI   $FD
         JSL   L0818DF
         PLY
         STA   [$EE]
         CMP   #$0001
         BNE   L0A0D18
         LDY   #$0012
         LDA   [$DC],Y
         PHA
         JSL   L0F0C8A
         PLY
         SEC
         SBC   #$0004
         BVS   L0A0D04
         EOR   #$8000
L0A0D04  BMI   L0A0D16
         LDY   #$0012
         LDA   [$DC],Y
         PHA
         PEI   $FF
         JSL   L081B87
         PLY
         PLY
         STA   $D6
L0A0D16  BRA   L0A0D1D
L0A0D18  LDA   #$0002
         STA   [$EE]
L0A0D1D  BRA   L0A0D56
         BRA   L0A0D56
L0A0D21  CMP   #$C001
         BNE   L0A0D29
         BRL   L0A0AC4
L0A0D29  CMP   #$C002
         BNE   L0A0D31
         BRL   L0A0BDC
L0A0D31  CMP   #$C003
         BEQ   L0A0CD3
         CMP   #$C004
         BNE   L0A0D3E
         BRL   L0A0BDC
L0A0D3E  CMP   #$C006
         BNE   L0A0D46
         BRL   L0A0B6D
L0A0D46  CMP   #$C007
         BNE   L0A0D4E
         BRL   L0A0BDC
L0A0D4E  CMP   #$FFFF
         BNE   L0A0D56
         BRL   L0A0AC1
L0A0D56  LDA   #$0000
         STA   [$EA]
         LDA   $D6
         TAY
         TSC
         CLC
         ADC   #$0022
         TCS
         TYA
         PLD
         RTL

L0A0D67  ENT
         PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00D8
         TCS
         LDA   #$000C
         STA   $DA
         LDA   #$0006
         STA   $EA
         BRL   L0A0F9C
L0A0D7F  LDA   $EA
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$0002
         LDA   [$F4],Y
         BNE   L0A0DA3
         BRL   L0A0F9A
L0A0DA3  LDA   $EA
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$000A
         LDA   [$F4],Y
         CMP   #$FFFF
         BNE   L0A0DD1
         BRL   L0A0F9A
L0A0DD1  LDA   $EA
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STX   $E2
         STA   $E0
         LDA   $E0
         CLC
         ADC   #$000C
         LDX   $E2
         BCC   L0A0DFD
         INX
L0A0DFD  STX   $EE
         STA   $EC
         LDA   $E0
         CLC
         ADC   #$000A
         LDX   $E2
         BCC   L0A0E0C
         INX
L0A0E0C  STX   $F2
         STA   $F0
         LDA   [$F0]
         LDX   #$0000
         TAY
         BPL   L0A0E19
         DEX
L0A0E19  STX   $F8
         ASL
         ROL   $F8
         ASL
         ROL   $F8
         LDX   $F8
         PHX
         PHA
         LDA   #L030476
         LDX   #^L030476
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$0002
         LDA   [$F4],Y
         TAX
         LDA   [$F4]
         STX   $E6
         STA   $E4
         PEI   $EA
         JSL   L080000
         PLY
         TAY
         BEQ   L0A0EC3
         LDA   [$EC]
         LDX   #$0000
         TAY
         BPL   L0A0E54
         DEX
L0A0E54  PEA   $0000
         PEA   $0006
         CLC
         JSL   L0105E1
         LDX   $E6
         LDA   $E4
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$0002
         LDA   [$F4],Y
         PHA
         LDY   #$000E
         LDA   [$E0],Y
         PLX
         STX   $F8
         CLC
         ADC   $F8
         LDY   #$000E
         STA   [$E0],Y
         LDA   [$EC]
         LDX   #$0000
         TAY
         BPL   L0A0E8C
         DEX
L0A0E8C  PEA   $0000
         PEA   $0006
         CLC
         JSL   L0105E1
         LDX   $E6
         LDA   $E4
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$0004
         LDA   [$F4],Y
         PHA
         LDY   #$0010
         LDA   [$E0],Y
         PLX
         STX   $F8
         CLC
         ADC   $F8
         LDY   #$0010
         STA   [$E0],Y
         LDA   [$EC]
         CLC
         ADC   #$0001
         STA   [$EC]
L0A0EC3  LDA   [$EC]
         LDX   #$0000
         TAY
         BPL   L0A0ECC
         DEX
L0A0ECC  PEA   $0000
         PEA   $0006
         CLC
         JSL   L0105E1
         LDX   $E6
         LDA   $E4
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   [$F4]
         AND   #$C000
         CMP   #$C000
         BEQ   L0A0EF2
         BRL   L0A0F9A
L0A0EF2  LDY   #$0018
         LDA   [$E0],Y
         CMP   #$0003
         BNE   L0A0F3B
         LDY   #$0012
         LDA   [$E0],Y
         BEQ   L0A0F3B
         LDY   #$0012
         LDA   [$E0],Y
         PHA
         PEI   $EA
         JSL   L081C57
         PLY
         PLY
         LDA   #$0000
         LDY   #$0018
         STA   [$E0],Y
         LDA   $EA
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   #$0000
         LDY   #$0004
         STA   [$F4],Y
L0A0F3B  LDY   #$0014
         LDA   [$E0],Y
         BRL   L0A0F8C
L0A0F43  PEI   $FF
         PEI   $EA
         JSL   L0A057F
         PLY
         PLY
         STA   $DA
         BRL   L0A0F9A
L0A0F52  PEI   $FF
         PEI   $EA
         JSL   L090000
         PLY
         PLY
         STA   $DA
         BRL   L0A0F9A
L0A0F61  PEI   $EA
         JSL   L09091B
         PLY
         BRL   L0A0F9A
L0A0F6B  PEI   $FF
         PEI   $EA
         JSL   L09107E
         PLY
         PLY
         STA   $DA
         BRL   L0A0F9A
L0A0F7A  BRL   L0A0F9A
         BRL   L0A0F9A
L0A0F80  DA    L0A0F43
         DA    L0A0F6B
         DA    L0A0F61
         DA    L0A0F7A
         DA    L0A0F52
         DA    L0A0F7A
L0A0F8C  DEC
         CMP   #$0005
         BCC   L0A0F95
         LDA   #$0005
L0A0F95  ASL
         TAX
         JMP   (L0A0F80,X)

L0A0F9A  INC   $EA
L0A0F9C  LDA   $EA
         SEC
         SBC   #$0014
         BVS   L0A0FA7
         EOR   #$8000
L0A0FA7  BMI   L0A0FAC
         BRL   L0A0D7F
L0A0FAC  LDA   #$0003
         STA   $EA
         BRL   L0A103E
L0A0FB4  LDA   $EA
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STX   $E2
         STA   $E0
         LDA   $E0
         CLC
         ADC   #$000C
         LDX   $E2
         BCC   L0A0FE0
         INX
L0A0FE0  STX   $EE
         STA   $EC
         LDA   $E0
         CLC
         ADC   #$000A
         LDX   $E2
         BCC   L0A0FEF
         INX
L0A0FEF  STX   $F2
         STA   $F0
         LDA   [$F0]
         LDX   #$0000
         TAY
         BPL   L0A0FFC
         DEX
L0A0FFC  STX   $F8
         ASL
         ROL   $F8
         ASL
         ROL   $F8
         LDX   $F8
         PHX
         PHA
         LDA   #L0314C0
         LDX   #^L0314C0
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$0002
         LDA   [$F4],Y
         TAX
         LDA   [$F4]
         STX   $E6
         STA   $E4
         LDA   [$F0]
         CMP   #$000E
         BNE   L0A103C
         PEI   $EA
         JSL   L080000
         PLY
         TAY
         BEQ   L0A103C
         PEI   $EA
         JSL   L0800E0
         PLY
L0A103C  INC   $EA
L0A103E  LDA   $EA
         SEC
         SBC   #$0006
         BVS   L0A1049
         EOR   #$8000
L0A1049  BMI   L0A104E
         BRL   L0A0FB4
L0A104E  LDA   #$0014
         STA   $EA
         BRL   L0A11C9
L0A1056  LDA   $EA
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STX   $E2
         STA   $E0
         LDA   $E0
         CLC
         ADC   #$000C
         LDX   $E2
         BCC   L0A1082
         INX
L0A1082  STX   $EE
         STA   $EC
         LDA   $E0
         CLC
         ADC   #$000A
         LDX   $E2
         BCC   L0A1091
         INX
L0A1091  STX   $F2
         STA   $F0
         LDA   [$F0]
         LDX   #$0000
         TAY
         BPL   L0A109E
         DEX
L0A109E  STX   $F8
         ASL
         ROL   $F8
         ASL
         ROL   $F8
         LDX   $F8
         PHX
         PHA
         LDA   #L0314C0
         LDX   #^L0314C0
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$0002
         LDA   [$F4],Y
         TAX
         LDA   [$F4]
         STX   $E6
         STA   $E4
         LDA   [$F0]
         CMP   #$000F
         BEQ   L0A10D0
         BRL   L0A11C7
L0A10D0  PEI   $EA
         JSL   L080000
         PLY
         TAY
         BNE   L0A10DD
         BRL   L0A11C7
L0A10DD  LDA   #$FFFF
         STA   [$F0]
         LDA   $EA
         ASL
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0304DA
         LDX   #^L0304DA
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   #$0000
         LDY   #$0002
         STA   [$F4],Y
         LDA   $EA
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDY   #$0012
         LDA   [$F4],Y
         CMP   #$FFFF
         BNE   L0A1162
         LDA   L02004C
         CLC
         ADC   #$0001
         STA   L02004C
         LDA   $EA
         PHA
         LDA   #$001A
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         PHX
         PHA
         LDA   #L03059A
         LDX   #^L03059A
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   #$0000
         LDY   #$0012
         STA   [$F4],Y
L0A1162  STZ   $E8
         BRA   L0A11BA
L0A1166  LDA   $E8
         LDX   #$0000
         TAY
         BPL   L0A116F
         DEX
L0A116F  STX   $F8
         ASL
         ROL   $F8
         LDX   $F8
         PHX
         PHA
         LDA   #L03177C
         LDX   #^L03177C
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   [$F4]
         AND   #$00FF
         CMP   $EA
         BNE   L0A11B8
         LDA   $E8
         LDX   #$0000
         TAY
         BPL   L0A119A
         DEX
L0A119A  STX   $F8
         ASL
         ROL   $F8
         LDX   $F8
         PHX
         PHA
         LDA   #L03177C
         LDX   #^L03177C
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   #$0000
         STA   [$F4]
L0A11B8  INC   $E8
L0A11BA  LDA   $E8
         SEC
         SBC   #$0003
         BVS   L0A11C5
         EOR   #$8000
L0A11C5  BPL   L0A1166
L0A11C7  INC   $EA
L0A11C9  LDA   $EA
         SEC
         SBC   #$0018
         BVS   L0A11D4
         EOR   #$8000
L0A11D4  BMI   L0A11D9
         BRL   L0A1056
L0A11D9  PEI   $FF
         JSL   L0810F8
         PLY
         JSL   L0F0000
         LDA   $DA
         TAY
         TSC
         CLC
         ADC   #$0020
         TCS
         TYA
         PLD
         RTL

