MMC3 PRG banks on reset

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

MMC3 PRG banks on reset

Post by Celius »

So I know that the MMC3 works with 8k banks and that there are two different bankswitching modes. I know that $E000-$FFFF will always be the last 8k of ROM, and either $C000-$DFFF or $8000-$9FFF will be the second to last depending on the PRG mode.

I'm wondering about the state of the banks on reset. Is it unpredictable/random? I want to put my reset code in $C000-$FFFF, and I think always keep it on mode 0. In order to be safe, will I have to make the reset address somewhere in $E000-$FFFF and then turn on mode 0, at which point I will jump somewhere in $C000-$DFFF? Or is the PRG mode by default 0 on reset, in which case I could make the reset address $C000-$DFFF safely?
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: MMC3 PRG banks on reset

Post by tepples »

Celius wrote:I'm wondering about the state of the banks on reset. Is it unpredictable/random? I want to put my reset code in $C000-$FFFF, and I think always keep it on mode 0. In order to be safe, will I have to make the reset address somewhere in $E000-$FFFF and then turn on mode 0, at which point I will jump somewhere in $C000-$DFFF?
That'd be the safest way. I'd toss something like this next to the vectors (untested):

Code: Select all

PPUCTRL = $2000
PPUMASK = $2001
MMC3CTRL = $8000
MMC3BANK = $8001
MMC3IRQOFF = $E000
P2 = $4017
.segment "ROM_FFE0"
reset:
  sei
  ldx #0
  stx PPUCTRL  ; disable nmi
  stx PPUMASK  ; disable rendering (and mmc3 irq)
  stx MMC3IRQOFF  ; ack/disable mmc3 irq
  stx MMC3CTRL  ; set normal banking mode
  dex

  txs
  lda #$40
  sta P2  ; ack/disable apu frame irq
  jmp main
  .pad (reset+$1A)-*
  .addr nmi, reset, irq
But then I don't know why you're using $C000-$DFFF as a fixed bank. If you use $8000-$9FFF as a fixed bank, you can bankswitch DPCM samples.
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

Okay, I guess I'll have to implement that then. It's okay though; my current projects aren't at all in their final stages.

I guess I never thought about the advantages of using $8000-$9FFF as the fixed bank. But thank you for mentioning that, I will definitely reconsider why I use $C000-$DFFF as fixed. I guess I wanted to be able to treat it as one big 16k bank, but then again, I can have:

$9FFD: JMP $E000

which would only cost 3 cycles. It would just not have to be in the middle of any timed code.
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

But then I don't know why you're using $C000-$DFFF as a fixed bank. If you use $8000-$9FFF as a fixed bank, you can bankswitch DPCM samples.
You may not want to waste a whole 8kb bank area of memory to be constantly dedicated to samples, leaving only $a000-$bfff as "normal" bankswitched mem.
Also, there is many you may want to use vitrual 16kb banks, having the last 16kb always at $c000-$ffff and banskwitch two consecutive banks at $8000-$bfff, having the more standard U*ROM configuration.

With WLA-DX, if you want the Reset code to be in $e000-$ffff, you'd have to do something like that :

Code: Select all

.org $e000
.section RESET SEMIFREE
sei
cld
.....
MainLoop
 jsr WaitVBl
 jsr Gameplay
  lda GameOver
  bne +
 jmp MainLoop
 + jmp GameOver
.ends
Just a quick example, normally, the semifree section guarantees it's in the $e000-$ffff range while normal free sections will be $c000-$ffff freely. Hopefully that should work.

Also, if you can do test on real MMC3 cards and proof experimentally that $c000-$dfff are always the second last bank at power on, then you are legit to use that to your advantage. It would have to be tested on all revisions of MMC3 to be safe tough. Also this may or may not break compatibility with emulators and powerpak.
Useless, lumbering half-wits don't scare us.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Or someone could write a program to search a folder full of commercial iNES ROMs for the reset vectors of anything mapper 4. If no commercial games use something, it's likely that Nintendo had a good reason to ban it in the lot check guidelines.
User avatar
beneficii
Posts: 127
Joined: Tue Jul 12, 2005 4:37 pm

Post by beneficii »

Isn't it undefined at startup whether the first fixed bank is located at $c000-$dfff or $8000-$9fff?
Post Reply