| Routines

26513: Write a single character on a blackboard

Used by the routine at 26752. 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 (200-204, 206)
26513 | CALL 26318 | A=ASCII code of the next character from the message being written
This entry point is used by the routine at 24175 when ERIC's writing on a board.
26516 | LD C,A | C=ASCII code of the next character from the message being written
26517 | CALL 26453 | Collect information about the blackboard
26520 | LD A,C |
26521 | LD C,B | Point BC at the blackboard's buffer (32596, 32602, 32608, 32614 or 32620)
26522 | LD B,127
26524 | AND A | Have we reached the end of the message?
26525 | JR NZ,26531 | Jump if not
26527 | DEC A | A=255
26528 | LD (BC),A | Set the first byte of the blackboard's buffer to 255 if the message is finished, or the the pixel column number for the next letter to be written otherwise
26529 | INC A | Set the zero flag if the end of the message has been reached
26530 | RET |
We haven't reached the end of the message yet. Examine the next character to be written.
26531 | CP 2 | Character code 2 is newline
26533 | JR NZ,26539 | Jump unless we're starting a new line
26535 | LD A,64 | This is the pixel column number of the start of the bottom line of the blackboard
26537 | JR 26528 |
The next character to be written is printable (as opposed to newline).
26539 | PUSH HL | Save the character number (in H) for now
26540 | LD L,A | Place the ASCII code of the character to be written in L
26541 | LD H,215 | Now (HL)=bit width of this character
26543 | LD A,(BC) | A=current pixel column number on the blackboard
26544 | AND 63 | Set the carry flag if there's not enough room on the current line to print the next character (plus one blank pixel column)
26546 | ADD A,192
26548 | SCF
26549 | ADC A,(HL)
26550 | LD A,(BC) | A=current pixel column number on the blackboard
26551 | JR NC,26557 | Jump if there's enough room on the current line for the character
26553 | CPL | Otherwise move to the other line of the blackboard by setting the current pixel column number to 0 or 64 as appropriate
26554 | AND 64
26556 | LD (BC),A
26557 | 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
26558 | RRCA
26559 | RRCA
26560 | AND 15
26562 | CP 8 | Are we on the top line of the board?
26564 | JR C,26569 | Jump if so (A=0-7)
26566 | INC D | D=4 or 9 (y-coordinate of the bottom line of the board)
26567 | AND 7 | A=0-7
26569 | ADD A,E | E=x-coordinate of the blackboard tile on which the next character will be written
26570 | LD E,A
26571 | CALL 26380 | Update the SRB for this blackboard
26574 | LD A,(BC) | A=current pixel column number on the blackboard
26575 | AND 7 | Modify the RES n,(HL) instruction at 26609 below to reset the appropriate bit for the current pixel column
26577 | ADD A,A
26578 | ADD A,A
26579 | ADD A,A
26580 | CPL
26581 | SUB 65
26583 | LD (26610),A
26586 | LD A,(BC) | A=current pixel column number on the blackboard
26587 | ADD A,(HL) | Add the bit-width of character to be written
26588 | INC A | Add 1 to make a blank vertical pixel line after the character to be written
26589 | LD (BC),A | Set the pixel column number for the next character to be written
26590 | LD C,(HL) | C=bit-width of the character to be written
26591 | 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
26592 | LD A,H | A=blackboard tile y-coordinate
26593 | LD H,181 | Pick up the Q value (0<=Q<=143) for the blackboard tile from page 181 in L (see 24684)
26595 | LD L,(HL)
26596 | ADD A,160 | Collect the LSB of the base address of the skool UDG for the blackboard tile in L
26598 | LD H,A
26599 | LD L,(HL)
26600 | LD H,128 | The base page for all blackboard tile UDGs is 128
26602 | INC D | Point DE at the next pixel column of bitmap data for the character to be written
26603 | LD A,(DE) | Pick this up in A
26604 | LD B,8 | 8 horizontal pixel lines in each character square
26606 | RLCA | Should a bit of chalk appear here?
26607 | JR NC,26611 | Jump if not
26609 | 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
26611 | INC H | Next row of the blackboard tile UDG
26612 | DJNZ 26606 | Jump back until all 8 rows are done
26614 | LD A,(26610) | Change the RES n,(HL) instruction at 26609 above to RES n-1,(HL) if n>0, or RES 7,(HL) if n=0
26617 | OR 64
26619 | SUB 8
26621 | AND 191
26623 | LD (26610),A
26626 | CP 190 | Did we just draw the rightmost vertical pixel line in the current blackboard tile?
26628 | JR NZ,26631 | Jump if so
26630 | INC L | Set L to the LSB of the base address of the skool UDG for the next blackboard tile to the right
26631 | DEC C | Next pixel column of the character bitmap
26632 | JR NZ,26600 | Jump back to do the remaining pixel columns
26634 | INC C | Reset the zero flag (the message is not finished yet)
26635 | POP HL | Restore the character number to H
26636 | RET |