Prev: 50045 Up: Map Next: 50148
50056: 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 50056 PUSH AF Store that in the low byte and clear the high byte.
50057 PUSH BC
50058 PUSH DE
50059 PUSH HL
50060 LD L,A
50061 LD H,0
50063 ADD HL,HL Multiply by 8 (each font character is 8 bytes of data).
50064 ADD HL,HL
50065 ADD HL,HL
50066 LD DE,15360 Point DE at CHARSET minus 256 plus this character's offset.
50069 ADD HL,DE
50070 EX DE,HL
50071 POP HL Restore the screen address from the stack.
50072 PUSH HL Keep a copy of it.
50073 LD B,8 Set a counter in B for 8 bytes of the font data.
PrintCharacter_0 50075 LD A,(DE) Read the next byte of this character's bitmap and keep the counters.
50076 PUSH BC
50077 PUSH AF
Does this character need shifting?
50078 DEC C See whether this character needs shifting.
50079 INC C
50080 LD B,255 Go to PrintCharacter_Next if the count reaches zero.
50082 JR Z,PrintCharacter_Next
PrintCharacter_Loop 50084 SRL A Jump back to PrintCharacter_Loop while the count is not finished.
50086 SRL B
50088 DEC C
50089 JR NZ,PrintCharacter_Loop
PrintCharacter_Next 50091 LD C,A Take the count.
50092 LD A,B
50093 CPL Invert the shifted mask so it covers the screen pixels to keep.
50094 AND (HL) Keep the screen pixels outside the character.
50095 OR C Add the pixels of the character.
50096 LD (HL),A Store it at the pointer.
50097 POP AF
50098 POP BC
Is the character byte-aligned?
50099 DEC C See whether the shift count is zero without changing it, so the character is byte-aligned.
50100 INC C
50101 JR Z,PrintCharacter_NextBitmapByte Go to PrintCharacter_NextBitmapByte when the shift count is zero, so the character is byte-aligned.
50103 PUSH BC Work out how many bit positions are left in this row.
50104 PUSH AF
50105 LD A,8
50107 SUB C
50108 LD C,A
50109 POP AF
50110 LD B,255 Start a mask of all ones, shifted with the character data.
PrintCharacter_CountFinished 50112 SLA A Jump back to PrintCharacter_CountFinished while the count is not finished.
50114 SLA B
50116 DEC C
50117 JR NZ,PrintCharacter_CountFinished
50119 LD C,A Take the count.
50120 LD A,B
50121 CPL Invert the shifted mask so it covers the screen pixels to keep in the next cell.
50122 INC HL Step to the next character.
50123 AND (HL) Keep the screen pixels in that cell outside the character.
50124 OR C Add the part of the character that spills into that cell.
50125 LD (HL),A Store it at the pointer and step back one character.
50126 DEC HL
50127 POP BC
PrintCharacter_NextBitmapByte 50128 INC DE Step to the next bitmap byte and the next pixel row.
50129 INC H
50130 DJNZ PrintCharacter_0 Draw the next pixel row and repeat from PrintCharacter_0 until the character is finished.
50132 POP HL Add 7 to the total.
50133 POP DE
50134 POP BC
50135 LD A,C
50136 ADD A,7
50138 CP 8 Jump ahead to PrintCharacter_1 if the total is below 8.
50140 JR C,PrintCharacter_1
50142 SUB 8 Drop 8 from the count.
50144 INC L
PrintCharacter_1 50145 LD C,A Store the result in the low byte of the count.
50146 POP AF Restore AF from the stack.
50147 RET Return.
View the equivalent code in;
Prev: 50045 Up: Map Next: 50148