Sherlock: annotated disassembly

Routines

Prev: F50D Up: Map Next: F54A
F514: Move attribute address HL up a row (not past the top)
F525 down, F536 left, F540 right: the four moves of a colour run (bit 5 commands in F3C2).
How it works:
1. Each of the four entry points moves HL, the address of an attribute byte, one cell: F514 up a row, F525 down a row, F536 left and F540 right.
2. A row is 32 bytes. After the move the high byte is checked against the edges of the attribute area ($5800 to $59FF): if the move left it, it is undone, so the address never leaves the screen.
Input
HL An attribute address
Output
HL The address one cell on, or unchanged at the edge
AF is preserved
F514 PUSH AF Save AF on the stack - HL 32 bytes back, unless that leaves the attribute area
F515 PUSH DE Save DE on the stack
F516 LD DE,$0020 Load DE with $0020
F519 AND A Clear the carry flag, so that the subtraction that follows is a plain one (a compare)
F51A SBC HL,DE Subtract DE from HL (a compare: carry = HL was smaller, zero = equal)
F51C LD A,H Copy H into A
F51D CP $57 Compare A with $57
F51F JR NZ,$F522 If A differs from $57, skip ahead to F522
F521 ADD HL,DE Add DE to HL
F522 POP DE Restore DE from the stack
F523 POP AF Restore AF from the stack
F524 RET Return to the caller
This entry point is used by the routine at F3C2.
F525 PUSH AF Save AF on the stack - HL 32 bytes on, unless that leaves the attribute area
F526 PUSH DE Save DE on the stack
F527 LD DE,$0020 Load DE with $0020, the amount that is added next
F52A ADD HL,DE Add DE to HL
F52B LD A,H Copy H into A
F52C CP $5A Compare A with $5A
F52E JR NZ,$F532 If A differs from $5A, skip ahead to $F532
F530 AND A Clear the carry flag, so that the subtraction that follows is a plain one (a compare)
F531 SBC HL,DE Subtract DE from HL (a compare: carry = HL was smaller, zero = equal)
F533 POP DE Restore DE from the stack
F534 POP AF Restore AF from the stack
F535 RET Return to the caller
This entry point is used by the routine at F3C2.
F536 PUSH AF Save AF on the stack - HL one byte back, unless that leaves the attribute area
F537 DEC HL Step HL back one byte
F538 LD A,H Copy H into A
F539 CP $57 Compare A with $57
F53B JR NZ,$F53E If A differs from $57, skip ahead to F53E
F53D INC HL Step HL on to the next byte
F53E POP AF Restore AF from the stack
F53F RET Return to the caller
This entry point is used by the routine at F3C2.
F540 PUSH AF Save AF on the stack - HL one byte on, unless that leaves the attribute area
F541 INC HL Step HL on to the next byte
F542 LD A,H Copy H into A
F543 CP $5A Compare A with $5A
F545 JR NZ,$F548 If A differs from $5A, skip ahead to F548
F547 DEC HL Step HL back one byte
F548 POP AF Restore AF from the stack
F549 RET Return to the caller
Prev: F50D Up: Map Next: F54A