Sherlock: annotated disassembly

Routines

Prev: BF59 Up: Map Next: BFD9
BF79: Print the clock: day, hour, minute, a or p
Builds 'Mon 08:02am' in BF6E from the day (9FE1), the hour (9FE0), the minute (9FDF) and the letter (9FE2), and prints it in the status bar (C1A8).
How it works:
1. Write the three-letter day name into the buffer at BF6E, choosing it from the table at BF59 by the day number (9FE1).
2. Write the hour (9FE0) and the minute (9FDF) as two digits each, found by repeated subtraction of ten (BFBB), with the space and colon already in the buffer.
3. Write the letter a or p (9FE2) and print the eleven characters, for example 'Mon 08:02am', in the status bar (C1A8).
Output
The clock printed in the status bar ($C1A8)
BF79 LD IX,$BF6E IX = the text buffer BF6E ('Mon 08:02am'; the space and colon are already in it)
BF7D LD A,($9FE1) Day number...
BF80 LD HL,$BF59 ...three letters per day from the table at BF59 (BFC6)
BF83 CALL $BFC6 ...as three letters
BF86 INC IX Step over the space
BF88 LD A,($9FE0) Read the hour, 1-12 (9FE0) into A - Hour: two digits (BFB0)
BF8B CALL $BFB0 Call BFB0 (inside "Print the clock: day, hour, minute, a or p")
BF8E INC IX Step over the colon
BF90 LD A,($9FDF) Read the minute (9FDF) into A - Minute: two digits
BF93 CALL $BFB0 Call BFB0 (inside "Print the clock: day, hour, minute, a or p")
BF96 LD A,($9FE2) Read 'a' or 'p' (9FE2) into A - The a or p
BF99 LD (IX+$00),A Store A in the first byte of the record at IX
BF9C LD HL,$BF6E Point HL at BF6E - Print the 11 characters in the status bar (C1A8)
BF9F LD B,$0B Load B with $0B
BFA1 JP $C1A8 Jump on to the routine "Print the clock line: B characters from HL at..." (C1A8)
BFA4 CALL $BFAA Two-digit writer: tens digit, then...
BFA7 LD A,L Copy L into A - ...the units as a digit
BFA8 ADD A,$30 Add $30 to A
BFAA LD (IX+$00),A Store A in the first byte of the record at IX - Store the character at IX and move on
BFAD INC IX Step IX on to the next byte
BFAF RET Return to the caller
BFB0 LD L,A Copy A into L - Split A by 10 into tens (A) and units (L) (BFBB)
BFB1 LD H,$00 Load H with $00
BFB3 LD DE,$000A Load DE with $000A
BFB6 CALL $BFBB Call BFBB (inside "Print the clock: day, hour, minute, a or p")
BFB9 JR $BFA4 Go back to BFA4
BFBB LD C,$2F Load C with $2F - Repeated subtraction: C counts from '0'
BFBD INC C Add one to C
BFBE AND A Clear the carry flag, so that the subtraction that follows is a plain one (a compare)
BFBF SBC HL,DE Subtract DE from HL (a compare: carry = HL was smaller, zero = equal)
BFC1 JR NC,$BFBD If it did not go below zero, go back to BFBD
BFC3 ADD HL,DE Add DE to HL
BFC4 LD A,C Copy C into A
BFC5 RET Return to the caller
BFC6 LD C,A Copy A into C - Copy three characters of day name number A (x3 into the table)
BFC7 ADD A,A Double A (shift it left one bit)
BFC8 ADD A,C Add C to A
BFC9 LD C,A Copy A into C
BFCA LD B,$00 Load B with $00
BFCC ADD HL,BC Add BC to HL
BFCD LD B,$03 Load B with $03
BFCF LD A,(HL) Read the byte HL points at into A
BFD0 LD (IX+$00),A Store A in the first byte of the record at IX
BFD3 INC IX Step IX on to the next byte
BFD5 INC HL Step HL on to the next byte
BFD6 DJNZ $BFCF Count B down and, while it is not zero, go back to BFCF
BFD8 RET Return to the caller
Prev: BF59 Up: Map Next: BFD9