Prev: C37D Up: Map Next: C3E4
C388: Print Character
Looks the character up in the font and draws it at the screen address.
Input
A Character to print
HL Screen buffer address
PrintCharacter C388 PUSH AF Store that in the low byte and clear the high byte.
C389 PUSH BC
C38A PUSH DE
C38B PUSH HL
C38C LD L,A
C38D LD H,$00
C38F ADD HL,HL Multiply by 08 (each font character is 08 bytes of data).
C390 ADD HL,HL
C391 ADD HL,HL
C392 LD DE,$3C00 Point DE at CHARSET minus 0100 plus this character's offset.
C395 ADD HL,DE
C396 EX DE,HL
C397 POP HL Restore the screen address from the stack.
C398 PUSH HL Keep a copy of it.
C399 LD B,$08 Set a counter in B for 08 bytes of the font data.
PrintCharacter_0 C39B LD A,(DE) Read the next byte of this character's bitmap and keep the counters.
C39C PUSH BC
C39D PUSH AF
Does this character need shifting?
C39E DEC C See whether this character needs shifting.
C39F INC C
C3A0 LD B,$FF Go to PrintCharacter_Next if the count reaches zero.
C3A2 JR Z,PrintCharacter_Next
PrintCharacter_Loop C3A4 SRL A Jump back to PrintCharacter_Loop while the count is not finished.
C3A6 SRL B
C3A8 DEC C
C3A9 JR NZ,PrintCharacter_Loop
PrintCharacter_Next C3AB LD C,A Take the count.
C3AC LD A,B
C3AD CPL Invert the shifted mask so it covers the screen pixels to keep.
C3AE AND (HL) Keep the screen pixels outside the character.
C3AF OR C Add the pixels of the character.
C3B0 LD (HL),A Store it at the pointer.
C3B1 POP AF
C3B2 POP BC
Is the character byte-aligned?
C3B3 DEC C See whether the shift count is zero without changing it, so the character is byte-aligned.
C3B4 INC C
C3B5 JR Z,PrintCharacter_NextBitmapByte Go to PrintCharacter_NextBitmapByte when the shift count is zero, so the character is byte-aligned.
C3B7 PUSH BC Work out how many bit positions are left in this row.
C3B8 PUSH AF
C3B9 LD A,$08
C3BB SUB C
C3BC LD C,A
C3BD POP AF
C3BE LD B,$FF Start a mask of all ones, shifted with the character data.
PrintCharacter_CountFinished C3C0 SLA A Jump back to PrintCharacter_CountFinished while the count is not finished.
C3C2 SLA B
C3C4 DEC C
C3C5 JR NZ,PrintCharacter_CountFinished
C3C7 LD C,A Take the count.
C3C8 LD A,B
C3C9 CPL Invert the shifted mask so it covers the screen pixels to keep in the next cell.
C3CA INC HL Step to the next character.
C3CB AND (HL) Keep the screen pixels in that cell outside the character.
C3CC OR C Add the part of the character that spills into that cell.
C3CD LD (HL),A Store it at the pointer and step back one character.
C3CE DEC HL
C3CF POP BC
PrintCharacter_NextBitmapByte C3D0 INC DE Step to the next bitmap byte and the next pixel row.
C3D1 INC H
C3D2 DJNZ PrintCharacter_0 Draw the next pixel row and repeat from PrintCharacter_0 until the character is finished.
C3D4 POP HL Add 07 to the total.
C3D5 POP DE
C3D6 POP BC
C3D7 LD A,C
C3D8 ADD A,$07
C3DA CP $08 Jump ahead to PrintCharacter_1 if the total is below 08.
C3DC JR C,PrintCharacter_1
C3DE SUB $08 Drop 08 from the count.
C3E0 INC L
PrintCharacter_1 C3E1 LD C,A Store the result in the low byte of the count.
C3E2 POP AF Restore AF from the stack.
C3E3 RET Return.
View the equivalent code in;
Prev: C37D Up: Map Next: C3E4