Refactored text renderer
This commit is contained in:
parent
b7ee801fa5
commit
d98ff62872
5 changed files with 40 additions and 65 deletions
|
@ -82,9 +82,10 @@ ClearWindow:
|
||||||
; @return hl - Workram position for text pointer
|
; @return hl - Workram position for text pointer
|
||||||
; @return de - Memory address to source string
|
; @return de - Memory address to source string
|
||||||
StartText:
|
StartText:
|
||||||
|
ld a, 10
|
||||||
|
ld [textwriter_curdelay], a
|
||||||
ld a, 0
|
ld a, 0
|
||||||
ld [textwriter_curletter], a
|
ld [textwriter_curletter], a
|
||||||
ld [textwriter_curdelay], a
|
|
||||||
ld [textwriter_posx], a
|
ld [textwriter_posx], a
|
||||||
ld [textwriter_posy], a
|
ld [textwriter_posy], a
|
||||||
ld a, 1
|
ld a, 1
|
||||||
|
@ -102,17 +103,16 @@ StartText:
|
||||||
DrawActiveText:
|
DrawActiveText:
|
||||||
ld a, [textwriter_active] ; Check if text is currently active
|
ld a, [textwriter_active] ; Check if text is currently active
|
||||||
and a
|
and a
|
||||||
jp z, .exit
|
ret z
|
||||||
|
|
||||||
; Delay writing a letter by 10 frames
|
; Delay writing a letter by 10 frames
|
||||||
ld a, [textwriter_curdelay]
|
ld a, [textwriter_curdelay]
|
||||||
inc a
|
dec a
|
||||||
ld [textwriter_curdelay], a
|
ld [textwriter_curdelay], a
|
||||||
cp 10
|
ret nz
|
||||||
jr c, .exit
|
|
||||||
|
|
||||||
; Reset the curdelay
|
; Reset the curdelay
|
||||||
ld a, 0
|
ld a, 10
|
||||||
ld [textwriter_curdelay], a
|
ld [textwriter_curdelay], a
|
||||||
|
|
||||||
.startdrawtext
|
.startdrawtext
|
||||||
|
@ -124,34 +124,23 @@ DrawActiveText:
|
||||||
ld e, [hl] ; Store the next byte address to e
|
ld e, [hl] ; Store the next byte address to e
|
||||||
; We now have the current letter being drawn at [de]
|
; We now have the current letter being drawn at [de]
|
||||||
|
|
||||||
ld hl, _SCRN1 ; Load the top-left map position to our map
|
; Get the current X position for the text on screen
|
||||||
ld a, [textwriter_posy]
|
ld hl, (_SCRN1 + $21) ; Load the top-left window position for our text
|
||||||
ld c, a
|
; Load the x position for current text position and
|
||||||
ld a, [textwriter_posx]
|
ld a, [textwriter_posx]
|
||||||
ld b, a
|
ld b, a
|
||||||
.moveyaxis
|
ld a, l
|
||||||
; Our first objective is to position the text to correct position
|
add b ; Add the x position
|
||||||
; We do so shifting the position by $20 for each y axis
|
ld l, a
|
||||||
; and position by $01 for each x axis that needs movement
|
|
||||||
ld a, c ; Load the y position to our accumilator
|
; Get the current Y position for the text on screen
|
||||||
|
ld a, [textwriter_posy]
|
||||||
and a ; Check if it's zero
|
and a ; Check if it's zero
|
||||||
jr z, .movexaxis ; Jump to x axis if it's zero and no moving necessary
|
jr z, .drawletter
|
||||||
ld a, l ; Load the first half of the destination position
|
; If not, jump forward by a whole line.
|
||||||
add a, $20 ; Add $20 (one vertical line)
|
ld a, l
|
||||||
ld l, a ; Store the position back
|
add a, $20
|
||||||
ld a, h ; Grab the second part of the address
|
ld l, a
|
||||||
adc a, $00 ; Add only the accumilator
|
|
||||||
ld h, a ; Store the position back
|
|
||||||
dec c ; Decrement our y parameter
|
|
||||||
jr .moveyaxis ; Repeat
|
|
||||||
.movexaxis
|
|
||||||
; Now we check and move the position based on the x position
|
|
||||||
ld a, b ; Load the x position to our accimulator
|
|
||||||
and a ; Check if it's zero
|
|
||||||
jr z, .drawletter ; Jump to drawletter if it's zero already
|
|
||||||
inc hl ; Increment the map position by one since we need to move by x position
|
|
||||||
dec b ; Decrement our x parameter
|
|
||||||
jr .movexaxis ; Repeat
|
|
||||||
.drawletter
|
.drawletter
|
||||||
ld a, [de] ; Load the first byte in the string
|
ld a, [de] ; Load the first byte in the string
|
||||||
ld bc, textwriter_map ; Get the map for the ASCII->Tile map
|
ld bc, textwriter_map ; Get the map for the ASCII->Tile map
|
||||||
|
@ -176,12 +165,12 @@ DrawActiveText:
|
||||||
|
|
||||||
; The byte we printed was a new line so we increment Y position
|
; The byte we printed was a new line so we increment Y position
|
||||||
; and reset our X position.
|
; and reset our X position.
|
||||||
ld a, 0 ; Usually we'd print into first position but since we're jumping
|
ld a, -1 ; Usually we'd print into first position but since we're jumping
|
||||||
; into continue, continue will automatically increment x for us.
|
; into continue, continue will automatically increment x for us.
|
||||||
ld [textwriter_posx], a
|
ld [textwriter_posx], a
|
||||||
ld a, [textwriter_posy]
|
ld a, 1
|
||||||
inc a
|
ld [textwriter_posy], a ; Set our Y position to 1
|
||||||
ld [textwriter_posy], a
|
ld [textwriter_curdelay], a ; Also set curdelay to 1 as well
|
||||||
|
|
||||||
; We already know we printed empty character so we can skip checking
|
; We already know we printed empty character so we can skip checking
|
||||||
; if we need to repeat once again and just set the b flag
|
; if we need to repeat once again and just set the b flag
|
||||||
|
@ -195,7 +184,8 @@ DrawActiveText:
|
||||||
; Check if we printed an empty letter
|
; Check if we printed an empty letter
|
||||||
cp a, $50
|
cp a, $50
|
||||||
jr nz, .continue
|
jr nz, .continue
|
||||||
ld b, 1
|
ld a, 1
|
||||||
|
ld [textwriter_curdelay], a ; Set curdelay to 1 so it immediately prints next character
|
||||||
|
|
||||||
.continue
|
.continue
|
||||||
; Time to update our work ram
|
; Time to update our work ram
|
||||||
|
@ -213,13 +203,6 @@ DrawActiveText:
|
||||||
; Update the current letter being drawn in ram
|
; Update the current letter being drawn in ram
|
||||||
ld a, [textwriter_curletter]
|
ld a, [textwriter_curletter]
|
||||||
inc a
|
inc a
|
||||||
|
|
||||||
; Check if we need to repeat whole thing due to printing empty character
|
|
||||||
ld a, b
|
|
||||||
and b
|
|
||||||
jr nz, .startdrawtext
|
|
||||||
|
|
||||||
; We didn't print an empty
|
|
||||||
ld [textwriter_curletter], a
|
ld [textwriter_curletter], a
|
||||||
|
|
||||||
.exit
|
.exit
|
||||||
|
|
BIN
main.o
BIN
main.o
Binary file not shown.
BIN
test.gb
BIN
test.gb
Binary file not shown.
20
test.map
20
test.map
|
@ -1,17 +1,13 @@
|
||||||
ROM Bank #0 (HOME):
|
ROM Bank #0 (HOME):
|
||||||
SECTION: $0200-$027F ($0080 bytes) ["rom_textmap"]
|
SECTION: $0200-$027F ($0080 bytes) ["rom_textmap"]
|
||||||
$0200 = textwriter_map
|
$0200 = textwriter_map
|
||||||
SECTION: $1280-$137D ($00FE bytes) ["TextWriter"]
|
SECTION: $1280-$136C ($00ED bytes) ["TextWriter"]
|
||||||
$137A = DrawActiveText.exit
|
$131D = DrawActiveText.drawletter
|
||||||
$1326 = DrawActiveText.movexaxis
|
$1331 = DrawActiveText.checkNewline
|
||||||
$1317 = DrawActiveText.moveyaxis
|
$1353 = DrawActiveText.continue
|
||||||
$132E = DrawActiveText.drawletter
|
$1347 = DrawActiveText.checkRepeatOnce
|
||||||
$1342 = DrawActiveText.checkNewline
|
|
||||||
$1360 = DrawActiveText.continue
|
|
||||||
$1357 = DrawActiveText.checkRepeatOnce
|
|
||||||
$1306 = DrawActiveText.startdrawtext
|
|
||||||
$12D3 = StartText
|
$12D3 = StartText
|
||||||
$12EF = DrawActiveText
|
$12F1 = DrawActiveText
|
||||||
$1280 = InitWindow
|
$1280 = InitWindow
|
||||||
SECTION: $0031-$003E ($000E bytes) ["Game Loop"]
|
SECTION: $0031-$003E ($000E bytes) ["Game Loop"]
|
||||||
$0037 = GameLoop.mainloop
|
$0037 = GameLoop.mainloop
|
||||||
|
@ -34,12 +30,12 @@ ROM Bank #0 (HOME):
|
||||||
SECTION: $0280-$127F ($1000 bytes) ["Font"]
|
SECTION: $0280-$127F ($1000 bytes) ["Font"]
|
||||||
$0280 = Page1
|
$0280 = Page1
|
||||||
$1280 = Page1End
|
$1280 = Page1End
|
||||||
SLACK: $2DAD bytes
|
SLACK: $2DBE bytes
|
||||||
|
|
||||||
WRAM Bank #0:
|
WRAM Bank #0:
|
||||||
SECTION: $C000-$C006 ($0007 bytes) ["ram_textwriter"]
|
SECTION: $C000-$C006 ($0007 bytes) ["ram_textwriter"]
|
||||||
$C002 = textwriter_curletter
|
|
||||||
$C005 = textwriter_curdelay
|
$C005 = textwriter_curdelay
|
||||||
|
$C002 = textwriter_curletter
|
||||||
$C003 = textwriter_posx
|
$C003 = textwriter_posx
|
||||||
$C004 = textwriter_posy
|
$C004 = textwriter_posy
|
||||||
$C006 = textwriter_active
|
$C006 = textwriter_active
|
||||||
|
|
16
test.sym
16
test.sym
|
@ -1,16 +1,12 @@
|
||||||
; File generated by rgblink
|
; File generated by rgblink
|
||||||
|
|
||||||
00:0200 textwriter_map
|
00:0200 textwriter_map
|
||||||
00:137A DrawActiveText.exit
|
00:131D DrawActiveText.drawletter
|
||||||
00:1326 DrawActiveText.movexaxis
|
00:1331 DrawActiveText.checkNewline
|
||||||
00:1317 DrawActiveText.moveyaxis
|
00:1353 DrawActiveText.continue
|
||||||
00:132E DrawActiveText.drawletter
|
00:1347 DrawActiveText.checkRepeatOnce
|
||||||
00:1342 DrawActiveText.checkNewline
|
|
||||||
00:1360 DrawActiveText.continue
|
|
||||||
00:1357 DrawActiveText.checkRepeatOnce
|
|
||||||
00:1306 DrawActiveText.startdrawtext
|
|
||||||
00:12D3 StartText
|
00:12D3 StartText
|
||||||
00:12EF DrawActiveText
|
00:12F1 DrawActiveText
|
||||||
00:1280 InitWindow
|
00:1280 InitWindow
|
||||||
00:0037 GameLoop.mainloop
|
00:0037 GameLoop.mainloop
|
||||||
00:0031 GameLoop
|
00:0031 GameLoop
|
||||||
|
@ -22,8 +18,8 @@
|
||||||
00:0061 Start
|
00:0061 Start
|
||||||
00:0280 Page1
|
00:0280 Page1
|
||||||
00:1280 Page1End
|
00:1280 Page1End
|
||||||
00:C002 textwriter_curletter
|
|
||||||
00:C005 textwriter_curdelay
|
00:C005 textwriter_curdelay
|
||||||
|
00:C002 textwriter_curletter
|
||||||
00:C003 textwriter_posx
|
00:C003 textwriter_posx
|
||||||
00:C004 textwriter_posy
|
00:C004 textwriter_posy
|
||||||
00:C006 textwriter_active
|
00:C006 textwriter_active
|
||||||
|
|
Loading…
Reference in a new issue