Regarding CHR banks for MMC3

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
User avatar
raydempsey
Posts: 160
Joined: Sat May 31, 2014 4:12 pm

Regarding CHR banks for MMC3

Post by raydempsey »

I am using the MMC3 mapper and compiling with NESASM3. I am using the following iNES header:

Code: Select all

  .inesmap 4   ; mapper 4 = MMC3
  .inesprg 8
  .ineschr 8
  .inesmir 3   ; background mirroring
I set up my MMC3 settings with the following:

Code: Select all

LDA #%01000010
STA $8000
this write says that I will be using two 2 KB banks at PPU $0000-$0FFF, and four 1 KB banks at PPU $1000-$1FFF which is what I want. Also, this write sets up my next write so that I am about to bank switch the 1 KB bank at PPU $1000-$13FF with whatever bank number I select to write to $8001.

I have a single 32K .chr file I'm including for all my graphics. Also, since I have selected .inesprg 8, then I understand that banks 0 through 15 are for the CPU. I have included the file by this method:

Code: Select all

  .bank 16
  .org $0000
  .incbin "tiles.chr"
Question: Under the settings I have, what bank numbers represent which sections of my tiles.chr? For example, how could I take the information at $4000-$43FF of my tiles.chr and bank switch that into the PPU at say, PPU $1000-$13FF?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Regarding CHR banks for MMC3

Post by tokumaru »

NESASM can be kinda weird sometimes... I believe that the .bank statements are mandatory every 8KB, so maybe including a 32KB CHR file at once might not work. I can't tell for sure, since I don't use this assembler, so hopefully someone else will confirm this.
raydempsey wrote:Question: Under the settings I have, what bank numbers represent which sections of my tiles.chr? For example, how could I take the information at $4000-$43FF of my tiles.chr and bank switch that into the PPU at say, PPU $1000-$13FF?
You select the target location for the tiles by writing to $8000. If your goal is to map the tiles to $1000-$13FF, that would mean that you have the second pattern table broken up in 4 1KB chunks, and you should set the lower 3 bits of the $8000 write to 010 (2), to tell the mapper you'll be mapping tiles into the first 1Kb slot. Then simply write the bank index to $8001. Since you want the bank located $4000 bytes into the CHR file, and each bank is 1KB ($400 bytes) large, the bank number is $4000 / $400 = $10, or 16 in decimal. When bankswitching 2KB CHR banks, the lower bit of the bank index is ignored. This means that to select the third 2KB bank, you'll not be writing 3 to $8001, you'll write 6, because the banks are twice as large as the 1KB ones.

All of this is written in the wiki page, be sure to check it out if you haven't already: http://wiki.nesdev.com/w/index.php/MMC3
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Regarding CHR banks for MMC3

Post by thefox »

tokumaru wrote:NESASM can be kinda weird sometimes... I believe that the .bank statements are mandatory every 8KB, so maybe including a 32KB CHR file at once might not work. I can't tell for sure, since I don't use this assembler, so hopefully someone else will confirm this.
From what I can remember including it all at once won't work. NESASM is also really shitty with error messages in situations like this. I believe hearing this "bank crossing" works in zzo38's modified version of NESASM, although I haven't used it myself.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Denine
Posts: 397
Joined: Wed Feb 17, 2010 5:42 pm

Re: Regarding CHR banks for MMC3

Post by Denine »

thefox wrote:From what I can remember including it all at once won't work. NESASM is also really shitty with error messages in situations like this. I believe hearing this "bank crossing" works in zzo38's modified version of NESASM, although I haven't used it myself.
I'm using a NESASM all the time and I can say with all confidence it does work. Even more-I'm making a MMC3 project right now. The "bank crossing" applies only to code, not data. Getting the right Bank number can be hard if you have a big chr, however, so I would split it.
Question: Under the settings I have, what bank numbers represent which sections of my tiles.chr?
You start from zero. So if you write 0 to $8001 as your bank number, then the beggining of the chr data will be used and placed into ppu. How many tiles and where exactly depends on $8000 setting.
For example, how could I take the information at $4000-$43FF of my tiles.chr and bank switch that into the PPU at say, PPU $1000-$13FF?

Code: Select all

lda #%00000010
sta $8000                    ; So our piece of chr will be put into $1000-$13FF in ppu

lda #$10
sta $8001                    ;Take our piece of chr data and put it into ppu.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Regarding CHR banks for MMC3

Post by thefox »

Denine wrote:I'm using a NESASM all the time and I can say with all confidence it does work. Even more-I'm making a MMC3 project right now. The "bank crossing" applies only to code, not data. Getting the right Bank number can be hard if you have a big chr, however, so I would split it.
Ah, I stand corrected. It's kind of quirky because NESASM allows overwriting data in existing banks. I guess that feature also makes it impossible to report bank overflows.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Denine
Posts: 397
Joined: Wed Feb 17, 2010 5:42 pm

Re: Regarding CHR banks for MMC3

Post by Denine »

thefox wrote:
Denine wrote:I'm using a NESASM all the time and I can say with all confidence it does work. Even more-I'm making a MMC3 project right now. The "bank crossing" applies only to code, not data. Getting the right Bank number can be hard if you have a big chr, however, so I would split it.
Ah, I stand corrected. It's kind of quirky because NESASM allows overwriting data in existing banks. I guess that feature also makes it impossible to report bank overflows.
I just double checked that. NESASM reports happen for the code and for byte\word declarations like .db or .dw. There is no reports for .incbin where included binary file is bigger than space left in the current bank.
The overwriting data in existing banks is not completly correct. The included binary file will be included as a whole if there is no next bank declaration.
For example, our "example.bin" is 16kb in size.

Code: Select all

.bank 0
 .org $8000
 .incbin "example.bin"

 .bank 2
 .org $C000
;anything in here

 .bank 3
 .org $E000
;anything in here
In example above, the example.bin will be included, first half will be in bank 0, the other one in bank 1.

But if you declare bank 1 existance...

Code: Select all

.bank 0
 .org $8000
 .incbin "example.bin"

 .bank 1
 .org $A000
;anything in here

 .bank 2
 .org $C000
;anything in here

 .bank 3
 .org $E000
;anything in here
Then only first 8kb will be included , the other half of the "example.bin" will be cut and removed. There will be no report of the overflow as well :\
zzo38
Posts: 1096
Joined: Mon Feb 07, 2011 12:46 pm

Re: Regarding CHR banks for MMC3

Post by zzo38 »

Denine wrote:
thefox wrote:
Denine wrote:I'm using a NESASM all the time and I can say with all confidence it does work. Even more-I'm making a MMC3 project right now. The "bank crossing" applies only to code, not data. Getting the right Bank number can be hard if you have a big chr, however, so I would split it.
Ah, I stand corrected. It's kind of quirky because NESASM allows overwriting data in existing banks. I guess that feature also makes it impossible to report bank overflows.
I just double checked that. NESASM reports happen for the code and for byte\word declarations like .db or .dw. There is no reports for .incbin where included binary file is bigger than space left in the current bank.
Yes, the "bank crossing" features are only needed if you are using something other than INCBIN. (To use my "bank crossing" feature, you have to assign several consecutive banks the same name. This must be done before any code is entered, otherwise it won't be detected properly.)
Then only first 8kb will be included , the other half of the "example.bin" will be cut and removed. There will be no report of the overflow as well :\
It is then overwritten by other code (which can sometimes be useful). Something which I don't know if it is possible in normal NESASM or only in my version (I haven't checked), is you could make a macro to report INCBIN overflows if you want to (by using the FAIL command).
(Free Hero Mesh - FOSS puzzle game engine)
sdm
Posts: 410
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Re: Regarding CHR banks for MMC3

Post by sdm »

Does NESASM3 have the ability to define 1KB CHR banks or do they always have 8KB?
Recently I tried to do test namco163 ROM and set the CHR banks. Unfortunately nothing works (Graphics are not displayed).

Code: Select all

	.inesprg 8
	.ineschr 2
	.inesmap 19
	.inesmir 0

Code: Select all


	.bank 16
	.org $0000

TileSet0:

	.incbin "demo.spr0"
	.org $0400
	.incbin "demo.spr1"
	.org $0800
	.incbin "demo.spr2"
	.org $0C00
	.incbin "demo.spr3"

	.org $1000
	.incbin "demo.spr0"
	.org $1400
	.incbin "demo.spr1"
	.org $1800
	.incbin "demo.spr2"
	.org $1C00
	.incbin "demo.spr3"

	.bank 17
	.org $0000

TileSet1:

	.incbin "demo.spr0"      ;1kb
	.org $0400
	.incbin "demo.spr1"
	.org $0800
	.incbin "demo.spr2"
	.org $0C00
	.incbin "demo.spr3"

	.org $1000
	.incbin "demo.spr0"
	.org $1400
	.incbin "demo.spr1"
	.org $1800
	.incbin "demo.spr2"
	.org $1C00
	.incbin "demo.spr3"
For now I do not know if in NESASM3 I have to set the addresses (.org) CHR banks every 1KB, or maybe they must always be 8KB size and only the mapper will notice and will automatically divide the banks by 1KB?

Code: Select all

	.bank 16
	.org $0000

TileSet0:

	.incbin "demo.spr"
	.incbin "demo.chr"

	.bank 17
	.org $0000

TileSet1:

	.incbin "demo.spr"
	.incbin "demo.chr"
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Regarding CHR banks for MMC3

Post by Kasumi »

Here's two banks of what I did in Indivisible:

Code: Select all

	.bank NUMPRGBANKS+6
	.org $0000
	
	.incbin "Data/ObjectCHR/ManoteThihaCHR/block7.chr"
	.incbin "Data/ObjectCHR/ManoteThihaCHR/block8.chr"
	
	.incbin "Data/ObjectCHR/ManoteThihaCHR/block9.chr"
HUNGRYGHOSTCHRSTART = MANOTETHIHACHRSTART+10
	.incbin "Data/ObjectCHR/HungryGhostCHR/block0.chr"
	

	
	
	.incbin "Data/ObjectCHR/HungryGhostCHR/block1.chr"
	.incbin "Data/ObjectCHR/HungryGhostCHR/block2.chr"
AHPCHRSTART = HUNGRYGHOSTCHRSTART+3
	.incbin "Data/ObjectCHR/AhpCHR/block0.chr"
	.incbin "Data/ObjectCHR/AhpCHR/block1.chr"
	
	.bank NUMPRGBANKS+7
	.org $0000
	
	.incbin "Data/ObjectCHR/AhpCHR/block2.chr"
BELUCHRSTART = AHPCHRSTART+3
	.incbin "Data/ObjectCHR/BeluCHR/block0.chr"
	
	.incbin "Data/ObjectCHR/BeluCHR/block1.chr"
	.incbin "Data/ObjectCHR/BeluCHR/block2.chr"
	
	
	
	
	
	.incbin "Data/ObjectCHR/BeluCHR/block3.chr"
	.incbin "Data/ObjectCHR/BeluCHR/block4.chr"
	.incbin "Data/ObjectCHR/BeluCHR/block5.chr"
	.incbin "Data/ObjectCHR/BeluCHR/block6.chr"
Each "block" is a 1KB file. You don't need the
"HUNGRYGHOSTCHRSTART = MANOTETHIHACHRSTART+10"
type lines, that's for the engine to access the right data.

edit: So basically: Banks are always 8KB, but you can totally just include eight 1KB files. (or four 2KB etc.) files. You only need to .org once. This is what my backgrounds looked like:

Code: Select all

	.bank NUMPRGBANKS
	.org $0000
	
BACKGROUNDCHRSTART = 0

FONTCHRSTART = BACKGROUNDCHRSTART
	.incbin "Data/BackgroundCHR/font001.chr";2
	
TITLESCREENCHRSTART = FONTCHRSTART+2
	.incbin "Data/BackgroundCHR/Title_0.chr";2
LOGOCHRSTART = TITLESCREENCHRSTART+2
	.incbin "Data/BackgroundCHR/Title_1.chr";2
	.incbin "Data/BackgroundCHR/Title_2.chr";2
The mapper doesn't care what you do, really. I could combine eight 1KB files into one 8KB file and incbin that, and it wouldn't change what the NES or mapper sees.

Did you write the correct numbers for the data you wanted to the registers for the mapper? Is your reset routine in $E000-$FFFF in the last PRG bank?
sdm
Posts: 410
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Re: Regarding CHR banks for MMC3

Post by sdm »

I had a code reset at bank0. Now it's ok. Thanks :)

Code: Select all


TileSet0:

	.incbin "demo.spr"
	.incbin "demo.chr"


	.bank 17
	.org $0000

TileSet1:


	.incbin "demo.spr"
	.incbin "demo.chr"
Post Reply