← 9837 Fill the attribute file with the color in A Map 987B → Print a font string at double height
9844: Print a font string to the screen
Prints a string from the game font into consecutive screen cells.
Input
HL screen address of the first character cell
DE pointer to the string (bit 7 set marks the final character)
C the attribute written to every cell
print_string 9844 PUSH BC Save the caller's attribute (C) and screen address.
9845 PUSH HL
9846 EXX Work in the alternate registers to build the attribute address.
9847 POP HL
9848 LD A,H The screen third comes from bits 3–4 of the high byte.
9849 AND $18
984B RRCA Shift it down to bits 0–1.
984C RRCA
984D RRCA
984E ADD A,$58 The addition of the attribute-file high byte leaves HL' on the cell's attribute.
9850 LD H,A
9851 POP BC
9852 EXX Back to the main registers, with HL on the screen cell and the attribute in C.
print_string_0 9853 PUSH DE Per character: save the string pointer and screen address.
9854 PUSH HL
9855 LD A,(DE) Read the character and strip its terminator.
9856 RES 7,A
9858 LD L,A
9859 LD H,$00 Point DE at the character's glyph in the font, 8 bytes per glyph.
985B ADD HL,HL
985C ADD HL,HL
985D ADD HL,HL
985E LD DE,FONT_BASE
9861 ADD HL,DE
9862 EX DE,HL
9863 POP HL Recover the screen cell and count off the glyph's rows.
9864 LD B,$08
9866 PUSH HL
print_string_1 9867 LD A,(DE) Copy the glyph into the cell, one pixel row at a time.
9868 LD (HL),A
9869 INC H
986A INC DE
986B DJNZ print_string_1
986D EXX Write attribute C into this cell and advance the attribute pointer.
986E LD (HL),C
986F INC HL
9870 EXX
9871 POP HL
9872 INC HL Advance to the next character cell.
9873 POP DE
9874 LD A,(DE) Was that the last character (bit 7 set)? If so, return.
9875 BIT 7,A
9877 RET NZ
9878 INC DE
9879 JR print_string_0 Otherwise loop for the next character.
← 9837 Fill the attribute file with the color in A Map 987B → Print a font string at double height
Fork me on GitHub