Master Chess

Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Game

Program Structure

MasterChess is a complete chess engine for the Timex Sinclair 2068, loaded at address 8000h. It’s entirely self-contained with no ROM calls – all I/O is custom.

Memory Layout (8000h-B2E0h)

  • 8000h-8537h: Opening book database (~1300 bytes of pre-programmed opening moves in 6-byte records)                  
  • 8538h-87FFh: Zero-filled workspace (BSS)                
  • 8800h-8808h: Three JP entry vectors (main entry, interrupt return, display refresh)                                 
  • 8809h-88ADh: Game state variables (search state, scores, evaluation accumulators)                                   
  • 88B4h-892Bh: 10×12 mailbox board array (FFh borders, piece codes with color/moved flags)                            
  • 892Ch-89FFh: Attack tables, king/rook tracking, level parameter tables (7 bytes x 10 levels)                        
  • 8A00h-8E59h: Piece sprites, mobility tables, history/killer tables, pawn structure tables, screen text buffer, IM2 vectors
  • 8E5Ah-B07Eh: Executable code (~60 subroutines)                                                                      
  • B07Fh-B2E0h: UI string data (“Play/colour/set up?”, “You win”, “Stalemate”, etc.)                                   

Key Algorithms

  • Alpha-beta minimax search with iterative deepening, killer/history move ordering                                    
  • 10×12 mailbox board representation with FFh sentinel borders
  • Position evaluation: material, pawn structure, king safety, piece-square tables, mobility                           
  • Opening book with linked-list tree structure                                                                        
  • Cooperative multitasking via IM2 interrupts during computer thinking                                                  

Hardware I/O

  • Port FEh: Keyboard scanning + beeper/border                                                                         
  • Port FBh: Timex 2068 thermal printer
  • Font from ROM at 3C00h; custom piece sprites in RAM

Content

Appears On

Related Products

Related Articles

Related Content

Image Gallery

Master Chess

Source Code

; ===========================================================================
; MasterChess - Chess program for the Timex Sinclair 2068
; (c) 198x, Author unknown
;
; This is a Z80 machine-language chess engine. The disassembler could not
; distinguish code from data, so many sections below are DATA that has been
; incorrectly decoded as Z80 instructions. Sections are annotated to
; indicate their true purpose.
; ===========================================================================

	org 08000h

; ===========================================================================
; OPENING BOOK DATABASE (8000h-8537h)
; This is NOT executable code. It is a table of pre-programmed opening moves.
; Each entry is a 6-byte record:
;   Bytes 0-1: Pointer to next variation (or 0000 = end of line)
;   Byte  2:   Board square index (source or destination)
;   Byte  3:   Piece/move flags
;   Bytes 4-5: Link to continuation / positional evaluation
;
; The disassembler has incorrectly decoded these data bytes as Z80
; instructions. All "instructions" from 8000h through 8537h should be
; understood as opening book data records, NOT as executable code.
; ===========================================================================

l8000h:
	ld e,080h		;8000	1e 80		. .	; OPENING BOOK DATA - not executable code
	inc (hl)		;8002	34		4
	rra			;8003	1f		.
	nop			;8004	00		.
	or d			;8005	b2		.
	jr $-126		;8006	18 80		. .
	inc (hl)		;8008	34		4
	ld b,a			;8009	47		G
	nop			;800a	00		.
	add a,l			;800b	85		.
	ld (de),a		;800c	12		.
	add a,b			;800d	80		.
	inc (hl)		;800e	34		4
	inc l			;800f	2c		,
	add hl,bc		;8010	09		.
	and h			;8011	a4		.
	nop			;8012	00		.
	add a,b			;8013	80		.
	inc (hl)		;8014	34		4
	ld hl,lae00h		;8015	21 00 ae	! . .
	sub b			;8018	90		.
	add a,b			;8019	80		.
	ld b,h			;801a	44		D
	ld c,(hl)		;801b	4e		N
	nop			;801c	00		.
	add a,l			;801d	85		.
	ld b,d			;801e	42		B
	add a,b			;801f	80		.
	ld b,h			;8020	44		D
	ld a,(0da00h)		;8021	3a 00 da	: . .
	ld hl,(04480h)		;8024	2a 80 44	* . D
	jr nc,l8029h		;8027	30 00		0 .
l8029h:
	in a,(030h)		;8029	db 30		. 0
	add a,b			;802b	80		.
	ld b,h			;802c	44		D
	ld h,000h		;802d	26 00		& .
	in a,(036h)		;802f	db 36		. 6
	add a,b			;8031	80		.
	ld b,h			;8032	44		D
	inc e			;8033	1c		.
	nop			;8034	00		.
	in a,(0a8h)		;8035	db a8		. .
	add a,b			;8037	80		.
	ld b,h			;8038	44		D
	ld b,e			;8039	43		C
	nop			;803a	00		.
	in a,(0c6h)		;803b	db c6		. .
	add a,b			;803d	80		.
	ld b,h			;803e	44		D
	ld b,d			;803f	42		B
	nop			;8040	00		.
	add a,b			;8041	80		.
	inc h			;8042	24		$
	add a,b			;8043	80		.
	ld b,h			;8044	44		D
	ld b,c			;8045	41		A
	nop			;8046	00		.
	jp c,l8054h		;8047	da 54 80	. T .
	ld c,b			;804a	48		H
	ld a,000h		;804b	3e 00		> .
	add a,d			;804d	82		.
	or h			;804e	b4		.
	add a,b			;804f	80		.
	ld c,c			;8050	49		I
	ccf			;8051	3f		?
	nop			;8052	00		.
	ld a,(hl)		;8053	7e		~
l8054h:
	xor (hl)		;8054	ae		.
	add a,b			;8055	80		.
	ld c,d			;8056	4a		J
	ld d,e			;8057	53		S
	nop			;8058	00		.
	add a,d			;8059	82		.
	ld b,080h		;805a	06 80		. .
	ld c,d			;805c	4a		J
	ld d,l			;805d	55		U
	nop			;805e	00		.
	add a,h			;805f	84		.
	add a,h			;8060	84		.
	add a,b			;8061	80		.
	ld c,d			;8062	4a		J
	ld h,b			;8063	60		`
	nop			;8064	00		.
	adc a,h			;8065	8c		.
	nop			;8066	00		.
	nop			;8067	00		.
	ld c,d			;8068	4a		J
	ccf			;8069	3f		?
	nop			;806a	00		.
	rst 28h			;806b	ef		.
	ld (hl),d		;806c	72		r
	add a,b			;806d	80		.
	ld c,d			;806e	4a		J
	ld b,c			;806f	41		A
	nop			;8070	00		.
	xor 066h		;8071	ee 66		. f
	add a,b			;8073	80		.
	ld c,d			;8074	4a		J
	jr c,l8080h		;8075	38 09		8 .
	xor 060h		;8077	ee 60		. `
	add a,b			;8079	80		.
	ld c,d			;807a	4a		J
	ld d,h			;807b	54		T
	nop			;807c	00		.
	adc a,d			;807d	8a		.
sub_807eh:
	ld a,b			;807e	78		x
	add a,b			;807f	80		.
l8080h:
	ld c,d			;8080	4a		J
	ld e,(hl)		;8081	5e		^
	nop			;8082	00		.
	add a,a			;8083	87		.
	inc c			;8084	0c		.
	add a,b			;8085	80		.
	ld c,e			;8086	4b		K
	ld b,c			;8087	41		A
	nop			;8088	00		.
	sub b			;8089	90		.
	ld l,h			;808a	6c		l
	add a,b			;808b	80		.
	ld c,l			;808c	4d		M
	ld b,e			;808d	43		C
	nop			;808e	00		.
	call po,sub_807eh	;808f	e4 7e 80	. ~ .
	ld d,(hl)		;8092	56		V
	ld e,a			;8093	5f		_
	nop			;8094	00		.
	add a,l			;8095	85		.
	adc a,d			;8096	8a		.
	add a,b			;8097	80		.
	ld d,(hl)		;8098	56		V
	ld h,c			;8099	61		a
	nop			;809a	00		.
	pop hl			;809b	e1		.
	ld e,d			;809c	5a		Z
	add a,b			;809d	80		.
	ld d,(hl)		;809e	56		V
	ld h,b			;809f	60		`
	nop			;80a0	00		.
	add a,e			;80a1	83		.
	ld c,(hl)		;80a2	4e		N
	add a,b			;80a3	80		.
	ld d,(hl)		;80a4	56		V
	ld c,h			;80a5	4c		L
	nop			;80a6	00		.
	ld a,d			;80a7	7a		z
	sub (hl)		;80a8	96		.
l80a9h:
	add a,b			;80a9	80		.
	ld d,(hl)		;80aa	56		V
	ld d,a			;80ab	57		W
	nop			;80ac	00		.
	rst 18h			;80ad	df		.
	cp d			;80ae	ba		.
	add a,b			;80af	80		.
	ld d,(hl)		;80b0	56		V
	ld d,l			;80b1	55		U
	nop			;80b2	00		.
	add a,d			;80b3	82		.
	inc a			;80b4	3c		<
	add a,b			;80b5	80		.
	ld e,b			;80b6	58		X
	ld c,(hl)		;80b7	4e		N
	djnz $+129		;80b8	10 7f		. .
	ret nz			;80ba	c0		.
	add a,b			;80bb	80		.
	ld e,h			;80bc	5c		\
	ld d,d			;80bd	52		R
	nop			;80be	00		.
	add a,d			;80bf	82		.
	call z,05c80h		;80c0	cc 80 5c	. . \
	ld e,l			;80c3	5d		]
	nop			;80c4	00		.
	add a,d			;80c5	82		.
	jp nc,05c80h		;80c6	d2 80 5c	. . \
	ld e,(hl)		;80c9	5e		^
	nop			;80ca	00		.
	add a,c			;80cb	81		.
	ret c			;80cc	d8		.
	add a,b			;80cd	80		.
	ld e,h			;80ce	5c		\
	ld e,a			;80cf	5f		_
	nop			;80d0	00		.
	add a,d			;80d1	82		.
	call po,05c80h		;80d2	e4 80 5c	. . \
	ld h,b			;80d5	60		`
	nop			;80d6	00		.
; (opening book data continues...)
	add a,c			;80d7	81		.
	sbc a,080h		;80d8	de 80		. .
	ld e,h			;80da	5c		\
	ld h,c			;80db	61		a
	nop			;80dc	00		.
	add a,d			;80dd	82		.
	sbc a,h			;80de	9c		.
	add a,b			;80df	80		.
	ld e,h			;80e0	5c		\
	ld h,d			;80e1	62		b
	nop			;80e2	00		.
	add a,d			;80e3	82		.
	ld c,b			;80e4	48		H
	add a,b			;80e5	80		.
	ld e,h			;80e6	5c		\
	ld e,e			;80e7	5b		[
	nop			;80e8	00		.
	add a,c			;80e9	81		.
	nop			;80ea	00		.
	nop			;80eb	00		.
	dec d			;80ec	15		.
	rra			;80ed	1f		.
	djnz l80f0h		;80ee	10 00		. .
l80f0h:
	jp pe,01580h		;80f0	ea 80 15	. . .
	add hl,hl		;80f3	29		)
	djnz l80f6h		;80f4	10 00		. .
l80f6h:
	ret p			;80f6	f0		.
	add a,b			;80f7	80		.
	dec d			;80f8	15		.
	ld d,010h		;80f9	16 10		. .
	nop			;80fb	00		.
	or 080h			;80fc	f6 80		. .
	dec d			;80fe	15		.
	rla			;80ff	17		.
	djnz l8102h		;8100	10 00		. .
l8102h:
	call m,01580h		;8102	fc 80 15	. . .
	jr l8117h		;8105	18 10		. .
	nop			;8107	00		.
	ld (bc),a		;8108	02		.
	add a,c			;8109	81		.
	dec d			;810a	15		.
	add hl,de		;810b	19		.
	djnz l810eh		;810c	10 00		. .
l810eh:
	ex af,af'		;810e	08		.
	add a,c			;810f	81		.
	dec d			;8110	15		.
	ld a,(de)		;8111	1a		.
	djnz l8114h		;8112	10 00		. .
l8114h:
	ld c,081h		;8114	0e 81		. .
	dec d			;8116	15		.
l8117h:
	dec de			;8117	1b		.
	djnz l811ah		;8118	10 00		. .
l811ah:
	adc a,h			;811a	8c		.
	add a,c			;811b	81		.
	dec d			;811c	15		.
	inc e			;811d	1c		.
	djnz l80f0h		;811e	10 d0		. .
	inc d			;8120	14		.
	add a,c			;8121	81		.
	ld (00016h),hl		;8122	22 16 00	" . .
	nop			;8125	00		.
	jr nz,l80a9h		;8126	20 81		  .
	ld (00035h),hl		;8128	22 35 00	" 5 .
	nop			;812b	00		.
	ld h,081h		;812c	26 81		& .
	ld (00037h),hl		;812e	22 37 00	" 7 .
	nop			;8131	00		.
	inc l			;8132	2c		,
	add a,c			;8133	81		.
	ld (0002eh),hl		;8134	22 2e 00	" . .
	nop			;8137	00		.
	ld (02281h),a		;8138	32 81 22	2 . "
	ld a,(de)		;813b	1a		.
	nop			;813c	00		.
	nop			;813d	00		.
	jr c,$-125		;813e	38 81		8 .
	dec h			;8140	25		%
	ld l,000h		;8141	2e 00		. .
	nop			;8143	00		.
	ld a,081h		;8144	3e 81		> .
	dec h			;8146	25		%
	jr nc,l8149h		;8147	30 00		0 .
l8149h:
	nop			;8149	00		.
	ld b,h			;814a	44		D
	add a,c			;814b	81		.
	dec h			;814c	25		%
	ld a,(de)		;814d	1a		.
	nop			;814e	00		.
	nop			;814f	00		.
	ld c,d			;8150	4a		J
	add a,c			;8151	81		.
	dec h			;8152	25		%
	inc e			;8153	1c		.
	nop			;8154	00		.
	nop			;8155	00		.
	ld d,b			;8156	50		P
	add a,c			;8157	81		.
	dec h			;8158	25		%
	cpl			;8159	2f		/
	nop			;815a	00		.
	nop			;815b	00		.
	ld d,(hl)		;815c	56		V
	add a,c			;815d	81		.
	dec h			;815e	25		%
	dec de			;815f	1b		.
	nop			;8160	00		.
	nop			;8161	00		.
	ld e,h			;8162	5c		\
	add a,c			;8163	81		.
	dec h			;8164	25		%
	ld h,000h		;8165	26 00		& .
	nop			;8167	00		.
	ld h,d			;8168	62		b
	add a,c			;8169	81		.
	dec h			;816a	25		%
	inc h			;816b	24		$
l816ch:
	nop			;816c	00		.
	nop			;816d	00		.
	ld l,b			;816e	68		h
	add a,c			;816f	81		.
	dec hl			;8170	2b		+
	dec (hl)		;8171	35		5
	nop			;8172	00		.
	nop			;8173	00		.
	and h			;8174	a4		.
	add a,c			;8175	81		.
	dec hl			;8176	2b		+
	ccf			;8177	3f		?
	adc a,l			;8178	8d		.
	dec b			;8179	05		.
	ld l,(hl)		;817a	6e		n
	add a,c			;817b	81		.
	dec hl			;817c	2b		+
	ld hl,00000h		;817d	21 00 00	! . .
	ld a,d			;8180	7a		z
	add a,c			;8181	81		.
	dec hl			;8182	2b		+
	rla			;8183	17		.
	nop			;8184	00		.
	nop			;8185	00		.
	add a,b			;8186	80		.
	add a,c			;8187	81		.
	dec l			;8188	2d		-
	scf			;8189	37		7
	nop			;818a	00		.
	nop			;818b	00		.
	ld (hl),h		;818c	74		t
	add a,c			;818d	81		.
	ld (hl),03fh		;818e	36 3f		6 ?
	adc a,l			;8190	8d		.
	ld (de),a		;8191	12		.
	add a,(hl)		;8192	86		.
	add a,c			;8193	81		.
	jr c,$+68		;8194	38 42		8 B
	nop			;8196	00		.
	nop			;8197	00		.
	sub d			;8198	92		.
	add a,c			;8199	81		.
l819ah:
	add hl,sp		;819a	39		9
	ld b,d			;819b	42		B
	nop			;819c	00		.
	nop			;819d	00		.
	call nc,03981h		;819e	d4 81 39	. . 9
	ld c,e			;81a1	4b		K
	adc a,c			;81a2	89		.
	ld bc,l81c8h		;81a3	01 c8 81	. . .
	add hl,sp		;81a6	39		9
	ld b,h			;81a7	44		D
	adc a,h			;81a8	8c		.
	inc b			;81a9	04		.
	sbc a,b			;81aa	98		.
	add a,c			;81ab	81		.
	add hl,sp		;81ac	39		9
	ld l,000h		;81ad	2e 00		. .
	nop			;81af	00		.
	xor d			;81b0	aa		.
	add a,c			;81b1	81		.
l81b2h:
	add hl,sp		;81b2	39		9
	inc hl			;81b3	23		#
	nop			;81b4	00		.
	nop			;81b5	00		.
	or b			;81b6	b0		.
	add a,c			;81b7	81		.
	add hl,sp		;81b8	39		9
	jr l81bbh		;81b9	18 00		. .
l81bbh:
	nop			;81bb	00		.
	or (hl)			;81bc	b6		.
	add a,c			;81bd	81		.
	add hl,sp		;81be	39		9
	jr nc,l81c1h		;81bf	30 00		0 .
l81c1h:
	nop			;81c1	00		.
l81c2h:
	cp h			;81c2	bc		.
	add a,c			;81c3	81		.
	add hl,sp		;81c4	39		9
	ld b,e			;81c5	43		C
	nop			;81c6	00		.
	nop			;81c7	00		.
l81c8h:
	sbc a,(hl)		;81c8	9e		.
	add a,c			;81c9	81		.
	add hl,sp		;81ca	39		9
	ld c,l			;81cb	4d		M
	adc a,c			;81cc	89		.
	ld bc,l81c2h		;81cd	01 c2 81	. . .
	add hl,sp		;81d0	39		9
	cpl			;81d1	2f		/
	nop			;81d2	00		.
	nop			;81d3	00		.
	adc a,081h		;81d4	ce 81		. .
	add hl,sp		;81d6	39		9
	ld a,(00000h)		;81d7	3a 00 00	: . .
	sub d			;81da	92		.
	add a,c			;81db	81		.
	add hl,sp		;81dc	39		9
	jr c,l816ch		;81dd	38 8d		8 .
	dec b			;81df	05		.
	nop			;81e0	00		.
	nop			;81e1	00		.
	inc (hl)		;81e2	34		4
	rra			;81e3	1f		.
	nop			;81e4	00		.
	nop			;81e5	00		.
l81e6h:
	ret po			;81e6	e0		.
	add a,c			;81e7	81		.
	inc (hl)		;81e8	34		4
	ld b,a			;81e9	47		G
	nop			;81ea	00		.
	nop			;81eb	00		.
	sub h			;81ec	94		.
	add a,d			;81ed	82		.
	inc (hl)		;81ee	34		4
	inc l			;81ef	2c		,
	add hl,bc		;81f0	09		.
	ld bc,l81e6h		;81f1	01 e6 81	. . .
	inc (hl)		;81f4	34		4
	ld hl,00000h		;81f5	21 00 00	! . .
	jp p,04481h		;81f8	f2 81 44	. . D
	ld c,(hl)		;81fb	4e		N
	nop			;81fc	00		.
	nop			;81fd	00		.
	ret m			;81fe	f8		.
	add a,c			;81ff	81		.
; (opening book data continues...)
	ld b,h			;8200	44		D
	ld a,(00000h)		;8201	3a 00 00	: . .
	cp 081h			;8204	fe 81		. .
	ld b,h			;8206	44		D
	jr nc,l8209h		;8207	30 00		0 .
l8209h:
	nop			;8209	00		.
	inc b			;820a	04		.
	add a,d			;820b	82		.
	ld b,h			;820c	44		D
	ld h,000h		;820d	26 00		& .
	nop			;820f	00		.
	ld a,(bc)		;8210	0a		.
	add a,d			;8211	82		.
	ld b,h			;8212	44		D
	inc e			;8213	1c		.
	nop			;8214	00		.
	nop			;8215	00		.
	djnz l819ah		;8216	10 82		. .
	ld b,h			;8218	44		D
	ld b,e			;8219	43		C
	nop			;821a	00		.
	nop			;821b	00		.
	ld d,082h		;821c	16 82		. .
	ld b,h			;821e	44		D
	ld b,d			;821f	42		B
	nop			;8220	00		.
	xor 01ch		;8221	ee 1c		. .
	add a,d			;8223	82		.
	ld b,h			;8224	44		D
	ld b,c			;8225	41		A
	nop			;8226	00		.
	nop			;8227	00		.
	ld (04882h),hl		;8228	22 82 48	" . H
	ld a,000h		;822b	3e 00		> .
	nop			;822d	00		.
	jr z,l81b2h		;822e	28 82		( .
	ld c,c			;8230	49		I
	ccf			;8231	3f		?
	nop			;8232	00		.
	nop			;8233	00		.
	ld l,082h		;8234	2e 82		. .
	ld c,e			;8236	4b		K
	ld b,c			;8237	41		A
	nop			;8238	00		.
	nop			;8239	00		.
	inc (hl)		;823a	34		4
	add a,d			;823b	82		.
	ld c,l			;823c	4d		M
	ld b,e			;823d	43		C
	nop			;823e	00		.
	nop			;823f	00		.
	ld a,(05682h)		;8240	3a 82 56	: . V
	ld e,a			;8243	5f		_
	nop			;8244	00		.
	xor 040h		;8245	ee 40		. @
	add a,d			;8247	82		.
	ld d,(hl)		;8248	56		V
	ld h,c			;8249	61		a
	nop			;824a	00		.
	xor 046h		;824b	ee 46		. F
	add a,d			;824d	82		.
	ld d,(hl)		;824e	56		V
	ld h,b			;824f	60		`
	nop			;8250	00		.
	nop			;8251	00		.
	ld c,h			;8252	4c		L
	add a,d			;8253	82		.
	ld d,(hl)		;8254	56		V
	ld c,h			;8255	4c		L
	nop			;8256	00		.
	nop			;8257	00		.
	ld d,d			;8258	52		R
	add a,d			;8259	82		.
	ld d,(hl)		;825a	56		V
	ld d,a			;825b	57		W
	nop			;825c	00		.
	xor 058h		;825d	ee 58		. X
	add a,d			;825f	82		.
	ld d,(hl)		;8260	56		V
	ld d,l			;8261	55		U
	nop			;8262	00		.
	xor 05eh		;8263	ee 5e		. ^
	add a,d			;8265	82		.
	ld e,b			;8266	58		X
	ld c,(hl)		;8267	4e		N
	djnz l826ah		;8268	10 00		. .
l826ah:
	ld h,h			;826a	64		d
	add a,d			;826b	82		.
	ld e,h			;826c	5c		\
	ld d,d			;826d	52		R
	nop			;826e	00		.
	nop			;826f	00		.
	ld l,d			;8270	6a		j
	add a,d			;8271	82		.
	ld e,h			;8272	5c		\
	ld e,l			;8273	5d		]
	nop			;8274	00		.
	nop			;8275	00		.
	ld (hl),b		;8276	70		p
	add a,d			;8277	82		.
	ld e,h			;8278	5c		\
	ld e,(hl)		;8279	5e		^
	nop			;827a	00		.
	nop			;827b	00		.
	halt			;827c	76		v
	add a,d			;827d	82		.
	ld e,h			;827e	5c		\
	ld e,a			;827f	5f		_
	nop			;8280	00		.
	nop			;8281	00		.
	ld a,h			;8282	7c		|
	add a,d			;8283	82		.
	ld e,h			;8284	5c		\
	ld h,b			;8285	60		`
	nop			;8286	00		.
	nop			;8287	00		.
	add a,d			;8288	82		.
	add a,d			;8289	82		.
	ld e,h			;828a	5c		\
	ld h,c			;828b	61		a
	nop			;828c	00		.
	nop			;828d	00		.
	adc a,b			;828e	88		.
	add a,d			;828f	82		.
	ld e,h			;8290	5c		\
	ld h,d			;8291	62		b
	nop			;8292	00		.
	nop			;8293	00		.
	adc a,(hl)		;8294	8e		.
	add a,d			;8295	82		.
	ld e,h			;8296	5c		\
	ld e,e			;8297	5b		[
	nop			;8298	00		.
	nop			;8299	00		.
	sub h			;829a	94		.
	add a,d			;829b	82		.
	ld e,b			;829c	58		X
	ld c,(hl)		;829d	4e		N
	djnz l82a0h		;829e	10 00		. .
l82a0h:
	sbc a,d			;82a0	9a		.
	add a,d			;82a1	82		.
	ld e,h			;82a2	5c		\
	ld d,d			;82a3	52		R
	nop			;82a4	00		.
	nop			;82a5	00		.
	and b			;82a6	a0		.
	add a,d			;82a7	82		.
	ld e,h			;82a8	5c		\
	ld e,l			;82a9	5d		]
	nop			;82aa	00		.
	nop			;82ab	00		.
	and (hl)		;82ac	a6		.
	add a,d			;82ad	82		.
	ld e,h			;82ae	5c		\
	ld e,(hl)		;82af	5e		^
	nop			;82b0	00		.
	nop			;82b1	00		.
	xor h			;82b2	ac		.
	add a,d			;82b3	82		.
	ld e,h			;82b4	5c		\
	ld e,a			;82b5	5f		_
	nop			;82b6	00		.
	nop			;82b7	00		.
	or d			;82b8	b2		.
	add a,d			;82b9	82		.
	ld e,h			;82ba	5c		\
	ld h,b			;82bb	60		`
	nop			;82bc	00		.
	nop			;82bd	00		.
	cp b			;82be	b8		.
	add a,d			;82bf	82		.
	ld e,h			;82c0	5c		\
	ld h,c			;82c1	61		a
	nop			;82c2	00		.
	nop			;82c3	00		.
	cp (hl)			;82c4	be		.
	add a,d			;82c5	82		.
	ld e,h			;82c6	5c		\
	ld h,d			;82c7	62		b
	nop			;82c8	00		.
	nop			;82c9	00		.
	call nz,05c82h		;82ca	c4 82 5c	. . \
	ld e,e			;82cd	5b		[
	nop			;82ce	00		.
	nop			;82cf	00		.
	jp z,05c82h		;82d0	ca 82 5c	. . \
	ld e,e			;82d3	5b		[
	nop			;82d4	00		.
	nop			;82d5	00		.
	ret nc			;82d6	d0		.
	add a,d			;82d7	82		.
	dec d			;82d8	15		.
	ld a,(de)		;82d9	1a		.
	djnz l82dch		;82da	10 00		. .
l82dch:
	sub 082h		;82dc	d6 82		. .
	dec d			;82de	15		.
	dec de			;82df	1b		.
	djnz l82e2h		;82e0	10 00		. .
l82e2h:
	call c,01582h		;82e2	dc 82 15	. . .
	inc e			;82e5	1c		.
	djnz l82e8h		;82e6	10 00		. .
l82e8h:
	jp po,02282h		;82e8	e2 82 22	. . "
	ld d,000h		;82eb	16 00		. .
	nop			;82ed	00		.
	ret pe			;82ee	e8		.
	add a,d			;82ef	82		.
	ld (00035h),hl		;82f0	22 35 00	" 5 .
	nop			;82f3	00		.
	xor 082h		;82f4	ee 82		. .
	ld (00037h),hl		;82f6	22 37 00	" 7 .
	nop			;82f9	00		.
	call p,02282h		;82fa	f4 82 22	. . "
	ld l,000h		;82fd	2e 00		. .
	nop			;82ff	00		.
; (opening book data continues...)
	jp m,02282h		;8300	fa 82 22	. . "
	ld a,(de)		;8303	1a		.
	nop			;8304	00		.
	nop			;8305	00		.
	nop			;8306	00		.
	add a,e			;8307	83		.
	dec h			;8308	25		%
	ld l,000h		;8309	2e 00		. .
	xor 006h		;830b	ee 06		. .
	add a,e			;830d	83		.
	dec h			;830e	25		%
	jr nc,l8311h		;830f	30 00		0 .
l8311h:
	xor 00ch		;8311	ee 0c		. .
	add a,e			;8313	83		.
	dec h			;8314	25		%
	ld a,(de)		;8315	1a		.
	nop			;8316	00		.
	xor 012h		;8317	ee 12		. .
	add a,e			;8319	83		.
	dec h			;831a	25		%
	inc e			;831b	1c		.
	nop			;831c	00		.
	xor 018h		;831d	ee 18		. .
	add a,e			;831f	83		.
	dec h			;8320	25		%
	cpl			;8321	2f		/
	nop			;8322	00		.
	nop			;8323	00		.
	ld e,083h		;8324	1e 83		. .
	dec h			;8326	25		%
	dec de			;8327	1b		.
	nop			;8328	00		.
	nop			;8329	00		.
	inc h			;832a	24		$
	add a,e			;832b	83		.
	dec h			;832c	25		%
	ld h,000h		;832d	26 00		& .
	xor 02ah		;832f	ee 2a		. *
	add a,e			;8331	83		.
	dec h			;8332	25		%
	inc h			;8333	24		$
	nop			;8334	00		.
	xor 030h		;8335	ee 30		. 0
	add a,e			;8337	83		.
	dec hl			;8338	2b		+
	dec (hl)		;8339	35		5
	nop			;833a	00		.
	nop			;833b	00		.
l833ch:
	ld (hl),083h		;833c	36 83		6 .
	dec hl			;833e	2b		+
	ccf			;833f	3f		?
	nop			;8340	00		.
	nop			;8341	00		.
	ld e,d			;8342	5a		Z
	add a,e			;8343	83		.
	dec hl			;8344	2b		+
	ld c,c			;8345	49		I
	adc a,c			;8346	89		.
	ld bc,l833ch		;8347	01 3c 83	. < .
	dec hl			;834a	2b		+
	ld hl,00000h		;834b	21 00 00	! . .
	ld c,b			;834e	48		H
	add a,e			;834f	83		.
	dec hl			;8350	2b		+
	rla			;8351	17		.
	nop			;8352	00		.
	nop			;8353	00		.
	ld c,(hl)		;8354	4e		N
	add a,e			;8355	83		.
	dec l			;8356	2d		-
	scf			;8357	37		7
	nop			;8358	00		.
	nop			;8359	00		.
	ld d,h			;835a	54		T
	add a,e			;835b	83		.
	jr c,l83a0h		;835c	38 42		8 B
	nop			;835e	00		.
	nop			;835f	00		.
	ld b,d			;8360	42		B
	add a,e			;8361	83		.
	jr c,l83a7h		;8362	38 43		8 C
	adc a,h			;8364	8c		.
	inc b			;8365	04		.
	nop			;8366	00		.
	nop			;8367	00		.
	inc (hl)		;8368	34		4
	rra			;8369	1f		.
	nop			;836a	00		.
	nop			;836b	00		.
l836ch:
	ld h,(hl)		;836c	66		f
	add a,e			;836d	83		.
	inc (hl)		;836e	34		4
	ld b,a			;836f	47		G
	nop			;8370	00		.
	nop			;8371	00		.
	ld h,084h		;8372	26 84		& .
	inc (hl)		;8374	34		4
	inc l			;8375	2c		,
	add hl,bc		;8376	09		.
	ld bc,l836ch		;8377	01 6c 83	. l .
	inc (hl)		;837a	34		4
	ld hl,00000h		;837b	21 00 00	! . .
	ld a,b			;837e	78		x
	add a,e			;837f	83		.
	ld c,b			;8380	48		H
	ld a,000h		;8381	3e 00		> .
	nop			;8383	00		.
	ld a,(hl)		;8384	7e		~
	add a,e			;8385	83		.
	ld c,c			;8386	49		I
	ccf			;8387	3f		?
	nop			;8388	00		.
	nop			;8389	00		.
	add a,h			;838a	84		.
	add a,e			;838b	83		.
	ld c,d			;838c	4a		J
	ld d,e			;838d	53		S
	nop			;838e	00		.
	nop			;838f	00		.
	adc a,d			;8390	8a		.
	add a,e			;8391	83		.
	ld c,d			;8392	4a		J
	ld d,l			;8393	55		U
	nop			;8394	00		.
	nop			;8395	00		.
	sub b			;8396	90		.
	add a,e			;8397	83		.
	ld c,d			;8398	4a		J
	ld h,b			;8399	60		`
	nop			;839a	00		.
	nop			;839b	00		.
	sub (hl)		;839c	96		.
	add a,e			;839d	83		.
	ld c,d			;839e	4a		J
	ccf			;839f	3f		?
l83a0h:
	nop			;83a0	00		.
	nop			;83a1	00		.
	sbc a,h			;83a2	9c		.
	add a,e			;83a3	83		.
	ld c,d			;83a4	4a		J
	ld b,c			;83a5	41		A
	nop			;83a6	00		.
l83a7h:
	nop			;83a7	00		.
	and d			;83a8	a2		.
	add a,e			;83a9	83		.
	ld c,d			;83aa	4a		J
	jr c,l83adh		;83ab	38 00		8 .
l83adh:
	nop			;83ad	00		.
	xor b			;83ae	a8		.
	add a,e			;83af	83		.
	ld c,d			;83b0	4a		J
	cpl			;83b1	2f		/
	nop			;83b2	00		.
	nop			;83b3	00		.
	xor (hl)		;83b4	ae		.
	add a,e			;83b5	83		.
	ld c,d			;83b6	4a		J
	ld h,000h		;83b7	26 00		& .
	nop			;83b9	00		.
	or h			;83ba	b4		.
	add a,e			;83bb	83		.
	ld c,d			;83bc	4a		J
	ld d,h			;83bd	54		T
	nop			;83be	00		.
	nop			;83bf	00		.
	cp d			;83c0	ba		.
	add a,e			;83c1	83		.
	ld c,d			;83c2	4a		J
	ld e,(hl)		;83c3	5e		^
	nop			;83c4	00		.
	nop			;83c5	00		.
	ret nz			;83c6	c0		.
	add a,e			;83c7	83		.
	ld c,e			;83c8	4b		K
	ld b,c			;83c9	41		A
	nop			;83ca	00		.
	nop			;83cb	00		.
	add a,083h		;83cc	c6 83		. .
	ld c,h			;83ce	4c		L
	ld d,l			;83cf	55		U
	nop			;83d0	00		.
	nop			;83d1	00		.
	call z,04c83h		;83d2	cc 83 4c	. . L
	ld d,a			;83d5	57		W
	nop			;83d6	00		.
	nop			;83d7	00		.
	jp nc,04c83h		;83d8	d2 83 4c	. . L
	ld b,c			;83db	41		A
	nop			;83dc	00		.
	nop			;83dd	00		.
	ld (hl),d		;83de	72		r
	add a,e			;83df	83		.
	ld c,h			;83e0	4c		L
	ld b,e			;83e1	43		C
	add hl,bc		;83e2	09		.
	inc e			;83e3	1c		.
	ret c			;83e4	d8		.
	add a,e			;83e5	83		.
	ld c,h			;83e6	4c		L
	ld d,(hl)		;83e7	56		V
	nop			;83e8	00		.
	nop			;83e9	00		.
	call po,04c83h		;83ea	e4 83 4c	. . L
	ld b,d			;83ed	42		B
	nop			;83ee	00		.
	nop			;83ef	00		.
	jp pe,05883h		;83f0	ea 83 58	. . X
	ld c,(hl)		;83f3	4e		N
	djnz l83f6h		;83f4	10 00		. .
l83f6h:
	ret p			;83f6	f0		.
	add a,e			;83f7	83		.
	ld e,b			;83f8	58		X
	ld b,h			;83f9	44		D
	djnz l83fch		;83fa	10 00		. .
l83fch:
	or 083h			;83fc	f6 83		. .
	ld e,h			;83fe	5c		\
	ld d,d			;83ff	52		R
l8400h:
; (opening book data continues...)
	nop			;8400	00		.
	nop			;8401	00		.
	call m,05c83h		;8402	fc 83 5c	. . \
	ld e,l			;8405	5d		]
	nop			;8406	00		.
	nop			;8407	00		.
	ld (bc),a		;8408	02		.
	add a,h			;8409	84		.
	ld e,h			;840a	5c		\
	ld e,(hl)		;840b	5e		^
	nop			;840c	00		.
	nop			;840d	00		.
	ex af,af'		;840e	08		.
	add a,h			;840f	84		.
	ld e,h			;8410	5c		\
	ld e,a			;8411	5f		_
	nop			;8412	00		.
	nop			;8413	00		.
	ld c,084h		;8414	0e 84		. .
	ld e,h			;8416	5c		\
	ld h,b			;8417	60		`
	nop			;8418	00		.
	nop			;8419	00		.
	inc d			;841a	14		.
	add a,h			;841b	84		.
	ld e,h			;841c	5c		\
	ld h,c			;841d	61		a
	nop			;841e	00		.
	nop			;841f	00		.
	ld a,(de)		;8420	1a		.
	add a,h			;8421	84		.
	ld e,h			;8422	5c		\
	ld h,d			;8423	62		b
	nop			;8424	00		.
	nop			;8425	00		.
	jr nz,$-122		;8426	20 84		  .
	ld e,h			;8428	5c		\
	ld e,e			;8429	5b		[
	nop			;842a	00		.
	nop			;842b	00		.
	dec d			;842c	15		.
	dec de			;842d	1b		.
	djnz l8430h		;842e	10 00		. .
l8430h:
	ld (hl),084h		;8430	36 84		6 .
	dec d			;8432	15		.
	inc e			;8433	1c		.
	djnz l8436h		;8434	10 00		. .
l8436h:
	inc a			;8436	3c		<
	add a,h			;8437	84		.
	ld (00016h),hl		;8438	22 16 00	" . .
	nop			;843b	00		.
	ld b,d			;843c	42		B
	add a,h			;843d	84		.
	ld (00035h),hl		;843e	22 35 00	" 5 .
	nop			;8441	00		.
	ld c,b			;8442	48		H
	add a,h			;8443	84		.
	ld (00037h),hl		;8444	22 37 00	" 7 .
	nop			;8447	00		.
	ld c,(hl)		;8448	4e		N
	add a,h			;8449	84		.
	ld (0002eh),hl		;844a	22 2e 00	" . .
	nop			;844d	00		.
	ld d,h			;844e	54		T
	add a,h			;844f	84		.
	ld (0001ah),hl		;8450	22 1a 00	" . .
	nop			;8453	00		.
	ld e,d			;8454	5a		Z
	add a,h			;8455	84		.
	dec hl			;8456	2b		+
	dec (hl)		;8457	35		5
	nop			;8458	00		.
	nop			;8459	00		.
	ld h,b			;845a	60		`
	add a,h			;845b	84		.
	dec hl			;845c	2b		+
	ccf			;845d	3f		?
	nop			;845e	00		.
	nop			;845f	00		.
	ld h,(hl)		;8460	66		f
	add a,h			;8461	84		.
	dec hl			;8462	2b		+
	ld c,c			;8463	49		I
	adc a,c			;8464	89		.
	nop			;8465	00		.
	ld l,h			;8466	6c		l
	add a,h			;8467	84		.
	dec hl			;8468	2b		+
	ld hl,00000h		;8469	21 00 00	! . .
	ld (hl),d		;846c	72		r
	add a,h			;846d	84		.
	dec hl			;846e	2b		+
	rla			;846f	17		.
	nop			;8470	00		.
	nop			;8471	00		.
	ld a,b			;8472	78		x
	add a,h			;8473	84		.
	dec l			;8474	2d		-
	scf			;8475	37		7
	nop			;8476	00		.
	nop			;8477	00		.
	ld a,(hl)		;8478	7e		~
	add a,h			;8479	84		.
	cpl			;847a	2f		/
	ld a,(00000h)		;847b	3a 00 00	: . .
	add a,h			;847e	84		.
	add a,h			;847f	84		.
	cpl			;8480	2f		/
	inc h			;8481	24		$
	nop			;8482	00		.
	nop			;8483	00		.
	adc a,d			;8484	8a		.
	add a,h			;8485	84		.
	cpl			;8486	2f		/
	ld h,000h		;8487	26 00		& .
	nop			;8489	00		.
	sub b			;848a	90		.
	add a,h			;848b	84		.
	cpl			;848c	2f		/
	dec h			;848d	25		%
	nop			;848e	00		.
	ld a,e			;848f	7b		{
	sub (hl)		;8490	96		.
	add a,h			;8491	84		.
	cpl			;8492	2f		/
	jr nc,l8495h		;8493	30 00		0 .
l8495h:
	nop			;8495	00		.
	sbc a,h			;8496	9c		.
	add a,h			;8497	84		.
	cpl			;8498	2f		/
	ld l,000h		;8499	2e 00		. .
	nop			;849b	00		.
	and d			;849c	a2		.
	add a,h			;849d	84		.
	jr c,l84e2h		;849e	38 42		8 B
	nop			;84a0	00		.
l84a1h:
	nop			;84a1	00		.
	xor b			;84a2	a8		.
	add a,h			;84a3	84		.
	add hl,sp		;84a4	39		9
	ld b,d			;84a5	42		B
	nop			;84a6	00		.
	nop			;84a7	00		.
	xor (hl)		;84a8	ae		.
	add a,h			;84a9	84		.
	add hl,sp		;84aa	39		9
	ld c,e			;84ab	4b		K
	adc a,c			;84ac	89		.
	nop			;84ad	00		.
	or h			;84ae	b4		.
	add a,h			;84af	84		.
	add hl,sp		;84b0	39		9
	ld b,h			;84b1	44		D
	adc a,h			;84b2	8c		.
	nop			;84b3	00		.
	cp d			;84b4	ba		.
	add a,h			;84b5	84		.
	add hl,sp		;84b6	39		9
	ld l,000h		;84b7	2e 00		. .
	nop			;84b9	00		.
	ret nz			;84ba	c0		.
	add a,h			;84bb	84		.
	add hl,sp		;84bc	39		9
	inc hl			;84bd	23		#
	nop			;84be	00		.
	nop			;84bf	00		.
	add a,084h		;84c0	c6 84		. .
	add hl,sp		;84c2	39		9
	jr l84c5h		;84c3	18 00		. .
l84c5h:
	nop			;84c5	00		.
	call z,03984h		;84c6	cc 84 39	. . 9
	jr nc,l84cbh		;84c9	30 00		0 .
l84cbh:
	nop			;84cb	00		.
	jp nc,03984h		;84cc	d2 84 39	. . 9
	ld b,e			;84cf	43		C
	nop			;84d0	00		.
	nop			;84d1	00		.
	ret c			;84d2	d8		.
	add a,h			;84d3	84		.
	add hl,sp		;84d4	39		9
	ld c,l			;84d5	4d		M
	adc a,c			;84d6	89		.
	nop			;84d7	00		.
	nop			;84d8	00		.
	nop			;84d9	00		.
	add hl,sp		;84da	39		9
	ld a,(00000h)		;84db	3a 00 00	: . .
	call po,03984h		;84de	e4 84 39	. . 9
	dec de			;84e1	1b		.
l84e2h:
	nop			;84e2	00		.
	nop			;84e3	00		.
	nop			;84e4	00		.
	nop			;84e5	00		.
	add hl,sp		;84e6	39		9
	ld a,(00000h)		;84e7	3a 00 00	: . .
	ret p			;84ea	f0		.
	add a,h			;84eb	84		.
	ld d,d			;84ec	52		R
	ld b,b			;84ed	40		@
	nop			;84ee	00		.
	nop			;84ef	00		.
	nop			;84f0	00		.
	nop			;84f1	00		.
	ld d,d			;84f2	52		R
	scf			;84f3	37		7
	nop			;84f4	00		.
	nop			;84f5	00		.
	nop			;84f6	00		.
	nop			;84f7	00		.
	ld d,d			;84f8	52		R
	scf			;84f9	37		7
	nop			;84fa	00		.
	nop			;84fb	00		.
	ld (bc),a		;84fc	02		.
	add a,l			;84fd	85		.
	ld d,d			;84fe	52		R
	ld c,c			;84ff	49		I
; (opening book data continues...)
	nop			;8500	00		.
	nop			;8501	00		.
	ex af,af'		;8502	08		.
	add a,l			;8503	85		.
	ld d,d			;8504	52		R
	ld b,b			;8505	40		@
	nop			;8506	00		.
	nop			;8507	00		.
	nop			;8508	00		.
	nop			;8509	00		.
	ld d,d			;850a	52		R
	scf			;850b	37		7
	nop			;850c	00		.
	nop			;850d	00		.
	inc d			;850e	14		.
	add a,l			;850f	85		.
	scf			;8510	37		7
	ld b,c			;8511	41		A
	nop			;8512	00		.
	nop			;8513	00		.
	ld a,(de)		;8514	1a		.
	add a,l			;8515	85		.
	scf			;8516	37		7
	ld c,e			;8517	4b		K
	nop			;8518	00		.
	nop			;8519	00		.
	jr nz,l84a1h		;851a	20 85		  .
	scf			;851c	37		7
	ld d,l			;851d	55		U
	add a,c			;851e	81		.
	nop			;851f	00		.
	ld h,085h		;8520	26 85		& .
	scf			;8522	37		7
	dec l			;8523	2d		-
	nop			;8524	00		.
	nop			;8525	00		.
	inc l			;8526	2c		,
	add a,l			;8527	85		.
	scf			;8528	37		7
	inc hl			;8529	23		#
	nop			;852a	00		.
	nop			;852b	00		.
	ld (03785h),a		;852c	32 85 37	2 . 7
	jr c,l8531h		;852f	38 00		8 .
l8531h:
	nop			;8531	00		.
	nop			;8532	00		.
	nop			;8533	00		.
	scf			;8534	37		7
	add hl,sp		;8535	39		9
	adc a,e			;8536	8b		.
	nop			;8537	00		.
; ===========================================================================
; END OF OPENING BOOK DATABASE
; ===========================================================================
; ===========================================================================
; WORKSPACE / BSS AREA (8538h-87FFh)
; This region is zero-initialized workspace memory used at runtime.
; The NOP instructions below are simply 00h fill bytes, not executable code.
; The chess engine uses this area for temporary storage during search,
; move generation, and evaluation.
; ===========================================================================
	nop			;8538	00		.	; Zero-filled workspace - not executable code
	nop			;8539	00		.
	nop			;853a	00		.
	nop			;853b	00		.
	nop			;853c	00		.
	nop			;853d	00		.
	nop			;853e	00		.
	nop			;853f	00		.
	nop			;8540	00		.
	nop			;8541	00		.
	nop			;8542	00		.
	nop			;8543	00		.
	nop			;8544	00		.
	nop			;8545	00		.
	nop			;8546	00		.
	nop			;8547	00		.
	nop			;8548	00		.
	nop			;8549	00		.
	nop			;854a	00		.
	nop			;854b	00		.
	nop			;854c	00		.
	nop			;854d	00		.
	nop			;854e	00		.
	nop			;854f	00		.
	nop			;8550	00		.
	nop			;8551	00		.
	nop			;8552	00		.
	nop			;8553	00		.
	nop			;8554	00		.
	nop			;8555	00		.
	nop			;8556	00		.
	nop			;8557	00		.
	nop			;8558	00		.
	nop			;8559	00		.
	nop			;855a	00		.
	nop			;855b	00		.
	nop			;855c	00		.
	nop			;855d	00		.
	nop			;855e	00		.
	nop			;855f	00		.
	nop			;8560	00		.
	nop			;8561	00		.
	nop			;8562	00		.
	nop			;8563	00		.
	nop			;8564	00		.
	nop			;8565	00		.
	nop			;8566	00		.
	nop			;8567	00		.
	nop			;8568	00		.
	nop			;8569	00		.
	nop			;856a	00		.
	nop			;856b	00		.
	nop			;856c	00		.
	nop			;856d	00		.
	nop			;856e	00		.
	nop			;856f	00		.
	nop			;8570	00		.
	nop			;8571	00		.
	nop			;8572	00		.
	nop			;8573	00		.
	nop			;8574	00		.
	nop			;8575	00		.
	nop			;8576	00		.
	nop			;8577	00		.
	nop			;8578	00		.
	nop			;8579	00		.
	nop			;857a	00		.
	nop			;857b	00		.
	nop			;857c	00		.
	nop			;857d	00		.
	nop			;857e	00		.
	nop			;857f	00		.
	nop			;8580	00		.
	nop			;8581	00		.
	nop			;8582	00		.
	nop			;8583	00		.
	nop			;8584	00		.
	nop			;8585	00		.
	nop			;8586	00		.
	nop			;8587	00		.
	nop			;8588	00		.
	nop			;8589	00		.
	nop			;858a	00		.
	nop			;858b	00		.
	nop			;858c	00		.
	nop			;858d	00		.
	nop			;858e	00		.
	nop			;858f	00		.
	nop			;8590	00		.
	nop			;8591	00		.
	nop			;8592	00		.
	nop			;8593	00		.
	nop			;8594	00		.
	nop			;8595	00		.
	nop			;8596	00		.
	nop			;8597	00		.
	nop			;8598	00		.
	nop			;8599	00		.
	nop			;859a	00		.
	nop			;859b	00		.
	nop			;859c	00		.
	nop			;859d	00		.
	nop			;859e	00		.
	nop			;859f	00		.
	nop			;85a0	00		.
	nop			;85a1	00		.
	nop			;85a2	00		.
	nop			;85a3	00		.
	nop			;85a4	00		.
	nop			;85a5	00		.
	nop			;85a6	00		.
	nop			;85a7	00		.
	nop			;85a8	00		.
	nop			;85a9	00		.
	nop			;85aa	00		.
	nop			;85ab	00		.
	nop			;85ac	00		.
	nop			;85ad	00		.
	nop			;85ae	00		.
	nop			;85af	00		.
	nop			;85b0	00		.
	nop			;85b1	00		.
	nop			;85b2	00		.
	nop			;85b3	00		.
	nop			;85b4	00		.
	nop			;85b5	00		.
	nop			;85b6	00		.
	nop			;85b7	00		.
	nop			;85b8	00		.
	nop			;85b9	00		.
	nop			;85ba	00		.
	nop			;85bb	00		.
	nop			;85bc	00		.
	nop			;85bd	00		.
	nop			;85be	00		.
	nop			;85bf	00		.
	nop			;85c0	00		.
	nop			;85c1	00		.
	nop			;85c2	00		.
	nop			;85c3	00		.
	nop			;85c4	00		.
	nop			;85c5	00		.
	nop			;85c6	00		.
	nop			;85c7	00		.
	nop			;85c8	00		.
	nop			;85c9	00		.
	nop			;85ca	00		.
	nop			;85cb	00		.
	nop			;85cc	00		.
	nop			;85cd	00		.
	nop			;85ce	00		.
	nop			;85cf	00		.
	nop			;85d0	00		.
	nop			;85d1	00		.
	nop			;85d2	00		.
	nop			;85d3	00		.
	nop			;85d4	00		.
	nop			;85d5	00		.
	nop			;85d6	00		.
	nop			;85d7	00		.
	nop			;85d8	00		.
	nop			;85d9	00		.
	nop			;85da	00		.
	nop			;85db	00		.
	nop			;85dc	00		.
	nop			;85dd	00		.
	nop			;85de	00		.
	nop			;85df	00		.
	nop			;85e0	00		.
	nop			;85e1	00		.
	nop			;85e2	00		.
	nop			;85e3	00		.
	nop			;85e4	00		.
	nop			;85e5	00		.
	nop			;85e6	00		.
	nop			;85e7	00		.
	nop			;85e8	00		.
	nop			;85e9	00		.
	nop			;85ea	00		.
	nop			;85eb	00		.
	nop			;85ec	00		.
	nop			;85ed	00		.
	nop			;85ee	00		.
	nop			;85ef	00		.
	nop			;85f0	00		.
	nop			;85f1	00		.
	nop			;85f2	00		.
	nop			;85f3	00		.
	nop			;85f4	00		.
	nop			;85f5	00		.
	nop			;85f6	00		.
	nop			;85f7	00		.
	nop			;85f8	00		.
	nop			;85f9	00		.
	nop			;85fa	00		.
	nop			;85fb	00		.
	nop			;85fc	00		.
	nop			;85fd	00		.
	nop			;85fe	00		.
	nop			;85ff	00		.
	nop			;8600	00		.
	nop			;8601	00		.
	nop			;8602	00		.
	nop			;8603	00		.
	nop			;8604	00		.
	nop			;8605	00		.
	nop			;8606	00		.
	nop			;8607	00		.
	nop			;8608	00		.
	nop			;8609	00		.
	nop			;860a	00		.
	nop			;860b	00		.
	nop			;860c	00		.
	nop			;860d	00		.
	nop			;860e	00		.
	nop			;860f	00		.
	nop			;8610	00		.
	nop			;8611	00		.
	nop			;8612	00		.
	nop			;8613	00		.
	nop			;8614	00		.
	nop			;8615	00		.
	nop			;8616	00		.
	nop			;8617	00		.
	nop			;8618	00		.
	nop			;8619	00		.
	nop			;861a	00		.
	nop			;861b	00		.
	nop			;861c	00		.
	nop			;861d	00		.
	nop			;861e	00		.
	nop			;861f	00		.
	nop			;8620	00		.
	nop			;8621	00		.
	nop			;8622	00		.
	nop			;8623	00		.
	nop			;8624	00		.
	nop			;8625	00		.
	nop			;8626	00		.
	nop			;8627	00		.
	nop			;8628	00		.
	nop			;8629	00		.
	nop			;862a	00		.
	nop			;862b	00		.
	nop			;862c	00		.
	nop			;862d	00		.
	nop			;862e	00		.
	nop			;862f	00		.
	nop			;8630	00		.
	nop			;8631	00		.
	nop			;8632	00		.
	nop			;8633	00		.
	nop			;8634	00		.
	nop			;8635	00		.
	nop			;8636	00		.
	nop			;8637	00		.
	nop			;8638	00		.
	nop			;8639	00		.
	nop			;863a	00		.
	nop			;863b	00		.
	nop			;863c	00		.
	nop			;863d	00		.
	nop			;863e	00		.
	nop			;863f	00		.
	nop			;8640	00		.
	nop			;8641	00		.
	nop			;8642	00		.
	nop			;8643	00		.
	nop			;8644	00		.
	nop			;8645	00		.
	nop			;8646	00		.
	nop			;8647	00		.
	nop			;8648	00		.
	nop			;8649	00		.
	nop			;864a	00		.
	nop			;864b	00		.
	nop			;864c	00		.
	nop			;864d	00		.
	nop			;864e	00		.
	nop			;864f	00		.
	nop			;8650	00		.
	nop			;8651	00		.
	nop			;8652	00		.
	nop			;8653	00		.
	nop			;8654	00		.
	nop			;8655	00		.
	nop			;8656	00		.
	nop			;8657	00		.
	nop			;8658	00		.
	nop			;8659	00		.
	nop			;865a	00		.
	nop			;865b	00		.
	nop			;865c	00		.
	nop			;865d	00		.
	nop			;865e	00		.
	nop			;865f	00		.
	nop			;8660	00		.
	nop			;8661	00		.
	nop			;8662	00		.
	nop			;8663	00		.
	nop			;8664	00		.
	nop			;8665	00		.
	nop			;8666	00		.
	nop			;8667	00		.
	nop			;8668	00		.
	nop			;8669	00		.
	nop			;866a	00		.
	nop			;866b	00		.
	nop			;866c	00		.
	nop			;866d	00		.
	nop			;866e	00		.
	nop			;866f	00		.
	nop			;8670	00		.
	nop			;8671	00		.
	nop			;8672	00		.
	nop			;8673	00		.
	nop			;8674	00		.
	nop			;8675	00		.
	nop			;8676	00		.
	nop			;8677	00		.
	nop			;8678	00		.
	nop			;8679	00		.
	nop			;867a	00		.
	nop			;867b	00		.
	nop			;867c	00		.
	nop			;867d	00		.
	nop			;867e	00		.
	nop			;867f	00		.
	nop			;8680	00		.
	nop			;8681	00		.
	nop			;8682	00		.
	nop			;8683	00		.
	nop			;8684	00		.
	nop			;8685	00		.
	nop			;8686	00		.
	nop			;8687	00		.
	nop			;8688	00		.
	nop			;8689	00		.
	nop			;868a	00		.
	nop			;868b	00		.
	nop			;868c	00		.
	nop			;868d	00		.
	nop			;868e	00		.
	nop			;868f	00		.
	nop			;8690	00		.
	nop			;8691	00		.
	nop			;8692	00		.
	nop			;8693	00		.
	nop			;8694	00		.
	nop			;8695	00		.
	nop			;8696	00		.
	nop			;8697	00		.
	nop			;8698	00		.
	nop			;8699	00		.
	nop			;869a	00		.
	nop			;869b	00		.
	nop			;869c	00		.
	nop			;869d	00		.
	nop			;869e	00		.
	nop			;869f	00		.
	nop			;86a0	00		.
	nop			;86a1	00		.
	nop			;86a2	00		.
	nop			;86a3	00		.
	nop			;86a4	00		.
	nop			;86a5	00		.
	nop			;86a6	00		.
	nop			;86a7	00		.
	nop			;86a8	00		.
	nop			;86a9	00		.
	nop			;86aa	00		.
	nop			;86ab	00		.
	nop			;86ac	00		.
	nop			;86ad	00		.
	nop			;86ae	00		.
	nop			;86af	00		.
	nop			;86b0	00		.
	nop			;86b1	00		.
	nop			;86b2	00		.
	nop			;86b3	00		.
	nop			;86b4	00		.
	nop			;86b5	00		.
	nop			;86b6	00		.
	nop			;86b7	00		.
	nop			;86b8	00		.
	nop			;86b9	00		.
	nop			;86ba	00		.
	nop			;86bb	00		.
	nop			;86bc	00		.
	nop			;86bd	00		.
	nop			;86be	00		.
	nop			;86bf	00		.
	nop			;86c0	00		.
	nop			;86c1	00		.
	nop			;86c2	00		.
	nop			;86c3	00		.
	nop			;86c4	00		.
	nop			;86c5	00		.
	nop			;86c6	00		.
	nop			;86c7	00		.
	nop			;86c8	00		.
	nop			;86c9	00		.
	nop			;86ca	00		.
	nop			;86cb	00		.
	nop			;86cc	00		.
	nop			;86cd	00		.
	nop			;86ce	00		.
	nop			;86cf	00		.
	nop			;86d0	00		.
	nop			;86d1	00		.
	nop			;86d2	00		.
	nop			;86d3	00		.
	nop			;86d4	00		.
	nop			;86d5	00		.
	nop			;86d6	00		.
	nop			;86d7	00		.
	nop			;86d8	00		.
	nop			;86d9	00		.
	nop			;86da	00		.
	nop			;86db	00		.
	nop			;86dc	00		.
	nop			;86dd	00		.
	nop			;86de	00		.
	nop			;86df	00		.
	nop			;86e0	00		.
	nop			;86e1	00		.
	nop			;86e2	00		.
	nop			;86e3	00		.
	nop			;86e4	00		.
	nop			;86e5	00		.
	nop			;86e6	00		.
	nop			;86e7	00		.
	nop			;86e8	00		.
	nop			;86e9	00		.
	nop			;86ea	00		.
	nop			;86eb	00		.
	nop			;86ec	00		.
	nop			;86ed	00		.
	nop			;86ee	00		.
	nop			;86ef	00		.
	nop			;86f0	00		.
	nop			;86f1	00		.
	nop			;86f2	00		.
	nop			;86f3	00		.
	nop			;86f4	00		.
	nop			;86f5	00		.
	nop			;86f6	00		.
	nop			;86f7	00		.
	nop			;86f8	00		.
	nop			;86f9	00		.
	nop			;86fa	00		.
	nop			;86fb	00		.
	nop			;86fc	00		.
	nop			;86fd	00		.
	nop			;86fe	00		.
	nop			;86ff	00		.
	nop			;8700	00		.
	nop			;8701	00		.
	nop			;8702	00		.
	nop			;8703	00		.
	nop			;8704	00		.
	nop			;8705	00		.
	nop			;8706	00		.
	nop			;8707	00		.
	nop			;8708	00		.
	nop			;8709	00		.
	nop			;870a	00		.
	nop			;870b	00		.
	nop			;870c	00		.
	nop			;870d	00		.
	nop			;870e	00		.
	nop			;870f	00		.
	nop			;8710	00		.
	nop			;8711	00		.
	nop			;8712	00		.
	nop			;8713	00		.
	nop			;8714	00		.
	nop			;8715	00		.
	nop			;8716	00		.
	nop			;8717	00		.
	nop			;8718	00		.
	nop			;8719	00		.
	nop			;871a	00		.
	nop			;871b	00		.
	nop			;871c	00		.
	nop			;871d	00		.
	nop			;871e	00		.
	nop			;871f	00		.
	nop			;8720	00		.
	nop			;8721	00		.
	nop			;8722	00		.
	nop			;8723	00		.
	nop			;8724	00		.
	nop			;8725	00		.
	nop			;8726	00		.
	nop			;8727	00		.
	nop			;8728	00		.
	nop			;8729	00		.
	nop			;872a	00		.
	nop			;872b	00		.
	nop			;872c	00		.
	nop			;872d	00		.
	nop			;872e	00		.
	nop			;872f	00		.
	nop			;8730	00		.
	nop			;8731	00		.
	nop			;8732	00		.
	nop			;8733	00		.
	nop			;8734	00		.
	nop			;8735	00		.
	nop			;8736	00		.
	nop			;8737	00		.
	nop			;8738	00		.
	nop			;8739	00		.
	nop			;873a	00		.
	nop			;873b	00		.
	nop			;873c	00		.
	nop			;873d	00		.
	nop			;873e	00		.
	nop			;873f	00		.
	nop			;8740	00		.
	nop			;8741	00		.
	nop			;8742	00		.
	nop			;8743	00		.
	nop			;8744	00		.
	nop			;8745	00		.
	nop			;8746	00		.
	nop			;8747	00		.
	nop			;8748	00		.
	nop			;8749	00		.
	nop			;874a	00		.
	nop			;874b	00		.
	nop			;874c	00		.
	nop			;874d	00		.
	nop			;874e	00		.
	nop			;874f	00		.
	nop			;8750	00		.
	nop			;8751	00		.
	nop			;8752	00		.
	nop			;8753	00		.
	nop			;8754	00		.
	nop			;8755	00		.
	nop			;8756	00		.
	nop			;8757	00		.
	nop			;8758	00		.
	nop			;8759	00		.
	nop			;875a	00		.
	nop			;875b	00		.
	nop			;875c	00		.
	nop			;875d	00		.
	nop			;875e	00		.
	nop			;875f	00		.
	nop			;8760	00		.
	nop			;8761	00		.
	nop			;8762	00		.
	nop			;8763	00		.
	nop			;8764	00		.
	nop			;8765	00		.
	nop			;8766	00		.
	nop			;8767	00		.
	nop			;8768	00		.
	nop			;8769	00		.
	nop			;876a	00		.
	nop			;876b	00		.
	nop			;876c	00		.
	nop			;876d	00		.
	nop			;876e	00		.
	nop			;876f	00		.
	nop			;8770	00		.
	nop			;8771	00		.
	nop			;8772	00		.
	nop			;8773	00		.
	nop			;8774	00		.
	nop			;8775	00		.
	nop			;8776	00		.
	nop			;8777	00		.
	nop			;8778	00		.
	nop			;8779	00		.
	nop			;877a	00		.
	nop			;877b	00		.
	nop			;877c	00		.
	nop			;877d	00		.
	nop			;877e	00		.
	nop			;877f	00		.
	nop			;8780	00		.
	nop			;8781	00		.
	nop			;8782	00		.
	nop			;8783	00		.
	nop			;8784	00		.
	nop			;8785	00		.
	nop			;8786	00		.
	nop			;8787	00		.
	nop			;8788	00		.
	nop			;8789	00		.
	nop			;878a	00		.
	nop			;878b	00		.
	nop			;878c	00		.
	nop			;878d	00		.
	nop			;878e	00		.
	nop			;878f	00		.
	nop			;8790	00		.
	nop			;8791	00		.
	nop			;8792	00		.
	nop			;8793	00		.
	nop			;8794	00		.
	nop			;8795	00		.
	nop			;8796	00		.
	nop			;8797	00		.
	nop			;8798	00		.
	nop			;8799	00		.
l879ah:
	nop			;879a	00		.
	nop			;879b	00		.
	nop			;879c	00		.
	nop			;879d	00		.
	nop			;879e	00		.
	nop			;879f	00		.
	nop			;87a0	00		.
	nop			;87a1	00		.
	nop			;87a2	00		.
	nop			;87a3	00		.
	nop			;87a4	00		.
	nop			;87a5	00		.
l87a6h:
	nop			;87a6	00		.
	nop			;87a7	00		.
	nop			;87a8	00		.
	nop			;87a9	00		.
	nop			;87aa	00		.
	nop			;87ab	00		.
	nop			;87ac	00		.
	nop			;87ad	00		.
	nop			;87ae	00		.
	nop			;87af	00		.
	nop			;87b0	00		.
	nop			;87b1	00		.
	nop			;87b2	00		.
	nop			;87b3	00		.
	nop			;87b4	00		.
	nop			;87b5	00		.
	nop			;87b6	00		.
	nop			;87b7	00		.
	nop			;87b8	00		.
	nop			;87b9	00		.
	nop			;87ba	00		.
	nop			;87bb	00		.
	nop			;87bc	00		.
	nop			;87bd	00		.
	nop			;87be	00		.
	nop			;87bf	00		.
	nop			;87c0	00		.
	nop			;87c1	00		.
	nop			;87c2	00		.
	nop			;87c3	00		.
	nop			;87c4	00		.
	nop			;87c5	00		.
	nop			;87c6	00		.
	nop			;87c7	00		.
	nop			;87c8	00		.
	nop			;87c9	00		.
	nop			;87ca	00		.
	nop			;87cb	00		.
	nop			;87cc	00		.
	nop			;87cd	00		.
	nop			;87ce	00		.
	nop			;87cf	00		.
	nop			;87d0	00		.
	nop			;87d1	00		.
	nop			;87d2	00		.
	nop			;87d3	00		.
	nop			;87d4	00		.
	nop			;87d5	00		.
	nop			;87d6	00		.
	nop			;87d7	00		.
	nop			;87d8	00		.
	nop			;87d9	00		.
	nop			;87da	00		.
	nop			;87db	00		.
	nop			;87dc	00		.
	nop			;87dd	00		.
	nop			;87de	00		.
	nop			;87df	00		.
	nop			;87e0	00		.
	nop			;87e1	00		.
	nop			;87e2	00		.
	nop			;87e3	00		.
	nop			;87e4	00		.
	nop			;87e5	00		.
	nop			;87e6	00		.
	nop			;87e7	00		.
	nop			;87e8	00		.
	nop			;87e9	00		.
	nop			;87ea	00		.
	nop			;87eb	00		.
	nop			;87ec	00		.
	nop			;87ed	00		.
	nop			;87ee	00		.
	nop			;87ef	00		.
	nop			;87f0	00		.
	nop			;87f1	00		.
	nop			;87f2	00		.
	nop			;87f3	00		.
	nop			;87f4	00		.
	nop			;87f5	00		.
	nop			;87f6	00		.
	nop			;87f7	00		.
l87f8h:
	nop			;87f8	00		.
	nop			;87f9	00		.
	nop			;87fa	00		.
	nop			;87fb	00		.
	nop			;87fc	00		.
	nop			;87fd	00		.
	nop			;87fe	00		.
	nop			;87ff	00		.
; ===========================================================================
; ENTRY POINT JUMP TABLE (8800h-8808h)
; These three JP instructions are the only executable code in this region.
; They serve as the program's entry vector table, called from BASIC or
; the loader to start execution.
; ===========================================================================
	jp l8e5ah		;8800	c3 5a 8e	. Z .	; Entry 0: Main program entry point
	jp laf82h		;8803	c3 82 af	. . .	; Entry 1: Interrupt return / cooperative multitask resume
	jp la958h		;8806	c3 58 a9	. X .	; Entry 2: Board display refresh
; ===========================================================================
; GAME STATE VARIABLES (8809h-88ADh)
; This region contains initialized data variables used by the chess engine.
; The disassembler has incorrectly decoded these as Z80 instructions,
; but they are actually variable storage locations read/written at runtime.
; ===========================================================================
l8809h:
	ld h,d			;8809	62		b	; VAR: Current source square pointer (low byte)
	adc a,c			;880a	89		.	; VAR: Current source square pointer (high byte)
l880bh:
	ld (de),a		;880b	12		.	; VAR: Current destination square pointer (low byte)
	adc a,c			;880c	89		.	; VAR: Current destination square pointer (high byte)
l880dh:
	dec h			;880d	25		%	; VAR: Current piece position (low byte)
	adc a,c			;880e	89		.	; VAR: Current piece position (high byte)
l880fh:
	jr c,l879ah		;880f	38 89		8 .	; VAR: Pin detection square (2 bytes)
l8811h:
	ld b,089h		;8811	06 89		. .	; VAR: Current piece type (2 bytes)
l8813h:
	nop			;8813	00		.	; VAR: Target piece type (low byte)
	adc a,c			;8814	89		.	; VAR: Target piece type (high byte)
l8815h:
	inc b			;8815	04		.	; VAR: Working piece type (low byte)
	adc a,c			;8816	89		.	; VAR: Working piece type (high byte)
	nop			;8817	00		.
	adc a,c			;8818	89		.
l8819h:
	ex af,af'		;8819	08		.	; VAR: Direction index counter (low byte)
	adc a,c			;881a	89		.	; VAR: Direction index counter (high byte)
l881bh:
	djnz l87a6h		;881b	10 89		. .	; VAR: Direction vector offset (2 bytes)
l881dh:
	nop			;881d	00		.	; VAR: Pin counter (low byte)
	adc a,c			;881e	89		.	; VAR: Pin counter (high byte)
l881fh:
	ld l,l			;881f	6d		m	; VAR: Move list pointer (low byte)
	adc a,c			;8820	89		.	; VAR: Move list pointer (high byte)
l8821h:
	nop			;8821	00		.	; VAR: Move tree node pointer (low byte)
	add a,b			;8822	80		.	; VAR: Move tree node pointer (high byte)
l8823h:
	ld d,e			;8823	53		S	; VAR: Alpha-beta bound stack pointer (low byte)
	adc a,c			;8824	89		.	; VAR: Alpha-beta bound stack pointer (high byte)
l8825h:
	ld d,h			;8825	54		T	; VAR: Best move pointer (low byte)
	add a,b			;8826	80		.	; VAR: Best move pointer (high byte)
l8827h:
	call nc,0ea81h		;8827	d4 81 ea	. . .	; VAR: Move tree base pointer (3 bytes)
	add a,b			;882a	80		.
l882bh:
	add a,b			;882b	80		.	; VAR: Human player color (0=white, 80h=black)
l882ch:
	nop			;882c	00		.	; VAR: Side to move (0=white, 80h=black)
l882dh:
	ld e,000h		;882d	1e 00		. .	; VAR: Current piece descriptor (2 bytes)
l882fh:
	inc c			;882f	0c		.	; VAR: Captured piece descriptor
l8830h:
	dec d			;8830	15		.	; VAR: Max depth reached
l8831h:
	ld bc,00101h		;8831	01 01 01	. . .	; VAR: Move number, max search depth, current ply (3 bytes)
l8834h:
	nop			;8834	00		.	; VAR: Check status flag
l8835h:
	ld bc,00012h		;8835	01 12 00	. . .	; VAR: Move found flag + best score
l8838h:
	nop			;8838	00		.
l8839h:
	nop			;8839	00		.
l883ah:
	nop			;883a	00		.
l883bh:
	nop			;883b	00		.
l883ch:
	nop			;883c	00		.
l883dh:
	nop			;883d	00		.
l883eh:
	jr nz,l8857h		;883e	20 17		  .	; VAR: Material balance accumulator (2 bytes)
l8840h:
	rla			;8840	17		.
l8841h:
	ld sp,hl		;8841	f9		.	; VAR: Pawn structure score
l8842h:
	ld sp,hl		;8842	f9		.
l8843h:
	defb 0fdh,008h,0fdh ;illegal sequence	;8843	fd 08 fd	. . .	; VAR: Piece-square table score
l8846h:
	ex af,af'		;8846	08		.
l8847h:
	nop			;8847	00		.	; VAR: Previous material scores
l8848h:
	call m,00000h		;8848	fc 00 00	. . .	; VAR: King safety score
l884bh:
	nop			;884b	00		.
l884ch:
	nop			;884c	00		.
l884dh:
	ld bc,00100h		;884d	01 00 01	. . .	; VAR: Opening book active flag
l8850h:
	ret			;8850	c9		.	; VAR: Node counter - positions evaluated
	nop			;8851	00		.
	nop			;8852	00		.
l8853h:
	sbc a,h			;8853	9c		.
	adc a,e			;8854	8b		.
l8855h:
	dec d			;8855	15		.
l8856h:
	inc e			;8856	1c		.
l8857h:
	nop			;8857	00		.
	nop			;8858	00		.
	nop			;8859	00		.
	nop			;885a	00		.
l885bh:
	nop			;885b	00		.
l885ch:
	nop			;885c	00		.
l885dh:
	nop			;885d	00		.
l885eh:
	ld bc,00101h		;885e	01 01 01	. . .
l8861h:
	ld h,d			;8861	62		b	; VAR: Move direction vectors - piece type data
l8862h:
	ld d,000h		;8862	16 00		. .
	nop			;8864	00		.
	nop			;8865	00		.
	ld bc,00101h		;8866	01 01 01	. . .
	ld bc,00101h		;8869	01 01 01	. . .
	ld bc,04d01h		;886c	01 01 4d	. . M
	ld b,c			;886f	41		A	; VAR: "MAX" string bytes (part of display)
	ld e,b			;8870	58		X
l8871h:
	ld bc,00100h		;8871	01 00 01	. . .	; VAR: User move entered flag
l8874h:
	jr nc,$-47		;8874	30 cf		0 .	; VAR: Difficulty level ASCII char + IM2 vector pointer
	adc a,l			;8876	8d		.
l8877h:
	daa			;8877	27		'	; VAR: Mate detection flag
l8878h:
	cp b			;8878	b8		.	; VAR: Screen cursor position
l8879h:
	ret c			;8879	d8		.	; VAR: Screen column counter
l887ah:
	call po,04261h		;887a	e4 61 42	. a B
	adc a,(hl)		;887d	8e		.
	ld a,(bc)		;887e	0a		.
	add hl,bc		;887f	09		.
; ---------------------------------------------------------------------------
; DIRECTION VECTOR TABLES (8880h-88ADh)
; These tables define how each piece type moves on the board.
; They contain move offsets, attack patterns, and direction counts.
; NOT executable code - the disassembler has decoded data bytes as
; instructions.
; ---------------------------------------------------------------------------
l8880h:
	add hl,bc		;8880	09		.	; DATA: Pawn attack offsets table
	dec bc			;8881	0b		.
	push af			;8882	f5		.
	rst 30h			;8883	f7		.
	ld a,(bc)		;8884	0a		.
	or 001h			;8885	f6 01		. .
	rst 38h			;8887	ff		.
	ex de,hl		;8888	eb		.
	call p,01308h		;8889	f4 08 13	. . .	; DATA: Piece move offset vectors
	dec d			;888c	15		.
	inc c			;888d	0c		.
	ret m			;888e	f8		.
	defb 0edh ;next byte illegal after ed	;888f	ed		.
	ld a,(bc)		;8890	0a		.
	ld a,(bc)		;8891	0a		.
	dec bc			;8892	0b		.
	add hl,bc		;8893	09		.
	or 0f6h			;8894	f6 f6		. .
	push af			;8896	f5		.
	rst 30h			;8897	f7		.
	inc d			;8898	14		.	; DATA: Direction counts per piece type
	djnz l88a3h		;8899	10 08		. .
	nop			;889b	00		.
	inc b			;889c	04		.
	nop			;889d	00		.
	nop			;889e	00		.
	inc b			;889f	04		.
	inc b			;88a0	04		.
	ex af,af'		;88a1	08		.
	inc b			;88a2	04		.
l88a3h:
	inc b			;88a3	04		.
	ex af,af'		;88a4	08		.
	ex af,af'		;88a5	08		.
	ld bc,00303h		;88a6	01 03 03	. . .
	dec b			;88a9	05		.
	add hl,bc		;88aa	09		.
	ld a,(bc)		;88ab	0a		.
	inc b			;88ac	04		.
	ld (bc),a		;88ad	02		.	; DATA: End of direction vector tables
	inc bc			;88ae	03		.
	dec b			;88af	05		.
	ld b,003h		;88b0	06 03		. .
	ld (bc),a		;88b2	02		.
	inc b			;88b3	04		.
; ===========================================================================
; BOARD BORDER SENTINEL VALUES (88B4h+)
; FFh bytes mark off-board squares in the 10x12 mailbox board representation.
; These sentinel values allow the move generator to detect board edges
; without explicit bounds checking.
; ===========================================================================
l88b4h:
	rst 38h			;88b4	ff		.	; DATA: Board border sentinel (FFh = off-board)
	rst 38h			;88b5	ff		.
	rst 38h			;88b6	ff		.
	rst 38h			;88b7	ff		.
	rst 38h			;88b8	ff		.
	rst 38h			;88b9	ff		.
	rst 38h			;88ba	ff		.
	rst 38h			;88bb	ff		.
	rst 38h			;88bc	ff		.
	rst 38h			;88bd	ff		.
	rst 38h			;88be	ff		.
	rst 38h			;88bf	ff		.
	rst 38h			;88c0	ff		.
	rst 38h			;88c1	ff		.
	rst 38h			;88c2	ff		.
	rst 38h			;88c3	ff		.
	rst 38h			;88c4	ff		.
	rst 38h			;88c5	ff		.
	rst 38h			;88c6	ff		.
	rst 38h			;88c7	ff		.
	rst 38h			;88c8	ff		.
; --- Rank 8 (black's back rank): Rook Knight Bishop King Queen Bishop Knight Rook ---
l88c9h:
	inc b			;88c9	04		.	; DATA: 04h = Rook
	ld (bc),a		;88ca	02		.	; DATA: 02h = Knight
	inc bc			;88cb	03		.	; DATA: 03h = Bishop
	dec b			;88cc	05		.	; DATA: 05h = King
	ld b,003h		;88cd	06 03		. .	; DATA: 06h = Queen, 03h = Bishop
	ld (bc),a		;88cf	02		.	; DATA: 02h = Knight
	inc b			;88d0	04		.	; DATA: 04h = Rook
	rst 38h			;88d1	ff		.	; DATA: FFh = off-board border
	rst 38h			;88d2	ff		.	; DATA: FFh = off-board border
; --- Rank 7 (black's pawns): 8 pawns ---
	ld bc,00101h		;88d3	01 01 01	. . .	; DATA: 01h = Pawn x3
	ld bc,00101h		;88d6	01 01 01	. . .	; DATA: 01h = Pawn x3
	ld bc,0ff01h		;88d9	01 01 ff	. . .	; DATA: 01h = Pawn x2, FFh = border
	rst 38h			;88dc	ff		.	; DATA: FFh = off-board border
; --- Ranks 6-3 (empty squares): 00h x8 per rank ---
	nop			;88dd	00		.	; DATA: 00h = empty square
	nop			;88de	00		.
	nop			;88df	00		.
	nop			;88e0	00		.
	nop			;88e1	00		.
	nop			;88e2	00		.
	nop			;88e3	00		.
	nop			;88e4	00		.
	rst 38h			;88e5	ff		.	; DATA: FFh = off-board border
	rst 38h			;88e6	ff		.
	nop			;88e7	00		.
	nop			;88e8	00		.
	nop			;88e9	00		.
	nop			;88ea	00		.
	nop			;88eb	00		.
	nop			;88ec	00		.
	nop			;88ed	00		.
	nop			;88ee	00		.
	rst 38h			;88ef	ff		.
	rst 38h			;88f0	ff		.
	nop			;88f1	00		.
	nop			;88f2	00		.
	nop			;88f3	00		.
	nop			;88f4	00		.
	nop			;88f5	00		.
	nop			;88f6	00		.
	nop			;88f7	00		.
	nop			;88f8	00		.
	rst 38h			;88f9	ff		.
	rst 38h			;88fa	ff		.
	nop			;88fb	00		.
	nop			;88fc	00		.
	nop			;88fd	00		.
	nop			;88fe	00		.
	nop			;88ff	00		.
	nop			;8900	00		.
	nop			;8901	00		.
	nop			;8902	00		.
	rst 38h			;8903	ff		.
	rst 38h			;8904	ff		.
	add a,c			;8905	81		.
	add a,c			;8906	81		.
	add a,c			;8907	81		.
	add a,c			;8908	81		.
	add a,c			;8909	81		.
	add a,c			;890a	81		.
	add a,c			;890b	81		.
	add a,c			;890c	81		.
	rst 38h			;890d	ff		.
	rst 38h			;890e	ff		.
	add a,h			;890f	84		.
	add a,d			;8910	82		.
	add a,e			;8911	83		.
	add a,l			;8912	85		.
	add a,(hl)		;8913	86		.
	add a,e			;8914	83		.
	add a,d			;8915	82		.
	add a,h			;8916	84		.
	rst 38h			;8917	ff		.
	rst 38h			;8918	ff		.
	rst 38h			;8919	ff		.
	rst 38h			;891a	ff		.
	rst 38h			;891b	ff		.
	rst 38h			;891c	ff		.
	rst 38h			;891d	ff		.
	rst 38h			;891e	ff		.
	rst 38h			;891f	ff		.
	rst 38h			;8920	ff		.
	rst 38h			;8921	ff		.
	rst 38h			;8922	ff		.
	rst 38h			;8923	ff		.
	rst 38h			;8924	ff		.
	rst 38h			;8925	ff		.
	rst 38h			;8926	ff		.
	rst 38h			;8927	ff		.
	rst 38h			;8928	ff		.
	rst 38h			;8929	ff		.
	rst 38h			;892a	ff		.
	rst 38h			;892b	ff		.
l892ch:
	ld bc,00000h		;892c	01 00 00	. . .
	nop			;892f	00		.
	nop			;8930	00		.
	nop			;8931	00		.
	nop			;8932	00		.
l8933h:
	ld (bc),a		;8933	02		.
	nop			;8934	00		.
	nop			;8935	00		.
l8936h:
	nop			;8936	00		.
	nop			;8937	00		.
	nop			;8938	00		.
	ld a,(bc)		;8939	0a		.
l893ah:
	ld b,d			;893a	42		B
	ld c,c			;893b	49		I
	ld c,c			;893c	49		I
	ld c,c			;893d	49		I
	nop			;893e	00		.
	nop			;893f	00		.
	nop			;8940	00		.
	nop			;8941	00		.
	nop			;8942	00		.
	nop			;8943	00		.
	or 0f6h			;8944	f6 f6		. .
	or 0f6h			;8946	f6 f6		. .
	nop			;8948	00		.
	nop			;8949	00		.
	nop			;894a	00		.
	nop			;894b	00		.
	nop			;894c	00		.
	nop			;894d	00		.
l894eh:
	add hl,de		;894e	19		.
l894fh:
	ld e,a			;894f	5f		_
l8950h:
	jr $+96			;8950	18 5e		. ^
	rst 38h			;8952	ff		.
l8953h:
	nop			;8953	00		.
l8954h:
	add a,b			;8954	80		.
	jr nc,$-126		;8955	30 80		0 .
	add a,b			;8957	80		.
	nop			;8958	00		.
	add a,b			;8959	80		.
	add a,026h		;895a	c6 26		. &
	add a,001h		;895c	c6 01		. .
	nop			;895e	00		.
	nop			;895f	00		.
	nop			;8960	00		.
	nop			;8961	00		.
	nop			;8962	00		.
	nop			;8963	00		.
	nop			;8964	00		.
	nop			;8965	00		.
	nop			;8966	00		.
	nop			;8967	00		.
	nop			;8968	00		.
l8969h:
	nop			;8969	00		.
	nop			;896a	00		.
	nop			;896b	00		.
	add a,b			;896c	80		.
	ld h,(hl)		;896d	66		f
	add a,b			;896e	80		.
	jp pe,l8c80h		;896f	ea 80 8c	. . .
	add a,c			;8972	81		.
	ret po			;8973	e0		.
	add a,c			;8974	81		.
	ret po			;8975	e0		.
	add a,c			;8976	81		.
	or d			;8977	b2		.
	add a,d			;8978	82		.
	or d			;8979	b2		.
	add a,d			;897a	82		.
	ld h,(hl)		;897b	66		f
	add a,e			;897c	83		.
	sbc a,083h		;897d	de 83		. .
	ld c,084h		;897f	0e 84		. .
	ld c,084h		;8981	0e 84		. .
	ld e,(hl)		;8983	5e		^
	add a,l			;8984	85		.
	ld e,(hl)		;8985	5e		^
	add a,l			;8986	85		.
	ld l,h			;8987	6c		l
	add a,(hl)		;8988	86		.
	ld (bc),a		;8989	02		.
	add a,a			;898a	87		.
	ld c,087h		;898b	0e 87		. .
	ld c,087h		;898d	0e 87		. .
	cp 087h			;898f	fe 87		. .
	nop			;8991	00		.
	nop			;8992	00		.
l8993h:
	ex af,af'		;8993	08		.
	ex af,af'		;8994	08		.
l8995h:
	nop			;8995	00		.
	jr $+42			;8996	18 28		. (
	ex af,af'		;8998	08		.
	ex af,af'		;8999	08		.
	ex af,af'		;899a	08		.
	ld a,000h		;899b	3e 00		> .
l899dh:
	rlca			;899d	07		.
l899eh:
	ld a,b			;899e	78		x
l899fh:
	rlca			;899f	07		.
l89a0h:
	ld (bc),a		;89a0	02		.
l89a1h:
	rlca			;89a1	07		.
l89a2h:
	nop			;89a2	00		.
l89a3h:
	nop			;89a3	00		.
l89a4h:
	ld bc,0000eh		;89a4	01 0e 00	. . .
l89a7h:
	add a,h			;89a7	84		.
l89a8h:
	add a,b			;89a8	80		.
l89a9h:
	inc sp			;89a9	33		3
	adc a,c			;89aa	89		.
l89abh:
	jr nc,l8936h		;89ab	30 89		0 .
l89adh:
	nop			;89ad	00		.
	ld bc,02e00h		;89ae	01 00 2e	. . .
	or b			;89b1	b0		.
l89b2h:
	nop			;89b2	00		.
	ld bc,00001h		;89b3	01 01 00	. . .
	nop			;89b6	00		.
	ld bc,00101h		;89b7	01 01 01	. . .
	ld bc,0ff01h		;89ba	01 01 ff	. . .
	rst 38h			;89bd	ff		.
	nop			;89be	00		.
	ld bc,00201h		;89bf	01 01 02	. . .
	inc bc			;89c2	03		.
	rst 38h			;89c3	ff		.
	rst 38h			;89c4	ff		.
	nop			;89c5	00		.
	ld bc,00201h		;89c6	01 01 02	. . .
	ld a,(bc)		;89c9	0a		.
	rst 38h			;89ca	ff		.
	rst 38h			;89cb	ff		.
	nop			;89cc	00		.
	ld bc,00301h		;89cd	01 01 03	. . .
	dec b			;89d0	05		.
	rst 38h			;89d1	ff		.
	rst 38h			;89d2	ff		.
	nop			;89d3	00		.
	ld bc,00301h		;89d4	01 01 03	. . .
	ld a,(bc)		;89d7	0a		.
	rst 38h			;89d8	ff		.
	rst 38h			;89d9	ff		.
	nop			;89da	00		.
	ld bc,00401h		;89db	01 01 04	. . .
	dec b			;89de	05		.
	rst 38h			;89df	ff		.
	rst 38h			;89e0	ff		.
	nop			;89e1	00		.
	ld bc,00401h		;89e2	01 01 04	. . .
	ld a,(bc)		;89e5	0a		.
	rst 38h			;89e6	ff		.
	rst 38h			;89e7	ff		.
	nop			;89e8	00		.
	ld bc,00501h		;89e9	01 01 05	. . .
	ld b,0ffh		;89ec	06 ff		. .
	rst 38h			;89ee	ff		.
	nop			;89ef	00		.
	ld bc,00601h		;89f0	01 01 06	. . .
	ld b,0ffh		;89f3	06 ff		. .
	rst 38h			;89f5	ff		.
	nop			;89f6	00		.
	ld bc,01000h		;89f7	01 00 10	. . .
	jr nz,l8a3ch		;89fa	20 40		  @
	rst 38h			;89fc	ff		.
	ld b,b			;89fd	40		@
	jr nz,l8a10h		;89fe	20 10		  .
	ex af,af'		;8a00	08		.
	ex af,af'		;8a01	08		.
	ex af,af'		;8a02	08		.
	ex af,af'		;8a03	08		.
	ld c,c			;8a04	49		I
	ld hl,(0081ch)		;8a05	2a 1c 08	* . .
	ex af,af'		;8a08	08		.
	inc e			;8a09	1c		.
	ld hl,(00849h)		;8a0a	2a 49 08	* I .
	ex af,af'		;8a0d	08		.
	ex af,af'		;8a0e	08		.
	ex af,af'		;8a0f	08		.
l8a10h:
	nop			;8a10	00		.
	ex af,af'		;8a11	08		.
	inc b			;8a12	04		.
	ld (bc),a		;8a13	02		.
	rst 38h			;8a14	ff		.
	ld (bc),a		;8a15	02		.
	inc b			;8a16	04		.
	ex af,af'		;8a17	08		.
	nop			;8a18	00		.
	nop			;8a19	00		.
	nop			;8a1a	00		.
	nop			;8a1b	00		.
	nop			;8a1c	00		.
	nop			;8a1d	00		.
	inc bc			;8a1e	03		.
	inc bc			;8a1f	03		.
	nop			;8a20	00		.
	nop			;8a21	00		.
	nop			;8a22	00		.
	nop			;8a23	00		.
	nop			;8a24	00		.
	nop			;8a25	00		.
	rst 38h			;8a26	ff		.
	rst 38h			;8a27	ff		.
	nop			;8a28	00		.
	nop			;8a29	00		.
	nop			;8a2a	00		.
	nop			;8a2b	00		.
	nop			;8a2c	00		.
	nop			;8a2d	00		.
	ret nz			;8a2e	c0		.
	ret nz			;8a2f	c0		.
	inc bc			;8a30	03		.
	inc bc			;8a31	03		.
	nop			;8a32	00		.
	nop			;8a33	00		.
	nop			;8a34	00		.
	nop			;8a35	00		.
	nop			;8a36	00		.
	nop			;8a37	00		.
	rst 38h			;8a38	ff		.
	rst 38h			;8a39	ff		.
	nop			;8a3a	00		.
	nop			;8a3b	00		.
l8a3ch:
	nop			;8a3c	00		.
	nop			;8a3d	00		.
	nop			;8a3e	00		.
	nop			;8a3f	00		.
	ret nz			;8a40	c0		.
	ret nz			;8a41	c0		.
	nop			;8a42	00		.
	nop			;8a43	00		.
	nop			;8a44	00		.
	nop			;8a45	00		.
	nop			;8a46	00		.
	nop			;8a47	00		.
	inc bc			;8a48	03		.
	inc bc			;8a49	03		.
	inc bc			;8a4a	03		.
	inc bc			;8a4b	03		.
	inc bc			;8a4c	03		.
	inc bc			;8a4d	03		.
	inc bc			;8a4e	03		.
	inc bc			;8a4f	03		.
	ret nz			;8a50	c0		.
	ret nz			;8a51	c0		.
	ret nz			;8a52	c0		.
	ret nz			;8a53	c0		.
	ret nz			;8a54	c0		.
	ret nz			;8a55	c0		.
	ret nz			;8a56	c0		.
	ret nz			;8a57	c0		.
	nop			;8a58	00		.
	inc b			;8a59	04		.
	ld b,005h		;8a5a	06 05		. .
	inc b			;8a5c	04		.
	inc b			;8a5d	04		.
	inc b			;8a5e	04		.
	nop			;8a5f	00		.
	nop			;8a60	00		.
	jr nz,l8ac6h		;8a61	20 63		  c
	and h			;8a63	a4		.
	daa			;8a64	27		'
	inc h			;8a65	24		$
	inc hl			;8a66	23		#
	nop			;8a67	00		.
	nop			;8a68	00		.
	nop			;8a69	00		.
	add a,b			;8a6a	80		.
	ld b,b			;8a6b	40		@
	add a,b			;8a6c	80		.
	nop			;8a6d	00		.
	ret nz			;8a6e	c0		.
	nop			;8a6f	00		.
l8a70h:
	nop			;8a70	00		.
	nop			;8a71	00		.
	nop			;8a72	00		.
	nop			;8a73	00		.
	nop			;8a74	00		.
	nop			;8a75	00		.
	nop			;8a76	00		.
	nop			;8a77	00		.
	nop			;8a78	00		.
	nop			;8a79	00		.
	nop			;8a7a	00		.
	nop			;8a7b	00		.
	nop			;8a7c	00		.
	nop			;8a7d	00		.
	nop			;8a7e	00		.
	nop			;8a7f	00		.
	nop			;8a80	00		.
	nop			;8a81	00		.
	nop			;8a82	00		.
	nop			;8a83	00		.
	nop			;8a84	00		.
	nop			;8a85	00		.
	ld (bc),a		;8a86	02		.
	ld (bc),a		;8a87	02		.
	ld (bc),a		;8a88	02		.
	ld bc,00203h		;8a89	01 03 02	. . .
	ld (bc),a		;8a8c	02		.
	nop			;8a8d	00		.
	nop			;8a8e	00		.
	ld bc,00100h		;8a8f	01 00 01	. . .
	nop			;8a92	00		.
	ld bc,00001h		;8a93	01 01 00	. . .
	ld bc,00000h		;8a96	01 00 00	. . .
	ld bc,00000h		;8a99	01 00 00	. . .
	nop			;8a9c	00		.
	nop			;8a9d	00		.
	inc bc			;8a9e	03		.
	ld (bc),a		;8a9f	02		.
	ld (bc),a		;8aa0	02		.
	nop			;8aa1	00		.
	nop			;8aa2	00		.
	nop			;8aa3	00		.
	nop			;8aa4	00		.
	inc b			;8aa5	04		.
	ld bc,00002h		;8aa6	01 02 00	. . .
	nop			;8aa9	00		.
	ld bc,00000h		;8aaa	01 00 00	. . .
	nop			;8aad	00		.
	ld bc,00000h		;8aae	01 00 00	. . .
	ld bc,00201h		;8ab1	01 01 02	. . .
	ld bc,00000h		;8ab4	01 00 00	. . .
	nop			;8ab7	00		.
	ld bc,00100h		;8ab8	01 00 01	. . .
	ld bc,00100h		;8abb	01 00 01	. . .
	nop			;8abe	00		.
	nop			;8abf	00		.
	nop			;8ac0	00		.
	nop			;8ac1	00		.
	nop			;8ac2	00		.
	nop			;8ac3	00		.
	nop			;8ac4	00		.
	nop			;8ac5	00		.
l8ac6h:
	nop			;8ac6	00		.
	nop			;8ac7	00		.
	nop			;8ac8	00		.
	nop			;8ac9	00		.
	nop			;8aca	00		.
	nop			;8acb	00		.
	nop			;8acc	00		.
	nop			;8acd	00		.
	nop			;8ace	00		.
	nop			;8acf	00		.
	nop			;8ad0	00		.
	nop			;8ad1	00		.
	nop			;8ad2	00		.
	nop			;8ad3	00		.
	nop			;8ad4	00		.
	nop			;8ad5	00		.
	nop			;8ad6	00		.
	nop			;8ad7	00		.
	nop			;8ad8	00		.
	nop			;8ad9	00		.
	nop			;8ada	00		.
	nop			;8adb	00		.
	nop			;8adc	00		.
	nop			;8add	00		.
	nop			;8ade	00		.
	nop			;8adf	00		.
	nop			;8ae0	00		.
	nop			;8ae1	00		.
	nop			;8ae2	00		.
	nop			;8ae3	00		.
	nop			;8ae4	00		.
	nop			;8ae5	00		.
	nop			;8ae6	00		.
	nop			;8ae7	00		.
l8ae8h:
	nop			;8ae8	00		.
	nop			;8ae9	00		.
	nop			;8aea	00		.
	nop			;8aeb	00		.
	nop			;8aec	00		.
	nop			;8aed	00		.
	nop			;8aee	00		.
	nop			;8aef	00		.
	nop			;8af0	00		.
	nop			;8af1	00		.
	nop			;8af2	00		.
	nop			;8af3	00		.
	nop			;8af4	00		.
	nop			;8af5	00		.
	nop			;8af6	00		.
	nop			;8af7	00		.
	nop			;8af8	00		.
	nop			;8af9	00		.
	nop			;8afa	00		.
	nop			;8afb	00		.
	nop			;8afc	00		.
	nop			;8afd	00		.
	nop			;8afe	00		.
	nop			;8aff	00		.
	nop			;8b00	00		.
	nop			;8b01	00		.
	nop			;8b02	00		.
	nop			;8b03	00		.
	ld bc,00000h		;8b04	01 00 00	. . .
	ld bc,00100h		;8b07	01 00 01	. . .
	nop			;8b0a	00		.
	nop			;8b0b	00		.
	nop			;8b0c	00		.
	nop			;8b0d	00		.
	ld bc,00000h		;8b0e	01 00 00	. . .
	nop			;8b11	00		.
	nop			;8b12	00		.
	nop			;8b13	00		.
	ld bc,00000h		;8b14	01 00 00	. . .
	nop			;8b17	00		.
	ld bc,00000h		;8b18	01 00 00	. . .
	nop			;8b1b	00		.
	nop			;8b1c	00		.
	ld bc,00100h		;8b1d	01 00 01	. . .
	nop			;8b20	00		.
	nop			;8b21	00		.
	ld bc,00000h		;8b22	01 00 00	. . .
	nop			;8b25	00		.
	ld bc,00001h		;8b26	01 01 00	. . .
	ld bc,00103h		;8b29	01 03 01	. . .
	nop			;8b2c	00		.
	nop			;8b2d	00		.
	nop			;8b2e	00		.
	ld bc,00000h		;8b2f	01 00 00	. . .
	nop			;8b32	00		.
	nop			;8b33	00		.
	ld bc,00100h		;8b34	01 00 01	. . .
	nop			;8b37	00		.
	nop			;8b38	00		.
	nop			;8b39	00		.
	ld bc,00000h		;8b3a	01 00 00	. . .
	ld bc,00100h		;8b3d	01 00 01	. . .
	nop			;8b40	00		.
	nop			;8b41	00		.
	nop			;8b42	00		.
	ld bc,00100h		;8b43	01 00 01	. . .
	ld bc,00202h		;8b46	01 02 02	. . .
	ld (bc),a		;8b49	02		.
	ld bc,00000h		;8b4a	01 00 00	. . .
	nop			;8b4d	00		.
	nop			;8b4e	00		.
	nop			;8b4f	00		.
	nop			;8b50	00		.
	nop			;8b51	00		.
	nop			;8b52	00		.
	nop			;8b53	00		.
	nop			;8b54	00		.
	nop			;8b55	00		.
	nop			;8b56	00		.
	nop			;8b57	00		.
	nop			;8b58	00		.
	nop			;8b59	00		.
	nop			;8b5a	00		.
	nop			;8b5b	00		.
	nop			;8b5c	00		.
	nop			;8b5d	00		.
	nop			;8b5e	00		.
	nop			;8b5f	00		.
l8b60h:
	nop			;8b60	00		.
	nop			;8b61	00		.
	nop			;8b62	00		.
	nop			;8b63	00		.
	nop			;8b64	00		.
	nop			;8b65	00		.
	nop			;8b66	00		.
	nop			;8b67	00		.
	nop			;8b68	00		.
	nop			;8b69	00		.
	nop			;8b6a	00		.
	nop			;8b6b	00		.
	nop			;8b6c	00		.
	nop			;8b6d	00		.
	nop			;8b6e	00		.
	nop			;8b6f	00		.
	nop			;8b70	00		.
	nop			;8b71	00		.
	nop			;8b72	00		.
	nop			;8b73	00		.
	nop			;8b74	00		.
	nop			;8b75	00		.
	nop			;8b76	00		.
	nop			;8b77	00		.
	nop			;8b78	00		.
	nop			;8b79	00		.
	nop			;8b7a	00		.
	nop			;8b7b	00		.
	nop			;8b7c	00		.
	nop			;8b7d	00		.
	ld d,(hl)		;8b7e	56		V
	ld c,h			;8b7f	4c		L
	ld bc,0534ah		;8b80	01 4a 53	. J S
	ld bc,00000h		;8b83	01 00 00	. . .
	nop			;8b86	00		.
	nop			;8b87	00		.
	nop			;8b88	00		.
	nop			;8b89	00		.
	nop			;8b8a	00		.
	nop			;8b8b	00		.
	nop			;8b8c	00		.
	nop			;8b8d	00		.
	nop			;8b8e	00		.
	nop			;8b8f	00		.
	nop			;8b90	00		.
	nop			;8b91	00		.
	nop			;8b92	00		.
	nop			;8b93	00		.
	nop			;8b94	00		.
	nop			;8b95	00		.
	nop			;8b96	00		.
	nop			;8b97	00		.
	nop			;8b98	00		.
	nop			;8b99	00		.
	nop			;8b9a	00		.
	nop			;8b9b	00		.
	dec d			;8b9c	15		.
	inc e			;8b9d	1c		.
	ld a,(de)		;8b9e	1a		.
	add hl,sp		;8b9f	39		9
	ld a,(03602h)		;8ba0	3a 02 36	: . 6
	ccf			;8ba3	3f		?
	ld (bc),a		;8ba4	02		.
	dec hl			;8ba5	2b		+
	inc l			;8ba6	2c		,
	ld bc,01f15h		;8ba7	01 15 1f	. . .
	ld bc,03039h		;8baa	01 39 30	. 9 0
	ld bc,02625h		;8bad	01 25 26	. % &
	ld bc,04339h		;8bb0	01 39 43	. 9 C
	ld bc,04138h		;8bb3	01 38 41	. 8 A
	ld bc,03839h		;8bb6	01 39 38	. 9 8
	ld bc,0424dh		;8bb9	01 4d 42	. M B
	ld bc,00000h		;8bbc	01 00 00	. . .
	nop			;8bbf	00		.
	nop			;8bc0	00		.
	nop			;8bc1	00		.
	nop			;8bc2	00		.
	nop			;8bc3	00		.
	nop			;8bc4	00		.
	nop			;8bc5	00		.
	nop			;8bc6	00		.
	nop			;8bc7	00		.
	nop			;8bc8	00		.
	nop			;8bc9	00		.
	nop			;8bca	00		.
	nop			;8bcb	00		.
	nop			;8bcc	00		.
	nop			;8bcd	00		.
	nop			;8bce	00		.
	nop			;8bcf	00		.
	nop			;8bd0	00		.
	nop			;8bd1	00		.
	nop			;8bd2	00		.
	nop			;8bd3	00		.
	nop			;8bd4	00		.
	nop			;8bd5	00		.
	nop			;8bd6	00		.
	nop			;8bd7	00		.
	nop			;8bd8	00		.
	nop			;8bd9	00		.
	nop			;8bda	00		.
	nop			;8bdb	00		.
	nop			;8bdc	00		.
	nop			;8bdd	00		.
	nop			;8bde	00		.
	nop			;8bdf	00		.
	nop			;8be0	00		.
	nop			;8be1	00		.
	nop			;8be2	00		.
	nop			;8be3	00		.
	nop			;8be4	00		.
	nop			;8be5	00		.
	nop			;8be6	00		.
	nop			;8be7	00		.
	nop			;8be8	00		.
	nop			;8be9	00		.
	nop			;8bea	00		.
	nop			;8beb	00		.
	nop			;8bec	00		.
	nop			;8bed	00		.
	nop			;8bee	00		.
	nop			;8bef	00		.
	nop			;8bf0	00		.
	nop			;8bf1	00		.
	nop			;8bf2	00		.
	nop			;8bf3	00		.
	nop			;8bf4	00		.
	nop			;8bf5	00		.
	nop			;8bf6	00		.
	nop			;8bf7	00		.
	nop			;8bf8	00		.
	nop			;8bf9	00		.
	nop			;8bfa	00		.
	nop			;8bfb	00		.
	nop			;8bfc	00		.
	nop			;8bfd	00		.
	nop			;8bfe	00		.
	nop			;8bff	00		.
	nop			;8c00	00		.
	nop			;8c01	00		.
	nop			;8c02	00		.
	nop			;8c03	00		.
	nop			;8c04	00		.
	nop			;8c05	00		.
	nop			;8c06	00		.
	nop			;8c07	00		.
	nop			;8c08	00		.
	nop			;8c09	00		.
	nop			;8c0a	00		.
	nop			;8c0b	00		.
	nop			;8c0c	00		.
	nop			;8c0d	00		.
	nop			;8c0e	00		.
	nop			;8c0f	00		.
	nop			;8c10	00		.
	nop			;8c11	00		.
	nop			;8c12	00		.
	nop			;8c13	00		.
	nop			;8c14	00		.
	nop			;8c15	00		.
	nop			;8c16	00		.
	nop			;8c17	00		.
	nop			;8c18	00		.
	nop			;8c19	00		.
	nop			;8c1a	00		.
	nop			;8c1b	00		.
	nop			;8c1c	00		.
	nop			;8c1d	00		.
	nop			;8c1e	00		.
	nop			;8c1f	00		.
	nop			;8c20	00		.
	nop			;8c21	00		.
	nop			;8c22	00		.
	nop			;8c23	00		.
	nop			;8c24	00		.
	nop			;8c25	00		.
	nop			;8c26	00		.
	nop			;8c27	00		.
	nop			;8c28	00		.
	nop			;8c29	00		.
	nop			;8c2a	00		.
	nop			;8c2b	00		.
	nop			;8c2c	00		.
	nop			;8c2d	00		.
	nop			;8c2e	00		.
	nop			;8c2f	00		.
	nop			;8c30	00		.
	nop			;8c31	00		.
	ld b,h			;8c32	44		D
	jr nz,l8c5dh		;8c33	20 28		  (
	ld c,c			;8c35	49		I
	ld e,b			;8c36	58		X
	dec hl			;8c37	2b		+
	add hl,sp		;8c38	39		9
	ld sp,02c29h		;8c39	31 29 2c	1 ) ,
	ld b,c			;8c3c	41		A
	dec c			;8c3d	0d		.
	ld a,(bc)		;8c3e	0a		.
	add hl,bc		;8c3f	09		.
	ld c,h			;8c40	4c		L
	ld b,h			;8c41	44		D
	jr nz,l8c6ch		;8c42	20 28		  (
	ld d,d			;8c44	52		R
	scf			;8c45	37		7
	inc bc			;8c46	03		.
	nop			;8c47	00		.
	nop			;8c48	00		.
	nop			;8c49	00		.
	nop			;8c4a	00		.
	nop			;8c4b	00		.
	nop			;8c4c	00		.
	nop			;8c4d	00		.
	nop			;8c4e	00		.
	nop			;8c4f	00		.
l8c50h:
	nop			;8c50	00		.
	nop			;8c51	00		.
	nop			;8c52	00		.
	nop			;8c53	00		.
	nop			;8c54	00		.
	nop			;8c55	00		.
	nop			;8c56	00		.
	nop			;8c57	00		.
	nop			;8c58	00		.
	nop			;8c59	00		.
	nop			;8c5a	00		.
	nop			;8c5b	00		.
	nop			;8c5c	00		.
l8c5dh:
	nop			;8c5d	00		.
	ld bc,00101h		;8c5e	01 01 01	. . .
	nop			;8c61	00		.
	nop			;8c62	00		.
	nop			;8c63	00		.
	nop			;8c64	00		.
	nop			;8c65	00		.
	nop			;8c66	00		.
	nop			;8c67	00		.
	ld bc,00100h		;8c68	01 00 01	. . .
	nop			;8c6b	00		.
l8c6ch:
	nop			;8c6c	00		.
	nop			;8c6d	00		.
	nop			;8c6e	00		.
	nop			;8c6f	00		.
	nop			;8c70	00		.
	nop			;8c71	00		.
	ld bc,00101h		;8c72	01 01 01	. . .
	nop			;8c75	00		.
	nop			;8c76	00		.
	nop			;8c77	00		.
	nop			;8c78	00		.
	nop			;8c79	00		.
	nop			;8c7a	00		.
	nop			;8c7b	00		.
	nop			;8c7c	00		.
	nop			;8c7d	00		.
	nop			;8c7e	00		.
	nop			;8c7f	00		.
l8c80h:
	nop			;8c80	00		.
	nop			;8c81	00		.
	nop			;8c82	00		.
	nop			;8c83	00		.
	nop			;8c84	00		.
	nop			;8c85	00		.
	nop			;8c86	00		.
	nop			;8c87	00		.
	nop			;8c88	00		.
	nop			;8c89	00		.
	nop			;8c8a	00		.
	nop			;8c8b	00		.
	nop			;8c8c	00		.
	nop			;8c8d	00		.
	nop			;8c8e	00		.
	nop			;8c8f	00		.
	nop			;8c90	00		.
	nop			;8c91	00		.
	nop			;8c92	00		.
	nop			;8c93	00		.
	nop			;8c94	00		.
	nop			;8c95	00		.
	nop			;8c96	00		.
	nop			;8c97	00		.
	nop			;8c98	00		.
	nop			;8c99	00		.
	nop			;8c9a	00		.
	nop			;8c9b	00		.
	nop			;8c9c	00		.
	nop			;8c9d	00		.
	nop			;8c9e	00		.
	nop			;8c9f	00		.
	nop			;8ca0	00		.
	nop			;8ca1	00		.
	nop			;8ca2	00		.
	nop			;8ca3	00		.
	nop			;8ca4	00		.
	nop			;8ca5	00		.
	nop			;8ca6	00		.
	nop			;8ca7	00		.
	nop			;8ca8	00		.
	nop			;8ca9	00		.
	nop			;8caa	00		.
	nop			;8cab	00		.
	nop			;8cac	00		.
	nop			;8cad	00		.
	nop			;8cae	00		.
	nop			;8caf	00		.
	nop			;8cb0	00		.
	nop			;8cb1	00		.
	nop			;8cb2	00		.
	nop			;8cb3	00		.
	nop			;8cb4	00		.
	nop			;8cb5	00		.
	nop			;8cb6	00		.
	nop			;8cb7	00		.
	nop			;8cb8	00		.
	nop			;8cb9	00		.
	nop			;8cba	00		.
	nop			;8cbb	00		.
	nop			;8cbc	00		.
	nop			;8cbd	00		.
	nop			;8cbe	00		.
	nop			;8cbf	00		.
	nop			;8cc0	00		.
	nop			;8cc1	00		.
	nop			;8cc2	00		.
	nop			;8cc3	00		.
	nop			;8cc4	00		.
	nop			;8cc5	00		.
	nop			;8cc6	00		.
	nop			;8cc7	00		.
l8cc8h:
	nop			;8cc8	00		.
	nop			;8cc9	00		.
	nop			;8cca	00		.
	nop			;8ccb	00		.
	nop			;8ccc	00		.
	nop			;8ccd	00		.
	nop			;8cce	00		.
	nop			;8ccf	00		.
	nop			;8cd0	00		.
	nop			;8cd1	00		.
	nop			;8cd2	00		.
	nop			;8cd3	00		.
	nop			;8cd4	00		.
	nop			;8cd5	00		.
	nop			;8cd6	00		.
	nop			;8cd7	00		.
	nop			;8cd8	00		.
	nop			;8cd9	00		.
	nop			;8cda	00		.
	nop			;8cdb	00		.
	nop			;8cdc	00		.
	nop			;8cdd	00		.
	nop			;8cde	00		.
	nop			;8cdf	00		.
	nop			;8ce0	00		.
	nop			;8ce1	00		.
	nop			;8ce2	00		.
	nop			;8ce3	00		.
	nop			;8ce4	00		.
	nop			;8ce5	00		.
	nop			;8ce6	00		.
	nop			;8ce7	00		.
	nop			;8ce8	00		.
	nop			;8ce9	00		.
	nop			;8cea	00		.
	nop			;8ceb	00		.
	nop			;8cec	00		.
	nop			;8ced	00		.
	nop			;8cee	00		.
	nop			;8cef	00		.
	nop			;8cf0	00		.
	nop			;8cf1	00		.
	nop			;8cf2	00		.
	nop			;8cf3	00		.
	nop			;8cf4	00		.
	nop			;8cf5	00		.
	nop			;8cf6	00		.
	nop			;8cf7	00		.
	nop			;8cf8	00		.
	nop			;8cf9	00		.
	nop			;8cfa	00		.
	nop			;8cfb	00		.
	nop			;8cfc	00		.
	nop			;8cfd	00		.
	nop			;8cfe	00		.
	nop			;8cff	00		.
	nop			;8d00	00		.
	nop			;8d01	00		.
	nop			;8d02	00		.
	nop			;8d03	00		.
	nop			;8d04	00		.
	nop			;8d05	00		.
	nop			;8d06	00		.
	nop			;8d07	00		.
	nop			;8d08	00		.
	nop			;8d09	00		.
	nop			;8d0a	00		.
	nop			;8d0b	00		.
	nop			;8d0c	00		.
	nop			;8d0d	00		.
	nop			;8d0e	00		.
	nop			;8d0f	00		.
	nop			;8d10	00		.
	nop			;8d11	00		.
	nop			;8d12	00		.
	nop			;8d13	00		.
	nop			;8d14	00		.
	nop			;8d15	00		.
	nop			;8d16	00		.
	nop			;8d17	00		.
	nop			;8d18	00		.
	nop			;8d19	00		.
	nop			;8d1a	00		.
	nop			;8d1b	00		.
	ld bc,00101h		;8d1c	01 01 01	. . .
	nop			;8d1f	00		.
	nop			;8d20	00		.
	nop			;8d21	00		.
	nop			;8d22	00		.
	nop			;8d23	00		.
	nop			;8d24	00		.
	nop			;8d25	00		.
	ld bc,00100h		;8d26	01 00 01	. . .
	nop			;8d29	00		.
	nop			;8d2a	00		.
	nop			;8d2b	00		.
	nop			;8d2c	00		.
	nop			;8d2d	00		.
	nop			;8d2e	00		.
	nop			;8d2f	00		.
	ld bc,00101h		;8d30	01 01 01	. . .
	nop			;8d33	00		.
	nop			;8d34	00		.
	nop			;8d35	00		.
	nop			;8d36	00		.
	nop			;8d37	00		.
	nop			;8d38	00		.
	nop			;8d39	00		.
	nop			;8d3a	00		.
	nop			;8d3b	00		.
	nop			;8d3c	00		.
	nop			;8d3d	00		.
	nop			;8d3e	00		.
	nop			;8d3f	00		.
l8d40h:
	jr nz,l8d62h		;8d40	20 20		   
	jr nz,l8d64h		;8d42	20 20		   
	jr nz,l8d66h		;8d44	20 20		   
	jr nz,l8d68h		;8d46	20 20		   
	jr nz,l8d6ah		;8d48	20 20		   
	jr nz,l8d6ch		;8d4a	20 20		   
	jr nz,l8d6eh		;8d4c	20 20		   
	jr nz,l8d70h		;8d4e	20 20		   
	jr nz,l8d72h		;8d50	20 20		   
	jr nz,l8d74h		;8d52	20 20		   
	jr nz,l8d76h		;8d54	20 20		   
	jr nz,l8d78h		;8d56	20 20		   
	jr nz,l8d7ah		;8d58	20 20		   
	jr nz,l8d7ch		;8d5a	20 20		   
	jr nz,l8d7eh		;8d5c	20 20		   
	jr nz,l8d80h		;8d5e	20 20		   
	jr nz,l8d82h		;8d60	20 20		   
l8d62h:
	jr nz,l8d84h		;8d62	20 20		   
l8d64h:
	jr nz,l8d86h		;8d64	20 20		   
l8d66h:
	jr nz,l8d88h		;8d66	20 20		   
l8d68h:
	jr nz,l8d8ah		;8d68	20 20		   
l8d6ah:
	jr nz,l8d8ch		;8d6a	20 20		   
l8d6ch:
	jr nz,l8d8eh		;8d6c	20 20		   
l8d6eh:
	jr nz,l8d90h		;8d6e	20 20		   
l8d70h:
	jr nz,l8d92h		;8d70	20 20		   
l8d72h:
	jr nz,l8d94h		;8d72	20 20		   
l8d74h:
	jr nz,l8d96h		;8d74	20 20		   
l8d76h:
	jr nz,l8d98h		;8d76	20 20		   
l8d78h:
	jr nz,l8d9ah		;8d78	20 20		   
l8d7ah:
	jr nz,l8d9ch		;8d7a	20 20		   
l8d7ch:
	jr nz,l8d9eh		;8d7c	20 20		   
l8d7eh:
	jr nz,l8da0h		;8d7e	20 20		   
l8d80h:
	jr nz,l8da2h		;8d80	20 20		   
l8d82h:
	jr nz,l8da4h		;8d82	20 20		   
l8d84h:
	jr nz,l8da6h		;8d84	20 20		   
l8d86h:
	jr nz,l8da8h		;8d86	20 20		   
l8d88h:
	jr nz,l8daah		;8d88	20 20		   
l8d8ah:
	jr nz,l8dach		;8d8a	20 20		   
l8d8ch:
	jr nz,l8daeh		;8d8c	20 20		   
l8d8eh:
	jr nz,l8db0h		;8d8e	20 20		   
l8d90h:
	jr nz,l8db2h		;8d90	20 20		   
l8d92h:
	jr nz,l8db4h		;8d92	20 20		   
l8d94h:
	jr nz,l8db6h		;8d94	20 20		   
l8d96h:
	jr nz,l8db8h		;8d96	20 20		   
l8d98h:
	jr nz,l8dbah		;8d98	20 20		   
l8d9ah:
	jr nz,l8dbch		;8d9a	20 20		   
l8d9ch:
	jr nz,l8dbeh		;8d9c	20 20		   
l8d9eh:
	jr nz,l8dc0h		;8d9e	20 20		   
l8da0h:
	jr nz,l8dc2h		;8da0	20 20		   
l8da2h:
	jr nz,l8dc4h		;8da2	20 20		   
l8da4h:
	jr nz,l8dc6h		;8da4	20 20		   
l8da6h:
	jr nz,l8dc8h		;8da6	20 20		   
l8da8h:
	jr nz,l8dcah		;8da8	20 20		   
l8daah:
	jr nz,l8dcch		;8daa	20 20		   
l8dach:
	jr nz,l8dceh		;8dac	20 20		   
l8daeh:
	jr nz,l8dd0h		;8dae	20 20		   
l8db0h:
	jr nz,l8dd2h		;8db0	20 20		   
l8db2h:
	jr nz,l8dd4h		;8db2	20 20		   
l8db4h:
	jr nz,l8dd6h		;8db4	20 20		   
l8db6h:
	jr nz,l8dd8h		;8db6	20 20		   
l8db8h:
	jr nz,l8ddah		;8db8	20 20		   
l8dbah:
	jr nz,l8ddch		;8dba	20 20		   
l8dbch:
	jr nz,$+34		;8dbc	20 20		   
l8dbeh:
	jr nz,l8de0h		;8dbe	20 20		   
l8dc0h:
	jr nz,$+34		;8dc0	20 20		   
l8dc2h:
	jr nz,l8de4h		;8dc2	20 20		   
l8dc4h:
	jr nz,l8de6h		;8dc4	20 20		   
l8dc6h:
	jr nz,l8de8h		;8dc6	20 20		   
l8dc8h:
	jr nz,l8deah		;8dc8	20 20		   
l8dcah:
	jr nz,$+34		;8dca	20 20		   
l8dcch:
	jr nz,l8deeh		;8dcc	20 20		   
l8dceh:
	jr nz,l8df0h		;8dce	20 20		   
l8dd0h:
	jr nz,l8df2h		;8dd0	20 20		   
l8dd2h:
	jr nz,l8df4h		;8dd2	20 20		   
l8dd4h:
	jr nz,l8df6h		;8dd4	20 20		   
l8dd6h:
	jr nz,l8df8h		;8dd6	20 20		   
l8dd8h:
	jr nz,l8dfah		;8dd8	20 20		   
l8ddah:
	jr nz,l8dfch		;8dda	20 20		   
l8ddch:
	ld b,a			;8ddc	47		G
l8dddh:
	ld (03349h),a		;8ddd	32 49 33	2 I 3
l8de0h:
	ld a,(04c09h)		;8de0	3a 09 4c	: . L
	ld b,h			;8de3	44		D
l8de4h:
	jr nz,l8e0eh		;8de4	20 28		  (
l8de6h:
	ld c,b			;8de6	48		H
	ld c,h			;8de7	4c		L
l8de8h:
	add hl,hl		;8de8	29		)
	inc l			;8de9	2c		,
l8deah:
	dec (hl)		;8dea	35		5
	jr nc,l8dfah		;8deb	30 0d		0 .
	ld a,(bc)		;8ded	0a		.
l8deeh:
	add hl,bc		;8dee	09		.
	ld c,c			;8def	49		I
l8df0h:
	ld c,(hl)		;8df0	4e		N
	ld b,e			;8df1	43		C
l8df2h:
	jr nz,l8e3ch		;8df2	20 48		  H
l8df4h:
	ld c,h			;8df4	4c		L
	dec c			;8df5	0d		.
l8df6h:
	ld a,(bc)		;8df6	0a		.
	add hl,bc		;8df7	09		.
l8df8h:
	ld c,h			;8df8	4c		L
	ld b,h			;8df9	44		D
l8dfah:
	jr nz,l8e3eh		;8dfa	20 42		  B
l8dfch:
	inc l			;8dfc	2c		,
	inc sp			;8dfd	33		3
	dec c			;8dfe	0d		.
	ld a,(bc)		;8dff	0a		.
	ld c,c			;8e00	49		I
	ld c,(hl)		;8e01	4e		N
	ld c,c			;8e02	49		I
	ld (0093ah),a		;8e03	32 3a 09	2 : .
	ld c,h			;8e06	4c		L
	ld b,h			;8e07	44		D
	jr nz,l8e32h		;8e08	20 28		  (
	ld c,b			;8e0a	48		H
	ld c,h			;8e0b	4c		L
	add hl,hl		;8e0c	29		)
	inc l			;8e0d	2c		,
l8e0eh:
	jr nc,l8e1dh		;8e0e	30 0d		0 .
	ld a,(bc)		;8e10	0a		.
	add hl,bc		;8e11	09		.
	ld c,c			;8e12	49		I
	ld c,(hl)		;8e13	4e		N
	ld b,e			;8e14	43		C
	jr nz,$+74		;8e15	20 48		  H
	ld c,h			;8e17	4c		L
	dec c			;8e18	0d		.
	ld a,(bc)		;8e19	0a		.
	add hl,bc		;8e1a	09		.
	ld b,h			;8e1b	44		D
	ld c,d			;8e1c	4a		J
l8e1dh:
	ld c,(hl)		;8e1d	4e		N
	ld e,d			;8e1e	5a		Z
	jr nz,$+75		;8e1f	20 49		  I
	ld c,(hl)		;8e21	4e		N
	ld c,c			;8e22	49		I
	ld (0401dh),a		;8e23	32 1d 40	2 . @
	defb 0fdh,002h,04dh ;illegal sequence	;8e26	fd 02 4d	. . M
	nop			;8e29	00		.
	dec e			;8e2a	1d		.
	ld b,b			;8e2b	40		@
	ld e,040h		;8e2c	1e 40		. @
	defb 0fdh,002h,04dh ;illegal sequence	;8e2e	fd 02 4d	. . M
	nop			;8e31	00		.
l8e32h:
	defb 0fdh,002h,04dh ;illegal sequence	;8e32	fd 02 4d	. . M
	nop			;8e35	00		.
	inc l			;8e36	2c		,
	inc bc			;8e37	03		.
	defb 0fdh,002h,04dh ;illegal sequence	;8e38	fd 02 4d	. . M
	nop			;8e3b	00		.
l8e3ch:
	inc (hl)		;8e3c	34		4
	nop			;8e3d	00		.
l8e3eh:
	ei			;8e3e	fb		.
	inc bc			;8e3f	03		.
	ld c,000h		;8e40	0e 00		. .
	ld d,02bh		;8e42	16 2b		. +
	or (hl)			;8e44	b6		.
	ld a,(01421h)		;8e45	3a 21 14	: ! .
	add a,e			;8e48	83		.
	ld (bc),a		;8e49	02		.
	ld c,(hl)		;8e4a	4e		N
	adc a,c			;8e4b	89		.
	cp b			;8e4c	b8		.
	nop			;8e4d	00		.
	ld d,0b1h		;8e4e	16 b1		. .
	rlca			;8e50	07		.
	nop			;8e51	00		.
	ld a,b			;8e52	78		x
	sub c			;8e53	91		.
	ld l,a			;8e54	6f		o
	sub b			;8e55	90		.
	sub c			;8e56	91		.
	sub c			;8e57	91		.
	cp l			;8e58	bd		.
	adc a,(hl)		;8e59	8e		.

; ===========================================================================
; EXECUTABLE CODE BEGINS HERE (8E5Ah - B07Eh)
; ===========================================================================

; ===========================================================================
; MAIN ENTRY POINT
; Saves the caller's stack pointer, initializes the board to starting
; position, sets default difficulty level to 2, refreshes the screen
; display, then falls through to the main menu loop.
; ===========================================================================
l8e5ah:
	ld hl,00000h		;8e5a	21 00 00	! . .	; HL = 0
	add hl,sp		;8e5d	39		9	; HL = caller's stack pointer
	ld (l887ah),hl		;8e5e	22 7a 88	" z .	; Save caller's SP for later restoration
	ld sp,l8e5ah		;8e61	31 5a 8e	1 Z .	; Set our own stack (grows down from 8E5Ah)
	xor a			;8e64	af		.	; A = 0
	ld (laeebh),a		;8e65	32 eb ae	2 . .	; Clear active player indicator
	ld hl,lb07fh		;8e68	21 7f b0	! . .	; HL -> "Play/colour/set up?" string
	ld (089b0h),hl		;8e6b	22 b0 89	" . .	; Store menu prompt pointer
	call sub_8fd1h		;8e6e	cd d1 8f	. . .	; Initialize board to starting position
	ld a,032h		;8e71	3e 32		> 2	; A = '2' (default difficulty level)
	call sub_8f34h		;8e73	cd 34 8f	. 4 .	; Set level parameters for level 2
	call la958h		;8e76	cd 58 a9	. X .	; Refresh full screen display
; ---------------------------------------------------------------------------
; MAIN MENU LOOP
; Displays "Play/colour/set up? p, c or s" and dispatches on keypress.
; ---------------------------------------------------------------------------
l8e79h:
	di			;8e79	f3		.	; Disable interrupts
	im 1			;8e7a	ed 56		. V	; Set interrupt mode 1 (normal)
	ei			;8e7c	fb		.	; Re-enable interrupts
	ld de,lb07fh		;8e7d	11 7f b0	. . .	; DE -> menu prompt string
	ld b,01eh		;8e80	06 1e		. .	; B = 30 chars to print
	call sub_b038h		;8e82	cd 38 b0	. 8 .	; Print menu prompt string
	call sub_af9bh		;8e85	cd 9b af	. . .	; Wait for keypress
	cp 053h			;8e88	fe 53		. S	; Key = 'S' (Setup)?
	jp z,la623h		;8e8a	ca 23 a6	. # .	; Yes -> enter setup position mode
	cp 043h			;8e8d	fe 43		. C	; Key = 'C' (Configure)?
	jp z,la728h		;8e8f	ca 28 a7	. ( .	; Yes -> enter configure mode
	cp 050h			;8e92	fe 50		. P	; Key = 'P' (Play)?
	jr nz,l8e79h		;8e94	20 e3		  .	; No -> loop, ask again
	sub a			;8e96	97		.	; A = 0 (white moves first)
	ld (l882ch),a		;8e97	32 2c 88	2 , .	; Set side-to-move = white
	call sub_8f06h		;8e9a	cd 06 8f	. . .	; Choose human player color (W or B)
	call sub_8fd1h		;8e9d	cd d1 8f	. . .	; Initialize board to starting position
	call sub_a951h		;8ea0	cd 51 a9	. Q .	; Refresh board display
	call sub_8f1eh		;8ea3	cd 1e 8f	. . .	; Choose difficulty level (0-9)
; ---------------------------------------------------------------------------
; GAME LOOP - Alternates between computer and human moves
; ---------------------------------------------------------------------------
l8ea6h:
	call sub_8eefh		;8ea6	cd ef 8e	. . .	; Set up for computer's move (IM2 for thinking)
	ld a,(l882bh)		;8ea9	3a 2b 88	: + .	; A = human player color
	and a			;8eac	a7		.	; Is human white (0)?
	jr nz,l8ebah		;8ead	20 0b		  .	; No -> human is black, human moves first
	; Human is white: computer moves first, then human
	call sub_97d8h		;8eaf	cd d8 97	. . .	; Computer thinks and makes move
l8eb2h:
	call sub_8ef6h		;8eb2	cd f6 8e	. . .	; Set up for human's move (IM2 for input)
	call sub_917bh		;8eb5	cd 7b 91	. { .	; Get human's move
	jr l8ec3h		;8eb8	18 09		. .	; Skip to post-move processing
l8ebah:
	; Human is black: human moves first, then computer
	call sub_917bh		;8eba	cd 7b 91	. { .	; Get human's move
l8ebdh:
	call sub_8ef6h		;8ebd	cd f6 8e	. . .	; Set up for computer move
	call sub_97d8h		;8ec0	cd d8 97	. . .	; Computer thinks and makes move
l8ec3h:
	; --- Post-move: scroll move display and increment move clock ---
	call sub_a845h		;8ec3	cd 45 a8	. E .	; Scroll move history text display up
	ld hl,0b0c8h		;8ec6	21 c8 b0	! . .	; HL -> move clock seconds digit
	ld a,020h		;8ec9	3e 20		>  	; A = ' ' (space = clock not started yet)
	cp (hl)			;8ecb	be		.	; Clock started?
	ld a,03ah		;8ecc	3e 3a		> :	; A = ':' (BCD overflow threshold)
	jr z,l8ed6h		;8ece	28 06		( .	; Clock not started -> skip seconds
	inc (hl)		;8ed0	34		4	; Increment seconds ones digit
	cp (hl)			;8ed1	be		.	; Overflow past '9'?
	jr nz,l8ee9h		;8ed2	20 15		  .	; No -> done with clock
	ld (hl),030h		;8ed4	36 30		6 0	; Reset seconds ones to '0'
l8ed6h:
	dec hl			;8ed6	2b		+	; Move to seconds tens digit
	inc (hl)		;8ed7	34		4	; Increment seconds tens
	cp (hl)			;8ed8	be		.	; Overflow?
	jr nz,l8ee9h		;8ed9	20 0e		  .	; No -> done
	ld (hl),030h		;8edb	36 30		6 0	; Reset to '0'
	dec hl			;8edd	2b		+	; Move to minutes digit
	inc (hl)		;8ede	34		4	; Increment minutes
	cp (hl)			;8edf	be		.	; Overflow?
	jr nz,l8ee9h		;8ee0	20 07		  .	; No -> done
	ld (hl),031h		;8ee2	36 31		6 1	; Set to '1' (roll to 1:00)
	ld a,030h		;8ee4	3e 30		> 0	; Reset seconds
	ld (0b0c8h),a		;8ee6	32 c8 b0	2 . .	; Store '0' in seconds position
l8ee9h:
	ld hl,l8831h		;8ee9	21 31 88	! 1 .	; HL -> move number counter
	inc (hl)		;8eec	34		4	; Increment move number
	jr l8ea6h		;8eed	18 b7		. .	; Loop back to next game turn
; ---------------------------------------------------------------------------
; SET UP FOR COMPUTER MOVE
; Sets player indicator to 1 (computer), configures IM2 interrupt vector
; for cooperative multitasking during search.
; ---------------------------------------------------------------------------
sub_8eefh:
	ld a,001h		;8eef	3e 01		> .	; Player indicator = 1 (computer)
	ld hl,l8dceh+1		;8ef1	21 cf 8d	! . .	; HL -> IM2 vector for computer thinking
	jr l8efbh		;8ef4	18 05		. .	; Jump to common setup code
; ---------------------------------------------------------------------------
; SET UP FOR HUMAN MOVE
; Sets player indicator to 2 (human), configures IM2 interrupt vector.
; ---------------------------------------------------------------------------
sub_8ef6h:
	ld a,002h		;8ef6	3e 02		> .	; Player indicator = 2 (human)
	ld hl,l8dd4h+1		;8ef8	21 d5 8d	! . .	; HL -> IM2 vector for human input
l8efbh:
	ld (laeebh),a		;8efb	32 eb ae	2 . .	; Store player indicator
	ld (l8874h+1),hl	;8efe	22 75 88	" u .	; Set IM2 interrupt vector pointer
	di			;8f01	f3		.	; Disable interrupts
	im 2			;8f02	ed 5e		. ^	; Switch to interrupt mode 2
	ei			;8f04	fb		.	; Re-enable interrupts
	ret			;8f05	c9		.
; ---------------------------------------------------------------------------
; CHOOSE COLOR - Prompts "Choose white or black, w or b."
; Sets human player color: 0 = white, 80h = black.
; ---------------------------------------------------------------------------
sub_8f06h:
	ld de,0b09dh		;8f06	11 9d b0	. . .	; DE -> "Choose white or black" string
	ld b,01fh		;8f09	06 1f		. .	; B = 31 chars to print
	call sub_b038h		;8f0b	cd 38 b0	. 8 .	; Print prompt string
	call sub_af9bh		;8f0e	cd 9b af	. . .	; Wait for keypress
	cp 057h			;8f11	fe 57		. W	; Key = 'W'?
	jr z,l8f6bh		;8f13	28 56		( V	; Yes -> set white (80h)
	cp 042h			;8f15	fe 42		. B	; Key = 'B'?
	jr nz,sub_8f06h		;8f17	20 ed		  .	; Neither -> ask again
	sub a			;8f19	97		.	; A = 0 (human plays white... wait, B=black, A=0?)
l8f1ah:
	ld (l882bh),a		;8f1a	32 2b 88	2 + .	; Store human player color
	ret			;8f1d	c9		.
; ---------------------------------------------------------------------------
; CHOOSE LEVEL - Prompts "Select level, (0-9)", accepts digit 0-9.
; ---------------------------------------------------------------------------
sub_8f1eh:
	call sub_af9eh		;8f1e	cd 9e af	. . .	; Clear status line
	ld de,lb122h		;8f21	11 22 b1	. " .	; DE -> "Select level, (0-9)" string
	ld b,014h		;8f24	06 14		. .	; B = 20 chars
	call sub_b038h		;8f26	cd 38 b0	. 8 .	; Print prompt
	call sub_af9bh		;8f29	cd 9b af	. . .	; Wait for keypress
	cp 030h			;8f2c	fe 30		. 0	; Key < '0'?
	jr c,sub_8f1eh		;8f2e	38 ee		8 .	; Yes -> ask again
	cp 03ah			;8f30	fe 3a		. :	; Key > '9'?
	jr nc,sub_8f1eh		;8f32	30 ea		0 .	; Yes -> ask again
; ---------------------------------------------------------------------------
; SET LEVEL PARAMETERS - Loads 7 bytes from level table into game config.
; Entry: A = ASCII digit '0'-'9'
; ---------------------------------------------------------------------------
sub_8f34h:
	ld (l8874h),a		;8f34	32 74 88	2 t .
	sub 030h		;8f37	d6 30		. 0
	ld bc,00007h		;8f39	01 07 00	. . .
	ld hl,l89b2h		;8f3c	21 b2 89	! . .
l8f3fh:
	and a			;8f3f	a7		.
	jp z,l8f48h		;8f40	ca 48 8f	. H .
	add hl,bc		;8f43	09		.
	dec a			;8f44	3d		=
	jp l8f3fh		;8f45	c3 3f 8f	. ? .
l8f48h:
	ld a,(hl)		;8f48	7e		~
	ld (l885bh),a		;8f49	32 5b 88	2 [ .
	inc hl			;8f4c	23		#
	ld a,(hl)		;8f4d	7e		~
	ld (l8831h+1),a		;8f4e	32 32 88	2 2 .
	inc hl			;8f51	23		#
	ld a,(hl)		;8f52	7e		~
	ld (l885eh+2),a		;8f53	32 60 88	2 ` .
	inc hl			;8f56	23		#
	ld a,(hl)		;8f57	7e		~
	ld (l885ch),a		;8f58	32 5c 88	2 \ .
	inc hl			;8f5b	23		#
	ld a,(hl)		;8f5c	7e		~
	ld (l885dh),a		;8f5d	32 5d 88	2 ] .
	inc hl			;8f60	23		#
	ld a,(hl)		;8f61	7e		~
	ld (l885eh),a		;8f62	32 5e 88	2 ^ .
	inc hl			;8f65	23		#
	ld a,(hl)		;8f66	7e		~
	ld (l885eh+1),a		;8f67	32 5f 88	2 _ .
	ret			;8f6a	c9		.
l8f6bh:
	ld a,080h		;8f6b	3e 80		> .
	jr l8f1ah		;8f6d	18 ab		. .
; ---------------------------------------------------------------------------
; INITIALIZE PAWN STRUCTURE TABLES
; Clears 78h-byte arrays at 8C50h (white) and 8CC8h (black),
; then fills pawn attack squares from king positions using
; direction vectors at 8880h.
; ---------------------------------------------------------------------------
sub_8f6fh:
	push af			;8f6f	f5		.
	push hl			;8f70	e5		.
	push de			;8f71	d5		.
	push ix			;8f72	dd e5		. .
	xor a			;8f74	af		.	; A = 0 for clearing
	ld b,078h		;8f75	06 78		. x	; 78h bytes to clear
	ld hl,l8c50h		;8f77	21 50 8c	! P .	; HL -> white pawn table
	ld de,l8cc8h		;8f7a	11 c8 8c	. . .	; DE -> black pawn table
l8f7dh:
	ld (hl),a		;8f7d	77		w
	ld (de),a		;8f7e	12		.
	inc hl			;8f7f	23		#
	inc de			;8f80	13		.
	djnz l8f7dh		;8f81	10 fa		. .
	ld de,l894eh		;8f83	11 4e 89	. N .
	ld hl,l8c50h		;8f86	21 50 8c	! P .
	ld b,000h		;8f89	06 00		. .
	ld a,(de)		;8f8b	1a		.
	ld c,a			;8f8c	4f		O
	add hl,bc		;8f8d	09		.
	ld b,008h		;8f8e	06 08		. .
	ld ix,l8880h		;8f90	dd 21 80 88	. ! . .
l8f94h:
	push hl			;8f94	e5		.
	ld e,(ix+000h)		;8f95	dd 5e 00	. ^ .
	ld d,000h		;8f98	16 00		. .
	bit 7,e			;8f9a	cb 7b		. {
	jr z,l8f9fh		;8f9c	28 01		( .
	dec d			;8f9e	15		.
l8f9fh:
	add hl,de		;8f9f	19		.
	ld (hl),001h		;8fa0	36 01		6 .
	pop hl			;8fa2	e1		.
	inc ix			;8fa3	dd 23		. #
	djnz l8f94h		;8fa5	10 ed		. .
	ld de,l894fh		;8fa7	11 4f 89	. O .
	ld hl,l8cc8h		;8faa	21 c8 8c	! . .
	ld b,000h		;8fad	06 00		. .
	ld a,(de)		;8faf	1a		.
	ld c,a			;8fb0	4f		O
	add hl,bc		;8fb1	09		.
	ld b,008h		;8fb2	06 08		. .
	ld ix,l8880h		;8fb4	dd 21 80 88	. ! . .
l8fb8h:
	push hl			;8fb8	e5		.
	ld e,(ix+000h)		;8fb9	dd 5e 00	. ^ .
	ld d,000h		;8fbc	16 00		. .
	bit 7,e			;8fbe	cb 7b		. {
	jr z,l8fc3h		;8fc0	28 01		( .
	dec d			;8fc2	15		.
l8fc3h:
	add hl,de		;8fc3	19		.
	ld (hl),001h		;8fc4	36 01		6 .
	pop hl			;8fc6	e1		.
	inc ix			;8fc7	dd 23		. #
	djnz l8fb8h		;8fc9	10 ed		. .
	pop ix			;8fcb	dd e1		. .
	pop de			;8fcd	d1		.
	pop hl			;8fce	e1		.
	pop af			;8fcf	f1		.
	ret			;8fd0	c9		.
; ---------------------------------------------------------------------------
; INITIALIZE BOARD
; Sets up the starting position in the 10x12 mailbox board at
; 88B4h. Fills borders with FFh, places piece codes in ranks
; 1/8, pawns in ranks 2/7, and empty squares elsewhere.
; ---------------------------------------------------------------------------
sub_8fd1h:
	ld hl,l8000h		;8fd1	21 00 80	! . .	; Opening book pointer
	ld (l8821h),hl		;8fd4	22 21 88	" ! .
	ld b,078h		;8fd7	06 78		. x	; 78h = 120 squares in 10x12 board
	ld hl,l88b4h		;8fd9	21 b4 88	! . .	; HL -> start of board array
l8fdch:
	ld (hl),0ffh		;8fdc	36 ff		6 .	; FFh = off-board sentinel
	inc hl			;8fde	23		#
	djnz l8fdch		;8fdf	10 fb		. .	; Fill entire board with FFh
	ld b,008h		;8fe1	06 08		. .
	ld ix,l88b4h		;8fe3	dd 21 b4 88	. ! . .
l8fe7h:
	ld a,(ix-008h)		;8fe7	dd 7e f8	. ~ .
	ld (ix+015h),a		;8fea	dd 77 15	. w .
	set 7,a			;8fed	cb ff		. .
	ld (ix+05bh),a		;8fef	dd 77 5b	. w [
	ld (ix+01fh),001h	;8ff2	dd 36 1f 01	. 6 . .
	ld (ix+051h),081h	;8ff6	dd 36 51 81	. 6 Q .
	ld (ix+029h),000h	;8ffa	dd 36 29 00	. 6 ) .
	ld (ix+033h),000h	;8ffe	dd 36 33 00	. 6 3 .
	ld (ix+03dh),000h	;9002	dd 36 3d 00	. 6 = .
	ld (ix+047h),000h	;9006	dd 36 47 00	. 6 G .
	inc ix			;900a	dd 23		. #
	djnz l8fe7h		;900c	10 d9		. .
	ld ix,l894eh		;900e	dd 21 4e 89	. ! N .
	ld (ix+000h),019h	;9012	dd 36 00 19	. 6 . .
	ld (ix+001h),05fh	;9016	dd 36 01 5f	. 6 . _
	ld (ix+002h),018h	;901a	dd 36 02 18	. 6 . .
	ld (ix+003h),05eh	;901e	dd 36 03 5e	. 6 . ^
	call sub_8f6fh		;9022	cd 6f 8f	. o .
	ld a,001h		;9025	3e 01		> .
	ld (l8831h),a		;9027	32 31 88	2 1 .
	ld (l884dh),a		;902a	32 4d 88	2 M .
	ld (l8871h+2),a		;902d	32 73 88	2 s .
	ld hl,0b0c6h		;9030	21 c6 b0	! . .
	ld (hl),030h		;9033	36 30		6 0
	inc hl			;9035	23		#
	ld (hl),031h		;9036	36 31		6 1
	inc hl			;9038	23		#
	ld (hl),020h		;9039	36 20		6  
	ld hl,l8d40h		;903b	21 40 8d	! @ .
	ld b,09ch		;903e	06 9c		. .
l9040h:
	ld (hl),020h		;9040	36 20		6  
	inc hl			;9042	23		#
	djnz l9040h		;9043	10 fb		. .
	ld hl,laeebh+1		;9045	21 ec ae	! . .
	ld c,002h		;9048	0e 02		. .
l904ah:
	ld (hl),032h		;904a	36 32		6 2
	inc hl			;904c	23		#
	ld b,003h		;904d	06 03		. .
l904fh:
	ld (hl),000h		;904f	36 00		6 .
	inc hl			;9051	23		#
	djnz l904fh		;9052	10 fb		. .
	dec c			;9054	0d		.
	jr nz,l904ah		;9055	20 f3		  .
	ret			;9057	c9		.
sub_9058h:
	call sub_9060h		;9058	cd 60 90	. ` .
	ld a,020h		;905b	3e 20		>  
	call sub_afb7h		;905d	cd b7 af	. . .
sub_9060h:
	ld a,(l8879h)		;9060	3a 79 88	: y .
	sub 008h		;9063	d6 08		. .
	ld (l8879h),a		;9065	32 79 88	2 y .
	ret			;9068	c9		.
l9069h:
	call sub_9058h		;9069	cd 58 90	. X .
; ---------------------------------------------------------------------------
; GET COLUMN INPUT
; Accepts a key press for file selection (A-H).
; Rejects any character outside that range and retries.
; Returns: A = ASCII 'A'-'H'
; ---------------------------------------------------------------------------
sub_906ch:
	call sub_9083h		;906c	cd 83 90	. . .
	cp 041h			;906f	fe 41		. A	; Key < 'A'?
	jr c,l9069h		;9071	38 f6		8 .	; Yes -> reject
	cp 049h			;9073	fe 49		. I	; Key > 'H'?
	jr nc,l9069h		;9075	30 f2		0 .	; Yes -> reject
	ret			;9077	c9		.
l9078h:
	call sub_90beh		;9078	cd be 90	. . .
l907bh:
	pop af			;907b	f1		.
	pop af			;907c	f1		.
	call sub_af9eh		;907d	cd 9e af	. . .
	jp l917eh		;9080	c3 7e 91	. ~ .
; ---------------------------------------------------------------------------
; GET KEY WITH COMMAND DISPATCH
; Reads a key and checks for special commands:
;   X=exit, L=level, R=reverse board, Z=print screen,
;   T=toggle side, 0=cancel move entry.
; ---------------------------------------------------------------------------
sub_9083h:
	call sub_af1ch		;9083	cd 1c af	. . .	; Read keyboard
	cp 058h			;9086	fe 58		. X	; 'X' = exit?
	jr z,l90b8h		;9088	28 2e		( .
	cp 04ch			;908a	fe 4c		. L	; 'L' = change level?
	jr z,l90a1h		;908c	28 13		( .
	cp 052h			;908e	fe 52		. R	; 'R' = reverse board?
	jr z,l9078h		;9090	28 e6		( .
	cp 030h			;9092	fe 30		. 0	; '0' = cancel?
	jr z,l907bh		;9094	28 e5		( .
	cp 054h			;9096	fe 54		. T	; 'T' = toggle side?
	jp z,l9175h		;9098	ca 75 91	. u .
	cp 05ah			;909b	fe 5a		. Z	; 'Z' = print screen?
	jp z,l9110h		;909d	ca 10 91	. . .
	ret			;90a0	c9		.
l90a1h:
	call sub_8f1eh		;90a1	cd 1e 8f	. . .
	call sub_aab2h		;90a4	cd b2 aa	. . .
	jr l907bh		;90a7	18 d2		. .
l90a9h:
	call sub_9058h		;90a9	cd 58 90	. X .
; ---------------------------------------------------------------------------
; GET ROW INPUT
; Accepts a key press for rank selection (1-8).
; Rejects any character outside that range and retries.
; Returns: A = ASCII '1'-'8'
; ---------------------------------------------------------------------------
sub_90ach:
	call sub_9083h		;90ac	cd 83 90	. . .
	cp 031h			;90af	fe 31		. 1	; Key < '1'?
	jr c,l90a9h		;90b1	38 f6		8 .	; Yes -> reject
	cp 039h			;90b3	fe 39		. 9	; Key > '8'?
	jr nc,l90a9h		;90b5	30 f2		0 .	; Yes -> reject
	ret			;90b7	c9		.
l90b8h:
	pop hl			;90b8	e1		.
	pop hl			;90b9	e1		.
	pop hl			;90ba	e1		.
	jp l8e79h		;90bb	c3 79 8e	. y .
sub_90beh:
	xor a			;90be	af		.
	ld (l884dh),a		;90bf	32 4d 88	2 M .
	ld (l8871h),a		;90c2	32 71 88	2 q .
	ld (l8871h+2),a		;90c5	32 73 88	2 s .
	ld de,lb2b5h		;90c8	11 b5 b2	. . .
	ld hl,000a8h		;90cb	21 a8 00	! . .
	ld b,00ch		;90ce	06 0c		. .
	call sub_b03bh		;90d0	cd 3b b0	. ; .
	call sub_af9eh		;90d3	cd 9e af	. . .
	ld a,(l882bh)		;90d6	3a 2b 88	: + .
	xor 080h		;90d9	ee 80		. .
	ld (l882ch),a		;90db	32 2c 88	2 , .
	call sub_9994h		;90de	cd 94 99	. . .
	ld hl,(l8825h)		;90e1	2a 25 88	* % .
	inc hl			;90e4	23		#
	inc hl			;90e5	23		#
	ld d,(hl)		;90e6	56		V
	inc hl			;90e7	23		#
	ld c,(hl)		;90e8	4e		N
	call sub_9c92h		;90e9	cd 92 9c	. . .
	ex de,hl		;90ec	eb		.
	ld hl,028a8h		;90ed	21 a8 28	! . (
	ld a,e			;90f0	7b		{
	call sub_afaeh		;90f1	cd ae af	. . .
	ld a,d			;90f4	7a		z
	call sub_afb7h		;90f5	cd b7 af	. . .
	ld a,02dh		;90f8	3e 2d		> -
	call sub_afb7h		;90fa	cd b7 af	. . .
	ld d,c			;90fd	51		Q
	call sub_9c92h		;90fe	cd 92 9c	. . .
	ex de,hl		;9101	eb		.
	ld a,e			;9102	7b		{
	call sub_afb7h		;9103	cd b7 af	. . .
	ld a,d			;9106	7a		z
	call sub_afb7h		;9107	cd b7 af	. . .
	ld a,001h		;910a	3e 01		> .
	ld (l8871h+2),a		;910c	32 73 88	2 s .
	ret			;910f	c9		.
l9110h:
	ld hl,l89a3h		;9110	21 a3 89	! . .
	ld a,(hl)		;9113	7e		~
	inc hl			;9114	23		#
	ld (hl),a		;9115	77		w
	dec hl			;9116	2b		+
	ld (hl),000h		;9117	36 00		6 .
	call sub_a951h		;9119	cd 51 a9	. Q .
	di			;911c	f3		.
	ld b,0b0h		;911d	06 b0		. .
	ld hl,04000h		;911f	21 00 40	! . @
l9122h:
	push hl			;9122	e5		.
	push bc			;9123	c5		.
	call sub_914ch		;9124	cd 4c 91	. L .
	pop bc			;9127	c1		.
	pop hl			;9128	e1		.
	inc h			;9129	24		$
	ld a,h			;912a	7c		|
	and 007h		;912b	e6 07		. .
	jr nz,l9139h		;912d	20 0a		  .
	ld a,l			;912f	7d		}
	add a,020h		;9130	c6 20		.  
	ld l,a			;9132	6f		o
	ccf			;9133	3f		?
	sbc a,a			;9134	9f		.
	and 0f8h		;9135	e6 f8		. .
	add a,h			;9137	84		.
	ld h,a			;9138	67		g
l9139h:
	djnz l9122h		;9139	10 e7		. .
	ld a,004h		;913b	3e 04		> .
	out (0fbh),a		;913d	d3 fb		. .
	ei			;913f	fb		.
	ld a,(l89a4h)		;9140	3a a4 89	: . .
	ld (l89a3h),a		;9143	32 a3 89	2 . .
	call sub_a951h		;9146	cd 51 a9	. Q .
	jp l907bh		;9149	c3 7b 90	. { .
; ---------------------------------------------------------------------------
; SCREEN DUMP TO PRINTER (line output)
; Outputs one line of pixel data to the Timex 2068 thermal
; printer via port FBh. Sends 32 bytes as serial bit data.
; ---------------------------------------------------------------------------
sub_914ch:
	ld a,b			;914c	78		x
	cp 003h			;914d	fe 03		. .
	sbc a,a			;914f	9f		.
	and 002h		;9150	e6 02		. .
	out (0fbh),a		;9152	d3 fb		. .	; Select printer page
	ld d,a			;9154	57		W
l9155h:
	in a,(0fbh)		;9155	db fb		. .	; Read printer status
	add a,a			;9157	87		.
	ret m			;9158	f8		.
	jr nc,l9155h		;9159	30 fa		0 .
	ld c,020h		;915b	0e 20		.  
l915dh:
	ld e,(hl)		;915d	5e		^
	inc hl			;915e	23		#
	ld b,008h		;915f	06 08		. .
l9161h:
	rl d			;9161	cb 12		. .
	rl e			;9163	cb 13		. .
	rr d			;9165	cb 1a		. .
l9167h:
	in a,(0fbh)		;9167	db fb		. .
	rra			;9169	1f		.
	jr nc,l9167h		;916a	30 fb		0 .
	ld a,d			;916c	7a		z
	out (0fbh),a		;916d	d3 fb		. .
	djnz l9161h		;916f	10 f0		. .
	dec c			;9171	0d		.
	jr nz,l915dh		;9172	20 e9		  .
	ret			;9174	c9		.
; ---------------------------------------------------------------------------
; SCREEN DUMP TO PRINTER
; Uses the Timex 2068 thermal printer port (FBh) to output
; the screen contents. Iterates B0h lines of screen memory,
; converts pixel data to serial format for the printer.
; ---------------------------------------------------------------------------
l9175h:
	call sub_af69h		;9175	cd 69 af	. i .	; Toggle side (save/restore context)
	jp l907bh		;9178	c3 7b 90	. { .
; ---------------------------------------------------------------------------
; HUMAN MOVE ENTRY
; Gets from-square (file + rank) and to-square via algebraic
; input, validates entered move against the legal move list.
; If invalid, displays "Invalid move" and retries.
; ---------------------------------------------------------------------------
sub_917bh:
	call sub_aab2h		;917b	cd b2 aa	. . .
l917eh:
	ld a,001h		;917e	3e 01		> .
	ld (l8871h),a		;9180	32 71 88	2 q .
	call sub_b04ah		;9183	cd 4a b0	. J .
	ld de,lb0fch		;9186	11 fc b0	. . .
	ld b,01ah		;9189	06 1a		. .
	call sub_b038h		;918b	cd 38 b0	. 8 .
	call sub_906ch		;918e	cd 6c 90	. l .
	ld (l8ddah),a		;9191	32 da 8d	2 . .
	ld h,a			;9194	67		g
	call sub_90ach		;9195	cd ac 90	. . .
	ld (l8ddah+1),a		;9198	32 db 8d	2 . .
	ld l,a			;919b	6f		o
	call sub_9201h		;919c	cd 01 92	. . .
	ld (0b0c9h),a		;919f	32 c9 b0	2 . .
	ld a,02dh		;91a2	3e 2d		> -
	call sub_afb7h		;91a4	cd b7 af	. . .
	call sub_906ch		;91a7	cd 6c 90	. l .
	ld (l8ddch),a		;91aa	32 dc 8d	2 . .
	ld h,a			;91ad	67		g
	call sub_90ach		;91ae	cd ac 90	. . .
	ld (l8dddh),a		;91b1	32 dd 8d	2 . .
	ld l,a			;91b4	6f		o
	call sub_9201h		;91b5	cd 01 92	. . .
	ld (lb0cah),a		;91b8	32 ca b0	2 . .
	call sub_af9eh		;91bb	cd 9e af	. . .
	call sub_9210h		;91be	cd 10 92	. . .
	and a			;91c1	a7		.
	jr nz,l91f3h		;91c2	20 2f		  /
	ld hl,000a8h		;91c4	21 a8 00	! . .
	ld de,lb0e8h		;91c7	11 e8 b0	. . .
	ld b,00ch		;91ca	06 0c		. .
	call sub_b03bh		;91cc	cd 3b b0	. ; .
	call sub_928ah		;91cf	cd 8a 92	. . .
	ld de,l8ddah		;91d2	11 da 8d	. . .
	ld hl,(l8874h+1)	;91d5	2a 75 88	* u .
	ld a,(de)		;91d8	1a		.
	ld (hl),a		;91d9	77		w
	inc hl			;91da	23		#
	inc de			;91db	13		.
	ld a,(de)		;91dc	1a		.
	ld (hl),a		;91dd	77		w
	inc hl			;91de	23		#
	ld a,(l8871h+1)		;91df	3a 72 88	: r .
	and a			;91e2	a7		.
	ld a,02dh		;91e3	3e 2d		> -
	jr z,l91e9h		;91e5	28 02		( .
	ld a,078h		;91e7	3e 78		> x
l91e9h:
	ld (hl),a		;91e9	77		w
	inc hl			;91ea	23		#
	inc de			;91eb	13		.
	ld a,(de)		;91ec	1a		.
	ld (hl),a		;91ed	77		w
	inc hl			;91ee	23		#
	inc de			;91ef	13		.
	ld a,(de)		;91f0	1a		.
	ld (hl),a		;91f1	77		w
	ret			;91f2	c9		.
l91f3h:
	ld de,lb27eh		;91f3	11 7e b2	. ~ .
	ld hl,000a8h		;91f6	21 a8 00	! . .
	ld b,00ch		;91f9	06 0c		. .
	call sub_b03bh		;91fb	cd 3b b0	. ; .
	jp l917eh		;91fe	c3 7e 91	. ~ .	; Invalid -> retry
; ---------------------------------------------------------------------------
; CONVERT ALGEBRAIC TO BOARD INDEX
; Maps file letter (A-H) in H and rank digit (1-8) in L
; to a 10x12 mailbox square index: rank*10 + file offset.
; Returns: A = board square index
; ---------------------------------------------------------------------------
sub_9201h:
	ld a,l			;9201	7d		}	; L = rank digit ASCII
	sub 030h		;9202	d6 30		. 0	; Convert ASCII to number
	inc a			;9204	3c		<	; Ranks are 1-based
	ld d,a			;9205	57		W	; D = rank number
	ld e,00ah		;9206	1e 0a		. .	; E = 10 (mailbox width)
	call sub_9279h		;9208	cd 79 92	. y .	; D = rank * 10
	ld a,h			;920b	7c		|	; H = file letter ASCII
	sub 040h		;920c	d6 40		. @	; Convert 'A'->1, 'B'->2, etc.
	add a,d			;920e	82		.	; A = rank*10 + file = square index
	ret			;920f	c9		.
sub_9210h:
	ld hl,(l8821h)		;9210	2a 21 88	* ! .
	push hl			;9213	e5		.
	ld a,(l882bh)		;9214	3a 2b 88	: + .
	xor 080h		;9217	ee 80		. .
	ld (l882ch),a		;9219	32 2c 88	2 , .
	ld hl,l8969h		;921c	21 69 89	! i .
	ld (l881fh),hl		;921f	22 1f 88	" . .
	ld hl,l8400h		;9222	21 00 84	! . .
	ld (l8827h+2),hl	;9225	22 29 88	" ) .
	call sub_92ebh		;9228	cd eb 92	. . .
	ld ix,l8400h		;922b	dd 21 00 84	. ! . .
l922fh:
	ld a,(0b0c9h)		;922f	3a c9 b0	: . .
	cp (ix+002h)		;9232	dd be 02	. . .
	jr nz,l923fh		;9235	20 08		  .
	ld a,(lb0cah)		;9237	3a ca b0	: . .
	cp (ix+003h)		;923a	dd be 03	. . .
	jr z,l924eh		;923d	28 0f		( .
l923fh:
	ld e,(ix+000h)		;923f	dd 5e 00	. ^ .
	ld d,(ix+001h)		;9242	dd 56 01	. V .
	xor a			;9245	af		.
	cp d			;9246	ba		.
	jr z,l9260h		;9247	28 17		( .
	push de			;9249	d5		.
	pop ix			;924a	dd e1		. .
	jr l922fh		;924c	18 e1		. .
l924eh:
	ld (l8821h),ix		;924e	dd 22 21 88	. " ! .
	call sub_942ah		;9252	cd 2a 94	. * .
	call sub_933bh		;9255	cd 3b 93	. ; .
	and a			;9258	a7		.
	jr nz,l925dh		;9259	20 02		  .
	pop hl			;925b	e1		.
	ret			;925c	c9		.
l925dh:
	call sub_94e7h		;925d	cd e7 94	. . .
l9260h:
	ld a,001h		;9260	3e 01		> .
	pop hl			;9262	e1		.
	ld (l8821h),hl		;9263	22 21 88	" ! .
	ret			;9266	c9		.
sub_9267h:
	push bc			;9267	c5		.
	ld b,008h		;9268	06 08		. .
l926ah:
	sla d			;926a	cb 22		. "
	rla			;926c	17		.
	sub e			;926d	93		.
	jp m,l9274h		;926e	fa 74 92	. t .
	inc d			;9271	14		.
	jr l9275h		;9272	18 01		. .
l9274h:
	add a,e			;9274	83		.
l9275h:
	djnz l926ah		;9275	10 f3		. .
	pop bc			;9277	c1		.
	ret			;9278	c9		.
sub_9279h:
	push bc			;9279	c5		.
	sub a			;927a	97		.
	ld b,008h		;927b	06 08		. .
l927dh:
	bit 0,d			;927d	cb 42		. B
	jr z,l9282h		;927f	28 01		( .
	add a,e			;9281	83		.
l9282h:
	sra a			;9282	cb 2f		. /
	rr d			;9284	cb 1a		. .
	djnz l927dh		;9286	10 f5		. .
	pop bc			;9288	c1		.
	ret			;9289	c9		.
; ---------------------------------------------------------------------------
; EXECUTE AND DISPLAY MOVE
; Makes the move on the internal board and updates the screen
; display. Handles castling (multi-part moves with bit 6 flag).
; ---------------------------------------------------------------------------
sub_928ah:
	push ix			;928a	dd e5		. .
	push af			;928c	f5		.
	ld ix,(l8821h)		;928d	dd 2a 21 88	. * ! .
	ld c,(ix+002h)		;9291	dd 4e 02	. N .
	ld e,(ix+003h)		;9294	dd 5e 03	. ^ .
	call sub_92ceh		;9297	cd ce 92	. . .
	ld d,(ix+004h)		;929a	dd 56 04	. V .
	ld b,000h		;929d	06 00		. .
	bit 6,d			;929f	cb 72		. r
	jr z,l92cah		;92a1	28 27		( '
	ld de,00006h		;92a3	11 06 00	. . .
	add ix,de		;92a6	dd 19		. .
	ld c,(ix+002h)		;92a8	dd 4e 02	. N .
	ld e,(ix+003h)		;92ab	dd 5e 03	. ^ .
	ld a,e			;92ae	7b		{
	cp c			;92af	b9		.
	jr nz,l92b5h		;92b0	20 03		  .
	inc b			;92b2	04		.
	jr l92c7h		;92b3	18 12		. .
l92b5h:
	cp 01ah			;92b5	fe 1a		. .
	jr nz,l92bdh		;92b7	20 04		  .
	set 1,b			;92b9	cb c8		. .
	jr l92c7h		;92bb	18 0a		. .
l92bdh:
	cp 060h			;92bd	fe 60		. `
	jr nz,l92c5h		;92bf	20 04		  .
	set 1,b			;92c1	cb c8		. .
	jr l92c7h		;92c3	18 02		. .
l92c5h:
	set 2,b			;92c5	cb d0		. .
l92c7h:
	call sub_92ceh		;92c7	cd ce 92	. . .
l92cah:
	pop af			;92ca	f1		.
	pop ix			;92cb	dd e1		. .
	ret			;92cd	c9		.
sub_92ceh:
	push af			;92ce	f5		.
	push bc			;92cf	c5		.
	push de			;92d0	d5		.
	push hl			;92d1	e5		.
	ld a,c			;92d2	79		y
	ld (l8861h),a		;92d3	32 61 88	2 a .
	call sub_aae4h		;92d6	cd e4 aa	. . .
	call sub_ab35h		;92d9	cd 35 ab	. 5 .
	ld a,e			;92dc	7b		{
	ld (l8861h),a		;92dd	32 61 88	2 a .
	call sub_aae4h		;92e0	cd e4 aa	. . .
	call sub_ab35h		;92e3	cd 35 ab	. 5 .
	pop hl			;92e6	e1		.
	pop de			;92e7	d1		.
	pop bc			;92e8	c1		.
	pop af			;92e9	f1		.
	ret			;92ea	c9		.
; ---------------------------------------------------------------------------
; GENERATE ALL LEGAL MOVES
; Iterates through board squares 15h-62h, calling the move
; generator for each friendly piece found. Builds the move
; tree linked list for the current position.
; ---------------------------------------------------------------------------
sub_92ebh:
	call sub_933bh		;92eb	cd 3b 93	. ; .
	ld (l8834h),a		;92ee	32 34 88	2 4 .
	ld hl,l8862h+1		;92f1	21 63 88	! c .
	ld a,(l8831h+2)		;92f4	3a 33 88	: 3 .
	ld d,000h		;92f7	16 00		. .
	ld e,a			;92f9	5f		_
	add hl,de		;92fa	19		.
	ld a,(l8834h)		;92fb	3a 34 88	: 4 .
	ld (hl),a		;92fe	77		w
	ld de,(l8827h+2)	;92ff	ed 5b 29 88	. [ ) .
	ld hl,(l881fh)		;9303	2a 1f 88	* . .
	inc hl			;9306	23		#
	inc hl			;9307	23		#
	ld (hl),e		;9308	73		s
	inc hl			;9309	23		#
	ld (hl),d		;930a	72		r
	inc hl			;930b	23		#
	ld (l881fh),hl		;930c	22 1f 88	" . .
	ld (l8827h),hl		;930f	22 27 88	" ' .
	ld a,015h		;9312	3e 15		> .
l9314h:
	ld (l8809h),a		;9314	32 09 88	2 . .
	ld ix,(l8809h)		;9317	dd 2a 09 88	. * . .
	ld a,(ix-04ch)		;931b	dd 7e b4	. ~ .
	and a			;931e	a7		.
	jr z,l9331h		;931f	28 10		( .
	cp 0ffh			;9321	fe ff		. .
	jr z,l9331h		;9323	28 0c		( .
	ld (l882dh),a		;9325	32 2d 88	2 - .
	ld hl,l882ch		;9328	21 2c 88	! , .
	xor (hl)		;932b	ae		.
	bit 7,a			;932c	cb 7f		. .
	call z,sub_9566h	;932e	cc 66 95	. f .
l9331h:
	ld a,(l8809h)		;9331	3a 09 88	: . .
	inc a			;9334	3c		<
	cp 063h			;9335	fe 63		. c
	jp nz,l9314h		;9337	c2 14 93	. . .
	ret			;933a	c9		.
sub_933bh:
	ld a,(l882ch)		;933b	3a 2c 88	: , .
sub_933eh:
	ld hl,l894eh		;933e	21 4e 89	! N .
	and a			;9341	a7		.
	jr z,l9345h		;9342	28 01		( .
	inc hl			;9344	23		#
l9345h:
	ld a,(hl)		;9345	7e		~
	ld (l880dh),a		;9346	32 0d 88	2 . .
	ld ix,(l880dh)		;9349	dd 2a 0d 88	. * . .
	ld a,(ix-04ch)		;934d	dd 7e b4	. ~ .
	ld (l882dh),a		;9350	32 2d 88	2 - .
	and 007h		;9353	e6 07		. .
	ld (l8811h),a		;9355	32 11 88	2 . .
	call sub_935ch		;9358	cd 5c 93	. \ .
	ret			;935b	c9		.
; ---------------------------------------------------------------------------
; GENERATE MOVES FOR ONE PIECE
; Traverses direction vectors for the piece type. Handles
; sliding pieces (bishop/rook/queen), non-sliding (knight/king),
; and pawn specials (double push, en passant, promotion).
; ---------------------------------------------------------------------------
sub_935ch:
	push bc			;935c	c5		.
	xor a			;935d	af		.
	ld b,010h		;935e	06 10		. .
	ld (l881bh),a		;9360	32 1b 88	2 . .
l9363h:
	ld ix,(l881bh)		;9363	dd 2a 1b 88	. * . .
	ld c,(ix-080h)		;9367	dd 4e 80	. N .
	ld d,000h		;936a	16 00		. .
	ld a,(l880dh)		;936c	3a 0d 88	: . .
	ld (l880bh),a		;936f	32 0b 88	2 . .
l9372h:
	inc d			;9372	14		.
	ld hl,l880bh		;9373	21 0b 88	! . .
	ld a,(hl)		;9376	7e		~
	add a,c			;9377	81		.
	ld (hl),a		;9378	77		w
	ld ix,(l880bh)		;9379	dd 2a 0b 88	. * . .
	ld a,(ix-04ch)		;937d	dd 7e b4	. ~ .
	cp 0ffh			;9380	fe ff		. .	; Hit board edge (FFh)?
	jr z,l9393h		;9382	28 0f		( .	; Yes -> try next direction
	ld (l882dh+1),a		;9384	32 2e 88	2 . .
	and 007h		;9387	e6 07		. .
	ld (l8813h),a		;9389	32 13 88	2 . .
	jr nz,l939ch		;938c	20 0e		  .
	ld a,b			;938e	78		x
	cp 009h			;938f	fe 09		. .
	jr nc,l9372h		;9391	30 df		0 .
l9393h:
	ld hl,l881bh		;9393	21 1b 88	! . .
	inc (hl)		;9396	34		4
	djnz l9363h		;9397	10 ca		. .
	xor a			;9399	af		.
l939ah:
	pop bc			;939a	c1		.
	ret			;939b	c9		.
l939ch:
	ld a,(l882dh+1)		;939c	3a 2e 88	: . .
	ld hl,l882dh		;939f	21 2d 88	! - .
	xor (hl)		;93a2	ae		.
	jp p,l93aeh		;93a3	f2 ae 93	. . .
	bit 6,d			;93a6	cb 72		. r
	jr nz,l9393h		;93a8	20 e9		  .
	set 5,d			;93aa	cb ea		. .
	jr l93b4h		;93ac	18 06		. .
l93aeh:
	bit 5,d			;93ae	cb 6a		. j
	jr nz,l9393h		;93b0	20 e1		  .
	set 6,d			;93b2	cb f2		. .
l93b4h:
	ld a,(l8813h)		;93b4	3a 13 88	: . .
	ld e,a			;93b7	5f		_
	ld a,b			;93b8	78		x
	cp 009h			;93b9	fe 09		. .
	jr c,l9402h		;93bb	38 45		8 E
	ld a,e			;93bd	7b		{
	cp 005h			;93be	fe 05		. .
	jr nz,l93c6h		;93c0	20 04		  .
	set 7,d			;93c2	cb fa		. .
	jr l9407h		;93c4	18 41		. A
l93c6h:
	ld a,d			;93c6	7a		z
	and 00fh		;93c7	e6 0f		. .
	cp 001h			;93c9	fe 01		. .
	jr nz,l93d2h		;93cb	20 05		  .
	ld a,e			;93cd	7b		{
	cp 006h			;93ce	fe 06		. .
	jr z,l9407h		;93d0	28 35		( 5
l93d2h:
	ld a,b			;93d2	78		x
	cp 00dh			;93d3	fe 0d		. .
	jr c,l93fbh		;93d5	38 24		8 $
	ld a,e			;93d7	7b		{
	cp 003h			;93d8	fe 03		. .
	jr z,l9407h		;93da	28 2b		( +
	ld a,d			;93dc	7a		z
	and 00fh		;93dd	e6 0f		. .
	cp 001h			;93df	fe 01		. .
	jr nz,l9393h		;93e1	20 b0		  .
	cp e			;93e3	bb		.
	jr nz,l9393h		;93e4	20 ad		  .
	ld a,(l882dh+1)		;93e6	3a 2e 88	: . .
	bit 7,a			;93e9	cb 7f		. .
	jr z,l93f4h		;93eb	28 07		( .
	ld a,b			;93ed	78		x
	cp 00fh			;93ee	fe 0f		. .
	jr c,l9393h		;93f0	38 a1		8 .
	jr l9407h		;93f2	18 13		. .
l93f4h:
	ld a,b			;93f4	78		x
	cp 00fh			;93f5	fe 0f		. .
	jr nc,l9393h		;93f7	30 9a		0 .
	jr l9407h		;93f9	18 0c		. .
l93fbh:
	ld a,e			;93fb	7b		{
	cp 004h			;93fc	fe 04		. .
	jr nz,l9393h		;93fe	20 93		  .
	jr l9407h		;9400	18 05		. .
l9402h:
	ld a,e			;9402	7b		{
	cp 002h			;9403	fe 02		. .
	jr nz,l9393h		;9405	20 8c		  .
l9407h:
	ld a,(l8811h)		;9407	3a 11 88	: . .
	cp 007h			;940a	fe 07		. .
	jr z,l9417h		;940c	28 09		( .
	bit 5,d			;940e	cb 6a		. j
	jr z,l941ah		;9410	28 08		( .
	ld a,001h		;9412	3e 01		> .
	jp l939ah		;9414	c3 9a 93	. . .
l9417h:
	call sub_9671h		;9417	cd 71 96	. q .
l941ah:
	ld a,(l8813h)		;941a	3a 13 88	: . .
	cp 006h			;941d	fe 06		. .
	jp z,l9393h		;941f	ca 93 93	. . .
	cp 002h			;9422	fe 02		. .
	jp z,l9393h		;9424	ca 93 93	. . .
	jp l9372h		;9427	c3 72 93	. r .
; ---------------------------------------------------------------------------
; MAKE MOVE
; Updates the board array for a move. Handles captures,
; pawn promotion (with user prompt), castling (bit 6),
; and sets the has-moved flag (bit 3) on moved pieces.
; ---------------------------------------------------------------------------
sub_942ah:
	ld hl,(l8821h)		;942a	2a 21 88	* ! .
	inc hl			;942d	23		#
	inc hl			;942e	23		#
	inc hl			;942f	23		#
	ld a,(hl)		;9430	7e		~
	ld (l880bh),a		;9431	32 0b 88	2 . .
	ld ix,(l880bh)		;9434	dd 2a 0b 88	. * . .
	ld a,(ix-04ch)		;9438	dd 7e b4	. ~ .
	and 007h		;943b	e6 07		. .
	ld (l8871h+1),a		;943d	32 72 88	2 r .
sub_9440h:
	ld hl,(l8821h)		;9440	2a 21 88	* ! .
	inc hl			;9443	23		#
	inc hl			;9444	23		#
l9445h:
	ld a,(hl)		;9445	7e		~
	ld (l8809h),a		;9446	32 09 88	2 . .
	inc hl			;9449	23		#
	ld a,(hl)		;944a	7e		~
	ld (l880bh),a		;944b	32 0b 88	2 . .
	inc hl			;944e	23		#
	ld d,(hl)		;944f	56		V
	ld ix,(l8809h)		;9450	dd 2a 09 88	. * . .
	ld e,(ix-04ch)		;9454	dd 5e b4	. ^ .
	bit 5,d			;9457	cb 6a		. j
	jr nz,l948ch		;9459	20 31		  1
	ld a,e			;945b	7b		{
	and 007h		;945c	e6 07		. .
	cp 005h			;945e	fe 05		. .
	jr z,l94c1h		;9460	28 5f		( _
	cp 006h			;9462	fe 06		. .
	jr z,l94d2h		;9464	28 6c		( l
l9466h:
	push ix			;9466	dd e5		. .
	set 3,e			;9468	cb db		. .	; Set has-moved flag (bit 3)
	ld ix,(l880bh)		;946a	dd 2a 0b 88	. * . .	; IX -> destination
	ld (ix-04ch),e		;946e	dd 73 b4	. s .	; Place piece on destination
	pop ix			;9471	dd e1		. .	; IX -> source
	ld (ix-04ch),000h	;9473	dd 36 b4 00	. 6 . .	; Clear source square
	bit 6,d			;9477	cb 72		. r
	jr nz,l94ddh		;9479	20 62		  b
	ld a,d			;947b	7a		z
	and 007h		;947c	e6 07		. .
	cp 005h			;947e	fe 05		. .
	ret nz			;9480	c0		.
	ld hl,l8950h		;9481	21 50 89	! P .
	bit 7,d			;9484	cb 7a		. z
	jr z,l9489h		;9486	28 01		( .
	inc hl			;9488	23		#
l9489h:
	xor a			;9489	af		.
	ld (hl),a		;948a	77		w
	ret			;948b	c9		.
l948ch:
	push af			;948c	f5		.
	ld a,(l8871h)		;948d	3a 71 88	: q .
	and a			;9490	a7		.
	jr z,l94bch		;9491	28 29		( )
l9493h:
	push bc			;9493	c5		.
	push de			;9494	d5		.
	push hl			;9495	e5		.
	ld de,lb293h		;9496	11 93 b2	. . .
	ld b,019h		;9499	06 19		. .
	call sub_b038h		;949b	cd 38 b0	. 8 .
	pop hl			;949e	e1		.
	pop de			;949f	d1		.
	pop bc			;94a0	c1		.
	call sub_af9bh		;94a1	cd 9b af	. . .
	cp 051h			;94a4	fe 51		. Q	; 'Q' = promote to Queen?
	jr z,l94bch		;94a6	28 14		( .
	cp 052h			;94a8	fe 52		. R	; 'R' = promote to Rook?
	jr z,l94bah		;94aa	28 0e		( .
	cp 042h			;94ac	fe 42		. B	; 'B' = promote to Bishop?
	jr z,l94b6h		;94ae	28 06		( .
	cp 04bh			;94b0	fe 4b		. K	; 'K' = promote to Knight?
	jr nz,l9493h		;94b2	20 df		  .	; No valid choice -> ask again
	res 0,e			;94b4	cb 83		. .
l94b6h:
	set 1,e			;94b6	cb cb		. .
	jr l94beh		;94b8	18 04		. .
l94bah:
	res 0,e			;94ba	cb 83		. .
l94bch:
	set 2,e			;94bc	cb d3		. .
l94beh:
	pop af			;94be	f1		.
	jr l9466h		;94bf	18 a5		. .
l94c1h:
	ld hl,l8950h		;94c1	21 50 89	! P .
l94c4h:
	bit 7,e			;94c4	cb 7b		. {
	jr z,l94c9h		;94c6	28 01		( .
	inc hl			;94c8	23		#
l94c9h:
	ld a,(l880bh)		;94c9	3a 0b 88	: . .
	ld (hl),a		;94cc	77		w
	call sub_8f6fh		;94cd	cd 6f 8f	. o .
	jr l9466h		;94d0	18 94		. .
l94d2h:
	ld hl,l894eh		;94d2	21 4e 89	! N .
	bit 6,d			;94d5	cb 72		. r
	jr z,l94c4h		;94d7	28 eb		( .
	set 4,e			;94d9	cb e3		. .
	jr l94c4h		;94db	18 e7		. .
l94ddh:
	ld hl,(l8821h)		;94dd	2a 21 88	* ! .
	ld de,00008h		;94e0	11 08 00	. . .
	add hl,de		;94e3	19		.
	jp l9445h		;94e4	c3 45 94	. E .
; ---------------------------------------------------------------------------
; UNMAKE MOVE
; Reverses MAKE MOVE changes - restores captured pieces,
; undoes promotion, and reverts castling state. Used during
; search to back out of tried moves.
; ---------------------------------------------------------------------------
sub_94e7h:
	ld hl,(l8821h)		;94e7	2a 21 88	* ! .
	inc hl			;94ea	23		#
	inc hl			;94eb	23		#
l94ech:
	ld a,(hl)		;94ec	7e		~
	ld (l8809h),a		;94ed	32 09 88	2 . .
	inc hl			;94f0	23		#
	ld a,(hl)		;94f1	7e		~
	ld (l880bh),a		;94f2	32 0b 88	2 . .
	inc hl			;94f5	23		#
	ld d,(hl)		;94f6	56		V
	ld ix,(l880bh)		;94f7	dd 2a 0b 88	. * . .	; IX -> destination square
	ld e,(ix-04ch)		;94fb	dd 5e b4	. ^ .
	bit 5,d			;94fe	cb 6a		. j
	jr nz,l9539h		;9500	20 37		  7
	ld a,e			;9502	7b		{
	and 007h		;9503	e6 07		. .
	cp 005h			;9505	fe 05		. .
	jr z,l9541h		;9507	28 38		( 8
	cp 006h			;9509	fe 06		. .
	jr z,l9552h		;950b	28 45		( E
l950dh:
	bit 4,d			;950d	cb 62		. b
	jr nz,l953dh		;950f	20 2c		  ,
l9511h:
	push ix			;9511	dd e5		. .
	ld ix,(l8809h)		;9513	dd 2a 09 88	. * . .
	ld (ix-04ch),e		;9517	dd 73 b4	. s .
	pop ix			;951a	dd e1		. .
	ld a,d			;951c	7a		z
	and 08fh		;951d	e6 8f		. .
	ld (ix-04ch),a		;951f	dd 77 b4	. w .
	bit 6,d			;9522	cb 72		. r
	jr nz,l955dh		;9524	20 37		  7
	ld a,d			;9526	7a		z
	and 007h		;9527	e6 07		. .
	cp 005h			;9529	fe 05		. .
	ret nz			;952b	c0		.
	ld hl,l8950h		;952c	21 50 89	! P .
	bit 7,d			;952f	cb 7a		. z
	jr z,l9534h		;9531	28 01		( .
	inc hl			;9533	23		#
l9534h:
	ld a,(l880bh)		;9534	3a 0b 88	: . .
	ld (hl),a		;9537	77		w
	ret			;9538	c9		.
l9539h:
	res 2,e			;9539	cb 93		. .
	jr l950dh		;953b	18 d0		. .
l953dh:
	res 3,e			;953d	cb 9b		. .
	jr l9511h		;953f	18 d0		. .
l9541h:
	ld hl,l8950h		;9541	21 50 89	! P .
l9544h:
	bit 7,e			;9544	cb 7b		. {
	jr z,l9549h		;9546	28 01		( .
	inc hl			;9548	23		#
l9549h:
	ld a,(l8809h)		;9549	3a 09 88	: . .
	ld (hl),a		;954c	77		w
	call sub_8f6fh		;954d	cd 6f 8f	. o .
	jr l950dh		;9550	18 bb		. .
l9552h:
	ld hl,l894eh		;9552	21 4e 89	! N .
	bit 6,d			;9555	cb 72		. r
	jr z,l9544h		;9557	28 eb		( .
	res 4,e			;9559	cb a3		. .
	jr l9544h		;955b	18 e7		. .
l955dh:
	ld hl,(l8821h)		;955d	2a 21 88	* ! .
	ld de,00008h		;9560	11 08 00	. . .
	add hl,de		;9563	19		.
	jr l94ech		;9564	18 86		. .
; ---------------------------------------------------------------------------
; GENERATE MOVES WITH LEGALITY CHECK
; Validates piece color against side-to-move, loads direction
; info from piece type tables, and dispatches to the move
; generator. Filters illegal moves (e.g. leaving king in check).
; ---------------------------------------------------------------------------
sub_9566h:
	xor (hl)		;9566	ae		.
	and 087h		;9567	e6 87		. .
	cp 081h			;9569	fe 81		. .
	jr nz,l956eh		;956b	20 01		  .
	dec a			;956d	3d		=
l956eh:
	and 007h		;956e	e6 07		. .
	ld (l8811h),a		;9570	32 11 88	2 . .
	ld ix,(l8811h)		;9573	dd 2a 11 88	. * . .
	ld b,(ix-061h)		;9577	dd 46 9f	. F .
	ld a,(ix-068h)		;957a	dd 7e 98	. ~ .
	ld (l8819h),a		;957d	32 19 88	2 . .
l9580h:
	ld ix,(l8819h)		;9580	dd 2a 19 88	. * . .
	ld c,(ix-080h)		;9584	dd 4e 80	. N .
	ld a,(l8809h)		;9587	3a 09 88	: . .
	ld (l880bh),a		;958a	32 0b 88	2 . .
l958dh:
	ld hl,l880bh		;958d	21 0b 88	! . .
	ld a,(hl)		;9590	7e		~
	add a,c			;9591	81		.
	ld (hl),a		;9592	77		w
	ld ix,(l880bh)		;9593	dd 2a 0b 88	. * . .
	ld a,(ix-04ch)		;9597	dd 7e b4	. ~ .
	cp 0ffh			;959a	fe ff		. .
	jr z,l95ceh		;959c	28 30		( 0
	ld (l882dh+1),a		;959e	32 2e 88	2 . .
	and 007h		;95a1	e6 07		. .
	ld (l8813h),a		;95a3	32 13 88	2 . .
	jr z,l95b4h		;95a6	28 0c		( .
	ld a,(l882dh+1)		;95a8	3a 2e 88	: . .
	ld hl,l882dh		;95ab	21 2d 88	! - .
	xor (hl)		;95ae	ae		.
	jp p,l95ceh		;95af	f2 ce 95	. . .
	ld a,001h		;95b2	3e 01		> .
l95b4h:
	and a			;95b4	a7		.
	ex af,af'		;95b5	08		.
	ld a,(l8811h)		;95b6	3a 11 88	: . .
	cp 002h			;95b9	fe 02		. .
	jr c,l95ddh		;95bb	38 20		8  
	call sub_962bh		;95bd	cd 2b 96	. + .
	ex af,af'		;95c0	08		.
	jr nz,l95ceh		;95c1	20 0b		  .
	ld a,(l8811h)		;95c3	3a 11 88	: . .
	cp 006h			;95c6	fe 06		. .
	jr z,l95ceh		;95c8	28 04		( .
	cp 003h			;95ca	fe 03		. .
	jr nc,l958dh		;95cc	30 bf		0 .
l95ceh:
	ld hl,l8819h		;95ce	21 19 88	! . .
	inc (hl)		;95d1	34		4
	djnz l9580h		;95d2	10 ac		. .
	ld a,(l8811h)		;95d4	3a 11 88	: . .
	cp 006h			;95d7	fe 06		. .
	call z,sub_96e6h	;95d9	cc e6 96	. . .
	ret			;95dc	c9		.
l95ddh:
	ld a,b			;95dd	78		x
	cp 003h			;95de	fe 03		. .
	jr c,l9610h		;95e0	38 2e		8 .
	jr z,l9608h		;95e2	28 24		( $
	ex af,af'		;95e4	08		.
	jr nz,l95ceh		;95e5	20 e7		  .
	ld a,(l880bh)		;95e7	3a 0b 88	: . .
	cp 05bh			;95ea	fe 5b		. [
	jr nc,l95f2h		;95ec	30 04		0 .
	cp 01dh			;95ee	fe 1d		. .
	jr nc,l95f7h		;95f0	30 05		0 .
l95f2h:
	ld hl,l882dh+1		;95f2	21 2e 88	! . .
	set 5,(hl)		;95f5	cb ee		. .
l95f7h:
	call sub_962bh		;95f7	cd 2b 96	. + .
	ld hl,l8819h		;95fa	21 19 88	! . .
	inc (hl)		;95fd	34		4
	dec b			;95fe	05		.
	ld hl,l882dh		;95ff	21 2d 88	! - .
	bit 3,(hl)		;9602	cb 5e		. ^
	jr z,l958dh		;9604	28 87		( .
	jr l95ceh		;9606	18 c6		. .
l9608h:
	ex af,af'		;9608	08		.
	jr nz,l95ceh		;9609	20 c3		  .
l960bh:
	call sub_962bh		;960b	cd 2b 96	. + .
	jr l95ceh		;960e	18 be		. .
l9610h:
	ex af,af'		;9610	08		.
	jr z,l9625h		;9611	28 12		( .
	ld a,(l880bh)		;9613	3a 0b 88	: . .
	cp 05bh			;9616	fe 5b		. [
	jr nc,l961eh		;9618	30 04		0 .
	cp 01dh			;961a	fe 1d		. .
	jr nc,l960bh		;961c	30 ed		0 .
l961eh:
	ld hl,l882dh+1		;961e	21 2e 88	! . .
	set 5,(hl)		;9621	cb ee		. .
	jr l960bh		;9623	18 e6		. .
l9625h:
	call sub_9763h		;9625	cd 63 97	. c .
	jp l95ceh		;9628	c3 ce 95	. . .
; ---------------------------------------------------------------------------
; ADD MOVE TO TREE
; Stores a generated move in the linked-list move tree.
; Checks for buffer overflow (87F8h limit). Writes from-square,
; to-square, captured piece, and flags into a 6-byte node.
; ---------------------------------------------------------------------------
sub_962bh:
	ld de,(l8827h+2)	;962b	ed 5b 29 88	. [ ) .
	ld hl,l87f8h		;962f	21 f8 87	! . .
	and a			;9632	a7		.
	sbc hl,de		;9633	ed 52		. R
	jr c,l966ah		;9635	38 33		8 3
	ld hl,(l8827h)		;9637	2a 27 88	* ' .
	ld (l8827h),de		;963a	ed 53 27 88	. S ' .
	ld (hl),e		;963e	73		s
	inc hl			;963f	23		#
	ld (hl),d		;9640	72		r
	ld hl,l882dh		;9641	21 2d 88	! - .
	bit 3,(hl)		;9644	cb 5e		. ^
	jr nz,l964dh		;9646	20 05		  .
	ld hl,l882dh+1		;9648	21 2e 88	! . .
	set 4,(hl)		;964b	cb e6		. .
l964dh:
	ex de,hl		;964d	eb		.
	ld (hl),000h		;964e	36 00		6 .
	inc hl			;9650	23		#
	ld (hl),000h		;9651	36 00		6 .
	inc hl			;9653	23		#
	ld a,(l8809h)		;9654	3a 09 88	: . .
	ld (hl),a		;9657	77		w
	inc hl			;9658	23		#
	ld a,(l880bh)		;9659	3a 0b 88	: . .
	ld (hl),a		;965c	77		w
	inc hl			;965d	23		#
	ld a,(l882dh+1)		;965e	3a 2e 88	: . .
	ld (hl),a		;9661	77		w
	inc hl			;9662	23		#
	ld (hl),000h		;9663	36 00		6 .
	inc hl			;9665	23		#
	ld (l8827h+2),hl	;9666	22 29 88	" ) .
	ret			;9669	c9		.
l966ah:
	ld (hl),000h		;966a	36 00		6 .
	inc hl			;966c	23		#
	ld (hl),000h		;966d	36 00		6 .
	dec hl			;966f	2b		+
	ret			;9670	c9		.
sub_9671h:
	push bc			;9671	c5		.
	push de			;9672	d5		.
	ld a,(l881dh)		;9673	3a 1d 88	: . .
	and a			;9676	a7		.
	call nz,sub_96b9h	;9677	c4 b9 96	. . .
	ld ix,(l8813h)		;967a	dd 2a 13 88	. * . .
	ld hl,l892ch		;967e	21 2c 89	! , .
	ld bc,00000h		;9681	01 00 00	. . .
	ld a,(l882dh+1)		;9684	3a 2e 88	: . .
	bit 7,a			;9687	cb 7f		. .
	jr z,l968dh		;9689	28 02		( .
	ld c,007h		;968b	0e 07		. .
l968dh:
	and 007h		;968d	e6 07		. .
	ld e,a			;968f	5f		_
	bit 7,d			;9690	cb 7a		. z
	jr z,l9696h		;9692	28 02		( .
	ld e,005h		;9694	1e 05		. .
l9696h:
	add hl,bc		;9696	09		.
	inc (hl)		;9697	34		4
	ld d,000h		;9698	16 00		. .
	add hl,de		;969a	19		.
	ld a,(hl)		;969b	7e		~
	and 00fh		;969c	e6 0f		. .
	jr z,l96b1h		;969e	28 11		( .
	ld a,(hl)		;96a0	7e		~
	and 0f0h		;96a1	e6 f0		. .
	jr z,l96a8h		;96a3	28 03		( .
	inc hl			;96a5	23		#
	jr l96b1h		;96a6	18 09		. .
l96a8h:
	rld			;96a8	ed 6f		. o
	ld a,(ix-05bh)		;96aa	dd 7e a5	. ~ .
	rrd			;96ad	ed 67		. g
	jr l96b6h		;96af	18 05		. .
l96b1h:
	ld a,(ix-05bh)		;96b1	dd 7e a5	. ~ .
	rld			;96b4	ed 6f		. o
l96b6h:
	pop de			;96b6	d1		.
	pop bc			;96b7	c1		.
	ret			;96b8	c9		.
sub_96b9h:
	ld d,c			;96b9	51		Q
	ld e,000h		;96ba	1e 00		. .
	ld c,a			;96bc	4f		O
	ld b,000h		;96bd	06 00		. .
	ld a,(l880bh)		;96bf	3a 0b 88	: . .
	ld hl,l893ah		;96c2	21 3a 89	! : .
l96c5h:
	cpir			;96c5	ed b1		. .
	ret nz			;96c7	c0		.
	ex af,af'		;96c8	08		.
	bit 0,e			;96c9	cb 43		. C
	jr nz,l96e2h		;96cb	20 15		  .
	set 0,e			;96cd	cb c3		. .
	push hl			;96cf	e5		.
	pop ix			;96d0	dd e1		. .
	ld a,(ix+009h)		;96d2	dd 7e 09	. ~ .
	cp d			;96d5	ba		.
	jr z,l96ddh		;96d6	28 05		( .
	neg			;96d8	ed 44		. D
	cp d			;96da	ba		.
	jr nz,l96e2h		;96db	20 05		  .
l96ddh:
	ex af,af'		;96dd	08		.
	jp pe,l96c5h		;96de	ea c5 96	. . .
	ret			;96e1	c9		.
l96e2h:
	pop af			;96e2	f1		.
	pop de			;96e3	d1		.
	pop bc			;96e4	c1		.
	ret			;96e5	c9		.
sub_96e6h:
	ld a,(l882dh)		;96e6	3a 2d 88	: - .
	bit 3,a			;96e9	cb 5f		. _
	ret nz			;96eb	c0		.
	ld a,(l8834h)		;96ec	3a 34 88	: 4 .
	and a			;96ef	a7		.
	ret nz			;96f0	c0		.
	ld bc,0ff03h		;96f1	01 03 ff	. . .
l96f4h:
	ld a,(l8809h)		;96f4	3a 09 88	: . .
	add a,c			;96f7	81		.
	ld c,a			;96f8	4f		O
	ld (l880dh),a		;96f9	32 0d 88	2 . .
	ld ix,(l880dh)		;96fc	dd 2a 0d 88	. * . .
	ld a,(ix-04ch)		;9700	dd 7e b4	. ~ .
	and 07fh		;9703	e6 7f		. .
	cp 004h			;9705	fe 04		. .
	jr nz,l975ah		;9707	20 51		  Q
	ld a,c			;9709	79		y
	jr l972ah		;970a	18 1e		. .
l970ch:
	ld ix,(l880dh)		;970c	dd 2a 0d 88	. * . .
	ld a,(ix-04ch)		;9710	dd 7e b4	. ~ .
	and a			;9713	a7		.
	jr nz,l975ah		;9714	20 44		  D
	ld a,(l880dh)		;9716	3a 0d 88	: . .
	cp 016h			;9719	fe 16		. .
	jr z,l972ah		;971b	28 0d		( .
	cp 05ch			;971d	fe 5c		. \
	jr z,l972ah		;971f	28 09		( .
	call sub_935ch		;9721	cd 5c 93	. \ .
	and a			;9724	a7		.
	jr nz,l975ah		;9725	20 33		  3
	ld a,(l880dh)		;9727	3a 0d 88	: . .
l972ah:
	add a,b			;972a	80		.
	ld (l880dh),a		;972b	32 0d 88	2 . .
	ld hl,l8809h		;972e	21 09 88	! . .
	cp (hl)			;9731	be		.
	jr nz,l970ch		;9732	20 d8		  .
	sub b			;9734	90		.
	sub b			;9735	90		.
	ld (l880bh),a		;9736	32 0b 88	2 . .
	ld hl,l882dh+1		;9739	21 2e 88	! . .
	ld (hl),040h		;973c	36 40		6 @
	call sub_962bh		;973e	cd 2b 96	. + .
	ld hl,l8809h		;9741	21 09 88	! . .
	ld a,(hl)		;9744	7e		~
	ld (hl),c		;9745	71		q
	sub b			;9746	90		.
	ld (l880bh),a		;9747	32 0b 88	2 . .
	xor a			;974a	af		.
	ld (l882dh+1),a		;974b	32 2e 88	2 . .
	call sub_962bh		;974e	cd 2b 96	. + .
	call sub_97c8h		;9751	cd c8 97	. . .
	ld a,(l880dh)		;9754	3a 0d 88	: . .
	ld (l8809h),a		;9757	32 09 88	2 . .
l975ah:
	ld a,b			;975a	78		x
	cp 001h			;975b	fe 01		. .
	ret z			;975d	c8		.
	ld bc,001fch		;975e	01 fc 01	. . .
	jr l96f4h		;9761	18 91		. .
sub_9763h:
	ld a,(l8809h)		;9763	3a 09 88	: . .
	ld hl,l882dh		;9766	21 2d 88	! - .
	bit 7,(hl)		;9769	cb 7e		. ~
	jr z,l976fh		;976b	28 02		( .
	add a,00ah		;976d	c6 0a		. .
l976fh:
	cp 03dh			;976f	fe 3d		. =
	ret c			;9771	d8		.
	cp 045h			;9772	fe 45		. E
	ret nc			;9774	d0		.
	ld ix,(l8821h)		;9775	dd 2a 21 88	. * ! .
	bit 4,(ix+004h)		;9779	dd cb 04 66	. . . f
	ret z			;977d	c8		.
	ld a,(ix+003h)		;977e	dd 7e 03	. ~ .
	ld (l880fh),a		;9781	32 0f 88	2 . .
	ld ix,(l880fh)		;9784	dd 2a 0f 88	. * . .
	ld a,(ix-04ch)		;9788	dd 7e b4	. ~ .
	ld (l882fh),a		;978b	32 2f 88	2 / .
	and 007h		;978e	e6 07		. .
	cp 001h			;9790	fe 01		. .
	ret nz			;9792	c0		.
	ld a,(l880fh)		;9793	3a 0f 88	: . .
	ld hl,l880bh		;9796	21 0b 88	! . .
	sub (hl)		;9799	96		.
	jp p,l979fh		;979a	f2 9f 97	. . .
	neg			;979d	ed 44		. D
l979fh:
	cp 00ah			;979f	fe 0a		. .
	ret nz			;97a1	c0		.
	ld hl,l882dh+1		;97a2	21 2e 88	! . .
	set 6,(hl)		;97a5	cb f6		. .
	call sub_962bh		;97a7	cd 2b 96	. + .
	ld a,(l8809h)		;97aa	3a 09 88	: . .
	ld (l880dh),a		;97ad	32 0d 88	2 . .
	ld a,(l880fh)		;97b0	3a 0f 88	: . .
	ld (l8809h),a		;97b3	32 09 88	2 . .
	ld (l880bh),a		;97b6	32 0b 88	2 . .
	ld a,(l882fh)		;97b9	3a 2f 88	: / .
	ld (l882dh+1),a		;97bc	32 2e 88	2 . .
	call sub_962bh		;97bf	cd 2b 96	. + .
	ld a,(l880dh)		;97c2	3a 0d 88	: . .
	ld (l8809h),a		;97c5	32 09 88	2 . .
sub_97c8h:
	ld hl,(l8827h)		;97c8	2a 27 88	* ' .
	ld de,0fffah		;97cb	11 fa ff	. . .
	add hl,de		;97ce	19		.
	ld (l8827h),hl		;97cf	22 27 88	" ' .
	ld (hl),000h		;97d2	36 00		6 .
	inc hl			;97d4	23		#
	ld (hl),000h		;97d5	36 00		6 .
	ret			;97d7	c9		.
sub_97d8h:
	call sub_aab2h		;97d8	cd b2 aa	. . .
	xor a			;97db	af		.
	ld (l8871h),a		;97dc	32 71 88	2 q .
	ld a,(l882bh)		;97df	3a 2b 88	: + .
	ld (l882ch),a		;97e2	32 2c 88	2 , .
	call sub_9994h		;97e5	cd 94 99	. . .
	ld hl,(l8825h)		;97e8	2a 25 88	* % .
	ld (l8821h),hl		;97eb	22 21 88	" ! .
	ld a,(l8954h)		;97ee	3a 54 89	: T .
	cp 001h			;97f1	fe 01		. .
	jr nz,l97fah		;97f3	20 05		  .
	ld c,001h		;97f5	0e 01		. .
	call sub_9c2bh		;97f7	cd 2b 9c	. + .
l97fah:
	call sub_942ah		;97fa	cd 2a 94	. * .
	call sub_928ah		;97fd	cd 8a 92	. . .
	ld a,b			;9800	78		x
	and a			;9801	a7		.
	jr nz,l982dh		;9802	20 29		  )
	push de			;9804	d5		.
	ld d,c			;9805	51		Q
	call sub_9c92h		;9806	cd 92 9c	. . .
	ld de,(l8874h+1)	;9809	ed 5b 75 88	. [ u .
	ld a,l			;980d	7d		}
	ld (de),a		;980e	12		.
	inc de			;980f	13		.
	ld a,h			;9810	7c		|
	ld (de),a		;9811	12		.
	inc de			;9812	13		.
	ld a,(l8871h+1)		;9813	3a 72 88	: r .
	and a			;9816	a7		.
	ld a,02dh		;9817	3e 2d		> -
	jr z,l981dh		;9819	28 02		( .
	ld a,078h		;981b	3e 78		> x
l981dh:
	ld (de),a		;981d	12		.
	inc de			;981e	13		.
	pop hl			;981f	e1		.
	push de			;9820	d5		.
	ld d,l			;9821	55		U
	call sub_9c92h		;9822	cd 92 9c	. . .
	pop de			;9825	d1		.
	ld a,l			;9826	7d		}
	ld (de),a		;9827	12		.
	inc de			;9828	13		.
	ld a,h			;9829	7c		|
	ld (de),a		;982a	12		.
	jr l984bh		;982b	18 1e		. .
l982dh:
	bit 1,b			;982d	cb 48		. H
	jr z,l9836h		;982f	28 05		( .
	ld hl,lb0cbh		;9831	21 cb b0	! . .
	jr l9842h		;9834	18 0c		. .
l9836h:
	bit 2,b			;9836	cb 50		. P
	jr z,l983fh		;9838	28 05		( .
	ld hl,0b0d0h		;983a	21 d0 b0	! . .
	jr l9842h		;983d	18 03		. .
l983fh:
	ld hl,0b279h		;983f	21 79 b2	! y .
l9842h:
	ld de,(l8874h+1)	;9842	ed 5b 75 88	. [ u .
	ld bc,00005h		;9846	01 05 00	. . .
	ldir			;9849	ed b0		. .
l984bh:
	ld a,(l882ch)		;984b	3a 2c 88	: , .
	ld b,a			;984e	47		G
	xor 080h		;984f	ee 80		. .
	ld (l882ch),a		;9851	32 2c 88	2 , .
	call sub_933bh		;9854	cd 3b 93	. ; .
	and a			;9857	a7		.
	ld a,b			;9858	78		x
	ld (l882ch),a		;9859	32 2c 88	2 , .
	jr z,l986dh		;985c	28 0f		( .
	call sub_a845h		;985e	cd 45 a8	. E .
	ld hl,lb0d5h		;9861	21 d5 b0	! . .
	ld de,(l8874h+1)	;9864	ed 5b 75 88	. [ u .
	ld bc,00005h		;9868	01 05 00	. . .
	ldir			;986b	ed b0		. .
l986dh:
	ld a,(l8954h)		;986d	3a 54 89	: T .
	cp 0ffh			;9870	fe ff		. .
	ret nz			;9872	c0		.
	ld c,000h		;9873	0e 00		. .
	call sub_9c2bh		;9875	cd 2b 9c	. + .
	ret			;9878	c9		.
; ---------------------------------------------------------------------------
; OPENING BOOK LOOKUP
; Matches the current position against pre-programmed opening
; book entries stored at 8000h. Walks the linked-list book
; structure to find matching moves for early game play.
; ---------------------------------------------------------------------------
sub_9879h:
	ld a,(l884dh)		;9879	3a 4d 88	: M .
	and a			;987c	a7		.
	ret z			;987d	c8		.
	ld a,(l8831h)		;987e	3a 31 88	: 1 .
	cp 001h			;9881	fe 01		. .
	jr nz,l988fh		;9883	20 0a		  .
	xor a			;9885	af		.
	ld (l884dh+1),a		;9886	32 4e 88	2 N .
	ld a,(l882bh)		;9889	3a 2b 88	: + .
	and a			;988c	a7		.
	jr z,l98b8h		;988d	28 29		( )
l988fh:
	call sub_98f0h		;988f	cd f0 98	. . .
	inc hl			;9892	23		#
	inc hl			;9893	23		#
	inc hl			;9894	23		#
l9895h:
	ld a,(hl)		;9895	7e		~
	and a			;9896	a7		.
	jr z,l98ebh		;9897	28 52		( R
	push hl			;9899	e5		.
	call sub_98f3h		;989a	cd f3 98	. . .
	inc hl			;989d	23		#
	ld ix,(l8821h)		;989e	dd 2a 21 88	. * ! .
	ld a,(ix+002h)		;98a2	dd 7e 02	. ~ .
	cp (hl)			;98a5	be		.
	jr nz,l98afh		;98a6	20 07		  .
	ld a,(ix+003h)		;98a8	dd 7e 03	. ~ .
	inc hl			;98ab	23		#
	cp (hl)			;98ac	be		.
	jr z,l98b3h		;98ad	28 04		( .
l98afh:
	pop hl			;98af	e1		.
	inc hl			;98b0	23		#
	jr l9895h		;98b1	18 e2		. .
l98b3h:
	pop hl			;98b3	e1		.
	ld a,(hl)		;98b4	7e		~
	ld (l884dh+1),a		;98b5	32 4e 88	2 N .
l98b8h:
	call sub_98f0h		;98b8	cd f0 98	. . .
	inc hl			;98bb	23		#
	inc hl			;98bc	23		#
	inc hl			;98bd	23		#
	ld a,(hl)		;98be	7e		~
	and a			;98bf	a7		.
	jr z,l98ebh		;98c0	28 29		( )
l98c2h:
	ld (l884dh+1),a		;98c2	32 4e 88	2 N .
	call sub_9903h		;98c5	cd 03 99	. . .
	bit 0,a			;98c8	cb 47		. G
	jr z,l98d1h		;98ca	28 05		( .
	inc hl			;98cc	23		#
	ld a,(hl)		;98cd	7e		~
	and a			;98ce	a7		.
	jr nz,l98c2h		;98cf	20 f1		  .
l98d1h:
	call sub_98f0h		;98d1	cd f0 98	. . .
	inc hl			;98d4	23		#
	ld a,(hl)		;98d5	7e		~
	ld (l9910h),a		;98d6	32 10 99	2 . .
	inc hl			;98d9	23		#
	ld a,(hl)		;98da	7e		~
	ld (l9911h),a		;98db	32 11 99	2 . .
	ld hl,l990eh		;98de	21 0e 99	! . .
	ld (l8825h),hl		;98e1	22 25 88	" % .
	ld hl,l8954h		;98e4	21 54 89	! T .
	ld (hl),000h		;98e7	36 00		6 .
	pop af			;98e9	f1		.
	ret			;98ea	c9		.
l98ebh:
	xor a			;98eb	af		.
	ld (l884dh),a		;98ec	32 4d 88	2 M .
	ret			;98ef	c9		.
; ---------------------------------------------------------------------------
; NAVIGATE BOOK TREE
; Walks the linked-list book structure using the book index
; at 884Eh. Skips zero-terminated entries to find the correct
; branch for the current game position.
; ---------------------------------------------------------------------------
sub_98f0h:
	ld a,(l884dh+1)		;98f0	3a 4e 88	: N .
sub_98f3h:
	ld hl,09913h		;98f3	21 13 99	! . .
	ld b,a			;98f6	47		G
l98f7h:
	ld a,b			;98f7	78		x
	and a			;98f8	a7		.
	ret z			;98f9	c8		.
l98fah:
	inc hl			;98fa	23		#
	ld a,(hl)		;98fb	7e		~
	and a			;98fc	a7		.
	jr nz,l98fah		;98fd	20 fb		  .
	inc hl			;98ff	23		#
	dec b			;9900	05		.
	jr l98f7h		;9901	18 f4		. .
; ---------------------------------------------------------------------------
; RANDOM NUMBER GENERATOR
; Simple counter-based RNG. Increments the low byte of the
; pointer at 89B0h and reads the value there. Used for
; opening book variety when multiple book moves are available.
; ---------------------------------------------------------------------------
sub_9903h:
	push hl			;9903	e5		.
	ld hl,(089b0h)		;9904	2a b0 89	* . .
	inc l			;9907	2c		,
	ld (089b0h),hl		;9908	22 b0 89	" . .
	ld a,(hl)		;990b	7e		~
	pop hl			;990c	e1		.
	ret			;990d	c9		.
l990eh:
	nop			;990e	00		.
	nop			;990f	00		.
l9910h:
	nop			;9910	00		.
l9911h:
	nop			;9911	00		.
	djnz l9914h		;9912	10 00		. .
l9914h:
	rst 38h			;9914	ff		.
	rst 38h			;9915	ff		.
	ld bc,00002h		;9916	01 02 00	. . .
	ld bc,03723h		;9919	01 23 37	. # 7
	inc bc			;991c	03		.
	ex af,af'		;991d	08		.
	dec bc			;991e	0b		.
	ld c,000h		;991f	0e 00		. .
	ld (bc),a		;9921	02		.
	ld (01136h),hl		;9922	22 36 11	" 6 .
	inc d			;9925	14		.
	nop			;9926	00		.
	inc bc			;9927	03		.
	ld d,l			;9928	55		U
	ld b,c			;9929	41		A
	inc b			;992a	04		.
	nop			;992b	00		.
	inc b			;992c	04		.
	dec de			;992d	1b		.
	ld l,005h		;992e	2e 05		. .
	nop			;9930	00		.
	dec b			;9931	05		.
	ld e,h			;9932	5c		\
	ld c,c			;9933	49		I
	ld b,000h		;9934	06 00		. .
	ld b,01ah		;9936	06 1a		. .
	ld a,007h		;9938	3e 07		> .
	nop			;993a	00		.
	rlca			;993b	07		.
	ld d,c			;993c	51		Q
	ld b,a			;993d	47		G
	nop			;993e	00		.
	ex af,af'		;993f	08		.
	ld d,e			;9940	53		S
	ccf			;9941	3f		?
	add hl,bc		;9942	09		.
	nop			;9943	00		.
	add hl,bc		;9944	09		.
	dec de			;9945	1b		.
	ld l,00ah		;9946	2e 0a		. .
	nop			;9948	00		.
	ld a,(bc)		;9949	0a		.
	ld e,h			;994a	5c		\
	ld c,c			;994b	49		I
	nop			;994c	00		.
	dec bc			;994d	0b		.
	ld d,l			;994e	55		U
	ld c,e			;994f	4b		K
	inc c			;9950	0c		.
	nop			;9951	00		.
	inc c			;9952	0c		.
	ld (00d36h),hl		;9953	22 36 0d	" 6 .
	nop			;9956	00		.
	dec c			;9957	0d		.
	ld d,h			;9958	54		T
	ld b,b			;9959	40		@
	rla			;995a	17		.
	nop			;995b	00		.
	ld c,053h		;995c	0e 53		. S
	ld c,c			;995e	49		I
	rrca			;995f	0f		.
	nop			;9960	00		.
	rrca			;9961	0f		.
	ld (01036h),hl		;9962	22 36 10	" 6 .
	nop			;9965	00		.
	djnz l99bch		;9966	10 54		. T
	ld b,b			;9968	40		@
	nop			;9969	00		.
	ld de,04054h		;996a	11 54 40	. T @
	ld (de),a		;996d	12		.
	nop			;996e	00		.
	ld (de),a		;996f	12		.
	ld hl,01335h		;9970	21 35 13	! 5 .
	nop			;9973	00		.
	inc de			;9974	13		.
	ld h,c			;9975	61		a
	ld c,h			;9976	4c		L
	nop			;9977	00		.
	inc d			;9978	14		.
	ld h,c			;9979	61		a
	ld c,h			;997a	4c		L
	dec d			;997b	15		.
	nop			;997c	00		.
	dec d			;997d	15		.
	ld hl,01635h		;997e	21 35 16	! 5 .
	nop			;9981	00		.
	ld d,053h		;9982	16 53		. S
	ccf			;9984	3f		?
	nop			;9985	00		.
	rla			;9986	17		.
	ld d,02bh		;9987	16 2b		. +
	jr l998bh		;9989	18 00		. .
l998bh:
	jr l99eeh		;998b	18 61		. a
	ld c,h			;998d	4c		L
	add hl,de		;998e	19		.
	nop			;998f	00		.
	add hl,de		;9990	19		.
	scf			;9991	37		7
	ld b,c			;9992	41		A
	nop			;9993	00		.
; ---------------------------------------------------------------------------
; TOP-LEVEL SEARCH ENTRY
; The computer's "brain". Checks the opening book first, then
; launches iterative deepening alpha-beta search. Initializes
; search state, node counter, and move tree pointers.
; ---------------------------------------------------------------------------
sub_9994h:
	call sub_9879h		;9994	cd 79 98	. y .	; Try opening book first
	xor a			;9997	af		.
	ld (l8877h),a		;9998	32 77 88	2 w .	; Clear check flag
	ld (l884dh+2),a		;999b	32 4f 88	2 O .
	ld (l8831h+2),a		;999e	32 33 88	2 3 .
	ld hl,00000h		;99a1	21 00 00	! . .
	ld (l8825h),hl		;99a4	22 25 88	" % .	; Clear best move pointer
	ld (l8850h),hl		;99a7	22 50 88	" P .	; Reset node counter
	ld hl,l8000h		;99aa	21 00 80	! . .
	ld (l8827h+2),hl	;99ad	22 29 88	" ) .
	ld hl,l8969h		;99b0	21 69 89	! i .
	ld (l881fh),hl		;99b3	22 1f 88	" . .
	ld hl,l8953h		;99b6	21 53 89	! S .
	ld (l8823h),hl		;99b9	22 23 88	" # .
l99bch:
	ld a,(l8831h+1)		;99bc	3a 32 88	: 2 .
	add a,002h		;99bf	c6 02		. .
	ld b,a			;99c1	47		G
	xor a			;99c2	af		.
l99c3h:
	ld (hl),a		;99c3	77		w
	inc hl			;99c4	23		#
	djnz l99c3h		;99c5	10 fc		. .
	ld (l8840h),a		;99c7	32 40 88	2 @ .
	ld (l8847h),a		;99ca	32 47 88	2 G .
	ld (l8848h),a		;99cd	32 48 88	2 H .
	ld (l8843h+2),a		;99d0	32 45 88	2 E .
	ld (l8846h),a		;99d3	32 46 88	2 F .
	ld (l8842h),a		;99d6	32 42 88	2 B .
	ld (l8848h+1),a		;99d9	32 49 88	2 I .
	ld b,0d2h		;99dc	06 d2		. .
	ld hl,l8b60h		;99de	21 60 8b	! ` .
l99e1h:
	ld (hl),a		;99e1	77		w
	inc hl			;99e2	23		#
	djnz l99e1h		;99e3	10 fc		. .
	call sub_9ca1h		;99e5	cd a1 9c	. . .
	call sub_9d75h		;99e8	cd 75 9d	. u .
	ld a,(l8838h)		;99eb	3a 38 88	: 8 .
l99eeh:
	ld (l8847h),a		;99ee	32 47 88	2 G .
	ld a,(l883eh)		;99f1	3a 3e 88	: > .
	ld (l8848h),a		;99f4	32 48 88	2 H .
	ld a,(l8843h+1)		;99f7	3a 44 88	: D .
	ld (l8846h),a		;99fa	32 46 88	2 F .
	ld a,(l8843h)		;99fd	3a 43 88	: C .
	ld (l8843h+2),a		;9a00	32 45 88	2 E .
	ld a,(l8841h)		;9a03	3a 41 88	: A .
	ld (l8842h),a		;9a06	32 42 88	2 B .
	ld a,(l883eh+1)		;9a09	3a 3f 88	: ? .
	ld (l8840h),a		;9a0c	32 40 88	2 @ .
	ld a,(l8848h+2)		;9a0f	3a 4a 88	: J .
	ld (l8848h+1),a		;9a12	32 49 88	2 I .
; ---------------------------------------------------------------------------
; SEARCH ITERATION
; Increments search depth, generates moves, sorts them by
; score, and begins alpha-beta traversal of the move tree.
; ---------------------------------------------------------------------------
l9a15h:
	ld hl,l8831h+2		;9a15	21 33 88	! 3 .
	inc (hl)		;9a18	34		4	; Increment search depth
	xor a			;9a19	af		.
	ld (l8835h),a		;9a1a	32 35 88	2 5 .
	call sub_92ebh		;9a1d	cd eb 92	. . .
	ld a,001h		;9a20	3e 01		> .
	ld (l883dh),a		;9a22	32 3d 88	2 = .
	ld hl,l8831h+2		;9a25	21 33 88	! 3 .
	ld a,(l885eh+1)		;9a28	3a 5f 88	: _ .
	cp (hl)			;9a2b	be		.
	push af			;9a2c	f5		.
	call p,sub_a48ah	;9a2d	f4 8a a4	. . .	; Sort ascending if not max depth
	pop af			;9a30	f1		.
	call m,sub_a4cbh	;9a31	fc cb a4	. . .	; Sort descending if at max depth
	ld a,(l8831h+2)		;9a34	3a 33 88	: 3 .
	cp 001h			;9a37	fe 01		. .
	jr nz,l9a48h		;9a39	20 0d		  .
	ld a,(l8877h)		;9a3b	3a 77 88	: w .
	and a			;9a3e	a7		.
	jr nz,l9a48h		;9a3f	20 07		  .
	call sub_933bh		;9a41	cd 3b 93	. ; .
	and a			;9a44	a7		.
	jp z,l9c10h		;9a45	ca 10 9c	. . .
l9a48h:
	ld hl,(l881fh)		;9a48	2a 1f 88	* . .
	ld (l8821h),hl		;9a4b	22 21 88	" ! .
; ---------------------------------------------------------------------------
; ALPHA-BETA MAIN LOOP
; Iterates through each candidate move: makes/unmakes it,
; evaluates the resulting position, and prunes when score
; exceeds beta (cutoff). Updates best move when better found.
; ---------------------------------------------------------------------------
l9a4eh:
	ld a,(l8831h+2)		;9a4e	3a 33 88	: 3 .
	cp 001h			;9a51	fe 01		. .
	jr nz,l9a68h		;9a53	20 13		  .
	ld hl,(l8850h)		;9a55	2a 50 88	* P .
	ld de,(l885ch)		;9a58	ed 5b 5c 88	. [ \ .
	ld a,d			;9a5c	7a		z
	cp h			;9a5d	bc		.
	jp c,l9addh		;9a5e	da dd 9a	. . .
	jr nz,l9a68h		;9a61	20 05		  .
	ld a,e			;9a63	7b		{
	cp l			;9a64	bd		.
	jp c,l9addh		;9a65	da dd 9a	. . .
l9a68h:
	ld hl,(l8821h)		;9a68	2a 21 88	* ! .
	ld e,(hl)		;9a6b	5e		^
	inc hl			;9a6c	23		#
	ld d,(hl)		;9a6d	56		V
	ld a,d			;9a6e	7a		z
	and a			;9a6f	a7		.
	jp z,l9addh		;9a70	ca dd 9a	. . .
	ld (l8821h),de		;9a73	ed 53 21 88	. S ! .
	ld hl,(l881fh)		;9a77	2a 1f 88	* . .
	ld (hl),e		;9a7a	73		s
	inc hl			;9a7b	23		#
	ld (hl),d		;9a7c	72		r
	ld a,(l8831h+2)		;9a7d	3a 33 88	: 3 .
	ld hl,l8831h+1		;9a80	21 32 88	! 2 .
	cp (hl)			;9a83	be		.
	jr c,l9aach		;9a84	38 26		8 &
	call sub_9440h		;9a86	cd 40 94	. @ .
	call sub_933bh		;9a89	cd 3b 93	. ; .
	and a			;9a8c	a7		.
	jr z,l9a94h		;9a8d	28 05		( .
	call sub_94e7h		;9a8f	cd e7 94	. . .
	jr l9a4eh		;9a92	18 ba		. .
l9a94h:
	ld a,(l8831h+2)		;9a94	3a 33 88	: 3 .
	ld hl,l8831h+1		;9a97	21 32 88	! 2 .
	cp (hl)			;9a9a	be		.
	jp c,l9b08h		;9a9b	da 08 9b	. . .
	ld a,(l882ch)		;9a9e	3a 2c 88	: , .
	xor 080h		;9aa1	ee 80		. .
	call sub_933eh		;9aa3	cd 3e 93	. > .
	and a			;9aa6	a7		.
	jr nz,l9abbh		;9aa7	20 12		  .
	jp l9b08h		;9aa9	c3 08 9b	. . .
l9aach:
	call sub_9440h		;9aac	cd 40 94	. @ .
	call sub_933bh		;9aaf	cd 3b 93	. ; .
	and a			;9ab2	a7		.
	jr z,l9abbh		;9ab3	28 06		( .
	call sub_94e7h		;9ab5	cd e7 94	. . .
	jp l9a4eh		;9ab8	c3 4e 9a	. N .
; ---------------------------------------------------------------------------
; MINIMAX FLIP
; Toggles side-to-move (XOR 80h on color flag), increments
; the ply counter, and recurses into the next search depth.
; ---------------------------------------------------------------------------
l9abbh:
	ld a,(l8831h+2)		;9abb	3a 33 88	: 3 .
	cp 001h			;9abe	fe 01		. .
	ld hl,l882ch		;9ac0	21 2c 88	! , .
	ld a,080h		;9ac3	3e 80		> .
	xor (hl)		;9ac5	ae		.	; Toggle side-to-move (XOR 80h)
	ld (hl),a		;9ac6	77		w
	bit 7,a			;9ac7	cb 7f		. .
	jr nz,l9acfh		;9ac9	20 04		  .
	ld hl,l8831h		;9acb	21 31 88	! 1 .
	inc (hl)		;9ace	34		4
l9acfh:
	ld hl,(l8823h)		;9acf	2a 23 88	* # .
	ld a,(hl)		;9ad2	7e		~
	inc hl			;9ad3	23		#
	inc hl			;9ad4	23		#
	ld (hl),a		;9ad5	77		w
	dec hl			;9ad6	2b		+
	ld (l8823h),hl		;9ad7	22 23 88	" # .
	jp l9a15h		;9ada	c3 15 9a	. . .	; Continue to next iteration
; ---------------------------------------------------------------------------
; TERMINAL NODE EVALUATION
; Handles leaf nodes of the search tree. Detects checkmate
; and stalemate, calls position evaluation (full at ply 1,
; lightweight at deeper plies), and returns the score.
; ---------------------------------------------------------------------------
l9addh:
	ld a,(l8835h)		;9add	3a 35 88	: 5 .
	and a			;9ae0	a7		.
	jr nz,l9af5h		;9ae1	20 12		  .
	ld a,(l8834h)		;9ae3	3a 34 88	: 4 .
	and a			;9ae6	a7		.
	ld a,080h		;9ae7	3e 80		> .
	jr z,l9b34h		;9ae9	28 49		( I
	ld a,(l8831h)		;9aeb	3a 31 88	: 1 .
	ld (l8830h),a		;9aee	32 30 88	2 0 .
	ld a,0ffh		;9af1	3e ff		> .
	jr l9b34h		;9af3	18 3f		. ?
l9af5h:
	ld a,(l8831h+2)		;9af5	3a 33 88	: 3 .
	cp 001h			;9af8	fe 01		. .
	ret z			;9afa	c8		.
	call sub_a452h		;9afb	cd 52 a4	. R .
	ld hl,(l8823h)		;9afe	2a 23 88	* # .
	inc hl			;9b01	23		#
	inc hl			;9b02	23		#
	ld a,(hl)		;9b03	7e		~
	dec hl			;9b04	2b		+
	dec hl			;9b05	2b		+
	jr l9b3ch		;9b06	18 34		. 4
l9b08h:
	call sub_9ca1h		;9b08	cd a1 9c	. . .
	ld a,(l8831h+2)		;9b0b	3a 33 88	: 3 .
	cp 001h			;9b0e	fe 01		. .
	push af			;9b10	f5		.
	call z,sub_9d75h	;9b11	cc 75 9d	. u .	; Full eval at ply 1
	pop af			;9b14	f1		.
	call nz,sub_a200h	;9b15	c4 00 a2	. . .	; Lightweight eval at deeper plies
	ld hl,l8831h+1		;9b18	21 32 88	! 2 .
	ld a,(l8831h+2)		;9b1b	3a 33 88	: 3 .
	cp (hl)			;9b1e	be		.
	jr nz,l9b2eh		;9b1f	20 0d		  .
	ld a,(l885eh+2)		;9b21	3a 60 88	: ` .
	cp 00ah			;9b24	fe 0a		. .
	jr nz,l9b2eh		;9b26	20 06		  .
	ld a,(l883ch)		;9b28	3a 3c 88	: < .
	and a			;9b2b	a7		.
	jr nz,l9abbh		;9b2c	20 8d		  .
l9b2eh:
	call sub_94e7h		;9b2e	cd e7 94	. . .
	ld a,(l8835h+1)		;9b31	3a 36 88	: 6 .
l9b34h:
	ld hl,l8835h		;9b34	21 35 88	! 5 .
	set 0,(hl)		;9b37	cb c6		. .
	ld hl,(l8823h)		;9b39	2a 23 88	* # .
l9b3ch:
	call sub_9c21h		;9b3c	cd 21 9c	. ! .
	cp (hl)			;9b3f	be		.
	jr c,l9b88h		;9b40	38 46		8 F
	jr z,l9b88h		;9b42	28 44		( D
	neg			;9b44	ed 44		. D
	inc hl			;9b46	23		#
	cp (hl)			;9b47	be		.
	jp c,l9a4eh		;9b48	da 4e 9a	. N .
	jp z,l9a4eh		;9b4b	ca 4e 9a	. N .
	ld (hl),a		;9b4e	77		w
	ld a,(l8831h+2)		;9b4f	3a 33 88	: 3 .
	bit 0,a			;9b52	cb 47		. G
	call nz,sub_9b96h	;9b54	c4 96 9b	. . .
	ld a,(l8831h+2)		;9b57	3a 33 88	: 3 .
	cp 001h			;9b5a	fe 01		. .
	jp nz,l9a4eh		;9b5c	c2 4e 9a	. N .
	ld hl,(l8821h)		;9b5f	2a 21 88	* ! .
	ld (l8825h),hl		;9b62	22 25 88	" % .
	ld a,001h		;9b65	3e 01		> .
	ld (l884dh+2),a		;9b67	32 4f 88	2 O .
	ld a,(l8954h)		;9b6a	3a 54 89	: T .
	cp 0ffh			;9b6d	fe ff		. .
	jp nz,l9a4eh		;9b6f	c2 4e 9a	. N .
	ld hl,l8831h+1		;9b72	21 32 88	! 2 .
	ld a,(l8871h+2)		;9b75	3a 73 88	: s .
	and a			;9b78	a7		.
	jr z,l9b7dh		;9b79	28 02		( .
	dec (hl)		;9b7b	35		5
	dec (hl)		;9b7c	35		5
l9b7dh:
	ld a,(l882bh)		;9b7d	3a 2b 88	: + .
	bit 7,a			;9b80	cb 7f		. .
	ret z			;9b82	c8		.
	ld hl,l8830h		;9b83	21 30 88	! 0 .
	dec (hl)		;9b86	35		5
	ret			;9b87	c9		.
l9b88h:
	ld a,(l8831h+2)		;9b88	3a 33 88	: 3 .
	bit 0,a			;9b8b	cb 47		. G
	call z,sub_9b96h	;9b8d	cc 96 9b	. . .
	call sub_a452h		;9b90	cd 52 a4	. R .
	jp l9a4eh		;9b93	c3 4e 9a	. N .
; ---------------------------------------------------------------------------
; HISTORY TABLE UPDATE
; Records killer/refutation moves for move ordering. Stores
; from-to pairs indexed by search depth in a 30-byte table
; at 8B60h. Swaps entries to maintain best-first ordering.
; ---------------------------------------------------------------------------
sub_9b96h:
	ld a,(l8831h+2)		;9b96	3a 33 88	: 3 .
	ld b,a			;9b99	47		G
	ld de,0001eh		;9b9a	11 1e 00	. . .
	ld hl,l8b60h		;9b9d	21 60 8b	! ` .
l9ba0h:
	add hl,de		;9ba0	19		.
	djnz l9ba0h		;9ba1	10 fd		. .
	ld ix,(l8821h)		;9ba3	dd 2a 21 88	. * ! .
	ld d,(ix+002h)		;9ba7	dd 56 02	. V .
	ld e,(ix+003h)		;9baa	dd 5e 03	. ^ .
	ld b,000h		;9bad	06 00		. .
	ld (l8853h),hl		;9baf	22 53 88	" S .
l9bb2h:
	ld a,(hl)		;9bb2	7e		~
	and a			;9bb3	a7		.
	jr z,l9bdfh		;9bb4	28 29		( )
	inc hl			;9bb6	23		#
	cp d			;9bb7	ba		.
	jr nz,l9bc0h		;9bb8	20 06		  .
	ld a,(hl)		;9bba	7e		~
	cp e			;9bbb	bb		.
	jr nz,l9bc0h		;9bbc	20 02		  .
	jr l9be2h		;9bbe	18 22		. "
l9bc0h:
	inc hl			;9bc0	23		#
	inc hl			;9bc1	23		#
	inc b			;9bc2	04		.
	ld a,00ah		;9bc3	3e 0a		> .
	cp b			;9bc5	b8		.
	jr nz,l9bb2h		;9bc6	20 ea		  .
	ld hl,(l8853h)		;9bc8	2a 53 88	* S .
	ld bc,00012h		;9bcb	01 12 00	. . .
	add hl,bc		;9bce	09		.
	ld b,00ch		;9bcf	06 0c		. .
	xor a			;9bd1	af		.
l9bd2h:
	ld (hl),a		;9bd2	77		w
	inc hl			;9bd3	23		#
	djnz l9bd2h		;9bd4	10 fc		. .
	ld hl,(l8853h)		;9bd6	2a 53 88	* S .
	ld bc,00012h		;9bd9	01 12 00	. . .
	add hl,bc		;9bdc	09		.
	ld b,006h		;9bdd	06 06		. .
l9bdfh:
	ld (hl),d		;9bdf	72		r
	inc hl			;9be0	23		#
	ld (hl),e		;9be1	73		s
l9be2h:
	inc hl			;9be2	23		#
	inc (hl)		;9be3	34		4
	ld a,(hl)		;9be4	7e		~
	and a			;9be5	a7		.
	jr nz,l9beah		;9be6	20 02		  .
	ld (hl),0ffh		;9be8	36 ff		6 .
l9beah:
	ld a,b			;9bea	78		x
	and a			;9beb	a7		.
	ret z			;9bec	c8		.
	push hl			;9bed	e5		.
	pop ix			;9bee	dd e1		. .
	ld a,(ix-003h)		;9bf0	dd 7e fd	. ~ .
	cp (hl)			;9bf3	be		.
	ret nc			;9bf4	d0		.
	ld d,(hl)		;9bf5	56		V
	ld (ix-003h),d		;9bf6	dd 72 fd	. r .
	ld (hl),a		;9bf9	77		w
	dec hl			;9bfa	2b		+
	ld a,(ix-004h)		;9bfb	dd 7e fc	. ~ .
	ld d,(hl)		;9bfe	56		V
	ld (ix-004h),d		;9bff	dd 72 fc	. r .
	ld (hl),a		;9c02	77		w
	dec hl			;9c03	2b		+
	ld a,(ix-005h)		;9c04	dd 7e fb	. ~ .
	ld d,(hl)		;9c07	56		V
	ld (ix-005h),d		;9c08	dd 72 fb	. r .
	ld (hl),a		;9c0b	77		w
	dec hl			;9c0c	2b		+
	dec b			;9c0d	05		.
	jr l9beah		;9c0e	18 da		. .
l9c10h:
	call sub_a845h		;9c10	cd 45 a8	. E .
	ld hl,lb28ah		;9c13	21 8a b2	! . .
	ld de,l8dceh+1		;9c16	11 cf 8d	. . .
	ld bc,00009h		;9c19	01 09 00	. . .
	ldir			;9c1c	ed b0		. .
	jp l9c74h		;9c1e	c3 74 9c	. t .
; ---------------------------------------------------------------------------
; INCREMENT NODE COUNTER
; Increments the 3-byte position counter at 8850h, tracking
; how many positions have been evaluated during the search.
; ---------------------------------------------------------------------------
sub_9c21h:
	push hl			;9c21	e5		.
	ld hl,(l8850h)		;9c22	2a 50 88	* P .
	inc hl			;9c25	23		#
	ld (l8850h),hl		;9c26	22 50 88	" P .
	pop hl			;9c29	e1		.
	ret			;9c2a	c9		.
sub_9c2bh:
	ld a,(l8831h)		;9c2b	3a 31 88	: 1 .
	ld b,a			;9c2e	47		G
	ld a,(l8830h)		;9c2f	3a 30 88	: 0 .
	sub b			;9c32	90		.
	and a			;9c33	a7		.
	jr nz,l9c7ch		;9c34	20 46		  F
	bit 0,c			;9c36	cb 41		. A
	jr z,l9c58h		;9c38	28 1e		( .
	call sub_a845h		;9c3a	cd 45 a8	. E .
	ld hl,lb0d5h		;9c3d	21 d5 b0	! . .
	ld de,l8dceh+1		;9c40	11 cf 8d	. . .
	ld bc,00009h		;9c43	01 09 00	. . .
	ldir			;9c46	ed b0		. .
	call sub_a845h		;9c48	cd 45 a8	. E .
	ld hl,lb116h		;9c4b	21 16 b1	! . .
	ld de,l8dceh+1		;9c4e	11 cf 8d	. . .
	ld bc,00007h		;9c51	01 07 00	. . .
	ldir			;9c54	ed b0		. .
	jr l9c74h		;9c56	18 1c		. .
l9c58h:
	call sub_a845h		;9c58	cd 45 a8	. E .
	ld hl,lb0dah		;9c5b	21 da b0	! . .
	ld de,l8dceh+1		;9c5e	11 cf 8d	. . .
	ld bc,00004h		;9c61	01 04 00	. . .
	ldir			;9c64	ed b0		. .
	call sub_a845h		;9c66	cd 45 a8	. E .
	ld hl,lb11dh		;9c69	21 1d b1	! . .
	ld de,l8dceh+1		;9c6c	11 cf 8d	. . .
	ld bc,00005h		;9c6f	01 05 00	. . .
	ldir			;9c72	ed b0		. .
l9c74h:
	pop hl			;9c74	e1		.
	pop hl			;9c75	e1		.
	call sub_aab2h		;9c76	cd b2 aa	. . .
	jp l8e79h		;9c79	c3 79 8e	. y .
l9c7ch:
	bit 0,c			;9c7c	cb 41		. A
	ret nz			;9c7e	c0		.
	call sub_a845h		;9c7f	cd 45 a8	. E .
	add a,030h		;9c82	c6 30		. 0
	ld hl,lb0dah		;9c84	21 da b0	! . .
	ld de,l8dceh+1		;9c87	11 cf 8d	. . .
	ld bc,00008h		;9c8a	01 08 00	. . .
	ldir			;9c8d	ed b0		. .
	ld (de),a		;9c8f	12		.
	jr l9c74h		;9c90	18 e2		. .
; ---------------------------------------------------------------------------
; CONVERT BOARD INDEX TO ALGEBRAIC
; Maps a 10x12 mailbox square index to file letter (A-H)
; and rank digit (1-8) for display. Uses division by 10.
; Returns: L = file letter, H = rank digit
; ---------------------------------------------------------------------------
sub_9c92h:
	sub a			;9c92	97		.	; A = 0 for division
	ld e,00ah		;9c93	1e 0a		. .	; Divide by 10 (mailbox width)
	call sub_9267h		;9c95	cd 67 92	. g .	; D = quotient (rank), A = remainder (file)
	dec d			;9c98	15		.	; Adjust rank to 0-based
	add a,040h		;9c99	c6 40		. @	; Convert file to ASCII letter
	ld l,a			;9c9b	6f		o	; L = file letter ('A'-'H')
	ld a,d			;9c9c	7a		z
	add a,030h		;9c9d	c6 30		. 0	; Convert rank to ASCII digit
	ld h,a			;9c9f	67		g	; H = rank digit ('1'-'8')
	ret			;9ca0	c9		.
; ---------------------------------------------------------------------------
; PIN DETECTION AND KING SAFETY
; Scans rays from both kings outward to detect pinned pieces.
; A piece is pinned if removing it would expose its king to
; attack along that ray. Sets pin flags for the evaluator.
; ---------------------------------------------------------------------------
sub_9ca1h:
	xor a			;9ca1	af		.
	ld (l881dh),a		;9ca2	32 1d 88	2 . .
	ld de,l894eh		;9ca5	11 4e 89	. N .
l9ca8h:
	ld a,(de)		;9ca8	1a		.
	and a			;9ca9	a7		.
	jp z,l9d71h		;9caa	ca 71 9d	. q .
	cp 0ffh			;9cad	fe ff		. .
	ret z			;9caf	c8		.
	ld (l880dh),a		;9cb0	32 0d 88	2 . .
	ld ix,(l880dh)		;9cb3	dd 2a 0d 88	. * . .
	ld a,(ix-04ch)		;9cb7	dd 7e b4	. ~ .
	ld (l882dh),a		;9cba	32 2d 88	2 - .
	ld b,008h		;9cbd	06 08		. .
	xor a			;9cbf	af		.
	ld (l8819h),a		;9cc0	32 19 88	2 . .
l9cc3h:
	ld ix,(l8819h)		;9cc3	dd 2a 19 88	. * . .
	ld a,(l880dh)		;9cc7	3a 0d 88	: . .
	ld (l880bh),a		;9cca	32 0b 88	2 . .
	xor a			;9ccd	af		.
	ld (l880fh),a		;9cce	32 0f 88	2 . .
	ld c,(ix-080h)		;9cd1	dd 4e 80	. N .
l9cd4h:
	ld hl,l880bh		;9cd4	21 0b 88	! . .
	ld a,(hl)		;9cd7	7e		~
	add a,c			;9cd8	81		.
	ld (hl),a		;9cd9	77		w
	ld ix,(l880bh)		;9cda	dd 2a 0b 88	. * . .
	ld a,(ix-04ch)		;9cde	dd 7e b4	. ~ .
	cp 0ffh			;9ce1	fe ff		. .
	jp z,l9d69h		;9ce3	ca 69 9d	. i .
	ld (l882dh+1),a		;9ce6	32 2e 88	2 . .
	and 007h		;9ce9	e6 07		. .
	ld (l8813h),a		;9ceb	32 13 88	2 . .
	jr z,l9cd4h		;9cee	28 e4		( .
	ld a,(l882dh+1)		;9cf0	3a 2e 88	: . .
	ld hl,l882dh		;9cf3	21 2d 88	! - .
	xor (hl)		;9cf6	ae		.
	ld a,(l880fh)		;9cf7	3a 0f 88	: . .
	jp p,l9d1bh		;9cfa	f2 1b 9d	. . .
	and a			;9cfd	a7		.
	jr z,l9d69h		;9cfe	28 69		( i
	ld a,(l8813h)		;9d00	3a 13 88	: . .
	cp 005h			;9d03	fe 05		. .
	jr z,l9d26h		;9d05	28 1f		( .
	ld l,a			;9d07	6f		o
	ld a,b			;9d08	78		x
	cp 005h			;9d09	fe 05		. .
	jr c,l9d14h		;9d0b	38 07		8 .
	ld a,l			;9d0d	7d		}
	cp 003h			;9d0e	fe 03		. .
	jr nz,l9d69h		;9d10	20 57		  W
	jr l9d58h		;9d12	18 44		. D
l9d14h:
	ld a,l			;9d14	7d		}
	cp 004h			;9d15	fe 04		. .
	jr nz,l9d69h		;9d17	20 50		  P
	jr l9d58h		;9d19	18 3d		. =
l9d1bh:
	and a			;9d1b	a7		.
	jr nz,l9d69h		;9d1c	20 4b		  K
	ld a,(l880bh)		;9d1e	3a 0b 88	: . .
	ld (l880fh),a		;9d21	32 0f 88	2 . .
	jr l9cd4h		;9d24	18 ae		. .
l9d26h:
	ld a,(l882dh)		;9d26	3a 2d 88	: - .
	and 007h		;9d29	e6 07		. .
	cp 005h			;9d2b	fe 05		. .
	jr nz,l9d58h		;9d2d	20 29		  )
	push bc			;9d2f	c5		.
	push de			;9d30	d5		.
	xor a			;9d31	af		.
	ld b,00eh		;9d32	06 0e		. .
	ld hl,l892ch		;9d34	21 2c 89	! , .
l9d37h:
	ld (hl),a		;9d37	77		w
	inc hl			;9d38	23		#
	djnz l9d37h		;9d39	10 fc		. .
	ld a,007h		;9d3b	3e 07		> .
	ld (l8811h),a		;9d3d	32 11 88	2 . .
	call sub_935ch		;9d40	cd 5c 93	. \ .
	ld hl,l892ch		;9d43	21 2c 89	! , .
	ld de,l8933h		;9d46	11 33 89	. 3 .
	ld a,(l882dh)		;9d49	3a 2d 88	: - .
	jp p,l9d50h		;9d4c	f2 50 9d	. P .
	ex de,hl		;9d4f	eb		.
l9d50h:
	ld a,(hl)		;9d50	7e		~
	ex de,hl		;9d51	eb		.
	sub (hl)		;9d52	96		.
	dec a			;9d53	3d		=
	pop de			;9d54	d1		.
	pop bc			;9d55	c1		.
	jr l9d69h		;9d56	18 11		. .
l9d58h:
	ld hl,l881dh		;9d58	21 1d 88	! . .
	inc (hl)		;9d5b	34		4
	ld ix,(l881dh)		;9d5c	dd 2a 1d 88	. * . .
	ld (ix+043h),c		;9d60	dd 71 43	. q C
	ld a,(l880fh)		;9d63	3a 0f 88	: . .
	ld (ix+039h),a		;9d66	dd 77 39	. w 9
l9d69h:
	ld hl,l8819h		;9d69	21 19 88	! . .
	inc (hl)		;9d6c	34		4
	dec b			;9d6d	05		.
	jp nz,l9cc3h		;9d6e	c2 c3 9c	. . .
l9d71h:
	inc de			;9d71	13		.
	jp l9ca8h		;9d72	c3 a8 9c	. . .
; ---------------------------------------------------------------------------
; FULL POSITION EVALUATION (PLY 1)
; Comprehensive evaluation at the first search ply. Scores
; material balance, pawn structure, king safety, mobility,
; piece-square bonuses, and positional factors.
; ---------------------------------------------------------------------------
sub_9d75h:
	xor a			;9d75	af		.
	ld (l883eh),a		;9d76	32 3e 88	2 > .
	ld (l8838h),a		;9d79	32 38 88	2 8 .
	ld (l8843h+1),a		;9d7c	32 44 88	2 D .
	ld (l8843h),a		;9d7f	32 43 88	2 C .
	ld (l8841h),a		;9d82	32 41 88	2 A .
	ld (l883eh+1),a		;9d85	32 3f 88	2 ? .
	ld (l8848h+2),a		;9d88	32 4a 88	2 J .
	ld (l8839h),a		;9d8b	32 39 88	2 9 .
	ld (l883ah),a		;9d8e	32 3a 88	2 : .
	ld (l883bh),a		;9d91	32 3b 88	2 ; .
	ld (l884bh),a		;9d94	32 4b 88	2 K .
	ld (l884ch),a		;9d97	32 4c 88	2 L .
	ld (l883ch),a		;9d9a	32 3c 88	2 < .
	call sub_a344h		;9d9d	cd 44 a3	. D .
	ld hl,l8811h		;9da0	21 11 88	! . .
	ld (hl),007h		;9da3	36 07		6 .
	ld a,015h		;9da5	3e 15		> .
l9da7h:
	ld (l880dh),a		;9da7	32 0d 88	2 . .
	ld ix,(l880dh)		;9daa	dd 2a 0d 88	. * . .
	ld a,(ix-04ch)		;9dae	dd 7e b4	. ~ .
	cp 0ffh			;9db1	fe ff		. .
	jp z,l9fe2h		;9db3	ca e2 9f	. . .
	ld hl,l882dh		;9db6	21 2d 88	! - .
	ld (hl),a		;9db9	77		w
	and 007h		;9dba	e6 07		. .
	ld (l8815h),a		;9dbc	32 15 88	2 . .
	and a			;9dbf	a7		.
	jp z,l9f22h		;9dc0	ca 22 9f	. " .
	cp 001h			;9dc3	fe 01		. .
	jr z,l9e33h		;9dc5	28 6c		( l
	cp 002h			;9dc7	fe 02		. .
	jr z,l9de4h		;9dc9	28 19		( .
	cp 003h			;9dcb	fe 03		. .
	jr z,l9df3h		;9dcd	28 24		( $
	cp 006h			;9dcf	fe 06		. .
	jr z,l9e02h		;9dd1	28 2f		( /
	ld a,(l8831h)		;9dd3	3a 31 88	: 1 .
	cp 008h			;9dd6	fe 08		. .
	jp nc,l9f22h		;9dd8	d2 22 9f	. " .
	ld a,(l8815h)		;9ddb	3a 15 88	: . .
	cp 004h			;9dde	fe 04		. .
	jr z,l9e17h		;9de0	28 35		( 5
	jr l9e1eh		;9de2	18 3a		. :
l9de4h:
	bit 3,(hl)		;9de4	cb 5e		. ^
	jp nz,l9f22h		;9de6	c2 22 9f	. " .
l9de9h:
	ld a,0fbh		;9de9	3e fb		> .
	bit 7,(hl)		;9deb	cb 7e		. ~
	jr z,l9e2bh		;9ded	28 3c		( <
	ld a,005h		;9def	3e 05		> .
	jr l9e2bh		;9df1	18 38		. 8
l9df3h:
	bit 3,(hl)		;9df3	cb 5e		. ^
	jp nz,l9f22h		;9df5	c2 22 9f	. " .
l9df8h:
	ld a,0fch		;9df8	3e fc		> .
	bit 7,(hl)		;9dfa	cb 7e		. ~
	jr z,l9e2bh		;9dfc	28 2d		( -
	ld a,004h		;9dfe	3e 04		> .
	jr l9e2bh		;9e00	18 29		. )
l9e02h:
	bit 4,(hl)		;9e02	cb 66		. f
	jr z,l9e10h		;9e04	28 0a		( .
	ld a,006h		;9e06	3e 06		> .
	bit 7,(hl)		;9e08	cb 7e		. ~
	jr z,l9e2bh		;9e0a	28 1f		( .
	ld a,0fah		;9e0c	3e fa		> .
	jr l9e2bh		;9e0e	18 1b		. .
l9e10h:
	bit 3,(hl)		;9e10	cb 5e		. ^
	jp z,l9f22h		;9e12	ca 22 9f	. " .
	jr l9de9h		;9e15	18 d2		. .
l9e17h:
	bit 3,(hl)		;9e17	cb 5e		. ^
	jp z,l9f22h		;9e19	ca 22 9f	. " .
	jr l9df8h		;9e1c	18 da		. .
l9e1eh:
	bit 3,(hl)		;9e1e	cb 5e		. ^
	jp z,l9f22h		;9e20	ca 22 9f	. " .
	ld a,0f8h		;9e23	3e f8		> .
	bit 7,(hl)		;9e25	cb 7e		. ~
	jr z,l9e2bh		;9e27	28 02		( .
	ld a,008h		;9e29	3e 08		> .
l9e2bh:
	ld hl,l8838h		;9e2b	21 38 88	! 8 .
	add a,(hl)		;9e2e	86		.
	ld (hl),a		;9e2f	77		w
	jp l9f22h		;9e30	c3 22 9f	. " .
l9e33h:
	bit 7,(hl)		;9e33	cb 7e		. ~
	ld hl,la15dh		;9e35	21 5d a1	! ] .
	jr z,l9e3dh		;9e38	28 03		( .
	ld hl,la103h		;9e3a	21 03 a1	! . .
l9e3dh:
	ld a,(l880dh)		;9e3d	3a 0d 88	: . .
	ld b,000h		;9e40	06 00		. .
	ld c,a			;9e42	4f		O
	add hl,bc		;9e43	09		.
	ld a,(hl)		;9e44	7e		~
	ld hl,l8843h		;9e45	21 43 88	! C .
	add a,(hl)		;9e48	86		.
	ld (hl),a		;9e49	77		w
	ld a,(l882bh)		;9e4a	3a 2b 88	: + .
	and a			;9e4d	a7		.
	ld hl,l8cc8h		;9e4e	21 c8 8c	! . .
	jr z,l9e56h		;9e51	28 03		( .
	ld hl,l8c50h		;9e53	21 50 8c	! P .
l9e56h:
	ld a,(l880dh)		;9e56	3a 0d 88	: . .
	ld b,000h		;9e59	06 00		. .
	ld c,a			;9e5b	4f		O
	add hl,bc		;9e5c	09		.
	ld a,(hl)		;9e5d	7e		~
	ld hl,l8848h+2		;9e5e	21 4a 88	! J .
	add a,(hl)		;9e61	86		.
	ld (hl),a		;9e62	77		w
	ld d,000h		;9e63	16 00		. .
	ld hl,l88b4h		;9e65	21 b4 88	! . .
	ld a,(l880dh)		;9e68	3a 0d 88	: . .
	ld b,000h		;9e6b	06 00		. .
	ld c,a			;9e6d	4f		O
	add hl,bc		;9e6e	09		.
	bit 7,(hl)		;9e6f	cb 7e		. ~
	jr nz,l9ec6h		;9e71	20 53		  S
	ld c,00ah		;9e73	0e 0a		. .
	add hl,bc		;9e75	09		.
	ld a,(hl)		;9e76	7e		~
	cp 0ffh			;9e77	fe ff		. .
	jp z,l9f1ch		;9e79	ca 1c 9f	. . .
	cp 000h			;9e7c	fe 00		. .
	jr z,l9eb4h		;9e7e	28 34		( 4
	bit 7,(hl)		;9e80	cb 7e		. ~
	ld a,0fdh		;9e82	3e fd		> .
	jr nz,l9eb2h		;9e84	20 2c		  ,
	ld a,(hl)		;9e86	7e		~
	and 007h		;9e87	e6 07		. .
	cp 001h			;9e89	fe 01		. .
	jr z,l9eb0h		;9e8b	28 23		( #
	cp 002h			;9e8d	fe 02		. .
	jr z,l9ea4h		;9e8f	28 13		( .
	cp 003h			;9e91	fe 03		. .
	ld a,0ffh		;9e93	3e ff		> .
	jr nz,l9eb2h		;9e95	20 1b		  .
	ld a,(l8831h)		;9e97	3a 31 88	: 1 .
	cp 00ah			;9e9a	fe 0a		. .
	ld a,0ffh		;9e9c	3e ff		> .
	jr nc,l9eb2h		;9e9e	30 12		0 .
	ld a,0fdh		;9ea0	3e fd		> .
	jr l9eb2h		;9ea2	18 0e		. .
l9ea4h:
	ld a,(l8831h)		;9ea4	3a 31 88	: 1 .
	cp 005h			;9ea7	fe 05		. .
	ld a,0ffh		;9ea9	3e ff		> .
	jr c,l9eb2h		;9eab	38 05		8 .
	xor a			;9ead	af		.
	jr l9eb2h		;9eae	18 02		. .
l9eb0h:
	ld a,0fch		;9eb0	3e fc		> .
l9eb2h:
	add a,d			;9eb2	82		.
	ld d,a			;9eb3	57		W
l9eb4h:
	add hl,bc		;9eb4	09		.
	ld a,(hl)		;9eb5	7e		~
	cp 0ffh			;9eb6	fe ff		. .
	jr z,l9f1ch		;9eb8	28 62		( b
	and 087h		;9eba	e6 87		. .
	cp 001h			;9ebc	fe 01		. .
	jr nz,l9eb4h		;9ebe	20 f4		  .
	ld a,0fch		;9ec0	3e fc		> .
	add a,d			;9ec2	82		.
	ld d,a			;9ec3	57		W
	jr l9f1ch		;9ec4	18 56		. V
l9ec6h:
	ld c,00ah		;9ec6	0e 0a		. .
	scf			;9ec8	37		7
	ccf			;9ec9	3f		?
	sbc hl,bc		;9eca	ed 42		. B
	ld a,(hl)		;9ecc	7e		~
	cp 0ffh			;9ecd	fe ff		. .
	jr z,l9f1ch		;9ecf	28 4b		( K
	and a			;9ed1	a7		.
	jr z,l9f09h		;9ed2	28 35		( 5
	bit 7,(hl)		;9ed4	cb 7e		. ~
	ld a,003h		;9ed6	3e 03		> .
	jr z,l9f07h		;9ed8	28 2d		( -
	ld a,(hl)		;9eda	7e		~
	and 007h		;9edb	e6 07		. .
	cp 001h			;9edd	fe 01		. .
	jp z,l9f05h		;9edf	ca 05 9f	. . .
	cp 002h			;9ee2	fe 02		. .
	jr z,l9ef9h		;9ee4	28 13		( .
	cp 003h			;9ee6	fe 03		. .
	ld a,001h		;9ee8	3e 01		> .
	jr nz,l9f07h		;9eea	20 1b		  .
	ld a,(l8831h)		;9eec	3a 31 88	: 1 .
	cp 00ah			;9eef	fe 0a		. .
	ld a,001h		;9ef1	3e 01		> .
	jr nc,l9f07h		;9ef3	30 12		0 .
	ld a,003h		;9ef5	3e 03		> .
	jr l9f07h		;9ef7	18 0e		. .
l9ef9h:
	ld a,(l8831h)		;9ef9	3a 31 88	: 1 .
	cp 005h			;9efc	fe 05		. .
	ld a,001h		;9efe	3e 01		> .
	jr c,l9f07h		;9f00	38 05		8 .
	xor a			;9f02	af		.
	jr l9f07h		;9f03	18 02		. .
l9f05h:
	ld a,004h		;9f05	3e 04		> .
l9f07h:
	add a,d			;9f07	82		.
	ld d,a			;9f08	57		W
l9f09h:
	scf			;9f09	37		7
	ccf			;9f0a	3f		?
	sbc hl,bc		;9f0b	ed 42		. B
	ld a,(hl)		;9f0d	7e		~
	cp 0ffh			;9f0e	fe ff		. .
	jr z,l9f1ch		;9f10	28 0a		( .
	and 087h		;9f12	e6 87		. .
	cp 081h			;9f14	fe 81		. .
	jr nz,l9f09h		;9f16	20 f1		  .
	ld a,004h		;9f18	3e 04		> .
	add a,d			;9f1a	82		.
	ld d,a			;9f1b	57		W
l9f1ch:
	ld hl,l8841h		;9f1c	21 41 88	! A .
	ld a,d			;9f1f	7a		z
	add a,(hl)		;9f20	86		.
	ld (hl),a		;9f21	77		w
l9f22h:
	ld hl,l8a70h		;9f22	21 70 8a	! p .
	ld d,000h		;9f25	16 00		. .
	ld a,(l880dh)		;9f27	3a 0d 88	: . .
	ld e,a			;9f2a	5f		_
	add hl,de		;9f2b	19		.
	ld b,h			;9f2c	44		D
	ld c,l			;9f2d	4d		M
	ld hl,l8ae8h		;9f2e	21 e8 8a	! . .
	add hl,de		;9f31	19		.
	ld a,(bc)		;9f32	0a		.
	sub (hl)		;9f33	96		.
	push hl			;9f34	e5		.
	push bc			;9f35	c5		.
	call nz,sub_a1ddh	;9f36	c4 dd a1	. . .
	ld hl,l8843h+1		;9f39	21 44 88	! D .
	add a,(hl)		;9f3c	86		.
	ld (hl),a		;9f3d	77		w
	pop bc			;9f3e	c1		.
	pop hl			;9f3f	e1		.
	ld a,(l882dh)		;9f40	3a 2d 88	: - .
	and a			;9f43	a7		.
	jp z,l9fe2h		;9f44	ca e2 9f	. . .
	ld a,(l883eh+1)		;9f47	3a 3f 88	: ? .
	inc a			;9f4a	3c		<
	ld (l883eh+1),a		;9f4b	32 3f 88	2 ? .
	ld a,(l882dh)		;9f4e	3a 2d 88	: - .
	bit 7,a			;9f51	cb 7f		. .
	ld a,(hl)		;9f53	7e		~
	jr z,l9f57h		;9f54	28 01		( .
	ld a,(bc)		;9f56	0a		.
l9f57h:
	and a			;9f57	a7		.
	jr nz,l9f70h		;9f58	20 16		  .
	ld a,(l882dh)		;9f5a	3a 2d 88	: - .
	and 007h		;9f5d	e6 07		. .
	ld (l8815h),a		;9f5f	32 15 88	2 . .
	ld ix,(l8815h)		;9f62	dd 2a 15 88	. * . .
	ld d,(ix-05bh)		;9f66	dd 56 a5	. V .
	sla d			;9f69	cb 22		. "
	sla d			;9f6b	cb 22		. "
	jp la1c1h		;9f6d	c3 c1 a1	. . .
l9f70h:
	xor a			;9f70	af		.
	ld b,00eh		;9f71	06 0e		. .
	ld hl,l892ch		;9f73	21 2c 89	! , .
l9f76h:
	ld (hl),a		;9f76	77		w
	inc hl			;9f77	23		#
	djnz l9f76h		;9f78	10 fc		. .
	call sub_935ch		;9f7a	cd 5c 93	. \ .
	call sub_a589h		;9f7d	cd 89 a5	. . .
	sla e			;9f80	cb 23		. #
	sla d			;9f82	cb 22		. "
	xor a			;9f84	af		.
	cp e			;9f85	bb		.
	jp z,la1c1h		;9f86	ca c1 a1	. . .
	dec d			;9f89	15		.
	ld a,001h		;9f8a	3e 01		> .
	ld (l883ch),a		;9f8c	32 3c 88	2 < .
	ld a,(l882dh)		;9f8f	3a 2d 88	: - .
	ld hl,l882ch		;9f92	21 2c 88	! , .
	xor (hl)		;9f95	ae		.
	bit 7,a			;9f96	cb 7f		. .
	ld a,e			;9f98	7b		{
	jr nz,l9fc4h		;9f99	20 29		  )
	push af			;9f9b	f5		.
	ld ix,(l8821h)		;9f9c	dd 2a 21 88	. * ! .
	ld a,(l880dh)		;9fa0	3a 0d 88	: . .
	cp (ix+003h)		;9fa3	dd be 03	. . .
	jr nz,l9fabh		;9fa6	20 03		  .
	ld (l884ch),a		;9fa8	32 4c 88	2 L .
l9fabh:
	pop af			;9fab	f1		.
	ld hl,l8839h		;9fac	21 39 88	! 9 .
	cp (hl)			;9faf	be		.
	jr c,l9fd3h		;9fb0	38 21		8 !
	ld (hl),e		;9fb2	73		s
	ld ix,(l8821h)		;9fb3	dd 2a 21 88	. * ! .
	ld a,(l880dh)		;9fb7	3a 0d 88	: . .
	cp (ix+003h)		;9fba	dd be 03	. . .
	jr nz,l9fd3h		;9fbd	20 14		  .
	ld (l884bh),a		;9fbf	32 4b 88	2 K .
	jr l9fd3h		;9fc2	18 0f		. .
l9fc4h:
	ld hl,l883ah		;9fc4	21 3a 88	! : .
	cp (hl)			;9fc7	be		.
	jr c,l9fcch		;9fc8	38 02		8 .
	ld a,(hl)		;9fca	7e		~
	ld (hl),e		;9fcb	73		s
l9fcch:
	ld hl,l883bh		;9fcc	21 3b 88	! ; .
	cp (hl)			;9fcf	be		.
	jr c,l9fd3h		;9fd0	38 01		8 .
	ld (hl),a		;9fd2	77		w
l9fd3h:
	ld hl,l882dh		;9fd3	21 2d 88	! - .
	bit 7,(hl)		;9fd6	cb 7e		. ~
	ld a,d			;9fd8	7a		z
	jr z,l9fddh		;9fd9	28 02		( .
	neg			;9fdb	ed 44		. D
l9fddh:
	ld hl,l883eh		;9fdd	21 3e 88	! > .
	add a,(hl)		;9fe0	86		.
	ld (hl),a		;9fe1	77		w
l9fe2h:
	ld a,(l880dh)		;9fe2	3a 0d 88	: . .
	inc a			;9fe5	3c		<
	cp 063h			;9fe6	fe 63		. c
	jp nz,l9da7h		;9fe8	c2 a7 9d	. . .
	ld a,(l884bh)		;9feb	3a 4b 88	: K .
	and a			;9fee	a7		.
	jr z,l9ffbh		;9fef	28 0a		( .
	ld a,(l883bh)		;9ff1	3a 3b 88	: ; .
	ld (l883ah),a		;9ff4	32 3a 88	2 : .
	xor a			;9ff7	af		.
	ld (l883bh),a		;9ff8	32 3b 88	2 ; .
l9ffbh:
	ld a,(l8839h)		;9ffb	3a 39 88	: 9 .
	and a			;9ffe	a7		.
	jr z,la003h		;9fff	28 02		( .
	dec a			;a001	3d		=
	dec a			;a002	3d		=
la003h:
	ld b,a			;a003	47		G
	ld a,(l883ah)		;a004	3a 3a 88	: : .
	and a			;a007	a7		.
	jr z,$+11		;a008	28 09		( .
	ld a,(l883bh)		;a00a	3a 3b 88	: ; .
	and a			;a00d	a7		.
	jr z,la014h		;a00e	28 04		( .
	dec a			;a010	3d		=
	dec a			;a011	3d		=
	srl a			;a012	cb 3f		. ?
la014h:
	sub b			;a014	90		.
	ld hl,l882ch		;a015	21 2c 88	! , .
	bit 7,(hl)		;a018	cb 7e		. ~
	jr z,la01eh		;a01a	28 02		( .
	neg			;a01c	ed 44		. D
la01eh:
	ld hl,l883eh		;a01e	21 3e 88	! > .
	add a,(hl)		;a021	86		.
	ld hl,l8848h		;a022	21 48 88	! H .
	sub (hl)		;a025	96		.
	ld b,a			;a026	47		G
	ld a,016h		;a027	3e 16		> .
	call sub_a444h		;a029	cd 44 a4	. D .
	ld e,a			;a02c	5f		_
	ld a,(l8843h)		;a02d	3a 43 88	: C .
	ld hl,l8843h+2		;a030	21 45 88	! E .
	sub (hl)		;a033	96		.
	ld d,a			;a034	57		W
	ld a,(l8841h)		;a035	3a 41 88	: A .
	ld hl,l8842h		;a038	21 42 88	! B .
	sub (hl)		;a03b	96		.
	add a,d			;a03c	82		.
	ld d,a			;a03d	57		W
	ld a,(l883eh+1)		;a03e	3a 3f 88	: ? .
	ld hl,l8840h		;a041	21 40 88	! @ .
	sub (hl)		;a044	96		.
	add a,d			;a045	82		.
	ld d,a			;a046	57		W
	ld a,(l8843h+1)		;a047	3a 44 88	: D .
	ld hl,l8846h		;a04a	21 46 88	! F .
	sub (hl)		;a04d	96		.
	ld b,a			;a04e	47		G
	ld a,(l8831h)		;a04f	3a 31 88	: 1 .
	cp 01ch			;a052	fe 1c		. .
	ld a,b			;a054	78		x
	jr c,la05ch		;a055	38 05		8 .
	ld a,001h		;a057	3e 01		> .
	call sub_a444h		;a059	cd 44 a4	. D .
la05ch:
	add a,d			;a05c	82		.
	ld d,a			;a05d	57		W
	ld a,(l8848h+2)		;a05e	3a 4a 88	: J .
	ld hl,l8848h+1		;a061	21 49 88	! I .
	sub (hl)		;a064	96		.
	add a,d			;a065	82		.
	ld d,a			;a066	57		W
	ld a,(l8838h)		;a067	3a 38 88	: 8 .
	ld hl,l8847h		;a06a	21 47 88	! G .
	sub (hl)		;a06d	96		.
	add a,d			;a06e	82		.
	ld b,a			;a06f	47		G
	ld a,(l884bh)		;a070	3a 4b 88	: K .
	and a			;a073	a7		.
	jr nz,la07ch		;a074	20 06		  .
	ld a,(l884ch)		;a076	3a 4c 88	: L .
	and a			;a079	a7		.
	jr z,la07eh		;a07a	28 02		( .
la07ch:
	ld b,000h		;a07c	06 00		. .
la07eh:
	ld a,00eh		;a07e	3e 0e		> .
	call sub_a444h		;a080	cd 44 a4	. D .
	ld d,a			;a083	57		W
	ld a,e			;a084	7b		{
	add a,a			;a085	87		.
	add a,a			;a086	87		.
	add a,e			;a087	83		.
	add a,d			;a088	82		.
	ld l,a			;a089	6f		o
	call sub_9903h		;a08a	cd 03 99	. . .
	bit 0,a			;a08d	cb 47		. G
	jr z,la092h		;a08f	28 01		( .
	inc l			;a091	2c		,
la092h:
	ld a,l			;a092	7d		}
	ld hl,l882ch		;a093	21 2c 88	! , .
	bit 7,(hl)		;a096	cb 7e		. ~
	jr nz,la09ch		;a098	20 02		  .
	neg			;a09a	ed 44		. D
la09ch:
	add a,080h		;a09c	c6 80		. .
	ld (l8835h+1),a		;a09e	32 36 88	2 6 .
	ld ix,(l8821h)		;a0a1	dd 2a 21 88	. * ! .
	ld (ix+005h),a		;a0a5	dd 77 05	. w .
	ret			;a0a8	c9		.
la0a9h:
	nop			;a0a9	00		.
	nop			;a0aa	00		.
	nop			;a0ab	00		.
	nop			;a0ac	00		.
	nop			;a0ad	00		.
	nop			;a0ae	00		.
	nop			;a0af	00		.
	nop			;a0b0	00		.
	nop			;a0b1	00		.
	nop			;a0b2	00		.
	nop			;a0b3	00		.
	nop			;a0b4	00		.
	nop			;a0b5	00		.
	nop			;a0b6	00		.
	nop			;a0b7	00		.
	nop			;a0b8	00		.
	nop			;a0b9	00		.
	nop			;a0ba	00		.
	nop			;a0bb	00		.
	nop			;a0bc	00		.
	nop			;a0bd	00		.
	nop			;a0be	00		.
	nop			;a0bf	00		.
	nop			;a0c0	00		.
	nop			;a0c1	00		.
	nop			;a0c2	00		.
	nop			;a0c3	00		.
	nop			;a0c4	00		.
	nop			;a0c5	00		.
	nop			;a0c6	00		.
	nop			;a0c7	00		.
	nop			;a0c8	00		.
	nop			;a0c9	00		.
	ld bc,00101h		;a0ca	01 01 01	. . .
	ld bc,00000h		;a0cd	01 00 00	. . .
	nop			;a0d0	00		.
	nop			;a0d1	00		.
	nop			;a0d2	00		.
	ld bc,00201h		;a0d3	01 01 02	. . .
	ld (bc),a		;a0d6	02		.
	ld bc,00001h		;a0d7	01 01 00	. . .
	nop			;a0da	00		.
	nop			;a0db	00		.
	nop			;a0dc	00		.
	ld bc,00302h		;a0dd	01 02 03	. . .
	inc bc			;a0e0	03		.
	ld (bc),a		;a0e1	02		.
	ld bc,00000h		;a0e2	01 00 00	. . .
	nop			;a0e5	00		.
	nop			;a0e6	00		.
	ld bc,00302h		;a0e7	01 02 03	. . .
	inc bc			;a0ea	03		.
	ld (bc),a		;a0eb	02		.
	ld bc,00000h		;a0ec	01 00 00	. . .
	nop			;a0ef	00		.
	nop			;a0f0	00		.
	ld bc,00201h		;a0f1	01 01 02	. . .
	ld (bc),a		;a0f4	02		.
	ld bc,00001h		;a0f5	01 01 00	. . .
	nop			;a0f8	00		.
	nop			;a0f9	00		.
	nop			;a0fa	00		.
	nop			;a0fb	00		.
	ld bc,00101h		;a0fc	01 01 01	. . .
	ld bc,00000h		;a0ff	01 00 00	. . .
	nop			;a102	00		.
la103h:
	nop			;a103	00		.
	nop			;a104	00		.
	nop			;a105	00		.
	nop			;a106	00		.
	nop			;a107	00		.
	nop			;a108	00		.
	nop			;a109	00		.
	nop			;a10a	00		.
	nop			;a10b	00		.
	nop			;a10c	00		.
	nop			;a10d	00		.
	nop			;a10e	00		.
	nop			;a10f	00		.
	nop			;a110	00		.
	nop			;a111	00		.
	nop			;a112	00		.
	nop			;a113	00		.
	nop			;a114	00		.
	nop			;a115	00		.
	nop			;a116	00		.
	nop			;a117	00		.
	nop			;a118	00		.
	nop			;a119	00		.
	nop			;a11a	00		.
	nop			;a11b	00		.
	nop			;a11c	00		.
	nop			;a11d	00		.
	nop			;a11e	00		.
	nop			;a11f	00		.
	nop			;a120	00		.
	nop			;a121	00		.
	ei			;a122	fb		.
	ei			;a123	fb		.
	ei			;a124	fb		.
	call m,0fbfch		;a125	fc fc fb	. . .
	ei			;a128	fb		.
	ei			;a129	fb		.
	nop			;a12a	00		.
	nop			;a12b	00		.
	call m,0fdfch		;a12c	fc fc fd	. . .
	cp 0feh			;a12f	fe fe		. .
	defb 0fdh,0fch,0fch ;illegal sequence	;a131	fd fc fc	. . .
	nop			;a134	00		.
	nop			;a135	00		.
	defb 0fdh,0feh,0ffh ;illegal sequence	;a136	fd fe ff	. . .
	nop			;a139	00		.
	nop			;a13a	00		.
	rst 38h			;a13b	ff		.
	cp 0fdh			;a13c	fe fd		. .
	nop			;a13e	00		.
	nop			;a13f	00		.
	cp 0ffh			;a140	fe ff		. .
	nop			;a142	00		.
	ld bc,00001h		;a143	01 01 00	. . .
	rst 38h			;a146	ff		.
	cp 000h			;a147	fe 00		. .
	nop			;a149	00		.
	rst 38h			;a14a	ff		.
	rst 38h			;a14b	ff		.
	nop			;a14c	00		.
	ld bc,00001h		;a14d	01 01 00	. . .
	rst 38h			;a150	ff		.
	rst 38h			;a151	ff		.
	nop			;a152	00		.
	nop			;a153	00		.
	nop			;a154	00		.
	nop			;a155	00		.
	nop			;a156	00		.
	ld bc,00001h		;a157	01 01 00	. . .
	nop			;a15a	00		.
	nop			;a15b	00		.
	nop			;a15c	00		.
la15dh:
	nop			;a15d	00		.
	nop			;a15e	00		.
	nop			;a15f	00		.
	nop			;a160	00		.
	nop			;a161	00		.
	nop			;a162	00		.
	nop			;a163	00		.
	nop			;a164	00		.
	nop			;a165	00		.
	nop			;a166	00		.
	nop			;a167	00		.
	nop			;a168	00		.
	nop			;a169	00		.
	nop			;a16a	00		.
	nop			;a16b	00		.
	nop			;a16c	00		.
	nop			;a16d	00		.
	nop			;a16e	00		.
	nop			;a16f	00		.
	nop			;a170	00		.
	nop			;a171	00		.
	nop			;a172	00		.
	nop			;a173	00		.
	nop			;a174	00		.
	nop			;a175	00		.
	nop			;a176	00		.
	nop			;a177	00		.
	nop			;a178	00		.
	nop			;a179	00		.
	nop			;a17a	00		.
	nop			;a17b	00		.
	nop			;a17c	00		.
	nop			;a17d	00		.
	nop			;a17e	00		.
	rst 38h			;a17f	ff		.
	rst 38h			;a180	ff		.
	nop			;a181	00		.
	nop			;a182	00		.
	nop			;a183	00		.
	nop			;a184	00		.
	nop			;a185	00		.
	ld bc,00000h		;a186	01 00 00	. . .
	rst 38h			;a189	ff		.
	rst 38h			;a18a	ff		.
	nop			;a18b	00		.
	nop			;a18c	00		.
	ld bc,00000h		;a18d	01 00 00	. . .
	ld (bc),a		;a190	02		.
	ld bc,0ff00h		;a191	01 00 ff	. . .
	rst 38h			;a194	ff		.
	nop			;a195	00		.
	ld bc,00002h		;a196	01 02 00	. . .
	nop			;a199	00		.
	inc bc			;a19a	03		.
	ld (bc),a		;a19b	02		.
	ld bc,00000h		;a19c	01 00 00	. . .
	ld bc,00302h		;a19f	01 02 03	. . .
	nop			;a1a2	00		.
	nop			;a1a3	00		.
	inc b			;a1a4	04		.
	inc b			;a1a5	04		.
	inc bc			;a1a6	03		.
	ld (bc),a		;a1a7	02		.
	ld (bc),a		;a1a8	02		.
	inc bc			;a1a9	03		.
	inc b			;a1aa	04		.
	inc b			;a1ab	04		.
	nop			;a1ac	00		.
	nop			;a1ad	00		.
	dec b			;a1ae	05		.
	dec b			;a1af	05		.
	dec b			;a1b0	05		.
	inc b			;a1b1	04		.
	inc b			;a1b2	04		.
	dec b			;a1b3	05		.
	dec b			;a1b4	05		.
	dec b			;a1b5	05		.
	nop			;a1b6	00		.
	nop			;a1b7	00		.
	nop			;a1b8	00		.
	nop			;a1b9	00		.
	nop			;a1ba	00		.
	nop			;a1bb	00		.
	nop			;a1bc	00		.
	nop			;a1bd	00		.
	nop			;a1be	00		.
	nop			;a1bf	00		.
	nop			;a1c0	00		.
la1c1h:
	ld hl,la0a9h		;a1c1	21 a9 a0	! . .
	ld a,(l880dh)		;a1c4	3a 0d 88	: . .
	ld b,000h		;a1c7	06 00		. .
	ld c,a			;a1c9	4f		O
	add hl,bc		;a1ca	09		.
	ld a,(hl)		;a1cb	7e		~
	ld hl,l882dh		;a1cc	21 2d 88	! - .
	bit 7,(hl)		;a1cf	cb 7e		. ~
	jr z,la1d5h		;a1d1	28 02		( .
	neg			;a1d3	ed 44		. D
la1d5h:
	ld hl,l8843h+1		;a1d5	21 44 88	! D .
	add a,(hl)		;a1d8	86		.
	ld (hl),a		;a1d9	77		w
	jp l9fd3h		;a1da	c3 d3 9f	. . .
sub_a1ddh:
	push af			;a1dd	f5		.
	ld hl,la0a9h		;a1de	21 a9 a0	! . .
	ld a,(l880dh)		;a1e1	3a 0d 88	: . .
	ld b,000h		;a1e4	06 00		. .
	ld c,a			;a1e6	4f		O
	add hl,bc		;a1e7	09		.
	ld a,(hl)		;a1e8	7e		~
	cp 002h			;a1e9	fe 02		. .
	jp p,la1f8h		;a1eb	f2 f8 a1	. . .
	pop af			;a1ee	f1		.
	ld a,001h		;a1ef	3e 01		> .
	jp p,la1f9h		;a1f1	f2 f9 a1	. . .
	neg			;a1f4	ed 44		. D
	jr la1f9h		;a1f6	18 01		. .
la1f8h:
	pop af			;a1f8	f1		.
la1f9h:
	jp m,la1feh		;a1f9	fa fe a1	. . .
	add a,(hl)		;a1fc	86		.
	ret			;a1fd	c9		.
la1feh:
	sub (hl)		;a1fe	96		.
	ret			;a1ff	c9		.
; ---------------------------------------------------------------------------
; LIGHTWEIGHT EVALUATION (deeper plies)
; Faster evaluation for deeper search levels. Skips expensive
; computations like full pawn structure analysis, focusing on
; material, basic mobility, and attack table scores.
; ---------------------------------------------------------------------------
sub_a200h:
	xor a			;a200	af		.
	ld (l883eh),a		;a201	32 3e 88	2 > .
	ld (l8839h),a		;a204	32 39 88	2 9 .
	ld (l883ah),a		;a207	32 3a 88	2 : .
	ld (l883bh),a		;a20a	32 3b 88	2 ; .
	ld (l884bh),a		;a20d	32 4b 88	2 K .
	ld (l884ch),a		;a210	32 4c 88	2 L .
	ld (l883ch),a		;a213	32 3c 88	2 < .
	call sub_a344h		;a216	cd 44 a3	. D .
	ld hl,l8811h		;a219	21 11 88	! . .
	ld (hl),007h		;a21c	36 07		6 .
	ld a,015h		;a21e	3e 15		> .
la220h:
	ld (l880dh),a		;a220	32 0d 88	2 . .
	ld ix,(l880dh)		;a223	dd 2a 0d 88	. * . .
	ld a,(ix-04ch)		;a227	dd 7e b4	. ~ .
	cp 0ffh			;a22a	fe ff		. .
	jp z,la2e0h		;a22c	ca e0 a2	. . .
	and a			;a22f	a7		.
	jp z,la2e0h		;a230	ca e0 a2	. . .
	ld hl,l882dh		;a233	21 2d 88	! - .
	ld (hl),a		;a236	77		w
	and 007h		;a237	e6 07		. .
	ld (l8815h),a		;a239	32 15 88	2 . .
	ld hl,l8a70h		;a23c	21 70 8a	! p .
	ld d,000h		;a23f	16 00		. .
	ld a,(l880dh)		;a241	3a 0d 88	: . .
	ld e,a			;a244	5f		_
	add hl,de		;a245	19		.
	ld b,h			;a246	44		D
	ld c,l			;a247	4d		M
	ld hl,l8ae8h		;a248	21 e8 8a	! . .
	add hl,de		;a24b	19		.
	ld a,(l882dh)		;a24c	3a 2d 88	: - .
	bit 7,a			;a24f	cb 7f		. .
	ld a,(hl)		;a251	7e		~
	jr z,la255h		;a252	28 01		( .
	ld a,(bc)		;a254	0a		.
la255h:
	and a			;a255	a7		.
	jr nz,la26eh		;a256	20 16		  .
	ld a,(l882dh)		;a258	3a 2d 88	: - .
	and 007h		;a25b	e6 07		. .
	ld (l8815h),a		;a25d	32 15 88	2 . .
	ld ix,(l8815h)		;a260	dd 2a 15 88	. * . .
	ld d,(ix-05bh)		;a264	dd 56 a5	. V .
	sla d			;a267	cb 22		. "
	sla d			;a269	cb 22		. "
	jp la2d1h		;a26b	c3 d1 a2	. . .
la26eh:
	xor a			;a26e	af		.
	ld b,00eh		;a26f	06 0e		. .
	ld hl,l892ch		;a271	21 2c 89	! , .
la274h:
	ld (hl),a		;a274	77		w
	inc hl			;a275	23		#
	djnz la274h		;a276	10 fc		. .
	call sub_935ch		;a278	cd 5c 93	. \ .
	call sub_a589h		;a27b	cd 89 a5	. . .
	sla e			;a27e	cb 23		. #
	sla d			;a280	cb 22		. "
	xor a			;a282	af		.
	cp e			;a283	bb		.
	jp z,la2d1h		;a284	ca d1 a2	. . .
	dec d			;a287	15		.
	ld a,(l882dh)		;a288	3a 2d 88	: - .
	ld hl,l882ch		;a28b	21 2c 88	! , .
	xor (hl)		;a28e	ae		.
	bit 7,a			;a28f	cb 7f		. .
	ld a,e			;a291	7b		{
	jr nz,la2c2h		;a292	20 2e		  .
	push af			;a294	f5		.
	ld ix,(l8821h)		;a295	dd 2a 21 88	. * ! .
	ld a,(l880dh)		;a299	3a 0d 88	: . .
	cp (ix+003h)		;a29c	dd be 03	. . .
	jr nz,la2a4h		;a29f	20 03		  .
	ld (l884ch),a		;a2a1	32 4c 88	2 L .
la2a4h:
	ld a,001h		;a2a4	3e 01		> .
	ld (l883ch),a		;a2a6	32 3c 88	2 < .
	pop af			;a2a9	f1		.
	ld hl,l8839h		;a2aa	21 39 88	! 9 .
	cp (hl)			;a2ad	be		.
	jr c,la2d1h		;a2ae	38 21		8 !
	ld (hl),e		;a2b0	73		s
	ld ix,(l8821h)		;a2b1	dd 2a 21 88	. * ! .
	ld a,(l880dh)		;a2b5	3a 0d 88	: . .
	cp (ix+003h)		;a2b8	dd be 03	. . .
	jr nz,la2d1h		;a2bb	20 14		  .
	ld (l884bh),a		;a2bd	32 4b 88	2 K .
	jr la2d1h		;a2c0	18 0f		. .
la2c2h:
	ld hl,l883ah		;a2c2	21 3a 88	! : .
	cp (hl)			;a2c5	be		.
	jr c,la2cah		;a2c6	38 02		8 .
	ld a,(hl)		;a2c8	7e		~
	ld (hl),e		;a2c9	73		s
la2cah:
	ld hl,l883bh		;a2ca	21 3b 88	! ; .
	cp (hl)			;a2cd	be		.
	jr c,la2d1h		;a2ce	38 01		8 .
	ld (hl),a		;a2d0	77		w
la2d1h:
	ld hl,l882dh		;a2d1	21 2d 88	! - .
	bit 7,(hl)		;a2d4	cb 7e		. ~
	ld a,d			;a2d6	7a		z
	jr z,la2dbh		;a2d7	28 02		( .
	neg			;a2d9	ed 44		. D
la2dbh:
	ld hl,l883eh		;a2db	21 3e 88	! > .
	add a,(hl)		;a2de	86		.
	ld (hl),a		;a2df	77		w
la2e0h:
	ld a,(l880dh)		;a2e0	3a 0d 88	: . .
	inc a			;a2e3	3c		<
	cp 063h			;a2e4	fe 63		. c
	jp nz,la220h		;a2e6	c2 20 a2	.   .
	ld a,(l884bh)		;a2e9	3a 4b 88	: K .
	and a			;a2ec	a7		.
	jr z,la2f9h		;a2ed	28 0a		( .
	ld a,(l883bh)		;a2ef	3a 3b 88	: ; .
	ld (l883ah),a		;a2f2	32 3a 88	2 : .
	xor a			;a2f5	af		.
	ld (l883bh),a		;a2f6	32 3b 88	2 ; .
la2f9h:
	ld a,(l8839h)		;a2f9	3a 39 88	: 9 .
	and a			;a2fc	a7		.
	jr z,la301h		;a2fd	28 02		( .
	dec a			;a2ff	3d		=
	dec a			;a300	3d		=
la301h:
	ld b,a			;a301	47		G
	ld a,(l883ah)		;a302	3a 3a 88	: : .
	and a			;a305	a7		.
	jr z,$+11		;a306	28 09		( .
	ld a,(l883bh)		;a308	3a 3b 88	: ; .
	and a			;a30b	a7		.
	jr z,la312h		;a30c	28 04		( .
	dec a			;a30e	3d		=
	dec a			;a30f	3d		=
	srl a			;a310	cb 3f		. ?
la312h:
	sub b			;a312	90		.
	ld hl,l882ch		;a313	21 2c 88	! , .
	bit 7,(hl)		;a316	cb 7e		. ~
	jr z,la31ch		;a318	28 02		( .
	neg			;a31a	ed 44		. D
la31ch:
	ld hl,l883eh		;a31c	21 3e 88	! > .
	add a,(hl)		;a31f	86		.
	ld hl,l8848h		;a320	21 48 88	! H .
	sub (hl)		;a323	96		.
	ld b,a			;a324	47		G
	ld a,016h		;a325	3e 16		> .
	call sub_a444h		;a327	cd 44 a4	. D .
	ld b,a			;a32a	47		G
	add a,a			;a32b	87		.
	add a,a			;a32c	87		.
	add a,b			;a32d	80		.
	ld hl,l882ch		;a32e	21 2c 88	! , .
	bit 7,(hl)		;a331	cb 7e		. ~
	jr nz,la337h		;a333	20 02		  .
	neg			;a335	ed 44		. D
la337h:
	add a,080h		;a337	c6 80		. .
	ld (l8835h+1),a		;a339	32 36 88	2 6 .
	ld ix,(l8821h)		;a33c	dd 2a 21 88	. * ! .
	ld (ix+005h),a		;a340	dd 77 05	. w .
	ret			;a343	c9		.
; ---------------------------------------------------------------------------
; MOBILITY/ATTACK TABLE INIT
; Clears the 78h-byte attack tables at 8A70h (white) and
; 8AE8h (black), then iterates all pieces on the board to
; fill in attack/mobility counts for each square.
; ---------------------------------------------------------------------------
sub_a344h:
	xor a			;a344	af		.
	ld b,078h		;a345	06 78		. x
	ld hl,l8a70h		;a347	21 70 8a	! p .
	ld de,l8ae8h		;a34a	11 e8 8a	. . .
la34dh:
	ld (hl),a		;a34d	77		w
	ld (de),a		;a34e	12		.
	inc hl			;a34f	23		#
	inc de			;a350	13		.
	djnz la34dh		;a351	10 fa		. .
	ld a,015h		;a353	3e 15		> .
la355h:
	ld (l8809h),a		;a355	32 09 88	2 . .
	ld ix,(l8809h)		;a358	dd 2a 09 88	. * . .
	ld a,(ix-04ch)		;a35c	dd 7e b4	. ~ .
	and a			;a35f	a7		.
	jr z,la36ch		;a360	28 0a		( .
	cp 0ffh			;a362	fe ff		. .
	jr z,la36ch		;a364	28 06		( .
	ld (l882dh),a		;a366	32 2d 88	2 - .
	call sub_a375h		;a369	cd 75 a3	. u .
la36ch:
	ld a,(l8809h)		;a36c	3a 09 88	: . .
	inc a			;a36f	3c		<
	cp 063h			;a370	fe 63		. c
	jr nz,la355h		;a372	20 e1		  .
	ret			;a374	c9		.
; ---------------------------------------------------------------------------
; MOBILITY COUNTING FOR ONE PIECE
; Traces direction vectors for a single piece, counting
; attacks on each reachable square. Updates the attack
; tables at 8A70h/8AE8h based on piece color.
; ---------------------------------------------------------------------------
sub_a375h:
	and 087h		;a375	e6 87		. .
	cp 081h			;a377	fe 81		. .
	jr nz,la37ch		;a379	20 01		  .
	dec a			;a37b	3d		=
la37ch:
	and 007h		;a37c	e6 07		. .
	ld (l8811h),a		;a37e	32 11 88	2 . .
	ld ix,(l8811h)		;a381	dd 2a 11 88	. * . .
	ld b,(ix-061h)		;a385	dd 46 9f	. F .
	ld a,(ix-068h)		;a388	dd 7e 98	. ~ .
	ld (l8819h),a		;a38b	32 19 88	2 . .
la38eh:
	ld ix,(l8819h)		;a38e	dd 2a 19 88	. * . .
	ld c,(ix-080h)		;a392	dd 4e 80	. N .
	ld a,(l8809h)		;a395	3a 09 88	: . .
	ld (l880bh),a		;a398	32 0b 88	2 . .
la39bh:
	ld hl,l880bh		;a39b	21 0b 88	! . .
	ld a,(hl)		;a39e	7e		~
	add a,c			;a39f	81		.
	ld (hl),a		;a3a0	77		w
	ld ix,(l880bh)		;a3a1	dd 2a 0b 88	. * . .
	ld a,(ix-04ch)		;a3a5	dd 7e b4	. ~ .
	cp 0ffh			;a3a8	fe ff		. .
	jr z,la3dch		;a3aa	28 30		( 0
	ld (l882dh+1),a		;a3ac	32 2e 88	2 . .
	and 007h		;a3af	e6 07		. .
	ld (l8813h),a		;a3b1	32 13 88	2 . .
	jr z,la3c2h		;a3b4	28 0c		( .
	ld a,(l882dh+1)		;a3b6	3a 2e 88	: . .
	ld hl,l882dh		;a3b9	21 2d 88	! - .
	xor (hl)		;a3bc	ae		.
	jp p,la3f1h		;a3bd	f2 f1 a3	. . .
	ld a,001h		;a3c0	3e 01		> .
la3c2h:
	and a			;a3c2	a7		.
	ex af,af'		;a3c3	08		.
	ld a,(l8811h)		;a3c4	3a 11 88	: . .
	cp 002h			;a3c7	fe 02		. .
	jr c,la3e3h		;a3c9	38 18		8 .
	call sub_a42eh		;a3cb	cd 2e a4	. . .
	ex af,af'		;a3ce	08		.
	jr nz,la3dch		;a3cf	20 0b		  .
	ld a,(l8811h)		;a3d1	3a 11 88	: . .
	cp 006h			;a3d4	fe 06		. .
	jr z,la3dch		;a3d6	28 04		( .
	cp 003h			;a3d8	fe 03		. .
	jr nc,la39bh		;a3da	30 bf		0 .
la3dch:
	ld hl,l8819h		;a3dc	21 19 88	! . .
	inc (hl)		;a3df	34		4
	djnz la38eh		;a3e0	10 ac		. .
	ret			;a3e2	c9		.
la3e3h:
	ld a,b			;a3e3	78		x
	cp 003h			;a3e4	fe 03		. .
	jr c,la3ebh		;a3e6	38 03		8 .
	ex af,af'		;a3e8	08		.
	jr la3dch		;a3e9	18 f1		. .
la3ebh:
	ex af,af'		;a3eb	08		.
	call sub_a42eh		;a3ec	cd 2e a4	. . .
	jr la3dch		;a3ef	18 eb		. .
la3f1h:
	ld a,(l8813h)		;a3f1	3a 13 88	: . .
	cp 003h			;a3f4	fe 03		. .
	jr z,la402h		;a3f6	28 0a		( .
	cp 004h			;a3f8	fe 04		. .
	jr z,la410h		;a3fa	28 14		( .
	cp 005h			;a3fc	fe 05		. .
	jr z,la41fh		;a3fe	28 1f		( .
	jr la3dch		;a400	18 da		. .
la402h:
	ld a,(l8811h)		;a402	3a 11 88	: . .
	cp 005h			;a405	fe 05		. .
	jr nz,la3dch		;a407	20 d3		  .
	ld a,b			;a409	78		x
	cp 005h			;a40a	fe 05		. .
	jr nc,la39bh		;a40c	30 8d		0 .
	jr la3dch		;a40e	18 cc		. .
la410h:
	ld a,(l8811h)		;a410	3a 11 88	: . .
	cp 005h			;a413	fe 05		. .
	jr nz,la427h		;a415	20 10		  .
	ld a,b			;a417	78		x
	cp 005h			;a418	fe 05		. .
	jp c,la39bh		;a41a	da 9b a3	. . .
	jr la3dch		;a41d	18 bd		. .
la41fh:
	ld a,(l8811h)		;a41f	3a 11 88	: . .
	cp 003h			;a422	fe 03		. .
	jp z,la39bh		;a424	ca 9b a3	. . .
la427h:
	cp 004h			;a427	fe 04		. .
	jp z,la39bh		;a429	ca 9b a3	. . .
	jr la3dch		;a42c	18 ae		. .
; ---------------------------------------------------------------------------
; INCREMENT ATTACK COUNTER
; Increments the attack count for a square in the mobility
; table. Selects 8A70h (white) or 8AE8h (black) based on
; the piece color flag at 882Dh.
; ---------------------------------------------------------------------------
sub_a42eh:
	ld hl,l8a70h		;a42e	21 70 8a	! p .
	ld a,(l882dh)		;a431	3a 2d 88	: - .
	bit 7,a			;a434	cb 7f		. .
	jr z,la43bh		;a436	28 03		( .
	ld hl,l8ae8h		;a438	21 e8 8a	! . .
la43bh:
	ld d,000h		;a43b	16 00		. .
	ld a,(l880bh)		;a43d	3a 0b 88	: . .
	ld e,a			;a440	5f		_
	add hl,de		;a441	19		.
	inc (hl)		;a442	34		4
	ret			;a443	c9		.
; ---------------------------------------------------------------------------
; CLAMP VALUE TO RANGE
; Bounds an evaluation term to +/- B. If A is negative,
; negates and clamps; if positive, caps at B.
; ---------------------------------------------------------------------------
sub_a444h:
	bit 7,b			;a444	cb 78		. x
	jr z,la44eh		;a446	28 06		( .
	neg			;a448	ed 44		. D
	cp b			;a44a	b8		.
	ret nc			;a44b	d0		.
	ld a,b			;a44c	78		x
	ret			;a44d	c9		.
la44eh:
	cp b			;a44e	b8		.
	ret c			;a44f	d8		.
	ld a,b			;a450	78		x
	ret			;a451	c9		.
; ---------------------------------------------------------------------------
; SWITCH SIDE / DECREMENT DEPTH
; Toggles the side-to-move (XOR 80h), decrements the search
; depth counter, unwinds the move tree pointer, and calls
; UNMAKE MOVE to restore the previous position.
; ---------------------------------------------------------------------------
sub_a452h:
	ld hl,l882ch		;a452	21 2c 88	! , .
	ld a,080h		;a455	3e 80		> .
	xor (hl)		;a457	ae		.
	ld (hl),a		;a458	77		w
	bit 7,a			;a459	cb 7f		. .
	jr z,la461h		;a45b	28 04		( .
	ld hl,l8831h		;a45d	21 31 88	! 1 .
	dec (hl)		;a460	35		5
la461h:
	ld hl,(l8823h)		;a461	2a 23 88	* # .
	dec hl			;a464	2b		+
	ld (l8823h),hl		;a465	22 23 88	" # .
	ld hl,l8831h+2		;a468	21 33 88	! 3 .
	dec (hl)		;a46b	35		5
	ld hl,(l881fh)		;a46c	2a 1f 88	* . .
	dec hl			;a46f	2b		+
	ld d,(hl)		;a470	56		V
	dec hl			;a471	2b		+
	ld e,(hl)		;a472	5e		^
	ld (l8827h+2),de	;a473	ed 53 29 88	. S ) .
	dec hl			;a477	2b		+
	ld d,(hl)		;a478	56		V
	dec hl			;a479	2b		+
	ld e,(hl)		;a47a	5e		^
	ld (l881fh),hl		;a47b	22 1f 88	" . .
	ld (l8821h),de		;a47e	ed 53 21 88	. S ! .
	call sub_94e7h		;a482	cd e7 94	. . .
	xor a			;a485	af		.
	ld (l883dh),a		;a486	32 3d 88	2 = .
	ret			;a489	c9		.
; ---------------------------------------------------------------------------
; MOVE ORDERING (ASCENDING)
; Sorts the move list by evaluation score in ascending order.
; Used for the side-to-move to try best moves first.
; Traverses linked list, evaluates each move, and relinks.
; ---------------------------------------------------------------------------
sub_a48ah:
	ld bc,(l881fh)		;a48a	ed 4b 1f 88	. K . .
	ld de,00000h		;a48e	11 00 00	. . .
la491h:
	ld h,b			;a491	60		`
	ld l,c			;a492	69		i
	ld c,(hl)		;a493	4e		N
	inc hl			;a494	23		#
	ld b,(hl)		;a495	46		F
	ld (hl),d		;a496	72		r
	dec hl			;a497	2b		+
	ld (hl),e		;a498	73		s
	xor a			;a499	af		.
	cp b			;a49a	b8		.
	jr z,la4c5h		;a49b	28 28		( (
	ld (l8821h),bc		;a49d	ed 43 21 88	. C ! .
	call sub_a562h		;a4a1	cd 62 a5	. b .
	ld hl,(l881fh)		;a4a4	2a 1f 88	* . .
	ld bc,(l8821h)		;a4a7	ed 4b 21 88	. K ! .
la4abh:
	ld e,(hl)		;a4ab	5e		^
	inc hl			;a4ac	23		#
	ld d,(hl)		;a4ad	56		V
	xor a			;a4ae	af		.
	cp d			;a4af	ba		.
	jr z,la4bdh		;a4b0	28 0b		( .
	push de			;a4b2	d5		.
	pop ix			;a4b3	dd e1		. .
	ld a,(l8835h+1)		;a4b5	3a 36 88	: 6 .
	cp (ix+005h)		;a4b8	dd be 05	. . .
	jr nc,la4c2h		;a4bb	30 05		0 .
la4bdh:
	ld (hl),b		;a4bd	70		p
	dec hl			;a4be	2b		+
	ld (hl),c		;a4bf	71		q
	jr la491h		;a4c0	18 cf		. .
la4c2h:
	ex de,hl		;a4c2	eb		.
	jr la4abh		;a4c3	18 e6		. .
la4c5h:
	ld a,(l8831h+2)		;a4c5	3a 33 88	: 3 .
	cp 001h			;a4c8	fe 01		. .
	ret			;a4ca	c9		.
; ---------------------------------------------------------------------------
; MOVE ORDERING (DESCENDING)
; Sorts the move list by evaluation score in descending order.
; Used for the opponent's perspective to try worst moves first
; (from the moving side's viewpoint).
; ---------------------------------------------------------------------------
sub_a4cbh:
	ld hl,(l881fh)		;a4cb	2a 1f 88	* . .
	dec hl			;a4ce	2b		+
	dec hl			;a4cf	2b		+
	dec hl			;a4d0	2b		+
	ld d,(hl)		;a4d1	56		V
	dec hl			;a4d2	2b		+
	ld e,(hl)		;a4d3	5e		^
	push de			;a4d4	d5		.
	pop ix			;a4d5	dd e1		. .
	ld a,(ix+004h)		;a4d7	dd 7e 04	. ~ .
	and 007h		;a4da	e6 07		. .
	jr z,la4e7h		;a4dc	28 09		( .
	xor a			;a4de	af		.
	ld (l8855h),a		;a4df	32 55 88	2 U .
	ld (l8856h),a		;a4e2	32 56 88	2 V .
	jr la4fdh		;a4e5	18 16		. .
la4e7h:
	ld a,(l8831h+2)		;a4e7	3a 33 88	: 3 .
	ld b,a			;a4ea	47		G
	ld de,0001eh		;a4eb	11 1e 00	. . .
	ld hl,l8b60h		;a4ee	21 60 8b	! ` .
la4f1h:
	add hl,de		;a4f1	19		.
	djnz la4f1h		;a4f2	10 fd		. .
	ld a,(hl)		;a4f4	7e		~
	ld (l8855h),a		;a4f5	32 55 88	2 U .
	inc hl			;a4f8	23		#
	ld a,(hl)		;a4f9	7e		~
	ld (l8856h),a		;a4fa	32 56 88	2 V .
la4fdh:
	ld bc,(l881fh)		;a4fd	ed 4b 1f 88	. K . .
	ld de,00000h		;a501	11 00 00	. . .
la504h:
	ld h,b			;a504	60		`
	ld l,c			;a505	69		i
	ld c,(hl)		;a506	4e		N
	inc hl			;a507	23		#
	ld b,(hl)		;a508	46		F
	ld (hl),d		;a509	72		r
	dec hl			;a50a	2b		+
	ld (hl),e		;a50b	73		s
	xor a			;a50c	af		.
	cp b			;a50d	b8		.
	ret z			;a50e	c8		.
	ld (l8821h),bc		;a50f	ed 43 21 88	. C ! .
	ld hl,(l8821h)		;a513	2a 21 88	* ! .
	inc hl			;a516	23		#
	inc hl			;a517	23		#
	ld a,(l8855h)		;a518	3a 55 88	: U .
	cp (hl)			;a51b	be		.
	jr nz,la529h		;a51c	20 0b		  .
	inc hl			;a51e	23		#
	ld a,(l8856h)		;a51f	3a 56 88	: V .
	cp (hl)			;a522	be		.
	jr nz,la529h		;a523	20 04		  .
	ld a,00ah		;a525	3e 0a		> .
	jr la533h		;a527	18 0a		. .
la529h:
	ld hl,(l8821h)		;a529	2a 21 88	* ! .
	inc hl			;a52c	23		#
	inc hl			;a52d	23		#
	inc hl			;a52e	23		#
	inc hl			;a52f	23		#
	ld a,(hl)		;a530	7e		~
	and 007h		;a531	e6 07		. .
la533h:
	ld (l8835h+2),a		;a533	32 37 88	2 7 .
	ld ix,(l8821h)		;a536	dd 2a 21 88	. * ! .
	ld (ix+005h),a		;a53a	dd 77 05	. w .
	ld hl,(l881fh)		;a53d	2a 1f 88	* . .
	ld bc,(l8821h)		;a540	ed 4b 21 88	. K ! .
la544h:
	ld e,(hl)		;a544	5e		^
	inc hl			;a545	23		#
	ld d,(hl)		;a546	56		V
	xor a			;a547	af		.
	cp d			;a548	ba		.
	jr z,la55ah		;a549	28 0f		( .
	push de			;a54b	d5		.
	pop ix			;a54c	dd e1		. .
	push bc			;a54e	c5		.
	ld a,(ix+005h)		;a54f	dd 7e 05	. ~ .
	ld b,a			;a552	47		G
	ld a,(l8835h+2)		;a553	3a 37 88	: 7 .
	cp b			;a556	b8		.
	pop bc			;a557	c1		.
	jr c,la55fh		;a558	38 05		8 .
la55ah:
	ld (hl),b		;a55a	70		p
	dec hl			;a55b	2b		+
	ld (hl),c		;a55c	71		q
	jr la504h		;a55d	18 a5		. .
la55fh:
	ex de,hl		;a55f	eb		.
	jr la544h		;a560	18 e2		. .
sub_a562h:
	call sub_9440h		;a562	cd 40 94	. @ .
	call sub_933bh		;a565	cd 3b 93	. ; .
	and a			;a568	a7		.
	jr z,la571h		;a569	28 06		( .
	xor a			;a56b	af		.
	ld (l8835h+1),a		;a56c	32 36 88	2 6 .
	jr la585h		;a56f	18 14		. .
la571h:
	call sub_9ca1h		;a571	cd a1 9c	. . .
	call sub_9d75h		;a574	cd 75 9d	. u .
	ld a,(l8831h+2)		;a577	3a 33 88	: 3 .
	cp 001h			;a57a	fe 01		. .
	jr nz,la585h		;a57c	20 07		  .
	ld a,(l8877h)		;a57e	3a 77 88	: w .
	inc a			;a581	3c		<
	ld (l8877h),a		;a582	32 77 88	2 w .
la585h:
	call sub_94e7h		;a585	cd e7 94	. . .
	ret			;a588	c9		.
; ---------------------------------------------------------------------------
; MOBILITY BALANCE CALCULATION
; Computes attack/defense balance from the mobility tables
; at 892Ch/8933h. Weighs piece attacks and defenses, applying
; sign based on side-to-move color.
; ---------------------------------------------------------------------------
sub_a589h:
	ld a,(l882dh)		;a589	3a 2d 88	: - .
	ld hl,l892ch		;a58c	21 2c 89	! , .
	ld de,l8933h		;a58f	11 33 89	. 3 .
	bit 7,a			;a592	cb 7f		. .
	jr z,la597h		;a594	28 01		( .
	ex de,hl		;a596	eb		.
la597h:
	ld b,(hl)		;a597	46		F
	ex de,hl		;a598	eb		.
	ld c,(hl)		;a599	4e		N
	ex de,hl		;a59a	eb		.
	ld (l89adh),bc		;a59b	ed 43 ad 89	. C . .
	ld (l89abh),de		;a59f	ed 53 ab 89	. S . .
	ld (l89a9h),hl		;a5a3	22 a9 89	" . .
	ld c,000h		;a5a6	0e 00		. .
	ld e,000h		;a5a8	1e 00		. .
	ld ix,(l8815h)		;a5aa	dd 2a 15 88	. * . .
	ld d,(ix-05bh)		;a5ae	dd 56 a5	. V .
	sla d			;a5b1	cb 22		. "
	ld b,d			;a5b3	42		B
	call sub_a5dfh		;a5b4	cd df a5	. . .
	ret z			;a5b7	c8		.
la5b8h:
	ld l,a			;a5b8	6f		o
	call sub_a5dfh		;a5b9	cd df a5	. . .
	jr z,la5d0h		;a5bc	28 12		( .
	ex af,af'		;a5be	08		.
	ld a,b			;a5bf	78		x
	cp l			;a5c0	bd		.
	jr nc,la5d2h		;a5c1	30 0f		0 .
	ex af,af'		;a5c3	08		.
la5c4h:
	cp l			;a5c4	bd		.
	ret c			;a5c5	d8		.
	call sub_a5dfh		;a5c6	cd df a5	. . .
	ret z			;a5c9	c8		.
	ld l,a			;a5ca	6f		o
	call sub_a5dfh		;a5cb	cd df a5	. . .
	jr nz,la5c4h		;a5ce	20 f4		  .
la5d0h:
	ex af,af'		;a5d0	08		.
	ld a,b			;a5d1	78		x
la5d2h:
	bit 0,c			;a5d2	cb 41		. A
	jr z,la5d8h		;a5d4	28 02		( .
	neg			;a5d6	ed 44		. D
la5d8h:
	add a,e			;a5d8	83		.
	ld e,a			;a5d9	5f		_
	ex af,af'		;a5da	08		.
	ret z			;a5db	c8		.
	ld b,l			;a5dc	45		E
	jr la5b8h		;a5dd	18 d9		. .
sub_a5dfh:
	inc c			;a5df	0c		.
	push bc			;a5e0	c5		.
	push de			;a5e1	d5		.
	push hl			;a5e2	e5		.
	ld bc,(l89adh)		;a5e3	ed 4b ad 89	. K . .
	ld de,(l89abh)		;a5e7	ed 5b ab 89	. [ . .
	ld hl,(l89a9h)		;a5eb	2a a9 89	* . .
	ld a,b			;a5ee	78		x
	ld b,c			;a5ef	41		A
	ld c,a			;a5f0	4f		O
	ex de,hl		;a5f1	eb		.
	xor a			;a5f2	af		.
	cp b			;a5f3	b8		.
	jr z,la5ffh		;a5f4	28 09		( .
	dec b			;a5f6	05		.
la5f7h:
	inc hl			;a5f7	23		#
	cp (hl)			;a5f8	be		.
	jr z,la5f7h		;a5f9	28 fc		( .
	rrd			;a5fb	ed 67		. g
	add a,a			;a5fd	87		.
	dec hl			;a5fe	2b		+
la5ffh:
	ld (l89a9h),hl		;a5ff	22 a9 89	" . .
	ld (l89abh),de		;a602	ed 53 ab 89	. S . .
	ld (l89adh),bc		;a606	ed 43 ad 89	. C . .
	pop hl			;a60a	e1		.
	pop de			;a60b	d1		.
	pop bc			;a60c	c1		.
	ret			;a60d	c9		.
la60eh:
	ld hl,l88c9h		;a60e	21 c9 88	! . .
	ld b,008h		;a611	06 08		. .
la613h:
	push bc			;a613	c5		.
	ld b,008h		;a614	06 08		. .
la616h:
	ld (hl),000h		;a616	36 00		6 .
	inc hl			;a618	23		#
	djnz la616h		;a619	10 fb		. .
	inc hl			;a61b	23		#
	inc hl			;a61c	23		#
	pop bc			;a61d	c1		.
	djnz la613h		;a61e	10 f3		. .
	call sub_a951h		;a620	cd 51 a9	. Q .
; ---------------------------------------------------------------------------
; SETUP POSITION MODE
; Allows manual piece placement/removal on the board.
; Keys: 0=clear, C=clear board, 5/8/7/6=navigate,
; X=exit setup, piece letters to place pieces.
; ---------------------------------------------------------------------------
la623h:
	xor a			;a623	af		.
	ld (l884dh),a		;a624	32 4d 88	2 M .
	ld a,036h		;a627	3e 36		> 6
la629h:
	ld (l8862h),a		;a629	32 62 88	2 b .
la62ch:
	ld (l8861h),a		;a62c	32 61 88	2 a .
	call sub_aae4h		;a62f	cd e4 aa	. . .
	ld (l8809h),a		;a632	32 09 88	2 . .
	ld ix,(l8809h)		;a635	dd 2a 09 88	. * . .
	ld a,(ix-04ch)		;a639	dd 7e b4	. ~ .
	call sub_ab35h		;a63c	cd 35 ab	. 5 .
	ld de,lb173h		;a63f	11 73 b1	. s .
	ld b,01ch		;a642	06 1c		. .
	call sub_b038h		;a644	cd 38 b0	. 8 .
	call sub_af9bh		;a647	cd 9b af	. . .
	cp 030h			;a64a	fe 30		. 0
	jp z,la6afh		;a64c	ca af a6	. . .
	cp 043h			;a64f	fe 43		. C
	jp z,la60eh		;a651	ca 0e a6	. . .
	cp 035h			;a654	fe 35		. 5
	jp z,la6b3h		;a656	ca b3 a6	. . .
	cp 038h			;a659	fe 38		. 8
	jp z,la6c6h		;a65b	ca c6 a6	. . .
	cp 037h			;a65e	fe 37		. 7
	jp z,la6d9h		;a660	ca d9 a6	. . .
	cp 036h			;a663	fe 36		. 6
	jp z,la6edh		;a665	ca ed a6	. . .
	cp 058h			;a668	fe 58		. X
	jp z,la701h		;a66a	ca 01 a7	. . .
	ld bc,00006h		;a66d	01 06 00	. . .
	ld hl,lb0e1h+1		;a670	21 e2 b0	! . .
	cpir			;a673	ed b1		. .
	jr nz,la6a9h		;a675	20 32		  2
	inc c			;a677	0c		.
la678h:
	ld de,lb150h		;a678	11 50 b1	. P .
	push bc			;a67b	c5		.
	ld b,010h		;a67c	06 10		. .
	call sub_b038h		;a67e	cd 38 b0	. 8 .
	pop bc			;a681	c1		.
	call sub_af9bh		;a682	cd 9b af	. . .
	cp 057h			;a685	fe 57		. W
	jr z,la68fh		;a687	28 06		( .
	cp 042h			;a689	fe 42		. B
	jr nz,la678h		;a68b	20 eb		  .
	set 7,c			;a68d	cb f9		. .
la68fh:
	ld de,lb160h		;a68f	11 60 b1	. ` .
	push bc			;a692	c5		.
	ld b,013h		;a693	06 13		. .
	call sub_b038h		;a695	cd 38 b0	. 8 .
	pop bc			;a698	c1		.
	call sub_af9bh		;a699	cd 9b af	. . .
	cp 04eh			;a69c	fe 4e		. N
	jr z,la6a6h		;a69e	28 06		( .
	cp 059h			;a6a0	fe 59		. Y
	jr nz,la68fh		;a6a2	20 eb		  .
	set 3,c			;a6a4	cb d9		. .
la6a6h:
	ld (ix-04ch),c		;a6a6	dd 71 b4	. q .
la6a9h:
	ld a,(l8862h)		;a6a9	3a 62 88	: b .
	jp la62ch		;a6ac	c3 2c a6	. , .
la6afh:
	ld c,000h		;a6af	0e 00		. .
	jr la6a6h		;a6b1	18 f3		. .
la6b3h:
	ld a,(l882bh)		;a6b3	3a 2b 88	: + .
	and a			;a6b6	a7		.
	jr z,la6cch		;a6b7	28 13		( .
la6b9h:
	ld a,(ix-04dh)		;a6b9	dd 7e b3	. ~ .
	inc a			;a6bc	3c		<
	jr z,la6a9h		;a6bd	28 ea		( .
	ld a,(l8862h)		;a6bf	3a 62 88	: b .
	dec a			;a6c2	3d		=
	jp la629h		;a6c3	c3 29 a6	. ) .
la6c6h:
	ld a,(l882bh)		;a6c6	3a 2b 88	: + .
	and a			;a6c9	a7		.
	jr z,la6b9h		;a6ca	28 ed		( .
la6cch:
	ld a,(ix-04bh)		;a6cc	dd 7e b5	. ~ .
	inc a			;a6cf	3c		<
	jr z,la6a9h		;a6d0	28 d7		( .
	ld a,(l8862h)		;a6d2	3a 62 88	: b .
	inc a			;a6d5	3c		<
	jp la629h		;a6d6	c3 29 a6	. ) .
la6d9h:
	ld a,(l882bh)		;a6d9	3a 2b 88	: + .
	and a			;a6dc	a7		.
	jr z,la6f3h		;a6dd	28 14		( .
la6dfh:
	ld a,(ix-042h)		;a6df	dd 7e be	. ~ .
	inc a			;a6e2	3c		<
	jr z,la6a9h		;a6e3	28 c4		( .
	ld a,(l8862h)		;a6e5	3a 62 88	: b .
	add a,00ah		;a6e8	c6 0a		. .
	jp la629h		;a6ea	c3 29 a6	. ) .
la6edh:
	ld a,(l882bh)		;a6ed	3a 2b 88	: + .
	and a			;a6f0	a7		.
	jr z,la6dfh		;a6f1	28 ec		( .
la6f3h:
	ld a,(ix-056h)		;a6f3	dd 7e aa	. ~ .
	inc a			;a6f6	3c		<
	jr z,la6a9h		;a6f7	28 b0		( .
	ld a,(l8862h)		;a6f9	3a 62 88	: b .
	sub 00ah		;a6fc	d6 0a		. .
	jp la629h		;a6fe	c3 29 a6	. ) .
la701h:
	call sub_a80bh		;a701	cd 0b a8	. . .
	call sub_8f06h		;a704	cd 06 8f	. . .
	call sub_a951h		;a707	cd 51 a9	. Q .
la70ah:
	ld de,0b136h		;a70a	11 36 b1	. 6 .
	ld b,019h		;a70d	06 19		. .
	call sub_b038h		;a70f	cd 38 b0	. 8 .
	call sub_af9bh		;a712	cd 9b af	. . .
	cp 057h			;a715	fe 57		. W
	jp z,l8ea6h		;a717	ca a6 8e	. . .
	cp 042h			;a71a	fe 42		. B
	jr nz,la70ah		;a71c	20 ec		  .
	ld a,(l882bh)		;a71e	3a 2b 88	: + .
	and a			;a721	a7		.
	jp nz,l8ebdh		;a722	c2 bd 8e	. . .
	jp l8eb2h		;a725	c3 b2 8e	. . .
; ---------------------------------------------------------------------------
; CONFIGURE MODE
; Allows changing board/surround colors and display options.
; B=board colors, S=surround colors. Prompts for ink/paper
; values and applies them to the attribute memory.
; ---------------------------------------------------------------------------
la728h:
	ld de,0b190h		;a728	11 90 b1	. . .
	ld b,01ah		;a72b	06 1a		. .
	call sub_b038h		;a72d	cd 38 b0	. 8 .
	call sub_af9bh		;a730	cd 9b af	. . .
	cp 042h			;a733	fe 42		. B
	jr z,la759h		;a735	28 22		( "
	cp 053h			;a737	fe 53		. S
	jr nz,la728h		;a739	20 ed		  .
	ld de,0b1aah		;a73b	11 aa b1	. . .
	ld b,012h		;a73e	06 12		. .
	call sub_a78eh		;a740	cd 8e a7	. . .
	ld hl,l899dh		;a743	21 9d 89	! . .
	call sub_a7a7h		;a746	cd a7 a7	. . .
	ld de,0b1bch		;a749	11 bc b1	. . .
	ld b,010h		;a74c	06 10		. .
	call sub_a78eh		;a74e	cd 8e a7	. . .
	call sub_a7b7h		;a751	cd b7 a7	. . .
	res 6,(hl)		;a754	cb b6		. .
	jp la788h		;a756	c3 88 a7	. . .
la759h:
	ld de,0b25ah		;a759	11 5a b2	. Z .
	ld b,01fh		;a75c	06 1f		. .
	call sub_a79ah		;a75e	cd 9a a7	. . .
	ld hl,l89a3h		;a761	21 a3 89	! . .
	cp 042h			;a764	fe 42		. B
	jp z,la7deh		;a766	ca de a7	. . .
	cp 04fh			;a769	fe 4f		. O
	jr nz,la759h		;a76b	20 ec		  .
	ld (hl),000h		;a76d	36 00		6 .
	ld de,0b1cch		;a76f	11 cc b1	. . .
	ld b,016h		;a772	06 16		. .
	call sub_a7c2h		;a774	cd c2 a7	. . .
	ld hl,l899eh		;a777	21 9e 89	! . .
	call sub_a7a7h		;a77a	cd a7 a7	. . .
	ld de,0b1e2h		;a77d	11 e2 b1	. . .
	ld b,016h		;a780	06 16		. .
	call sub_a7d2h		;a782	cd d2 a7	. . .
	call sub_a7b7h		;a785	cd b7 a7	. . .
la788h:
	call sub_a951h		;a788	cd 51 a9	. Q .
	jp l8e79h		;a78b	c3 79 8e	. y .
; ---------------------------------------------------------------------------
; GET BOARD POSITION INPUT FOR SETUP
; Reads a digit key (0-7) for setup mode position entry.
; Validates range and returns the numeric value in A.
; ---------------------------------------------------------------------------
sub_a78eh:
	call sub_a79ah		;a78e	cd 9a a7	. . .
	sub 030h		;a791	d6 30		. 0
	jr c,sub_a78eh		;a793	38 f9		8 .
	cp 008h			;a795	fe 08		. .
	jr nc,sub_a78eh		;a797	30 f5		0 .
	ret			;a799	c9		.
sub_a79ah:
	push hl			;a79a	e5		.
	push de			;a79b	d5		.
	push bc			;a79c	c5		.
	call sub_b038h		;a79d	cd 38 b0	. 8 .
	call sub_af9bh		;a7a0	cd 9b af	. . .
	pop bc			;a7a3	c1		.
	pop de			;a7a4	d1		.
	pop hl			;a7a5	e1		.
	ret			;a7a6	c9		.
; ---------------------------------------------------------------------------
; SET ATTRIBUTE INK COLOR
; Writes the ink (foreground) color into an attribute byte.
; Shifts the color value into bits 3-5 and merges with the
; existing paper/bright bits.
; ---------------------------------------------------------------------------
sub_a7a7h:
	push af			;a7a7	f5		.
	rlca			;a7a8	07		.
	rlca			;a7a9	07		.
	rlca			;a7aa	07		.
	and 038h		;a7ab	e6 38		. 8
	ld b,a			;a7ad	47		G
	ld a,(hl)		;a7ae	7e		~
	and 0c7h		;a7af	e6 c7		. .
la7b1h:
	or b			;a7b1	b0		.
	set 6,a			;a7b2	cb f7		. .
	ld (hl),a		;a7b4	77		w
	pop af			;a7b5	f1		.
	ret			;a7b6	c9		.
; ---------------------------------------------------------------------------
; SET ATTRIBUTE PAPER COLOR
; Writes the paper (background) color into an attribute byte.
; Masks the lower 3 bits and merges with existing ink/bright.
; ---------------------------------------------------------------------------
sub_a7b7h:
	push af			;a7b7	f5		.
	and 007h		;a7b8	e6 07		. .
	ld b,a			;a7ba	47		G
	ld a,(hl)		;a7bb	7e		~
	and 0f8h		;a7bc	e6 f8		. .
	jr la7b1h		;a7be	18 f1		. .
sub_a7c0h:
	ld b,019h		;a7c0	06 19		. .
sub_a7c2h:
	call sub_a79ah		;a7c2	cd 9a a7	. . .
	sub 034h		;a7c5	d6 34		. 4
	jr c,sub_a7c2h		;a7c7	38 f9		8 .
	cp 004h			;a7c9	fe 04		. .
	jr nc,sub_a7c2h		;a7cb	30 f5		0 .
	add a,004h		;a7cd	c6 04		. .
	ret			;a7cf	c9		.
sub_a7d0h:
	ld b,019h		;a7d0	06 19		. .
sub_a7d2h:
	call sub_a79ah		;a7d2	cd 9a a7	. . .
	sub 030h		;a7d5	d6 30		. 0
	jr c,sub_a7d2h		;a7d7	38 f9		8 .
	cp 004h			;a7d9	fe 04		. .
	jr nc,sub_a7d2h		;a7db	30 f5		0 .
	ret			;a7dd	c9		.
la7deh:
	ld (hl),001h		;a7de	36 01		6 .
	ld de,0b1f8h		;a7e0	11 f8 b1	. . .
	call sub_a7c0h		;a7e3	cd c0 a7	. . .
	ld (l899fh),a		;a7e6	32 9f 89	2 . .
	ld de,lb210h+1		;a7e9	11 11 b2	. . .
	call sub_a7d0h		;a7ec	cd d0 a7	. . .
	ld (l89a0h),a		;a7ef	32 a0 89	2 . .
	ld de,0b22ah		;a7f2	11 2a b2	. * .
	ld b,018h		;a7f5	06 18		. .
	call sub_a7c2h		;a7f7	cd c2 a7	. . .
	ld (l89a1h),a		;a7fa	32 a1 89	2 . .
	ld de,0b242h		;a7fd	11 42 b2	. B .
	ld b,018h		;a800	06 18		. .
	call sub_a7d2h		;a802	cd d2 a7	. . .
	ld (l89a2h),a		;a805	32 a2 89	2 . .
	jp la788h		;a808	c3 88 a7	. . .
; ---------------------------------------------------------------------------
; REBUILD KING/ROOK POSITION TABLE
; Scans the entire board to find kings and rooks, storing
; their positions in the table at 894Eh. Needed after
; manual setup mode to ensure castling logic works correctly.
; ---------------------------------------------------------------------------
sub_a80bh:
	ld hl,l894eh		;a80b	21 4e 89	! N .
	ld b,004h		;a80e	06 04		. .
la810h:
	ld (hl),000h		;a810	36 00		6 .
	inc hl			;a812	23		#
	djnz la810h		;a813	10 fb		. .
	ld a,015h		;a815	3e 15		> .
la817h:
	ld (l8809h),a		;a817	32 09 88	2 . .
	ld hl,l894eh		;a81a	21 4e 89	! N .
	ld ix,(l8809h)		;a81d	dd 2a 09 88	. * . .
	ld a,(ix-04ch)		;a821	dd 7e b4	. ~ .
	bit 7,a			;a824	cb 7f		. .
	jr z,la829h		;a826	28 01		( .
	inc hl			;a828	23		#
la829h:
	and 007h		;a829	e6 07		. .
	cp 006h			;a82b	fe 06		. .
	jr z,la835h		;a82d	28 06		( .
	cp 005h			;a82f	fe 05		. .
	jr nz,la839h		;a831	20 06		  .
	inc hl			;a833	23		#
	inc hl			;a834	23		#
la835h:
	ld a,(l8809h)		;a835	3a 09 88	: . .
	ld (hl),a		;a838	77		w
la839h:
	ld a,(l8809h)		;a839	3a 09 88	: . .
	inc a			;a83c	3c		<
	cp 063h			;a83d	fe 63		. c
	jr nz,la817h		;a83f	20 d6		  .
	call sub_8f6fh		;a841	cd 6f 8f	. o .
	ret			;a844	c9		.
; ---------------------------------------------------------------------------
; SCROLL TEXT DISPLAY UP
; Shifts the move history display buffer at 8D40h up by one
; line (0Bh bytes per line, 0Dh lines). Clears the bottom
; line with spaces for new text entry.
; ---------------------------------------------------------------------------
sub_a845h:
	ld de,l8d40h		;a845	11 40 8d	. @ .
	ld hl,08d4bh		;a848	21 4b 8d	! K .
	ld b,00dh		;a84b	06 0d		. .
la84dh:
	push bc			;a84d	c5		.
	ld bc,0000bh		;a84e	01 0b 00	. . .
	ldir			;a851	ed b0		. .
	pop bc			;a853	c1		.
	djnz la84dh		;a854	10 f7		. .
	ld hl,l8dceh+1		;a856	21 cf 8d	! . .
	ld b,00bh		;a859	06 0b		. .
la85bh:
	ld (hl),020h		;a85b	36 20		6  
	inc hl			;a85d	23		#
	djnz la85bh		;a85e	10 fb		. .
	ret			;a860	c9		.
	ld bc,00002h		;a861	01 02 00	. . .
	jr la873h		;a864	18 0d		. .
	ld bc,00102h		;a866	01 02 01	. . .
	jr la873h		;a869	18 08		. .
	ld bc,00001h		;a86b	01 01 00	. . .
	jr la873h		;a86e	18 03		. .
; ---------------------------------------------------------------------------
; SPRITE RENDERING ENGINE
; Draws 8x8 pixel sprites to screen memory. Reads sprite
; data from a bitmap table, calculates the Spectrum screen
; address, and writes pixel rows with optional inversion.
; ---------------------------------------------------------------------------
sub_a870h:
	ld bc,00100h		;a870	01 00 01	. . .
la873h:
	ld (la910h),bc		;a873	ed 43 10 a9	. C . .
	ld a,(hl)		;a877	7e		~
	ld (la90eh+1),a		;a878	32 0f a9	2 . .
	inc hl			;a87b	23		#
	ld a,(hl)		;a87c	7e		~
	ld c,a			;a87d	4f		O
	inc hl			;a87e	23		#
	ld (la90bh),hl		;a87f	22 0b a9	" . .
	ld a,d			;a882	7a		z
	ld (la90eh),a		;a883	32 0e a9	2 . .
	ld a,007h		;a886	3e 07		> .
	ld (la90dh),a		;a888	32 0d a9	2 . .
la88bh:
	ld a,(la90eh+1)		;a88b	3a 0f a9	: . .
	ld b,a			;a88e	47		G
	ld a,(la90eh)		;a88f	3a 0e a9	: . .
	ld d,a			;a892	57		W
la893h:
	push hl			;a893	e5		.
	ld hl,(la90bh)		;a894	2a 0b a9	* . .
	ld a,(la90dh)		;a897	3a 0d a9	: . .
	rlca			;a89a	07		.
	rlca			;a89b	07		.
	rlca			;a89c	07		.
	or 046h			;a89d	f6 46		. F
	ld (0a8a3h),a		;a89f	32 a3 a8	2 . .
	bit 0,(hl)		;a8a2	cb 46		. F
	pop hl			;a8a4	e1		.
	ld a,(la910h)		;a8a5	3a 10 a9	: . .
	jr z,la8adh		;a8a8	28 03		( .
	ld a,(la911h)		;a8aa	3a 11 a9	: . .
la8adh:
	and a			;a8ad	a7		.
	jr z,la8f5h		;a8ae	28 45		( E
	dec a			;a8b0	3d		=
	jr nz,la8bdh		;a8b1	20 0a		  .
	call sub_a8cfh		;a8b3	cd cf a8	. . .
	or 0c0h			;a8b6	f6 c0		. .
la8b8h:
	ld (0a8bch),a		;a8b8	32 bc a8	2 . .
	res 2,(hl)		;a8bb	cb 96		. .
la8bdh:
	ld a,(la90dh)		;a8bd	3a 0d a9	: . .
	dec a			;a8c0	3d		=
	ld (la90dh),a		;a8c1	32 0d a9	2 . .
	call m,sub_a8fch	;a8c4	fc fc a8	. . .
	inc d			;a8c7	14		.
	djnz la893h		;a8c8	10 c9		. .
	inc e			;a8ca	1c		.
	dec c			;a8cb	0d		.
	jr nz,la88bh		;a8cc	20 bd		  .
	ret			;a8ce	c9		.
sub_a8cfh:
	ld a,e			;a8cf	7b		{
	and 0c0h		;a8d0	e6 c0		. .
	rrca			;a8d2	0f		.
	rrca			;a8d3	0f		.
	rrca			;a8d4	0f		.
	or 040h			;a8d5	f6 40		. @
	ld h,a			;a8d7	67		g
	ld a,e			;a8d8	7b		{
	and 007h		;a8d9	e6 07		. .
	or h			;a8db	b4		.
	ld h,a			;a8dc	67		g
	ld a,e			;a8dd	7b		{
	and 038h		;a8de	e6 38		. 8
	rlca			;a8e0	07		.
	rlca			;a8e1	07		.
	ld l,a			;a8e2	6f		o
	ld a,d			;a8e3	7a		z
	and 0f8h		;a8e4	e6 f8		. .
	rrca			;a8e6	0f		.
	rrca			;a8e7	0f		.
	rrca			;a8e8	0f		.
	or l			;a8e9	b5		.
	ld l,a			;a8ea	6f		o
	ld a,d			;a8eb	7a		z
	cpl			;a8ec	2f		/
	and 007h		;a8ed	e6 07		. .
	rlca			;a8ef	07		.
	rlca			;a8f0	07		.
	rlca			;a8f1	07		.
	or 006h			;a8f2	f6 06		. .
	ret			;a8f4	c9		.
la8f5h:
	call sub_a8cfh		;a8f5	cd cf a8	. . .
	or 080h			;a8f8	f6 80		. .
	jr la8b8h		;a8fa	18 bc		. .
sub_a8fch:
	ld a,007h		;a8fc	3e 07		> .
	ld (la90dh),a		;a8fe	32 0d a9	2 . .
	push hl			;a901	e5		.
	ld hl,(la90bh)		;a902	2a 0b a9	* . .
	inc hl			;a905	23		#
	ld (la90bh),hl		;a906	22 0b a9	" . .
	pop hl			;a909	e1		.
	ret			;a90a	c9		.
la90bh:
	sbc a,l			;a90b	9d		.
	adc a,c			;a90c	89		.
la90dh:
	rlca			;a90d	07		.
la90eh:
	or 008h			;a90e	f6 08		. .
la910h:
	nop			;a910	00		.
la911h:
	ld bc,04821h		;a911	01 21 48	. ! H
	ld e,h			;a914	5c		\
	ld a,(l899dh)		;a915	3a 9d 89	: . .
	ld (hl),a		;a918	77		w
	rrca			;a919	0f		.
	rrca			;a91a	0f		.
	rrca			;a91b	0f		.
	and 007h		;a91c	e6 07		. .
	or 0e8h			;a91e	f6 e8		. .
	out (0feh),a		;a920	d3 fe		. .
	ld hl,05800h		;a922	21 00 58	! . X	; Start of attribute memory
la925h:
	ld a,(l899dh)		;a925	3a 9d 89	: . .	; Load surround color attribute
	ld (hl),a		;a928	77		w	; Set attribute for this cell
	inc hl			;a929	23		#
	ld a,h			;a92a	7c		|
	cp 05bh			;a92b	fe 5b		. [
	jr nz,la925h		;a92d	20 f6		  .
	ld hl,05800h		;a92f	21 00 58	! . X
	ld b,005h		;a932	06 05		. .
la934h:
	ld (hl),078h		;a934	36 78		6 x
	inc hl			;a936	23		#
	djnz la934h		;a937	10 fb		. .
	inc hl			;a939	23		#
	ld b,005h		;a93a	06 05		. .
la93ch:
	ld (hl),047h		;a93c	36 47		6 G
	inc hl			;a93e	23		#
	djnz la93ch		;a93f	10 fb		. .
	inc hl			;a941	23		#
	ld b,00ah		;a942	06 0a		. .
la944h:
	ld (hl),078h		;a944	36 78		6 x
	inc hl			;a946	23		#
	djnz la944h		;a947	10 fb		. .
	ld b,00ah		;a949	06 0a		. .
la94bh:
	ld (hl),047h		;a94b	36 47		6 G
	inc hl			;a94d	23		#
	djnz la94bh		;a94e	10 fb		. .
	ret			;a950	c9		.
; ---------------------------------------------------------------------------
; REFRESH BOARD DISPLAY (entry 1)
; Saves registers, jumps to the common board draw code that
; redraws rank/file labels, piece sprites, and status display.
; ---------------------------------------------------------------------------
sub_a951h:
	push bc			;a951	c5		.
	push de			;a952	d5		.
	push hl			;a953	e5		.
	push af			;a954	f5		.
	jp la9eah		;a955	c3 ea a9	. . .	; Skip to common draw code
; ---------------------------------------------------------------------------
; REFRESH BOARD DISPLAY (entry 2)
; Full screen initialization: clears display, sets up IM2
; interrupt vectors at CC00h, draws board frame, labels,
; all pieces, clock, and status text.
; ---------------------------------------------------------------------------
la958h:
	push bc			;a958	c5		.
	push de			;a959	d5		.
	push hl			;a95a	e5		.
	push af			;a95b	f5		.
	ld hl,0cc00h		;a95c	21 00 cc	! . .	; IM2 vector table at CC00h
	ld b,000h		;a95f	06 00		. .	; 256 entries
la961h:
	ld (hl),0cdh		;a961	36 cd		6 .	; All vectors point to CDCDh
	inc hl			;a963	23		#
	djnz la961h		;a964	10 fb		. .
	ld (hl),0cdh		;a966	36 cd		6 .
	ld a,0c3h		;a968	3e c3		> .
	ld (0cdcdh),a		;a96a	32 cd cd	2 . .
	ld hl,lae50h		;a96d	21 50 ae	! P .
	ld (0cdceh),hl		;a970	22 ce cd	" . .
	ld a,0cch		;a973	3e cc		> .	; I register = CCh (vector table page)
	ld i,a			;a975	ed 47		. G	; Set IM2 interrupt vector base
	ld hl,04000h		;a977	21 00 40	! . @	; Start of screen memory
la97ah:
	ld (hl),000h		;a97a	36 00		6 .	; Clear pixel data
	inc hl			;a97c	23		#
	ld a,h			;a97d	7c		|
	cp 058h			;a97e	fe 58		. X	; Reached attribute area (5800h)?
	jr nz,la97ah		;a980	20 f8		  .	; No -> keep clearing
	ld de,0b0f4h		;a982	11 f4 b0	. . .
	ld hl,06800h		;a985	21 00 68	! . h
	ld b,008h		;a988	06 08		. .
	call sub_b03bh		;a98a	cd 3b b0	. ; .
	ld de,0b0f4h		;a98d	11 f4 b0	. . .
	ld hl,0b800h		;a990	21 00 b8	! . .
	ld b,008h		;a993	06 08		. .
	call sub_b03bh		;a995	cd 3b b0	. ; .
	ld hl,06818h		;a998	21 18 68	! . h
	ld a,004h		;a99b	3e 04		> .
	call sub_afaeh		;a99d	cd ae af	. . .
	ld b,010h		;a9a0	06 10		. .
la9a2h:
	ld a,005h		;a9a2	3e 05		> .
	call sub_afb7h		;a9a4	cd b7 af	. . .
	djnz la9a2h		;a9a7	10 f9		. .
	ld a,006h		;a9a9	3e 06		> .
	call sub_afb7h		;a9ab	cd b7 af	. . .
	ld hl,068a0h		;a9ae	21 a0 68	! . h
	ld a,007h		;a9b1	3e 07		> .
	call sub_afaeh		;a9b3	cd ae af	. . .
	ld b,010h		;a9b6	06 10		. .
la9b8h:
	ld a,008h		;a9b8	3e 08		> .
	call sub_afb7h		;a9ba	cd b7 af	. . .
	djnz la9b8h		;a9bd	10 f9		. .
	ld a,009h		;a9bf	3e 09		> .
	call sub_afb7h		;a9c1	cd b7 af	. . .
	ld hl,06820h		;a9c4	21 20 68	!   h
	ld a,00ah		;a9c7	3e 0a		> .
	call sub_aab8h		;a9c9	cd b8 aa	. . .
	ld hl,0f020h		;a9cc	21 20 f0	!   .
	ld a,00bh		;a9cf	3e 0b		> .
	call sub_aab8h		;a9d1	cd b8 aa	. . .
	ld de,0b2ach		;a9d4	11 ac b2	. . .
	ld hl,01088h		;a9d7	21 88 10	! . .
	ld b,005h		;a9da	06 05		. .
	call sub_b03bh		;a9dc	cd 3b b0	. ; .
	ld de,lb2b1h		;a9df	11 b1 b2	. . .
	ld hl,01098h		;a9e2	21 98 10	! . .
	ld b,004h		;a9e5	06 04		. .
	call sub_b03bh		;a9e7	cd 3b b0	. ; .
la9eah:
	ld a,(laeebh)		;a9ea	3a eb ae	: . .
	push af			;a9ed	f5		.
	ld a,001h		;a9ee	3e 01		> .
	ld (laeebh),a		;a9f0	32 eb ae	2 . .
	call sub_ae8dh		;a9f3	cd 8d ae	. . .
	ld a,002h		;a9f6	3e 02		> .
	ld (laeebh),a		;a9f8	32 eb ae	2 . .
	call sub_ae8dh		;a9fb	cd 8d ae	. . .
	pop af			;a9fe	f1		.
	ld (laeebh),a		;a9ff	32 eb ae	2 . .
	call la911h+1		;aa02	cd 12 a9	. . .
	ld hl,07412h		;aa05	21 12 74	! . t
	ld c,001h		;aa08	0e 01		. .
	ld a,(l882bh)		;aa0a	3a 2b 88	: + .
	and a			;aa0d	a7		.
	ld a,041h		;aa0e	3e 41		> A
	jr nz,laa16h		;aa10	20 04		  .
	ld c,0ffh		;aa12	0e ff		. .
	ld a,048h		;aa14	3e 48		> H
laa16h:
	push bc			;aa16	c5		.
	push af			;aa17	f5		.
	call sub_aac6h		;aa18	cd c6 aa	. . .
	pop af			;aa1b	f1		.
	pop bc			;aa1c	c1		.
	ld hl,074a6h		;aa1d	21 a6 74	! . t
	call sub_aac6h		;aa20	cd c6 aa	. . .
	ld hl,06224h		;aa23	21 24 62	! $ b
	ld c,0ffh		;aa26	0e ff		. .
	ld a,(l882bh)		;aa28	3a 2b 88	: + .
	and a			;aa2b	a7		.
	ld a,038h		;aa2c	3e 38		> 8
	jr nz,laa34h		;aa2e	20 04		  .
	ld c,001h		;aa30	0e 01		. .
	ld a,031h		;aa32	3e 31		> 1
laa34h:
	push bc			;aa34	c5		.
	push af			;aa35	f5		.
	call sub_aad5h		;aa36	cd d5 aa	. . .
	ld hl,0f624h		;aa39	21 24 f6	! $ .
	pop af			;aa3c	f1		.
	pop bc			;aa3d	c1		.
	call sub_aad5h		;aa3e	cd d5 aa	. . .
	ld de,lb0e8h		;aa41	11 e8 b0	. . .
	ld hl,000a8h		;aa44	21 a8 00	! . .
	ld b,00ch		;aa47	06 0c		. .
	call sub_b03bh		;aa49	cd 3b b0	. ; .
	ld a,015h		;aa4c	3e 15		> .
laa4eh:
	ld (l8861h),a		;aa4e	32 61 88	2 a .
	call sub_aae4h		;aa51	cd e4 aa	. . .
	call sub_ab49h		;aa54	cd 49 ab	. I .
	inc a			;aa57	3c		<
	cp 063h			;aa58	fe 63		. c
	jr c,laa4eh		;aa5a	38 f2		8 .
	ld hl,00000h		;aa5c	21 00 00	! . .
	ld de,lb0c1h		;aa5f	11 c1 b0	. . .
	ld a,(l882bh)		;aa62	3a 2b 88	: + .
	and a			;aa65	a7		.
	push af			;aa66	f5		.
	jr nz,laa6ch		;aa67	20 03		  .
	ld de,lb0bch		;aa69	11 bc b0	. . .
laa6ch:
	ld b,005h		;aa6c	06 05		. .
	call sub_b03bh		;aa6e	cd 3b b0	. ; .
	ld hl,03000h		;aa71	21 00 30	! . 0
	ld de,lb0bch		;aa74	11 bc b0	. . .
	pop af			;aa77	f1		.
	jr nz,laa7dh		;aa78	20 03		  .
	ld de,lb0c1h		;aa7a	11 c1 b0	. . .
laa7dh:
	ld b,005h		;aa7d	06 05		. .
	call sub_b03bh		;aa7f	cd 3b b0	. ; .
laa82h:
	ld a,(l8874h)		;aa82	3a 74 88	: t .
	ld hl,04088h		;aa85	21 88 40	! . @
	call sub_afaeh		;aa88	cd ae af	. . .
	ld de,0b0c6h		;aa8b	11 c6 b0	. . .
	ld hl,03898h		;aa8e	21 98 38	! . 8
	ld b,003h		;aa91	06 03		. .
	call sub_b03bh		;aa93	cd 3b b0	. ; .
	ld hl,00010h		;aa96	21 10 00	! . .
	ld de,l8d40h		;aa99	11 40 8d	. @ .
	ld b,00eh		;aa9c	06 0e		. .
laa9eh:
	push bc			;aa9e	c5		.
	push hl			;aa9f	e5		.
	ld b,00bh		;aaa0	06 0b		. .
	call sub_b03bh		;aaa2	cd 3b b0	. ; .
	pop hl			;aaa5	e1		.
	pop bc			;aaa6	c1		.
	ld a,l			;aaa7	7d		}
	add a,008h		;aaa8	c6 08		. .
	ld l,a			;aaaa	6f		o
	djnz laa9eh		;aaab	10 f1		. .
	pop af			;aaad	f1		.
	pop hl			;aaae	e1		.
	pop de			;aaaf	d1		.
	pop bc			;aab0	c1		.
	ret			;aab1	c9		.
; ---------------------------------------------------------------------------
; DRAW ALL SQUARES
; Quick refresh: saves registers, then jumps to the code
; that redraws the level indicator, clock, move history,
; and all 64 board squares with their pieces.
; ---------------------------------------------------------------------------
sub_aab2h:
	push bc			;aab2	c5		.
	push de			;aab3	d5		.
	push hl			;aab4	e5		.
	push af			;aab5	f5		.
	jr laa82h		;aab6	18 ca		. .
sub_aab8h:
	ld b,010h		;aab8	06 10		. .
laabah:
	push af			;aaba	f5		.
	call sub_afaeh		;aabb	cd ae af	. . .
	ld a,l			;aabe	7d		}
	add a,008h		;aabf	c6 08		. .
	ld l,a			;aac1	6f		o
	pop af			;aac2	f1		.
	djnz laabah		;aac3	10 f5		. .
	ret			;aac5	c9		.
sub_aac6h:
	ld b,008h		;aac6	06 08		. .
laac8h:
	push af			;aac8	f5		.
	call sub_b003h		;aac9	cd 03 b0	. . .
	ld a,010h		;aacc	3e 10		> .
	add a,h			;aace	84		.
	ld h,a			;aacf	67		g
	pop af			;aad0	f1		.
	add a,c			;aad1	81		.
	djnz laac8h		;aad2	10 f4		. .
	ret			;aad4	c9		.
sub_aad5h:
	ld b,008h		;aad5	06 08		. .
laad7h:
	push af			;aad7	f5		.
	call sub_b003h		;aad8	cd 03 b0	. . .
	ld a,010h		;aadb	3e 10		> .
	add a,l			;aadd	85		.
	ld l,a			;aade	6f		o
	pop af			;aadf	f1		.
	add a,c			;aae0	81		.
	djnz laad7h		;aae1	10 f4		. .
	ret			;aae3	c9		.
; ---------------------------------------------------------------------------
; CALCULATE SCREEN POSITION FROM BOARD SQUARE INDEX
; Converts a 10x12 mailbox square index to the pixel
; coordinates (H=row, L=col) for the screen display.
; Accounts for board orientation (white/black at bottom).
; ---------------------------------------------------------------------------
sub_aae4h:
	push bc			;aae4	c5		.
	push de			;aae5	d5		.
	push af			;aae6	f5		.
	ld a,(l8861h)		;aae7	3a 61 88	: a .
	ld d,a			;aaea	57		W
	sub a			;aaeb	97		.
	ld e,00ah		;aaec	1e 0a		. .
	call sub_9267h		;aaee	cd 67 92	. g .
	dec d			;aaf1	15		.
	dec d			;aaf2	15		.
	dec a			;aaf3	3d		=
	ld c,d			;aaf4	4a		J
	ld e,a			;aaf5	5f		_
	ld a,(l882bh)		;aaf6	3a 2b 88	: + .
	and a			;aaf9	a7		.
	jr nz,lab00h		;aafa	20 04		  .
	ld a,007h		;aafc	3e 07		> .
	sub e			;aafe	93		.
	ld e,a			;aaff	5f		_
lab00h:
	ld d,010h		;ab00	16 10		. .
	call sub_9279h		;ab02	cd 79 92	. y .
	ld a,d			;ab05	7a		z
	push af			;ab06	f5		.
	rrca			;ab07	0f		.
	rrca			;ab08	0f		.
	rrca			;ab09	0f		.
	and 01fh		;ab0a	e6 1f		. .
	ld (l89a4h+1),a		;ab0c	32 a5 89	2 . .
	pop af			;ab0f	f1		.
	add a,070h		;ab10	c6 70		. p
	ld h,a			;ab12	67		g
	ld a,(l882bh)		;ab13	3a 2b 88	: + .
	and a			;ab16	a7		.
	jr z,lab1dh		;ab17	28 04		( .
	ld a,007h		;ab19	3e 07		> .
	sub c			;ab1b	91		.
	ld c,a			;ab1c	4f		O
lab1dh:
	ld e,c			;ab1d	59		Y
	ld d,010h		;ab1e	16 10		. .
	call sub_9279h		;ab20	cd 79 92	. y .
	ld a,d			;ab23	7a		z
	push af			;ab24	f5		.
	rrca			;ab25	0f		.
	rrca			;ab26	0f		.
	rrca			;ab27	0f		.
	and 01fh		;ab28	e6 1f		. .
	ld (l89a4h+2),a		;ab2a	32 a6 89	2 . .
	pop af			;ab2d	f1		.
	add a,020h		;ab2e	c6 20		.  
	ld l,a			;ab30	6f		o
	pop af			;ab31	f1		.
	pop de			;ab32	d1		.
	pop bc			;ab33	c1		.
	ret			;ab34	c9		.
; ---------------------------------------------------------------------------
; DRAW SINGLE SQUARE WITH ATTRIBUTES
; Draws a checkerboard square (alternating 38h/07h attributes)
; for the 2x2 character cell area, creating the chess board
; pattern in the attribute memory.
; ---------------------------------------------------------------------------
sub_ab35h:
	push hl			;ab35	e5		.
	push bc			;ab36	c5		.
	push de			;ab37	d5		.
	ld b,008h		;ab38	06 08		. .
lab3ah:
	ld a,038h		;ab3a	3e 38		> 8
	call sub_ac10h		;ab3c	cd 10 ac	. . .
	ld a,007h		;ab3f	3e 07		> .
	call sub_ac10h		;ab41	cd 10 ac	. . .
	djnz lab3ah		;ab44	10 f4		. .
	pop de			;ab46	d1		.
	pop bc			;ab47	c1		.
	pop hl			;ab48	e1		.
; ---------------------------------------------------------------------------
; DRAW PIECE ON SQUARE
; Looks up the piece sprite from the sprite table, handles
; color inversion for piece-on-dark-square rendering, and
; calls the sprite engine to draw the 16x16 pixel piece.
; ---------------------------------------------------------------------------
sub_ab49h:
	push bc			;ab49	c5		.
	push de			;ab4a	d5		.
	push ix			;ab4b	dd e5		. .
	push af			;ab4d	f5		.
	ld a,(l8861h)		;ab4e	3a 61 88	: a .
	ld (l8809h),a		;ab51	32 09 88	2 . .
	ld e,a			;ab54	5f		_
	ld ix,(l8809h)		;ab55	dd 2a 09 88	. * . .
	ld a,(ix-04ch)		;ab59	dd 7e b4	. ~ .
	ld (l89a7h),a		;ab5c	32 a7 89	2 . .
	cp 0ffh			;ab5f	fe ff		. .
	jp z,labebh		;ab61	ca eb ab	. . .
	push hl			;ab64	e5		.
	ld d,000h		;ab65	16 00		. .
	ld hl,lac2dh		;ab67	21 2d ac	! - .
	add hl,de		;ab6a	19		.
	push af			;ab6b	f5		.
	and 007h		;ab6c	e6 07		. .
	add a,a			;ab6e	87		.
	add a,a			;ab6f	87		.
	or 080h			;ab70	f6 80		. .
	ld c,a			;ab72	4f		O
	ld a,(l89a3h)		;ab73	3a a3 89	: . .
	and a			;ab76	a7		.
	jp nz,lac02h		;ab77	c2 02 ac	. . .
	pop af			;ab7a	f1		.
	xor (hl)		;ab7b	ae		.
	jp p,lab83h		;ab7c	f2 83 ab	. . .
	ld a,01ch		;ab7f	3e 1c		> .
	add a,c			;ab81	81		.
	ld c,a			;ab82	4f		O
lab83h:
	ld a,(hl)		;ab83	7e		~
lab84h:
	ld (089afh),a		;ab84	32 af 89	2 . .
	pop hl			;ab87	e1		.
	ld a,c			;ab88	79		y
	push af			;ab89	f5		.
	call sub_afb4h		;ab8a	cd b4 af	. . .
	pop af			;ab8d	f1		.
	inc a			;ab8e	3c		<
	push af			;ab8f	f5		.
	call sub_afb7h		;ab90	cd b7 af	. . .
	ld a,008h		;ab93	3e 08		> .
	add a,l			;ab95	85		.
	ld l,a			;ab96	6f		o
	pop af			;ab97	f1		.
	inc a			;ab98	3c		<
	push af			;ab99	f5		.
	call sub_afb4h		;ab9a	cd b4 af	. . .
	pop af			;ab9d	f1		.
	inc a			;ab9e	3c		<
	call sub_afb7h		;ab9f	cd b7 af	. . .
	call sub_ac2ah		;aba2	cd 2a ac	. * .
	ld a,(l89a3h)		;aba5	3a a3 89	: . .
	and a			;aba8	a7		.
	jp z,labf1h		;aba9	ca f1 ab	. . .
	push hl			;abac	e5		.
	ld hl,l899fh		;abad	21 9f 89	! . .
	ld a,(l89a8h)		;abb0	3a a8 89	: . .
	and a			;abb3	a7		.
	jr z,labb7h		;abb4	28 01		( .
	inc hl			;abb6	23		#
labb7h:
	ld a,(hl)		;abb7	7e		~
	pop hl			;abb8	e1		.
	call sub_a7a7h		;abb9	cd a7 a7	. . .
	push hl			;abbc	e5		.
	inc hl			;abbd	23		#
	call sub_a7a7h		;abbe	cd a7 a7	. . .
	ld de,0001fh		;abc1	11 1f 00	. . .
	add hl,de		;abc4	19		.
	call sub_a7a7h		;abc5	cd a7 a7	. . .
	inc hl			;abc8	23		#
	call sub_a7a7h		;abc9	cd a7 a7	. . .
	ld hl,l89a1h		;abcc	21 a1 89	! . .
	ld a,(l89a7h)		;abcf	3a a7 89	: . .
	and a			;abd2	a7		.
	jp p,labd7h		;abd3	f2 d7 ab	. . .
	inc hl			;abd6	23		#
labd7h:
	ld a,(hl)		;abd7	7e		~
	pop hl			;abd8	e1		.
	call sub_a7b7h		;abd9	cd b7 a7	. . .
	inc hl			;abdc	23		#
	call sub_a7b7h		;abdd	cd b7 a7	. . .
	ld de,0001fh		;abe0	11 1f 00	. . .
	add hl,de		;abe3	19		.
	call sub_a7b7h		;abe4	cd b7 a7	. . .
	inc hl			;abe7	23		#
	call sub_a7b7h		;abe8	cd b7 a7	. . .
labebh:
	pop af			;abeb	f1		.
	pop ix			;abec	dd e1		. .
	pop de			;abee	d1		.
	pop bc			;abef	c1		.
	ret			;abf0	c9		.
labf1h:
	ld a,(l899eh)		;abf1	3a 9e 89	: . .
	set 6,a			;abf4	cb f7		. .
	ld (hl),a		;abf6	77		w
	inc hl			;abf7	23		#
	ld (hl),a		;abf8	77		w
	ld de,0001fh		;abf9	11 1f 00	. . .
	add hl,de		;abfc	19		.
	ld (hl),a		;abfd	77		w
	inc hl			;abfe	23		#
	ld (hl),a		;abff	77		w
	jr labebh		;ac00	18 e9		. .
lac02h:
	pop af			;ac02	f1		.
	ld a,01ch		;ac03	3e 1c		> .
	add a,c			;ac05	81		.
	ld c,a			;ac06	4f		O
	ld a,(hl)		;ac07	7e		~
	ld (l89a8h),a		;ac08	32 a8 89	2 . .
	ld a,000h		;ac0b	3e 00		> .
	jp lab84h		;ac0d	c3 84 ab	. . .
; ---------------------------------------------------------------------------
; SET ATTRIBUTE FOR SQUARE
; Writes a color attribute value to the 2x2 character cell
; area in the Spectrum attribute memory at 5800h. Includes
; a small delay loop for visual effect.
; ---------------------------------------------------------------------------
sub_ac10h:
	push af			;ac10	f5		.
	call sub_ac2ah		;ac11	cd 2a ac	. * .
	pop af			;ac14	f1		.
	ld (hl),a		;ac15	77		w
	inc hl			;ac16	23		#
	ld (hl),a		;ac17	77		w
	ld de,0001fh		;ac18	11 1f 00	. . .
	add hl,de		;ac1b	19		.
	ld (hl),a		;ac1c	77		w
	inc hl			;ac1d	23		#
	ld (hl),a		;ac1e	77		w
	push bc			;ac1f	c5		.
	ld bc,02020h		;ac20	01 20 20	.    
lac23h:
	djnz lac23h		;ac23	10 fe		. .
	dec c			;ac25	0d		.
	jr nz,lac23h		;ac26	20 fb		  .
	pop bc			;ac28	c1		.
	ret			;ac29	c9		.
sub_ac2ah:
	ld hl,0588eh		;ac2a	21 8e 58	! . X	; Base attribute address for board
lac2dh:
	ld de,00020h		;ac2d	11 20 00	.   .
	ld a,(l89a4h+2)		;ac30	3a a6 89	: . .
lac33h:
	dec a			;ac33	3d		=
	jp m,lac3ah		;ac34	fa 3a ac	. : .
	add hl,de		;ac37	19		.
	jr lac33h		;ac38	18 f9		. .
lac3ah:
	ld a,(l89a4h+1)		;ac3a	3a a5 89	: . .
lac3dh:
	dec a			;ac3d	3d		=
	ret m			;ac3e	f8		.
	inc hl			;ac3f	23		#
	jr lac3dh		;ac40	18 fb		. .
	add a,b			;ac42	80		.
	nop			;ac43	00		.
	add a,b			;ac44	80		.
	nop			;ac45	00		.
	add a,b			;ac46	80		.
	nop			;ac47	00		.
	add a,b			;ac48	80		.
	nop			;ac49	00		.
	rst 38h			;ac4a	ff		.
	rst 38h			;ac4b	ff		.
	nop			;ac4c	00		.
	add a,b			;ac4d	80		.
	nop			;ac4e	00		.
	add a,b			;ac4f	80		.
	nop			;ac50	00		.
	add a,b			;ac51	80		.
	nop			;ac52	00		.
	add a,b			;ac53	80		.
	rst 38h			;ac54	ff		.
	rst 38h			;ac55	ff		.
	add a,b			;ac56	80		.
	nop			;ac57	00		.
	add a,b			;ac58	80		.
	nop			;ac59	00		.
	add a,b			;ac5a	80		.
	nop			;ac5b	00		.
	add a,b			;ac5c	80		.
	nop			;ac5d	00		.
	rst 38h			;ac5e	ff		.
	rst 38h			;ac5f	ff		.
	nop			;ac60	00		.
	add a,b			;ac61	80		.
	nop			;ac62	00		.
	add a,b			;ac63	80		.
	nop			;ac64	00		.
	add a,b			;ac65	80		.
	nop			;ac66	00		.
	add a,b			;ac67	80		.
	rst 38h			;ac68	ff		.
	rst 38h			;ac69	ff		.
	add a,b			;ac6a	80		.
	nop			;ac6b	00		.
	add a,b			;ac6c	80		.
	nop			;ac6d	00		.
	add a,b			;ac6e	80		.
	nop			;ac6f	00		.
	add a,b			;ac70	80		.
	nop			;ac71	00		.
	rst 38h			;ac72	ff		.
	rst 38h			;ac73	ff		.
	nop			;ac74	00		.
	add a,b			;ac75	80		.
	nop			;ac76	00		.
	add a,b			;ac77	80		.
	nop			;ac78	00		.
	add a,b			;ac79	80		.
	nop			;ac7a	00		.
	add a,b			;ac7b	80		.
	rst 38h			;ac7c	ff		.
	rst 38h			;ac7d	ff		.
	add a,b			;ac7e	80		.
	nop			;ac7f	00		.
	add a,b			;ac80	80		.
	nop			;ac81	00		.
	add a,b			;ac82	80		.
	nop			;ac83	00		.
	add a,b			;ac84	80		.
	nop			;ac85	00		.
	rst 38h			;ac86	ff		.
	rst 38h			;ac87	ff		.
	nop			;ac88	00		.
	add a,b			;ac89	80		.
	nop			;ac8a	00		.
	add a,b			;ac8b	80		.
	nop			;ac8c	00		.
	add a,b			;ac8d	80		.
	nop			;ac8e	00		.
	add a,b			;ac8f	80		.
	nop			;ac90	00		.
	nop			;ac91	00		.
	nop			;ac92	00		.
	nop			;ac93	00		.
	nop			;ac94	00		.
	nop			;ac95	00		.
	nop			;ac96	00		.
	nop			;ac97	00		.
	nop			;ac98	00		.
	nop			;ac99	00		.
	nop			;ac9a	00		.
	nop			;ac9b	00		.
	nop			;ac9c	00		.
	nop			;ac9d	00		.
	nop			;ac9e	00		.
	nop			;ac9f	00		.
	nop			;aca0	00		.
	nop			;aca1	00		.
	nop			;aca2	00		.
	nop			;aca3	00		.
	nop			;aca4	00		.
	nop			;aca5	00		.
	nop			;aca6	00		.
	nop			;aca7	00		.
	nop			;aca8	00		.
	nop			;aca9	00		.
	nop			;acaa	00		.
	nop			;acab	00		.
	nop			;acac	00		.
	nop			;acad	00		.
	nop			;acae	00		.
lacafh:
	nop			;acaf	00		.
	nop			;acb0	00		.
	nop			;acb1	00		.
	nop			;acb2	00		.
	nop			;acb3	00		.
	nop			;acb4	00		.
	inc bc			;acb5	03		.
	inc b			;acb6	04		.
	inc b			;acb7	04		.
	nop			;acb8	00		.
	nop			;acb9	00		.
	nop			;acba	00		.
	nop			;acbb	00		.
	nop			;acbc	00		.
	ret nz			;acbd	c0		.
	jr nz,$+34		;acbe	20 20		   
	ld (bc),a		;acc0	02		.
	ld bc,00201h		;acc1	01 01 02	. . .
	rlca			;acc4	07		.
	nop			;acc5	00		.
	nop			;acc6	00		.
	nop			;acc7	00		.
	ld b,b			;acc8	40		@
	add a,b			;acc9	80		.
	add a,b			;acca	80		.
	ld b,b			;accb	40		@
	ret po			;accc	e0		.
	nop			;accd	00		.
	nop			;acce	00		.
	nop			;accf	00		.
	nop			;acd0	00		.
	nop			;acd1	00		.
	ld (bc),a		;acd2	02		.
	dec b			;acd3	05		.
	ex af,af'		;acd4	08		.
	ex af,af'		;acd5	08		.
	ex af,af'		;acd6	08		.
	add hl,bc		;acd7	09		.
	nop			;acd8	00		.
	nop			;acd9	00		.
	nop			;acda	00		.
	nop			;acdb	00		.
	ret nz			;acdc	c0		.
	jr nz,lacafh		;acdd	20 d0		  .
	jr nc,lace6h		;acdf	30 05		0 .
	inc b			;ace1	04		.
	inc b			;ace2	04		.
	inc b			;ace3	04		.
	ex af,af'		;ace4	08		.
	rrca			;ace5	0f		.
lace6h:
	nop			;ace6	00		.
	nop			;ace7	00		.
	nop			;ace8	00		.
	add a,b			;ace9	80		.
	ld b,b			;acea	40		@
	jr nz,lacfdh		;aceb	20 10		  .
	ret p			;aced	f0		.
	nop			;acee	00		.
	nop			;acef	00		.
	nop			;acf0	00		.
	nop			;acf1	00		.
	ld bc,00402h		;acf2	01 02 04	. . .
	ex af,af'		;acf5	08		.
	add hl,bc		;acf6	09		.
	inc b			;acf7	04		.
	nop			;acf8	00		.
	nop			;acf9	00		.
	add a,b			;acfa	80		.
	ld b,b			;acfb	40		@
	ld h,b			;acfc	60		`
lacfdh:
	sub b			;acfd	90		.
lacfeh:
	djnz lad20h		;acfe	10 20		.  
	ld (bc),a		;ad00	02		.
	ld bc,00201h		;ad01	01 01 02	. . .
	inc b			;ad04	04		.
	rrca			;ad05	0f		.
	nop			;ad06	00		.
	nop			;ad07	00		.
	ld b,b			;ad08	40		@
	add a,b			;ad09	80		.
	add a,b			;ad0a	80		.
	ld b,b			;ad0b	40		@
	jr nz,lacfeh		;ad0c	20 f0		  .
	nop			;ad0e	00		.
	nop			;ad0f	00		.
	nop			;ad10	00		.
	nop			;ad11	00		.
	nop			;ad12	00		.
	add hl,de		;ad13	19		.
	add hl,de		;ad14	19		.
	ld d,008h		;ad15	16 08		. .
	inc b			;ad17	04		.
	nop			;ad18	00		.
	nop			;ad19	00		.
	nop			;ad1a	00		.
	sbc a,b			;ad1b	98		.
	sbc a,b			;ad1c	98		.
	ld l,b			;ad1d	68		h
	djnz lad40h		;ad1e	10 20		.  
lad20h:
	inc b			;ad20	04		.
	inc b			;ad21	04		.
	inc b			;ad22	04		.
	inc b			;ad23	04		.
	ex af,af'		;ad24	08		.
	rra			;ad25	1f		.
lad26h:
	nop			;ad26	00		.
	nop			;ad27	00		.
	jr nz,$+34		;ad28	20 20		   
	jr nz,$+34		;ad2a	20 20		   
	djnz lad26h		;ad2c	10 f8		. .
	nop			;ad2e	00		.
	nop			;ad2f	00		.
	nop			;ad30	00		.
	ld bc,0040eh		;ad31	01 0e 04	. . .
	ld (bc),a		;ad34	02		.
	ld (bc),a		;ad35	02		.
	ld (bc),a		;ad36	02		.
	ld (bc),a		;ad37	02		.
	nop			;ad38	00		.
	add a,b			;ad39	80		.
	ld (hl),b		;ad3a	70		p
	jr nz,lad7dh		;ad3b	20 40		  @
	ld b,b			;ad3d	40		@
	ld b,b			;ad3e	40		@
	ld b,b			;ad3f	40		@
lad40h:
	ld (bc),a		;ad40	02		.
	inc b			;ad41	04		.
	inc b			;ad42	04		.
	ex af,af'		;ad43	08		.
	ex af,af'		;ad44	08		.
	djnz lad66h		;ad45	10 1f		. .
	nop			;ad47	00		.
	ld b,b			;ad48	40		@
	jr nz,$+34		;ad49	20 20		   
	djnz lad5dh		;ad4b	10 10		. .
	ex af,af'		;ad4d	08		.
	ret m			;ad4e	f8		.
	nop			;ad4f	00		.
	nop			;ad50	00		.
	ld bc,00606h		;ad51	01 06 06	. . .
	ld bc,01e01h		;ad54	01 01 1e	. . .
	ex af,af'		;ad57	08		.
	nop			;ad58	00		.
	add a,b			;ad59	80		.
	ld h,b			;ad5a	60		`
	ld h,b			;ad5b	60		`
	add a,b			;ad5c	80		.
lad5dh:
	add a,b			;ad5d	80		.
	ld a,b			;ad5e	78		x
	djnz $+6		;ad5f	10 04		. .
	inc b			;ad61	04		.
	inc b			;ad62	04		.
	ex af,af'		;ad63	08		.
	djnz lad76h		;ad64	10 10		. .
lad66h:
	rra			;ad66	1f		.
	nop			;ad67	00		.
	jr nz,lad8ah		;ad68	20 20		   
	jr nz,lad7ch		;ad6a	20 10		  .
	ex af,af'		;ad6c	08		.
	ex af,af'		;ad6d	08		.
	ret m			;ad6e	f8		.
	nop			;ad6f	00		.
	nop			;ad70	00		.
	nop			;ad71	00		.
	nop			;ad72	00		.
	nop			;ad73	00		.
	nop			;ad74	00		.
	nop			;ad75	00		.
lad76h:
	nop			;ad76	00		.
	nop			;ad77	00		.
	nop			;ad78	00		.
	nop			;ad79	00		.
	nop			;ad7a	00		.
	nop			;ad7b	00		.
lad7ch:
	nop			;ad7c	00		.
lad7dh:
	nop			;ad7d	00		.
	nop			;ad7e	00		.
	nop			;ad7f	00		.
	nop			;ad80	00		.
	nop			;ad81	00		.
	nop			;ad82	00		.
	nop			;ad83	00		.
	nop			;ad84	00		.
	nop			;ad85	00		.
	nop			;ad86	00		.
	nop			;ad87	00		.
	nop			;ad88	00		.
	nop			;ad89	00		.
lad8ah:
	nop			;ad8a	00		.
	nop			;ad8b	00		.
	nop			;ad8c	00		.
	nop			;ad8d	00		.
	nop			;ad8e	00		.
	nop			;ad8f	00		.
	nop			;ad90	00		.
	nop			;ad91	00		.
	nop			;ad92	00		.
	nop			;ad93	00		.
	nop			;ad94	00		.
	inc bc			;ad95	03		.
	rlca			;ad96	07		.
	rlca			;ad97	07		.
	nop			;ad98	00		.
	nop			;ad99	00		.
	nop			;ad9a	00		.
	nop			;ad9b	00		.
	nop			;ad9c	00		.
	ret nz			;ad9d	c0		.
	ret po			;ad9e	e0		.
	ret po			;ad9f	e0		.
	inc bc			;ada0	03		.
	ld bc,00301h		;ada1	01 01 03	. . .
	rlca			;ada4	07		.
	nop			;ada5	00		.
	nop			;ada6	00		.
	nop			;ada7	00		.
	ret nz			;ada8	c0		.
	add a,b			;ada9	80		.
	add a,b			;adaa	80		.
	ret nz			;adab	c0		.
	ret po			;adac	e0		.
	nop			;adad	00		.
	nop			;adae	00		.
	nop			;adaf	00		.
	nop			;adb0	00		.
	nop			;adb1	00		.
	ld (bc),a		;adb2	02		.
	rlca			;adb3	07		.
	rrca			;adb4	0f		.
	rrca			;adb5	0f		.
	rrca			;adb6	0f		.
	rrca			;adb7	0f		.
	nop			;adb8	00		.
	nop			;adb9	00		.
	nop			;adba	00		.
	nop			;adbb	00		.
	ret nz			;adbc	c0		.
	ret po			;adbd	e0		.
	ret p			;adbe	f0		.
	jr nc,ladc8h		;adbf	30 07		0 .
	rlca			;adc1	07		.
	rlca			;adc2	07		.
	rlca			;adc3	07		.
	rrca			;adc4	0f		.
	rrca			;adc5	0f		.
	nop			;adc6	00		.
	nop			;adc7	00		.
ladc8h:
	nop			;adc8	00		.
	add a,b			;adc9	80		.
	ret nz			;adca	c0		.
	ret po			;adcb	e0		.
	ret p			;adcc	f0		.
	ret p			;adcd	f0		.
	nop			;adce	00		.
	nop			;adcf	00		.
	nop			;add0	00		.
	nop			;add1	00		.
	ld bc,00703h		;add2	01 03 07	. . .
	ld c,00eh		;add5	0e 0e		. .
	rlca			;add7	07		.
	nop			;add8	00		.
	nop			;add9	00		.
	add a,b			;adda	80		.
	add a,b			;addb	80		.
	jr nz,lae4eh		;addc	20 70		  p
	ret p			;adde	f0		.
	ret po			;addf	e0		.
	inc bc			;ade0	03		.
	ld bc,00301h		;ade1	01 01 03	. . .
	rlca			;ade4	07		.
	rrca			;ade5	0f		.
	nop			;ade6	00		.
	nop			;ade7	00		.
	ret nz			;ade8	c0		.
	add a,b			;ade9	80		.
	add a,b			;adea	80		.
	ret nz			;adeb	c0		.
	ret po			;adec	e0		.
	ret p			;aded	f0		.
	nop			;adee	00		.
	nop			;adef	00		.
	nop			;adf0	00		.
	nop			;adf1	00		.
	nop			;adf2	00		.
	add hl,de		;adf3	19		.
	add hl,de		;adf4	19		.
	rra			;adf5	1f		.
	rrca			;adf6	0f		.
	rlca			;adf7	07		.
	nop			;adf8	00		.
	nop			;adf9	00		.
	nop			;adfa	00		.
	sbc a,b			;adfb	98		.
	sbc a,b			;adfc	98		.
	ret m			;adfd	f8		.
	ret p			;adfe	f0		.
	ret po			;adff	e0		.
lae00h:
	rlca			;ae00	07		.
	rlca			;ae01	07		.
	rlca			;ae02	07		.
	rlca			;ae03	07		.
	rrca			;ae04	0f		.
	rra			;ae05	1f		.
	nop			;ae06	00		.
	nop			;ae07	00		.
	ret po			;ae08	e0		.
	ret po			;ae09	e0		.
	ret po			;ae0a	e0		.
	ret po			;ae0b	e0		.
	ret p			;ae0c	f0		.
	ret m			;ae0d	f8		.
	nop			;ae0e	00		.
	nop			;ae0f	00		.
	nop			;ae10	00		.
	ld bc,0070fh		;ae11	01 0f 07	. . .
	inc bc			;ae14	03		.
	inc bc			;ae15	03		.
	inc bc			;ae16	03		.
	inc bc			;ae17	03		.
	nop			;ae18	00		.
	add a,b			;ae19	80		.
	ret p			;ae1a	f0		.
	ret po			;ae1b	e0		.
	ret nz			;ae1c	c0		.
	ret nz			;ae1d	c0		.
	ret nz			;ae1e	c0		.
	ret nz			;ae1f	c0		.
	inc bc			;ae20	03		.
	rlca			;ae21	07		.
	rlca			;ae22	07		.
	rrca			;ae23	0f		.
	rrca			;ae24	0f		.
	rra			;ae25	1f		.
	rra			;ae26	1f		.
	nop			;ae27	00		.
	ret nz			;ae28	c0		.
	ret po			;ae29	e0		.
	ret po			;ae2a	e0		.
	ret p			;ae2b	f0		.
	ret p			;ae2c	f0		.
	ret m			;ae2d	f8		.
	ret m			;ae2e	f8		.
	nop			;ae2f	00		.
	nop			;ae30	00		.
	ld bc,00707h		;ae31	01 07 07	. . .
	ld bc,01f01h		;ae34	01 01 1f	. . .
	rrca			;ae37	0f		.
	nop			;ae38	00		.
	add a,b			;ae39	80		.
	ret po			;ae3a	e0		.
	ret po			;ae3b	e0		.
	add a,b			;ae3c	80		.
	add a,b			;ae3d	80		.
	ret m			;ae3e	f8		.
	ret p			;ae3f	f0		.
	rlca			;ae40	07		.
	rlca			;ae41	07		.
	rlca			;ae42	07		.
	rrca			;ae43	0f		.
	rra			;ae44	1f		.
	rra			;ae45	1f		.
	rra			;ae46	1f		.
	nop			;ae47	00		.
	ret po			;ae48	e0		.
	ret po			;ae49	e0		.
	ret po			;ae4a	e0		.
	ret p			;ae4b	f0		.
	ret m			;ae4c	f8		.
	ret m			;ae4d	f8		.
lae4eh:
	ret m			;ae4e	f8		.
	nop			;ae4f	00		.
lae50h:
	push af			;ae50	f5		.
	push hl			;ae51	e5		.
	ld a,(laeebh)		;ae52	3a eb ae	: . .
	ld hl,laef0h		;ae55	21 f0 ae	! . .
	dec a			;ae58	3d		=
	jp nz,lae5fh		;ae59	c2 5f ae	. _ .
	ld hl,laeebh+1		;ae5c	21 ec ae	! . .
lae5fh:
	dec (hl)		;ae5f	35		5
	jp nz,lae88h		;ae60	c2 88 ae	. . .
	ld (hl),032h		;ae63	36 32		6 2
	inc hl			;ae65	23		#
	ld a,001h		;ae66	3e 01		> .
	add a,(hl)		;ae68	86		.
	daa			;ae69	27		'
	ld (hl),a		;ae6a	77		w
	cp 060h			;ae6b	fe 60		. `
	jp nz,lae85h		;ae6d	c2 85 ae	. . .
	ld (hl),000h		;ae70	36 00		6 .
	inc hl			;ae72	23		#
	ld a,001h		;ae73	3e 01		> .
	add a,(hl)		;ae75	86		.
	daa			;ae76	27		'
	ld (hl),a		;ae77	77		w
	cp 060h			;ae78	fe 60		. `
	jp nz,lae85h		;ae7a	c2 85 ae	. . .
	ld (hl),000h		;ae7d	36 00		6 .
	inc hl			;ae7f	23		#
	ld a,001h		;ae80	3e 01		> .
	add a,(hl)		;ae82	86		.
	daa			;ae83	27		'
	ld (hl),a		;ae84	77		w
lae85h:
	call sub_ae8dh		;ae85	cd 8d ae	. . .
lae88h:
	pop hl			;ae88	e1		.
	pop af			;ae89	f1		.
	jp 00038h		;ae8a	c3 38 00	. 8 .
sub_ae8dh:
	push de			;ae8d	d5		.
	push bc			;ae8e	c5		.
	ld de,laef3h		;ae8f	11 f3 ae	. . .
	ld bc,04017h		;ae92	01 17 40	. . @
	ld a,(laeebh)		;ae95	3a eb ae	: . .
	dec a			;ae98	3d		=
	jp nz,laea2h		;ae99	c2 a2 ae	. . .
	ld de,laeefh		;ae9c	11 ef ae	. . .
	ld bc,0400dh		;ae9f	01 0d 40	. . @
laea2h:
	call sub_aeb2h		;aea2	cd b2 ae	. . .
	dec de			;aea5	1b		.
	inc c			;aea6	0c		.
	call sub_aeb2h		;aea7	cd b2 ae	. . .
	dec de			;aeaa	1b		.
	inc c			;aeab	0c		.
	call sub_aeb2h		;aeac	cd b2 ae	. . .
	pop bc			;aeaf	c1		.
	pop de			;aeb0	d1		.
	ret			;aeb1	c9		.
sub_aeb2h:
	ld a,(de)		;aeb2	1a		.
	srl a			;aeb3	cb 3f		. ?
	srl a			;aeb5	cb 3f		. ?
	srl a			;aeb7	cb 3f		. ?
	srl a			;aeb9	cb 3f		. ?
	call sub_aec1h		;aebb	cd c1 ae	. . .
	ld a,(de)		;aebe	1a		.
	and 00fh		;aebf	e6 0f		. .
sub_aec1h:
	push bc			;aec1	c5		.
	ld hl,03d80h		;aec2	21 80 3d	! . =
	add a,a			;aec5	87		.
	add a,a			;aec6	87		.
	add a,a			;aec7	87		.
	add a,l			;aec8	85		.
	ld l,a			;aec9	6f		o
	ld a,(hl)		;aeca	7e		~
	ld (bc),a		;aecb	02		.
	inc b			;aecc	04		.
	inc hl			;aecd	23		#
	ld a,(hl)		;aece	7e		~
	ld (bc),a		;aecf	02		.
	inc b			;aed0	04		.
	inc hl			;aed1	23		#
	ld a,(hl)		;aed2	7e		~
	ld (bc),a		;aed3	02		.
	inc b			;aed4	04		.
	inc hl			;aed5	23		#
	ld a,(hl)		;aed6	7e		~
	ld (bc),a		;aed7	02		.
	inc b			;aed8	04		.
	inc hl			;aed9	23		#
	ld a,(hl)		;aeda	7e		~
	ld (bc),a		;aedb	02		.
	inc b			;aedc	04		.
	inc hl			;aedd	23		#
	ld a,(hl)		;aede	7e		~
	ld (bc),a		;aedf	02		.
	inc b			;aee0	04		.
	inc hl			;aee1	23		#
	ld a,(hl)		;aee2	7e		~
	ld (bc),a		;aee3	02		.
	inc b			;aee4	04		.
	inc hl			;aee5	23		#
	ld a,(hl)		;aee6	7e		~
	ld (bc),a		;aee7	02		.
	pop bc			;aee8	c1		.
	inc c			;aee9	0c		.
	ret			;aeea	c9		.
laeebh:
	ld bc,01518h		;aeeb	01 18 15	. . .
	nop			;aeee	00		.
laeefh:
	nop			;aeef	00		.
laef0h:
	ld (00000h),a		;aef0	32 00 00	2 . .
laef3h:
	nop			;aef3	00		.
laef4h:
	jr nz,laf16h		;aef4	20 20		   
	ld c,l			;aef6	4d		M
	ld c,(hl)		;aef7	4e		N
	ld b,d			;aef8	42		B
	jr nz,$+78		;aef9	20 4c		  L
	ld c,e			;aefb	4b		K
	ld c,d			;aefc	4a		J
	ld c,b			;aefd	48		H
	ld d,b			;aefe	50		P
	ld c,a			;aeff	4f		O
	ld c,c			;af00	49		I
	ld d,l			;af01	55		U
	ld e,c			;af02	59		Y
	jr nc,$+59		;af03	30 39		0 9
	jr c,$+57		;af05	38 37		8 7
	ld (hl),031h		;af07	36 31		6 1
	ld (03433h),a		;af09	32 33 34	2 3 4
	dec (hl)		;af0c	35		5
	ld d,c			;af0d	51		Q
	ld d,a			;af0e	57		W
	ld b,l			;af0f	45		E
	ld d,d			;af10	52		R
	ld d,h			;af11	54		T
	ld b,c			;af12	41		A
	ld d,e			;af13	53		S
	ld b,h			;af14	44		D
	ld b,(hl)		;af15	46		F
laf16h:
	ld b,a			;af16	47		G
	jr nz,laf73h		;af17	20 5a		  Z
	ld e,b			;af19	58		X
	ld b,e			;af1a	43		C
	ld d,(hl)		;af1b	56		V
; ---------------------------------------------------------------------------
; KEYBOARD INPUT
; Scans the keyboard matrix via port FEh. Waits for all keys
; released, then detects a keypress. Maps the row/column to
; an ASCII code via lookup table at AEF4h. Outputs a beep.
; ---------------------------------------------------------------------------
sub_af1ch:
	push bc			;af1c	c5		.
	push de			;af1d	d5		.
	push hl			;af1e	e5		.
laf1fh:
	call sub_9903h		;af1f	cd 03 99	. . .
	ld c,07fh		;af22	0e 7f		. .
	ld b,008h		;af24	06 08		. .
	ld a,c			;af26	79		y
laf27h:
	in a,(0feh)		;af27	db fe		. .	; Read keyboard row
	and 01fh		;af29	e6 1f		. .	; Mask to 5 key bits
	cp 01fh			;af2b	fe 1f		. .	; All keys released?
	jr nz,laf1fh		;af2d	20 f0		  .	; No -> wait for release
	ld a,c			;af2f	79		y
	rrca			;af30	0f		.
	ld c,a			;af31	4f		O
	djnz laf27h		;af32	10 f3		. .
	ld de,00005h		;af34	11 05 00	. . .
laf37h:
	call sub_9903h		;af37	cd 03 99	. . .
	ld hl,laef4h		;af3a	21 f4 ae	! . .
	ld c,07fh		;af3d	0e 7f		. .
	ld b,008h		;af3f	06 08		. .
	ld a,c			;af41	79		y
laf42h:
	in a,(0feh)		;af42	db fe		. .
	and 01fh		;af44	e6 1f		. .
	cp 01fh			;af46	fe 1f		. .
	jr nz,laf53h		;af48	20 09		  .
	ld a,c			;af4a	79		y
	rrca			;af4b	0f		.
	ld c,a			;af4c	4f		O
	add hl,de		;af4d	19		.
	djnz laf42h		;af4e	10 f2		. .
	jr laf37h		;af50	18 e5		. .
laf52h:
	inc hl			;af52	23		#
laf53h:
	rrca			;af53	0f		.
	jr c,laf52h		;af54	38 fc		8 .
	ld a,(hl)		;af56	7e		~
	push af			;af57	f5		.
	call sub_afb7h		;af58	cd b7 af	. . .
	pop af			;af5b	f1		.
	ld hl,00020h		;af5c	21 20 00	!   .
	ld de,00080h		;af5f	11 80 00	. . .
	call sub_b058h		;af62	cd 58 b0	. X .
	pop hl			;af65	e1		.
	pop de			;af66	d1		.
	pop bc			;af67	c1		.
	ret			;af68	c9		.
; ---------------------------------------------------------------------------
; SAVE/RESTORE CONTEXT
; Saves all registers (including shadow set and IX) plus
; the stack pointer for cooperative multitasking during
; computer thinking. Swaps to a secondary stack at 887Ah.
; ---------------------------------------------------------------------------
sub_af69h:
	push bc			;af69	c5		.
	push de			;af6a	d5		.
	push hl			;af6b	e5		.
	push ix			;af6c	dd e5		. .
	ex af,af'		;af6e	08		.
	push af			;af6f	f5		.
	ex af,af'		;af70	08		.
	exx			;af71	d9		.
	push bc			;af72	c5		.
laf73h:
	push de			;af73	d5		.
	push hl			;af74	e5		.
	exx			;af75	d9		.
	ld hl,00000h		;af76	21 00 00	! . .
	add hl,sp		;af79	39		9	; HL = current SP
	ld (l887ah+2),hl	;af7a	22 7c 88	" | .	; Save primary SP
	ld hl,(l887ah)		;af7d	2a 7a 88	* z .	; Load secondary SP
	ld sp,hl		;af80	f9		.	; Switch to secondary stack
	ret			;af81	c9		.	; Return resumes secondary context
; ---------------------------------------------------------------------------
; INTERRUPT RETURN POINT
; One of three JP vectors at 8800h. Restores the primary
; context after a multitask yield, returning all registers
; and stack pointer to their saved state.
; ---------------------------------------------------------------------------
laf82h:
	ld hl,00000h		;af82	21 00 00	! . .
	add hl,sp		;af85	39		9
	ld (l887ah),hl		;af86	22 7a 88	" z .
	ld hl,(l887ah+2)	;af89	2a 7c 88	* | .
	ld sp,hl		;af8c	f9		.
	exx			;af8d	d9		.
	pop hl			;af8e	e1		.
	pop de			;af8f	d1		.
	pop bc			;af90	c1		.
	exx			;af91	d9		.
	ex af,af'		;af92	08		.
	pop af			;af93	f1		.
	ex af,af'		;af94	08		.
	pop ix			;af95	dd e1		. .
	pop hl			;af97	e1		.
	pop de			;af98	d1		.
	pop bc			;af99	c1		.
	ret			;af9a	c9		.
; ---------------------------------------------------------------------------
; GET KEY WITH PROMPT / CLEAR STATUS LINE
; sub_af9bh: Calls keyboard scan, then falls through to clear.
; sub_af9eh: Clears the status line by printing 32 spaces
; from lb2c1h at screen position 00B8h.
; ---------------------------------------------------------------------------
sub_af9bh:
	call sub_af1ch		;af9b	cd 1c af	. . .	; Get keypress
sub_af9eh:
	push bc			;af9e	c5		.
	push de			;af9f	d5		.
	push hl			;afa0	e5		.
	push af			;afa1	f5		.
	ld de,lb2c1h		;afa2	11 c1 b2	. . .
	ld b,020h		;afa5	06 20		.  
	call sub_b038h		;afa7	cd 38 b0	. 8 .
	pop af			;afaa	f1		.
	jp lb034h		;afab	c3 34 b0	. 4 .
; ---------------------------------------------------------------------------
; PRINT CHARACTER (NORMAL)
; Clears the inversion flag at 89AFh before printing, so
; the character renders in normal (non-inverted) video.
; ---------------------------------------------------------------------------
sub_afaeh:
	push af			;afae	f5		.
	xor a			;afaf	af		.
	ld (089afh),a		;afb0	32 af 89	2 . .
	pop af			;afb3	f1		.
sub_afb4h:
	ld (l8878h),hl		;afb4	22 78 88	" x .	; Save screen position
; ---------------------------------------------------------------------------
; PRINT CHARACTER TO SCREEN
; Renders a character using the font at 3C00h (ROM charset)
; or custom sprites at A890h/89F8h. Calculates the Spectrum
; screen address from HL coordinates and copies 8 pixel rows.
; ---------------------------------------------------------------------------
sub_afb7h:
	push bc			;afb7	c5		.
	push de			;afb8	d5		.
	push hl			;afb9	e5		.
	ld l,a			;afba	6f		o
	ld h,000h		;afbb	26 00		& .
	add hl,hl		;afbd	29		)
	add hl,hl		;afbe	29		)
	add hl,hl		;afbf	29		)
	ld de,0a890h		;afc0	11 90 a8	. . .
	and a			;afc3	a7		.
	jp m,lafd1h		;afc4	fa d1 af	. . .
	ld de,03c00h		;afc7	11 00 3c	. . <	; ROM charset at 3C00h
	cp 020h			;afca	fe 20		.	; Printable ASCII (>= space)?
	jr nc,lafd1h		;afcc	30 03		0 .	; Yes -> use ROM font
	ld de,089f8h		;afce	11 f8 89	. . .	; No -> use custom sprites
lafd1h:
	add hl,de		;afd1	19		.
	ld bc,(l8878h)		;afd2	ed 4b 78 88	. K x .
	ld a,c			;afd6	79		y
	and 0c0h		;afd7	e6 c0		. .
	rrca			;afd9	0f		.
	rrca			;afda	0f		.
	rrca			;afdb	0f		.
	or 040h			;afdc	f6 40		. @
	ld d,a			;afde	57		W
	ld a,c			;afdf	79		y
	and 007h		;afe0	e6 07		. .
	or d			;afe2	b2		.
	ld d,a			;afe3	57		W
	ld a,c			;afe4	79		y
	and 038h		;afe5	e6 38		. 8
	rlca			;afe7	07		.
	rlca			;afe8	07		.
	ld e,a			;afe9	5f		_
	ld a,b			;afea	78		x
	and 0f8h		;afeb	e6 f8		. .
	rrca			;afed	0f		.
	rrca			;afee	0f		.
	rrca			;afef	0f		.
	or e			;aff0	b3		.
	ld e,a			;aff1	5f		_
	ld b,008h		;aff2	06 08		. .
laff4h:
	ld a,(089afh)		;aff4	3a af 89	: . .
	and a			;aff7	a7		.
	ld a,(hl)		;aff8	7e		~
	jr z,laffch		;aff9	28 01		( .
	cpl			;affb	2f		/
laffch:
	ld (de),a		;affc	12		.
	inc hl			;affd	23		#
	inc d			;affe	14		.
	djnz laff4h		;afff	10 f3		. .
	jr lb02ch		;b001	18 29		. )
; ---------------------------------------------------------------------------
; PRINT CHARACTER WITH BUFFER
; Copies the character bitmap to a temporary buffer at 8995h,
; then renders it via the sprite engine. Used for characters
; that need pre-processing before display.
; ---------------------------------------------------------------------------
sub_b003h:
	ld (l8878h),hl		;b003	22 78 88	" x .
	push bc			;b006	c5		.
	push de			;b007	d5		.
	push hl			;b008	e5		.
	ld l,a			;b009	6f		o
	ld h,000h		;b00a	26 00		& .
	add hl,hl		;b00c	29		)
	add hl,hl		;b00d	29		)
	add hl,hl		;b00e	29		)
	ld de,03c00h		;b00f	11 00 3c	. . <
	cp 020h			;b012	fe 20		.  
	jr nc,lb019h		;b014	30 03		0 .
	ld de,089f8h		;b016	11 f8 89	. . .
lb019h:
	add hl,de		;b019	19		.
	ld de,l8995h		;b01a	11 95 89	. . .
	ld bc,00008h		;b01d	01 08 00	. . .
	ldir			;b020	ed b0		. .
	ld de,(l8878h)		;b022	ed 5b 78 88	. [ x .
	ld hl,l8993h		;b026	21 93 89	! . .
	call sub_a870h		;b029	cd 70 a8	. p .
lb02ch:
	ld a,(l8879h)		;b02c	3a 79 88	: y .
	add a,008h		;b02f	c6 08		. .
	ld (l8879h),a		;b031	32 79 88	2 y .
lb034h:
	pop hl			;b034	e1		.
	pop de			;b035	d1		.
	pop bc			;b036	c1		.
	ret			;b037	c9		.
; ---------------------------------------------------------------------------
; PRINT STRING
; sub_b038h: Prints B characters from (DE) at default position
;   00B8h (bottom status line).
; sub_b03bh: Prints B characters from (DE) at position in HL.
; ---------------------------------------------------------------------------
sub_b038h:
	ld hl,000b8h		;b038	21 b8 00	! . .	; Default: status line position
sub_b03bh:
	ld (l8878h),hl		;b03b	22 78 88	" x .
	xor a			;b03e	af		.
	ld (089afh),a		;b03f	32 af 89	2 . .
lb042h:
	ld a,(de)		;b042	1a		.
	inc de			;b043	13		.
	call sub_afb7h		;b044	cd b7 af	. . .
	djnz lb042h		;b047	10 f9		. .
	ret			;b049	c9		.
; ---------------------------------------------------------------------------
; LONG BEEP
; Produces a longer-duration beep by calling the sound
; routine with HL=0200h and DE=0080h parameters.
; ---------------------------------------------------------------------------
sub_b04ah:
	push bc			;b04a	c5		.
	push hl			;b04b	e5		.
	ld hl,00200h		;b04c	21 00 02	! . .
	ld de,00080h		;b04f	11 80 00	. . .
	call sub_b058h		;b052	cd 58 b0	. X .
	pop hl			;b055	e1		.
	pop bc			;b056	c1		.
	ret			;b057	c9		.
; ---------------------------------------------------------------------------
; BEEP/SOUND
; Outputs alternating high/low states to port FEh (speaker).
; HL = duration (number of cycles), DE = half-period delay.
; Also sets the border color from 899Dh.
; ---------------------------------------------------------------------------
sub_b058h:
	push af			;b058	f5		.
lb059h:
	ld a,(l899dh)		;b059	3a 9d 89	: . .
	rrca			;b05c	0f		.
	rrca			;b05d	0f		.
	rrca			;b05e	0f		.
	and 007h		;b05f	e6 07		. .
	or 0f8h			;b061	f6 f8		. .
	out (0feh),a		;b063	d3 fe		. .	; Toggle speaker + set border
	push de			;b065	d5		.
lb066h:
	dec de			;b066	1b		.
	ld a,d			;b067	7a		z
	or e			;b068	b3		.
	jr nz,lb066h		;b069	20 fb		  .
	pop de			;b06b	d1		.
	ld a,(l899dh)		;b06c	3a 9d 89	: . .
	rrca			;b06f	0f		.
	rrca			;b070	0f		.
	rrca			;b071	0f		.
	and 007h		;b072	e6 07		. .
	or 0e8h			;b074	f6 e8		. .
	out (0feh),a		;b076	d3 fe		. .
	dec hl			;b078	2b		+
	ld a,h			;b079	7c		|
	or l			;b07a	b5		.
	jr nz,lb059h		;b07b	20 dc		  .
	pop af			;b07d	f1		.
	ret			;b07e	c9		.
; ===========================================================================
; STRING DATA (B07Fh+)
; ASCII text messages for the user interface. These are
; referenced by various display routines via DE pointer
; and B = length. Strings are not null-terminated; length
; is passed explicitly in the B register.
; ===========================================================================
;
; "Play/colour/set up? p, c or s"
lb07fh:
	ld d,b			;b07f	50		P
	ld l,h			;b080	6c		l
	ld h,c			;b081	61		a
	ld a,c			;b082	79		y
	cpl			;b083	2f		/
	ld h,e			;b084	63		c
	ld l,a			;b085	6f		o
	ld l,h			;b086	6c		l
	ld l,a			;b087	6f		o
	ld (hl),l		;b088	75		u
	ld (hl),d		;b089	72		r
	cpl			;b08a	2f		/
	ld (hl),e		;b08b	73		s
	ld h,l			;b08c	65		e
	ld (hl),h		;b08d	74		t
	jr nz,lb105h		;b08e	20 75		  u
	ld (hl),b		;b090	70		p
	ccf			;b091	3f		?
	jr nz,$+114		;b092	20 70		  p
	inc l			;b094	2c		,
	jr nz,$+101		;b095	20 63		  c
	jr nz,lb108h		;b097	20 6f		  o
	ld (hl),d		;b099	72		r
	jr nz,lb10fh		;b09a	20 73		  s
; (B09Dh) "Choose white or black, w or b."
	jr nz,lb0e1h		;b09c	20 43		  C
	ld l,b			;b09e	68		h
	ld l,a			;b09f	6f		o
	ld l,a			;b0a0	6f		o
	ld (hl),e		;b0a1	73		s
	ld h,l			;b0a2	65		e
	jr nz,lb11ch		;b0a3	20 77		  w
	ld l,b			;b0a5	68		h
	ld l,c			;b0a6	69		i
	ld (hl),h		;b0a7	74		t
	ld h,l			;b0a8	65		e
	jr nz,$+113		;b0a9	20 6f		  o
	ld (hl),d		;b0ab	72		r
	jr nz,lb110h		;b0ac	20 62		  b
	ld l,h			;b0ae	6c		l
	ld h,c			;b0af	61		a
	ld h,e			;b0b0	63		c
	ld l,e			;b0b1	6b		k
	inc l			;b0b2	2c		,
	jr nz,lb12ch		;b0b3	20 77		  w
	jr nz,lb126h		;b0b5	20 6f		  o
	ld (hl),d		;b0b7	72		r
	jr nz,lb11ch		;b0b8	20 62		  b
	ld l,020h		;b0ba	2e 20		.  
lb0bch:
	jr nz,lb0cah		;b0bc	20 0c		  .
	dec c			;b0be	0d		.
	ld c,020h		;b0bf	0e 20		.  
lb0c1h:
	jr nz,lb11ch		;b0c1	20 59		  Y
	ld l,a			;b0c3	6f		o
	ld (hl),l		;b0c4	75		u
	jr nz,lb0f7h		;b0c5	20 30		  0
	ld sp,02f20h		;b0c7	31 20 2f	1   /
lb0cah:
	dec h			;b0ca	25		%
lb0cbh:
	jr nz,lb11ch		;b0cb	20 4f		  O
	dec l			;b0cd	2d		-
	ld c,a			;b0ce	4f		O
	jr nz,lb120h		;b0cf	20 4f		  O
	dec l			;b0d1	2d		-
	ld c,a			;b0d2	4f		O
	dec l			;b0d3	2d		-
	ld c,a			;b0d4	4f		O
lb0d5h:
	ld b,e			;b0d5	43		C
	ld l,b			;b0d6	68		h
	ld h,l			;b0d7	65		e
	ld h,e			;b0d8	63		c
	ld l,e			;b0d9	6b		k
lb0dah:
	ld l,l			;b0da	6d		m
	ld h,c			;b0db	61		a
	ld (hl),h		;b0dc	74		t
	ld h,l			;b0dd	65		e
	jr nz,lb149h		;b0de	20 69		  i
	ld l,(hl)		;b0e0	6e		n
lb0e1h:
	jr nz,lb12eh		;b0e1	20 4b		  K
	ld d,c			;b0e3	51		Q
	ld d,d			;b0e4	52		R
	ld b,d			;b0e5	42		B
	ld c,(hl)		;b0e6	4e		N
	ld d,b			;b0e7	50		P
; "Masterchess 00:00:00" (title + clock display)
lb0e8h:
	ld c,l			;b0e8	4d		M
	ld h,c			;b0e9	61		a
	ld (hl),e		;b0ea	73		s
	ld (hl),h		;b0eb	74		t
	ld h,l			;b0ec	65		e
	ld (hl),d		;b0ed	72		r
	ld h,e			;b0ee	63		c
	ld l,b			;b0ef	68		h
	ld h,l			;b0f0	65		e
	ld (hl),e		;b0f1	73		s
	ld (hl),e		;b0f2	73		s
	jr nz,lb125h		;b0f3	20 30		  0
	jr nc,lb131h		;b0f5	30 3a		0 :
lb0f7h:
	jr nc,$+50		;b0f7	30 30		0 0
	ld a,(03030h)		;b0f9	3a 30 30	: 0 0
; "a-h,1-8 or Del,l,r,z,t,x."
lb0fch:
	ld h,c			;b0fc	61		a
	dec l			;b0fd	2d		-
	ld l,b			;b0fe	68		h
	inc l			;b0ff	2c		,
	ld sp,0382dh		;b100	31 2d 38	1 - 8
	jr nz,lb174h		;b103	20 6f		  o
lb105h:
	ld (hl),d		;b105	72		r
	jr nz,lb14ch		;b106	20 44		  D
lb108h:
	ld h,l			;b108	65		e
	ld l,h			;b109	6c		l
	inc l			;b10a	2c		,
	ld l,h			;b10b	6c		l
	inc l			;b10c	2c		,
	ld (hl),d		;b10d	72		r
	inc l			;b10e	2c		,
lb10fh:
	ld a,d			;b10f	7a		z
lb110h:
	inc l			;b110	2c		,
	ld (hl),h		;b111	74		t
	inc l			;b112	2c		,
	ld a,b			;b113	78		x
	ld l,020h		;b114	2e 20		.
; "You win"
lb116h:
	ld e,c			;b116	59		Y
	ld l,a			;b117	6f		o
	ld (hl),l		;b118	75		u
	jr nz,lb192h		;b119	20 77		  w
	ld l,c			;b11b	69		i
lb11ch:
	ld l,(hl)		;b11c	6e		n
; "I win"
lb11dh:
	ld c,c			;b11d	49		I
	jr nz,lb197h		;b11e	20 77		  w
lb120h:
	ld l,c			;b120	69		i
	ld l,(hl)		;b121	6e		n
; "Select level, (0-9)"
lb122h:
	ld d,e			;b122	53		S
	ld h,l			;b123	65		e
	ld l,h			;b124	6c		l
lb125h:
	ld h,l			;b125	65		e
lb126h:
	ld h,e			;b126	63		c
	ld (hl),h		;b127	74		t
	jr nz,$+110		;b128	20 6c		  l
	ld h,l			;b12a	65		e
	halt			;b12b	76		v
lb12ch:
	ld h,l			;b12c	65		e
	ld l,h			;b12d	6c		l
lb12eh:
	inc l			;b12e	2c		,
	jr nz,lb159h		;b12f	20 28		  (
lb131h:
	jr nc,lb160h		;b131	30 2d		0 -
	add hl,sp		;b133	39		9
	add hl,hl		;b134	29		)
	jr nz,lb18eh		;b135	20 57		  W
	ld l,b			;b137	68		h
	ld l,a			;b138	6f		o
	ld (hl),e		;b139	73		s
	ld h,l			;b13a	65		e
	jr nz,$+111		;b13b	20 6d		  m
	ld l,a			;b13d	6f		o
	halt			;b13e	76		v
	ld h,l			;b13f	65		e
	jr nz,lb1abh		;b140	20 69		  i
	ld (hl),e		;b142	73		s
	jr nz,lb1aeh		;b143	20 69		  i
	ld (hl),h		;b145	74		t
	ccf			;b146	3f		?
	jr nz,$+121		;b147	20 77		  w
lb149h:
	jr nz,lb1bah		;b149	20 6f		  o
	ld (hl),d		;b14b	72		r
lb14ch:
	jr nz,$+100		;b14c	20 62		  b
	ld l,020h		;b14e	2e 20		.
; "Colour? w or b."
lb150h:
	ld b,e			;b150	43		C
	ld l,a			;b151	6f		o
	ld l,h			;b152	6c		l
	ld l,a			;b153	6f		o
	ld (hl),l		;b154	75		u
	ld (hl),d		;b155	72		r
	ccf			;b156	3f		?
	jr nz,lb1d0h		;b157	20 77		  w
lb159h:
	jr nz,lb1cah		;b159	20 6f		  o
	ld (hl),d		;b15b	72		r
	jr nz,$+100		;b15c	20 62		  b
	ld l,020h		;b15e	2e 20		.
; "Moved yet? y or n."
lb160h:
	ld c,l			;b160	4d		M
	ld l,a			;b161	6f		o
	halt			;b162	76		v
	ld h,l			;b163	65		e
	ld h,h			;b164	64		d
	jr nz,lb1e0h		;b165	20 79		  y
	ld h,l			;b167	65		e
	ld (hl),h		;b168	74		t
	ccf			;b169	3f		?
	jr nz,lb1e5h		;b16a	20 79		  y
	jr nz,lb1ddh		;b16c	20 6f		  o
	ld (hl),d		;b16e	72		r
	jr nz,lb1dfh		;b16f	20 6e		  n
	ld l,020h		;b171	2e 20		.  
lb173h:
	nop			;b173	00		.
lb174h:
	inc l			;b174	2c		,
	ld bc,0022ch		;b175	01 2c 02	. , .
	inc l			;b178	2c		,
	inc bc			;b179	03		.
	inc l			;b17a	2c		,
	ld b,h			;b17b	44		D
	ld h,l			;b17c	65		e
	ld l,h			;b17d	6c		l
	inc l			;b17e	2c		,
	ld b,e			;b17f	43		C
	inc l			;b180	2c		,
	ld c,e			;b181	4b		K
	inc l			;b182	2c		,
	ld d,c			;b183	51		Q
	inc l			;b184	2c		,
	ld d,d			;b185	52		R
	inc l			;b186	2c		,
	ld b,d			;b187	42		B
	inc l			;b188	2c		,
	ld c,(hl)		;b189	4e		N
	inc l			;b18a	2c		,
	ld d,b			;b18b	50		P
	inc l			;b18c	2c		,
	ld e,b			;b18d	58		X
lb18eh:
	ccf			;b18e	3f		?
	jr nz,$+68		;b18f	20 42		  B
	ld l,a			;b191	6f		o
lb192h:
	ld h,c			;b192	61		a
	ld (hl),d		;b193	72		r
	ld h,h			;b194	64		d
	jr nz,lb206h		;b195	20 6f		  o
lb197h:
	ld (hl),d		;b197	72		r
	jr nz,$+117		;b198	20 73		  s
	ld (hl),l		;b19a	75		u
	ld (hl),d		;b19b	72		r
	ld (hl),d		;b19c	72		r
	ld l,a			;b19d	6f		o
	ld (hl),l		;b19e	75		u
	ld l,(hl)		;b19f	6e		n
	ld h,h			;b1a0	64		d
	ccf			;b1a1	3f		?
	jr nz,lb206h		;b1a2	20 62		  b
	jr nz,lb215h		;b1a4	20 6f		  o
	ld (hl),d		;b1a6	72		r
	jr nz,lb21ch		;b1a7	20 73		  s
	jr nz,lb1fbh		;b1a9	20 50		  P
lb1abh:
	ld h,c			;b1ab	61		a
	ld (hl),b		;b1ac	70		p
	ld h,l			;b1ad	65		e
lb1aeh:
	ld (hl),d		;b1ae	72		r
	jr nz,lb214h		;b1af	20 63		  c
	ld l,a			;b1b1	6f		o
	ld l,h			;b1b2	6c		l
	ld l,a			;b1b3	6f		o
	ld (hl),l		;b1b4	75		u
	ld (hl),d		;b1b5	72		r
	ccf			;b1b6	3f		?
	jr nz,$+50		;b1b7	20 30		  0
	dec l			;b1b9	2d		-
lb1bah:
	scf			;b1ba	37		7
	jr nz,lb206h		;b1bb	20 49		  I
	ld l,(hl)		;b1bd	6e		n
	ld l,e			;b1be	6b		k
	jr nz,lb224h		;b1bf	20 63		  c
	ld l,a			;b1c1	6f		o
	ld l,h			;b1c2	6c		l
	ld l,a			;b1c3	6f		o
	ld (hl),l		;b1c4	75		u
	ld (hl),d		;b1c5	72		r
	ccf			;b1c6	3f		?
	jr nz,lb1f9h		;b1c7	20 30		  0
	dec l			;b1c9	2d		-
lb1cah:
	scf			;b1ca	37		7
	jr nz,lb210h		;b1cb	20 43		  C
	ld l,a			;b1cd	6f		o
	ld l,h			;b1ce	6c		l
	ld l,a			;b1cf	6f		o
lb1d0h:
	ld (hl),l		;b1d0	75		u
	ld (hl),d		;b1d1	72		r
	jr nz,lb23ah		;b1d2	20 66		  f
	ld l,a			;b1d4	6f		o
	ld (hl),d		;b1d5	72		r
	jr nz,lb24fh		;b1d6	20 77		  w
	ld l,b			;b1d8	68		h
	ld l,c			;b1d9	69		i
	ld (hl),h		;b1da	74		t
	ld h,l			;b1db	65		e
	ccf			;b1dc	3f		?
lb1ddh:
	jr nz,lb213h		;b1dd	20 34		  4
lb1dfh:
	dec l			;b1df	2d		-
lb1e0h:
	scf			;b1e0	37		7
	jr nz,$+69		;b1e1	20 43		  C
	ld l,a			;b1e3	6f		o
	ld l,h			;b1e4	6c		l
lb1e5h:
	ld l,a			;b1e5	6f		o
	ld (hl),l		;b1e6	75		u
	ld (hl),d		;b1e7	72		r
	jr nz,lb250h		;b1e8	20 66		  f
	ld l,a			;b1ea	6f		o
	ld (hl),d		;b1eb	72		r
	jr nz,lb250h		;b1ec	20 62		  b
	ld l,h			;b1ee	6c		l
	ld h,c			;b1ef	61		a
	ld h,e			;b1f0	63		c
	ld l,e			;b1f1	6b		k
	ccf			;b1f2	3f		?
	jr nz,lb225h		;b1f3	20 30		  0
	dec l			;b1f5	2d		-
	inc sp			;b1f6	33		3
	jr nz,lb250h		;b1f7	20 57		  W
lb1f9h:
	ld l,b			;b1f9	68		h
	ld l,c			;b1fa	69		i
lb1fbh:
	ld (hl),h		;b1fb	74		t
	ld h,l			;b1fc	65		e
	jr nz,$+117		;b1fd	20 73		  s
	ld (hl),c		;b1ff	71		q
	ld (hl),l		;b200	75		u
	ld h,c			;b201	61		a
	ld (hl),d		;b202	72		r
	ld h,l			;b203	65		e
	jr nz,lb269h		;b204	20 63		  c
lb206h:
	ld l,a			;b206	6f		o
	ld l,h			;b207	6c		l
	ld l,a			;b208	6f		o
	ld (hl),l		;b209	75		u
	ld (hl),d		;b20a	72		r
	ccf			;b20b	3f		?
	jr nz,$+54		;b20c	20 34		  4
	dec l			;b20e	2d		-
	scf			;b20f	37		7
lb210h:
	jr nz,lb254h		;b210	20 42		  B
	ld l,h			;b212	6c		l
lb213h:
	ld h,c			;b213	61		a
lb214h:
	ld h,e			;b214	63		c
lb215h:
	ld l,e			;b215	6b		k
	jr nz,lb28bh		;b216	20 73		  s
	ld (hl),c		;b218	71		q
	ld (hl),l		;b219	75		u
	ld h,c			;b21a	61		a
	ld (hl),d		;b21b	72		r
lb21ch:
	ld h,l			;b21c	65		e
	jr nz,lb282h		;b21d	20 63		  c
	ld l,a			;b21f	6f		o
	ld l,h			;b220	6c		l
	ld l,a			;b221	6f		o
	ld (hl),l		;b222	75		u
	ld (hl),d		;b223	72		r
lb224h:
	ccf			;b224	3f		?
lb225h:
	jr nz,lb257h		;b225	20 30		  0
	dec l			;b227	2d		-
	inc sp			;b228	33		3
	jr nz,lb282h		;b229	20 57		  W
	ld l,b			;b22b	68		h
	ld l,c			;b22c	69		i
	ld (hl),h		;b22d	74		t
	ld h,l			;b22e	65		e
	jr nz,$+114		;b22f	20 70		  p
	ld l,c			;b231	69		i
	ld h,l			;b232	65		e
	ld h,e			;b233	63		c
	ld h,l			;b234	65		e
	jr nz,lb29ah		;b235	20 63		  c
	ld l,a			;b237	6f		o
	ld l,h			;b238	6c		l
	ld l,a			;b239	6f		o
lb23ah:
	ld (hl),l		;b23a	75		u
	ld (hl),d		;b23b	72		r
	ccf			;b23c	3f		?
	jr nz,lb273h		;b23d	20 34		  4
	dec l			;b23f	2d		-
	scf			;b240	37		7
	jr nz,lb285h		;b241	20 42		  B
	ld l,h			;b243	6c		l
	ld h,c			;b244	61		a
	ld h,e			;b245	63		c
	ld l,e			;b246	6b		k
	jr nz,lb2b9h		;b247	20 70		  p
	ld l,c			;b249	69		i
	ld h,l			;b24a	65		e
	ld h,e			;b24b	63		c
	ld h,l			;b24c	65		e
	jr nz,lb2b2h		;b24d	20 63		  c
lb24fh:
	ld l,a			;b24f	6f		o
lb250h:
	ld l,h			;b250	6c		l
	ld l,a			;b251	6f		o
	ld (hl),l		;b252	75		u
	ld (hl),d		;b253	72		r
lb254h:
	ccf			;b254	3f		?
	jr nz,lb287h		;b255	20 30		  0
lb257h:
	dec l			;b257	2d		-
	inc sp			;b258	33		3
	jr nz,lb2aah		;b259	20 4f		  O
	ld (hl),l		;b25b	75		u
	ld (hl),h		;b25c	74		t
	ld l,h			;b25d	6c		l
	ld l,c			;b25e	69		i
	ld l,(hl)		;b25f	6e		n
	ld h,l			;b260	65		e
	cpl			;b261	2f		/
	ld h,d			;b262	62		b
	ld l,h			;b263	6c		l
	ld l,a			;b264	6f		o
	ld h,e			;b265	63		c
	ld l,e			;b266	6b		k
	jr nz,$+105		;b267	20 67		  g
lb269h:
	ld (hl),d		;b269	72		r
	ld h,c			;b26a	61		a
	ld (hl),b		;b26b	70		p
	ld l,b			;b26c	68		h
	ld l,c			;b26d	69		i
	ld h,e			;b26e	63		c
	ld (hl),e		;b26f	73		s
	ccf			;b270	3f		?
	jr nz,$+113		;b271	20 6f		  o
lb273h:
	jr nz,$+113		;b273	20 6f		  o
	ld (hl),d		;b275	72		r
	jr nz,$+100		;b276	20 62		  b
	jr nz,$+82		;b278	20 50		  P
	ld a,b			;b27a	78		x
	ld d,b			;b27b	50		P
	ld h,l			;b27c	65		e
	ld (hl),b		;b27d	70		p
; "Invalid move"
lb27eh:
	ld c,c			;b27e	49		I
	ld l,(hl)		;b27f	6e		n
	halt			;b280	76		v
	ld h,c			;b281	61		a
lb282h:
	ld l,h			;b282	6c		l
	ld l,c			;b283	69		i
	ld h,h			;b284	64		d
lb285h:
	jr nz,$+111		;b285	20 6d		  m
lb287h:
	ld l,a			;b287	6f		o
	halt			;b288	76		v
	ld h,l			;b289	65		e
; "Stalemate"
lb28ah:
	ld d,e			;b28a	53		S
lb28bh:
	ld (hl),h		;b28b	74		t
	ld h,c			;b28c	61		a
	ld l,h			;b28d	6c		l
	ld h,l			;b28e	65		e
	ld l,l			;b28f	6d		m
	ld h,c			;b290	61		a
	ld (hl),h		;b291	74		t
	ld h,l			;b292	65		e
; "Promote to Q, R, B or K?"
lb293h:
	ld d,b			;b293	50		P
	ld (hl),d		;b294	72		r
	ld l,a			;b295	6f		o
	ld l,l			;b296	6d		m
	ld l,a			;b297	6f		o
	ld (hl),h		;b298	74		t
	ld h,l			;b299	65		e
lb29ah:
	jr nz,$+118		;b29a	20 74		  t
	ld l,a			;b29c	6f		o
	jr nz,$+83		;b29d	20 51		  Q
	inc l			;b29f	2c		,
	jr nz,$+84		;b2a0	20 52		  R
	inc l			;b2a2	2c		,
	jr nz,$+68		;b2a3	20 42		  B
	jr nz,$+113		;b2a5	20 6f		  o
	ld (hl),d		;b2a7	72		r
	jr nz,$+77		;b2a8	20 4b		  K
lb2aah:
	ccf			;b2aa	3f		?
	jr nz,$+78		;b2ab	20 4c		  L
	ld h,l			;b2ad	65		e
	halt			;b2ae	76		v
	ld h,l			;b2af	65		e
	ld l,h			;b2b0	6c		l
lb2b1h:
	ld c,l			;b2b1	4d		M
lb2b2h:
	ld l,a			;b2b2	6f		o
	halt			;b2b3	76		v
	ld h,l			;b2b4	65		e
; " Try   " (thinking indicator)
lb2b5h:
	jr nz,$+86		;b2b5	20 54		  T
	ld (hl),d		;b2b7	72		r
	ld a,c			;b2b8	79		y
lb2b9h:
	jr nz,lb2dbh		;b2b9	20 20		   
	jr nz,lb2ddh		;b2bb	20 20		   
	jr nz,lb2dfh		;b2bd	20 20		   
	jr nz,$+34		;b2bf	20 20
; 32 spaces (blank line for clearing status display)
lb2c1h:
	jr nz,$+34		;b2c1	20 20		   
	jr nz,$+34		;b2c3	20 20		   
	jr nz,$+34		;b2c5	20 20		   
	jr nz,$+34		;b2c7	20 20		   
	jr nz,$+34		;b2c9	20 20		   
	jr nz,$+34		;b2cb	20 20		   
	jr nz,$+34		;b2cd	20 20		   
	jr nz,$+34		;b2cf	20 20		   
	jr nz,$+34		;b2d1	20 20		   
	jr nz,$+34		;b2d3	20 20		   
	jr nz,$+34		;b2d5	20 20		   
	jr nz,$+34		;b2d7	20 20		   
	jr nz,$+34		;b2d9	20 20		   
lb2dbh:
	jr nz,$+34		;b2db	20 20		   
lb2ddh:
	jr nz,$+34		;b2dd	20 20		   
lb2dfh:
	jr nz,$+34		;b2df	20 20		   

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top