Sherlock: annotated disassembly

Routines

Prev: F3A2 Up: Map Next: F48E
F3C2: Draw a picture (the picture interpreter)
HL = the picture's bytecode (from the table at F60C via A277). The pen starts at (127, 63).
How it works:
1. The pen starts at (127, 63). Take the next command; 0 ends the picture.
2. $08 moves the pen to the (x, y) in the next two bytes (x always has bit 7 set, so the pen stays in the right half of the screen).
3. A command with bit 7 set draws a line (F56E): its low three bits give the direction, and the rest the number of steps and run lengths.
4. Other commands set the colour, fill an area (F490) or draw other shapes; each is followed by its operands.
Input
HL The picture's bytecode
Output
The picture drawn; registers kept
F3C2 PUSH IY Save IY on the stack
F3C4 PUSH HL Save HL on the stack
F3C5 PUSH HL Save HL on the stack - IY = the bytecode
F3C6 POP IY Restore IY from the stack
F3C8 PUSH DE Save DE on the stack
F3C9 PUSH BC Save BC on the stack
F3CA LD D,$7F Load D with $7F - The pen starts at (127, 63)
F3CC LD E,$3F Load E with $3F
F3CE LD B,$01 Load B with $01
F3D0 LD C,$01 Load C with $01
F3D2 LD L,$01 Load L with $01
F3D4 LD A,(IY+$00) Read the first byte of the record at IY into A - Next command; 0 ends the picture
F3D7 AND A Test A for zero (this leaves A as it was and clears carry)
F3D8 JP Z,$F488 If A is zero, jump on to F488
F3DB INC IY Step IY on to the next byte
F3DD CP $08 Compare A with $08 - $08: move the pen to (x, y) from the next two bytes
F3DF JR NZ,$F3EF If A differs from $08, skip ahead to F3EF
F3E1 LD D,(IY+$00) Read the first byte of the record at IY into D
F3E4 SET 7,D Set bit 7 of D - x always has bit 7 set: the pen stays in the right half of the screen
F3E6 INC IY Step IY on to the next byte
F3E8 LD E,(IY+$00) Read the first byte of the record at IY into E
F3EB INC IY Step IY on to the next byte
F3ED JR $F3D4 Go back to F3D4
F3EF BIT 7,A Test bit 7 of A - Bit 7: a line
F3F1 JR Z,$F414 If bit 7 of A is clear, skip ahead to F414
F3F3 LD B,A Copy A into B - C = bits 2-0: which way it goes
F3F4 AND $07 Keep only bits 0, 1, 2 of A (mask $07)
F3F6 LD C,A Copy A into C
F3F7 LD A,B Copy B into A - B = bits 6-3 of this byte and bits 7-6 of the next: one length, plus 1
F3F8 RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
F3F9 AND $3C Keep only bits 2, 3, 4, 5 of A (mask $3C)
F3FB LD B,A Copy A into B
F3FC LD A,(IY+$00) Read the first byte of the record at IY into A - L = bits 5-0 of the next byte: the other length, plus 1
F3FF AND $3F Keep only bits 0, 1, 2, 3, 4, 5 of A (mask $3F)
F401 LD L,A Copy A into L
F402 INC L Add one to L
F403 LD A,(IY+$00) Read the first byte of the record at IY into A
F406 INC IY Step IY on to the next byte
F408 RLCA Rotate A left one place (bit 7 goes to carry and bit 0)
F409 RLCA Rotate A left one place (bit 7 goes to carry and bit 0)
F40A AND $03 Keep only bits 0, 1 of A (mask $03)
F40C OR B Set in A the bits that are set in B
F40D LD B,A Copy A into B
F40E INC B Add one to B
F40F CALL $F56E Call the routine "Draw a line from the pen" (F56E) - Draw it (F56E)
F412 JR $F3D4 Go back to F3D4
F414 BIT 6,A Test bit 6 of A - Bit 6: fill in colour bits 2-0 from the point in the next two bytes (F490)
F416 JR Z,$F42E If bit 6 of A is clear, skip ahead to F42E
F418 AND $07 Keep only bits 0, 1, 2 of A (mask $07)
F41A PUSH DE Save DE on the stack
F41B LD D,(IY+$00) Read the first byte of the record at IY into D
F41E SET 7,D Set bit 7 of D
F420 INC IY Step IY on to the next byte
F422 LD E,(IY+$00) Read the first byte of the record at IY into E
F425 INC IY Step IY on to the next byte
F427 CALL $F490 Call the routine "Fill the area around the pen in colour A" (F490)
F42A POP DE Restore DE from the stack
F42B JP $F3D4 Go back to F3D4
F42E BIT 5,A Test bit 5 of A - Bit 5: runs of attribute cells in paper colour bits 2-0 (any other byte is ignored)
F430 JP Z,$F3D4 If bit 5 of A is clear, go back to F3D4
F433 AND $07 Keep only bits 0, 1, 2 of A (mask $07)
F435 RLCA Rotate A left one place (bit 7 goes to carry and bit 0)
F436 RLCA Rotate A left one place (bit 7 goes to carry and bit 0)
F437 RLCA Rotate A left one place (bit 7 goes to carry and bit 0)
F438 PUSH HL Save HL on the stack
F439 PUSH DE Save DE on the stack
F43A PUSH BC Save BC on the stack
F43B LD C,A Copy A into C
F43C LD H,(IY+$00) Read the first byte of the record at IY into H - HL = the attribute address: high byte, then low byte + $10
F43F INC IY Step IY on to the next byte
F441 LD A,(IY+$00) Read the first byte of the record at IY into A
F444 ADD A,$10 Add $10 to A
F446 LD L,A Copy A into L
F447 INC IY Step IY on to the next byte
F449 LD A,(IY+$00) Read the first byte of the record at IY into A - Next run; $FF ends them
F44C INC IY Step IY on to the next byte
F44E CP $FF Compare A with $FF
F450 JR Z,$F482 If A equals $FF, jump on to F482
F452 LD B,A Copy A into B - E = bits 1-0: the direction (0 up, 1 right, 2 down, 3 left)
F453 AND $03 Keep only bits 0, 1 of A (mask $03)
F455 LD E,A Copy A into E
F456 LD A,B Copy B into A - B = bits 7-2, plus 1: how many cells
F457 RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
F458 RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
F459 AND $3F Keep only bits 0, 1, 2, 3, 4, 5 of A (mask $3F)
F45B INC A Add one to A
F45C LD B,A Copy A into B
F45D LD A,(HL) Read the byte HL points at into A - Give the cell the new paper; if its ink is that colour too, flip the ink
F45E AND $07 Keep only bits 0, 1, 2 of A (mask $07)
F460 RLCA Rotate A left one place (bit 7 goes to carry and bit 0)
F461 RLCA Rotate A left one place (bit 7 goes to carry and bit 0)
F462 RLCA Rotate A left one place (bit 7 goes to carry and bit 0)
F463 CP C Compare A with C
F464 JR NZ,$F468 If A differs from C, skip ahead to F468
F466 XOR $38 Flip in A the bits that are set in $38
F468 RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
F469 RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
F46A RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
F46B OR C Set in A the bits that are set in C
F46C LD (HL),A Store A at the address HL points to
F46D LD A,E Copy E into A - Step to the next cell: up (F514), right (F540), down (F525) or left (F536)
F46E AND A Test A for zero (this leaves A as it was and clears carry)
F46F CALL Z,$F514 If A is zero, call the routine "Move attribute address HL up a row (not past the top)" (F514)
F472 DEC A Subtract one from A
F473 CALL Z,$F540 If A has become zero, call F540 (inside "Move attribute address HL up a row (not...")
F476 DEC A Subtract one from A
F477 CALL Z,$F525 If A has become zero, call F525 (inside "Move attribute address HL up a row (not...")
F47A DEC A Subtract one from A
F47B CALL Z,$F536 If A has become zero, call F536 (inside "Move attribute address HL up a row (not...")
F47E DJNZ $F45D Count B down and, while it is not zero, go back to F45D
F480 JR $F449 Go back to F449
F482 POP BC Restore BC from the stack
F483 POP DE Restore DE from the stack
F484 POP HL Restore HL from the stack
F485 JP $F3D4 Go back to F3D4
F488 POP BC Restore BC from the stack - End of the picture
F489 POP DE Restore DE from the stack
F48A POP HL Restore HL from the stack
F48B POP IY Restore IY from the stack
F48D RET Return to the caller
Prev: F3A2 Up: Map Next: F48E