; Pokemon Mini text engine by Alessandro Lo-Presti (Agilo). ; Write text on the screen using the charmap. .macro writestr a_string ; Jump over the following bytes so as to avoid them from being interpreted. jmp _afterdata ; Store the string as bytes into memory. _string: .db a_string, 0x7F ; Print the address of _string in the console when compiling. .printf "_string (0x%06X) is: %s\n", _string, a_string _afterdata: ; Point HL to the Tile Map data. movw HL, 0x1360 ; Point BA to the location of the string. movw BA, _string ; Skip increments, go to the first letter of the string. jmp _firstletter _incnext: ; Increment pointers to the string/tile map. inc HL inc BA _firstletter: ; Push BA and HL onto the stack to preserve them. push BA push HL ; Move the pointer to the string into HL registers. ; You can't move a memory address held in BA into a register, HL can. movw HL, BA ; Move a byte (letter) from the memory address into a. movb a, [HL] ; Subtract 32 from the ASCII character to align with the charmap. sub a, 32 ; Restore HL. pop HL ; Move the letter to the correct tile map. movb [HL], a ; Restore BA. pop BA ; If the letter isn't the end of the string, go to the next letter. cmp [HL], 0x5F jl _incnext .endm ; Store the address of the image in the memory address register. movw x1, charmap ; Write the address to a register of the LCD so the PM knows where to look. movw [0x2082], x1 ; Initialize empty screen. writestr " "