It is currently Sun Oct 22, 2017 3:16 am

All times are UTC - 7 hours



Forum rules


Related:



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sun Sep 25, 2016 12:20 pm 
Offline

Joined: Fri Jul 15, 2016 9:47 pm
Posts: 13
Hello, so I'm working on a SNES emulator and I'm testing it with the game Aerobiz, the US version. Anyway, I'm using the SNES9.x with debugging capability as my control, so that I can step through each instruction and see that I've got things in the same state after each instruction. However, I'm getting some oddities when popping the stack. Early on in the game, it sets the stack pointer to 8FC, here's the instruction:

Code:
$00/804E A2 FC 08


This is fine, it runs through a whole bunch of functions moving data here and there. It does some DMA data moving. All of this is fine. Later, it begins to pull data off the stack and store it to memory. However, after it hits $00/08FC, it pops again, moving the pointer to $00/08FD (the instruction is
Code:
$00/A2A8 68
), there's nothing inherently wrong with that, I don't think, but I'm getting a value of 0 from that location and SNES9.x gets a $55 from that location. This value is stored to memory, I assume to be used later. I don't see anywhere that this location is written to, and I put breakpoints on that location to see if anything was written there, and I don't see it ever doing that (as well as logging DMA/HDMA writes in case it was done via that).

There's obviously something I'm missing here, but I have no idea and after looking for something for a few days, I thought I'd ask here.

Thanks ahead of time!


Top
 Profile  
 
PostPosted: Sun Sep 25, 2016 3:51 pm 
Offline

Joined: Sun Mar 27, 2016 7:56 pm
Posts: 137
I'm guessing what's happening is this:

When you turn a real SNES on, its RAM and some of its registers are in essentially a random state. It doesn't start out with all of its RAM set to zero; it could potentially be anything, from random bytes to whatever was left in RAM if the console was reset. Because of that, many games go to the trouble of clearing all RAM when starting up to prevent accidentally reading uninitialized bytes, because they could cause bugs that would be difficult to fix, since those bugs might happen only on some power-ons.

SNES emulators, on the other hand, sometimes start the RAM out with $00 bytes (which I'm guessing your emulator does), or, in the case of bsnes-plus (and I'm guessing your debug SNES9x version), $55 bytes. It looks like Aerobiz does not zero-fill its RAM, and that's where you're getting that discrepancy.

I would suggest either randomizing RAM to start out with (but leaving it intact when resetting, since on a real SNES it would be unaffected then), or filling it with a non-zero byte like $55. Emulators zero-filling RAM have actually caused issues in the past, because a number of homebrew ROMs or patches have mistakenly relied on RAM being zero initially, causing it to fail on real hardware.


Top
 Profile  
 
PostPosted: Sun Sep 25, 2016 4:02 pm 
Offline

Joined: Sat Apr 25, 2015 1:47 pm
Posts: 329
Location: FL
I took a look and Aerobiz does underflow the stack on purpose at that point in order to read some uninitialized memory (to use as a RNG seed or something? I didn't actually look at it any further). So, like Nicole said, the only difference there between your emulator and others is how the emulator itself initializes RAM.


Top
 Profile  
 
PostPosted: Sun Sep 25, 2016 4:17 pm 
Offline

Joined: Fri Jul 15, 2016 9:47 pm
Posts: 13
That makes sense. Is it better to use random numbers, or a specific number for initialization? Either way, thanks a lot, both of you, for the information!


Top
 Profile  
 
PostPosted: Sun Sep 25, 2016 4:29 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
The state of RAM/memory on the console's power-on is undefined. On soft reset, the RAM is not touched. On power loss, RAM loses power, and contents begin to decay (think "get corrupted") (this isn't something you have to emulate, nor should you).

The subject of "what to pre-init memory to" in emulators has come up a few times on this forum. Different emulators behave differently, but the above statement about the hardware is accurate.

The recommendation is to permit different behaviour based on the user's choosing. I maintain strongly that the default should be pre-init with $00, with other options being pre-init with random values, and maybe another ("higan/bsnes v078 compatibility") which initialises things to $55. Allowing a user to pre-init to a specific value of their choice would be nice too.

I won't post any more on the subject, in attempt to minimise gong-banging that happens often on this forum when it comes to such subjects.


Top
 Profile  
 
PostPosted: Sun Sep 25, 2016 4:46 pm 
Offline

Joined: Fri Jul 15, 2016 9:47 pm
Posts: 13
I'll search for those posts. Thanks for again for the information!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group