diff --git a/Makefile b/Makefile index 2af3e9f..15354f1 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,8 @@ dirs: # CPU # cpu: cpuDirs \ - ${BIN_DIR}/cpu/callRet.gb + ${BIN_DIR}/cpu/callRet.gb \ + ${BIN_DIR}/cpu/rst.gb cpuDirs: ${MKDIR} -p ${OBJ_DIR}/cpu @@ -33,6 +34,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/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 + ${FIX} ${BIN_DIR}/cpu/rst.gb + # # Video # diff --git a/common/functions.inc b/common/functions.inc index 7c89098..a3027a4 100644 --- a/common/functions.inc +++ b/common/functions.inc @@ -26,3 +26,38 @@ fillTile: 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. +clearLogo: + push af + push hl + + ; disable the LCD + call waitVBlank + ld hl, $ff40 + ld a, [hl] + res 7, a + ld [hl], a + + ; wipe the logo + ld hl, $81A0 +.clearLogoLoop: + ld a, $0 + ld [hld], a + ld a, h + cp $80 + jr nz, .clearLogoLoop + ld a, l + cp $0f + jr nz, .clearLogoLoop + + ; enable the LCD and return + ld hl, $ff40 + ld a, [hl] + set 7, a + ld [hl], a + + pop af + pop hl + ret diff --git a/cpu/callRet.asm b/cpu/callRet.asm index fa90e3d..b0b438f 100644 --- a/cpu/callRet.asm +++ b/cpu/callRet.asm @@ -20,19 +20,8 @@ ProgramStart: ld b, $ff ; Fill color. - ; disable the LCD while we clear the logo - ld hl, $ff40 - ld a, [hl] - res 7, a - ld [hl], a call clearLogo - ; enable the LCD - ld hl, $ff40 - ld a, [hl] - set 7, a - ld [hl], a - call waitVBlank ld hl, $8010 call fillTile @@ -85,22 +74,7 @@ loop: jr loop -SECTION "clearLogo", ROM0[$200] -clearLogo: - ld hl, $81A0 -.clearLoop: - ld a, $0 - ld [hld], a - ld a, h - cp $80 - jr nz, .clearLoop - ld a, l - cp $10 - jr nz, .clearLoop - ret - - -SECTION "retTests", ROM0[$220] +SECTION "retTests", ROM0[$200] retError: jr retError diff --git a/cpu/rst.asm b/cpu/rst.asm new file mode 100644 index 0000000..c81aea3 --- /dev/null +++ b/cpu/rst.asm @@ -0,0 +1,84 @@ +HeaderTitle EQUS "\"RST\"" + +include "common/defines.inc" + +OverrideRst00 SET 1 +OverrideRst08 SET 1 +OverrideRst10 SET 1 +OverrideRst18 SET 1 +OverrideRst20 SET 1 +OverrideRst28 SET 1 +OverrideRst30 SET 1 +OverrideRst38 SET 1 + +include "common/header.inc" +include "common/functions.inc" + +SECTION "rst00", ROM0[$0000] + ld hl, $8030 + call fillTile + ret + +SECTION "rst08", ROM0[$0008] + ld hl, $8050 + call fillTile + ret + +SECTION "rst10", ROM0[$0010] + ld hl, $8070 + call fillTile + ret + +SECTION "rst18", ROM0[$0018] + ld hl, $8090 + call fillTile + ret + +SECTION "rst20", ROM0[$0020] + ld hl, $8100 + call fillTile + ret + +SECTION "rst28", ROM0[$0028] + ld hl, $8120 + call fillTile + ret + +SECTION "rst30", ROM0[$0030] + ld hl, $8140 + call fillTile + ret + +SECTION "rst38", ROM0[$0038] + ld hl, $8160 + call fillTile + ret + +SECTION "home", ROM0 +ProgramStart: + call waitVBlank + call clearLogo + + ld a, %11100100 + ldh [$ff47], a + + ld b, $ff + call waitVBlank + rst $00 + call waitVBlank + rst $08 + call waitVBlank + rst $10 + call waitVBlank + rst $18 + call waitVBlank + rst $20 + call waitVBlank + rst $28 + call waitVBlank + rst $30 + call waitVBlank + rst $38 + +loop: + jr loop