From d98ff628720acc14f66555ac0ba8e750ea05166d Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Fri, 21 Jun 2019 10:30:43 +0000 Subject: [PATCH] Refactored text renderer --- game/text.asm | 69 +++++++++++++++++++------------------------------- main.o | Bin 8127 -> 7743 bytes test.gb | Bin 32768 -> 32768 bytes test.map | 20 ++++++--------- test.sym | 16 +++++------- 5 files changed, 40 insertions(+), 65 deletions(-) diff --git a/game/text.asm b/game/text.asm index d891c77..829d6be 100644 --- a/game/text.asm +++ b/game/text.asm @@ -82,9 +82,10 @@ ClearWindow: ; @return hl - Workram position for text pointer ; @return de - Memory address to source string StartText: + ld a, 10 + ld [textwriter_curdelay], a ld a, 0 ld [textwriter_curletter], a - ld [textwriter_curdelay], a ld [textwriter_posx], a ld [textwriter_posy], a ld a, 1 @@ -102,17 +103,16 @@ StartText: DrawActiveText: ld a, [textwriter_active] ; Check if text is currently active and a - jp z, .exit + ret z ; Delay writing a letter by 10 frames ld a, [textwriter_curdelay] - inc a + dec a ld [textwriter_curdelay], a - cp 10 - jr c, .exit + ret nz ; Reset the curdelay - ld a, 0 + ld a, 10 ld [textwriter_curdelay], a .startdrawtext @@ -124,34 +124,23 @@ DrawActiveText: ld e, [hl] ; Store the next byte address to e ; We now have the current letter being drawn at [de] - ld hl, _SCRN1 ; Load the top-left map position to our map - ld a, [textwriter_posy] - ld c, a + ; Get the current X position for the text on screen + ld hl, (_SCRN1 + $21) ; Load the top-left window position for our text + ; Load the x position for current text position and ld a, [textwriter_posx] ld b, a -.moveyaxis - ; Our first objective is to position the text to correct position - ; We do so shifting the position by $20 for each y axis - ; and position by $01 for each x axis that needs movement - ld a, c ; Load the y position to our accumilator + ld a, l + add b ; Add the x position + ld l, a + + ; Get the current Y position for the text on screen + ld a, [textwriter_posy] and a ; Check if it's zero - jr z, .movexaxis ; Jump to x axis if it's zero and no moving necessary - ld a, l ; Load the first half of the destination position - add a, $20 ; Add $20 (one vertical line) - ld l, a ; Store the position back - ld a, h ; Grab the second part of the address - 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 + jr z, .drawletter + ; If not, jump forward by a whole line. + ld a, l + add a, $20 + ld l, a .drawletter ld a, [de] ; Load the first byte in the string 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 ; 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. ld [textwriter_posx], a - ld a, [textwriter_posy] - inc a - ld [textwriter_posy], a + ld a, 1 + ld [textwriter_posy], a ; Set our Y position to 1 + ld [textwriter_curdelay], a ; Also set curdelay to 1 as well ; 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 @@ -195,7 +184,8 @@ DrawActiveText: ; Check if we printed an empty letter cp a, $50 jr nz, .continue - ld b, 1 + ld a, 1 + ld [textwriter_curdelay], a ; Set curdelay to 1 so it immediately prints next character .continue ; Time to update our work ram @@ -213,13 +203,6 @@ DrawActiveText: ; Update the current letter being drawn in ram ld a, [textwriter_curletter] 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 .exit diff --git a/main.o b/main.o index ca37ac9229487a742cb22256e85817c7114c643e..51e8d4c6e4a55ac2b5d9cf51e694e310224d6322 100644 GIT binary patch delta 802 zcmY+BOK1~O6o${8WG0)p{6%&Xh-sZIH=j{MCj{vks8H6l{5?y_6y(;rmTGfpZS^y#Yl%Bfi-;Hgnmr~$ES8fi}qr)dEhi;G%V{RH~OMLn#30R5Eo z9`v1Kp0GLx`YP!y=nI?3y#g(88NDw-AGuN!R-c1rB~5_d$lWKPX)dGVG3bTk()tKA zh2>Haa2hvi>zlm~0+HR?-S>vjv#z-N6~(Zsed zwAzo&bRu;^R_}u7#9F%jD(>)i_SFAh5Q7Lf1;M1& delta 1236 zcmZ{kT}YEr7{{OU&i9?0PR(VmO>rtlQ8t1Up=BtEP!~o-DM>PN*}(aV8*XZ$h8T2X z>l8vC&_yXmr8JBnN(z#cJ}9DYiqeaqLD*Hqg3}8{biX(33lgL=r3x+u!90)tn6ay1hq4 z*speb!=A7&u(F2hHDhbn^sH4gM5JgNjq)nC!*oq=ai9BHqv@{hJ?Bia@&%S}dZ{bl zpzNxd(Y;UjT`^=J=;;c!VsLSym4kNcb;Ep*q?%6Yo*IoxMu{c(Goj5rv6@r#9I|UmE#cu3at1ugx6-pdJ7PIPmqpMrwNaPOR zbczu%%iK21pZa);g#CtygmnvCG=MCvaY=|%6#X8{+@Fm<&2dGce+Cd>fWj+u- zXMJiTDD_lrP&&1jZx%7}V)AiNtEM%9TC`moLCxAE$3RV7H7zlfx0tuEjeOW##H@S_ zYc8L~x`BVkn!}Zhk-|;L4ytNL%(g(qf6o;NT0Amboo`8<)?#~i%ZVlS{F==bX03W9e3fkp$(WjO%U&&DXh!^Ot%FF=76D8za|N*HPx b&^#NUx?fB{is=B*;**;jh3j)BZV&+gWrj(w delta 182 zcmZo@U}|V!nqa~Bexs!*Bhx+c$&FkaHZffhU}Jd2bl?^1