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

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

	 use	SPRITEGS.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
	
*-----------------------

L130000  PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00F2
         TCS
         LDA   $FF
         CMP   #$0041
         BCC   L13001E
         LDA   $FF
         SEC
         SBC   #$0041
         CLC
         ADC   #$000A
         BRA   L130024
L13001E  LDA   $FF
         SEC
         SBC   #$0030
L130024  TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

         PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00F0
         TCS
         LDX   $FF
         LDA   $FD
         TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

L130047  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         PEA   $0000
         JSL   L130062
         PLY
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L130062  PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00EC
         TCS
         LDA   $FF
         STA   L0200FF
         LDA   $FF
         ASL
         ASL
         ASL
         ASL
         STA   L020101
         LDA   $FF
         ASL
         ASL
         ASL
         ASL
         ASL
         ASL
         ASL
         ASL
         STA   L020103
         LDA   #$000C
         PHA
         LDA   $FF
         CLC
         JSL   L010733
         PLA
         STA   L020105
         STZ   $F2
         BRL   L1301B2
L13009C  LDA   $F2
         AND   #$000F
         CMP   $FF
         BNE   L1300AA
         LDA   #$000F
         BRA   L1300AD
L1300AA  LDA   #$0000
L1300AD  PHA
         LDA   $F2
         LDX   #$0000
         PHX
         PHA
         LDA   #L032D01
         LDX   #^L032D01
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         PLA
         SEP   #$20
         STA   [$F4]
         REP   #$20
         LDA   $F2
         AND   #$000F
         CMP   $FF
         BNE   L1300DA
         LDA   #$008F
         BRA   L1300DD
L1300DA  LDA   #$0088
L1300DD  PHA
         LDA   $F2
         LDX   #$0000
         PHX
         PHA
         LDA   #L032F01
         LDX   #^L032F01
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         PLA
         SEP   #$20
         STA   [$F4]
         REP   #$20
         LDA   $F2
         AND   #$00F0
         CMP   L020101
         BNE   L130150
         LDA   $F2
         LDX   #$0000
         PHX
         PHA
         LDA   #L032D01
         LDX   #^L032D01
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   [$F4]
         AND   #$00FF
         ORA   #$00F0
         SEP   #$20
         STA   [$F4]
         REP   #$20
         LDA   $F2
         LDX   #$0000
         PHX
         PHA
         LDA   #L032F01
         LDX   #^L032F01
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   [$F4]
         AND   #$00FF
         ORA   #$00F0
         SEP   #$20
         STA   [$F4]
         REP   #$20
L130150  SEP   #$20
         LDA   $F2
         LSR
         ROR
         ROR
         ROR
         TAY
         ROR
         REP   #$20
         AND   #$00F0
         STA   $F0
         TYA
         AND   #$000F
         ORA   $F0
         STA   $F0
         AND   #$0077
         STA   $EE
         LDA   $F0
         PHA
         LDA   $F2
         LDX   #$0000
         PHX
         PHA
         LDA   #L032E01
         LDX   #^L032E01
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         PLA
         SEP   #$20
         STA   [$F4]
         REP   #$20
         LDA   $EE
         PHA
         LDA   $F2
         LDX   #$0000
         PHX
         PHA
         LDA   #L033001
         LDX   #^L033001
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         PLA
         SEP   #$20
         STA   [$F4]
         REP   #$20
         INC   $F2
L1301B2  LDA   $F2
         CMP   #$0100
         BEQ   L1301BC
         BRL   L13009C
L1301BC  PHX
         PHA
         _GetPort
         BCS   L1301CA
         LDA   #$0000
L1301CA  STAL  L020010
         PLA
         PLX
         STX   L020111
         STA   L02010F
         TSC
         CLC
         ADC   #$000C
         TCS
         PLD
         RTL

L1301DE  XBA
         TAX
         LSR
         LSR
         LSR
         LSR
         AND   #$0F0F
         STA   L020109
         TXA
         ASL
         ASL
         ASL
         ASL
         AND   #$F0F0
         ORA   L020109
         RTL

L1301F6  STA   $00
         STX   $02
         XBA
         SEP   #$30
         TAX
         LDAL  L032D01,X
         XBA
         LDX   $00
         LDAL  L032D01,X
         REP   #$30
         TAX
         AND   $02
         STA   $02
         TXA
         EOR   #$FFFF
         AND   $00
         ORA   $02
         RTL

L130219  PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00E8
         TCS
         LDA   #$0000
         SEP   #$20
         STA   $F1
         REP   #$20
         LDA   #$0006
         STA   $F2
L130232  LDA   #$000A
         PHA
         LDA   $FF
         CLC
         JSL   L01041B
         LDA   #$0030
         PLX
         STX   $F8
         CLC
         ADC   $F8
         PHA
         LDA   $F2
         DEC   $F2
         LDX   #$0000
         PHX
         PHA
         LDX   #$0000
         TDC
         CLC
         ADC   #$00EA
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         PLA
         SEP   #$20
         STA   [$F4]
         REP   #$20
         LDA   #$000A
         PHA
         LDA   $FF
         CLC
         JSL   L01041B
         PLY
         STA   $FF
         LDA   $FF
         BNE   L130232
         LDA   $F2
         CLC
         ADC   #$0001
         LDX   #$0000
         PHX
         PHA
         LDX   #$0000
         TDC
         CLC
         ADC   #$00EA
         JSL   L010410
         _DrawCString
         BCS   L13029E
         LDA   #$0000
L13029E  STAL  L020010
         TSC
         CLC
         ADC   #$0010
         TCS
         PLD
         RTL

L1302AA  PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00E6
         TCS
         LDA   #$0000
         SEP   #$20
         STA   $EF
         REP   #$20
         LDA   #$0006
         STA   $F0
L1302C3  LDX   #$0000
         LDA   #$000A
         PHX
         PHA
         LDX   $FF
         LDA   $FD
         CLC
         JSL   L0104A0
         LDX   #$0000
         LDA   #$0030
         JSL   L010410
         PLA
         PLX
         PHA
         LDA   $F0
         DEC   $F0
         LDX   #$0000
         PHX
         PHA
         LDX   #$0000
         TDC
         CLC
         ADC   #$00E8
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         PLA
         SEP   #$20
         STA   [$F2]
         REP   #$20
         LDX   #$0000
         LDA   #$000A
         PHX
         PHA
         LDX   $FF
         LDA   $FD
         CLC
         JSL   L0104A0
         PLY
         PLY
         STX   $FF
         STA   $FD
         LDX   $FF
         LDA   $FD
         STX   $F2
         ORA   $F2
         BNE   L1302C3
         LDA   $F0
         CLC
         ADC   #$0001
         LDX   #$0000
         PHX
         PHA
         LDX   #$0000
         TDC
         CLC
         ADC   #$00E8
         JSL   L010410
         _DrawCString
         BCS   L130347
         LDA   #$0000
L130347  STAL  L020010
         TSC
         CLC
         ADC   #$0010
         TCS
         PLD
         RTL

L130353  ENT
         PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00F0
         TCS
         LDX   L020111
         LDA   L02010F
         STA   $F2
         STX   $F4
         LDY   #$0004
         LDA   [$F2],Y
         TAX
         LDY   #$0002
         LDA   [$F2],Y
         STX   L02010D
         STA   L02010B
         LDX   L020111
         LDA   L02010F
         STA   $F2
         STX   $F4
         LDX   $FF
         LDA   $FD
         LDY   #$0004
         PHA
         TXA
         STA   [$F2],Y
         PLA
         LDY   #$0002
         STA   [$F2],Y
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L13039C  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         LDX   L020111
         LDA   L02010F
         STA   $F6
         STX   $F8
         LDX   L02010D
         LDA   L02010B
         LDY   #$0004
         PHA
         TXA
         STA   [$F6],Y
         PLA
         LDY   #$0002
         STA   [$F6],Y
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

         PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00F0
         TCS
         PEI   $FD
         _SetForeColor
         BCS   L1303E5
         LDA   #$0000
L1303E5  STAL  L020010
         PEI   $FF
         _SetBackColor
         BCS   L1303F7
         LDA   #$0000
L1303F7  STAL  L020010
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L130403  ENT
         PHD
         TSC
         SEC
         SBC   #$00EF
         TCD
         ADC   #$00DA
         TCS
         DEC   $F7
         PEI   $FB
         PEI   $F9
         JSL   L130353
         PLY
         PLY
         PEI   $F5
         LDA   $F7
         CLC
         ADC   #$0008
         PHA
         _MoveTo
         BCS   L13042F
         LDA   #$0000
L13042F  STAL  L020010
         LDX   #$0000
         TDC
         CLC
         ADC   #$00FD
         STX   $E8
         STA   $E6
         LDX   $E8
         LDA   $E6
         CLC
         ADC   #$0004
         PHA
         TXA
         ADC   #$0000
         TAX
         PLA
         STX   $E8
         STA   $E6
L130452  LDA   [$FD]
         AND   #$00FF
         BNE   L13045C
         BRL   L130676
L13045C  LDA   [$FD]
         AND   #$00FF
         BEQ   L130493
         LDA   [$FD]
         AND   #$00FF
         CMP   #$0025
         BEQ   L130493
         LDX   $FF
         LDA   $FD
         INC   $FD
         BNE   L130477
         INC   $FF
L130477  STA   $EA
         STX   $EC
         LDA   [$EA]
         AND   #$00FF
         PHA
         _DrawChar
         BCS   L13048D
         LDA   #$0000
L13048D  STAL  L020010
         BRA   L13045C
L130493  LDA   [$FD]
         AND   #$00FF
         CMP   #$0025
         BEQ   L1304A0
         BRL   L130673
L1304A0  INC   $FD
         BNE   L1304A6
         INC   $FF
L1304A6  LDX   $FF
         LDA   $FD
         INC   $FD
         BNE   L1304B0
         INC   $FF
L1304B0  STA   $EA
         STX   $EC
         LDA   [$EA]
         AND   #$00FF
         STA   $E4
         STZ   $E2
         LDA   $E4
         BRL   L130609
L1304C2  PEA   $0025
         _DrawChar
         BCS   L1304D1
         LDA   #$0000
L1304D1  STAL  L020010
         BRL   L13065E
L1304D8  PEA   $0004
         _SetTextMode
         BCS   L1304E7
         LDA   #$0000
L1304E7  STAL  L020010
         BRL   L13065E
L1304EE  PEA   $0000
         _SetTextMode
         BCS   L1304FD
         LDA   #$0000
L1304FD  STAL  L020010
         BRL   L13065E
L130504  LDA   [$E6]
         PHA
         _SetForeColor
         BCS   L130513
         LDA   #$0000
L130513  STAL  L020010
         LDA   #$0002
         STA   $E2
         BRL   L13065E
L13051F  LDA   [$E6]
         PHA
         _SetBackColor
         BCS   L13052E
         LDA   #$0000
L13052E  STAL  L020010
         LDA   #$0002
         STA   $E2
         BRL   L13065E
L13053A  LDX   $FF
         LDA   $FD
         INC   $FD
         BNE   L130544
         INC   $FF
L130544  STA   $EA
         STX   $EC
         LDA   [$EA]
         AND   #$00FF
         PHA
         JSL   L130000
         PLY
         STA   $E0
         PEI   $E0
         _SetForeColor
         BCS   L130563
         LDA   #$0000
L130563  STAL  L020010
         BRL   L13065E
L13056A  LDX   $FF
         LDA   $FD
         INC   $FD
         BNE   L130574
         INC   $FF
L130574  STA   $EA
         STX   $EC
         LDA   [$EA]
         AND   #$00FF
         PHA
         JSL   L130000
         PLY
         STA   $E0
         PEI   $E0
         _SetBackColor
         BCS   L130593
         LDA   #$0000
L130593  STAL  L020010
         BRL   L13065E
L13059A  LDY   #$0002
         LDA   [$E6],Y
         TAX
         LDA   [$E6]
         PHX
         PHA
         _DrawCString
         BCS   L1305B0
         LDA   #$0000
L1305B0  STAL  L020010
         LDA   #$0004
         STA   $E2
         BRL   L13065E
L1305BC  LDA   [$E6]
         PHA
         JSL   L130219
         PLY
         LDA   #$0002
         STA   $E2
         BRL   L13065E
L1305CC  LDY   #$0002
         LDA   [$E6],Y
         TAX
         LDA   [$E6]
         PHX
         PHA
         JSL   L1302AA
         PLY
         PLY
         LDA   #$0004
         STA   $E2
         BRL   L13065E
L1305E4  LDA   $F7
         CLC
         ADC   #$0008
         STA   $F7
         PEI   $F5
         LDA   $F7
         CLC
         ADC   #$0008
         PHA
         _MoveTo
         BCS   L130601
         LDA   #$0000
L130601  STAL  L020010
         BRA   L13065E
         BRA   L13065E
L130609  CMP   #$0025
         BNE   L130611
         BRL   L1304C2
L130611  CMP   #$0043
         BNE   L130619
         BRL   L13053A
L130619  CMP   #$0046
         BNE   L130621
         BRL   L13056A
L130621  CMP   #$0049
         BNE   L130629
         BRL   L1304D8
L130629  CMP   #$004E
         BNE   L130631
         BRL   L1304EE
L130631  CMP   #$0063
         BNE   L130639
         BRL   L130504
L130639  CMP   #$0064
         BNE   L130641
         BRL   L1305BC
L130641  CMP   #$0066
         BNE   L130649
         BRL   L13051F
L130649  CMP   #$006C
         BNE   L130651
         BRL   L1305CC
L130651  CMP   #$006E
         BEQ   L1305E4
         CMP   #$0073
         BNE   L13065E
         BRL   L13059A
L13065E  LDA   $E2
         LDX   #$0000
         PHX
         PHA
         LDX   $E8
         LDA   $E6
         JSL   L010410
         PLA
         PLX
         STX   $E8
         STA   $E6
L130673  BRL   L130452
L130676  PEA   $0000
         _SetTextMode
         BCS   L130685
         LDA   #$0000
L130685  STAL  L020010
         JSL   L13039C
         TSC
         CLC
         ADC   #$0014
         TCS
         PLD
         RTL

L130695  ENT
         PHD
         TSC
         SEC
         SBC   #$00ED
         TCD
         ADC   #$00CE
         TCS
         LDA   $F3
         AND   #$8000
         STA   $E2
         LDA   $F3
         AND   #$4000
         TAY
         BEQ   L1306B4
         LDA   #$0000
         BRA   L1306B7
L1306B4  LDA   #$0001
L1306B7  STA   $E0
         LDA   $F3
         AND   #$3FFF
         STA   $F3
         LDA   $F3
         LDX   #$0000
         STX   $EC
         ASL
         ROL   $EC
         ASL
         ROL   $EC
         LDX   $EC
         PHX
         PHA
         LDX   $FF
         LDA   $FD
         JSL   L010410
         PLA
         PLX
         STA   $E8
         STX   $EA
         LDY   #$0002
         LDA   [$E8],Y
         TAX
         LDA   [$E8]
         STX   $DE
         STA   $DC
         LDX   $DE
         LDA   $DC
         INC   $DC
         BNE   L1306F5
         INC   $DE
L1306F5  STA   $E8
         STX   $EA
         LDA   [$E8]
         AND   #$00FF
         ASL
         STA   $E4
         LDX   $DE
         LDA   $DC
         INC   $DC
         BNE   L13070B
         INC   $DE
L13070B  STA   $E8
         STX   $EA
         LDA   [$E8]
         AND   #$00FF
         STA   $E6
         LDA   $E4
         LSR
         PHA
         LDA   $F5
         LSR
         PLX
         STX   $EC
         CLC
         ADC   $EC
         CMP   #$00A0
         BEQ   L13073D
         BCC   L13073D
         LDA   $F5
         LSR
         PHA
         LDA   #$00A0
         PLX
         STX   $EC
         SEC
         SBC   $EC
         SEC
         SBC   #$0002
         BRA   L130744
L13073D  LDA   $E4
         LSR
         SEC
         SBC   #$0002
L130744  STA   $D2
         LDA   $D2
         SEC
         SBC   #$0000
         BEQ   L13075C
         BVS   L130753
         EOR   #$8000
L130753  BPL   L13075C
         LDA   $E6
         CMP   #$0000
         BNE   L13075F
L13075C  BRL   L13085B
L13075F  LDA   $F7
         CMP   $E6
         BCS   L1307A3
         LDA   $F5
         LSR
         LDX   #$0000
         PHX
         PHA
         LDX   $FB
         LDA   $F9
         JSL   L010410
         PLA
         PLX
         STX   $DA
         STA   $D8
         LDA   $E4
         PHA
         LDA   $E6
         SEC
         SBC   $F7
         CLC
         JSL   L01059C
         PLA
         LSR
         LDX   #$0000
         PHX
         PHA
         LDX   $DE
         LDA   $DC
         JSL   L010410
         PLA
         PLX
         STX   $DE
         STA   $DC
         LDA   $F7
         STA   $E6
         BRA   L1307E7
L1307A3  LDA   $F7
         SEC
         SBC   $E6
         LDX   #$0000
         STX   $EC
         ASL
         ROL   $EC
         LDX   $EC
         PHX
         PHA
         LDA   #L033394
         LDX   #^L033394
         JSL   L010410
         PLA
         PLX
         STA   $E8
         STX   $EA
         LDA   [$E8]
         LDX   #$0000
         PHX
         PHA
         LDA   $F5
         LSR
         LDX   #$0000
         PHX
         PHA
         LDX   $FB
         LDA   $F9
         JSL   L010410
         PLA
         PLX
         JSL   L010410
         PLA
         PLX
         STX   $DA
         STA   $D8
L1307E7  LDA   $E0
         BEQ   L130825
         LDA   $E2
         BEQ   L130809
         PEI   $E4
         PEI   $E6
         PEI   $DA
         PEI   $D8
         PEI   $DE
         PEI   $DC
         JSL   L1309E4
         TAY
         TSC
         CLC
         ADC   #$000C
         TCS
         TYA
         BRA   L130823
L130809  PEI   $D2
         PEI   $E4
         PEI   $E6
         PEI   $DA
         PEI   $D8
         PEI   $DE
         PEI   $DC
         JSL   L130947
         TAY
         TSC
         CLC
         ADC   #$000E
         TCS
         TYA
L130823  BRA   L13085B
L130825  LDA   $E2
         BEQ   L130843
         PEI   $E4
         PEI   $E6
         PEI   $DA
         PEI   $D8
         PEI   $DE
         PEI   $DC
         JSL   L130990
         TAY
         TSC
         CLC
         ADC   #$000C
         TCS
         TYA
         BRA   L13085B
L130843  PEI   $E4
         PEI   $E6
         PEI   $DA
         PEI   $D8
         PEI   $DE
         PEI   $DC
         JSL   L130863
         TAY
         TSC
         CLC
         ADC   #$000C
         TCS
         TYA
L13085B  TSC
         CLC
         ADC   #$001E
         TCS
         PLD
         RTL

L130863  PHD
         TSC
         SEC
         SBC   #$00EF
         TCD
         ADC   #$00E4
         TCS
         LDA   $FF
         LSR
         DEC
         STA   $FF
         LDA   #$00A0
         SEC
         SBC   $FF
         DEC
         STA   $E6
         PHB
         PHK
         PLB
         PER   L130897+1
         PLA
         STA   $E8
         SEP   #$20
         LDA   $F7
         XBA
         LDA   $FB
         REP   #$20
         STA   ($E8)
         LDX   $F5
         LDY   $F9
L130895  LDA   $FF
L130897  MVN   $000000,$000000
         TYA
         CLC
         ADC   $E6
         TAY
         DEC   $FD
         BNE   L130895
         PLB
         TSC
         CLC
         ADC   #$000A
         TCS
         PLD
         RTL

         PHD
         TSC
         SEC
         SBC   #$00EF
         TCD
         ADC   #$00E4
         TCS
         TSC
         CLC
         ADC   #$000A
         TCS
         PLD
         RTL

L1308BF  ENT
         PHD
         TSC
         SEC
         SBC   #$00EF
         TCD
         ADC   #$00E4
         TCS
         LDA   $FF
         LSR
         DEC
         STA   $FF
         LDA   #$00A0
         SEC
         SBC   $FF
         DEC
         STA   $E6
         PHB
         PHK
         PLB
         PER   L1308F3+1
         PLA
         STA   $E8
         SEP   #$20
         LDA   $F7
         XBA
         LDA   $FB
         REP   #$20
         STA   ($E8)
         LDX   $F5
         LDY   $F9
L1308F1  LDA   $FF
L1308F3  MVN   $000000,$000000
         TYA
         CLC
         ADC   $E6
         TAY
         TXA
         CLC
         ADC   $E6
         TAX
         DEC   $FD
         BNE   L1308F1
         PLB
         TSC
         CLC
         ADC   #$000A
         TCS
         PLD
         RTL

L13090D  ENT
         PHD
         TSC
         SEC
         SBC   #$00F5
         TCD
         ADC   #$00EA
         TCS
         LDA   $FF
         LSR
         DEC
         STA   $FF
         LDA   #$00A0
         SEC
         SBC   $FF
         DEC
         STA   $EE
         PHB
         CLC
         LDA   $FB
         ADC   #$2000
         TAX
         TAY
L130930  LDA   $FF
         MVN   $010000,$E10000
         TYA
         ADC   $EE
         TAY
         TAX
         DEC   $FD
         BNE   L130930
         PLB
         TSC
         CLC
         ADC   #$000A
         TCS
         PLD
         RTL

L130947  PHD
         TSC
         SEC
         SBC   #$00ED
         TCD
         ADC   #$00E4
         TCS
         LSR   $FD
L130954  LDY   $FF
L130956  LDA   [$F3],Y
         BEQ   L130972
         STA   $E6
         SEP   #$30
         XBA
         TAX
         LDAL  L032D01,X
         XBA
         TAX
         LDAL  L032D01,X
         REP   #$30
         AND   [$F7],Y
         ORA   $E6
         STA   [$F7],Y
L130972  DEY
         DEY
         BPL   L130956
         CLC
         LDA   $F7
         ADC   #$00A0
         STA   $F7
         LDA   $F3
         ADC   $FD
         STA   $F3
         DEC   $FB
         BNE   L130954
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

L130990  PHD
         TSC
         SEC
         SBC   #$00EF
         TCD
         ADC   #$00E8
         TCS
         LDA   $FF
         LSR
         LSR
         DEC
         ASL
         STA   $FF
         LDX   $FD
L1309A5  PHX
         LDY   $FF
L1309A8  LDA   [$F5],Y
         STY   L020107
         JSL   L1301DE
         TAX
         LDA   $FF
         SEC
         SBC   L020107
         TAY
         TXA
         STA   [$F9],Y
         LDY   L020107
         DEY
         DEY
         BPL   L1309A8
         CLC
         LDA   $F9
         ADC   #$00A0
         BCC   L1309CD
         INC   $FB
L1309CD  STA   $F9
         LDA   $F5
         ADC   $FF
         ADC   #$0002
         STA   $F5
         PLX
         DEX
         BNE   L1309A5
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L1309E4  PHD
         TSC
         SEC
         SBC   #$00EF
         TCD
         ADC   #$00E8
         TCS
         LDA   $FF
         LSR
         LSR
         DEC
         ASL
         STA   $FF
         LDX   $FD
L1309F9  PHX
         LDY   $FF
L1309FC  LDA   [$F5],Y
         STY   L020107
         JSL   L1301DE
         PHA
         LDA   $FF
         SEC
         SBC   L020107
         TAY
         LDA   [$F9],Y
         TAX
         PLA
         PHY
         JSL   L1301F6
         PLY
         STA   [$F9],Y
         LDY   L020107
         DEY
         DEY
         BPL   L1309FC
         CLC
         LDA   $F9
         ADC   #$00A0
         STA   $F9
         LDA   $F5
         ADC   $FF
         ADC   #$0002
         STA   $F5
         PLX
         DEX
         BNE   L1309F9
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L130A3D  PHD
         TSC
         SEC
         SBC   #$00EF
         TCD
         ADC   #$00AC
         TCS
         STZ   $E2
         LDA   $F5
         AND   #$3FFF
         STA   $F5
         ASL
         ASL
         TAY
         LDA   [$F9],Y
         STA   $C8
         INY
         INY
         LDA   [$F9],Y
         STA   $CA
         LDA   [$C8]
         TAX
         AND   #$00FF
         STA   $E2
         ASL
         STA   $E6
         TXA
         XBA
         AND   #$00FF
         STA   $E8
         INC   $C8
         INC   $C8
         LDA   #$0004
         PHA
         LDA   $F7
         CLC
         ADC   #$0001
         PHA
         LDA   $E6
         SEC
         JSL   L01059C
         PLA
         SEC
         JSL   L01076A
         PLA
         STA   $CC
         LDA   $E6
         SEC
         SBC   $CC
         STA   $D8
         LDA   $D8
         PHA
         LDA   $E6
         SEC
         JSL   L01041B
         PLY
         STA   $DA
         LDA   $D8
         PHA
         LDA   $E6
         SEC
         JSL   L01041B
         PLA
         STA   $D6
         STZ   $DE
         LDA   #$0001
         STA   $E0
         BRA   L130AFD
L130AB9  LDA   $D8
         PHA
         LDA   $E0
         PHA
         LDA   $D6
         SEC
         JSL   L01059C
         PLA
         SEC
         JSL   L01041B
         PLY
         STA   $D2
         LDX   $DE
         LDY   $DA
         DEY
         LDA   #$0001
         SEP   #$20
L130AD9  STAL  L033101,X
         INX
         DEY
         BNE   L130AD9
         LDA   #$00
         STAL  L033101,X
         INX
         LDY   $D2
         CPY   $D4
         BEQ   L130AF7
         STY   $D4
         LDA   #$01
         STAL  L033101,X
         INX
L130AF7  STX   $DE
         REP   #$20
         INC   $E0
L130AFD  LDA   $E0
         SEC
         SBC   $D8
         BEQ   L130AB9
         BVS   L130B09
         EOR   #$8000
L130B09  BPL   L130AB9
         LDA   #$0004
         PHA
         LDA   $F7
         CLC
         ADC   #$0001
         PHA
         LDA   $E8
         SEC
         JSL   L01059C
         PLA
         SEC
         JSL   L01076A
         PLA
         STA   $E4
         LDA   $E4
         CLC
         ADC   #$0001
         PHA
         LDA   #$0004
         PHA
         LDA   $CC
         SEC
         JSL   L01076A
         PLA
         CLC
         ADC   #$0001
         ASL
         ASL
         ASL
         CLC
         ADC   #$0001
         SEC
         JSL   L01059C
         PLA
         LDX   #$0000
         TAY
         BPL   L130B51
         DEX
L130B51  CLC
         ADC   #$000A
         PHA
         TXA
         ADC   #$0000
         TAX
         PLA
         PHX
         PHA
         JSL   L1601A2
         PLY
         PLY
         STX   $C6
         STA   $C4
         LDA   $F5
         LDX   #$0000
         TAY
         BPL   L130B71
         DEX
L130B71  STX   $EE
         ASL
         ROL   $EE
         ASL
         ROL   $EE
         LDX   $EE
         PHX
         PHA
         LDX   $FF
         LDA   $FD
         JSL   L010410
         PLA
         PLX
         STA   $EA
         STX   $EC
         LDX   $C6
         LDA   $C4
         LDY   #$0002
         PHA
         TXA
         STA   [$EA],Y
         PLA
         STA   [$EA]
         LDA   #$0004
         PHA
         LDA   $CC
         SEC
         SBC   #$0001
         SEC
         JSL   L01076A
         PLA
         CLC
         ADC   #$0001
         ASL
         ASL
         ASL
         PHA
         LDX   $C6
         LDA   $C4
         INC   $C4
         BNE   L130BBB
         INC   $C6
L130BBB  STA   $EA
         STX   $EC
         PLA
         SEP   #$20
         STA   [$EA]
         REP   #$20
         LDA   $E4
         PHA
         LDX   $C6
         LDA   $C4
         INC   $C4
         BNE   L130BD3
         INC   $C6
L130BD3  STA   $EA
         STX   $EC
         PLA
         SEP   #$20
         STA   [$EA]
         REP   #$20
         STZ   $BE
         LDA   $E4
         CMP   #$0000
         BNE   L130BEA
         BRL   L130E51
L130BEA  LDA   $E8
         SEC
         SBC   $E4
         STA   $D8
         LDA   $D8
         PHA
         LDA   $E8
         SEC
         JSL   L01041B
         PLY
         STA   $DA
         LDA   $D8
         PHA
         LDA   $E8
         SEC
         JSL   L01041B
         PLA
         STA   $D6
         STZ   $DC
         STZ   $DE
         LDA   #$0001
         STA   $E0
         BRL   L130E3D
L130C17  LDA   $D8
         PHA
         LDA   $E0
         PHA
         LDA   $D6
         SEC
         JSL   L01059C
         PLA
         SEC
         JSL   L01041B
         PLY
         STA   $D2
         LDA   #$0001
         STA   $D0
L130C32  LDA   $D0
         SEC
         SBC   $DA
         BVS   L130C3C
         EOR   #$8000
L130C3C  BPL   L130C41
         BRL   L130D36
L130C41  STZ   $E2
         STZ   $CE
         BRL   L130CDE
L130C48  LDA   $CE
         LDX   #$0000
         PHX
         PHA
         LDA   #L033101
         LDX   #^L033101
         JSL   L010410
         PLA
         PLX
         STA   $EA
         STX   $EC
         LDA   [$EA]
         AND   #$00FF
         BEQ   L130CD0
         LDA   $CE
         AND   #$0001
         CMP   #$0000
         BNE   L130C93
         LDA   $E2
         CMP   #$0000
         BNE   L130C82
         LDY   $DC
         LDA   [$C8],Y
         AND   #$00F0
         STA   $BC
         BRA   L130C91
L130C82  LDY   $DC
         LDA   [$C8],Y
         LSR
         LSR
         LSR
         LSR
         AND   #$000F
         ORA   $BC
         STA   $BC
L130C91  BRA   L130CB4
L130C93  LDA   $E2
         CMP   #$0000
         BNE   L130CA9
         LDY   $DC
         LDA   [$C8],Y
         ASL
         ASL
         ASL
         ASL
         AND   #$00F0
         STA   $BC
         BRA   L130CB4
L130CA9  LDY   $DC
         LDA   [$C8],Y
         AND   #$000F
         ORA   $BC
         STA   $BC
L130CB4  LDA   $E2
         CMP   #$0001
         BNE   L130CCB
         LDY   $BE
         LDA   $BC
         SEP   #$20
         STA   [$C4],Y
         REP   #$20
         INC   $BE
         STZ   $E2
         BRA   L130CD0
L130CCB  LDA   #$0001
         STA   $E2
L130CD0  LDA   $CE
         AND   #$0001
         CMP   #$0001
         BNE   L130CDC
         INC   $DC
L130CDC  INC   $CE
L130CDE  LDA   $CE
         SEC
         SBC   $E6
         BVS   L130CE8
         EOR   #$8000
L130CE8  BMI   L130CED
         BRL   L130C48
L130CED  LDA   $CC
         AND   #$0001
         TAY
         BEQ   L130D01
         LDY   $BE
         LDA   $BC
         SEP   #$20
         STA   [$C4],Y
         REP   #$20
         INC   $BE
L130D01  LDA   $CC
         AND   #$000F
         TAY
         BEQ   L130D31
         LDA   $CC
         AND   #$000F
         PHA
         LDA   #$0010
         PLX
         STX   $EE
         SEC
         SBC   $EE
         STA   $CE
         LSR   $CE
         LDY   $BE
         LDX   $CE
         BEQ   L130D2F
         LDA   #$0000
         SEP   #$20
L130D27  STA   [$C4],Y
         INY
         DEX
         BNE   L130D27
         REP   #$20
L130D2F  STY   $BE
L130D31  INC   $D0
         BRL   L130C32
L130D36  LDA   $E6
         LSR
         CLC
         ADC   $DC
         STA   $DC
         LDA   $D2
         CMP   $D4
         BNE   L130D47
         BRL   L130E3B
L130D47  LDA   $D2
         STA   $D4
         STZ   $E2
         STZ   $CE
         BRL   L130DE8
L130D52  LDA   $CE
         LDX   #$0000
         PHX
         PHA
         LDA   #L033101
         LDX   #^L033101
         JSL   L010410
         PLA
         PLX
         STA   $EA
         STX   $EC
         LDA   [$EA]
         AND   #$00FF
         BEQ   L130DDA
         LDA   $CE
         AND   #$0001
         CMP   #$0000
         BNE   L130D9D
         LDA   $E2
         CMP   #$0000
         BNE   L130D8C
         LDY   $DC
         LDA   [$C8],Y
         AND   #$00F0
         STA   $BC
         BRA   L130D9B
L130D8C  LDY   $DC
         LDA   [$C8],Y
         LSR
         LSR
         LSR
         LSR
         AND   #$000F
         ORA   $BC
         STA   $BC
L130D9B  BRA   L130DBE
L130D9D  LDA   $E2
         CMP   #$0000
         BNE   L130DB3
         LDY   $DC
         LDA   [$C8],Y
         ASL
         ASL
         ASL
         ASL
         AND   #$00F0
         STA   $BC
         BRA   L130DBE
L130DB3  LDY   $DC
         LDA   [$C8],Y
         AND   #$000F
         ORA   $BC
         STA   $BC
L130DBE  LDA   $E2
         CMP   #$0001
         BNE   L130DD5
         LDY   $BE
         LDA   $BC
         SEP   #$20
         STA   [$C4],Y
         REP   #$20
         INC   $BE
         STZ   $E2
         BRA   L130DDA
L130DD5  LDA   #$0001
         STA   $E2
L130DDA  LDA   $CE
         AND   #$0001
         CMP   #$0001
         BNE   L130DE6
         INC   $DC
L130DE6  INC   $CE
L130DE8  LDA   $CE
         SEC
         SBC   $E6
         BVS   L130DF2
         EOR   #$8000
L130DF2  BMI   L130DF7
         BRL   L130D52
L130DF7  LDA   $CC
         AND   #$0001
         TAY
         BEQ   L130E0B
         LDY   $BE
         LDA   $BC
         SEP   #$20
         STA   [$C4],Y
         REP   #$20
         INC   $BE
L130E0B  LDA   $CC
         AND   #$000F
         TAY
         BEQ   L130E3B
         LDA   $CC
         AND   #$000F
         PHA
         LDA   #$0010
         PLX
         STX   $EE
         SEC
         SBC   $EE
         STA   $CE
         LSR   $CE
         LDY   $BE
         LDX   $CE
         BEQ   L130E39
         LDA   #$0000
         SEP   #$20
L130E31  STA   [$C4],Y
         INY
         DEX
         BNE   L130E31
         REP   #$20
L130E39  STY   $BE
L130E3B  INC   $E0
L130E3D  LDA   $E0
         SEC
         SBC   $D8
         BNE   L130E47
         BRL   L130C17
L130E47  BVS   L130E4C
         EOR   #$8000
L130E4C  BMI   L130E51
         BRL   L130C17
L130E51  TSC
         CLC
         ADC   #$0042
         TCS
         PLD
         RTL

L130E59  ENT
         PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00EE
         TCS
         STZ   $F0
L130E66  LDX   #$FFFF
         LDA   #$FFFF
         PHX
         PHA
         LDA   $F0
         LDX   #$0000
         STX   $F6
         ASL
         ROL   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDX   $FF
         LDA   $FD
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0002
         LDA   [$F2],Y
         TAX
         LDA   [$F2]
         JSL   L010668
         BNE   L130E9E
         BRL   L130F36
L130E9E  LDX   #$0000
         LDA   #$0000
         PHX
         PHA
         LDA   $F0
         LDX   #$0000
         STX   $F6
         ASL
         ROL   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDX   $FF
         LDA   $FD
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0002
         LDA   [$F2],Y
         TAX
         LDA   [$F2]
         JSL   L010668
         BEQ   L130F02
         LDA   $F0
         LDX   #$0000
         STX   $F6
         ASL
         ROL   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDX   $FF
         LDA   $FD
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0002
         LDA   [$F2],Y
         TAX
         LDA   [$F2]
         PHX
         PHA
         JSL   L160228
         PLY
         PLY
L130F02  LDA   $F0
         LDX   #$0000
         STX   $F6
         ASL
         ROL   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDX   $FF
         LDA   $FD
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDX   #$0000
         LDA   #$0000
         LDY   #$0002
         PHA
         TXA
         STA   [$F2],Y
         PLA
         STA   [$F2]
         INC   $F0
         BRL   L130E66
L130F36  PEI   $FF
         PEI   $FD
         JSL   L160228
         PLY
         PLY
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

L130F48  PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00EC
         TCS
         LDA   $FF
         ASL
         ASL
         LDX   #$0000
         CLC
         ADC   #$0004
         PHA
         TXA
         ADC   #$0000
         TAX
         PLA
         PHX
         PHA
         JSL   L1601A2
         PLY
         PLY
         STX   $F2
         STA   $F0
         STZ   $EE
         BRA   L130FA6
L130F75  LDA   $EE
         LDX   #$0000
         STX   $F8
         ASL
         ROL   $F8
         ASL
         ROL   $F8
         LDX   $F8
         PHX
         PHA
         LDX   $F2
         LDA   $F0
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDX   #$0000
         LDA   #$0000
         LDY   #$0002
         PHA
         TXA
         STA   [$F4],Y
         PLA
         STA   [$F4]
         INC   $EE
L130FA6  LDA   $EE
         CMP   $FF
         BNE   L130F75
         LDA   $FF
         LDX   #$0000
         STX   $F8
         ASL
         ROL   $F8
         ASL
         ROL   $F8
         LDX   $F8
         PHX
         PHA
         LDX   $F2
         LDA   $F0
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDX   #$FFFF
         LDA   #$FFFF
         LDY   #$0002
         PHA
         TXA
         STA   [$F4],Y
         PLA
         STA   [$F4]
         LDX   $F2
         LDA   $F0
         TAY
         TSC
         CLC
         ADC   #$000C
         TCS
         TYA
         PLD
         RTL

L130FE9  ENT
         PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00D2
         TCS
         LDY   #$0002
         LDA   [$FD],Y
         TAX
         LDA   [$FD]
         STX   $EC
         STA   $EA
         LDX   #$0000
         LDA   #$0002
         PHX
         PHA
         LDX   $EC
         LDA   $EA
         SEC
         JSL   L01078E
         PLA
         PLX
         STA   $E8
         PEI   $E8
         JSL   L130F48
         PLY
         STX   $D6
         STA   $D4
         STZ   $E2
L131022  LDA   $E2
         CMP   $E8
         BCC   L13102B
         BRL   L13114C
L13102B  LDA   $E2
         LDX   #$0000
         STX   $F6
         ASL
         ROL   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDX   $FF
         LDA   $FD
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDY   #$0002
         LDA   [$F2],Y
         TAX
         LDA   [$F2]
         PHX
         PHA
         LDX   $FF
         LDA   $FD
         JSL   L010410
         PLA
         PLX
         STX   $DE
         STA   $DC
         LDX   $DE
         LDA   $DC
         INC   $DC
         BNE   L13106C
         INC   $DE
L13106C  STA   $F2
         STX   $F4
         LDA   [$F2]
         AND   #$00FF
         ASL
         ASL
         ASL
         STA   $E6
         LDX   $DE
         LDA   $DC
         INC   $DC
         BNE   L131084
         INC   $DE
L131084  STA   $F2
         STX   $F4
         LDA   [$F2]
         AND   #$00FF
         STA   $E4
         LDA   $E4
         PHA
         LDA   $E6
         CLC
         JSL   L01059C
         PLA
         LDX   #$0000
         STX   $EC
         STA   $EA
         LDX   $EC
         LDA   $EA
         CLC
         ADC   #$000A
         PHA
         TXA
         ADC   #$0000
         TAX
         PLA
         PHX
         PHA
         JSL   L1601A2
         PLY
         PLY
         STX   $DA
         STA   $D8
         LDA   $E2
         LDX   #$0000
         STX   $F6
         ASL
         ROL   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDX   $D6
         LDA   $D4
         JSL   L010410
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDX   $DA
         LDA   $D8
         LDY   #$0002
         PHA
         TXA
         STA   [$F2],Y
         PLA
         STA   [$F2]
         LDA   $E6
         PHA
         LDX   $DA
         LDA   $D8
         INC   $D8
         BNE   L1310F6
         INC   $DA
L1310F6  STA   $F2
         STX   $F4
         PLA
         SEP   #$20
         STA   [$F2]
         REP   #$20
         LDA   $E4
         PHA
         LDX   $DA
         LDA   $D8
         INC   $D8
         BNE   L13110E
         INC   $DA
L13110E  STA   $F2
         STX   $F4
         PLA
         SEP   #$20
         STA   [$F2]
         REP   #$20
         SEC
         LDA   $EA
         SBC   #$0000
         BNE   L131128
         LDA   $EC
         SBC   #$0000
         BRA   L13112F
L131128  LDA   $EC
         SBC   #$0000
         REP   #$02
L13112F  BEQ   L131147
         LDX   $EC
         LDA   $EA
         PHA
         PEI   $DA
         PEI   $D8
         PEI   $DE
         PEI   $DC
         JSL   L1608E2
         PLY
         PLY
         PLY
         PLY
         PLY
L131147  INC   $E2
         BRL   L131022
L13114C  LDX   $D6
         LDA   $D4
         TAY
         TSC
         CLC
         ADC   #$0024
         TCS
         TYA
         PLD
         RTL

L13115A  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00E8
         TCS
         SEI
         LDA   #$0001
         STA   $F2
         BRL   L1311FE
L13116E  PEA   $0000
         PEA   $0058
         JSL   L130F48
         PLY
         PLY
         STX   $F0
         STA   $EE
         STZ   $F4
         BRA   L1311C2
L131182  PEI   $F0
         PEI   $EE
         LDAL  L03173E
         TAX
         LDAL  L03173C
         PHX
         PHA
         LDA   $F2
         LDX   #$0000
         STX   $FA
         ASL
         ROL   $FA
         LDX   $FA
         PHX
         PHA
         LDA   #L0314E8
         LDX   #^L0314E8
         JSL   L010410
         PLA
         PLX
         STA   $F6
         STX   $F8
         LDA   [$F6]
         PHA
         PEI   $F4
         JSL   L130A3D
         TAY
         TSC
         CLC
         ADC   #$000C
         TCS
         TYA
         INC   $F4
L1311C2  LDA   $F4
         CMP   #$0016
         BNE   L131182
         LDA   #$0006
         CLC
         ADC   $F2
         LDX   #$0000
         STX   $FA
         ASL
         ROL   $FA
         ASL
         ROL   $FA
         LDX   $FA
         PHX
         PHA
         LDA   #L03173C
         LDX   #^L03173C
         JSL   L010410
         PLA
         PLX
         STA   $F6
         STX   $F8
         LDX   $F0
         LDA   $EE
         LDY   #$0002
         PHA
         TXA
         STA   [$F6],Y
         PLA
         STA   [$F6]
         INC   $F2
L1311FE  LDA   $F2
         CMP   #$0004
         BEQ   L131208
         BRL   L13116E
L131208  LDAL  L03175A
         TAX
         LDAL  L031758
         PHA
         TXA
         STAL  L031756
         PLA
         STAL  L031754
         CLI
         TSC
         CLC
         ADC   #$0012
         TCS
         PLD
         RTL

L131225  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F2
         TCS
         LDA   #$0001
         STA   $F4
         BRA   L13126E
L131237  LDA   #$0006
         CLC
         ADC   $F4
         LDX   #$0000
         STX   $FA
         ASL
         ROL   $FA
         ASL
         ROL   $FA
         LDX   $FA
         PHX
         PHA
         LDA   #L03173C
         LDX   #^L03173C
         JSL   L010410
         PLA
         PLX
         STA   $F6
         STX   $F8
         LDY   #$0002
         LDA   [$F6],Y
         TAX
         LDA   [$F6]
         PHX
         PHA
         JSL   L130E59
         PLY
         PLY
         INC   $F4
L13126E  LDA   $F4
         CMP   #$0004
         BNE   L131237
         LDAL  L03173E
         TAX
         LDAL  L03173C
         PHX
         PHA
         JSL   L130E59
         PLY
         PLY
         LDAL  L031742
         TAX
         LDAL  L031740
         PHX
         PHA
         JSL   L130E59
         PLY
         PLY
         LDAL  L031746
         TAX
         LDAL  L031744
         PHX
         PHA
         JSL   L130E59
         PLY
         PLY
         LDAL  L03174A
         TAX
         LDAL  L031748
         PHX
         PHA
         JSL   L130E59
         PLY
         PLY
         LDAL  L031752
         TAX
         LDAL  L031750
         PHX
         PHA
         JSL   L130E59
         PLY
         PLY
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

