Skip to content

Instantly share code, notes, and snippets.

@agrif
Created April 11, 2013 17:35
Show Gist options
  • Select an option

  • Save agrif/5365435 to your computer and use it in GitHub Desktop.

Select an option

Save agrif/5365435 to your computer and use it in GitHub Desktop.
gameboy-putln.asm
strlen:
;; string address is in hl, output is in bc
ld bc, 0
.loop:
ld a, (hli)
cp 0
ret z
inc bc
jr .loop
putln:
;; string address is in hl, y coordinate is in a
push hl
push af
call strlen
;; string length is now in bc
ld hl, SCRN0 ; hl will store our destination, for now
;; center the string (on X)
ld a, 21
sub c
srl a
add a, l
ld l, a
pop af ; we need the y coordinate now
.multloop:
cp 0
jr z, .multexit
dec a
ld de, SCRN_VY_B
add hl, de
jr .multloop
.multexit:
;; move hl into de, our final dest storage
ld d, h
ld e, l
pop hl
;; string address is in hl, destination is in de, length is in bc
;; we're set (tail-call!)
jp mem_CopyVRAM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment