	org #8000

	JP     #8006
	JP     #80D7
	LD     SP,#BFFF
	LD     HL,#9000
	LD     A,#81
	LD     (HL),#FF
	INC    L
	CP     L
	JR     NZ,#800E
	LD     A,#C0
	LD     (HL),L
	INC    L
	CP     L
	JR     NZ,#8016
	LD     (HL),#FF
	INC    L
	JR     NZ,#801B
	IN     A,(#E2)
	EX     AF,AF'
	LD     A,#FE
	OUT    (#E2),A
	LD     A,(#C181)
	OUT    (#E2),A
	AND    A
	JR     Z,#8050
	LD     HL,#C000
	LD     D,#90
	LD     E,(HL)
	LD     A,(DE)
	LD     (HL),A
	INC    L
	JR     NZ,#8034
	INC    H
	JR     NZ,#8034
	IN     A,(#E2)
	LD     L,A
	LD     A,#FE
	OUT    (#E2),A
	LD     H,#C2
	LD     A,(HL)
	OUT    (#E2),A
	CP     #FF
	LD     HL,#C000
	JR     NZ,#8034
	LD     A,#FE
	OUT    (#E2),A
	LD     A,(#C182)
	OUT    (#E2),A
	LD     HL,#C036
	LD     DE,#9000
	LD     BC,#0400
	LDIR
	LD     A,#FE
	OUT    (#E2),A
	LD     A,(#C183)
	OUT    (#E2),A
	LD     HL,#C236
	LD     DE,#9200
	LD     BC,#0100
	LDIR
	EX     AF,AF'
	OUT    (#E2),A
	LD     HL,#9000
	LD     B,#FF
	LD     C,#A4
	LD     DE,#0000
	LD     A,#00
	CALL   #3D13
	LD     HL,#9000
	LD     B,#FF
	LD     C,#A4
	LD     DE,#0000
	LD     A,#01
	CALL   #3D13
	LD     A,#02
	LD     C,#F2
	CALL   #3D13
	LD     C,#80
	LD     B,#08
	LD     E,#00
	LD     HL,#5000
	CALL   #3D13
	LD     C,#80
	LD     B,#09
	LD     E,#01
	LD     HL,#4000
	CALL   #3D13
	LD     HL,#C100
	LD     DE,#0800
	LD     BC,#4005
	CALL   #3D13
	LD     HL,#83B5
	LD     DE,#C080
	LD     BC,#0011
	LDIR
	DI
	IN     A,(#E2)
	LD     C,#F3
	CALL   #3D13
	LD     SP,#BFFF
	IM     1
	DI
	IN     A,(#E2)
	EX     AF,AF'
	LD     A,#FE
	OUT    (#E2),A
	LD     A,(#C184)
	LD     (#834D),A
	EX     AF,AF'
	OUT    (#E2),A
	EI
	HALT
	DI
	LD     D,#DC
	CALL   #8171
	EI
	HALT
	DI
	IN     A,(#C9)
	XOR    #01
	AND    #01
	OUT    (#C9),A
	LD     D,#DC
	CALL   #8171
	LD     HL,#8191
	LD     DE,#9100
	LD     D,D
	LD     A,#1B
	LD     L,L
	LD     A,(HL)
	LD     (DE),A
	INC    D
	LD     (DE),A
	INC    D
	LD     (DE),A
	LD     B,B
	LD     (#9004),DE
	DEC    D
	LD     (#9002),DE
	DEC    D
	LD     (#9000),DE
	EI
	HALT
	DI
	LD     A,#02
	OUT    (#FE),A
	LD     IX,(#9000)
	CALL   #8350
	CALL   #81FE
	LD     IX,(#9004)
	CALL   #8293
	CALL   #8350
	LD     DE,(#9000)
	LD     HL,(#9002)
	LD     (#9000),HL
	LD     HL,(#9004)
	LD     (#9002),HL
	LD     (#9004),DE
	LD     A,#07
	OUT    (#FE),A
	CALL   #8350
	CALL   #8350
	EI
	HALT
	DI
	IN     A,(#C9)
	XOR    #01
	AND    #01
	OUT    (#C9),A
	CALL   #8350
	CALL   #8350
	JP     #8127
	LD     A,#50
	OUT    (#E2),A
	LD     HL,#C040
	IN     A,(#C9)
	AND    A
	JR     NZ,#8180
	LD     HL,#C180
	LD     D,D
	LD     A,#00
	LD     B,B
	OUT    (#89),A
	LD     B,#A0
	LD     E,E
	LD     (HL),D
	INC    HL
	LD     (HL),D
	INC    HL
	LD     B,B
	DJNZ   #8188
	RET
	RST    #38
	NOP
	RET    NZ
	LD     A,B
	ADD    A,B
	NOP
	NOP
	LD     D,B
	LD     E,H
	RST    #38
	NOP
	RET    NZ
	LD     A,B
	ADD    A,B
	LD     H,B
	NOP
	LD     D,B
	LD     E,H
	RST    #38
	NOP
	RET    NZ
	LD     A,B
	ADD    A,B
	RET    NZ
	NOP
	LD     D,B
	LD     E,L
	PUSH   IX
	IN     A,(#A2)
	PUSH   AF
	IN     A,(#E2)
	PUSH   AF
	IN     A,(#89)
	PUSH   AF
	LD     A,#50
	OUT    (#A2),A
	LD     BC,#4040
	IN     A,(#C9)
	AND    A
	JR     NZ,#81C6
	LD     BC,#4180
	LD     E,(IX+#05)
	LD     D,(IX+#06)
	EX     DE,HL
	ADD    HL,BC
	LD     B,(IX+#03)
	LD     C,(IX+#04)
	LD     A,(IX+#07)
	OUT    (#89),A
	LD     D,D
	LD     (HL),C
	LD     B,B
	LD     C,#89
	LD     L,L
	INC    (HL)
	LD     B,B
	INC    A
	OUT    (C),A
	DJNZ   #81DE
	LD     BC,#0009
	ADD    IX,BC
	BIT    0,(IX-#01)
	JR     Z,#81B7
	POP    AF
	OUT    (#89),A
	POP    AF
	OUT    (#E2),A
	POP    AF
	OUT    (#A2),A
	POP    IX
	RET
	NOP
	LD     A,#01
	OUT    (#FD),A
	PUSH   IX
	IN     A,(#82)
	PUSH   AF
	IN     A,(#A2)
	PUSH   AF
	IN     A,(#E2)
	PUSH   AF
	IN     A,(#89)
	PUSH   AF
	LD     A,#50
	OUT    (#A2),A
	LD     A,#FE
	OUT    (#E2),A
	LD     A,(#C182)
	LD     H,#C2
	LD     L,A
	EX     AF,AF'
	LD     A,(HL)
	OUT    (#82),A
	LD     HL,#C436
	LD     DE,(#8291)
	ADD    HL,DE
	LD     DE,#4040
	IN     A,(#C9)
	AND    #01
	JR     NZ,#8236
	LD     DE,#4180
	EX     AF,AF'
	OUT    (#E2),A
	LD     A,#DF
	OUT    (#89),A
	LD     A,#C8
	EX     AF,AF'
	LD     D,D
	LD     B,#00
	LD     L,L
	LD     A,(HL)
	LD     (DE),A
	INC    H
	INC    D
	LD     D,D
	LD     C,#40
	LD     L,L
	LD     A,(HL)
	LD     (DE),A
	DEC    H
	DEC    D
	LD     B,B
	LD     BC,#0208
	ADD    HL,BC
	BIT    7,H
	JR     NZ,#8275
	EXX
	CALL   #8350
	LD     B,#FE
	LD     C,#82
	IN     L,(C)
	OUT    (C),B
	LD     C,#E2
	OUT    (C),L
	LD     C,#82
	LD     H,#02
	LD     L,(HL)
	OUT    (C),L
	EXX
	SET    7,H
	SET    6,H
	IN     A,(#89)
	DEC    A
	OUT    (#89),A
	EX     AF,AF'
	DEC    A
	JR     NZ,#823F
	POP    AF
	OUT    (#89),A
	POP    AF
	OUT    (#E2),A
	POP    AF
	OUT    (#A2),A
	POP    AF
	OUT    (#82),A
	POP    IX
	LD     A,#00
	OUT    (#FD),A
	RET
	LD     H,H
	NOP
	PUSH   IX
	IN     A,(#A2)
	PUSH   AF
	IN     A,(#E2)
	PUSH   AF
	IN     A,(#89)
	PUSH   AF
	CALL   #830A
	CALL   #8350
	LD     A,(IX+#00)
	OUT    (#E2),A
	LD     A,(IX+#08)
	AND    #0C
	OR     #50
	OUT    (#A2),A
	LD     BC,#4040
	IN     A,(#C9)
	AND    #01
	JR     NZ,#82BE
	LD     BC,#4180
	LD     L,(IX+#05)
	LD     H,(IX+#06)
	ADD    HL,BC
	EX     DE,HL
	LD     L,(IX+#01)
	LD     H,(IX+#02)
	LD     C,(IX+#04)
	LD     A,(IX+#07)
	ADD    A,(IX+#03)
	DEC    A
	OUT    (#89),A
	LD     A,(IX+#03)
	LD     D,D
	LD     (HL),C
	LD     B,B
	LD     B,#00
	EXX
	LD     C,#89
	IN     E,(C)
	LD     B,A
	EXX
	LD     L,L
	LD     A,(HL)
	LD     (DE),A
	LD     B,B
	ADD    HL,BC
	EXX
	DEC    E
	OUT    (C),E
	DJNZ   #82E6
	EXX
	LD     BC,#0009
	ADD    IX,BC
	BIT    0,(IX-#01)
	JR     Z,#82A1
	POP    AF
	OUT    (#89),A
	POP    AF
	OUT    (#E2),A
	POP    AF
	OUT    (#A2),A
	POP    IX
	RET
	LD     A,(#8291)
	ADD    A,#04
	LD     (#8291),A
	JR     Z,#8318
	CP     #C8
	JR     NZ,#8320
	LD     A,(#830E)
	NEG
	LD     (#830E),A
	LD     A,#FE
	OUT    (#E2),A
	LD     H,#C2
	LD     A,(#834A)
	LD     L,A
	LD     L,(HL)
	LD     (IX+#00),L
	LD     (IX+#09),L
	LD     (IX+#12),L
	LD     A,L
	LD     (#834A),A
	INC    A
	RET    NZ
	LD     A,(#C181)
	LD     (IX+#00),A
	LD     (IX+#09),A
	LD     (IX+#12),A
	LD     (#834A),A
	RET
	RST    #38
	RST    #38
	NOP
	RST    #38
	NOP
	RET    NZ
	PUSH   AF
	PUSH   HL
	IN     A,(#FE)
	LD     HL,#834C
	XOR    (HL)
	AND    #80
	JP     Z,#83B2
	LD     A,(HL)
	CPL
	LD     B,A
	PUSH   DE
	PUSH   BC
	LD     HL,(#834E)
	LD     C,#FB
	LD     D,#10
	IN     A,(#E2)
	LD     E,A
	LD     A,(#834D)
	OUT    (#E2),A
	OUTI
	OUTI
	OUTI
	OUTI
	OUTI
	OUTI
	OUTI
	OUTI
	DEC    D
	JR     NZ,#8371
	LD     (#834E),HL
	LD     A,H
	AND    A
	JR     NZ,#83A8
	LD     H,#C2
	LD     A,(#834D)
	LD     L,A
	LD     A,#FE
	OUT    (#E2),A
	LD     A,(HL)
	LD     (#834D),A
	INC    A
	LD     HL,#C000
	LD     (#834E),HL
	JR     NZ,#83A8
	LD     A,(#C184)
	LD     (#834D),A
	LD     A,B
	CPL
	LD     (#834C),A
	LD     A,E
	OUT    (#E2),A
	POP    BC
	POP    DE
	POP    HL
	POP    AF
	RET
	LD     B,(HL)
	LD     C,H
	LD     B,L
	LD     E,B
	LD     E,A
	LD     SP,#4B30
	LD     E,A
	LD     C,H
	LD     C,A
	LD     B,C
	LD     B,H
	LD     C,C
	LD     C,(HL)
	LD     B,A
	RST    #38
;