Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing memory with assembly (Z80 / Gameboy)

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:
like image 511
Paul Avatar asked Jan 07 '23 22:01

Paul


1 Answers

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.

like image 150
Ville Krumlinde Avatar answered Feb 04 '23 19:02

Ville Krumlinde