Browse Source

Split some common functions into an include.

master
Ian Burgmyer 4 years ago
parent
commit
a9bc3bfb96
  1. 28
      common/functions.inc
  2. 55
      cpu/callRet.asm
  3. 19
      video/lcdToggle.asm

28
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

55
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

19
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]

Loading…
Cancel
Save