| Routines

6791: Write a single character on a blackboard

Used by the routine at 6880. Returns with the zero flag set if the end of the message has been reached.
Input
H | Number of the character writing on the board (0xC8-0xCC, 0xCE)
6791 | CALL $66CE | A=ASCII code of the next character from the message being written
This entry point is used by the routine at 5E6F when ERIC's writing on a board.
6794 | LD C,A | C=ASCII code of the next character from the message being written
6795 | CALL $6755 | Collect information about the blackboard
6798 | LD A,C |
6799 | LD C,B | Point BC at the blackboard's buffer (7F54, 7F5A, 7F60, 7F66 or 7F6C)
679A | LD B,$7F
679C | AND A | Have we reached the end of the message?
679D | JR NZ,$67A3 | Jump if not
679F | DEC A | A=0xFF
67A0 | LD (BC),A | Set the first byte of the blackboard's buffer to 0xFF if the message is finished, or the the pixel column number for the next letter to be written otherwise
67A1 | INC A | Set the zero flag if the end of the message has been reached
67A2 | RET |
We haven't reached the end of the message yet. Examine the next character to be written.
67A3 | CP $02 | Character code 0x02 is newline
67A5 | JR NZ,$67AB | Jump unless we're starting a new line
67A7 | LD A,$40 | This is the pixel column number of the start of the bottom line of the blackboard
67A9 | JR $67A0 |
The next character to be written is printable (as opposed to newline).
67AB | PUSH HL | Save the character number (in H) for now
67AC | LD L,A | Place the ASCII code of the character to be written in L
67AD | LD H,$D7 | Now (HL)=bit width of this character
67AF | LD A,(BC) | A=current pixel column number on the blackboard
67B0 | AND $3F | Set the carry flag if there's not enough room on the current line to print the next character (plus one blank pixel column)
67B2 | ADD A,$C0
67B4 | SCF
67B5 | ADC A,(HL)
67B6 | LD A,(BC) | A=current pixel column number on the blackboard
67B7 | JR NC,$67BD | Jump if there's enough room on the current line for the character
67B9 | CPL | Otherwise move to the other line of the blackboard by setting the current pixel column number to 0 or 64 as appropriate
67BA | AND $40
67BC | LD (BC),A
67BD | RRCA | Divide the pixel column number by 8 to get the corresponding character square number (0-7); also keep bit 3 for now to check which line of the board we're on
67BE | RRCA
67BF | RRCA
67C0 | AND $0F
67C2 | CP $08 | Are we on the top line of the board?
67C4 | JR C,$67C9 | Jump if so (A=0-7)
67C6 | INC D | D=4 or 9 (y-coordinate of the bottom line of the board)
67C7 | AND $07 | A=0-7
67C9 | ADD A,E | E=x-coordinate of the blackboard tile on which the next character will be written
67CA | LD E,A
67CB | CALL $670C | Update the SRB for this blackboard
67CE | LD A,(BC) | A=current pixel column number on the blackboard
67CF | AND $07 | Modify the RES n,(HL) instruction at 67F1 below to reset the appropriate bit for the current pixel column
67D1 | ADD A,A
67D2 | ADD A,A
67D3 | ADD A,A
67D4 | CPL
67D5 | SUB $41
67D7 | LD ($67F2),A
67DA | LD A,(BC) | A=current pixel column number on the blackboard
67DB | ADD A,(HL) | Add the bit-width of character to be written
67DC | INC A | Add 1 to make a blank vertical pixel line after the character to be written
67DD | LD (BC),A | Set the pixel column number for the next character to be written
67DE | LD C,(HL) | C=bit-width of the character to be written
67DF | EX DE,HL | Now DE points at the bitmap data for the character to be written on the board, and HL holds the coordinates of the blackboard tile on which the character will be written
67E0 | LD A,H | A=blackboard tile y-coordinate
67E1 | LD H,$B5 | Pick up the Q value (0x00<=Q<=0x8F) for the blackboard tile from page 0xB5 in L (see 606C)
67E3 | LD L,(HL)
67E4 | ADD A,$A0 | Collect the LSB of the base address of the skool UDG for the blackboard tile in L
67E6 | LD H,A
67E7 | LD L,(HL)
67E8 | LD H,$80 | The base page for all blackboard tile UDGs is 0x80
67EA | INC D | Point DE at the next pixel column of bitmap data for the character to be written
67EB | LD A,(DE) | Pick this up in A
67EC | LD B,$08 | 8 horizontal pixel lines in each character square
67EE | RLCA | Should a bit of chalk appear here?
67EF | JR NC,$67F3 | Jump if not
67F1 | RES 7,(HL) | Reset the appropriate bit in the skool UDG for the blackboard tile, thus making a bit of chalk appear; this instruction is modified by this routine to reset the required bit
67F3 | INC H | Next row of the blackboard tile UDG
67F4 | DJNZ $67EE | Jump back until all 8 rows are done
67F6 | LD A,($67F2) | Change the RES n,(HL) instruction at 67F1 above to RES n-1,(HL) if n>0, or RES 7,(HL) if n=0
67F9 | OR $40
67FB | SUB $08
67FD | AND $BF
67FF | LD ($67F2),A
6802 | CP $BE | Did we just draw the rightmost vertical pixel line in the current blackboard tile?
6804 | JR NZ,$6807 | Jump if so
6806 | INC L | Set L to the LSB of the base address of the skool UDG for the next blackboard tile to the right
6807 | DEC C | Next pixel column of the character bitmap
6808 | JR NZ,$67E8 | Jump back to do the remaining pixel columns
680A | INC C | Reset the zero flag (the message is not finished yet)
680B | POP HL | Restore the character number to H
680C | RET |