Re: Fix SCAN_OFF() too
[Re: Re: fix the crashing neogeo savestate thinggy]
Earlier today whilst reviewing yesterdays code I realized SCAN_OFF() was used in other parts of the code and thought that it would be a good idea to investigate how/why SCAN_OFF() is messing up pointers. If SCAN_OFF() is bungling pointers that don't cause a crash - who knows what kind of corruption is going on behind the scenes. Scary stuff!
I lifted SCAN_OFF() from FBA, put it in a little test program and added some printf's to see whats going on....
start: rambank=1020,ram=1000.
SCAN_OFF(rambank, ram, 0);
end: rambank=980,ram=1000.
rambank after SCAN_OFF() executes is supposed to be 1020, but here its 980. This is really bad, especially since we're dealing with pointers
To get the offset, SCAN_OFF was subtracting the rambank variable from ram. 1000 - 1020 = -20
So, it was saving -20 as the offset, and to recalculate the rambank(on savestate load), it was adding this saved value to the ram variable, which is where the 980 came from (1000 + -20=980). A simple change so that it now subtracts the ram variable (1000) from rambank (1020), which gives 20 [which is stored in the savestate]. Now, when it adds the stored value of 20 to the ram variable, we get the proper value of 1020.
*I'm confused - What does all that mean?* Better reliability & stability when using savestates. and, of course, none of that Guru Meditation sh*t
Thats it for now,
best regards,
- dink