From b7b00de3a5a092c3240fbe5892cc30bdd5393633 Mon Sep 17 00:00:00 2001 From: Daniel Borges Date: Thu, 3 Jan 2019 01:09:44 +0100 Subject: [PATCH] use B and C registers for line and tile counters in rendering --- Code/main.asm | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/Code/main.asm b/Code/main.asm index b6f3629..2f59cf8 100644 --- a/Code/main.asm +++ b/Code/main.asm @@ -488,10 +488,14 @@ Render: ld a, [hl+] ld h, [hl] ld l, a - - ; set c to point to tiles left to render -.nextline - ld c, LOW(TilesLeft) + + ; init tile counter in C + ldh a, [TilesLeft] + ld c, a + + ; init line counter in B + ldh a, [LinesLeft] + ld b, a .loop ; check we can still render @@ -505,9 +509,7 @@ Render: inc de ; loop while there are tiles to render - ld a, [$FF00+c] - dec a - ld [$FF00+c], a + dec c jr nz, .loop ; go to next line @@ -519,20 +521,21 @@ Render: .nocarry ; loop while there are lines to render - ld c, LOW(LinesLeft) - ld a, [$FF00+c] - dec a - ld [$FF00+c], a + dec b jr z, .finish + + ld c, 20 ; reset tile counter - ld a, 20 - ldh [TilesLeft], a - ld c, a + jr .loop - jr .nextline - - ; save incremented video and buffer pointers .finish + ; save counters + ld a, c + ldh [TilesLeft], a + ld a, b + ldh [LinesLeft], a + + ; save incremented video pointer and buffer pointer ld a, l ldh [Video], a ld a, h