It is currently Fri Oct 20, 2017 11:17 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: question on savestates
PostPosted: Fri Jul 22, 2005 9:16 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3064
Location: Brazil
I'm saving the last write to every register only, and on state loading, I'm performing a write to these registers with the saved value.

Is this correct? Thanks in advice. ^_^;;

_________________
Zepper
RockNES developer


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 10:14 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19110
Location: NE Indiana, USA (NTSC)
The actual registers of the NES are not 1:1 mapped to the thirty registers accessible by the CPU. Some registers' current values change behind the program's back. For instance, the square wave generators' period registers will be changed by the sweep units.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 23, 2005 9:45 am 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
A save state needs to capture all hardware state that matters. At various points in time the amount of state that matters changes. For example, saving in the middle of a CPU instruction requires more state than saving after an instruction has completed, same for saving in the middle of a visible scanline.

Writing to hardware registers unconditionally sets some internal state, so saving and restoring the last written values is an easy way to preserve lots of internal state. It doesn't depend on how a particular emulator is written, so it won't require changes if you change how your emulator works.

Other internal state can't be set directly by writing to registers, or is always set to one value when writing to a register. This means an emulator has to save additional internal state after the last written values to registers, and restore it after restoring the registers. For example, the square sound channel phase resets after writing to $4003/$4007, so if the last written values to these registers are restored, the phase needs to be restored afterwards.

Some internal state has no long-term effect on emulation, like the phase of the square wave (since it's reset quite often, and can't be read back from the CPU). It helps to keep clear which state is critical and which can be given less scrutiny if there isn't time to be really careful in implementation.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 23, 2005 11:02 am 
Saving the state of the square wave is important if you want to implement save-state-rewinding by saving the state of every frame. ;)


Top
  
 
 Post subject:
PostPosted: Sat Jul 23, 2005 11:42 am 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3064
Location: Brazil
Correct, blargg. About the counters, don't forget they have a reload value, usually from the last value written to a register. Saving only the counters OR only the last value written to a register is incorrect... both must be saved AND loaded like you said. :) Of course, we need to save the relevant data.

_________________
Zepper
RockNES developer


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 7 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