I'm trying to programmatically write characters into memory such that I can then display it on screen. How do I take a value (say 65) and write it into memory with Z80 assembly for the Gameboy?
From what I've read this is simply a case of loading a register into the memory address:
ld [hl], b
My code is seemingly working apart from the writing of characters to memory. The output I get is "BBBBBBBB".
The surrounding code is below.
printnum:
ld a, 0 ; cursor position
ld b, 65 ; ASCII 'A'
ld hl, Number ; set pointer to address of Number
overwrite:
ld [hl], b ; set dereference to 'A' ???
inc hl ; increment pointer
inc a ; increment acc
cp 7 ; are we done?
jp z, overwrite ; continue if not
; V output to screen V
ld hl, Number
ld de, _SCRN0+3+(SCRN_VY_B*7) ;
ld bc, NumberEnd-Number
call mem_CopyVRAM
ret ; done
Number:
DB "BBBBBBBB" ; placeholder
NumberEnd:
Gameboy code executes in ROM: read-only memory. So your loop that overwrites number has no effect (trying to write to ROM just keeps the existing value). If you want a buffer to write on you need to make sure it is in RAM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With