Sherlock: annotated disassembly

Routines

Prev: BF79 Up: Map Next: C00C
BFD9: Advance the clock by one minute
Counts the minutes since the start (9FDD), then the minute (9FDF); at 60 the hour (9FE0) moves on, 12 wrapping to 1; at 12 the 'a'/'p' letter (9FE2) flips (XOR $11 turns $61 into $70 and back), and when it becomes 'a' the day (9FE1) moves on.
How it works:
1. Count the minute since the start (9FDD) and add one to the minute (9FDF).
2. At 60, the minute becomes 0 and the hour (9FE0) goes up; 13 becomes 1.
3. When the hour reaches 12, am and pm swap; going to am starts the next day (9FE1).
Output
The minute counter, the minute, hour, am/pm and day moved on by one minute
BFD9 LD HL,($9FDD) Read minutes since the start (9FDD) into HL
BFDC INC HL Step HL on to the next byte
BFDD LD ($9FDD),HL Store HL in minutes since the start (9FDD)
BFE0 LD HL,$9FDF Point HL at the minute (9FDF)
BFE3 INC (HL) Add one to the byte at the minute (9FDF)
BFE4 LD A,(HL) Read the byte at the minute (9FDF) into A
BFE5 CP $3C Compare A with $3C - ...reached 60?
BFE7 RET NZ If A differs from $3C, return
BFE8 LD (HL),$00 Yes: back to 0
BFEA LD HL,$9FE0 Point HL at the hour, 1-12 (9FE0)
BFED INC (HL) Add one to the byte at the hour, 1-12 (9FE0)
BFEE LD A,(HL) Read the byte at the hour, 1-12 (9FE0) into A
BFEF CP $0D Compare A with $0D - ...13 becomes 1
BFF1 JR NZ,$BFF6 If A differs from $0D, skip ahead to BFF6
BFF3 LD (HL),$01 Store $01 at the address HL points to
BFF5 RET Return to the caller
BFF6 CP $0C Compare A with $0C - Reached 12?
BFF8 RET NZ If A differs from $0C, return
BFF9 LD A,($9FE2) Read 'a' or 'p' (9FE2) into A - Then 'a' and 'p' swap
BFFC XOR $11 Flip in A the bits that are set in $11
BFFE LD ($9FE2),A Store A in 'a' or 'p' (9FE2)
C001 CP $61 Compare A with $61 - Now 'a'?
C003 RET NZ If A differs from $61, return
C004 LD A,($9FE1) Read the day (9FE1) into A - Then it is the next day
C007 INC A Add one to A
C008 LD ($9FE1),A Store A in the day (9FE1)
C00B RET Return to the caller
Prev: BF79 Up: Map Next: C00C