|Scrolling Text Snippet
|Page 1 of 1|
|Author:||nicklausw [ Sun Mar 06, 2016 3:32 pm ]|
|Post subject:||Scrolling Text Snippet|
I've been cooking up something for the Gameboy, and while it's just a few fades and a main menu, already I have learned tons of stuff. Bank switching is actually alright on the GB, for one.
Anyway, I want to at least share something with you all (having been absent for a while now), so here's my code for scrolling text. You call it like this: (macro)
ld hl,\3 ; the text
ld bc,bank(\3) ; the text bank
ld de,_SCRN0+\1+(SCRN_VY_B*\2) ; \1 is x, \2 is y
call f_print_text ; do it!
and here's the code: (note, you need these lovely defines)
line_nl = $fe
line_end = $ff
line_length = 32
section "wram", wram0
; wait for vblank
section "wait_vblank", rom0
ldh a, [rSTAT-$ff00]
and 2 ; unimportant bytes
jr nz, wait_vblank
section "f_print_text", rom0
; set line counter
; set bank
ld a,[hl+] ; get a byte
ld a, [counter]
dec a ; lower line counter
cp line_nl ; is it time for newline?
jr z, .newline ; yep.
cp line_end ; is it done?
ret z ; yes, we're done.
add $6f ; this is assuming the text tiles are $70 higher than the raw data text
halt ; wait a bit!
halt ; wait some more!
; the last frame is only called
; if a is pressed...
; that functionality works, but is
; not wanted just yet.
halt ; keep waiting!
ld a, [counter]
; fill until next line
jr nz, .nl_loop
ld a, line_length
An example of some text could be:
db "hello this is nicklausw", line_nl
db "and i do not tap dance", line_end
It would be called like this:
print_text 0, 0, the_text
and would print on the screen as such:
hello this is nicklausw
and i do not tap dance
note that the gameboy screen probably isn't big enough for the width of that text.
If you do not want the text to scroll, then easy, just remove the halts to keep from pausing. Maybe replace one of them with a "call wait_vblank" to make sure things don't mess up with vblank and all that.
The code might be a little sloppy, but it works for me. I'll probably cook up a little demo to show it off in action soon.
|Page 1 of 1||All times are UTC - 7 hours|
|Powered by phpBB® Forum Software © phpBB Group