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

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

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

L040000  PHA
         REP   #$20
         TXA
         STAL  $E1C03E
         SEP   #$20
         LDA   #$60
         ORAL  $E100CA
         STAL  $E1C03C
         PLA
         RTL

L040016  PHA
         TXA
         STAL  $E1C03E
         LDA   #$20
         ORAL  $E100CA
         STAL  $E1C03C
         PLA
         RTL

L040028  SEP   #$20
         JSL   L040016
         JSL   L04003B
         REP   #$20
         RTL

L040035  SEP   #$20
         JSL   L040000
L04003B  LDAL  $E1C03D
         SEP   #$20
         LDAL  $E1C03D
         REP   #$20
         RTL

L040048  SEP   #$20
         JSL   L040016
         JSL   L04005B
         REP   #$20
         RTL

L040055  SEP   #$20
         JSL   L040000
L04005B  SEP   #$20
         STAL  $E1C03D
         REP   #$20
         RTL

L040064  PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F2
         TCS
         STZ   $F4
         BRA   L040092
L040073  LDA   $F4
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0300E8
         LDX   #^L0300E8
         JSL   L010410
         PLA
         PLX
         STA   $F6
         STX   $F8
         LDA   #$0000
         STA   [$F6]
         INC   $F4
L040092  LDA   $F4
         CMP   #$0100
         BNE   L040073
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

L0400A1  PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00E8
         TCS
         STZ   $F0
         LDA   #$FFFF
         STA   $EE
         LDA   #$01F4
         STA   $EC
         STZ   $F2
         BRA   L040106
L0400BC  LDA   $F2
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0300E8
         LDX   #^L0300E8
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   [$F4]
         CMP   #$0000
         BNE   L0400EA
         INC   $F0
         LDA   $F0
         CMP   #$0001
         BNE   L0400E8
         LDA   $F2
         STA   $EA
L0400E8  BRA   L040104
L0400EA  LDA   $F0
         BEQ   L040104
         LDA   $F0
         CMP   $EC
         BCS   L040102
         LDA   $F0
         CMP   $FF
         BCC   L040102
         LDA   $F0
         STA   $EC
         LDA   $EA
         STA   $EE
L040102  STZ   $F0
L040104  INC   $F2
L040106  LDA   $F2
         CMP   #$0100
         BNE   L0400BC
         LDA   $F0
         BEQ   L040127
         LDA   $F0
         CMP   $EC
         BCS   L040125
         LDA   $F0
         CMP   $FF
         BCC   L040125
         LDA   $F0
         STA   $EC
         LDA   $EA
         STA   $EE
L040125  STZ   $F0
L040127  LDA   $EE
         CMP   #$FFFF
         BEQ   L04015A
         STZ   $F2
         BRA   L040154
L040132  LDA   $F2
         CLC
         ADC   $EE
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0300E8
         LDX   #^L0300E8
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   #$FFFF
         STA   [$F4]
         INC   $F2
L040154  LDA   $F2
         CMP   $FF
         BNE   L040132
L04015A  LDA   $EE
         CMP   #$FFFF
         BEQ   L040168
         LDA   $FF
         XBA
         ORA   $EE
         STA   $EE
L040168  LDA   $EE
         TAY
         TSC
         CLC
         ADC   #$0010
         TCS
         TYA
         PLD
         RTL

L040174  PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00EE
         TCS
         LDA   $FF
         AND   #$FF00
         XBA
         STA   $F0
         LDA   $FF
         AND   #$00FF
         STA   $FF
         STZ   $F2
         BRA   L0401B4
L040192  LDA   $F2
         CLC
         ADC   $FF
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L0300E8
         LDX   #^L0300E8
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   #$0000
         STA   [$F4]
         INC   $F2
L0401B4  LDA   $F2
         CMP   $F0
         BNE   L040192
         TSC
         CLC
         ADC   #$000A
         TCS
         PLD
         RTL

L0401C2  PHD
         TSC
         SEC
         SBC   #$00F3
         TCD
         ADC   #$00EA
         TCS
         LDY   #$0000
         LDA   $FD
         AND   #$FF00
         TAX
L0401D6  REP   #$20
         LDA   [$F9],Y
         AND   #$00FF
         BNE   L0401E2
         LDA   #$0001
L0401E2  STA   $EC
         JSL   L040055
         JSL   L040035
         SEP   #$20
         CMP   $EC
         BNE   L0401D6
         REP   #$20
         INX
         INY
         CPY   $FF
         BNE   L0401D6
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

L040202  PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00EE
         TCS
         LDA   $FD
         CLC
         ADC   $FF
         TAX
         AND   #$FF00
         ADC   #$0200
         AND   #$FE00
         STA   $F0
L04021E  LDA   #$0000
         JSL   L040055
         JSL   L040035
         AND   #$00FF
         BNE   L04021E
         INX
         CPX   $F0
         BNE   L04021E
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

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

L040256  PHP
         SEP   #$20
         LDA   #^L02001D
         PHB
         PHA
         PLB
         REP   #$30
         LDX   #$00E0
         JSL   L040028
         LDA   L02001B
         BNE   L04026F
         BRL   L0402AB
L04026F  CMP   #$0001
         BNE   L040277
         BRL   L0402AF
L040277  DEC
         STA   L02001B
         LDA   L020025
         ORA   #$0080
         TAX
         LDA   L020023
         JSL   L040048
         LDA   L020025
         ORA   #$00A0
         TAX
         LDA   #$000F
         JSL   L040048
         LDA   L020025
         EOR   #$0001
         STA   L020025
         LDA   L020023
         INC
         STA   L020023
         PLB
         PLP
         CLC
         RTL

L0402AB  PLB
         PLP
         CLC
         RTL

L0402AF  LDA   #$0000
         STA   L02001B
         LDA   L020021
         CMP   #$0001
         BNE   L0402C2
         LDA   L020027
         BNE   L0402EB
L0402C2  LDA   L020025
         ORA   #$0080
         TAX
         LDA   L020023
         JSL   L040048
         LDA   L020025
         ORA   #$00A0
         TAX
         LDA   #$0003
         JSL   L040048
         LDA   #$FFFF
         STA   L02001D
         STZ   L020027
         PLB
         PLP
         CLC
         RTL

L0402EB  PHD
         TSC
         TAX
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         PHX
         CLC
         LDA   L02002B
         ADC   #$0002
         STA   $F6
         LDA   L02002D
         ADC   #$0000
         STA   $F8
         LDA   [$F6]
         CMP   #$FFFF
         BNE   L04031A
         LDA   L02002F
         STA   $F6
         LDA   L020031
         STA   $F8
L04031A  LDA   L020025
         ORA   #$0080
         TAX
         LDA   L020023
         JSL   L040048
         LDA   L020025
         ORA   #$00A0
         TAX
         LDA   #$000F
         JSL   L040048
         LDA   L020025
         EOR   #$0001
         STA   L020025
         LDA   [$F6]
         CMP   #$FFFF
         BEQ   L04035E
         ASL
         ASL
         TAX
         LDAL  L03006C,X
         TAX
         AND   #$00FF
         STA   L020023
         TXA
         XBA
         AND   #$00FF
         STA   L02001B
         BRA   L040361
L04035E  STZ   L020027
L040361  LDA   $F6
         STA   L02002B
         LDA   $F8
         STA   L02002D
         PLA
         TCS
         PLD
         PLB
         PLP
         CLC
         RTL

L040372  PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F2
         TCS
         JSL   L040064
         PEA   $00CF
         PEA   $00E1
         JSL   L04023B
         PLY
         PLY
         STZ   $F4
         BRA   L0403A3
L040391  PEA   $0001
         LDA   #$00A0
         CLC
         ADC   $F4
         PHA
         JSL   L04023B
         PLY
         PLY
         INC   $F4
L0403A3  LDA   $F4
         CMP   #$0020
         BNE   L040391
         STZ   L02001B
         LDA   #$FFFF
         STA   L02001D
         PEA   ^L040256
         PEA   L040256
         _SetSoundMIRQV
         BCS   L0403C5
         LDA   #$0000
L0403C5  STAL  L020010
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

L0403D1  PHD
         TSC
         SEC
         SBC   #$00F3
         TCD
         ADC   #$00EC
         TCS
         LDX   #$0000
         LDA   #$C036
         STA   $EE
         STX   $F0
         LDA   [$EE]
         AND   #$00FF
         AND   #$007F
         SEP   #$20
         STA   [$EE]
         REP   #$20
         PEI   $FF
         PEI   $FD
         PEI   $FB
         PEI   $F9
         JSL   L0401C2
         PLY
         PLY
         PLY
         PLY
         PEI   $FF
         PEI   $FD
         JSL   L040202
         PLY
         PLY
         LDX   #$0000
         LDA   #$C036
         STA   $EE
         STX   $F0
         LDA   [$EE]
         AND   #$00FF
         ORA   #$0080
         SEP   #$20
         STA   [$EE]
         REP   #$20
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L04042E  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         SEI
         PEA   $00CF
         PEA   $00E1
         JSL   L04023B
         PLY
         PLY
         PEA   $0003
         PEA   $00A0
         JSL   L04023B
         PLY
         PLY
         PEA   $0003
         PEA   $00A1
         JSL   L04023B
         PLY
         PLY
         CLI
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L040467  PHD
         TSC
         SEC
         SBC   #$00F5
         TCD
         ADC   #$00E8
         TCS
         LDA   $FF
         XBA
         AND   #$00FF
         INC
         INC
         AND   #$00FE
         STA   $EC
         PEI   $EC
         JSL   L0400A1
         PLY
         STA   $EE
         LDA   $EE
         XBA
         AND   #$FF00
         STA   $EA
         PEI   $FF
         PEI   $EA
         PEI   $FD
         PEI   $FB
         JSL   L0403D1
         PLY
         PLY
         PLY
         PLY
         LDA   $EE
         TAY
         TSC
         CLC
         ADC   #$000C
         TCS
         TYA
         PLD
         RTL

L0404AC  PHD
         TSC
         SEC
         SBC   #$00F5
         TCD
         ADC   #$00EC
         TCS
         LDA   $FD
         AND   #$00FF
         PHA
         PEA   $0000
         JSL   L04023B
         PLY
         PLY
         LDA   $FD
         AND   #$00FF
         PHA
         PEA   $0001
         JSL   L04023B
         PLY
         PLY
         LDA   $FD
         XBA
         STA   $FD
         LDA   $FD
         AND   #$00FF
         PHA
         PEA   $0020
         JSL   L04023B
         PLY
         PLY
         LDA   $FD
         AND   #$00FF
         PHA
         PEA   $0021
         JSL   L04023B
         PLY
         PLY
         PEI   $FF
         PEA   $0040
         JSL   L04023B
         PLY
         PLY
         PEI   $FF
         PEA   $0041
         JSL   L04023B
         PLY
         PLY
         LDA   $FB
         TAY
         AND   #$00FF
         STA   $EE
         TYA
         XBA
         AND   #$00FF
         DEC
         DEC
         STAL  L02001B
         PEI   $EE
         PEA   $0080
         JSL   L04023B
         PLY
         PLY
         LDA   $EE
         CLC
         ADC   #$0001
         PHA
         PEA   $0081
         JSL   L04023B
         PLY
         PLY
         PEA   $0000
         PEA   $00C0
         JSL   L04023B
         PLY
         PLY
         PEA   $0000
         PEA   $00C1
         JSL   L04023B
         PLY
         PLY
         LDA   $EE
         INC
         INC
         AND   #$00FF
         STA   $EE
         LDA   $EE
         STA   L020023
         STZ   L020025
         STZ   L02001D
         LDA   L02001B
         CMP   #$0000
         BEQ   L04058C
         BCC   L04058C
         PEA   $000F
         PEA   $00A1
         JSL   L04023B
         PLY
         PLY
         PEA   $000E
         PEA   $00A0
         JSL   L04023B
         PLY
         PLY
         BRA   L0405C2
L04058C  LDA   L02001B
         CMP   #$0000
         BNE   L0405AE
         PEA   $0003
         PEA   $00A1
         JSL   L04023B
         PLY
         PLY
         PEA   $000E
         PEA   $00A0
         JSL   L04023B
         PLY
         PLY
         BRA   L0405C2
L0405AE  LDA   L02001B
         CMP   #$FFFF
         BNE   L0405C2
         PEA   $0002
         PEA   $00A0
         JSL   L04023B
         PLY
         PLY
L0405C2  TAY
         TSC
         CLC
         ADC   #$0008
         TCS
         TYA
         PLD
         RTL

L0405CC  PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         PEA   $00C0
         LDA   L02001F
         PHA
         LDAL  L0300E4
         PHA
         JSL   L0404AC
         PLY
         PLY
         PLY
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L0405F2  ENT
         PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00F2
         TCS
         LDA   $FF
         CMP   L02001F
         BEQ   L040609
         LDA   $FF
         STA   L02001F
L040609  TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L040611  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F2
         TCS
         JSL   L040372
         STZ   L020027
         LDA   #$0002
         STA   L020021
         JSL   L04042E
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

L040635  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         JSL   L040611
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L04064C  ENT
         PHD
         TSC
         SEC
         SBC   #$00F3
         TCD
         ADC   #$00C8
         TCS
         PEA   ^L030042
         PEA   L030042
         PEA   $0000
         TDC
         CLC
         ADC   #$00CC
         PHA
         JSL   L010882
         PLY
         PLY
         PLY
         PLY
         PEI   $FB
         PEI   $F9
         PEA   $0000
         TDC
         CLC
         ADC   #$00CC
         PHA
         JSL   L0107D7
         PLY
         PLY
         PLY
         PLY
         PEA   ^L030049
         PEA   L030049
         PEA   $0000
         TDC
         CLC
         ADC   #$00CC
         PHA
         JSL   L0107D7
         PLY
         PLY
         PLY
         PLY
         PEA   $0000
         TDC
         CLC
         ADC   #$00CC
         PHA
         JSL   L160334
         PLY
         PLY
         STX   $EC
         STA   $EA
         LDX   L020131
         LDA   L02012F
         PHA
         PEI   $EC
         PEI   $EA
         JSL   L040467
         PLY
         PLY
         PLY
         STA   $CA
         LDA   $FD
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L03006C
         LDX   #^L03006C
         JSL   L010410
         PLA
         PLX
         STA   $EE
         STX   $F0
         LDA   $CA
         STA   [$EE]
         LDX   L020131
         LDA   L02012F
         PHA
         LDA   $FD
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L03006C
         LDX   #^L03006C
         JSL   L010410
         PLA
         PLX
         STA   $EE
         STX   $F0
         PLA
         LDY   #$0002
         STA   [$EE],Y
         LDA   $FD
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L03004E
         LDX   #^L03004E
         JSL   L010410
         PLA
         PLX
         STA   $EE
         STX   $F0
         LDA   $FF
         STA   [$EE]
         PEI   $EC
         PEI   $EA
         JSL   L160228
         PLY
         PLY
         TSC
         CLC
         ADC   #$002A
         TCS
         PLD
         RTL

L040732  ENT
         PHD
         TSC
         SEC
         SBC   #$00F5
         TCD
         ADC   #$00EE
         TCS
         LDA   $FF
         CMP   #$0002
         BNE   L040747
         BRL   L0407B9
L040747  LDX   $FD
         LDA   $FB
         STX   L02002D
         STA   L02002B
         STX   L020031
         STA   L02002F
         LDA   [$FB]
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L03006C
         LDX   #^L03006C
         JSL   L010410
         PLA
         PLX
         STA   $F0
         STX   $F2
         LDA   $F0
         LDX   $F2
         PHX
         PHA
         PEA   ^L0300E4
         PEA   L0300E4
         PEA   $0004
         JSL   L010693
         PLA
         PLA
         PLA
         PLA
         PLX
         LDA   $FF
         STA   L020021
         LDA   #$0001
         STA   L020027
         LDA   [$FB]
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L03004E
         LDX   #^L03004E
         JSL   L010410
         PLA
         PLX
         STA   $F0
         STX   $F2
         LDA   [$F0]
         PHA
         JSL   L0405F2
         PLY
         JSL   L0405CC
         BRA   L0407C0
L0407B9  STZ   L020027
         JSL   L04042E
L0407C0  TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

         PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00F2
         TCS
         LDA   $FF
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L03006C
         LDX   #^L03006C
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   [$F4]
         PHA
         JSL   L040174
         PLY
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

         PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00F2
         TCS
         JSL   L04042E
         LDA   $FF
         ASL
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L03006C
         LDX   #^L03006C
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   $F4
         LDX   $F6
         PHX
         PHA
         PEA   ^L0300E4
         PEA   L0300E4
         PEA   $0004
         JSL   L010693
         PLA
         PLA
         PLA
         PLA
         PLX
         STZ   L020021
         LDA   #$0001
         STA   L020027
         LDA   $FF
         ASL
         LDX   #$0000
         PHX
         PHA
         LDA   #L03004E
         LDX   #^L03004E
         JSL   L010410
         PLA
         PLX
         STA   $F4
         STX   $F6
         LDA   [$F4]
         PHA
         JSL   L0405F2
         PLY
         JSL   L0405CC
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L040871  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         LDA   L02001D
         TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

