Sherlock: annotated disassembly

Routines

Prev: AEEA Up: Map Next: AF38
AEF1: Merge parse node IX into node IY
ORs in IX's flag byte (bit 7 dropped) and takes its first byte; if IX has words at +4/+5 and IY's ten bytes from +$0E are empty (AF38), moves IY's six bytes from +8 up to +$12 and copies IX's words in (AF52, and AF56 for the +2 pair if IY has none).
How it works:
1. IY takes IX's verb: the low byte at +0 and the other flag bits from +1 (without bit 7).
2. If IX has no words at +4 and +5 there is nothing more to do.
3. If IY already has words at +14 to +23 stop. Otherwise move IY's first group up to the second group and copy IX's words from +4.
4. Copy IX's second word in as well if IY has none.
Input
IX The node to merge
IY The node to merge it into
Output
IY Updated
AEF1 EXX Swap BC, DE and HL with their shadow copies
AEF2 LD A,(IX+$01) Read byte +1 of the record at IX into A - Node IY takes IX's verb (+0, and +1 without bit 7 but keeping its own bits)
AEF5 AND $7F Keep only bits 0, 1, 2, 3, 4, 5, 6 of A (mask $7F)
AEF7 OR (IY+$01) Set in A the bits that are set in byte +1 of the record at IY
AEFA LD (IY+$01),A Store A in byte +1 of the record at IY
AEFD LD A,(IX+$00) Read the first byte of the record at IX into A
AF00 LD (IY+$00),A Store A in the first byte of the record at IY
AF03 EXX Swap BC, DE and HL with their shadow copies
AF04 LD A,(IX+$04) Read byte +4 of the record at IX into A - Nothing at IX's +4: done
AF07 OR (IX+$05) Set in A the bits that are set in byte +5 of the record at IX
AF0A RET Z If the result is zero, return
AF0B LD A,$0E Load A with $0E - IY's +14 to +23 not all empty (AF38): done
AF0D CALL $AF38 Call the routine "Z if the ten bytes at IY + A are all zero" (AF38)
AF10 RET NZ If the zero flag is clear, return
AF11 EXX Swap BC, DE and HL with their shadow copies - Otherwise IY's first group (+8) moves to its second (+18)...
AF12 PUSH IY Save IY on the stack
AF14 POP HL Restore HL from the stack
AF15 LD DE,$0012 Load DE with $0012, the amount that is added next
AF18 ADD HL,DE Add DE to HL
AF19 PUSH HL Save HL on the stack
AF1A LD DE,$FFF6 Load DE with $FFF6 (-10 as a signed offset), the amount that is added next
AF1D ADD HL,DE Add DE to HL
AF1E POP DE Restore DE from the stack
AF1F LD BC,$0006 Load BC with $0006
AF22 LDIR Copy BC bytes from where HL points to where DE points, counting up
AF24 LD DE,$0004 Load DE with $0004 - ...and IY takes IX's words from +4 to +13 (AF52)
This entry point is used by the routine at AD57.
AF27 CALL $AF52 Call AF52 (inside "Copy 6, 10 or 2 bytes from IX + DE to IY +...")
AF2A LD A,(IY+$02) Read byte +2 of the record at IY into A - and IX's +2 too if IY has none (AF56)
AF2D OR (IY+$03) Set in A the bits that are set in byte +3 of the record at IY
AF30 LD DE,$0002 Load DE with $0002
AF33 CALL Z,$AF56 If the result is zero, call AF56 (inside "Copy 6, 10 or 2 bytes from IX + DE to IY +...")
AF36 EXX Swap BC, DE and HL with their shadow copies
AF37 RET Return to the caller
Prev: AEEA Up: Map Next: AF38