[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx:[712] trunk/libspectrum/libspectrum
Brought to you by:
fredm
From: <fr...@us...> - 2012-11-24 10:24:11
|
Revision: 712 http://sourceforge.net/p/fuse-for-macosx/code/712 Author: fredm Date: 2012-11-24 10:24:08 +0000 (Sat, 24 Nov 2012) Log Message: ----------- Merge up to vendor revision 4676. Revision Links: -------------- http://sourceforge.net/p/fuse-for-macosx/code/4676 Modified Paths: -------------- trunk/libspectrum/libspectrum/accessor.pl trunk/libspectrum/libspectrum/csw.c trunk/libspectrum/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum/make-perl.c trunk/libspectrum/libspectrum/snap_accessors.txt trunk/libspectrum/libspectrum/snapshot.c trunk/libspectrum/libspectrum/szx.c Property Changed: ---------------- trunk/libspectrum/libspectrum/ Property changes on: trunk/libspectrum/libspectrum ___________________________________________________________________ Modified: svn:mergeinfo - /vendor/fuse-emulator/0.10.0/libspectrum:556-557 /vendor/fuse-emulator/0.10.0-pre1/libspectrum:545-546 /vendor/fuse-emulator/current/libspectrum:530-685 /vendor/fuse-emulator/fuse-1.0.0a/libspectrum:668-669 /vendor/fuse-emulator/fuse-r4617/libspectrum:686 + /vendor/fuse-emulator/0.10.0/libspectrum:556-557 /vendor/fuse-emulator/0.10.0-pre1/libspectrum:545-546 /vendor/fuse-emulator/current/libspectrum:530-711 /vendor/fuse-emulator/fuse-1.0.0a/libspectrum:668-669 /vendor/fuse-emulator/fuse-r4617/libspectrum:686 Modified: trunk/libspectrum/libspectrum/accessor.pl =================================================================== --- trunk/libspectrum/libspectrum/accessor.pl 2012-11-24 06:50:35 UTC (rev 711) +++ trunk/libspectrum/libspectrum/accessor.pl 2012-11-24 10:24:08 UTC (rev 712) @@ -3,7 +3,7 @@ # accessor.pl: generate accessor functions # Copyright (c) 2003-2009 Philip Kendall -# $Id: accessor.pl 4356 2011-04-07 14:21:40Z fredm $ +# $Id: accessor.pl 4624 2012-01-09 20:59:35Z pak21 $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -216,6 +216,22 @@ /* Cheetah SpecDrum status */ int specdrum_active; libspectrum_signed_byte specdrum_dac; + + /* Spectranet status */ + int spectranet_active; + int spectranet_paged; + int spectranet_paged_via_io; + int spectranet_programmable_trap_active; + int spectranet_programmable_trap_msb; + int spectranet_all_traps_disabled; + int spectranet_rst8_trap_disabled; + int spectranet_deny_downstream_a15; + int spectranet_page_a; + int spectranet_page_b; + libspectrum_word spectranet_programmable_trap; + libspectrum_byte *spectranet_w5100[1]; + libspectrum_byte *spectranet_flash[1]; + libspectrum_byte *spectranet_ram[1]; }; /* Initialise a libspectrum_snap structure */ Modified: trunk/libspectrum/libspectrum/csw.c =================================================================== --- trunk/libspectrum/libspectrum/csw.c 2012-11-24 06:50:35 UTC (rev 711) +++ trunk/libspectrum/libspectrum/csw.c 2012-11-24 10:24:08 UTC (rev 712) @@ -2,7 +2,7 @@ Copyright (c) 2002-2007 Darren Salt, Fredrick Meunier Based on tap.c, copyright (c) 2001 Philip Kendall - $Id: csw.c 3708 2008-07-01 08:07:01Z pak21 $ + $Id: csw.c 4653 2012-02-03 11:48:30Z fredm $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -86,8 +86,8 @@ if( compressed != 0 && compressed != 1 ) goto csw_bad_compress; + if( length < 29 - buffer[12] ) goto csw_short; length -= 29 - buffer[12]; - if( length < 0 ) goto csw_short; buffer += 29 + buffer[12]; break; Modified: trunk/libspectrum/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/libspectrum/hacking/ChangeLog 2012-11-24 06:50:35 UTC (rev 711) +++ trunk/libspectrum/libspectrum/hacking/ChangeLog 2012-11-24 10:24:08 UTC (rev 712) @@ -850,6 +850,18 @@ 20110515 tap.c: add support for the TZX set signal level block (Fred). 20110515 tzx_write.c: factor out common code for writing signal level and pure tone blocks (Fred). +20110608 accessor.pl,snap_accessors.txt,snapshot.c,szx.c: beginnings of + Spectranet snapshot support. +20110610 accessor.pl,snap_accessors.txt,szx.c: pretty much working Spectranet + snapshot support. +20110611 accessor.pl,snap_accessors.txt,szx.c: implement Spectranet + programmable trap support. +20110619 accessor.pl,snap_accessors.txt,szx.c: implement Spectranet "deny + downstream A15 flag". +20110621 accessor.pl,snap_accessors.txt,szx.c: implement Spectranet "paged via + IO port" flag. +20110622 accessor.pl,snapshot.c,snap_accessors.txt,szx.c: store core W5100 + state in snapshots. 20110811 libspectrum.h.in,libspectrum.c: add support for detecting POK files (patch #3382538) (Sergio Baldoví). 20110905 libspectrum.c,make-perl.c,myglib/garray.c: remove operations with @@ -857,3 +869,9 @@ recordings or saving snapshots (part of patch #3404090) (Sergio Baldoví). 20111106 rzx.c,szx.c: remove unused variables (thanks, gcc 4.6). +20120203 csw.c: fix less than 0 check on unsigned expression (thanks, clang + 2.1) (Fred). +20120203 szx.c: correct error argument in libspectrum_print_error() calls + (thanks, clang 2.1) (Fred). +20120220 make-perl.c: advertise that we support bzip2 compressed and wav files + (part of patch #3413549) (Sergio Baldoví). Modified: trunk/libspectrum/libspectrum/make-perl.c =================================================================== --- trunk/libspectrum/libspectrum/make-perl.c 2012-11-24 06:50:35 UTC (rev 711) +++ trunk/libspectrum/libspectrum/make-perl.c 2012-11-24 10:24:08 UTC (rev 712) @@ -1,7 +1,7 @@ /* make-perl.c: Generate a perl script to create the libspectrum_* typedefs Copyright (c) 2002-2003 Philip Kendall, Darren Salt - $Id: make-perl.c 4539 2011-09-05 12:17:34Z fredm $ + $Id: make-perl.c 4673 2012-02-20 10:50:13Z fredm $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -321,6 +321,16 @@ #endif /* #ifdef HAVE_ZLIB_H */ +#ifdef HAVE_LIBBZ2 + printf( "\n/* we support files compressed with bz2 */\n" ); + printf( "#define LIBSPECTRUM_SUPPORTS_BZ2_COMPRESSION (1)\n\n" ); +#endif /* #ifdef HAVE_LIBBZ2 */ + +#ifdef HAVE_LIB_AUDIOFILE + printf( "\n/* we support files wav files */\n" ); + printf( "#define LIBSPECTRUM_SUPPORTS_AUDIOFILE (1)\n\n" ); +#endif /* #ifdef HAVE_LIB_AUDIOFILE */ + printf( "CODE\n}\n\n" ); return 0; Modified: trunk/libspectrum/libspectrum/snap_accessors.txt =================================================================== --- trunk/libspectrum/libspectrum/snap_accessors.txt 2012-11-24 06:50:35 UTC (rev 711) +++ trunk/libspectrum/libspectrum/snap_accessors.txt 2012-11-24 10:24:08 UTC (rev 712) @@ -1,7 +1,7 @@ # snap_accessors.txt: simple accessors for libspectrum_snap # Copyright (c) 2003-2009 Philip Kendall -# $Id: snap_accessors.txt 4356 2011-04-07 14:21:40Z fredm $ +# $Id: snap_accessors.txt 4624 2012-01-09 20:59:35Z pak21 $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -172,3 +172,18 @@ int specdrum_active libspectrum_signed_byte specdrum_dac + +int spectranet_active +int spectranet_paged +int spectranet_paged_via_io +int spectranet_programmable_trap_active +int spectranet_programmable_trap_msb +int spectranet_all_traps_disabled +int spectranet_rst8_trap_disabled +int spectranet_deny_downstream_a15 +int spectranet_page_a +int spectranet_page_b +libspectrum_word spectranet_programmable_trap +libspectrum_byte* spectranet_w5100 1 +libspectrum_byte* spectranet_flash 1 +libspectrum_byte* spectranet_ram 1 Modified: trunk/libspectrum/libspectrum/snapshot.c =================================================================== --- trunk/libspectrum/libspectrum/snapshot.c 2012-11-24 06:50:35 UTC (rev 711) +++ trunk/libspectrum/libspectrum/snapshot.c 2012-11-24 10:24:08 UTC (rev 712) @@ -1,7 +1,7 @@ /* snapshot.c: Snapshot handling routines Copyright (c) 2001-2009 Philip Kendall, Darren Salt - $Id: snapshot.c 4356 2011-04-07 14:21:40Z fredm $ + $Id: snapshot.c 4624 2012-01-09 20:59:35Z pak21 $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -210,6 +210,13 @@ libspectrum_snap_set_melodik_active( snap, 0 ); + libspectrum_snap_set_spectranet_active( snap, 0 ); + libspectrum_snap_set_spectranet_all_traps_disabled( snap, 0 ); + libspectrum_snap_set_spectranet_rst8_trap_disabled( snap, 0 ); + libspectrum_snap_set_spectranet_w5100( snap, 0, NULL ); + libspectrum_snap_set_spectranet_flash( snap, 0, NULL ); + libspectrum_snap_set_spectranet_ram( snap, 0, NULL ); + return snap; } @@ -251,6 +258,13 @@ if( libspectrum_snap_interface1_rom( snap, 0 ) ) libspectrum_free( libspectrum_snap_interface1_rom( snap, 0 ) ); + if( libspectrum_snap_spectranet_w5100( snap, 0 ) ) + libspectrum_free( libspectrum_snap_spectranet_w5100( snap, 0 ) ); + if( libspectrum_snap_spectranet_flash( snap, 0 ) ) + libspectrum_free( libspectrum_snap_spectranet_flash( snap, 0 ) ); + if( libspectrum_snap_spectranet_ram( snap, 0 ) ) + libspectrum_free( libspectrum_snap_spectranet_ram( snap, 0 ) ); + libspectrum_free( snap ); return LIBSPECTRUM_ERROR_NONE; Modified: trunk/libspectrum/libspectrum/szx.c =================================================================== --- trunk/libspectrum/libspectrum/szx.c 2012-11-24 06:50:35 UTC (rev 711) +++ trunk/libspectrum/libspectrum/szx.c 2012-11-24 10:24:08 UTC (rev 712) @@ -1,7 +1,7 @@ /* szx.c: Routines for .szx snapshots Copyright (c) 1998-2010 Philip Kendall, Fredrick Meunier, Stuart Brady - $Id: szx.c 4548 2011-11-06 21:44:48Z pak21 $ + $Id: szx.c 4654 2012-02-03 11:52:16Z fredm $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -66,7 +66,7 @@ static const char *libspectrum_string = "libspectrum: "; static const libspectrum_byte SZX_VERSION_MAJOR = 1; -static const libspectrum_byte SZX_VERSION_MINOR = 3; +static const libspectrum_byte SZX_VERSION_MINOR = 5; /* Constants etc for each chunk type */ @@ -191,6 +191,17 @@ #define ZXSTBID_DIVIDERAMPAGE "DIRP" +#define ZXSTBID_SPECTRANET "SNET" +static const libspectrum_word ZXSTSNET_PAGED = 1; +static const libspectrum_word ZXSTSNET_PAGED_VIA_IO = 2; +static const libspectrum_word ZXSTSNET_PROGRAMMABLE_TRAP_ACTIVE = 4; +static const libspectrum_word ZXSTSNET_PROGRAMMABLE_TRAP_MSB = 8; +static const libspectrum_word ZXSTSNET_ALL_DISABLED = 16; +static const libspectrum_word ZXSTSNET_RST8_DISABLED = 32; +static const libspectrum_word ZXSTSNET_DENY_DOWNSTREAM_A15 = 64; +static const libspectrum_word ZXSTSNET_FLASH_COMPRESSED = 128; +static const libspectrum_word ZXSTSNET_RAM_COMPRESSED = 256; + static libspectrum_error read_chunk( libspectrum_snap *snap, libspectrum_word version, const libspectrum_byte **buffer, const libspectrum_byte *end, @@ -278,6 +289,9 @@ static libspectrum_error write_drum_chunk( libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length, libspectrum_snap *snap ); +static libspectrum_error +write_snet_chunk( libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length, libspectrum_snap *snap, int compress ); #ifdef HAVE_ZLIB_H @@ -1896,6 +1910,140 @@ } static libspectrum_error +read_snet_memory( libspectrum_snap *snap, const libspectrum_byte **buffer, + int compressed, size_t *data_remaining, + void (*setter)(libspectrum_snap*, int, libspectrum_byte*) ) +{ + size_t data_length, uncompressed_length = 0; + libspectrum_error error; + libspectrum_byte *data_out, *uncompressed_data; + const libspectrum_byte *data; + + if( *data_remaining < 4 ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, + "%s:read_snet_memory: not enough data for length", __FILE__ ); + return LIBSPECTRUM_ERROR_UNKNOWN; + } + + data_length = libspectrum_read_dword( buffer ); + *data_remaining -= 4; + + if( *data_remaining < data_length ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, + "%s:read_snet_memory: not enough data", __FILE__ ); + return LIBSPECTRUM_ERROR_UNKNOWN; + } + *data_remaining -= data_length; + + if( compressed ) { + +#ifdef HAVE_ZLIB_H + + error = libspectrum_zlib_inflate( *buffer, data_length, &uncompressed_data, + &uncompressed_length ); + if( error ) return error; + + *buffer += data_length; + + if( uncompressed_length != 0x20000 ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, + "%s:read_snet_memory: data decompressed to %lu but should be 0x20000", + __FILE__, (unsigned long)uncompressed_length ); + libspectrum_free( uncompressed_data ); + return LIBSPECTRUM_ERROR_UNKNOWN; + } + + data = uncompressed_data; + +#else + + libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, + "%s:read_snet_memory: zlib needed for decompression\n", __FILE__ ); + return LIBSPECTRUM_ERROR_UNKNOWN; + +#endif + + } else { + if( data_length != 0x20000 ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, + "%s:read_snet_memory: data has length %lu but should be 0x20000", + __FILE__, (unsigned long)data_length ); + return LIBSPECTRUM_ERROR_NONE; + } + + data = *buffer; + *buffer += data_length; + } + + data_out = libspectrum_malloc( 0x20000 ); + memcpy( data_out, data, 0x20000 ); + setter( snap, 0, data_out ); + + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error +read_snet_chunk( libspectrum_snap *snap, libspectrum_word version GCC_UNUSED, + const libspectrum_byte **buffer, + const libspectrum_byte *end GCC_UNUSED, size_t data_length, + szx_context *ctx GCC_UNUSED ) +{ + libspectrum_word flags; + int flash_compressed, ram_compressed; + libspectrum_error error; + libspectrum_byte *w5100; + size_t data_remaining; + + if( data_length < 62 ) { + libspectrum_print_error( + LIBSPECTRUM_ERROR_UNKNOWN, + "read_snet_chunk: length %lu too short", (unsigned long)data_length + ); + return LIBSPECTRUM_ERROR_UNKNOWN; + } + + libspectrum_snap_set_spectranet_active( snap, 1 ); + + flags = libspectrum_read_word( buffer ); + libspectrum_snap_set_spectranet_paged( snap, flags & ZXSTSNET_PAGED ); + libspectrum_snap_set_spectranet_paged_via_io( snap, flags & ZXSTSNET_PAGED_VIA_IO ); + libspectrum_snap_set_spectranet_programmable_trap_active( snap, + flags & ZXSTSNET_PROGRAMMABLE_TRAP_ACTIVE ); + libspectrum_snap_set_spectranet_programmable_trap_msb( snap, + flags & ZXSTSNET_PROGRAMMABLE_TRAP_MSB ); + libspectrum_snap_set_spectranet_all_traps_disabled( snap, flags & ZXSTSNET_ALL_DISABLED ); + libspectrum_snap_set_spectranet_rst8_trap_disabled( snap, flags & ZXSTSNET_RST8_DISABLED ); + libspectrum_snap_set_spectranet_deny_downstream_a15( snap, flags & ZXSTSNET_DENY_DOWNSTREAM_A15 ); + flash_compressed = flags & ZXSTSNET_FLASH_COMPRESSED; + ram_compressed = flags & ZXSTSNET_RAM_COMPRESSED; + + libspectrum_snap_set_spectranet_page_a( snap, **buffer ); (*buffer)++; + libspectrum_snap_set_spectranet_page_b( snap, **buffer ); (*buffer)++; + + libspectrum_snap_set_spectranet_programmable_trap( snap, + libspectrum_read_word( buffer ) ); + + w5100 = libspectrum_malloc( 0x30 * sizeof( libspectrum_byte ) ); + libspectrum_snap_set_spectranet_w5100( snap, 0, w5100 ); + memcpy( w5100, *buffer, 0x30 ); + (*buffer) += 0x30; + + data_remaining = data_length - 54; + + error = read_snet_memory( snap, buffer, flash_compressed, &data_remaining, + libspectrum_snap_set_spectranet_flash ); + if( error ) + return error; + + error = read_snet_memory( snap, buffer, ram_compressed, &data_remaining, + libspectrum_snap_set_spectranet_ram ); + if( error ) + return error; + + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error skip_chunk( libspectrum_snap *snap GCC_UNUSED, libspectrum_word version GCC_UNUSED, const libspectrum_byte **buffer, @@ -1944,6 +2092,7 @@ { ZXSTBID_SIMPLEIDE, read_side_chunk }, { ZXSTBID_SPECDRUM, read_drum_chunk }, { ZXSTBID_SPECREGS, read_spcr_chunk }, + { ZXSTBID_SPECTRANET, read_snet_chunk }, { ZXSTBID_TIMEXREGS, read_scld_chunk }, { ZXSTBID_USPEECH, skip_chunk }, { ZXSTBID_Z80REGS, read_z80r_chunk }, @@ -2118,10 +2267,10 @@ default: libspectrum_print_error( - LIBSPECTRUM_MACHINE_UNKNOWN, + LIBSPECTRUM_ERROR_UNKNOWN, "libspectrum_szx_read: unknown machine type %d", (int)*buffer ); - return LIBSPECTRUM_MACHINE_UNKNOWN; + return LIBSPECTRUM_ERROR_UNKNOWN; } /* Skip to the end of the header */ @@ -2295,6 +2444,11 @@ } } + if( libspectrum_snap_spectranet_active( snap ) ) { + error = write_snet_chunk( buffer, &ptr, length, snap, compress ); + if( error ) return error; + } + /* Set length to be actual length, not allocated length */ *length = ptr - *buffer; @@ -3452,6 +3606,111 @@ return LIBSPECTRUM_ERROR_NONE; } +static libspectrum_error +write_snet_chunk( libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length, libspectrum_snap *snap, int compress ) +{ +#ifdef HAVE_ZLIB_H + libspectrum_error error; +#endif + + size_t flash_length; + libspectrum_byte *flash_data; + libspectrum_byte *compressed_flash_data = NULL; + int flash_compressed = 0; + + size_t ram_length; + libspectrum_byte *ram_data; + libspectrum_byte *compressed_ram_data = NULL; + int ram_compressed = 0; + + size_t block_size; + libspectrum_word flags = 0; + + flash_data = libspectrum_snap_spectranet_flash( snap, 0 ); + flash_length = 0x20000; + + ram_data = libspectrum_snap_spectranet_ram( snap, 0 ); + ram_length = 0x20000; + +#ifdef HAVE_ZLIB_H + + if( compress ) { + size_t compressed_length; + + error = libspectrum_zlib_compress( flash_data, flash_length, + &compressed_flash_data, &compressed_length ); + if( error ) return error; + + if( compress & LIBSPECTRUM_FLAG_SNAPSHOT_ALWAYS_COMPRESS || + compressed_length < flash_length ) { + flash_compressed = 1; + flash_data = compressed_flash_data; + flash_length = compressed_length; + } + + error = libspectrum_zlib_compress( ram_data, ram_length, + &compressed_ram_data, &compressed_length ); + if( error ) return error; + + if( compress & LIBSPECTRUM_FLAG_SNAPSHOT_ALWAYS_COMPRESS || + compressed_length < flash_length ) { + ram_compressed = 1; + ram_data = compressed_ram_data; + ram_length = compressed_length; + } + } + +#endif + + block_size = 62 + flash_length + ram_length; + + write_chunk_header( buffer, ptr, length, ZXSTBID_SPECTRANET, block_size ); + + if( libspectrum_snap_spectranet_paged( snap ) ) + flags |= ZXSTSNET_PAGED; + if( libspectrum_snap_spectranet_paged_via_io( snap ) ) + flags |= ZXSTSNET_PAGED_VIA_IO; + if( libspectrum_snap_spectranet_programmable_trap_active( snap ) ) + flags |= ZXSTSNET_PROGRAMMABLE_TRAP_ACTIVE; + if( libspectrum_snap_spectranet_programmable_trap_msb( snap ) ) + flags |= ZXSTSNET_PROGRAMMABLE_TRAP_MSB; + if( libspectrum_snap_spectranet_all_traps_disabled( snap ) ) + flags |= ZXSTSNET_ALL_DISABLED; + if( libspectrum_snap_spectranet_rst8_trap_disabled( snap ) ) + flags |= ZXSTSNET_RST8_DISABLED; + if( libspectrum_snap_spectranet_deny_downstream_a15( snap ) ) + flags |= ZXSTSNET_DENY_DOWNSTREAM_A15; + if( flash_compressed ) + flags |= ZXSTSNET_FLASH_COMPRESSED; + if( ram_compressed ) + flags |= ZXSTSNET_RAM_COMPRESSED; + libspectrum_write_word( ptr, flags ); + + *(*ptr)++ = libspectrum_snap_spectranet_page_a( snap ); + *(*ptr)++ = libspectrum_snap_spectranet_page_b( snap ); + + libspectrum_write_word( ptr, + libspectrum_snap_spectranet_programmable_trap( snap ) ); + + memcpy( *ptr, libspectrum_snap_spectranet_w5100( snap, 0 ), 0x30 ); + (*ptr) += 0x30; + + libspectrum_write_dword( ptr, flash_length ); + memcpy( *ptr, flash_data, flash_length ); *ptr += flash_length; + + libspectrum_write_dword( ptr, ram_length ); + memcpy( *ptr, ram_data, ram_length ); *ptr += ram_length; + + if( flash_compressed ) + libspectrum_free( compressed_flash_data ); + + if( ram_compressed ) + libspectrum_free( compressed_ram_data ); + + return LIBSPECTRUM_ERROR_NONE; +} + static void write_chunk_header( libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length, const char *id, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |