From: <zu...@us...> - 2015-03-16 23:44:37
|
Revision: 5162 http://sourceforge.net/p/fuse-emulator/code/5162 Author: zubzero Date: 2015-03-16 23:44:35 +0000 (Mon, 16 Mar 2015) Log Message: ----------- Store PC-1 for all snapshot formats whilst in the halted state Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/snapshot.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-16 23:42:32 UTC (rev 5161) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-16 23:44:35 UTC (rev 5162) @@ -1000,3 +1000,5 @@ 20150316 generate.pl.in,libspectrum.h.in: remove autogeneration warning from libspectrum.h.in (Stuart). 20150316 doc/libspectrum.txt: add missing line break (Stuart). +20150316 snapshot.c: store PC-1 for all snapshot formats whilst in the halted + state (Stuart). Modified: trunk/libspectrum/snapshot.c =================================================================== --- trunk/libspectrum/snapshot.c 2015-03-16 23:42:32 UTC (rev 5161) +++ trunk/libspectrum/snapshot.c 2015-03-16 23:44:35 UTC (rev 5162) @@ -361,6 +361,13 @@ return LIBSPECTRUM_ERROR_LOGIC; } + /* Sadly, virtually all emulators handle saving of PC incorrectly when + * executing a HALT instruction, so it's easiest to deal with this just + * once, so that it affects all snapshot formats. */ + if( libspectrum_snap_halted( snap ) ) { + libspectrum_snap_set_pc( snap, libspectrum_snap_pc( snap ) + 1 ); + } + libspectrum_free( new_buffer ); return error; } @@ -373,6 +380,7 @@ { libspectrum_class_t class; libspectrum_error error; + libspectrum_word orig_pc; error = libspectrum_identify_class( &class, type ); if( error ) return error; @@ -383,17 +391,29 @@ return LIBSPECTRUM_ERROR_INVALID; } + /* Sadly, virtually all emulators handle saving of PC incorrectly when + * executing a HALT instruction, so it's easiest to deal with this just + * once, so that it affects all snapshot formats. */ + orig_pc = libspectrum_snap_pc( snap ); + if( libspectrum_snap_halted( snap ) ) { + libspectrum_snap_set_pc( snap, orig_pc - 1 ); + } + switch( type ) { case LIBSPECTRUM_ID_SNAPSHOT_SNA: - return libspectrum_sna_write( buffer, length, out_flags, snap, in_flags ); + error = libspectrum_sna_write( buffer, length, out_flags, snap, in_flags ); + break; case LIBSPECTRUM_ID_SNAPSHOT_SZX: - return libspectrum_szx_write( buffer, length, out_flags, snap, creator, - in_flags ); + error = libspectrum_szx_write( buffer, length, out_flags, snap, creator, + in_flags ); + break; case LIBSPECTRUM_ID_SNAPSHOT_Z80: - return libspectrum_z80_write2( buffer, length, out_flags, snap, in_flags ); + error = libspectrum_z80_write2( buffer, length, out_flags, snap, + in_flags ); + break; default: libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, @@ -401,6 +421,11 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } + + /* Put back the correct value of PC, in case snap is needed again */ + libspectrum_snap_set_pc( snap, orig_pc ); + + return error; } /* Given a 48K memory dump `data', place it into the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |