From 57a15f9385560308e5ac05aa057f3bcb1df22824 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 16 Oct 2026 23:32:36 +0200 Subject: runrom: add support for the MMC3 chip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds support from the runrom frontend, but more importantly it provides to vnf all the infrastructure to implement memory mapping, and at least the MMC3 chip. The vnf crate now translates addresses as a MMC would do, and it implements all the relevant interfaces for the MMC3. Support for the 'brk' instruction on this chip has been left out on purpose, and it will be covered on subsequent commits. Signed-off-by: Miquel Sabaté Solà --- tests/expected/runrom/mmc3-basic.txt | 94 ++++++++++++ tests/expected/runrom/mmc3-no-wram.txt | 71 +++++++++ tests/expected/runrom/mmc3-no-writes.txt | 72 +++++++++ tests/runrom/mmc3/basic.s | 241 +++++++++++++++++++++++++++++++ tests/runrom/mmc3/mmc3.cfg | 92 ++++++++++++ 5 files changed, 570 insertions(+) create mode 100644 tests/expected/runrom/mmc3-basic.txt create mode 100644 tests/expected/runrom/mmc3-no-wram.txt create mode 100644 tests/expected/runrom/mmc3-no-writes.txt create mode 100644 tests/runrom/mmc3/basic.s create mode 100644 tests/runrom/mmc3/mmc3.cfg (limited to 'tests') diff --git a/tests/expected/runrom/mmc3-basic.txt b/tests/expected/runrom/mmc3-basic.txt new file mode 100644 index 0000000..886f97a --- /dev/null +++ b/tests/expected/runrom/mmc3-basic.txt @@ -0,0 +1,94 @@ + PC: $E045, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I-- + [STACK]: 47 E0 00 00 +jsr $E000 PC: $E000, cycles: 13, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----I-- +bit $2002 PC: $E003, cycles: 17, registers: [a: $00, x: $00, y: $00, sp: $FB], status: N---IZ- +lda #$00 PC: $E005, cycles: 19, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $2006 PC: $E008, cycles: 23, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E00B, cycles: 27, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$10 PC: $E00D, cycles: 29, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- +sta $2006 PC: $E010, cycles: 33, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E013, cycles: 37, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$00 PC: $E015, cycles: 39, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $2006 PC: $E018, cycles: 43, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E01B, cycles: 47, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$10 PC: $E01D, cycles: 49, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- +sta $2006 PC: $E020, cycles: 53, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E023, cycles: 57, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$00 PC: $E025, cycles: 59, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $A000 PC: $E028, cycles: 63, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +sta $E000 PC: $E02B, cycles: 67, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$80 PC: $E02D, cycles: 69, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I-- +sta $A001 PC: $E030, cycles: 73, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$06 PC: $E032, cycles: 75, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I-- +sta $8000 PC: $E035, cycles: 79, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$00 PC: $E037, cycles: 81, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $8001 PC: $E03A, cycles: 85, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$07 PC: $E03C, cycles: 87, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I-- +sta $8000 PC: $E03F, cycles: 91, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$01 PC: $E041, cycles: 93, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- +sta $8001 PC: $E044, cycles: 97, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + + [STACK]: 00 00 +rts PC: $E048, cycles: 103, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I-- + [STACK]: 4A E0 00 00 +jsr $8000 PC: $8000, cycles: 109, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- +clc PC: $8001, cycles: 111, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- +adc $6000 PC: $8004, cycles: 115, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- +sta $6000 PC: $8007, cycles: 119, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- + [STACK]: 00 00 +rts PC: $E04B, cycles: 125, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I-- +lda #$06 PC: $E04D, cycles: 127, registers: [a: $06, x: $00, y: $00, sp: $FD], status: ----I-- +sta $8000 PC: $E050, cycles: 131, registers: [a: $06, x: $00, y: $00, sp: $FD], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$01 PC: $E052, cycles: 133, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I-- +sta $8001 PC: $E055, cycles: 137, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 1, R7: 1, PRG RAM enabled, writes allowed + + [STACK]: 57 E0 00 00 +jsr $8000 PC: $8000, cycles: 143, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- +inc $6000 PC: $8003, cycles: 149, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- + [STACK]: 00 00 +rts PC: $E058, cycles: 155, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I-- + [STACK]: 5A E0 00 00 +jsr $8000 PC: $8000, cycles: 161, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- +inc $6000 PC: $8003, cycles: 167, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- + [STACK]: 00 00 +rts PC: $E05B, cycles: 173, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I-- +rts PC: $E05C, cycles: 179, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I-- + + +== Memory dump == + +[$02FC] = $5A [reads=4, writes=4] +[$02FD] = $E0 [reads=4, writes=4] +[$6000] = $03 [reads=3, writes=3] diff --git a/tests/expected/runrom/mmc3-no-wram.txt b/tests/expected/runrom/mmc3-no-wram.txt new file mode 100644 index 0000000..fd4977e --- /dev/null +++ b/tests/expected/runrom/mmc3-no-wram.txt @@ -0,0 +1,71 @@ + PC: $E067, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I-- + [STACK]: 69 E0 00 00 +jsr $E000 PC: $E000, cycles: 13, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----I-- +bit $2002 PC: $E003, cycles: 17, registers: [a: $00, x: $00, y: $00, sp: $FB], status: N---IZ- +lda #$00 PC: $E005, cycles: 19, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $2006 PC: $E008, cycles: 23, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E00B, cycles: 27, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$10 PC: $E00D, cycles: 29, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- +sta $2006 PC: $E010, cycles: 33, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E013, cycles: 37, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$00 PC: $E015, cycles: 39, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $2006 PC: $E018, cycles: 43, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E01B, cycles: 47, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$10 PC: $E01D, cycles: 49, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- +sta $2006 PC: $E020, cycles: 53, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E023, cycles: 57, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$00 PC: $E025, cycles: 59, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $A000 PC: $E028, cycles: 63, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +sta $E000 PC: $E02B, cycles: 67, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$80 PC: $E02D, cycles: 69, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I-- +sta $A001 PC: $E030, cycles: 73, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$06 PC: $E032, cycles: 75, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I-- +sta $8000 PC: $E035, cycles: 79, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$00 PC: $E037, cycles: 81, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $8001 PC: $E03A, cycles: 85, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$07 PC: $E03C, cycles: 87, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I-- +sta $8000 PC: $E03F, cycles: 91, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$01 PC: $E041, cycles: 93, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- +sta $8001 PC: $E044, cycles: 97, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + + [STACK]: 00 00 +rts PC: $E06A, cycles: 103, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I-- +lda #$00 PC: $E06C, cycles: 105, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- +sta $A001 PC: $E06F, cycles: 109, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM disabled, writes allowed + +jmp $8000 PC: $8000, cycles: 112, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- +clc PC: $8001, cycles: 114, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- + +@: +adc $6000 PC: $8001, cycles: 114, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- +error: reading was not allowed on address '$6000' diff --git a/tests/expected/runrom/mmc3-no-writes.txt b/tests/expected/runrom/mmc3-no-writes.txt new file mode 100644 index 0000000..1dcb644 --- /dev/null +++ b/tests/expected/runrom/mmc3-no-writes.txt @@ -0,0 +1,72 @@ + PC: $E05C, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I-- + [STACK]: 5E E0 00 00 +jsr $E000 PC: $E000, cycles: 13, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----I-- +bit $2002 PC: $E003, cycles: 17, registers: [a: $00, x: $00, y: $00, sp: $FB], status: N---IZ- +lda #$00 PC: $E005, cycles: 19, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $2006 PC: $E008, cycles: 23, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E00B, cycles: 27, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$10 PC: $E00D, cycles: 29, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- +sta $2006 PC: $E010, cycles: 33, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E013, cycles: 37, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$00 PC: $E015, cycles: 39, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $2006 PC: $E018, cycles: 43, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E01B, cycles: 47, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$10 PC: $E01D, cycles: 49, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- +sta $2006 PC: $E020, cycles: 53, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +sta $2006 PC: $E023, cycles: 57, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I-- + [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00 + +lda #$00 PC: $E025, cycles: 59, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $A000 PC: $E028, cycles: 63, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +sta $E000 PC: $E02B, cycles: 67, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$80 PC: $E02D, cycles: 69, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I-- +sta $A001 PC: $E030, cycles: 73, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$06 PC: $E032, cycles: 75, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I-- +sta $8000 PC: $E035, cycles: 79, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$00 PC: $E037, cycles: 81, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- +sta $8001 PC: $E03A, cycles: 85, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$07 PC: $E03C, cycles: 87, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I-- +sta $8000 PC: $E03F, cycles: 91, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + +lda #$01 PC: $E041, cycles: 93, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- +sta $8001 PC: $E044, cycles: 97, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed + + [STACK]: 00 00 +rts PC: $E05F, cycles: 103, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I-- +lda #$C0 PC: $E061, cycles: 105, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I-- +sta $A001 PC: $E064, cycles: 109, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I-- + [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes disallowed + +jmp $8000 PC: $8000, cycles: 112, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I-- +clc PC: $8001, cycles: 114, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I-- +adc $6000 PC: $8004, cycles: 118, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I-- + +@: +sta $6000 PC: $8004, cycles: 118, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I-- +error: writing was not allowed on address '$6000' diff --git a/tests/runrom/mmc3/basic.s b/tests/runrom/mmc3/basic.s new file mode 100644 index 0000000..f97fe3f --- /dev/null +++ b/tests/runrom/mmc3/basic.s @@ -0,0 +1,241 @@ +.segment "HEADER" + .byte 'N', 'E', 'S', $1A + .byte $10, $10 + .byte $43 + .byte $08 + .byte $00 + .byte $00 + .byte $70 + .res $05, $00 + +.segment "TAIL" +;;; asan:stack full + +;;; TODO: into another segment, writing to WRAM clc; adc wr_whatever; sta wr_whatever; this is then called via different segments + +.scope PPU + m_status = $2002 + m_address = $2006 +.endscope + +.scope MMC3 + m_bank_select = $8000 + m_bank_data = $8001 + m_mirroring = $A000 + m_ram_protect = $A001 + m_irq_disable = $E000 +.endscope + +.macro BANK_REGISTER_SET REGISTER_ID, REGISTER_VALUE + lda #REGISTER_ID + sta MMC3::m_bank_select + lda #REGISTER_VALUE + sta MMC3::m_bank_data +.endmacro + +.proc regular_mmc3_init + ;; Init scanline counter. + bit PPU::m_status + + lda #$00 + sta PPU::m_address + sta PPU::m_address + lda #$10 + sta PPU::m_address + sta PPU::m_address + + lda #$00 + sta PPU::m_address + sta PPU::m_address + lda #$10 + sta PPU::m_address + sta PPU::m_address + + ;; Setup mirroring. + lda #$00 + sta MMC3::m_mirroring + + ;; Disable interrupts. + sta MMC3::m_irq_disable + + ;; Enable PRG RAM and allow writes to it. + lda #$80 + sta MMC3::m_ram_protect + + ;; PRG banking setup. + BANK_REGISTER_SET 6, 0 + BANK_REGISTER_SET 7, 1 + + rts +.endproc + +.proc basic + jsr regular_mmc3_init + + jsr foo ; asan:safe + + BANK_REGISTER_SET 6, 1 + + ;; NOTE: this is actually not safe, as it will call another_foo() instead :) + jsr foo ; asan:safe + + ;; NOTE: calling a different address but it's the same function as per the + ;; previous mapping :) + jsr another_foo ; asan:safe + + rts +.endproc + +.proc no_writes_allowed + jsr regular_mmc3_init + + lda #$C0 + sta MMC3::m_ram_protect + + jmp foo ; asan:safe +.endproc + +.proc no_wram + jsr regular_mmc3_init + + lda #$00 + sta MMC3::m_ram_protect + + jmp foo ; asan:safe +.endproc + +.proc reset + ;; NOTE: avoid warnings from unused functions. + jsr basic + jsr no_writes_allowed + jsr no_wram + + rts +.endproc + +.proc nmi + rti +.endproc + +.proc irq + rti +.endproc + +.segment "PRG0_00" + +wr_value = $6000 + +.proc foo + clc + adc wr_value + sta wr_value + rts +.endproc + +.segment "PRG0_01" + +.proc another_foo + inc wr_value + rts +.endproc + +.segment "CHARS" +.res $F000, $00 +.res $F000, $00 +.res $2000, $00 + +.segment "VECTORS" + .addr nmi, reset, irq + +.segment "PRG0_00" +.byte $00 + +.segment "PRG0_01" +.byte $00 + +.segment "PRG0_02" +.byte $00 + +.segment "PRG0_03" +.byte $00 + +.segment "PRG0_04" +.byte $00 + +.segment "PRG0_05" +.byte $00 + +.segment "PRG0_06" +.byte $00 + +.segment "PRG0_07" +.byte $00 + +.segment "PRG0_08" +.byte $00 + +.segment "PRG0_09" +.byte $00 + +.segment "PRG0_0A" +.byte $00 + +.segment "PRG0_0B" +.byte $00 + +.segment "PRG0_0C" +.byte $00 + +.segment "PRG0_0D" +.byte $00 + +.segment "PRG0_0E" +.byte $00 + +.segment "PRG1_00" +.byte $00 + +.segment "PRG1_01" +.byte $00 + +.segment "PRG1_02" +.byte $00 + +.segment "PRG1_03" +.byte $00 + +.segment "PRG1_04" +.byte $00 + +.segment "PRG1_05" +.byte $00 + +.segment "PRG1_06" +.byte $00 + +.segment "PRG1_07" +.byte $00 + +.segment "PRG1_08" +.byte $00 + +.segment "PRG1_09" +.byte $00 + +.segment "PRG1_0A" +.byte $00 + +.segment "PRG1_0B" +.byte $00 + +.segment "PRG1_0C" +.byte $00 + +.segment "PRG1_0D" +.byte $00 + +.segment "PRG1_0E" +.byte $00 + +.segment "FIXED" +.byte $00 diff --git a/tests/runrom/mmc3/mmc3.cfg b/tests/runrom/mmc3/mmc3.cfg new file mode 100644 index 0000000..56f6314 --- /dev/null +++ b/tests/runrom/mmc3/mmc3.cfg @@ -0,0 +1,92 @@ +MEMORY { + # iNES header + HEADER: file = %O, start = $0000, size = $0010, fill = yes; + + # First 15 switchable banks at $8000. + PRG0_00: start = $8000, size = $2000, file = %O, fill = yes, fillval = $00; + PRG0_01: start = $8000, size = $2000, file = %O, fill = yes, fillval = $01; + PRG0_02: start = $8000, size = $2000, file = %O, fill = yes, fillval = $02; + PRG0_03: start = $8000, size = $2000, file = %O, fill = yes, fillval = $03; + PRG0_04: start = $8000, size = $2000, file = %O, fill = yes, fillval = $04; + PRG0_05: start = $8000, size = $2000, file = %O, fill = yes, fillval = $05; + PRG0_06: start = $8000, size = $2000, file = %O, fill = yes, fillval = $06; + PRG0_07: start = $8000, size = $2000, file = %O, fill = yes, fillval = $07; + PRG0_08: start = $8000, size = $2000, file = %O, fill = yes, fillval = $08; + PRG0_09: start = $8000, size = $2000, file = %O, fill = yes, fillval = $09; + PRG0_0A: start = $8000, size = $2000, file = %O, fill = yes, fillval = $0A; + PRG0_0B: start = $8000, size = $2000, file = %O, fill = yes, fillval = $0B; + PRG0_0C: start = $8000, size = $2000, file = %O, fill = yes, fillval = $0C; + PRG0_0D: start = $8000, size = $2000, file = %O, fill = yes, fillval = $0D; + PRG0_0E: start = $8000, size = $2000, file = %O, fill = yes, fillval = $0E; + + # Last 15 switchable banks at $A000. + PRG1_00: start = $A000, size = $2000, file = %O, fill = yes, fillval = $10; + PRG1_01: start = $A000, size = $2000, file = %O, fill = yes, fillval = $11; + PRG1_02: start = $A000, size = $2000, file = %O, fill = yes, fillval = $12; + PRG1_03: start = $A000, size = $2000, file = %O, fill = yes, fillval = $13; + PRG1_04: start = $A000, size = $2000, file = %O, fill = yes, fillval = $14; + PRG1_05: start = $A000, size = $2000, file = %O, fill = yes, fillval = $15; + PRG1_06: start = $A000, size = $2000, file = %O, fill = yes, fillval = $16; + PRG1_07: start = $A000, size = $2000, file = %O, fill = yes, fillval = $17; + PRG1_08: start = $A000, size = $2000, file = %O, fill = yes, fillval = $18; + PRG1_09: start = $A000, size = $2000, file = %O, fill = yes, fillval = $19; + PRG1_0A: start = $A000, size = $2000, file = %O, fill = yes, fillval = $1A; + PRG1_0B: start = $A000, size = $2000, file = %O, fill = yes, fillval = $1B; + PRG1_0C: start = $A000, size = $2000, file = %O, fill = yes, fillval = $1C; + PRG1_0D: start = $A000, size = $2000, file = %O, fill = yes, fillval = $1D; + PRG1_0E: start = $A000, size = $2000, file = %O, fill = yes, fillval = $1E; + + # Last two fixed banks + vectors. + FIXED: start = $C000, size = $2000, fill = yes, fillval = $FA, define = yes; + TAIL: start = $E000, size = $1FFA, fill = yes, fillval = $FB, define = yes; + ROMV: start = $FFFA, size = $0006, fill = yes, fillval = $FC, define = yes; + + # CHR ROM. + CHARS: start = $0000, size = $20000, file = %O, fill = no; +} + +SEGMENTS { + HEADER: load = HEADER, type = ro; + + # 15 first switchable banks. + PRG0_00: load = PRG0_00, type = ro; + PRG0_01: load = PRG0_01, type = ro; + PRG0_02: load = PRG0_02, type = ro; + PRG0_03: load = PRG0_03, type = ro; + PRG0_04: load = PRG0_04, type = ro; + PRG0_05: load = PRG0_05, type = ro; + PRG0_06: load = PRG0_06, type = ro; + PRG0_07: load = PRG0_07, type = ro; + PRG0_08: load = PRG0_08, type = ro; + PRG0_09: load = PRG0_09, type = ro; + PRG0_0A: load = PRG0_0A, type = ro; + PRG0_0B: load = PRG0_0B, type = ro; + PRG0_0C: load = PRG0_0C, type = ro; + PRG0_0D: load = PRG0_0D, type = ro; + PRG0_0E: load = PRG0_0E, type = ro; + + # 15 last switchable banks. + PRG1_00: load = PRG1_00, type = ro; + PRG1_01: load = PRG1_01, type = ro; + PRG1_02: load = PRG1_02, type = ro; + PRG1_03: load = PRG1_03, type = ro; + PRG1_04: load = PRG1_04, type = ro; + PRG1_05: load = PRG1_05, type = ro; + PRG1_06: load = PRG1_06, type = ro; + PRG1_07: load = PRG1_07, type = ro; + PRG1_08: load = PRG1_08, type = ro; + PRG1_09: load = PRG1_09, type = ro; + PRG1_0A: load = PRG1_0A, type = ro; + PRG1_0B: load = PRG1_0B, type = ro; + PRG1_0C: load = PRG1_0C, type = ro; + PRG1_0D: load = PRG1_0D, type = ro; + PRG1_0E: load = PRG1_0E, type = ro; + + # Last two fixed banks + vectors. + FIXED: load = FIXED, type = ro; + TAIL: load = TAIL, type = ro; + VECTORS: load = ROMV, type = ro; + + # CHR-ROM is groupped all together. + CHARS: load = CHARS, type = ro; +} -- cgit v1.2.3