| The Hobbit (v1.0) | Routines |
| Prev: 775E | Up: Map | Next: 7815 |
|
Draws one 8x8 character from the font at 7815. The glyph address is 7715 + 8 x character code (the font only defines codes $20 to $7F, so the table effectively starts at 7815).
Characters are drawn on a 6-pixel pitch rather than the Spectrum's usual 8, which is why The Hobbit fits more text on a line than most Spectrum games. C holds the pixel offset within the current screen byte, so each glyph row is shifted right by C bits and may straddle two screen bytes: the first part is masked into (HL) and the overflow is shifted left and masked into (HL+1). After drawing, C is advanced by 6 and, if it passes 8, L moves on to the next byte.
|
||||||||||||
| 77BC | PUSH AF | Save the registers this uses | ||||||||||
| 77BD | PUSH BC | |||||||||||
| 77BE | PUSH DE | |||||||||||
| 77BF | PUSH HL | |||||||||||
| 77C0 | LD L,A | HL = the character code... | ||||||||||
| 77C1 | LD H,$00 | |||||||||||
| 77C3 | ADD HL,HL | ...times 8, since each glyph is 8 bytes... | ||||||||||
| 77C4 | ADD HL,HL | |||||||||||
| 77C5 | ADD HL,HL | |||||||||||
| 77C6 | LD DE,$7715 | ...added to the start of the game's own font | ||||||||||
| 77C9 | ADD HL,DE | |||||||||||
| 77CA | EX DE,HL | DE = the glyph's own bitmap | ||||||||||
| 77CB | POP HL | HL = where to draw it (put back for a moment) | ||||||||||
| 77CC | PUSH HL | |||||||||||
| 77CD | LD B,$08 | Eight pixel rows to draw | ||||||||||
| 77CF | LD A,(DE) | A = this row of the glyph | ||||||||||
| 77D0 | PUSH BC | |||||||||||
| 77D1 | DEC C | Is the pixel offset C exactly 0 (no shifting needed)? | ||||||||||
| 77D2 | INC C | |||||||||||
| 77D3 | LD B,$FF | B will become a mask of which bits belong to this glyph | ||||||||||
| 77D5 | JR Z,$77DE | No shift needed: skip the loop below | ||||||||||
| 77D7 | SRL A | Shift the glyph right by C bits... | ||||||||||
| 77D9 | SRL B | ...building the matching mask alongside it | ||||||||||
| 77DB | DEC C | |||||||||||
| 77DC | JR NZ,$77D7 | |||||||||||
| 77DE | LD C,A | C = the (possibly shifted) glyph bits for this screen byte | ||||||||||
| 77DF | LD A,B | Combine them into the screen, keeping whatever was already there outside the mask | ||||||||||
| 77E0 | CPL | |||||||||||
| 77E1 | AND (HL) | |||||||||||
| 77E2 | OR C | |||||||||||
| 77E3 | LD (HL),A | |||||||||||
| 77E4 | POP BC | Restore the pixel offset | ||||||||||
| 77E5 | DEC C | Does the glyph spill over into the NEXT screen byte too? | ||||||||||
| 77E6 | INC C | |||||||||||
| 77E7 | JR Z,$7801 | No: nothing more to do for this row | ||||||||||
| 77E9 | PUSH BC | Yes: work out the overflow into that next byte | ||||||||||
| 77EA | LD A,$08 | |||||||||||
| 77EC | SUB C | |||||||||||
| 77ED | LD C,A | |||||||||||
| 77EE | LD A,(DE) | A = the same glyph row again | ||||||||||
| 77EF | LD B,$FF | |||||||||||
| 77F1 | SLA A | This time shift it LEFT, to land the spilt-over bits at the start of the next byte... | ||||||||||
| 77F3 | SLA B | |||||||||||
| 77F5 | DEC C | |||||||||||
| 77F6 | JR NZ,$77F1 | |||||||||||
| 77F8 | LD C,A | C = those overflow bits | ||||||||||
| 77F9 | LD A,B | Combine them into the next screen byte, again keeping what was already there | ||||||||||
| 77FA | CPL | |||||||||||
| 77FB | INC HL | |||||||||||
| 77FC | AND (HL) | |||||||||||
| 77FD | OR C | |||||||||||
| 77FE | LD (HL),A | |||||||||||
| 77FF | DEC HL | Back to the first byte, ready for the next pixel row | ||||||||||
| 7800 | POP BC | |||||||||||
| 7801 | INC DE | Move on to the next row of the glyph... | ||||||||||
| 7802 | INC H | ...and the next pixel line on screen (the odd layout means +$100) | ||||||||||
| 7803 | DJNZ $77CF | |||||||||||
| 7805 | POP HL | Restore the saved registers | ||||||||||
| 7806 | POP DE | |||||||||||
| 7807 | POP BC | |||||||||||
| 7808 | LD A,C | Move the pixel offset on by 6, the width of a character... | ||||||||||
| 7809 | ADD A,$06 | |||||||||||
| 780B | CP $08 | Did that cross into the next screen byte? | ||||||||||
| 780D | JR C,$7812 | |||||||||||
| 780F | SUB $08 | If so, wrap the offset round... | ||||||||||
| 7811 | INC L | ...and step on to that byte | ||||||||||
| 7812 | LD C,A | Save the new pixel offset | ||||||||||
| 7813 | POP AF | Restore AF | ||||||||||
| 7814 | RET | |||||||||||
| Prev: 775E | Up: Map | Next: 7815 |