Today, I encountered a strange issue in my game:
I have an MMC3 ROM with 32 x 8 KB PRG ROM and 8 x 8 KB CHR ROM.
My meta tile definitions (simple data arrays that define what tiles to fetch) are all in the same bank.
When the meta tile definitions are in bank 0-12, then everything is fine. But as soon as I put them into bank 13-28, graphical glitches happen.
(The banks from 0-28 are all declared as start = $8000, size = $2000.
Bank 29 is start = $A000, size = $2000 and bank 30-31 are the fixed bank.)
Have a look at the red object in the screenshots. Left is the fine version, right is the glitchy version:
Glitch.png [ 10.9 KiB | Viewed 3245 times ]
The strange thing is that everything works fine in one part of the banks, but not in another.
Since the red object on the screen is declared in one C array, we can exclude the fact that it is declared exactly at the border between two banks, so that the first part is still read correctly while the other part is from a non-active bank. That's definitely not the case.
Also, in the moment, all of the meta sprite data is merely 61 bytes and it's located at the start of the bank.
Furthermore, I use a constant for bank numbers, so the idea that I set the wrong bank value in one location can also be excluded. If I did that, I would probably have much more issues and not very rare tile glitches that only manifest exactly in bank 13-28 while they work fine in bank 0-12.
The glitchy tile is background tile number 0. I included a little test code that plays a sound when this specific meta tile is drawn and when a 0 is read. And the game indeed reads a 0 from ROM.
But I don't understand it. I mean, look at this:
Later:
And then I have the array:
If I change the meta tiles bank and the calls to that bank to 12 or lower, then everything is fine. But with 13 or higher, glitches happen.
The glitches are even a bit arbitrary. Depending on from where you come, that red door has more or less 0-tiles, even though the ROM data should always be the same.
I even included a check to see whether my current pointer that reads the data actually equals the address of the array in ROM. And yes, it does. So, it's not even that my pointer is somehow off by a few bytes. (If the door consist of different tiles, then the ones that are displayed with non-0 are always in the correct location, so it's not that the pointer starts to read at the last tile row and fills everything else with zeroes.)
And I even had an emulator savestate from one screen before this screen. And when I load it and enter the screen, then the glitchiness can vary, even though it's the same savestate.
So, does anybody know what this is? Are there any known issues regarding certain banks within MMC3?
I have an MMC3 ROM with 32 x 8 KB PRG ROM and 8 x 8 KB CHR ROM.
My meta tile definitions (simple data arrays that define what tiles to fetch) are all in the same bank.
When the meta tile definitions are in bank 0-12, then everything is fine. But as soon as I put them into bank 13-28, graphical glitches happen.
(The banks from 0-28 are all declared as start = $8000, size = $2000.
Bank 29 is start = $A000, size = $2000 and bank 30-31 are the fixed bank.)
Have a look at the red object in the screenshots. Left is the fine version, right is the glitchy version:
Attachment:
Glitch.png [ 10.9 KiB | Viewed 3245 times ]
The strange thing is that everything works fine in one part of the banks, but not in another.
Since the red object on the screen is declared in one C array, we can exclude the fact that it is declared exactly at the border between two banks, so that the first part is still read correctly while the other part is from a non-active bank. That's definitely not the case.
Also, in the moment, all of the meta sprite data is merely 61 bytes and it's located at the start of the bank.
Furthermore, I use a constant for bank numbers, so the idea that I set the wrong bank value in one location can also be excluded. If I did that, I would probably have much more issues and not very rare tile glitches that only manifest exactly in bank 13-28 while they work fine in bank 0-12.
The glitchy tile is background tile number 0. I included a little test code that plays a sound when this specific meta tile is drawn and when a 0 is read. And the game indeed reads a 0 from ROM.
But I don't understand it. I mean, look at this:
Code:
PRG_ROM_BANK_12: type = ro, start = $8000, size = $2000, file = %O, fill = yes;
PRG_ROM_BANK_13: type = ro, start = $8000, size = $2000, file = %O, fill = yes;
PRG_ROM_BANK_13: type = ro, start = $8000, size = $2000, file = %O, fill = yes;
Later:
Code:
META_TILES_BMTL: load = PRG_ROM_BANK_13, type = ro;
And then I have the array:
Code:
#pragma rodataseg(push, "META_TILES_BMTL")
static const byte MetaTileCastleDoor_bMTl[] =
{
MT_INIT(1, 4, 4, Solid),
0x1A, 0x1A, 0x1A, 0x1A,
0x1A, 0x1A, 0x1A, 0x1A,
0x1A, 0x1A, 0x1A, 0x1A,
0x1A, 0x1A, 0x1A, 0x1A,
};
#pragma rodataseg(pop)
static const byte MetaTileCastleDoor_bMTl[] =
{
MT_INIT(1, 4, 4, Solid),
0x1A, 0x1A, 0x1A, 0x1A,
0x1A, 0x1A, 0x1A, 0x1A,
0x1A, 0x1A, 0x1A, 0x1A,
0x1A, 0x1A, 0x1A, 0x1A,
};
#pragma rodataseg(pop)
If I change the meta tiles bank and the calls to that bank to 12 or lower, then everything is fine. But with 13 or higher, glitches happen.
The glitches are even a bit arbitrary. Depending on from where you come, that red door has more or less 0-tiles, even though the ROM data should always be the same.
I even included a check to see whether my current pointer that reads the data actually equals the address of the array in ROM. And yes, it does. So, it's not even that my pointer is somehow off by a few bytes. (If the door consist of different tiles, then the ones that are displayed with non-0 are always in the correct location, so it's not that the pointer starts to read at the last tile row and fills everything else with zeroes.)
And I even had an emulator savestate from one screen before this screen. And when I load it and enter the screen, then the glitchiness can vary, even though it's the same savestate.
So, does anybody know what this is? Are there any known issues regarding certain banks within MMC3?