mmc1 character bank swaping

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
mmc1 character bank swaping
by on (#16799)
i read the wiki and the doc that is linked at the bottom. it only seems to describe how the program banks are switched. is there any info on how the character banks are switched? i am working on mmc1 now and some games are playable (only because i am familiar with the game) but all the tiles are wrong. most of the colors are close.

matt

by on (#16806)
http://nesdevwiki.ath.cx/index.php/MMC1 <--- looks like it describes CHR swapping to me.

Anyway:

When in 8k mode ($8000.4 clear), reg $A000 controls the 8k page swapped in at ppu$0000 (ignore the low bit in this mode -- ie, the value right shift 1 is the actual 8k page number)

When in 4k mode ($8000.4 set), reg $A000 controls the 4k page swapped in at ppu$0000, and reg $C000 controls the 4k page swapped in at ppu$1000

by on (#16810)
i suppose i was referring to what happens when there is a change on reg 0. http://nesdev.com/mmc1.txt explains what happens when reg 0 changes and how it effects the program banks. some games look fine and some have messed up graphics.

zelda messed up
zelda2 ok
metroid kinda messed up
rc pro am messed up
double dragon ok
tetris ok
castlevania2 ok, but background shakes up and down.
bionic commando messed up
blast master ok
dragon warrior ok
final fantisy messed up
kid icarus messed up

messed up only means that it apears that the wrong tiles are used. sorry if this is a long list. i been trying to figure it out for a few weeks now.

thanks for any suggestions

matt

by on (#16812)
Looks to me like most of the games you list as being messed up use CHR-RAM (except RC Pro-AM, I think, I'm just going from memory), so they wouldn't use CHR switching at all.

by on (#16815)
i think that was it. a quick hack and zelda, metroid, final fantasy, and bionic commando looked alot better.

thanks !!

matt

by on (#16819)
mattmatteh wrote:
i suppose i was referring to what happens when there is a change on reg 0.


Changing the mode simply changes how the CHR regs are applied. The behavior can be inferred from the page on the wiki.

Remember that no actual "swap" takes place... it's just the mapper replacing the high address bits with an internal register. The order the regs are written does not matter in the end... ultimately, it comes down to the contents of the registers.

At ANY time bit 4 of reg 0 is clear, reg 1 is used as the 8k page number, and at any time bit 4 of reg 0 is set, regs 1 and 2 will be used as the 4k page number.


In an emulator, if you use a "swap" style approach, you will have to reswap everything on a reg 0 write if the mode changes. Many emus do this by having a "sync" function:

Code:
void Sync()
{
  if(reg0 & 0x10)   // 4k mode
  {
    SwapCHR_4k(0x0000,reg1);
    SwapCHR_4k(0x1000,reg2);
  }
  else    // 8k mode
    SwapCHR_8k(0x0000,reg1 >> 1);
}


Then all Sync on every related reg write (in this case, regs 0-2)



Many mappers operate this way (MMC3 and MMC5 included). Mode changes often have an immediate effect and will need to have things reswapped using the contents of each register.

by on (#16821)
Suggestion: end the potential confusion and u the word "select" in place of "swap". We are the word makers, the dreamers of dreams. If you select something again, nothing changes. If you swap something twice, you get back to the original. Swap implies more state than exists, while select doesn't.

by on (#16950)
Quote:
think that was it. a quick hack and zelda, metroid, final fantasy, and bionic commando looked alot better.

What did you do? Metroid looks fine until I start the actual game then everything is filled with a single tile.

I still don't exactly understand what happens when CHR selecting occurs if CHR-RAM is used.

thanks

by on (#16951)
blargg wrote:
Suggestion: end the potential confusion and u the word "select" in place of "swap".

Unless you're trying to run an emulator on a machine with less RAM than the ROM that you're trying to run. Then you have to load the ROM as a swap file. But I'm glad that Dwedit managed to get so much of the NES library playable in PocketNES on the GBA Movie Player.

by on (#16959)
Quote:
Metroid looks fine until I start the actual game then everything is filled with a single tile.


Are you sure this isn't a nametable mirroring issue? Double-check your MMC1 mirroring code to make sure it's doing things right.

EDIT -- actually, in retrospect I doubt this is the issue, but it can't hurt to check it anyway.

n6 wrote:
I still don't exactly understand what happens when CHR selecting occurs if CHR-RAM is used.


The same thing. Just instead of ROM, it's RAM.

Most MMC1 games with CHR-RAM will just throw the mapper into 8k mode, and maybe write 0 to the CHR regs once at startup, then just leave it like that forever.


Some games for other mappers (notably: Lagrange Point) will actually require that you have CHR-RAM selectable just as if it were CHR-ROM

by on (#16963)
Nope, it wasnt the nametable... about the same thing happens with ff1, when the game starts the airship appears in a green area.

here is screenshots from both games:
http://www.nancy-6.com/me.bmp
http://www.nancy-6.com/ff.bmp

in ff its like in metroid when you have selected your names and the game is about to start, this happens.

I can see that bit4 of register 3 is written to, actually I dont exactly understand what it is, is it important for these games?

by on (#16985)
On a side note: .bmp? No .bmp has any place on the internet.

On the actual note:

I don't really see how this could be a CHR problem -- something else seems to be going terribly wrong here. Metroid shows doors (which appear to be sprites) on both the left and right sides of the screen ... when in fact there are NO doors at that point in the game. So the game is drawing doors when it shouldn't be... which is a big red flag saying "hey, the game code isn't executing properly"


Have you passed the nestest ROM and/or the CPU portion of NEStress?

Quote:
I can see that bit4 of register 3 is written to, actually I dont exactly understand what it is, is it important for these games?


I don't think bit 4 of reg 3 is EVER set in Metroid or Final Fantasy.

Sounding more and more like a CPU bug.

What it does, though, is when set, it will make the cartridge RAM at $6000-7FFF inaccessable. If set and the game tries to write there, the writes will do nothing ... and reads will get open bus.

by on (#16991)
nestest passes, the nestress cursor doesnt appear and I can't select so I can just run the PPU test, but I also think it is a CPU-bug more then a mapperbug I'll look through the opcodes once again, thanks

by on (#16996)
if nestest passes, why do you think it is a cpu bug ?

if the nestress cursor doest appear, dont you think that might be a problem worth fixing ?

have you gotten any of blargg's test to work ? you might have a bug in the ppu and/or sprites.

also, you might want to start another thread if its off topic.

matt

by on (#16997)
Quote:
if nestest passes, why do you think it is a cpu bug ?

1. The behaviour looks more like a read/write error more then a rendering problem I think.
2. because nestest have passed earlier even cause it was bugs.

Quote:
if the nestress cursor doest appear, dont you think that might be a problem worth fixing ?

Of course it is, but I think that is a cpu bug as well.

Quote:
have you gotten any of blargg's test to work ? you might have a bug in the ppu and/or sprites.

That the sprite wasnt shown was a ppu bug but its still not possible to select.
All ppu test passes, Ive very inaccurate sprite hit and max sprites code so these tests fail a lot, but I don't think these flags have with the todo.

Quote:
also, you might want to start another thread if its off topic.

Yeah I know, just wanted to answer, I first thought it was a similiar problem as you had.

by on (#17007)
Disch wrote:
On a side note: .bmp? No .bmp has any place on the internet.

I agree that it's not a good generic format for web images because all graphical web browsers in common use support PNG. But it's useful if I'm providing .bmp.zip (which is pretty much what .png is) because I'm using .bmp for textures in a PC program that I have developed, right? At least that's what I'm doing in a reference implementation of the tetromino game because statically linking libpng would make the download bigger than just zipping the sample skins, which are in .bmp format.

by on (#17017)
If you're posting a few quick images to a board like this and your program outputs only .bmp, it might be worth the few extra seconds of download to not bother with conversion to another image format. But for a general web page, using .bmp would be idiotic.

Now I'm quite sure we've wasted whatever benefit could have been gained now and in the future by avoiding converting .bmp in these cases. :)

by on (#17100)
my problem is solved, my writes to 0x6000-0x7FFF didn't work properly.