diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-10-16 23:32:36 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-10-16 23:32:36 +0200 |
| commit | 57a15f9385560308e5ac05aa057f3bcb1df22824 (patch) | |
| tree | b14933709f202f25acf86bef80b4fe5f2c76d4e3 /tests/runrom | |
| parent | 4fc97089734c713725295b76b23510a7b13f3c3d (diff) | |
| download | tools.nes-57a15f9385560308e5ac05aa057f3bcb1df22824.tar.gz tools.nes-57a15f9385560308e5ac05aa057f3bcb1df22824.zip | |
runrom: add support for the MMC3 chip
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à <mssola@mssola.com>
Diffstat (limited to 'tests/runrom')
| -rw-r--r-- | tests/runrom/mmc3/basic.s | 241 | ||||
| -rw-r--r-- | tests/runrom/mmc3/mmc3.cfg | 92 |
2 files changed, 333 insertions, 0 deletions
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; +} |
