SRAM ghost written...

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

SRAM ghost written...

Post by tryphon » Tue Jul 05, 2016 5:58 pm

I'm currently hacking Lord Monarch for a group of translators.

The code is located up to 1FFFFF, and SRAM starts at 200001, according to the header.

The translated script being longer than the original, I want to enlarge the ROM : I'd like the code to go up to 2FFFFF and SRAM start at 300001. I modified the header and all the routines using SRAM I found up to now.

But it doesn't work : the game branches to the routine displaying a message telling SRAM is corrupted.

I made breakpoints to the SRAM are and found something strange : the error message is displayed if the SRAM is not starting by the ASCII text :

Code: Select all

- LORD MONARCH -
But I checked : this text seems to never be written in SRAM :?

Nevertheless, it is present with the original ROM, but is not with my enlarged version.

Are there ways of writing in SRAM that would bypass breakpoints ? (some kind of DMA)

Are there bytes that are automatically copied to SRAM ?

Other ideas ?

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: SRAM ghost written...

Post by Sik » Wed Jul 06, 2016 12:38 pm

Just changing it in the header won't work, the code still looks for the original address.

But forget that: Phantasy Star IV already has to cope with this. Look up register $A130F1. Writing $00 makes ROM show up in the upper 2MB area, writing $03 makes the SRAM show up instead. So keep it in its original address, and use that register to enable SRAM only when accessing it (and keep ROM at all other times). This should work in emulators as well.
Sik is pronounced as "seek", not as "sick".

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: SRAM ghost written...

Post by tryphon » Wed Jul 06, 2016 12:54 pm

Sik wrote:Just changing it in the header won't work, the code still looks for the original address.
I also changed code in all routines accessing to SRAM.
But forget that: Phantasy Star IV already has to cope with this. Look up register $A130F1. Writing $00 makes ROM show up in the upper 2MB area, writing $03 makes the SRAM show up instead. So keep it in its original address, and use that register to enable SRAM only when accessing it (and keep ROM at all other times). This should work in emulators as well.
I was aware of PS4 doing that. I found that a bit circonvoluted, but (just a guess) maybe SRAM is forced to be at 0x200000 ?

I didn't try my patched rom on real hw, but maybe emulators (I used Gens) always locate SRAM at 0x200000, whatever the header tells ?

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: SRAM ghost written...

Post by Sik » Wed Jul 06, 2016 6:49 pm

Yeah, emulators like to hardcode SRAM from 0x200000 to 0x20FFFF (and on all bytes, not only every other). Don't bother trying to set it anywhere else if you want it to work on emulators =P
Sik is pronounced as "seek", not as "sick".

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: SRAM ghost written...

Post by tryphon » Wed Jul 06, 2016 9:06 pm

Thanks, very good to know :)

Stupid question : if I leave the area from 0x200000 to 0x20FFFF blank, and insert new data from 0x210000, do I have to care with 0xA130F1 ?

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: SRAM ghost written...

Post by Sik » Wed Jul 06, 2016 9:51 pm

Yes, the entire 0x200000-0x3FFFFF range is affected. (when set to $03 it will keep repeating SRAM until the whole range is filled up)
Sik is pronounced as "seek", not as "sick".

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SRAM ghost written...

Post by Stef » Thu Jul 07, 2016 5:56 am

I have to check but i think only 200000-27FFFF is filled by SRAM (512 KB bank).

Edit: well in fact it totally depends from the cart scheme.

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: SRAM ghost written...

Post by Sik » Thu Jul 07, 2016 1:57 pm

Most cartridges just have a flip-flop toggling what A21 does lol (so yes, it would swap the whole $200000-$3FFFFF range). As far as I know the only thing supporting the full blown behavior should be SSF2 because it has the proper mapper... and that game doesn't have SRAM. I guess you may be mixing up with the Mega Everdrive where "SRAM" is just page 30, no idea how it's implemented there though.
Sik is pronounced as "seek", not as "sick".

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: SRAM ghost written...

Post by tryphon » Sat Jul 09, 2016 2:06 pm

Just a clarification:
Sik wrote:Look up register $A130F1. Writing $00 makes ROM show up in the upper 2MB area, writing $03 makes the SRAM show up instead. So keep it in its original address, and use that register to enable SRAM only when accessing it (and keep ROM at all other times). This should work in emulators as well.
But :
gen-hw wrote: Phantasy Star 4 is a 24 megabit game with 16k of battery backed RAM
mapped to $200001-$203FFF. (odd addresses used) It has ROM in the same
area where the RAM is. I've observed that the game will always write
$01 to $A130F1 before accessing the RAM, and then write $00 when
done. It could be that bit 0 of $A130F1 controls ROM/RAM banking at
that location.
So, I write $01 or $03 ?

Also, will it work on real hw with an Everdrive ?

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: SRAM ghost written...

Post by Sik » Sat Jul 09, 2016 7:35 pm

Technically it should be $03... but if you're going to use a flip flop like just about everything else you only care about one bit in the end.

What it should be, if you wonder:
  • $00 = map ROM
  • $01 = map SRAM, read-only
  • $03 = map SRAM, read and write
Nothing implements the read-only part though, so $01 and $03 end up being both read/write =O) (OK, not sure if the Mega Everdrive does in its extended mapper mode)
Sik is pronounced as "seek", not as "sick".

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: SRAM ghost written...

Post by tryphon » Tue Jul 12, 2016 10:34 pm

I forgot to thank you :)

Thanks, it seems to work. Still have to test on hardware, but flawless victory on emus.

Post Reply