Need help with mmc5.cpp source, for custom modification
Moderator: Moderators
-
- Posts: 490
- Joined: Fri Mar 01, 2013 4:46 am
Need help with mmc5.cpp source, for custom modification
I'm not fluent in c++, but I've been attempting to modify certain functions within the MMC5 mapper. So far I've been able to adjust the output size of the .sav file, but I need to adjust how many swappable wram pages are available. Register $5113 goes from 00-07, giving you 8 individual 2000 byte pages. But I need 32 pages (00-1F), and when you go higher than 07 within $5113, it repeats the other previous pages due to the bits involved.
Anyone with c++ knowledge that'd be willing to help would be greatly appreciated.
Anyone with c++ knowledge that'd be willing to help would be greatly appreciated.
Re: Need help with mmc5.cpp source, for custom modification
32 pages is 256 KiB of RAM. What application needs that much RAM?
-
- Posts: 490
- Joined: Fri Mar 01, 2013 4:46 am
Re: Need help with mmc5.cpp source, for custom modification
I'm creating a new project where the player can construct & save. I dont want to spoil any details as to what I'm trying to accomplish, but it works. I just need more available wram, which is why I've been trying to modify the mmc5.cpp file.
-
- Posts: 490
- Joined: Fri Mar 01, 2013 4:46 am
Re: Need help with mmc5.cpp source, for custom modification
So I'm hoping there's someone who can help me out with this.
Re: Need help with mmc5.cpp source, for custom modification
There's an "& 7" in a couple places around 5113 setting there. You'd change that to 31. But there may be many other places needing modification.
-
- Posts: 490
- Joined: Fri Mar 01, 2013 4:46 am
Re: Need help with mmc5.cpp source, for custom modification
I'll edit that tonight. I know there's another section that looks to deal with the actual swapping of pages. They were "case"'s
case 0
case 1
case 2
case 4
case 8
I tried fiddling with that area but wasnt getting the correct results. Shouldn't have expected much since I can't write c++ :-/
case 0
case 1
case 2
case 4
case 8
I tried fiddling with that area but wasnt getting the correct results. Shouldn't have expected much since I can't write c++ :-/
- rainwarrior
- Posts: 8731
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Need help with mmc5.cpp source, for custom modification
We're talking about FCEUX's mmc5.cpp?
Check the GenMMC5_Init function at the bottom to set the save game size, in particular info->SaveGameLen needs to be set to the size of your WRAM for saving and loading to disk to work. You'll notice this is full of 3 special case hacks currently, so I guess you'll need another special case for 256k.
Secondly in MMC5_Init you'll need some way to specify WRAMSIZE... The iNES 2 header can specify WRAM size, and if info->ines2 is true it will show up in info->wram_size and/or info->battery_warm_size. You'll want to make MMC5_Init pay attention to that instead of just guessing it via CRC.
Go over all the uses of the actual bankswitch registers and see how the value is used to select a bank (search for uses of MMC5WRAM). It looks like & 7 is hardcoded in a bunch of locations, so... replace those with a mask variable I guess. Probably something to set in MMC5_Init to 7 generically, or something like (WRAMSIZE>>13)-1 when specified via iNES 2?
Also there's MMC5WRAMIndex which seems to map the smaller sizes to a 64k master. This needs to be expanded from 8 entries to 32, and BuildWRAMSizeTable should fill it with the values 0 to 31 for the 256k case, I guess?
There might be other stuff, too, but that's as far as I want to dig here speculatively. MMC5 is a big mapper implementation with a lot of historical hacky stuff in it. What you're asking can certainly be done, but it's not quite trivial.
Check the GenMMC5_Init function at the bottom to set the save game size, in particular info->SaveGameLen needs to be set to the size of your WRAM for saving and loading to disk to work. You'll notice this is full of 3 special case hacks currently, so I guess you'll need another special case for 256k.
Secondly in MMC5_Init you'll need some way to specify WRAMSIZE... The iNES 2 header can specify WRAM size, and if info->ines2 is true it will show up in info->wram_size and/or info->battery_warm_size. You'll want to make MMC5_Init pay attention to that instead of just guessing it via CRC.
Go over all the uses of the actual bankswitch registers and see how the value is used to select a bank (search for uses of MMC5WRAM). It looks like & 7 is hardcoded in a bunch of locations, so... replace those with a mask variable I guess. Probably something to set in MMC5_Init to 7 generically, or something like (WRAMSIZE>>13)-1 when specified via iNES 2?
Also there's MMC5WRAMIndex which seems to map the smaller sizes to a 64k master. This needs to be expanded from 8 entries to 32, and BuildWRAMSizeTable should fill it with the values 0 to 31 for the 256k case, I guess?
There might be other stuff, too, but that's as far as I want to dig here speculatively. MMC5 is a big mapper implementation with a lot of historical hacky stuff in it. What you're asking can certainly be done, but it's not quite trivial.
-
- Posts: 490
- Joined: Fri Mar 01, 2013 4:46 am
Re: Need help with mmc5.cpp source, for custom modification
Thank you rainwarrior, I'm going to start making adjustments/changes the best I can.
EDIT
So these are the changes I've made, but still no luck with swapping newer pages. I do however have the .sav outputting perfectly at 256kb.
BuildWRAMSizeTable(void)
MMC5WRAM(uint32 A, uint32 V)
DECLFW(Mapper5_write)
MMC5Synco(void)
GenMMC5Init(CartInfo * info, int wsize, int battery)
EDIT
So these are the changes I've made, but still no luck with swapping newer pages. I do however have the .sav outputting perfectly at 256kb.
BuildWRAMSizeTable(void)
Code: Select all
for (x = 0; x < 32; x++) { //infidelity 11-12-19
case 0: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7 //infidelity 11-12-19 (case 0 - case 32)
case 1: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 2: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 3: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 4: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 5: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 6: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 7: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 8: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 9: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 10: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 11: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 12: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 13: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 14: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 15: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 16: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 17: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 18: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 19: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 20: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 21: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 22: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 23: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 24: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 25: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 26: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 27: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 28: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 29: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 30: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 31: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
case 32: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7
Code: Select all
V = MMC5WRAMIndex[V & 0x1F]; //infidelity 11-12-19
Code: Select all
case 0x5113:
WRAMPage = V;
MMC5WRAM(0x6000, V & 0x1F); //infidelity 11-12-19
Code: Select all
MMC5WRAM(0x6000, WRAMPage & 0x1F); //infidelity 11-12-19
Code: Select all
WRAM = (uint8*)FCEU_gmalloc(wsize * 262144); //infidelity 11-12-19
info->SaveGameLen[0] = 262144; //infidelity 11-12-19
else
info->SaveGameLen[0] = 262144; //infidelity 11-12-19
-
- Posts: 490
- Joined: Fri Mar 01, 2013 4:46 am
Re: Need help with mmc5.cpp source, for custom modification
Do my current changes look ok? Especially my changes to & 7 ?
Any further assistance would be great. I can't progress any further with this, not even sure if what I've done is correct.
Any further assistance would be great. I can't progress any further with this, not even sure if what I've done is correct.
-
- Posts: 490
- Joined: Fri Mar 01, 2013 4:46 am
- never-obsolete
- Posts: 411
- Joined: Wed Sep 07, 2005 9:55 am
- Location: Phoenix, AZ
- Contact:
Re: Need help with mmc5.cpp source, for custom modification
I quickly looked it over but it looks like DetectMMC5WRAMSize should return 256 for your case.
In BuildWRAMSizeTable you only needed to add a case for when MMC5WRAMsize == 32, but hardcoding MMC5WRAMIndex[]to always be 0-31 should also work.
Unless wsize == 1, this will allocate too much space.
In BuildWRAMSizeTable you only needed to add a case for when MMC5WRAMsize == 32, but hardcoding MMC5WRAMIndex[]to always be 0-31 should also work.
Code: Select all
WRAM = (uint8*)FCEU_gmalloc(wsize * 262144);
-
- Posts: 490
- Joined: Fri Mar 01, 2013 4:46 am
Re: Need help with mmc5.cpp source, for custom modification
Thank you, you and zeromus said the same on detectwramsize. He assisted the rest of the way and now it's all set. Thanks everyone.
- rainwarrior
- Posts: 8731
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Need help with mmc5.cpp source, for custom modification
Had some down time today, and felt like looking at this a little more. After thinking about it, especially with all the people doing work on MMC5 recently, and new pinout discoveries, it seemed like it might be worth doing a more permanent solution that everyone can use rather than a private hack.
I added proper iNES 2 WRAM support for MMC5 to FCEUX with this pull request. Any interested reviews of the change are appreciated.
There's an appveyor build of that change if anyone needs an executable to try: (FCEUX artifact with MMC5 iNES 2 WRAM support, old link removed)
Edit: Now part of FCEUX 2.3.0: http://fceux.com/web/download.html
I've created a set of test ROMs that should cover potential cases: with or without iNES 2 header, with 0-7 bits of WRAM select, battery backed (s) or not battery backed (u). Source code is included.
The test results will show a grid of 128 values, each is the lowest $5113 value that can access that RAM bank. Banks that don't behave like RAM (e.g. open bus) will show as FF. It also sets the high bit if a previous save was successfully loaded, so you get 80 instead of 00, 81 instead of 01, etc. to check if saving works.
Edit: added a "2u1" ROM with a header that has 16k split as 8k saved + 8k unsaved.
I added proper iNES 2 WRAM support for MMC5 to FCEUX with this pull request. Any interested reviews of the change are appreciated.
There's an appveyor build of that change if anyone needs an executable to try: (FCEUX artifact with MMC5 iNES 2 WRAM support, old link removed)
Edit: Now part of FCEUX 2.3.0: http://fceux.com/web/download.html
I've created a set of test ROMs that should cover potential cases: with or without iNES 2 header, with 0-7 bits of WRAM select, battery backed (s) or not battery backed (u). Source code is included.
The test results will show a grid of 128 values, each is the lowest $5113 value that can access that RAM bank. Banks that don't behave like RAM (e.g. open bus) will show as FF. It also sets the high bit if a previous save was successfully loaded, so you get 80 instead of 00, 81 instead of 01, etc. to check if saving works.
Edit: added a "2u1" ROM with a header that has 16k split as 8k saved + 8k unsaved.
- Attachments
-
- mmc5ramsize.zip
- (38.72 KiB) Downloaded 275 times
Last edited by rainwarrior on Wed Feb 10, 2021 3:44 pm, edited 3 times in total.
Re: Need help with mmc5.cpp source, for custom modification
I'm unhappy about extending a mapper beyond what the real-world hardware could possibly support, but I don't think there's any use in my arguing about it...
- rainwarrior
- Posts: 8731
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Need help with mmc5.cpp source, for custom modification
Well, in this case it's the same implementation either way. After this change, the only difference would be a 16 instead of a 128 in exactly one place in the code.
So... I don't particularly love theoretically impractical-for-hardware extensions like this, but in this particular case there is zero implementation burden for the emulator. Seems better to just quietly allow it to be supported than cause more hacky forks of FCEUX to floating around in the wild.
The wiki at least only documents the "real" stuff. At this point I don't think this hypothetical extension should even be mentioned there.
So... I don't particularly love theoretically impractical-for-hardware extensions like this, but in this particular case there is zero implementation burden for the emulator. Seems better to just quietly allow it to be supported than cause more hacky forks of FCEUX to floating around in the wild.
The wiki at least only documents the "real" stuff. At this point I don't think this hypothetical extension should even be mentioned there.