Page 1 of 1

MegaCD - Help understanding Memory for cheating

Posted: Sat Jul 17, 2021 12:43 am
by Slade
I'm trying to figure out why some cheats work in some games, but not others. I noticed there was a distinct lack of cheats for games on the Sega CD / Mega CD, so I figured I'd write my own, and share them around (ie post to gamehacking.org), so we can all benefit.

Finding / making the cheats is a time consuming, but not overly difficult thing. Working out the idiosyncrasies between systems is much harder.

There are a number of cheats available from game hacking, however, they do not all work with MiSTer. The MegaCD has several ram locations, and different games use different ram locations. I can only assume that these ram locations do not overlap, otherwise there doesn't seem to be a way for the cheat file to tell the simulation to use 68k ram or the CD Program Ram.

My issue is that if I have the memory location of:

15 16 in 68K ram (this is the time location for Sonic CD (USA)), the cheat file (being little endian) should look like this:

Code: Select all

00 00 00 00 16 15 00 00 00 00 00 00 00 00 00 00

Being:
00 00 00 00 - Compare flag (not used in this instance)
16 15 00 00 - Memory location in little endian
00 00 00 00 - Compare value (not used here)
00 00 00 00 - value to poke (zero, we have zero time used)
This doesn't work.

If I look at the actual cheat file, which does work it looks like this:

Code: Select all

00 00 00 00 16 15 FF 00 00 00 00 00 00 00 00 00
Why is there an "FF" as part of the ram location, effectively making the system see the ram as FF 15 16, not just 15 16?

Is this only required for 68k ram cheats, or for CD PRG ram as well?

Any help would be appreciated. There are so few cheats for these games, and going through them would be fun.

Thanks for reading.

Re: MegaCD - Help understanding Memory for cheating

Posted: Sat Jul 24, 2021 3:07 pm
by mindstation
Slade wrote: Sat Jul 17, 2021 12:43 amWhy is there an "FF" as part of the ram location, effectively making the system see the ram as FF 15 16, not just 15 16?
Main CPU RAM address space is $FF0000-$FFFFFF.
Addresses $000000-$400000 is a ROM space (cartridge, read-only usually).

Full memory map is avaliable at offical documentation (page 8): https://segaretro.org/Mega_Drive_official_documentation
Slade wrote: Sat Jul 17, 2021 12:43 amIs this only required for 68k ram cheats, or for CD PRG ram as well?
Mapping CD PRG ram to main 68k CPU (Genesis/MegaDrive) address space is more complex.
Main CPU can access to CD RAM at addresses:
$20000-$40000 - CD PRG RAM mapped to the CARTRIDGE memory area;
$200000-$240000 - common DATA RAM for both CPU (Main and CD 68k).

Main CPU RAM at $FF0000-$FFFFFF also uses in CD games.

More information about Sega CD memory access is avaliable at official documentation: https://segaretro.org/Mega-CD_official_documentation
Look memory map at 8 page.

I'm not familliar with Sega CD programming, therefore can't say which CD RAM is more or less usefull for cheating :)

Re: MegaCD - Help understanding Memory for cheating

Posted: Fri Jul 30, 2021 8:37 am
by Slade
Thanks for your help. I've been chatting / getting help from Sorgelig. I ended up opening a bug report and we've managed to find and fix 2 bugs on the cheat engine (well, Sorgelig found and fixed them, I just pointed out what wasn't working on the MegaCD).

Now, so far, all the cheats I've made work fine.