Programming MMC1: Difference between revisions

From NESdev Wiki
Jump to navigationJump to search
(→‎Quick setup for UNROM style: Split section about PRG banks and added how to make the code work everywhere with a 16-byte stub)
(→‎PRG banks: I disassembled Barbie and it does the same thing)
Line 21: Line 21:
Some revisions of the MMC1 IC might power up in a mode other than fixed-$C000, requiring that the vectors and the start of the [[init code]] be placed in all banks, much as in [[BxROM]] or [[AxROM]] or [[GxROM]].
Some revisions of the MMC1 IC might power up in a mode other than fixed-$C000, requiring that the vectors and the start of the [[init code]] be placed in all banks, much as in [[BxROM]] or [[AxROM]] or [[GxROM]].
Other revisions guarantee that the fixed bank is loaded at power on.
Other revisions guarantee that the fixed bank is loaded at power on.
To make sure your code works on all MMC1 revisions, put the following code in the last 16 bytes of each 16384 byte bank:
To make sure your code works on all MMC1 revisions, put the following code in the last 16 bytes of each 16384 byte bank. (Barbie uses almost identical code.)
<pre>
<pre>
reset_stub:
reset_stub:
   sei
   sei
  cld
   ldx #$80  ; reset the mapper
   ldx #$80  ; reset the mapper
   stx $E000
   stx $E000
  cld
   jmp reset  ; must be in $C000-$FFED
   jmp reset  ; must be in $C000-$FFED
   .addr nmiHandler, reset_stub, irqHandler
   .addr nmiHandler, reset_stub, irqHandler

Revision as of 18:47, 20 July 2010

MMC1 was Nintendo's first ASIC mapper for the NES.

Quick setup for UNROM style

If you are using the SGROM or SNROM board to provide an environment similar to UNROM, with 8 KB of CHR RAM, a fixed PRG ROM bank at $C000, and a 16 KB switchable PRG ROM bank at $8000, do this in your init code after the mapper has been reset:

  lda #$0E   ; vertical mirroring, fixed $C000, 8 KB CHR pages
  sta $8000  ; (use $0F instead for horizontal mirroring)
  lsr a
  sta $8000
  lsr a
  sta $8000
  lsr a
  sta $8000
  lsr a
  sta $8000

Games that use CHR RAM switch to another PRG bank before they copy tile data into CHR RAM.

PRG banks

Some revisions of the MMC1 IC might power up in a mode other than fixed-$C000, requiring that the vectors and the start of the init code be placed in all banks, much as in BxROM or AxROM or GxROM. Other revisions guarantee that the fixed bank is loaded at power on. To make sure your code works on all MMC1 revisions, put the following code in the last 16 bytes of each 16384 byte bank. (Barbie uses almost identical code.)

reset_stub:
  sei
  ldx #$80   ; reset the mapper
  stx $E000
  cld
  jmp reset  ; must be in $C000-$FFED
  .addr nmiHandler, reset_stub, irqHandler

Then to switch PRG ROM banks, load the bank number (0-15) into A and call this subroutine:

mmc1_load_prg_bank:
  sta $E000
  lsr a
  sta $E000
  lsr a
  sta $E000
  lsr a
  sta $E000
  lsr a
  sta $E000
  rts

See also

  • MMC1 technical reference