Browse Source

Added a memcpy function and a test.

* Alphabetized the functions.inc by label name.
master
Ian Burgmyer 4 years ago
parent
commit
bd9aa4f675
  1. 6
      Makefile
  2. 72
      common/functions.inc
  3. 43
      cpu/memcpy.asm

6
Makefile

@ -23,6 +23,7 @@ dirs:
#
cpu: cpuDirs \
${BIN_DIR}/cpu/callRet.gb \
${BIN_DIR}/cpu/memcpy.gb \
${BIN_DIR}/cpu/rst.gb
cpuDirs:
@ -34,6 +35,11 @@ ${BIN_DIR}/cpu/callRet.gb: dirs cpu/callRet.asm
${LD} -o ${BIN_DIR}/cpu/callRet.gb ${OBJ_DIR}/cpu/callRet.o
${FIX} ${BIN_DIR}/cpu/callRet.gb
${BIN_DIR}/cpu/memcpy.gb: dirs cpu/memcpy.asm
${AS} -o ${OBJ_DIR}/cpu/memcpy.o cpu/memcpy.asm
${LD} -o ${BIN_DIR}/cpu/memcpy.gb ${OBJ_DIR}/cpu/memcpy.o
${FIX} ${BIN_DIR}/cpu/memcpy.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

72
common/functions.inc

@ -1,31 +1,4 @@
SECTION "functions", ROM0[$2000]
; Wait for vblank without using interrupts.
waitVBlank:
push af
.loop:
ldh a, [$ff44]
cp $90
jr nz, .loop
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
.loop:
ld [hli], a
dec d
jr nz, .loop
pop de
pop af
ret
; 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.
@ -61,3 +34,48 @@ clearLogo:
pop af
pop hl
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
.loop:
ld [hli], a
dec d
jr nz, .loop
pop de
pop af
ret
; Copies up to 256 bytes of memory to another location.
; Parameter:
; BC - Source location.
; HL - Destination location.
; D - The number of bytes to copy.
; Modifies:
; BC - End result: BC + D
; HL - End result: BC + d
; D - End result: $00
memcpy:
ld a, [bc]
ld [hli], a
inc bc
dec d
ret z
jr memcpy
; Wait for vblank without using interrupts.
waitVBlank:
push af
.loop:
ldh a, [$ff44]
cp $90
jr nz, .loop
pop af
ret

43
cpu/memcpy.asm

@ -0,0 +1,43 @@
HeaderTitle EQUS "\"MEMCPY\""
include "common/defines.inc"
include "common/header.inc"
include "common/functions.inc"
; Output:
; 1: copy block finished
; 2: verify block succeeded
SECTION "home", ROM0
ProgramStart:
call clearLogo
ld hl, $c000 ; WRAM
ld bc, $0104 ; Cartridge Logo
ld d, 48 ; size
call memcpy
ld hl, $8010
call waitVBlank
ld b, $ff
call fillTile
ld hl, $c000
ld bc, $0104
ld d, 48
.verifyLoop:
ld a, [bc]
cp [hl]
jr nz, loop
inc hl
inc bc
dec d
jr nz, .verifyLoop
ld hl, $8030
call waitVBlank
ld b, $ff
call fillTile
loop:
jr loop
Loading…
Cancel
Save