From fe0e86d475b825d855e58662bef3bcedab5eab60 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 25 May 2023 07:53:05 +0100 Subject: Add score to the HUD - add points to the score - hiscore updates --- game/main.asm | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 140 insertions(+), 9 deletions(-) diff --git a/game/main.asm b/game/main.asm index 87e2f97..253c812 100644 --- a/game/main.asm +++ b/game/main.asm @@ -49,6 +49,46 @@ game_loop: bnz jmp game_loop + ; see if the hiscore needs updating + + ; 6 digits to compare + ld y, 6 + push y + + ld x, score + ld y, hiscore +update_hiscore_loop: + cmpi + bc + jmp update_no_hiscore + bnz + jmp update_new_hiscore + + push y + ld y, [sp + 1] + dec y + ld [sp + 1], y + pop y + bno + jmp update_hiscore_loop + +update_new_hiscore: + ; new hiscore! + ld x, score + ld y, hiscore + ldi + ldi + ldi + ldi + ldi + ldi + +update_no_hiscore: + pop y jmp menu ; @@ -70,15 +110,18 @@ init_game: ld [a : x], y ; clear score - ld x, score - ld y, 6 - ld b, 0 -init_score_loop: - ld [a : x], b - dec y - bnz - jmp init_score_loop + ld y, score + ; this is all zeroes that we use + ; to erase things on screen etc + ld x, 0 + ld a, 0xa0 + ldi + ldi + ldi + ldi + ldi + ldi halt @@ -87,7 +130,53 @@ init_score_loop: ret +; +; Update the HUD (score, lives, etc) +; update_hud: + ; erase + + ; settings mode + ld y, 128 + ld b, 0xb0 + port b, y + + ; setup + inc b + + ; addr: bg data + ld y, 0 + port b, y + ld y, 0xa0 + port b, y + + ; x + inc x + bo + inc a + ld y, 100 + port b, y + + ; y + inc x + bo + inc a + ld y, 4 + port b, y + + ; w + ld y, 25 + port b, y + ; h + ld y, 8 + port b, y + + ; blit + dec b + ; write, no transparent + ld y, 1 + port b, y + ; 6 digits ld x, 6 push x @@ -104,6 +193,48 @@ update_hud: pop x ret +; +; Add points to the score +; +; in: y points (1 to 10) +add_score: + ; update score + ld x, score + add x, 5 + bo + inc a + + ld b, 6 +add_score_loop: + push b + + ld b, [a : x] + add b, y + ld [a : x], b + cmp b, 10 + bnc + jmp add_score_carry + + pop b + ret + +add_score_carry: + sub b, 10 + ld [a : x], b + + ld y, 1 + + dec x + bo + dec a + + pop b + dec b + bnz + jmp add_score_loop + ret + ; ; Helper to clear the screen ; -- cgit v1.2.3