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

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

	 use	MAIN.E.S
	 use	MAIN.X.S
	 
*-----------------------

	use	4/Load.Macs
	use	4/Mem.Macs
	use	4/Misc.Macs
	use	4/Util.Macs
	
*-----------------------

         BRA   L010005
         NOP
         NOP
         NOP
L010005  STAL  L020010
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         SEP   #$20
         LDA   #^L02001A
         PHA
         PLB
         REP   #$20
         PHX
         PHA
         PEA   $0000	; want $1000 bytes
         PEA   $1000
         LDA   L020010
         PHA
*         PEA   $C013
	 pea   $c005	; as a direct page
         PEA   $0000
*         PEA   $1000	; at address $1000
	 pea   $0000
         _NewHandle
         BCS   L01003D
         LDA   #$0000
L01003D  STAL  L020014
         PLA
         PLX
         STX   L02000C
         STA   L02000A
         LDX   L02000C
         LDA   L02000A
         STA   $F6
         STX   $F8
         LDY   #$0002
         LDA   [$F6],Y
         TAX
         LDA   [$F6]
         STX   L020008
         STA   L020006
*         LDAL  L020006
*         CMP   #$1000
	 lda   L020014	; no error means continue
         BEQ   L010072
*         LDA   L020014
         PHA
         JSL   L0101F8
L010072  CLC
         ADC   #$1000
         TSX
         TCS
         TXA
         STAL  L020022
         LDA   #$0000
         STAL  L020024
         PHX
         PHA
         LDX   L020024
         LDA   L020022
         PHX
         PHA
         _FindHandle
         BCS   L01009A
         LDA   #$0000
L01009A  STAL  L020014
         PLA
         PLX
         STX   L020028
         STA   L020026
         SEC
         LDA   L020026
         SBC   #$0000
         BNE   L0100B7
         LDA   L020028
         SBC   #$0000
         BRA   L0100BF
L0100B7  LDA   L020028
         SBC   #$0000
         REP   #$02
L0100BF  BEQ   L0100D9
         LDX   L020028
         LDA   L020026
         PHX
         PHA
         _DisposeHandle
         BCS   L0100D5
         LDA   #$0000
L0100D5  STAL  L020014
L0100D9  PHX
         PHA
         PEA   $0000
*         PEA   $9000
	 pea   $8000
         LDA   L020010
         PHA
*         PEA   $C013
	 pea   $c003
         PEA   $0001
*         PEA   $1000 	; we want the shadowing screen only
	 pea   $2000
         _NewHandle
         BCS   L0100FA
         LDA   #$0000
L0100FA  STAL  L020014
         PLA
         PLX
         STX   L020016+2
         STA   L020016
         LDA   L020016
         CMP   #$0000
         BNE   L01011F
         LDA   L020016+2
         CMP   #$0000
         BNE   L01011F
         LDA   L020014
         PHA
         JSL   L0101F8
         PLY
L01011F  PEA   $0000
         PEA   ^L030008
         PEA   L030008
         LDA   L020010
         PHA
         JSL   L01021A
         PLY
         PLY
         PLY
         PLY
         PHX
         PHA
         PEA   ^L030075
         PEA   L030075
         PEA   $000A
         JSL   L010267
         PLA
         PLA
         PLA
         PLA
         PLX
         LDA   L020014
         CMP   #$0000
         BEQ   L010161
         LDA   L020014
         PHA
         PEA   ^L03000E
         PEA   L03000E
         JSL   L0101CF
         PLY
         PLY
         PLY
L010161  LDAL  L030075
         STAL  L020012
         LDAL  L030079
         TAX
         LDAL  L030077
         JSL   L0101B9
         STA   L02001C
         LDA   L02001C
         CMP   #$0001
         BNE   L010194
         LDA   #L030036
         LDX   #^L030036
         PHA
         TXA
         STAL  L030002
         PLA
         STAL  L030000
         BRA   L0101A5
L010194  LDA   #L030043
         LDX   #^L030043
         PHA
         TXA
         STAL  L030002
         PLA
         STAL  L030000
L0101A5  JSL   GSOS
         DW    $0029      ; Quit
         ADRL  L030000
         BRK   $00
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L0101B9  SEP   #$10
         PHX
         REP   #$10
         DEC
         PHA
         LDAL  L020006
         TAY
         LDAL  L020008
         TAX
         LDAL  L020010
         RTL

L0101CF  PHD
         TSC
         SEC
         SBC   #$00F5
         TCD
         ADC   #$00EE
         TCS
         PEI   $FF
         PEI   $FD
         PEI   $FB
         _SysFailMgr
         BCS   L0101EC
         LDA   #$0000
L0101EC  STAL  L020014
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L0101F8  PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00F2
         TCS
         PEI   $FF
         PEA   ^L03004B
         PEA   L03004B
         JSL   L0101CF
         PLY
         PLY
         PLY
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L01021A  PHD
         TSC
         TCD
         PHA
         PHA
         PHA
         PHA
         PHA
         PEI   $06
         PEI   $0A
         PEI   $08
         PEI   $0C
         _InitialLoad
         BCS   L010236
         LDA   #$0000
L010236  STAL  L020014
         PLA
         STAL  L02002A
         LDX   #$0002
         PLA
         STAL  L02002A,X
         PLA
         LDX   #$0004
         STAL  L02002A,X
         PLA
         LDX   #$0006
         STAL  L02002A,X
         PLA
         LDX   #$0008
         STAL  L02002A,X
         PLD
         LDA   #L02002A
         LDX   #^L02002A
         RTL

L010267  PHD
         TSC
         SEC
         SBC   #$00F1
         TCD
         ADC   #$00E6
         TCS
         LDX   $FB
         LDA   $F9
         STX   $EA
         STA   $E8
L01027A  LDA   $F7
         CMP   #$0001
         BEQ   L0102A5
         BCC   L0102A5
         LDA   [$FD]
         STA   [$F9]
         LDA   $F9
         CLC
         ADC   #$0002
         STA   $F9
         BCC   L010293
         INC   $FB
L010293  LDA   $FD
         CLC
         ADC   #$0002
         STA   $FD
         BCC   L01029F
         INC   $FF
L01029F  DEC   $F7
         DEC   $F7
         BRA   L01027A
L0102A5  LDA   $F7
         BEQ   L0102B1
         SEP   #$20
         LDA   [$FD]
         STA   [$F9]
         REP   #$20
L0102B1  LDX   $EA
         LDA   $E8
         STX   $FF
         STA   $FD
         TDC
         CLC
         ADC   #$00F1
         TCS
         PLD
         RTL

