From: <fr...@us...> - 2012-12-25 12:34:43
|
Revision: 4793 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4793&view=rev Author: fredm Date: 2012-12-25 12:34:34 +0000 (Tue, 25 Dec 2012) Log Message: ----------- Extend SZX support to version 1.5 draft specs. Modified Paths: -------------- trunk/libspectrum/accessor.pl trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.h.in trunk/libspectrum/sna.c trunk/libspectrum/snap_accessors.txt trunk/libspectrum/snapshot.c trunk/libspectrum/szx.c trunk/libspectrum/z80.c Modified: trunk/libspectrum/accessor.pl =================================================================== --- trunk/libspectrum/accessor.pl 2012-12-22 12:09:33 UTC (rev 4792) +++ trunk/libspectrum/accessor.pl 2012-12-25 12:34:34 UTC (rev 4793) @@ -73,6 +73,7 @@ int halted; /* Is the Z80 currently HALTed? */ int last_instruction_ei; /* Was the last instruction an EI? */ + int last_instruction_set_f; /* Did the last instruction set Flags? */ /* Custom ROM */ int custom_rom; @@ -232,6 +233,9 @@ libspectrum_byte *spectranet_w5100[1]; libspectrum_byte *spectranet_flash[1]; libspectrum_byte *spectranet_ram[1]; + + /* Timings emulation */ + int late_timings; }; /* Initialise a libspectrum_snap structure */ Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2012-12-22 12:09:33 UTC (rev 4792) +++ trunk/libspectrum/hacking/ChangeLog 2012-12-25 12:34:34 UTC (rev 4793) @@ -914,3 +914,5 @@ 20121208 README: document support for reading PZX files (Sergio). 20121222 szx.c: split SNET block into SNET, SNEF and SNER so that flash could theoretically be saved separately (patch #3596469) (Fred). +20121225 accessor.pl,libspectrum.h.in,sna.c,snap_accessors.txt,snapshot.c,szx.c, + z80.c: extend SZX support to version 1.5 draft specs (Fred). Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2012-12-22 12:09:33 UTC (rev 4792) +++ trunk/libspectrum/libspectrum.h.in 2012-12-25 12:34:34 UTC (rev 4793) @@ -312,6 +312,8 @@ LIBSPECTRUM_MACHINE_48_NTSC, + LIBSPECTRUM_MACHINE_128E, + } libspectrum_machine; WIN32_DLL const char* libspectrum_machine_name( libspectrum_machine type ); Modified: trunk/libspectrum/sna.c =================================================================== --- trunk/libspectrum/sna.c 2012-12-22 12:09:33 UTC (rev 4792) +++ trunk/libspectrum/sna.c 2012-12-25 12:34:34 UTC (rev 4793) @@ -331,6 +331,10 @@ if( libspectrum_snap_specdrum_active( snap ) ) *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MAJOR_INFO_LOSS; + /* We don't save the Spectranet state at all */ + if( libspectrum_snap_spectranet_active( snap ) ) + *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MAJOR_INFO_LOSS; + ptr = *buffer; write_header( buffer, &ptr, length, snap ); @@ -349,6 +353,7 @@ break; case LIBSPECTRUM_MACHINE_128: + case LIBSPECTRUM_MACHINE_128E: case LIBSPECTRUM_MACHINE_PENT512: case LIBSPECTRUM_MACHINE_PENT1024: case LIBSPECTRUM_MACHINE_PLUS2: Modified: trunk/libspectrum/snap_accessors.txt =================================================================== --- trunk/libspectrum/snap_accessors.txt 2012-12-22 12:09:33 UTC (rev 4792) +++ trunk/libspectrum/snap_accessors.txt 2012-12-25 12:34:34 UTC (rev 4793) @@ -47,6 +47,7 @@ int halted int last_instruction_ei +int last_instruction_set_f libspectrum_byte out_ula @@ -187,3 +188,5 @@ libspectrum_byte* spectranet_w5100 1 libspectrum_byte* spectranet_flash 1 libspectrum_byte* spectranet_ram 1 + +int late_timings Modified: trunk/libspectrum/snapshot.c =================================================================== --- trunk/libspectrum/snapshot.c 2012-12-22 12:09:33 UTC (rev 4792) +++ trunk/libspectrum/snapshot.c 2012-12-25 12:34:34 UTC (rev 4793) @@ -71,6 +71,7 @@ libspectrum_snap_set_halted( snap, 0 ); libspectrum_snap_set_last_instruction_ei( snap, 0 ); + libspectrum_snap_set_last_instruction_set_f( snap, 0 ); libspectrum_snap_set_custom_rom( snap, 0 ); libspectrum_snap_set_custom_rom_pages( snap, 0 ); @@ -217,6 +218,8 @@ libspectrum_snap_set_spectranet_flash( snap, 0, NULL ); libspectrum_snap_set_spectranet_ram( snap, 0, NULL ); + libspectrum_snap_set_late_timings( snap, 0 ); + return snap; } Modified: trunk/libspectrum/szx.c =================================================================== --- trunk/libspectrum/szx.c 2012-12-22 12:09:33 UTC (rev 4792) +++ trunk/libspectrum/szx.c 2012-12-25 12:34:34 UTC (rev 4793) @@ -57,12 +57,15 @@ SZX_MACHINE_PENTAGON512, SZX_MACHINE_PENTAGON1024, SZX_MACHINE_48_NTSC, + SZX_MACHINE_128KE, } szx_machine_type; static const char *signature = "ZXST"; static const size_t signature_length = 4; +static const libspectrum_byte ZXSTMF_ALTERNATETIMINGS = 1; + static const char *libspectrum_string = "libspectrum: "; static const libspectrum_byte SZX_VERSION_MAJOR = 1; @@ -75,6 +78,7 @@ #define ZXSTBID_Z80REGS "Z80R" static const libspectrum_byte ZXSTZF_EILAST = 1; static const libspectrum_byte ZXSTZF_HALTED = 2; +static const libspectrum_byte ZXSTZF_FSET = 4; #define ZXSTBID_SPECREGS "SPCR" @@ -133,6 +137,12 @@ #define ZXSTBID_MICRODRIVE "MDRV" #define ZXSTBID_PLUS3DISK "+3\0\0" #define ZXSTBID_DSKFILE "DSK\0" +#define ZXSTBID_LEC "LEC\0" +static const libspectrum_word ZXSTLECF_PAGED = 1; + +#define ZXSTBID_LECRAMPAGE "LCRP" +static const libspectrum_word ZXSTLCRPF_COMPRESSED = 1; + #define ZXSTBID_TIMEXREGS "SCLD" #define ZXSTBID_BETA128 "B128" @@ -1372,8 +1382,10 @@ if( version >= 0x0101 ) { (*buffer)++; /* Skip dwHoldIntReqCycles */ - /* Flags; ignore the 'last instruction EI' flag for now */ + /* Flags */ + libspectrum_snap_set_last_instruction_ei( snap, **buffer & ZXSTZF_EILAST ); libspectrum_snap_set_halted( snap, **buffer & ZXSTZF_HALTED ); + libspectrum_snap_set_last_instruction_set_f( snap, **buffer & ZXSTZF_FSET ); (*buffer)++; (*buffer)++; /* Skip the hidden register */ @@ -2132,6 +2144,8 @@ { ZXSTBID_DIVIDERAMPAGE, read_dirp_chunk }, { ZXSTBID_DOCK, read_dock_chunk }, { ZXSTBID_DSKFILE, skip_chunk }, + { ZXSTBID_LEC, skip_chunk }, + { ZXSTBID_LECRAMPAGE, skip_chunk }, { ZXSTBID_GS, skip_chunk }, { ZXSTBID_GSRAMPAGE, skip_chunk }, { ZXSTBID_IF1, read_if1_chunk }, @@ -2236,6 +2250,8 @@ size_t length ) { libspectrum_word version; + libspectrum_byte machine; + libspectrum_byte flags; libspectrum_error error; const libspectrum_byte *end = buffer + length; @@ -2260,8 +2276,10 @@ version = (*buffer++) << 8; version |= *buffer++; - switch( *buffer ) { + machine = *buffer++; + switch( machine ) { + case SZX_MACHINE_16: libspectrum_snap_set_machine( snap, LIBSPECTRUM_MACHINE_16 ); break; @@ -2326,6 +2344,10 @@ libspectrum_snap_set_machine( snap, LIBSPECTRUM_MACHINE_PENT1024 ); break; + case SZX_MACHINE_128KE: + libspectrum_snap_set_machine( snap, LIBSPECTRUM_MACHINE_128E ); + break; + default: libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, @@ -2334,9 +2356,21 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } - /* Skip to the end of the header */ - buffer += 2; + flags = *buffer++; + switch( machine ) { + + case SZX_MACHINE_16: + case SZX_MACHINE_48: + case SZX_MACHINE_48_NTSC: + case SZX_MACHINE_128: + libspectrum_snap_set_late_timings( snap, flags & ZXSTMF_ALTERNATETIMINGS ); + break; + + default: + break; + } + ctx = libspectrum_malloc( sizeof( *ctx ) ); ctx->swap_af = 0; @@ -2524,6 +2558,8 @@ write_file_header( libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length, int *out_flags, libspectrum_snap *snap ) { + libspectrum_byte flags; + libspectrum_make_room( buffer, 8, ptr, length ); memcpy( *ptr, signature, 4 ); *ptr += 4; @@ -2536,6 +2572,7 @@ case LIBSPECTRUM_MACHINE_48: **ptr = SZX_MACHINE_48; break; case LIBSPECTRUM_MACHINE_48_NTSC: **ptr = SZX_MACHINE_48_NTSC; break; case LIBSPECTRUM_MACHINE_128: **ptr = SZX_MACHINE_128; break; + case LIBSPECTRUM_MACHINE_128E: **ptr = SZX_MACHINE_128KE; break; case LIBSPECTRUM_MACHINE_PLUS2: **ptr = SZX_MACHINE_PLUS2; break; case LIBSPECTRUM_MACHINE_PLUS2A: **ptr = SZX_MACHINE_PLUS2A; break; case LIBSPECTRUM_MACHINE_PLUS3: **ptr = SZX_MACHINE_PLUS3; break; @@ -2556,8 +2593,10 @@ } (*ptr)++; - /* Reserved byte */ - *(*ptr)++ = '\0'; + /* Flags byte */ + flags = 0; + if( libspectrum_snap_late_timings( snap ) ) flags |= ZXSTMF_ALTERNATETIMINGS; + *(*ptr)++ = flags; return LIBSPECTRUM_ERROR_NONE; } @@ -2630,6 +2669,7 @@ flags = '\0'; if( libspectrum_snap_last_instruction_ei( snap ) ) flags |= ZXSTZF_EILAST; if( libspectrum_snap_halted( snap ) ) flags |= ZXSTZF_HALTED; + if( libspectrum_snap_last_instruction_set_f( snap ) ) flags |= ZXSTZF_FSET; *(*ptr)++ = flags; /* Hidden register not supported */ @@ -2820,6 +2860,7 @@ } break; case LIBSPECTRUM_MACHINE_128: + case LIBSPECTRUM_MACHINE_128E: case LIBSPECTRUM_MACHINE_PENT: case LIBSPECTRUM_MACHINE_PLUS2: case LIBSPECTRUM_MACHINE_SE: Modified: trunk/libspectrum/z80.c =================================================================== --- trunk/libspectrum/z80.c 2012-12-22 12:09:33 UTC (rev 4792) +++ trunk/libspectrum/z80.c 2012-12-25 12:34:34 UTC (rev 4793) @@ -1125,12 +1125,19 @@ *out_flags = 0; - /* .z80 format doesn't store the 'last instruction EI' or 'halted' state */ + /* .z80 format doesn't store the 'last instruction EI', 'halted' state or + the 'last instruction set Flags' */ if( libspectrum_snap_last_instruction_ei( snap ) ) *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MINOR_INFO_LOSS; if( libspectrum_snap_halted( snap ) ) *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MINOR_INFO_LOSS; + if( libspectrum_snap_last_instruction_set_f( snap ) ) + *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MINOR_INFO_LOSS; + /* .z80 format doesn't store the 'late timings' state */ + if( libspectrum_snap_late_timings( snap ) ) + *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MINOR_INFO_LOSS; + /* .z80 format doesn't store +D info well */ if( libspectrum_snap_plusd_active( snap ) ) *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MINOR_INFO_LOSS; @@ -1171,6 +1178,10 @@ if( libspectrum_snap_specdrum_active( snap ) ) *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MAJOR_INFO_LOSS; + /* .z80 format doesn't save the Spectranet state at all */ + if( libspectrum_snap_spectranet_active( snap ) ) + *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MAJOR_INFO_LOSS; + error = write_header( buffer, &ptr, length, out_flags, snap ); if( error != LIBSPECTRUM_ERROR_NONE ) return error; @@ -1297,6 +1308,7 @@ } break; case LIBSPECTRUM_MACHINE_SE: + case LIBSPECTRUM_MACHINE_128E: *flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MAJOR_INFO_LOSS; /* fall through */ case LIBSPECTRUM_MACHINE_128: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |