From a9bc3bfb963049cb8a4fa20b9830378144bde416 Mon Sep 17 00:00:00 2001 From: Ian Burgmyer Date: Mon, 7 Sep 2020 20:18:30 -0400 Subject: [PATCH] Split some common functions into an include. --- common/functions.inc | 28 ++++++++++++++++++++++++++ cpu/callRet.asm | 55 +++++++++++++++++----------------------------------- video/lcdToggle.asm | 19 ++++-------------- 3 files changed, 50 insertions(+), 52 deletions(-) create mode 100644 common/functions.inc diff --git a/common/functions.inc b/common/functions.inc new file mode 100644 index 0000000..7c89098 --- /dev/null +++ b/common/functions.inc @@ -0,0 +1,28 @@ +SECTION "functions", ROM0[$2000] +; Wait for vblank without using interrupts. +waitVBlank: + push af +.waitVBlankLoop: + ldh a, [$ff44] + cp $90 + jr nz, .waitVBlankLoop + pop af + ret + +; Writes a value across 16 bytes, starting at HL. Intended to fill a single tile. +; Parameters: +; B - The value to set the bytes to. +; Modifies: +; HL - End result: HL + 16 +fillTile: + push af + push de + ld d, 16 + ld a, b +.fillTileLoop: + ld [hli], a + dec d + jr nz, .fillTileLoop + pop de + pop af + ret diff --git a/cpu/callRet.asm b/cpu/callRet.asm index dae1abf..fa90e3d 100644 --- a/cpu/callRet.asm +++ b/cpu/callRet.asm @@ -2,6 +2,7 @@ HeaderTitle EQUS "\"CALLRET\"" include "common/defines.inc" include "common/header.inc" +include "common/functions.inc" ; 1: call / ret ; 2: call / ret nz @@ -17,6 +18,8 @@ SECTION "home", ROM0 ProgramStart: call waitVBlank + ld b, $ff ; Fill color. + ; disable the LCD while we clear the logo ld hl, $ff40 ld a, [hl] @@ -32,65 +35,57 @@ ProgramStart: call waitVBlank ld hl, $8010 - call drawRect + call fillTile call waitVBlank call retNz ld hl, $8040 - call drawRect + call fillTile call waitVBlank call retZ ld hl, $8060 - call drawRect + call fillTile call waitVBlank call retNc ld hl, $8080 - call drawRect + call fillTile call waitVBlank call retC ld hl, $80a0 - call drawRect + call fillTile call waitVBlank ld a, 2 dec a ld hl, $8110 - call nz, drawRect + call nz, fillTile call waitVBlank ld a, 1 dec a ld hl, $8130 - call z, drawRect + call z, fillTile call waitVBlank - ld a, 2 - dec a + ld a, 200 + add a, 55 ld hl, $8150 - call nc, drawRect + call nc, fillTile call waitVBlank ld a, 255 add a, 1 ld hl, $8170 - call c, drawRect + call c, fillTile loop: jr loop -SECTION "waitVBlank", ROM0[$200] -waitVBlank: - ldh a, [$ff44] - cp $90 - jr nz, waitVBlank - ret - - -SECTION "clearLogo", ROM0[$220] +SECTION "clearLogo", ROM0[$200] clearLogo: ld hl, $81A0 .clearLoop: @@ -105,21 +100,7 @@ clearLogo: ret -SECTION "drawRect", ROM0[$240] -drawRect: - push af - push de - ld d, 16 - ld a, $ff -.logoDraw: - ld [hli], a - dec d - jr nz, .logoDraw - pop de - pop af - ret - -SECTION "ret", ROM0[$300] +SECTION "retTests", ROM0[$220] retError: jr retError @@ -136,8 +117,8 @@ retZ: jr retError retNc: - ld a, 2 - dec a + ld a, 200 + add a, 55 ret nc jr retError diff --git a/video/lcdToggle.asm b/video/lcdToggle.asm index bbb0c11..2ca550a 100644 --- a/video/lcdToggle.asm +++ b/video/lcdToggle.asm @@ -2,17 +2,11 @@ HeaderTitle EQUS "\"LCDTOGGLE\"" include "common/defines.inc" include "common/header.inc" +include "common/functions.inc" SECTION "home", ROM0 -vblankWait: - ; Wait for vblank without interrupts. - ldh a, [$ff44] - cp $90 - jr nz, vblankWait - ret - wait: - call vblankWait + call waitVBlank dec d jr nz, wait ret @@ -28,18 +22,13 @@ reset: .loop: ; Disable the LCD - call vblankWait + call waitVBlank ldh a, [$ff40] res 7, a ldh [$ff40], a ; Mess with the logo, as we often do. - ld d, 16 - ld a, b -.logoDraw: - ld [hli], a - dec d - jr nz, .logoDraw + call fillTile ; Enable the LCD ldh a, [$ff40]