Created
October 2, 2016 22:21
-
-
Save lf94/5338296c69632c972bc5b1a0dc41b6d3 to your computer and use it in GitHub Desktop.
Check to see if OAM DMA doesn't write unused bits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| INCLUDE "Global.inc" | |
| ; Cartridge header | |
| SECTION "Org $00",ROM0[$00] | |
| RST_00: | |
| jp $100 | |
| SECTION "Org $08",ROM0[$08] | |
| RST_08: | |
| jp $100 | |
| SECTION "Org $10",ROM0[$10] | |
| RST_10: | |
| jp $100 | |
| SECTION "Org $18",ROM0[$18] | |
| RST_18: | |
| jp $100 | |
| SECTION "Org $20",ROM0[$20] | |
| RST_20: | |
| jp $100 | |
| SECTION "Org $28",ROM0[$28] | |
| RST_28: | |
| jp $100 | |
| SECTION "Org $30",ROM0[$30] | |
| RST_30: | |
| jp $100 | |
| SECTION "Org $38",ROM0[$38] | |
| RST_38: | |
| jp $100 | |
| ; Interrupt vectors | |
| SECTION "V-Blank IRQ Vector",ROM0[$40] | |
| VBL_VECT: | |
| call VBlankHandler | |
| reti | |
| SECTION "LCD IRQ Vector",ROM0[$48] | |
| LCD_VECT: | |
| reti | |
| SECTION "Timer IRQ Vector",ROM0[$50] | |
| TIMER_VECT: | |
| reti | |
| SECTION "Serial IRQ Vector",ROM0[$58] | |
| SERIAL_VECT: | |
| reti | |
| SECTION "Joypad IRQ Vector",ROM0[$60] | |
| JOYPAD_VECT: | |
| reti | |
| SECTION "Start",ROM0[$100] | |
| nop | |
| jp Start | |
| ;; RGBFIX will fill in the header information and include the Nintendo logo. | |
| SECTION "Global variables", WRAM0 | |
| wOAM:: DS $9F ; Allocate space for OAM sprites in WRAM | |
| wIEF:: DS 1 ; Interrupt bit flags | |
| SECTION "Program Start", ROM0[$0150] | |
| Start:: | |
| di | |
| ;; CPU | |
| ld sp, $CFFF | |
| ;; WRAM | |
| ld hl, $C000 | |
| ld bc, $E000-$C000 | |
| ld a, 0 | |
| call FillMemoryLong | |
| ;; Interrupts | |
| ld a, 0 ; Clear flags | |
| ldh [rIF], a | |
| ld a, IEF_VBLANK ; Enable interrupts we'll use | |
| ldh [rIE], a | |
| ;; Input | |
| ld a, %00110000 ; Setting bits 5 and 6 will reset joypad input. | |
| ldh [rP1], a | |
| ei | |
| ;; Graphics | |
| call WaitVBlank ; Can't do any graphics access outside of v-blank or LCD control. | |
| ;; Turn off LCD to do any LCD or VRAM related action | |
| ;; If the Game Boy turned on with LCD off this wouldn't be necessary (and no need to wait for v-blank above) | |
| ld a, LCDCF_OFF | |
| ldh [rLCDC], a | |
| ;; Palettes | |
| ld a, %11100100 ; White, Light Gray, Dark Dray, Black | |
| ldh [rBGP], a ; Background (BG) | |
| ldh [rOBP0], a ; OAM 1 | |
| ldh [rOBP1], a ; OAM 2 | |
| ;; Load OAM DMA code into HRAM | |
| ld hl, N_OAMDMA | |
| ld de, _HRAM | |
| ld b, N_OAMDMA_END - N_OAMDMA | |
| call TransferBytes | |
| ;; OAMRAM | |
| ld hl, wOAM | |
| ld b, $9F | |
| ld a, 0 | |
| call FillMemory | |
| ;; VRAM | |
| ;; Normally clear VRAM but we want graphics to indicate something passed or failed | |
| ;; OAM | |
| call _HRAM | |
| .loop | |
| call Logic | |
| jp .loop | |
| VBlankHandler: | |
| push af | |
| ld a, [wIEF] | |
| ld b, IEF_VBLANK | |
| or b | |
| ld [wIEF], a | |
| pop af | |
| ret | |
| WaitVBlank:: | |
| push af | |
| halt | |
| nop | |
| nop | |
| ld a, [wIEF] | |
| bit IEF_VBLANK / 2, a ; Check VBlank flag | |
| jr z, WaitVBlank | |
| res IEF_VBLANK / 2, a ; Reset VBlank flag | |
| ld [wIEF], a | |
| pop af | |
| ret | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| INCLUDE "Hardware.inc" | |
| SECTION "OAM DMA 28Bit Test", WRAM0 | |
| wPassed: DS $01 ; Did the test pass? | |
| SECTION "Main", ROM0 | |
| Logic:: | |
| ld hl, wPassed ; Initial state is passed | |
| ld [hl], 1 | |
| ld hl, wOAM + 3 | |
| ld [hl], %00001111 ; When DMA'd, these 1s shouldn't be written. | |
| ld hl, _OAMRAM + 3 | |
| ld [hl], %00000000 ; OAM should accept these zeros when written manually. | |
| call _HRAM | |
| ld a, [hl] ; OAMRAM + 3 should be 0 still. | |
| cp 0 | |
| jp z, pass | |
| ld hl, wPassed ; Test failed | |
| ld [hl], 0 | |
| ld a, %00011011 | |
| ldh [rBGP], a ; Invert BG palette to indicate failure | |
| jp scrnon | |
| pass: | |
| ld a, %01010101 | |
| ldh [rBGP], a ; Make screen light gray to indicate pass | |
| scrnon: | |
| ld a, LCDCF_ON | LCDCF_BG8000 | LCDCF_BGON | |
| ldh [rLCDC], a | |
| ;; End of the tests, just loop until GB is turned off. | |
| loop: | |
| call WaitVBlank | |
| jp loop | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment