*
* 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   L020018
         REP   #$20
         LDX   #$0000
         LDA   #$C036
         STA   $F6
         STX   $F8
         LDA   [$F6]
         AND   #$00FF
         ORA   #$0080
         SEP   #$20
         STA   [$F6]
         REP   #$20
         _TLStartUp
         BCS   L01005B
         LDA   #$0000
L01005B  STAL  L020010
         PHA
         _MMStartUp
         BCS   L01006C
         LDA   #$0000
L01006C  STAL  L020010
         PLA
         STA   L02000C
         _MTStartUp
         BCS   L010080
         LDA   #$0000
L010080  STAL  L020010
         PEA   ^L030000
         PEA   L030000
         _LoadTools
         BCS   L010096
         LDA   #$0000
L010096  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   L0100C9
         LDA   #$0000
L0100C9  STAL  L020010
         LDX   L020014
         LDA   L020012
         CLC
         ADC   #$0400
         PHA
         TXA
         ADC   #$0000
         TAX
         _SoundStartUp
         BCS   L0100E9
         LDA   #$0000
L0100E9  STAL  L020010
         LDX   L020014
         LDA   L020012
         PHA
         PEA   $0000
         PEA   $00A0
         LDA   L02000C
         PHA
         _QDStartUp
         BCS   L01010A
         LDA   #$0000
L01010A  STAL  L020010
         LDX   #$0000
         LDA   #$C034
         STA   $F6
         STX   $F8
         LDA   #$0000
         SEP   #$20
         STA   [$F6]
         REP   #$20
         PEA   ^L0103E9
         PEA   L0103E9
         _SetHeartBeat
         BCS   L010133
         LDA   #$0000
L010133  STAL  L020010
         PEA   $0000
         _SetIntUse
         BCS   L010146
         LDA   #$0000
L010146  STAL  L020010
         PEA   $000A
         PEA   ^L010430
         PEA   L010430
         _SetVector
         BCS   L01015F
         LDA   #$0000
L01015F  STAL  L020010
         LDX   #$0000
         LDA   #$0000
L010169  STAL  $E19D00,X
         INX
         INX
         CPX   #$00C8
         BNE   L010169
         PEA   $000C
         _IntSource
         BCS   L010183
         LDA   #$0000
L010183  STAL  L020010
         JSL   L04037D
         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]
         PEA   ^L0103E9
         PEA   L0103E9
         _DelHeartBeat
         BCS   L0101D7
         LDA   #$0000
L0101D7  STAL  L020010
         LDA   L020018
         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
         _SoundShutDown
         BCS   L010217
         LDA   #$0000
L010217  STAL  L020010
         _EMShutDown
         BCS   L010227
         LDA   #$0000
L010227  STAL  L020010
         _QDShutDown
         BCS   L010237
         LDA   #$0000
L010237  STAL  L020010
         _MTShutDown
         BCS   L010247
         LDA   #$0000
L010247  STAL  L020010
         LDA   L02000C
         PHA
         _MMShutDown
         BCS   L01025B
         LDA   #$0000
L01025B  STAL  L020010
         _TLShutDown
         BCS   L01026B
         LDA   #$0000
L01026B  STAL  L020010
         LDA   #$0002
         TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

L01027C  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         PEA   ^L0103E9
         PEA   L0103E9
         _DelHeartBeat
         BCS   L010299
         LDA   #$0000
L010299  STAL  L020010
         PEA   $0000
         _SetIntUse
         BCS   L0102AC
         LDA   #$0000
L0102AC  STAL  L020010
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L0102B8  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F4
         TCS
         PEA   ^L0103E9
         PEA   L0103E9
         _SetHeartBeat
         BCS   L0102D5
         LDA   #$0000
L0102D5  STAL  L020010
         PEA   $0000
         _SetIntUse
         BCS   L0102E8
         LDA   #$0000
L0102E8  STAL  L020010
         PEA   $000A
         PEA   ^L010430
         PEA   L010430
         _SetVector
         BCS   L010301
         LDA   #$0000
L010301  STAL  L020010
         PEA   $000C
         _IntSource
         BCS   L010314
         LDA   #$0000
L010314  STAL  L020010
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L010320  ENT
         LDAL  L020004
         RTL

L010325  ENT
         LDA   #$0000
         STAL  L020004
         RTL

L01032D  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00F2
         TCS
         JSL   L01027C
         PHA
         PEA   $FFFF
         PEA   $0000
         _FlushEvents
         BCS   L01034F
         LDA   #$0000
L01034F  STAL  L020010
         PLA
         STZ   $F4
L010356  JSL   L100099
         AND   #$007F
         TAY
         BEQ   L010365
         LDA   #$0001
         STA   $F4
L010365  PHA
         PEA   $FFFF
         PEA   ^L03002A
         PEA   L03002A
         _GetNextEvent
         BCS   L01037B
         LDA   #$0000
L01037B  STAL  L020010
         PLA
         TAY
         BEQ   L0103AA
         LDAL  L03002A
         CMP   #$0003
         BNE   L0103AA
         LDAL  L03002E
         TAX
         LDAL  L03002C
         AND   #$0001
         PHA
         TXA
         AND   #$0000
         TAX
         PLA
         STX   $F6
         ORA   $F6
         BEQ   L0103AA
         LDA   #$0001
         STA   $F4
L0103AA  LDA   $F4
         BEQ   L010356
         JSL   L010325
         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
         JSL   L0102B8
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

         MX    %11
	 
L0103E9  ADRL  $00000000
         DW    $0001
	 DW    $A55A
	 
	 PHP
	 LDX   #$04
	 NOP
	 LDA   #$01
	 NOP
         STAL  L0103E9,X
         LDAL  L020000
         INC
         STAL  L020000
         SEP   #$30
         LDY   #$00
         LDAL  KBDSTROBE
         BPL   L010410
         TAY
L010410  REP   #$30
         TYA
         AND   #$007F
         STAL  L0200B6
         CMP   #$0070
         BNE   L010428
L01041F  LDA   #$0001
         STAL  L020004
         BRA   L01042D
L010428  CMP   #$0050
         BEQ   L01041F
L01042D  PLP
         CLC
         RTL

         MX    %00
	 
L010430  PHP
         REP   #$30
         LDAL  L020002
         INC
         STAL  L020002
         LDX   #$C032
         LDA   #$EADF
         SEP   #$20
         STAL  $000000,X
         PLP
         CLC
         RTL

         MX    %00
	 
L01044B  ENT
         PHD
         TSC
         SEC
         SBC   #$00F7
	 TCD
	 ADC   #$00CE
	 TCS
         PEA   ^L032E33
         PEA   L032E33
         PEA   $0000
         TDC
         CLC
         ADC   #$00D4
         JSL   L011248
         PLY
         PLY
         PLY
         PLY
         PEI   $FF
         PEI   $FD
         PEA   $0000
         TDC
         CLC
         ADC   #$00D4
         JSL   L01119D
         PLY
         PLY
         PLY
         PLY
         PEA   ^L032E3A
         PEA   L032E3A
         PEA   $0000
         TDC
         CLC
         ADC   #$00D4
         JSL   L01119D
         PLY
         PLY
         PLY
         PLY
         PEA   $0000
         TDC
         CLC
         ADC   #$00D4
         JSL   L1002E2
         PLY
         PLY
         STX   $D2
         STA   $D0
         LDX   $D2
         LDA   $D0
         TAY
         TSC
         CLC
         ADC   #$0028
	 TCS
         TYA
         PLD
         RTL

L0104BA  ENT
         LDA   $F0
         CLC
         ADC   #$2000
	 TAY
	 PHD
	 PHB
	 LDA   #$0101
	 PHA
	 PLB
	 PLB
         SEP   #$20
         LDAL  STATEREG
         ORA   #$30
         STAL  STATEREG
         REP   #$20
         TYA
         TCD
         LDY   #$8888
         CLC
         LDA   #$00A0
         STA   $1FFE
         LDX   #$0002
L0104E6  LDA   #$8808
         TSB   $09
         TYA
         TSB   $0B
         LDA   #$8088
         TSB   $0D
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TSB   $06
         TYA
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         LDA   #$8088
         TSB   $10
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $05
         TSB   $07
         TSB   $09
         TSB   $0B
         TSB   $0D
         TSB   $0F
         TSB   $11
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TSB   $04
         TYA
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         LDA   #$8088
         TSB   $12
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TSB   $03
         TYA
         TSB   $05
         TSB   $07
         TSB   $09
         TSB   $0B
         TSB   $0D
         TSB   $0F
         TSB   $11
         LDA   #$8088
         TSB   $13
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $03
         TSB   $05
         TSB   $07
         TSB   $09
         TSB   $0B
         TSB   $0D
         TSB   $0F
         TSB   $11
         TSB   $13
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TSB   $02
         TYA
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         LDA   #$8088
         TSB   $14
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $02
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TSB   $14
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $02
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TSB   $14
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TSB   $01
         TYA
         TSB   $03
         TSB   $05
         TSB   $07
         TSB   $09
         TSB   $0B
         TSB   $0D
         TSB   $0F
         TSB   $11
         TSB   $13
         LDA   #$8088
         TSB   $15
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $01
         TSB   $03
         TSB   $05
         TSB   $07
         TSB   $09
         TSB   $0B
         TSB   $0D
         TSB   $0F
         TSB   $11
         TSB   $13
         TSB   $15
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $01
         TSB   $03
         TSB   $05
         TSB   $07
         TSB   $09
         TSB   $0B
         TSB   $0D
         TSB   $0F
         TSB   $11
         TSB   $13
         TSB   $15
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $01
         TSB   $03
         TSB   $05
         TSB   $07
         TSB   $09
         TSB   $0B
         TSB   $0D
         TSB   $0F
         TSB   $11
         TSB   $13
         TSB   $15
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TSB   $00
         TYA
         TSB   $02
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TSB   $14
         LDA   #$8088
         TSB   $16
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TSB   $00
         TYA
         TSB   $02
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TSB   $14
         LDA   #$8088
         TSB   $16
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TSB   $00
         TYA
         TSB   $02
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TSB   $14
         LDA   #$8088
         TSB   $16
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $00
         TSB   $02
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TSB   $14
         TSB   $16
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $00
         TSB   $02
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TSB   $14
         TSB   $16
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $00
         TSB   $02
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TSB   $14
         TSB   $16
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $00
         TSB   $02
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TSB   $14
         TSB   $16
         TDC
         ADC   $1FFE
         TCD
         TYA
         TSB   $00
         TSB   $02
         TSB   $04
         TSB   $06
         TSB   $08
         TSB   $0A
         TSB   $0C
         TSB   $0E
         TSB   $10
         TSB   $12
         TSB   $14
         TSB   $16
         TDC
         ADC   #$0F00
         TCD
         SEC
         LDA   #$FF5F
         STA   $1FFE
         DEX
         BEQ   L010785
         BRL   L0104E6
L010785  SEP   #$20
         LDAL  STATEREG
         AND   #$CF
         STAL  STATEREG
         REP   #$20
         PLB
         PLD
         RTL

L010796  ENT
         PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00EE
         TCS
         LDA   $FF
         LDX   #$0000
         STX   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDA   #L033ED8
         LDX   #^L033ED8
         JSL   L010E15
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         CLC
         ADC   $FD
         STA   $F0
         LDA   $F0
         CLC
         ADC   #$2000
         TAY
         PHD
         PHB
         LDA   #$0101
         PHA
         PLB
         PLB
         SEP   #$20
         LDAL  STATEREG
         ORA   #$30
         STAL  STATEREG
         REP   #$20
         TYA
         TCD
         LDY   #$8888
         CLC
         LDA   #$00A0
         STA   $1FFE
         LDX   #$0002
L0107F2  LDA   #$8808
         TRB   $09
         TYA
         TRB   $0B
         LDA   #$8088
         TRB   $0D
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TRB   $06
         TYA
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         LDA   #$8088
         TRB   $10
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $05
         TRB   $07
         TRB   $09
         TRB   $0B
         TRB   $0D
         TRB   $0F
         TRB   $11
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TRB   $04
         TYA
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         LDA   #$8088
         TRB   $12
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TRB   $03
         TYA
         TRB   $05
         TRB   $07
         TRB   $09
         TRB   $0B
         TRB   $0D
         TRB   $0F
         TRB   $11
         LDA   #$8088
         TRB   $13
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $03
         TRB   $05
         TRB   $07
         TRB   $09
         TRB   $0B
         TRB   $0D
         TRB   $0F
         TRB   $11
         TRB   $13
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TRB   $02
         TYA
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         LDA   #$8088
         TRB   $14
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $02
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TRB   $14
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $02
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TRB   $14
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TRB   $01
         TYA
         TRB   $03
         TRB   $05
         TRB   $07
         TRB   $09
         TRB   $0B
         TRB   $0D
         TRB   $0F
         TRB   $11
         TRB   $13
         LDA   #$8088
         TRB   $15
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $01
         TRB   $03
         TRB   $05
         TRB   $07
         TRB   $09
         TRB   $0B
         TRB   $0D
         TRB   $0F
         TRB   $11
         TRB   $13
         TRB   $15
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $01
         TRB   $03
         TRB   $05
         TRB   $07
         TRB   $09
         TRB   $0B
         TRB   $0D
         TRB   $0F
         TRB   $11
         TRB   $13
         TRB   $15
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $01
         TRB   $03
         TRB   $05
         TRB   $07
         TRB   $09
         TRB   $0B
         TRB   $0D
         TRB   $0F
         TRB   $11
         TRB   $13
         TRB   $15
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TRB   $00
         TYA
         TRB   $02
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TRB   $14
         LDA   #$8088
         TRB   $16
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TRB   $00
         TYA
         TRB   $02
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TRB   $14
         LDA   #$8088
         TRB   $16
         TDC
         ADC   $1FFE
         TCD
         LDA   #$8808
         TRB   $00
         TYA
         TRB   $02
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TRB   $14
         LDA   #$8088
         TRB   $16
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $00
         TRB   $02
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TRB   $14
         TRB   $16
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $00
         TRB   $02
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TRB   $14
         TRB   $16
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $00
         TRB   $02
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TRB   $14
         TRB   $16
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $00
         TRB   $02
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TRB   $14
         TRB   $16
         TDC
         ADC   $1FFE
         TCD
         TYA
         TRB   $00
         TRB   $02
         TRB   $04
         TRB   $06
         TRB   $08
         TRB   $0A
         TRB   $0C
         TRB   $0E
         TRB   $10
         TRB   $12
         TRB   $14
         TRB   $16
         TDC
         ADC   #$0F00
         TCD
         SEC
         LDA   #$FF5F
         STA   $1FFE
         DEX
         BEQ   L010A91
         BRL   L0107F2
L010A91  SEP   #$20
         LDAL  STATEREG
         AND   #$CF
         STAL  STATEREG
         REP   #$20
         PLB
         PLD
         TSC
         CLC
         ADC   #$0008
         TCS
         PLD
         RTL

L010AA9  ENT
         PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00EC
         TCS
         LDA   $FF
         SEC
         SBC   #$0044
         BVS   L010ABF
         EOR   #$8000
L010ABF  BMI   L010AC8
         LDA   #$0044
         STA   $FF
         BRA   L010ADC
L010AC8  LDA   $FF
         SEC
         SBC   #$008C
         BEQ   L010ADC
         BVS   L010AD5
         EOR   #$8000
L010AD5  BPL   L010ADC
         LDA   #$008C
         STA   $FF
L010ADC  LDA   $FD
         SEC
         SBC   #$000A
         BVS   L010AE7
         EOR   #$8000
L010AE7  BMI   L010AF0
         LDA   #$000A
         STA   $FD
         BRA   L010B04
L010AF0  LDA   $FD
         SEC
         SBC   #$006E
         BEQ   L010B04
         BVS   L010AFD
         EOR   #$8000
L010AFD  BPL   L010B04
         LDA   #$006E
         STA   $FD
L010B04  LDA   $FF
         LDX   #$0000
         TAY
         BPL   L010B0D
         DEX
L010B0D  STX   $F6
         ASL
         ROL   $F6
         LDX   $F6
         PHX
         PHA
         LDA   #L033ED8
         LDX   #^L033ED8
         JSL   L010E15
         PLA
         PLX
         STA   $F2
         STX   $F4
         LDA   [$F2]
         CLC
         ADC   $FD
         CLC
         ADC   #$2000
         STA   $F0
         TDC
         TAY
         LDX   $F0
         SEP   #$20
         LDAL  STATEREG
         ORA   #$30
         STAL  STATEREG
         LDA   #$16
         STAL  SHADOW
         REP   #$20
         TXA
         SEC
         SBC   #$0282
         TCD
         LDX   #$001C
         CLC
L010B53  LDA   #$0000
         TSB   $1A
         TSB   $18
         TSB   $16
         TSB   $14
         TSB   $12
         TSB   $10
         TSB   $0E
         TSB   $0C
         TSB   $0A
         TSB   $08
         TSB   $06
         TSB   $04
         TSB   $02
         TSB   $00
         TSB   $BA
         TSB   $B8
         TSB   $B6
         TSB   $B4
         TSB   $B2
         TSB   $B0
         TSB   $AE
         TSB   $AC
         TSB   $AA
         TSB   $A8
         TSB   $A6
         TSB   $A4
         TSB   $A2
         TSB   $A0
         TDC
         ADC   #$0140
         TCD
         DEX
         BNE   L010B53
         SEP   #$20
         LDAL  STATEREG
         AND   #$CF
         STAL  STATEREG
         LDA   #$1E
         STAL  SHADOW
         REP   #$20
         TYA
         TCD
         TSC
         CLC
         ADC   #$000A
         TCS
         PLD
         RTL

L010BB4  PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00F0
         TCS
         LDA   $FD
         SEC
         SBC   $FF
         BVS   L010BC9
         EOR   #$8000
L010BC9  BMI   L010BCF
         LDA   $FD
         BRA   L010BD1
L010BCF  LDA   $FF
L010BD1  TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

L010BDB  PHD
         TSC
         SEC
         SBC   #$00F7
         TCD
         ADC   #$00F0
         TCS
         LDA   $FF
         SEC
         SBC   $FD
         BVS   L010BF0
         EOR   #$8000
L010BF0  BPL   L010BF6
         LDA   $FF
         BRA   L010BF8
L010BF6  LDA   $FD
L010BF8  TAY
         TSC
         CLC
         ADC   #$0006
         TCS
         TYA
         PLD
         RTL

L010C02  ENT
         PHD
         TSC
         SEC
         SBC   #$00FB
         TCD
         ADC   #$00E0
         TCS
         LDA   L0200BA
         BNE   L010C15
         BRL   L010CF5
L010C15  LDA   L0200D6
         PHA
         LDA   L0200CE
         PHA
         JSL   L010BB4
         PLY
         PLY
         STA   $EC
         LDA   L0200D6
         CLC
         ADC   L0200DA
         PHA
         LDA   L0200CE
         CLC
         ADC   L0200D2
         PHA
         JSL   L010BDB
         PLY
         PLY
         CLC
         ADC   #$0001
         STA   $EA
         LDA   L0200D8
         SEC
         SBC   L0200DC
         PHA
         LDA   L0200D0
         SEC
         SBC   L0200D4
         PHA
         JSL   L010BB4
         PLY
         PLY
         STA   $E8
         LDA   L0200D8
         PHA
         LDA   L0200D0
         PHA
         JSL   L010BDB
         PLY
         PLY
         STA   $E6
         LDA   L020104
         BEQ   L010CAC
         LDA   L0200BC
         LSR
         PHA
         PEI   $EC
         JSL   L010BB4
         PLY
         PLY
         STA   $EC
         LDA   L0200C0
         LSR
         PHA
         PEI   $EA
         JSL   L010BDB
         PLY
         PLY
         CLC
         ADC   #$0001
         STA   $EA
         LDA   L0200BE
         PHA
         PEI   $E8
         JSL   L010BB4
         PLY
         PLY
         STA   $E8
         LDA   L0200C2
         PHA
         PEI   $E6
         JSL   L010BDB
         PLY
         PLY
         STA   $E6
L010CAC  LDA   $E6
         SEC
         SBC   $E8
         STA   $F2
         LDA   $EA
         SEC
         SBC   $EC
         STA   $F0
         LDA   $F2
         BEQ   L010CF3
         LDA   $F0
         BEQ   L010CF3
         LDA   $F0
         ASL
         PHA
         PEI   $F2
         LDA   $E8
         LDX   #$0000
         STX   $FA
         ASL
         ROL   $FA
         LDX   $FA
         PHX
         PHA
         LDA   #L033ED8
         LDX   #^L033ED8
         JSL   L010E15
         PLA
         PLX
         STA   $F6
         STX   $F8
         LDA   [$F6]
         CLC
         ADC   $EC
         PHA
         JSL   L0F0BD6
         PLY
         PLY
         PLY
L010CF3  BRA   L010D0B
L010CF5  PEA   $0100
         PEA   $0080
         PEA   $2808
         JSL   L0F0BD6
         PLY
         PLY
         PLY
         LDA   #$FFFF
         STA   L0200BA
L010D0B  LDX   L02001B
         LDA   L020019
         STX   $E4
         STA   $E2
         LDAL  L0200D4
         STA   $F2
         BEQ   L010D50
         LDAL  L0200D2
         LSR
         STA   $F0
         LDAL  L0200DE
         SEC
         SBC   #$5980
         TAY
         STA   $EE
         PHB
         LDA   #$0101
         PHA
         PLB
         PLB
L010D36  LDX   $F0
L010D38  LDA   [$E2],Y
         STA   $5980,Y
         INY
         INY
         DEX
         BNE   L010D38
         LDA   $EE
         SEC
         SBC   #$00A0
         STA   $EE
         TAY
         DEC   $F2
         BNE   L010D36
         PLB
L010D50  TSC
         CLC
         ADC   #$001A
         TCS
         PLD
         RTL

L010D58  ENT
         PHD
         TSC
         SEC
         SBC   #$00F9
         TCD
         ADC   #$00F2
         TCS
         LDA   $FF
         STA   L0200C4
         PEA   $0100
         PEA   $0064
         LDX   L02001B
         LDA   L020019
         CLC
         ADC   #$0008
         PHA
         TXA
         ADC   #$0000
         TAX
         PLA
         PHX
         PHA
         LDX   L0200B4
         LDA   L0200B2
         CLC
         ADC   #$3988
         PHA
         TXA
         ADC   #$0000
         TAX
         PLA
         PHX
         PHA
         JSL   L0F0B88
         TAY
         TSC
         CLC
         ADC   #$000C
         TCS
         TYA
         TSC
         CLC
         ADC   #$0006
         TCS
         PLD
         RTL

L010DA8  ENT
         PHD
         TSC
         SEC
         SBC   #$00F5
         TCD
         ADC   #$00CC
         TCS
         PEA   $0190
         PEA   $0001
         PEA   $4808
         PEA   $0007
         PEA   $000F
         PEI   $FF
         PEI   $FD
         JSL   L050721
         TAY
         TSC
         CLC
         ADC   #$000E
         TCS
         TYA
         PEA   $0100
         PEA   $0064
         LDX   L02001B
         LDA   L020019
         CLC
         ADC   #$0008
         PHA
         TXA
         ADC   #$0000
         TAX
         PLA
         PHX
         PHA
         LDX   L0200B4
         LDA   L0200B2
         CLC
         ADC   #$3988
         PHA
         TXA
         ADC   #$0000
         TAX
         PLA
         PHX
         PHA
         JSL   L0F0B88
         TAY
         TSC
         CLC
         ADC   #$000C
         TCS
         TYA
         STZ   L0200BA
         TSC
         CLC
         ADC   #$0028
         TCS
         PLD
         RTL

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

L010E20  ENT
         PHD
         PHA
         PEA   $0001
         TSC
         TCD
         LDA   $0A
         BEQ   L010E95
         LDX   #$0000
         BCC   L010E4B
         BIT   #$8000
         BEQ   L010E3C
         EOR   #$FFFF
         INC
         STA   $0A
         INX
L010E3C  LDA   $03
         BIT   #$8000
         BEQ   L010E4B
         EOR   #$FFFF
         INC
         STA   $03
         INX
         INX
L010E4B  LDY   #$0000
         BRA   L010E52
L010E50  ASL   $01
L010E52  ASL   $0A
         BCC   L010E50
         ROR   $0A
L010E58  LDA   $03
         CMP   $0A
         BCC   L010E69
         LDA   $03
         SEC
         SBC   $0A
         STA   $03
         TYA
         ORA   $01
         TAY
L010E69  LSR   $0A
         LSR   $01
         BCC   L010E58
         LDA   $03
         STA   $0A
         TYA
         CPX   #$0000
         BEQ   L010E91
         CPX   #$0003
         BEQ   L010E87
         EOR   #$FFFF
         INC
         CPX   #$0001
         BEQ   L010E91
L010E87  TAY
         LDA   $0A
         EOR   #$FFFF
         INC
         STA   $0A
         TYA
L010E91  PLY
         PLY
         PLD
         RTL

L010E95  PEA   $0004
         PEA   $0000
         PEA   $0000
         _SysFailMgr
L010EA5  ENT
         ORA   $04,S
         STA   $04,S
         TXA
         ORA   $06,S
         STA   $06,S
         RTL

L010EAF  ENT
         PHD
         PHX
         PHA
         PEA   $0000
         PEA   $0001
         PEA   $0000
         PEA   $0000
         TSC
         TCD
         LDA   $12
         ORA   $14
         BNE   L010ECC
         LDX   #$0000
         BRL   L010F90
L010ECC  LDX   #$0000
         BCC   L010F04
         LDA   $14
         BIT   #$8000
         BEQ   L010EEA
         EOR   #$FFFF
         STA   $14
         LDA   $12
         EOR   #$FFFF
         INC
         BNE   L010EE7
         INC   $14
L010EE7  STA   $12
         INX
L010EEA  LDA   $0B
         BIT   #$8000
         BEQ   L010F04
         EOR   #$FFFF
         STA   $0B
         LDA   $09
         EOR   #$FFFF
         INC
         BNE   L010F00
         INC   $0B
L010F00  STA   $09
         INX
         INX
L010F04  BRA   L010F0A
L010F06  ASL   $05
         ROL   $07
L010F0A  ASL   $12
         ROL   $14
         BCC   L010F06
         ROR   $14
         ROR   $12
L010F14  LDA   $0B
         CMP   $14
         BEQ   L010F1E
         BCC   L010F3D
         BRA   L010F24
L010F1E  LDA   $09
         CMP   $12
         BCC   L010F3D
L010F24  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
L010F3D  LSR   $14
         ROR   $12
         LSR   $07
         ROR   $05
         BCC   L010F14
         CPX   #$0000
         BEQ   L010F7C
         CPX   #$0003
         BEQ   L010F69
         LDA   $01
         EOR   #$FFFF
         STA   $01
         LDA   $03
         EOR   #$FFFF
         INC   $01
         BNE   L010F62
         INC
L010F62  STA   $03
         CPX   #$0001
         BEQ   L010F7C
L010F69  LDA   $09
         EOR   #$FFFF
         STA   $09
         LDA   $0B
         EOR   #$FFFF
         INC   $09
         BNE   L010F7A
         INC
L010F7A  STA   $0B
L010F7C  LDA   $09
         STA   $12
         LDA   $0B
         STA   $14
         LDA   $01
         LDX   $03
         PLY
         PLY
         PLY
         PLY
         PLY
         PLY
         PLD
         RTL

L010F90  PEA   $0004
         PEA   $0000
         PEA   $0000
         _SysFailMgr
L010FA0  ENT
         SEC
         SBC   $04,S
         STA   $04,S
         TXA
         SBC   $06,S
         STA   $06,S
         RTL

L010FAB  ENT
         PHD
         PHA
         TSC
         TCD
         LDX   #$0000
         BCC   L010FD0
         LDA   $08
         BIT   #$8000
         BEQ   L010FC2
         EOR   #$FFFF
         INC
         STA   $08
         INX
L010FC2  LDA   $01
         BIT   #$8000
         BEQ   L010FD0
         EOR   #$FFFF
         INC
         STA   $01
         DEX
L010FD0  LDA   #$0000
         BRA   L010FDE
L010FD5  LSR   $01
         BCC   L010FDC
         CLC
         ADC   $08
L010FDC  ASL   $08
L010FDE  LDY   $01
         BNE   L010FD5
         CPX   #$0000
         BEQ   L010FEB
         EOR   #$FFFF
         INC
L010FEB  STA   $08
         PLY
         PLD
         RTL

L010FF0  ENT
         PHD
         PHX
         PHA
         PEA   $0000
         PEA   $0000
         TSC
         TCD
         LDX   #$0000
         BCC   L011032
         LDA   $10
         BIT   #$8000
         BEQ   L011019
         EOR   #$FFFF
         STA   $10
         LDA   $0E
         EOR   #$FFFF
         INC
         BNE   L011016
         INC   $10
L011016  STA   $0E
         INX
L011019  LDA   $07
         BIT   #$8000
         BEQ   L011032
         EOR   #$FFFF
         STA   $07
         LDA   $05
         EOR   #$FFFF
         INC
         BNE   L01102F
         INC   $07
L01102F  STA   $05
         DEX
L011032  BRA   L01104B
L011034  LSR   $07
         ROR   $05
         BCC   L011047
         LDA   $01
         CLC
         ADC   $0E
         STA   $01
         LDA   $03
         ADC   $10
         STA   $03
L011047  ASL   $0E
         ROL   $10
L01104B  LDA   $05
         ORA   $07
         BNE   L011034
         CPX   #$0000
         BEQ   L011069
         LDA   $01
         EOR   #$FFFF
         STA   $01
         LDA   $03
         EOR   #$FFFF
         INC   $01
         BNE   L011067
         INC
L011067  STA   $03
L011069  LDA   $01
         STA   $0E
         LDA   $03
         STA   $10
         PLY
         PLY
         PLY
         PLY
         PLD
         RTL

L011077  ENT
         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   L011092
         TYA
         SBC   $03,S
         BRA   L011097
L011092  TYA
         SBC   $03,S
         REP   #$02
L011097  PHP
         LDA   $00,S
         STA   $08,S
         PLY
         PLY
         PLY
         PLY
         PLP
         RTL

L0110A2  ENT
         PHD
         TSC
         SEC
         SBC   #$00F1
         TCD
         ADC   #$00E6
         TCS
         LDX   $FB
         LDA   $F9
         STX   $EA
         STA   $E8
L0110B5  LDA   $F7
         CMP   #$0001
         BEQ   L0110E0
         BCC   L0110E0
         LDA   [$FD]
         STA   [$F9]
         LDA   $F9
         CLC
         ADC   #$0002
         STA   $F9
         BCC   L0110CE
         INC   $FB
L0110CE  LDA   $FD
         CLC
         ADC   #$0002
         STA   $FD
         BCC   L0110DA
         INC   $FF
L0110DA  DEC   $F7
         DEC   $F7
         BRA   L0110B5
L0110E0  LDA   $F7
         BEQ   L0110EC
         SEP   #$20
         LDA   [$FD]
         STA   [$F9]
         REP   #$20
L0110EC  LDX   $EA
         LDA   $E8
         STX   $FF
         STA   $FD
         TDC
         CLC
         ADC   #$00F1
         TCS
         PLD
         RTL

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

L011142  ENT
         TAY
         LDA   $04,S
         TAX
         BEQ   L01114E
         TYA
L011149  ASL
         DEX
         BNE   L011149
         TAY
L01114E  TYA
         STA   $04,S
         RTL

L011152  ENT
         PHD
         PHX
         PHA
         TSC
         TCD
         LDX   $0A
         LDA   $0C
         BEQ   L011160
         LDX   #$0021
L011160  TXY
         BEQ   L01116D
         LDA   $01
L011165  ASL
         ROL   $03
         DEX
         BNE   L011165
         STA   $01
L01116D  LDA   $01
         STA   $0A
         LDA   $03
         STA   $0C
         PLY
         PLY
         PLD
         RTL

L011179  ENT
         BCC   L01118D
         TAY
         LDA   $04,S
         TAX
         BEQ   L011199
         TYA
         BEQ   L01119A
         BPL   L011194
L011186  SEC
         ROR
         DEX
         BNE   L011186
         BRA   L01119A
L01118D  TAY
         LDA   $04,S
         TAX
         BEQ   L011199
         TYA
L011194  LSR
         DEX
         BNE   L011194
         TAY
L011199  TYA
L01119A  STA   $04,S
         RTL

L01119D  ENT
         PHD
         TSC
         SEC
         SBC   #$00F3
         TCD
         ADC   #$00E8
         TCS
         LDX   $FB
         LDA   $F9
         STX   $EC
         STA   $EA
L0111B0  LDX   $FB
         LDA   $F9
         INC   $F9
         BNE   L0111BA
         INC   $FB
L0111BA  STA   $EE
         STX   $F0
         LDA   [$EE]
         AND   #$00FF
         BEQ   L0111C7
         BRA   L0111B0
L0111C7  LDA   $F9
         BNE   L0111CD
         DEC   $FB
L0111CD  DEC   $F9
L0111CF  LDX   $FF
         LDA   $FD
         INC   $FD
         BNE   L0111D9
         INC   $FF
L0111D9  STA   $EE
         STX   $F0
         LDA   [$EE]
         PHA
         LDX   $FB
         LDA   $F9
         INC   $F9
         BNE   L0111EA
         INC   $FB
L0111EA  STA   $EE
         STX   $F0
         PLA
         SEP   #$20
         STA   [$EE]
         REP   #$20
         AND   #$00FF
         BEQ   L0111FC
         BRA   L0111CF
L0111FC  LDX   $EC
         LDA   $EA
         TAY
         TDC
         CLC
         ADC   #$00F3
         TCS
         TYA
         PLD
         RTL

L01120A  ENT
         PHB
         PLA
         XBA
         STAL  L011245
         PLA
         STAL  L011245+1
         PLA
         STAL  L01122B
         PLA
         STAL  L01122B+2
         PLA
         STAL  L011229
         JSL   GSOS
L011229  DW    $0000
L01122B  ADRL  $00000000
         BCS   L011234
         LDA   #$0000
L011234  STAL  L020010
         LDAL  L011245+1
         PHA
         PHB
         LDAL  L011245
         STA   $01,S
         RTL

L011245  HEX   000000

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

L011296  ENT
         SEP   #$10
         PHX
         REP   #$10
         DEC
         PHA
         RTL

