Browse Source

Scaffolded a file to test misc opcodes.

* No tests current being run in it.
    * Moved LCD disable/enable into macros.
    * Created memset function, modified fillTile to use it.
    * Changed the stack pointer in callRet to $e000 to ensure that LD SP
      functions as expected.
master
Ian Burgmyer 4 years ago
parent
commit
230e827671
  1. 6
      Makefile
  2. 52
      common/functions.inc
  3. 5
      cpu/callRet.asm
  4. 35
      cpu/miscInstrs.asm

6
Makefile

@ -24,6 +24,7 @@ dirs:
cpu: cpuDirs \
${BIN_DIR}/cpu/callRet.gb \
${BIN_DIR}/cpu/memcpy.gb \
${BIN_DIR}/cpu/miscInstrs.gb \
${BIN_DIR}/cpu/rst.gb
cpuDirs:
@ -40,6 +41,11 @@ ${BIN_DIR}/cpu/memcpy.gb: dirs cpu/memcpy.asm
${LD} -o ${BIN_DIR}/cpu/memcpy.gb ${OBJ_DIR}/cpu/memcpy.o
${FIX} ${BIN_DIR}/cpu/memcpy.gb
${BIN_DIR}/cpu/miscInstrs.gb: dirs cpu/miscInstrs.asm
${AS} -o ${OBJ_DIR}/cpu/miscInstrs.o cpu/miscInstrs.asm
${LD} -o ${BIN_DIR}/cpu/miscInstrs.gb ${OBJ_DIR}/cpu/miscInstrs.o
${FIX} ${BIN_DIR}/cpu/miscInstrs.gb
${BIN_DIR}/cpu/rst.gb: dirs cpu/rst.asm
${AS} -o ${OBJ_DIR}/cpu/rst.o cpu/rst.asm
${LD} -o ${BIN_DIR}/cpu/rst.gb ${OBJ_DIR}/cpu/rst.o

52
common/functions.inc

@ -1,5 +1,20 @@
SECTION "functions", ROM0[$2000]
_lcdDisable: MACRO
call waitVBlank
ld hl, $ff40
ld a, [hl]
res 7, a
ld [hl], a
ENDM
_lcdEnable: MACRO
ld hl, $ff40
ld a, [hl]
set 7, a
ld [hl], a
ENDM
; Clears the Nintendo logo tile data. This is intended to leave the screen open
; for simple (i.e. a bunch of boxes drawn with fillTile) test output.
clearLogo:
@ -7,11 +22,7 @@ clearLogo:
push hl
; disable the LCD
call waitVBlank
ld hl, $ff40
ld a, [hl]
res 7, a
ld [hl], a
_lcdDisable
; wipe the logo
ld hl, $81A0
@ -26,10 +37,7 @@ clearLogo:
jr nz, .loop
; enable the LCD and return
ld hl, $ff40
ld a, [hl]
set 7, a
ld [hl], a
_lcdEnable
pop af
pop hl
@ -41,16 +49,10 @@ clearLogo:
; Modifies:
; HL - End result: HL + 16
fillTile:
push af
push de
ld d, 16
ld a, b
.loop:
ld [hli], a
dec d
jr nz, .loop
call memset
pop de
pop af
ret
; Copies up to 256 bytes of memory to another location.
@ -70,6 +72,24 @@ memcpy:
ret z
jr memcpy
; Fills up to 256 bytes of memory with a set value, starting at HL.
; Parameters:
; B - The value to set the bytes to.
; D - The number of bytes to modify.
; HL - Destination location.
; Modifies:
; D - End result: 0
; HL - End result: HL + D
memset:
push af
ld a, b
.loop:
ld [hli], a
dec d
jr nz, .loop
pop af
ret
; Wait for vblank without using interrupts.
waitVBlank:
push af

5
cpu/callRet.asm

@ -19,6 +19,7 @@ ProgramStart:
call waitVBlank
ld b, $ff ; Fill pattern.
ld sp, $e000
call clearLogo
@ -76,10 +77,10 @@ ProgramStart:
; Stack pointer validation.
ld hl, sp+$00
ld a, h
cp $ff
cp $e0
jr nz, loop
ld a, l
cp $fe
cp $00
jr nz, loop
ld hl, $8180
call waitVBlank

35
cpu/miscInstrs.asm

@ -0,0 +1,35 @@
HeaderTitle EQUS "\"MISCINSTRS\""
include "common/defines.inc"
include "common/header.inc"
include "common/functions.inc"
SECTION "home", ROM0
ProgramStart:
call clearLogo
_lcdDisable
; Set a proper grayscale palette.
ld a, %11100100
ldh [$ff47], a
; TODO: Write actual tests. :)
ld a, $ff
ld hl, $8014
ld [hl], a
ld hl, $8016
ld [hl], a
ld hl, $8019
ld [hl], a
ld hl, $801b
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
call memset
_lcdEnable
.loop:
jr .loop
Loading…
Cancel
Save