Question about implementing MMC1 in NESDEV...

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
PacManPlus
Posts: 26
Joined: Mon Jun 20, 2016 7:56 am

Question about implementing MMC1 in NESDEV...

Post by PacManPlus »

Hi all!

I have a question for you, if I may:

My goal is to have a 128K PRG / 16K CHR game made, with 16K banked at $8000-$BFFF ($C000-$FFFF is fixed).

I have the Mapper control byte at #%00001100. This is my RESET VECTOR:

Code: Select all

RESET:
	SEI											; DISABLE IRQS
	CLD											; DISABLE DECIMAL MODE

	LDA #$80									; THIS LOCKS THE PRG ROM AT $C000-$FFFF TO THE LAST BANK.
	STA $8000
 
	LDX #$40
	STX $4017									; DISABLE APU FRAME IRQ
	LDX #$FF
	TXS											; SET UP STACK
	INX											; NOW X = 0
	STX $2000									; DISABLE NMI
	STX $2001									; DISABLE RENDERING
	STX $4010									; DISABLE DMC IRQS
What I don't know, is how to arrange the .BANKs in my source file.
Do I start this way:

Code: Select all

.BANK 0
.ORG $C000
(program code & data)

.BANK 1
.ORG $E000
(program code & data)

.BANK 2
.ORG $8000
(data)

.BANK 3
.ORG $A000
(data)

.BANK 4
.ORG $8000
(data)

.BANK 5
.ORG $A000
(data)

(etc.)
(which doesn't make sense to me because it is out of order)

Or like this:

Code: Select all

.BANK 0
.ORG $8000
(data)

.BANK 1
.ORG $A000
(data)

.BANK 2
.ORG $C000
(program code & data)

.BANK 3
.ORG $E000
(program code & data)

.BANK 4
.ORG $8000
(data)

.BANK 5
.ORG $A000
(data)

(etc.)
I have this link that gives an example on how to do the actual bank switch: https://wiki.nesdev.com/w/index.php/Programming_MMC1
Seems simple enough.

I have to say, bank switching on the Atari 7800 is so simple. You just write the bank number to any address from $8000-$BFFF. That's all. :(

Thank you for your help!
Bob
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Question about implementing MMC1 in NESDEV...

Post by tepples »

Bank switching on UNROM is almost as simple as on the 7800. But because you're using both CHR ROM larger than 8K and PRG ROM larger than 32K, you need to switch both PRG ROM and CHR ROM. Can you reduce your game's PRG size to about 104K so that you can decompress CHR data from PRG ROM to CHR RAM at runtime and thus not have to switch CHR ROM?
User avatar
PacManPlus
Posts: 26
Joined: Mon Jun 20, 2016 7:56 am

Re: Question about implementing MMC1 in NESDEV...

Post by PacManPlus »

tepples wrote:Bank switching on UNROM is almost as simple as on the 7800. But because you're using both CHR ROM larger than 8K and PRG ROM larger than 32K, you need to switch both PRG ROM and CHR ROM. Can you reduce your game's PRG size to about 104K so that you can decompress CHR data from PRG ROM to CHR RAM at runtime and thus not have to switch CHR ROM?
Absolutely, as the extra banks are just for tile/sound data and I overestimated what I needed just to be on the safe side...
But I've never had to work with CHR data like that on the NES and have no idea how to do it. :( Is there a 'name' for that so I know what to search for?

Also, which order do I put the banks in (using my examples from above)?

Thank you, thank you.
Bob
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Question about implementing MMC1 in NESDEV...

Post by tokumaru »

PacManPlus wrote:Also, which order do I put the banks in (using my examples from above)?
Alternate $8000 and $A000 banks as many times as needed, and make the last two $C000 and $E000, which will be the fixed ones.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Question about implementing MMC1 in NESDEV...

Post by tepples »

PacManPlus wrote:
tepples wrote:Bank switching on UNROM is almost as simple as on the 7800. [...] Can you reduce your game's PRG size to about 104K so that you can decompress CHR data from PRG ROM to CHR RAM at runtime and thus not have to switch CHR ROM?
I've never had to work with CHR data like that on the NES and have no idea how to do it. :( Is there a 'name' for that so I know what to search for?
See Tile compression, Programming UNROM, and CHR ROM vs. CHR RAM.
User avatar
PacManPlus
Posts: 26
Joined: Mon Jun 20, 2016 7:56 am

Re: Question about implementing MMC1 in NESDEV...

Post by PacManPlus »

Thank you!

You've given me something to go on. :)
Post Reply