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. ^_^;;
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.
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.
Saving the state of the square wave is important if you want to implement save-state-rewinding by saving the state of every frame.
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.