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

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

	 use 	MAIN.E.S
	 use	MAIN.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
	
*-----------------------

         BRA   L010005
         NOP
         NOP
         NOP
L010005  STAL  L02000E
         TYA
         STAL  L020012
         TXA
         STAL  L020014
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         LDX   #$0000
         LDA   #$C036
         STA   $F6
         STX   $F8
         LDA   [$F6]
         AND   #$00FF
         AND   #$0080
         SEP   #$20
         STA   L02001A
         REP   #$20
         LDX   #$0000
         LDA   #$C036
         STA   $F6
         STX   $F8
         LDA   [$F6]
         AND   #$00FF
         ORA   #$0080
         SEP   #$20
         STA   [$F6]
         REP   #$20
         LDX   #$0001
         LDA   #$2000
         STA   $F6
         STX   $F8
         LDY   #$0002
         LDA   [$F6],Y
         TAX
         LDA   [$F6]
         PHA
         TXA
         STAL  L030024
         PLA
         STAL  L030022
         LDX   #$0001
         LDA   #$2004
         STA   $F6
         STX   $F8
         LDY   #$0002
         LDA   [$F6],Y
         TAX
         LDA   [$F6]
         PHA
         TXA
         STAL  L030028
         PLA
         STAL  L030026
         _TLStartUp
         BCS   L010095
         LDA   #$0000
L010095  STAL  L020010
         PHA
         _MMStartUp
         BCS   L0100A6
         LDA   #$0000
L0100A6  STAL  L020010
         PLA
         STA   L02000C
         _MTStartUp
         BCS   L0100BA
         LDA   #$0000
L0100BA  STAL  L020010
         PEA   ^L030000
         PEA   L030000
         _LoadTools
         BCS   L0100D0
         LDA   #$0000
L0100D0  STAL  L020010
         LDX   L020014
         LDA   L020012
         CLC
         ADC   #$0300
         PHA
         TXA
         ADC   #$0000
         TAX
         PEA   $0001
         PEA   $0000
         PEA   $0120
         PEA   $0000
         PEA   $00C4
         LDA   L02000C
         PHA
         _EMStartUp
         BCS   L010103
         LDA   #$0000
L010103  STAL  L020010
         LDX   L020014
         LDA   L020012
         CLC
         ADC   #$0400
         PHA
         TXA
         ADC   #$0000
         TAX
         _SoundStartUp
         BCS   L010123
         LDA   #$0000
L010123  STAL  L020010
         LDX   L020014
         LDA   L020012
         PHA
         PEA   $0000
         PEA   $00A0
         LDA   L02000C
         PHA
         _QDStartUp
         BCS   L010144
         LDA   #$0000
L010144  STAL  L020010
         LDX   #$0000
         LDA   #$C034
         STA   $F6
         STX   $F8
         LDA   #$0000
         SEP   #$20
         STA   [$F6]
         REP   #$20
         PEA   ^L010394
         PEA   L010394
         _SetHeartBeat
         BCS   L01016D
         LDA   #$0000
L01016D  STAL  L020010
         JSL   L0B09D0
         PEA   ^L010394
         PEA   L010394
         _DelHeartBeat
         BCS   L010187
         LDA   #$0000
L010187  STAL  L020010
         LDA   L02001A
         AND   #$00FF
         PHA
         LDX   #$0000
         LDA   #$C036
         STA   $F6
         STX   $F8
         LDA   [$F6]
         AND   #$00FF
         AND   #$007F
         PLX
         STX   $FA
         ORA   $FA
         PHA
         LDX   #$0000
         LDA   #$C036
         STA   $F6
         STX   $F8
         PLA
         SEP   #$20
         STA   [$F6]
         REP   #$20
         LDX   #$0001
         LDA   #$2000
         STA   $F6
         STX   $F8
         LDAL  L030024
         TAX
         LDAL  L030022
         LDY   #$0002
         PHA
         TXA
         STA   [$F6],Y
         PLA
         STA   [$F6]
         LDX   #$0001
         LDA   #$2004
         STA   $F6
         STX   $F8
         LDAL  L030028
         TAX
         LDAL  L030026
         LDY   #$0002
         PHA
         TXA
         STA   [$F6],Y
         PLA
         STA   [$F6]
         _GrafOff
         BCS   L010201
         LDA   #$0000
L010201  STAL  L020010
         _SoundShutDown
         BCS   L010211
         LDA   #$0000
L010211  STAL  L020010
         _EMShutDown
         BCS   L010221
         LDA   #$0000
L010221  STAL  L020010
         _QDShutDown
         BCS   L010231
         LDA   #$0000
L010231  STAL  L020010
         _MTShutDown
         BCS   L010241
         LDA   #$0000
L010241  STAL  L020010
         LDA   L02000C
         PHA
         _MMShutDown
         BCS   L010255
         LDA   #$0000
L010255  STAL  L020010
         _TLShutDown
         BCS   L010265
         LDA   #$0000
L010265  STAL  L020010
         LDA   L020018
         TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

L010276  ENT
         LDAL  L020004
         RTL

L01027B  ENT
         LDA   #$0000
         STAL  L020004
         RTL

L010283  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F2
         TCS
         PEA   ^L010394
         PEA   L010394
         _DelHeartBeat
         BCS   L0102A0
         LDA   #$0000
L0102A0  STAL  L020010
         PHA
         PEA   $FFFF
         PEA   $0000
         _FlushEvents
         BCS   L0102B7
         LDA   #$0000
L0102B7  STAL  L020010
         PLA
L0102BC  PHA
         PEA   $0008
         PEA   ^L03002A
         PEA   L03002A
         _GetNextEvent
         BCS   L0102D2
         LDA   #$0000
L0102D2  STAL  L020010
         PLA
         TAY
         BEQ   L0102DC
         BRA   L0102BC
L0102DC  STZ   $F4
L0102DE  LDY   #$0000
         LDAL  KBDSTROBE
         BPL   L0102FE
         AND   #$007F
         CMP   #$000D
         BEQ   L0102FE
         CMP   #$0070
         BEQ   L0102FE
         CMP   #$0050
         BEQ   L0102FE
         LDA   #$0001
         STA   $F4
L0102FE  PHA
         PEA   $FFFF
         PEA   ^L03002A
         PEA   L03002A
         _GetNextEvent
         BCS   L010314
         LDA   #$0000
L010314  STAL  L020010
         PLA
         TAY
         BEQ   L010343
         LDAL  L03002A
         CMP   #$0003
         BNE   L010343
         LDAL  L03002E
         TAX
         LDAL  L03002C
         AND   #$0001
         PHA
         TXA
         AND   #$0000
         TAX
         PLA
         STX   $F6
         ORA   $F6
         BEQ   L010343
         LDA   #$0001
         STA   $F4
L010343  LDA   $F4
         BEQ   L0102DE
         JSL   L01027B
         LDX   #$0000
         LDA   #$C034
         STA   $F6
         STX   $F8
         LDA   #$0000
         SEP   #$20
         STA   [$F6]
         REP   #$20
         LDX   #$0000
         LDA   #$C036
         STA   $F6
         STX   $F8
         LDA   [$F6]
         AND   #$00FF
         ORA   #$0080
         SEP   #$20
         STA   [$F6]
         REP   #$20
         PEA   ^L010394
         PEA   L010394
         _SetHeartBeat
         BCS   L010388
         LDA   #$0000
L010388  STAL  L020010
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

	 MX    %11
	 
L010394  ADRL  $00000000
         DW    $0001
	 DW    $A55A

	 PHP
	 LDX   #$04
	 NOP
	 LDA   #$01
	 NOP
         STAL  L010394,X
         LDAL  L020000
         INC
         STAL  L020000
         SEP   #$30
         LDY   #$00
         LDAL  KBDSTROBE
         BPL   L0103BB
         TAY
L0103BB  REP   #$30
         TYA
         AND   #$007F
         STAL  L0200A8
         CMP   #$0070
         BNE   L0103D3
L0103CA  LDA   #$0001
         STAL  L020004
         BRA   L0103D8
L0103D3  CMP   #$0050
         BEQ   L0103CA
L0103D8  PLP
         CLC
         RTL

	 MX    %00
	 
L0103DB  ENT
         PHD
         TSC
         SEC
         SBC   #$00F3
         TCD
         ADC   #$00EA
         TCS
         LDY   #$70F7
         STY   $EC
L0103EB  LDA   #$7777
         LDX   #$0011
L0103F1  STA   [$F9],Y
         STA   [$FD],Y
         INY
         INY
         DEX
         BNE   L0103F1
         CLC
         LDA   $EC
         ADC   #$00A0
         STA   $EC
         TAY
         CMP   #$7AF7
         BNE   L0103EB
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

L010410  ENT
         CLC
         ADC   $04,S
         STA   $04,S
         TXA
         ADC   $06,S
         STA   $06,S
         RTL

L01041B  ENT
         PHD
         PHA
         PEA   $0001
         TSC
         TCD
         LDA   $0A
         BEQ   L010490
         LDX   #$0000
         BCC   L010446
         BIT   #$8000
         BEQ   L010437
         EOR   #$FFFF
         INC
         STA   $0A
         INX
L010437  LDA   $03
         BIT   #$8000
         BEQ   L010446
         EOR   #$FFFF
         INC
         STA   $03
         INX
         INX
L010446  LDY   #$0000
         BRA   L01044D
L01044B  ASL   $01
L01044D  ASL   $0A
         BCC   L01044B
         ROR   $0A
L010453  LDA   $03
         CMP   $0A
         BCC   L010464
         LDA   $03
         SEC
         SBC   $0A
         STA   $03
         TYA
         ORA   $01
         TAY
L010464  LSR   $0A
         LSR   $01
         BCC   L010453
         LDA   $03
         STA   $0A
         TYA
         CPX   #$0000
         BEQ   L01048C
         CPX   #$0003
         BEQ   L010482
         EOR   #$FFFF
         INC
         CPX   #$0001
         BEQ   L01048C
L010482  TAY
         LDA   $0A
         EOR   #$FFFF
         INC
         STA   $0A
         TYA
L01048C  PLY
         PLY
         PLD
         RTL

L010490  PEA   $0004
         PEA   $0000
         PEA   $0000
         _SysFailMgr
L0104A0  ENT
         PHD
         PHX
         PHA
         PEA   $0000
         PEA   $0001
         PEA   $0000
         PEA   $0000
         TSC
         TCD
         LDA   $12
         ORA   $14
         BNE   L0104BD
         LDX   #$0000
         BRL   L010581
L0104BD  LDX   #$0000
         BCC   L0104F5
         LDA   $14
         BIT   #$8000
         BEQ   L0104DB
         EOR   #$FFFF
         STA   $14
         LDA   $12
         EOR   #$FFFF
         INC
         BNE   L0104D8
         INC   $14
L0104D8  STA   $12
         INX
L0104DB  LDA   $0B
         BIT   #$8000
         BEQ   L0104F5
         EOR   #$FFFF
         STA   $0B
         LDA   $09
         EOR   #$FFFF
         INC
         BNE   L0104F1
         INC   $0B
L0104F1  STA   $09
         INX
         INX
L0104F5  BRA   L0104FB
L0104F7  ASL   $05
         ROL   $07
L0104FB  ASL   $12
         ROL   $14
         BCC   L0104F7
         ROR   $14
         ROR   $12
L010505  LDA   $0B
         CMP   $14
         BEQ   L01050F
         BCC   L01052E
         BRA   L010515
L01050F  LDA   $09
         CMP   $12
         BCC   L01052E
L010515  LDA   $09
         SEC
         SBC   $12
         STA   $09
         LDA   $0B
         SBC   $14
         STA   $0B
         LDA   $01
         ORA   $05
         STA   $01
         LDA   $03
         ORA   $07
         STA   $03
L01052E  LSR   $14
         ROR   $12
         LSR   $07
         ROR   $05
         BCC   L010505
         CPX   #$0000
         BEQ   L01056D
         CPX   #$0003
         BEQ   L01055A
         LDA   $01
         EOR   #$FFFF
         STA   $01
         LDA   $03
         EOR   #$FFFF
         INC   $01
         BNE   L010553
         INC
L010553  STA   $03
         CPX   #$0001
         BEQ   L01056D
L01055A  LDA   $09
         EOR   #$FFFF
         STA   $09
         LDA   $0B
         EOR   #$FFFF
         INC   $09
         BNE   L01056B
         INC
L01056B  STA   $0B
L01056D  LDA   $09
         STA   $12
         LDA   $0B
         STA   $14
         LDA   $01
         LDX   $03
         PLY
         PLY
         PLY
         PLY
         PLY
         PLY
         PLD
         RTL

L010581  PEA   $0004
         PEA   $0000
         PEA   $0000
         _SysFailMgr
L010591  ENT
         SEC
         SBC   $04,S
         STA   $04,S
         TXA
         SBC   $06,S
         STA   $06,S
         RTL

L01059C  ENT
         PHD
         PHA
         TSC
         TCD
         LDX   #$0000
         BCC   L0105C1
         LDA   $08
         BIT   #$8000
         BEQ   L0105B3
         EOR   #$FFFF
         INC
         STA   $08
         INX
L0105B3  LDA   $01
         BIT   #$8000
         BEQ   L0105C1
         EOR   #$FFFF
         INC
         STA   $01
         DEX
L0105C1  LDA   #$0000
         BRA   L0105CF
L0105C6  LSR   $01
         BCC   L0105CD
         CLC
         ADC   $08
L0105CD  ASL   $08
L0105CF  LDY   $01
         BNE   L0105C6
         CPX   #$0000
         BEQ   L0105DC
         EOR   #$FFFF
         INC
L0105DC  STA   $08
         PLY
         PLD
         RTL

L0105E1  ENT
         PHD
         PHX
         PHA
         PEA   $0000
         PEA   $0000
         TSC
         TCD
         LDX   #$0000
         BCC   L010623
         LDA   $10
         BIT   #$8000
         BEQ   L01060A
         EOR   #$FFFF
         STA   $10
         LDA   $0E
         EOR   #$FFFF
         INC
         BNE   L010607
         INC   $10
L010607  STA   $0E
         INX
L01060A  LDA   $07
         BIT   #$8000
         BEQ   L010623
         EOR   #$FFFF
         STA   $07
         LDA   $05
         EOR   #$FFFF
         INC
         BNE   L010620
         INC   $07
L010620  STA   $05
         DEX
L010623  BRA   L01063C
L010625  LSR   $07
         ROR   $05
         BCC   L010638
         LDA   $01
         CLC
         ADC   $0E
         STA   $01
         LDA   $03
         ADC   $10
         STA   $03
L010638  ASL   $0E
         ROL   $10
L01063C  LDA   $05
         ORA   $07
         BNE   L010625
         CPX   #$0000
         BEQ   L01065A
         LDA   $01
         EOR   #$FFFF
         STA   $01
         LDA   $03
         EOR   #$FFFF
         INC   $01
         BNE   L010658
         INC
L010658  STA   $03
L01065A  LDA   $01
         STA   $0E
         LDA   $03
         STA   $10
         PLY
         PLY
         PLY
         PLY
         PLD
         RTL

L010668  ENT		; LOGO
         PHX
         PHA
         LDA   $08,S
         TAX
         LDA   $0A,S
         TAY
         LDA   $06,S
         STA   $0A,S
         LDA   $04,S
         STA   $08,S
         TXA
         SEC
         SBC   $01,S
         BNE   L010683
         TYA
         SBC   $03,S
         BRA   L010688
L010683  TYA
         SBC   $03,S
         REP   #$02
L010688  PHP
         LDA   $00,S
         STA   $08,S
         PLY
         PLY
         PLY
         PLY
         PLP
         RTL

L010693  ENT
         PHD
         TSC
         SEC
         SBC   #$00F1
         TCD
         ADC   #$00E6
         TCS
         LDX   $FB
         LDA   $F9
         STX   $EA
         STA   $E8
L0106A6  LDA   $F7
         CMP   #$0001
         BEQ   L0106D1
         BCC   L0106D1
         LDA   [$FD]
         STA   [$F9]
         LDA   $F9
         CLC
         ADC   #$0002
         STA   $F9
         BCC   L0106BF
         INC   $FB
L0106BF  LDA   $FD
         CLC
         ADC   #$0002
         STA   $FD
         BCC   L0106CB
         INC   $FF
L0106CB  DEC   $F7
         DEC   $F7
         BRA   L0106A6
L0106D1  LDA   $F7
         BEQ   L0106DD
         SEP   #$20
         LDA   [$FD]
         STA   [$F9]
         REP   #$20
L0106DD  LDX   $EA
         LDA   $E8
         STX   $FF
         STA   $FD
         TDC
         CLC
         ADC   #$00F1
         TCS
         PLD
         RTL

L0106ED  ENT
         TAY
         PHB
         LDA   $06,S
         PHA
         PLB
         PLB
         PHY
         PHY
         PEA   $0000
         TXA
         CMP   ($0B,S),Y
         BEQ   L01072D
         LDY   #$0000
         CMP   ($0B,S),Y
         BEQ   L01072D
         BRA   L01070A
L010707  TYA
         STA   $03,S
L01070A  LDA   $03,S
         CMP   $01,S
         BEQ   L010728
         CLC
         ADC   $01,S
         LSR
         AND   #$00FE
         CMP   $01,S
         BEQ   L010728
         TAY
         TXA
         CMP   ($0B,S),Y
         BEQ   L01072D
         BCC   L010707
         TYA
         STA   $01,S
         BRA   L01070A
L010728  LDA   $05,S
         INC
         INC
         TAY
L01072D  TYX
         PLA
         PLA
         PLA
         PLB
         RTL

L010733  ENT
         TAY
         LDA   $04,S
         TAX
         BEQ   L01073F
         TYA
L01073A  ASL
         DEX
         BNE   L01073A
         TAY
L01073F  TYA
         STA   $04,S
         RTL

L010743  ENT
         PHD
         PHX
         PHA
         TSC
         TCD
         LDX   $0A
         LDA   $0C
         BEQ   L010751
         LDX   #$0021
L010751  TXY
         BEQ   L01075E
         LDA   $01
L010756  ASL
         ROL   $03
         DEX
         BNE   L010756
         STA   $01
L01075E  LDA   $01
         STA   $0A
         LDA   $03
         STA   $0C
         PLY
         PLY
         PLD
         RTL

L01076A  ENT
         BCC   L01077E
         TAY
         LDA   $04,S
         TAX
         BEQ   L01078A
         TYA
         BEQ   L01078B
         BPL   L010785
L010777  SEC
         ROR
         DEX
         BNE   L010777
         BRA   L01078B
L01077E  TAY
         LDA   $04,S
         TAX
         BEQ   L01078A
         TYA
L010785  LSR
         DEX
         BNE   L010785
         TAY
L01078A  TYA
L01078B  STA   $04,S
         RTL

L01078E  ENT
         BCC   L0107B0
         PHD
         PHX
         PHA
         TSC
         TCD
         LDX   $0A
         LDA   $0C
         BEQ   L01079E
         LDX   #$0021
L01079E  TXY
         BEQ   L0107CB
         LDA   $03
         BPL   L0107C1
L0107A5  SEC
         ROR
         ROR   $01
         DEX
         BNE   L0107A5
         STA   $03
         BRA   L0107CB
L0107B0  PHD
         PHX
         PHA
         TSC
         TCD
         LDX   $0A
         LDA   $0C
         BEQ   L0107BE
         LDX   #$0021
L0107BE  TXY
         BEQ   L0107CB
L0107C1  LDA   $03
L0107C3  LSR
         ROR   $01
         DEX
         BNE   L0107C3
         STA   $03
L0107CB  LDA   $03
         STA   $0C
         LDA   $01
         STA   $0A
         PLY
         PLY
         PLD
         RTL

L0107D7  ENT
         PHD
         TSC
         SEC
         SBC   #$00F3
         TCD
         ADC   #$00E8
         TCS
         LDX   $FB
         LDA   $F9
         STX   $EC
         STA   $EA
L0107EA  LDX   $FB
         LDA   $F9
         INC   $F9
         BNE   L0107F4
         INC   $FB
L0107F4  STA   $EE
         STX   $F0
         LDA   [$EE]
         AND   #$00FF
         BEQ   L010801
         BRA   L0107EA
L010801  LDA   $F9
         BNE   L010807
         DEC   $FB
L010807  DEC   $F9
L010809  LDX   $FF
         LDA   $FD
         INC   $FD
         BNE   L010813
         INC   $FF
L010813  STA   $EE
         STX   $F0
         LDA   [$EE]
         PHA
         LDX   $FB
         LDA   $F9
         INC   $F9
         BNE   L010824
         INC   $FB
L010824  STA   $EE
         STX   $F0
         PLA
         SEP   #$20
         STA   [$EE]
         REP   #$20
         AND   #$00FF
         BEQ   L010836
         BRA   L010809
L010836  LDX   $EC
         LDA   $EA
         TAY
         TDC
         CLC
         ADC   #$00F3
         TCS
         TYA
         PLD
         RTL

L010844  ENT
         PHB
         PLA
         XBA
         STAL  L01087F
         PLA
         STAL  L01087F+1
         PLA
         STAL  L010865
         PLA
         STAL  L010865+2
         PLA
         STAL  L010863
         JSL   GSOS
L010863  DW    $0000
L010865  ADRL  $00000000
         BCS   L01086E
         LDA   #$0000
L01086E  STAL  L020010
         LDAL  L01087F+1
         PHA
         PHB
         LDAL  L01087F
         STA   $01,S
         RTL

L01087F  HEX   000000

L010882  ENT
         PHD
         TSC
         SEC
         SBC   #$00F3
         TCD
         ADC   #$00E8
         TCS
         LDX   $FB
         LDA   $F9
         STX   $EC
         STA   $EA
L010895  LDX   $FF
         LDA   $FD
         INC   $FD
         BNE   L01089F
         INC   $FF
L01089F  STA   $EE
         STX   $F0
         LDA   [$EE]
         PHA
         LDX   $FB
         LDA   $F9
         INC   $F9
         BNE   L0108B0
         INC   $FB
L0108B0  STA   $EE
         STX   $F0
         PLA
         SEP   #$20
         STA   [$EE]
         REP   #$20
         AND   #$00FF
         BEQ   L0108C2
         BRA   L010895
L0108C2  LDX   $EC
         LDA   $EA
         TAY
         TDC
         CLC
         ADC   #$00F3
         TCS
         TYA
         PLD
         RTL

