From: <pa...@us...> - 2011-01-30 21:10:11
|
Revision: 4282 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4282&view=rev Author: pak21 Date: 2011-01-30 21:10:05 +0000 (Sun, 30 Jan 2011) Log Message: ----------- Add support for SpecDrum in SZX snapshots (patch #3164313) (Jon Mitchell). Modified Paths: -------------- trunk/libspectrum/accessor.pl trunk/libspectrum/doc/libspectrum.txt trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/snap_accessors.txt trunk/libspectrum/snapshot.c trunk/libspectrum/szx.c Modified: trunk/libspectrum/accessor.pl =================================================================== --- trunk/libspectrum/accessor.pl 2011-01-30 02:55:55 UTC (rev 4281) +++ trunk/libspectrum/accessor.pl 2011-01-30 21:10:05 UTC (rev 4282) @@ -211,6 +211,10 @@ /* Melodik status */ int melodik_active; + + /* Cheetah SpecDrum status */ + int specdrum_active; + libspectrum_signed_byte specdrum_dac; }; /* Initialise a libspectrum_snap structure */ Modified: trunk/libspectrum/doc/libspectrum.txt =================================================================== --- trunk/libspectrum/doc/libspectrum.txt 2011-01-30 02:55:55 UTC (rev 4281) +++ trunk/libspectrum/doc/libspectrum.txt 2011-01-30 21:10:05 UTC (rev 4282) @@ -678,6 +678,9 @@ * int fuller_box_active * int melodik_active +* int specdrum_active +* libspectrum_signed_byte specdrum_dac + Most of those should be fairly self-explanatory; those which may not be are: Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-01-30 02:55:55 UTC (rev 4281) +++ trunk/libspectrum/hacking/ChangeLog 2011-01-30 21:10:05 UTC (rev 4282) @@ -800,3 +800,6 @@ update g_hash_table_new() function to support the g_hash_table_new( NULL, NULL ) syntax (patch #3160211) (Sergio Baldovi). +20110130 accessor.pl,doc/libspectrum.txt,snap_accessors.txt,snapshot.c,szx.c: + add support for SpecDrum in SZX snapshots (patch #3164313) (Jon + Mitchell). Modified: trunk/libspectrum/snap_accessors.txt =================================================================== --- trunk/libspectrum/snap_accessors.txt 2011-01-30 02:55:55 UTC (rev 4281) +++ trunk/libspectrum/snap_accessors.txt 2011-01-30 21:10:05 UTC (rev 4282) @@ -168,3 +168,6 @@ int fuller_box_active int melodik_active + +int specdrum_active +libspectrum_signed_byte specdrum_dac Modified: trunk/libspectrum/snapshot.c =================================================================== --- trunk/libspectrum/snapshot.c 2011-01-30 02:55:55 UTC (rev 4281) +++ trunk/libspectrum/snapshot.c 2011-01-30 21:10:05 UTC (rev 4282) @@ -192,6 +192,9 @@ libspectrum_snap_set_simpleide_active( snap, 0 ); + libspectrum_snap_set_specdrum_active( snap, 0 ); + libspectrum_snap_set_specdrum_dac( snap, 0 ); + libspectrum_snap_set_divide_active( snap, 0 ); libspectrum_snap_set_divide_eprom_writeprotect( snap, 0 ); libspectrum_snap_set_divide_paged( snap, 0 ); Modified: trunk/libspectrum/szx.c =================================================================== --- trunk/libspectrum/szx.c 2011-01-30 02:55:55 UTC (rev 4281) +++ trunk/libspectrum/szx.c 2011-01-30 21:10:05 UTC (rev 4282) @@ -274,6 +274,9 @@ static libspectrum_error write_side_chunk( libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length, libspectrum_snap *snap ); +static libspectrum_error +write_drum_chunk( libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length, libspectrum_snap *snap ); #ifdef HAVE_ZLIB_H @@ -977,6 +980,27 @@ return LIBSPECTRUM_ERROR_NONE; } +static libspectrum_error +read_drum_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 ) +{ + if( data_length != 1 ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, + "%s:read_drum_chunk: unknown length %lu", + __FILE__, (unsigned long)data_length ); + return LIBSPECTRUM_ERROR_UNKNOWN; + } + + libspectrum_snap_set_specdrum_dac( snap, *(*buffer)++ ); + + libspectrum_snap_set_specdrum_active( snap, 1 ); + + return LIBSPECTRUM_ERROR_NONE; +} + + static void add_joystick( libspectrum_snap *snap, libspectrum_joystick type, int inputs ) { @@ -1916,7 +1940,7 @@ { ZXSTBID_RAMPAGE, read_ramp_chunk }, { ZXSTBID_ROM, read_rom_chunk }, { ZXSTBID_SIMPLEIDE, read_side_chunk }, - { ZXSTBID_SPECDRUM, skip_chunk }, + { ZXSTBID_SPECDRUM, read_drum_chunk }, { ZXSTBID_SPECREGS, read_spcr_chunk }, { ZXSTBID_TIMEXREGS, read_scld_chunk }, { ZXSTBID_USPEECH, skip_chunk }, @@ -2254,6 +2278,11 @@ if( error ) return error; } + if( libspectrum_snap_specdrum_active( snap ) ) { + error = write_drum_chunk( buffer, &ptr, length, snap ); + if( error ) return error; + } + if( libspectrum_snap_divide_active( snap ) ) { error = write_dide_chunk( buffer, &ptr, length, snap, compress ); if( error ) return error; @@ -3333,6 +3362,17 @@ } static libspectrum_error +write_drum_chunk( libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length, libspectrum_snap *snap ) +{ + write_chunk_header( buffer, ptr, length, ZXSTBID_SPECDRUM, 1 ); + + *(*ptr)++ = libspectrum_snap_specdrum_dac( snap ); + + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error write_dide_chunk( libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length, libspectrum_snap *snap, int compress ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-01-31 10:47:07
|
Revision: 4285 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4285&view=rev Author: fredm Date: 2011-01-31 10:47:01 +0000 (Mon, 31 Jan 2011) Log Message: ----------- Note info loss of SpecDrum info when writing sna or z80 format snapshots. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/sna.c trunk/libspectrum/z80.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-01-31 10:31:09 UTC (rev 4284) +++ trunk/libspectrum/hacking/ChangeLog 2011-01-31 10:47:01 UTC (rev 4285) @@ -803,3 +803,5 @@ 20110130 accessor.pl,doc/libspectrum.txt,snap_accessors.txt,snapshot.c,szx.c: add support for SpecDrum in SZX snapshots (patch #3164313) (Jon Mitchell). +20110131 sna.c,z80.c: note info loss of SpecDrum info when writing sna or z80 + format snapshots (Fred). Modified: trunk/libspectrum/sna.c =================================================================== --- trunk/libspectrum/sna.c 2011-01-31 10:31:09 UTC (rev 4284) +++ trunk/libspectrum/sna.c 2011-01-31 10:47:01 UTC (rev 4285) @@ -327,6 +327,10 @@ libspectrum_snap_melodik_active( snap ) ) *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MAJOR_INFO_LOSS; + /* We don't save the Specdrum state at all */ + if( libspectrum_snap_specdrum_active( snap ) ) + *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MAJOR_INFO_LOSS; + ptr = *buffer; write_header( buffer, &ptr, length, snap ); Modified: trunk/libspectrum/z80.c =================================================================== --- trunk/libspectrum/z80.c 2011-01-31 10:31:09 UTC (rev 4284) +++ trunk/libspectrum/z80.c 2011-01-31 10:47:01 UTC (rev 4285) @@ -1167,6 +1167,10 @@ if( libspectrum_snap_custom_rom( snap ) ) *out_flags |= LIBSPECTRUM_FLAG_SNAPSHOT_MAJOR_INFO_LOSS; + /* .z80 format doesn't save the Specdrum state at all */ + if( libspectrum_snap_specdrum_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; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-03-27 11:05:53
|
Revision: 4323 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4323&view=rev Author: fredm Date: 2011-03-27 11:05:46 +0000 (Sun, 27 Mar 2011) Log Message: ----------- Allow the user to say they do not want to use windres (works around bug #3248008; thanks, Cygnus). Modified Paths: -------------- trunk/libspectrum/configure.in trunk/libspectrum/hacking/ChangeLog Modified: trunk/libspectrum/configure.in =================================================================== --- trunk/libspectrum/configure.in 2011-03-20 18:06:00 UTC (rev 4322) +++ trunk/libspectrum/configure.in 2011-03-27 11:05:46 UTC (rev 4323) @@ -53,17 +53,25 @@ dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST -dnl Check for Win32 resource tool -AC_CHECK_TOOL(WINDRES, windres, no) -AC_SUBST(WINDRES) -if test "$WINDRES" != no; then - WINDRES_OBJ="windres.o" - WINDRES_LDFLAGS="-Xlinker windres.o" - define(LIBSPECTRUM_FULL_VERSION, - [ifelse(translit(LIBSPECTRUM_VERSION, [0-9]), [.], [LIBSPECTRUM_VERSION[.0.0]], - translit(LIBSPECTRUM_VERSION, [0-9]), [..], [LIBSPECTRUM_VERSION[.0]], - [LIBSPECTRUM_VERSION])])dnl - AC_DEFINE([VERSION_WIN32], [translit(LIBSPECTRUM_FULL_VERSION, [.], [,])], [Define version information for win32 dll library]) +dnl Check whether to use Windows resource file utility +AC_MSG_CHECKING(whether to use windres) +AC_ARG_WITH(windres, +[ --without-windres don't use windres], +if test "$withval" = no; then windres=no; else windres=yes; fi, +windres=yes) +AC_MSG_RESULT($windres) +if test "$windres" = yes; then + AC_CHECK_TOOL(WINDRES, windres, no) + AC_SUBST(WINDRES) + if test "$WINDRES" != no; then + WINDRES_OBJ="windres.o" + WINDRES_LDFLAGS="-Xlinker windres.o" + define(LIBSPECTRUM_FULL_VERSION, + [ifelse(translit(LIBSPECTRUM_VERSION, [0-9]), [.], [LIBSPECTRUM_VERSION[.0.0]], + translit(LIBSPECTRUM_VERSION, [0-9]), [..], [LIBSPECTRUM_VERSION[.0]], + [LIBSPECTRUM_VERSION])])dnl + AC_DEFINE([VERSION_WIN32], [translit(LIBSPECTRUM_FULL_VERSION, [.], [,])], [Define version information for win32 dll library]) + fi fi AC_SUBST(WINDRES_OBJ) AM_SUBST_NOTMAKE(WINDRES_OBJ) Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-03-20 18:06:00 UTC (rev 4322) +++ trunk/libspectrum/hacking/ChangeLog 2011-03-27 11:05:46 UTC (rev 4323) @@ -805,3 +805,5 @@ Mitchell). 20110131 sna.c,z80.c: note info loss of SpecDrum info when writing sna or z80 format snapshots (Fred). +20110327 configure.in: allow the user to say they do not want to use windres + (works around bug #3248008; thanks, Cygnus). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2011-04-04 23:15:42
|
Revision: 4346 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4346&view=rev Author: zubzero Date: 2011-04-04 23:15:36 +0000 (Mon, 04 Apr 2011) Log Message: ----------- Add missing WIN32_DLL. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.h.in Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-04 20:14:04 UTC (rev 4345) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-04 23:15:36 UTC (rev 4346) @@ -807,3 +807,4 @@ format snapshots (Fred). 20110327 configure.in: allow the user to say they do not want to use windres (works around bug #3248008; thanks, Cygnus). +20110405 libspectrum.h.in: add missing WIN32_DLL (Stuart). Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2011-04-04 20:14:04 UTC (rev 4345) +++ trunk/libspectrum/libspectrum.h.in 2011-04-04 23:15:36 UTC (rev 4346) @@ -772,7 +772,7 @@ } libspectrum_rzx_block_id; -void +WIN32_DLL void libspectrum_rzx_insert_snap( libspectrum_rzx *rzx, libspectrum_snap *snap, int where ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-07 14:21:48
|
Revision: 4356 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4356&view=rev Author: fredm Date: 2011-04-07 14:21:40 +0000 (Thu, 07 Apr 2011) Log Message: ----------- Add support for Beta 128 interface autoboot setting in SZX snapshots. Modified Paths: -------------- trunk/libspectrum/accessor.pl trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/snap_accessors.txt trunk/libspectrum/snapshot.c trunk/libspectrum/szx.c Modified: trunk/libspectrum/accessor.pl =================================================================== --- trunk/libspectrum/accessor.pl 2011-04-07 14:06:27 UTC (rev 4355) +++ trunk/libspectrum/accessor.pl 2011-04-07 14:21:40 UTC (rev 4356) @@ -119,6 +119,7 @@ /* Betadisk status */ int beta_active; int beta_paged; + int beta_autoboot; int beta_drive_count; int beta_custom_rom; int beta_direction; /* FDC seek direction: Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-07 14:06:27 UTC (rev 4355) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-07 14:21:40 UTC (rev 4356) @@ -808,3 +808,5 @@ 20110327 configure.in: allow the user to say they do not want to use windres (works around bug #3248008; thanks, Cygnus). 20110405 libspectrum.h.in: add missing WIN32_DLL (Stuart). +20110407 accessor.pl,snap_accessors.txt,snapshot.c,szx.c: add support for Beta + 128 interface autoboot setting in SZX snapshots (Fred). Modified: trunk/libspectrum/snap_accessors.txt =================================================================== --- trunk/libspectrum/snap_accessors.txt 2011-04-07 14:06:27 UTC (rev 4355) +++ trunk/libspectrum/snap_accessors.txt 2011-04-07 14:21:40 UTC (rev 4356) @@ -68,6 +68,7 @@ int beta_active int beta_paged +int beta_autoboot int beta_drive_count int beta_custom_rom int beta_direction Modified: trunk/libspectrum/snapshot.c =================================================================== --- trunk/libspectrum/snapshot.c 2011-04-07 14:06:27 UTC (rev 4355) +++ trunk/libspectrum/snapshot.c 2011-04-07 14:21:40 UTC (rev 4356) @@ -109,6 +109,7 @@ libspectrum_snap_set_beta_active( snap, 0 ); libspectrum_snap_set_beta_paged( snap, 0 ); + libspectrum_snap_set_beta_autoboot( snap, 0 ); libspectrum_snap_set_beta_drive_count( snap, 0 ); libspectrum_snap_set_beta_custom_rom( snap, 0 ); libspectrum_snap_set_beta_direction( snap, 0 ); Modified: trunk/libspectrum/szx.c =================================================================== --- trunk/libspectrum/szx.c 2011-04-07 14:06:27 UTC (rev 4355) +++ trunk/libspectrum/szx.c 2011-04-07 14:21:40 UTC (rev 4356) @@ -139,6 +139,7 @@ static const libspectrum_dword ZXSTBETAF_CONNECTED = 1; static const libspectrum_dword ZXSTBETAF_CUSTOMROM = 2; static const libspectrum_dword ZXSTBETAF_PAGED = 4; +static const libspectrum_dword ZXSTBETAF_AUTOBOOT = 8; static const libspectrum_dword ZXSTBETAF_SEEKLOWER = 16; static const libspectrum_dword ZXSTBETAF_COMPRESSED = 32; @@ -444,6 +445,7 @@ flags = libspectrum_read_dword( buffer ); libspectrum_snap_set_beta_active( snap, 1 ); libspectrum_snap_set_beta_paged( snap, flags & ZXSTBETAF_PAGED ); + libspectrum_snap_set_beta_autoboot( snap, flags & ZXSTBETAF_AUTOBOOT ); libspectrum_snap_set_beta_direction( snap, !( flags & ZXSTBETAF_SEEKLOWER ) ); @@ -2927,6 +2929,7 @@ flags = ZXSTBETAF_CONNECTED; /* Betadisk interface connected */ if( libspectrum_snap_beta_paged( snap ) ) flags |= ZXSTBETAF_PAGED; + if( libspectrum_snap_beta_autoboot( snap ) ) flags |= ZXSTBETAF_AUTOBOOT; if( !libspectrum_snap_beta_direction( snap ) ) flags |= ZXSTBETAF_SEEKLOWER; if( libspectrum_snap_beta_custom_rom( snap ) ) flags |= ZXSTBETAF_CUSTOMROM; if( use_compression ) flags |= ZXSTBETAF_COMPRESSED; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-22 11:50:57
|
Revision: 4371 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4371&view=rev Author: fredm Date: 2011-04-22 11:50:51 +0000 (Fri, 22 Apr 2011) Log Message: ----------- ROM block duration didn't take into account pilot and sync pulses (Fred). Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tape_block.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-15 12:13:26 UTC (rev 4370) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-22 11:50:51 UTC (rev 4371) @@ -810,3 +810,5 @@ 20110405 libspectrum.h.in: add missing WIN32_DLL (Stuart). 20110407 accessor.pl,snap_accessors.txt,snapshot.c,szx.c: add support for Beta 128 interface autoboot setting in SZX snapshots (Fred). +20110422 tape_block.c: ROM block duration didn't take into account pilot and + sync pulses (Fred). Modified: trunk/libspectrum/tape_block.c =================================================================== --- trunk/libspectrum/tape_block.c 2011-04-15 12:13:26 UTC (rev 4370) +++ trunk/libspectrum/tape_block.c 2011-04-22 11:50:51 UTC (rev 4371) @@ -498,6 +498,13 @@ libspectrum_dword length = convert_ms_to_tstates( rom->pause ); size_t i; + size_t edge_count = rom->length && rom->data[0] & 0x80 ? + LIBSPECTRUM_TAPE_PILOTS_DATA : + LIBSPECTRUM_TAPE_PILOTS_HEADER; + length += LIBSPECTRUM_TAPE_TIMING_PILOT * edge_count; + length += LIBSPECTRUM_TAPE_TIMING_SYNC1; + length += LIBSPECTRUM_TAPE_TIMING_SYNC2; + for( i = 0; i < rom->length; i++ ) { libspectrum_byte data = rom->data[ i ]; length += convert_pulses_to_tstates( LIBSPECTRUM_TAPE_TIMING_DATA1, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-22 13:49:31
|
Revision: 4372 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4372&view=rev Author: fredm Date: 2011-04-22 13:49:24 +0000 (Fri, 22 Apr 2011) Log Message: ----------- Don't expect an edge for a jump, group start/end, loop start/end or other non-audio blocks. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tape.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-22 11:50:51 UTC (rev 4371) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-22 13:49:24 UTC (rev 4372) @@ -812,3 +812,5 @@ 128 interface autoboot setting in SZX snapshots (Fred). 20110422 tape_block.c: ROM block duration didn't take into account pilot and sync pulses (Fred). +20110422 tape.c: don't expect an edge for a jump, group start/end, loop + start/end or other non-audio blocks (Fred). Modified: trunk/libspectrum/tape.c =================================================================== --- trunk/libspectrum/tape.c 2011-04-22 11:50:51 UTC (rev 4371) +++ trunk/libspectrum/tape.c 2011-04-22 13:49:24 UTC (rev 4372) @@ -372,7 +372,8 @@ case LIBSPECTRUM_TAPE_BLOCK_JUMP: error = jump_blocks( tape, block->types.jump.offset ); if( error ) return error; - *tstates = 0; end_of_block = 1; no_advance = 1; + *tstates = 0; *flags |= LIBSPECTRUM_TAPE_FLAGS_NO_EDGE; end_of_block = 1; + no_advance = 1; break; case LIBSPECTRUM_TAPE_BLOCK_LOOP_START: @@ -380,7 +381,7 @@ it->loop_block = it->current_block->next; it->loop_count = block->types.loop_start.count; } - *tstates = 0; end_of_block = 1; + *tstates = 0; *flags |= LIBSPECTRUM_TAPE_FLAGS_NO_EDGE; end_of_block = 1; break; case LIBSPECTRUM_TAPE_BLOCK_LOOP_END: @@ -392,7 +393,7 @@ it->loop_block = NULL; } } - *tstates = 0; end_of_block = 1; + *tstates = 0; *flags |= LIBSPECTRUM_TAPE_FLAGS_NO_EDGE; end_of_block = 1; break; case LIBSPECTRUM_TAPE_BLOCK_STOP48: @@ -409,7 +410,7 @@ case LIBSPECTRUM_TAPE_BLOCK_ARCHIVE_INFO: case LIBSPECTRUM_TAPE_BLOCK_HARDWARE: case LIBSPECTRUM_TAPE_BLOCK_CUSTOM: - *tstates = 0; end_of_block = 1; + *tstates = 0; *flags |= LIBSPECTRUM_TAPE_FLAGS_NO_EDGE; end_of_block = 1; break; case LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-27 02:31:24
|
Revision: 4379 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4379&view=rev Author: fredm Date: 2011-04-27 02:31:17 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Centralise ms/tstate conversions and tape block pause setting functions. Modified Paths: -------------- trunk/libspectrum/Makefile.am trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/internals.h trunk/libspectrum/tap.c trunk/libspectrum/tape_block.c trunk/libspectrum/tzx_read.c trunk/libspectrum/warajevo_read.c Added Paths: ----------- trunk/libspectrum/utilities.c Modified: trunk/libspectrum/Makefile.am =================================================================== --- trunk/libspectrum/Makefile.am 2011-04-26 23:02:06 UTC (rev 4378) +++ trunk/libspectrum/Makefile.am 2011-04-27 02:31:17 UTC (rev 4379) @@ -51,6 +51,7 @@ timings.c \ tzx_read.c \ tzx_write.c \ + utilities.c \ warajevo_read.c \ wav.c \ windres.rc \ Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-26 23:02:06 UTC (rev 4378) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-27 02:31:17 UTC (rev 4379) @@ -814,3 +814,6 @@ sync pulses (Fred). 20110422 tape.c: don't expect an edge for a jump, group start/end, loop start/end or other non-audio blocks (Fred). +20110427 Makefile.am,internals.h,tap.c,tape_block.c,tzx_read.c,utilities.c, + warajevo_read.c: centralise ms/tstate conversions and tape block pause + setting functions (Fred). Modified: trunk/libspectrum/internals.h =================================================================== --- trunk/libspectrum/internals.h 2011-04-26 23:02:06 UTC (rev 4378) +++ trunk/libspectrum/internals.h 2011-04-27 02:31:17 UTC (rev 4379) @@ -235,4 +235,22 @@ libspectrum_byte *data, size_t data_length, libspectrum_rzx_dsa_key *key ); +/* Utility functions */ + +libspectrum_dword +libspectrum_ms_to_tstates( libspectrum_dword ms ); + +libspectrum_dword +libspectrum_tstates_to_ms( libspectrum_dword tstates ); + +void +libspectrum_set_pause_ms( libspectrum_tape_block *block, + libspectrum_dword pause_ms ); + +void +libspectrum_set_pause_tstates( libspectrum_tape_block *block, + libspectrum_dword pause_tstates ); + +extern const int LIBSPECTRUM_BITS_IN_BYTE; + #endif /* #ifndef LIBSPECTRUM_INTERNALS_H */ Modified: trunk/libspectrum/tap.c =================================================================== --- trunk/libspectrum/tap.c 2011-04-26 23:02:06 UTC (rev 4378) +++ trunk/libspectrum/tap.c 2011-04-27 02:31:17 UTC (rev 4379) @@ -126,7 +126,7 @@ ptr += buf_length; /* Give a 1s pause after each block */ - libspectrum_tape_block_set_pause( block, 1000 ); + libspectrum_set_pause_ms( block, 1000 ); libspectrum_tape_append_block( tape, block ); } Modified: trunk/libspectrum/tape_block.c =================================================================== --- trunk/libspectrum/tape_block.c 2011-04-26 23:02:06 UTC (rev 4378) +++ trunk/libspectrum/tape_block.c 2011-04-27 02:31:17 UTC (rev 4379) @@ -37,8 +37,6 @@ static const size_t LIBSPECTRUM_TAPE_PILOTS_HEADER = 0x1f7f; static const size_t LIBSPECTRUM_TAPE_PILOTS_DATA = 0x0c97; -#define TZX_HZ 3500000 - /* Functions to initialise block types */ static libspectrum_error @@ -445,7 +443,7 @@ #define BITS_SET_ARRAY_SIZE 256 static int bits_set[ BITS_SET_ARRAY_SIZE ]; -static const int LIBSPECTRUM_BITS_IN_BYTE = 8; +const int LIBSPECTRUM_BITS_IN_BYTE = 8; static int libspectrum_bits_set_n_bits( libspectrum_byte byte, libspectrum_byte bits ) @@ -486,16 +484,9 @@ } static libspectrum_dword -convert_ms_to_tstates( libspectrum_dword ms ) -{ - static const libspectrum_dword tstates_per_ms = TZX_HZ / 1000; - return ms * tstates_per_ms; -} - -static libspectrum_dword rom_block_length( libspectrum_tape_rom_block *rom ) { - libspectrum_dword length = convert_ms_to_tstates( rom->pause ); + libspectrum_dword length = libspectrum_ms_to_tstates( rom->pause ); size_t i; size_t edge_count = rom->length && rom->data[0] & 0x80 ? @@ -522,7 +513,7 @@ libspectrum_dword length = turbo->pilot_pulses * turbo->pilot_length + turbo->sync1_length + turbo->sync2_length + - convert_ms_to_tstates( turbo->pause ); + libspectrum_ms_to_tstates( turbo->pause ); size_t i; if( turbo->length ) { int bits_set_in_last_byte = @@ -561,7 +552,7 @@ static libspectrum_dword pure_data_block_length( libspectrum_tape_pure_data_block *pure_data ) { - libspectrum_dword length = convert_ms_to_tstates( pure_data->pause ); + libspectrum_dword length = libspectrum_ms_to_tstates( pure_data->pause ); size_t i; if( pure_data->length ) { int bits_set_in_last_byte = @@ -589,7 +580,7 @@ static libspectrum_dword raw_data_block_length( libspectrum_tape_raw_data_block *raw_data ) { - libspectrum_dword length = convert_ms_to_tstates( raw_data->pause ); + libspectrum_dword length = libspectrum_ms_to_tstates( raw_data->pause ); length += ( LIBSPECTRUM_BITS_IN_BYTE * raw_data->length - ( LIBSPECTRUM_BITS_IN_BYTE - raw_data->bits_in_last_byte ) ) * @@ -656,7 +647,7 @@ case LIBSPECTRUM_TAPE_BLOCK_PURE_DATA: return pure_data_block_length( &block->types.pure_data ); case LIBSPECTRUM_TAPE_BLOCK_PAUSE: - return convert_ms_to_tstates( block->types.pause.length ); + return libspectrum_ms_to_tstates( block->types.pause.length ); case LIBSPECTRUM_TAPE_BLOCK_RAW_DATA: return raw_data_block_length( &block->types.raw_data ); case LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE: Modified: trunk/libspectrum/tzx_read.c =================================================================== --- trunk/libspectrum/tzx_read.c 2011-04-26 23:02:06 UTC (rev 4378) +++ trunk/libspectrum/tzx_read.c 2011-04-27 02:31:17 UTC (rev 4379) @@ -270,7 +270,7 @@ block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_ROM ); /* Get the pause length */ - libspectrum_tape_block_set_pause( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); + libspectrum_set_pause_ms( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); (*ptr) += 2; /* And the data */ @@ -323,7 +323,7 @@ (*ptr)[0] + (*ptr)[1] * 0x100 ); (*ptr) += 2; libspectrum_tape_block_set_bits_in_last_byte( block, **ptr ); (*ptr)++; - libspectrum_tape_block_set_pause ( block, + libspectrum_set_pause_ms ( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); (*ptr) += 2; Added: trunk/libspectrum/utilities.c =================================================================== --- trunk/libspectrum/utilities.c (rev 0) +++ trunk/libspectrum/utilities.c 2011-04-27 02:31:17 UTC (rev 4379) @@ -0,0 +1,59 @@ +/* utilities.c: miscellaneous utility routines + Copyright (c) 2011 Philip Kendall + + $Id$ + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + Author contact information: + + E-mail: Philip Kendall <phi...@sh...> + +*/ + +#include <config.h> + +#include "internals.h" + +#define TZX_HZ 3500000 + +static const libspectrum_dword tstates_per_ms = TZX_HZ / 1000; + +libspectrum_dword +libspectrum_ms_to_tstates( libspectrum_dword ms ) +{ + return ms * tstates_per_ms; +} + +libspectrum_dword +libspectrum_tstates_to_ms( libspectrum_dword tstates ) +{ + return tstates / tstates_per_ms; +} + +void +libspectrum_set_pause_ms( libspectrum_tape_block *block, + libspectrum_dword pause_ms ) +{ + libspectrum_tape_block_set_pause( block, pause_ms ); +} + +void +libspectrum_set_pause_tstates( libspectrum_tape_block *block, + libspectrum_dword pause_tstates ) +{ + libspectrum_tape_block_set_pause( block, + libspectrum_tstates_to_ms( pause_tstates ) ); +} Property changes on: trunk/libspectrum/utilities.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/libspectrum/warajevo_read.c =================================================================== --- trunk/libspectrum/warajevo_read.c 2011-04-26 23:02:06 UTC (rev 4378) +++ trunk/libspectrum/warajevo_read.c 2011-04-27 02:31:17 UTC (rev 4379) @@ -496,7 +496,7 @@ block_data[ length - 1 ] ^= block_data[i]; /* Give a 1s pause after each block */ - libspectrum_tape_block_set_pause( block, 1000 ); + libspectrum_set_pause_ms( block, 1000 ); /* Put the block into the block list */ libspectrum_tape_append_block( tape, block ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-27 02:45:24
|
Revision: 4380 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4380&view=rev Author: fredm Date: 2011-04-27 02:45:18 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Complete centralisation of tape block pause setting functions. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tzx_read.c trunk/libspectrum/tzx_write.c trunk/libspectrum/warajevo_read.c trunk/libspectrum/wav.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-27 02:31:17 UTC (rev 4379) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-27 02:45:18 UTC (rev 4380) @@ -817,3 +817,5 @@ 20110427 Makefile.am,internals.h,tap.c,tape_block.c,tzx_read.c,utilities.c, warajevo_read.c: centralise ms/tstate conversions and tape block pause setting functions (Fred). +20110427 tzx_read.c,tzx_write.c,warajevo_read.c,wav.c: complete centralisation + of tape block pause setting functions (Fred). Modified: trunk/libspectrum/tzx_read.c =================================================================== --- trunk/libspectrum/tzx_read.c 2011-04-27 02:31:17 UTC (rev 4379) +++ trunk/libspectrum/tzx_read.c 2011-04-27 02:45:18 UTC (rev 4380) @@ -439,7 +439,7 @@ (*ptr)[0] + (*ptr)[1] * 0x100 ); (*ptr) += 2; libspectrum_tape_block_set_bits_in_last_byte( block, **ptr ); (*ptr)++; - libspectrum_tape_block_set_pause( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); + libspectrum_set_pause_ms( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); (*ptr) += 2; /* And the actual data */ @@ -473,8 +473,7 @@ /* Get the metadata */ libspectrum_tape_block_set_bit_length( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); - libspectrum_tape_block_set_pause ( block, - (*ptr)[2] + (*ptr)[3] * 0x100 ); + libspectrum_set_pause_ms( block, (*ptr)[2] + (*ptr)[3] * 0x100 ); libspectrum_tape_block_set_bits_in_last_byte( block, (*ptr)[4] ); (*ptr) += 5; @@ -536,7 +535,7 @@ libspectrum_tape_block_zero( block ); - libspectrum_tape_block_set_pause( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); + libspectrum_set_pause_ms( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); (*ptr) += 2; error = libspectrum_tape_block_read_symbol_table_parameters( block, 1, ptr ); @@ -639,7 +638,7 @@ block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PAUSE ); /* Get the pause length */ - libspectrum_tape_block_set_pause( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); + libspectrum_set_pause_ms( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); (*ptr) += 2; libspectrum_tape_append_block( tape, block ); @@ -867,7 +866,7 @@ block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_MESSAGE ); /* Get the time */ - libspectrum_tape_block_set_pause( block, **ptr ); (*ptr)++; + libspectrum_set_pause_ms( block, **ptr ); (*ptr)++; /* Get the message itself */ error = tzx_read_string( ptr, end, &text ); Modified: trunk/libspectrum/tzx_write.c =================================================================== --- trunk/libspectrum/tzx_write.c 2011-04-27 02:31:17 UTC (rev 4379) +++ trunk/libspectrum/tzx_write.c 2011-04-27 02:45:18 UTC (rev 4380) @@ -738,7 +738,7 @@ libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_RAW_DATA ); libspectrum_tape_block_set_bit_length( raw_block, scale ); - libspectrum_tape_block_set_pause ( raw_block, 0 ); + libspectrum_set_pause_ms( raw_block, 0 ); rle_state.bits_used = 0; rle_state.level = 0; Modified: trunk/libspectrum/warajevo_read.c =================================================================== --- trunk/libspectrum/warajevo_read.c 2011-04-27 02:31:17 UTC (rev 4379) +++ trunk/libspectrum/warajevo_read.c 2011-04-27 02:45:18 UTC (rev 4380) @@ -567,7 +567,7 @@ } libspectrum_tape_block_set_bit_length( block, bit_length ); - libspectrum_tape_block_set_pause( block, 0 ); + libspectrum_set_pause_tstates( block, 0 ); libspectrum_tape_block_set_bits_in_last_byte( block, status.bits.bits_used + 1 ); Modified: trunk/libspectrum/wav.c =================================================================== --- trunk/libspectrum/wav.c 2011-04-27 02:31:17 UTC (rev 4379) +++ trunk/libspectrum/wav.c 2011-04-27 02:45:18 UTC (rev 4380) @@ -127,7 +127,7 @@ /* 44100 Hz 79 t-states 22050 Hz 158 t-states */ libspectrum_tape_block_set_bit_length( block, 3500000/afGetRate( handle, track ) ); - libspectrum_tape_block_set_pause ( block, 0 ); + libspectrum_set_pause_ms( block, 0 ); libspectrum_tape_block_set_bits_in_last_byte( block, length%8 ? length%8 : 8 ); libspectrum_tape_block_set_data_length( block, tape_length/8 ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-27 02:56:52
|
Revision: 4381 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4381&view=rev Author: fredm Date: 2011-04-27 02:56:46 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Add comments for LIBSPECTRUM_TAPE_FLAGS_LENGTH_SHORT and LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG (Fred). Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.h.in trunk/libspectrum/tape.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-27 02:45:18 UTC (rev 4380) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-27 02:56:46 UTC (rev 4381) @@ -819,3 +819,6 @@ setting functions (Fred). 20110427 tzx_read.c,tzx_write.c,warajevo_read.c,wav.c: complete centralisation of tape block pause setting functions (Fred). +20110427 libspectrum.h.in,tape.c: add comments for + LIBSPECTRUM_TAPE_FLAGS_LENGTH_SHORT and + LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG (Fred). Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2011-04-27 02:45:18 UTC (rev 4380) +++ trunk/libspectrum/libspectrum.h.in 2011-04-27 02:56:46 UTC (rev 4381) @@ -529,8 +529,10 @@ extern WIN32_DLL const int LIBSPECTRUM_TAPE_FLAGS_NO_EDGE; /* Edge isn't really an edge */ extern WIN32_DLL const int LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; /* Set level low */ extern WIN32_DLL const int LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH; /* Set level high */ -extern WIN32_DLL const int LIBSPECTRUM_TAPE_FLAGS_LENGTH_SHORT; -extern WIN32_DLL const int LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG; +extern WIN32_DLL const int LIBSPECTRUM_TAPE_FLAGS_LENGTH_SHORT;/* Short edge; + used for loader acceleration */ +extern WIN32_DLL const int LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG; /* Long edge; + used for loader acceleration */ extern WIN32_DLL const int LIBSPECTRUM_TAPE_FLAGS_TAPE; /* Tape has finished */ /* The states which a block can be in */ Modified: trunk/libspectrum/tape.c =================================================================== --- trunk/libspectrum/tape.c 2011-04-27 02:45:18 UTC (rev 4380) +++ trunk/libspectrum/tape.c 2011-04-27 02:56:46 UTC (rev 4381) @@ -298,8 +298,10 @@ const int LIBSPECTRUM_TAPE_FLAGS_NO_EDGE = 1 << 3; /* Not an edge really */ const int LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW = 1 << 4; /* Set level low */ const int LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH = 1 << 5; /* Set level high */ -const int LIBSPECTRUM_TAPE_FLAGS_LENGTH_SHORT = 1 << 6; -const int LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG = 1 << 7; +const int LIBSPECTRUM_TAPE_FLAGS_LENGTH_SHORT = 1 << 6;/* Short edge; used for + loader acceleration */ +const int LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG = 1 << 7; /* Long edge; used for + loader acceleration */ const int LIBSPECTRUM_TAPE_FLAGS_TAPE = 1 << 8; /* End of tape */ libspectrum_error This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-27 03:06:09
|
Revision: 4382 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4382&view=rev Author: fredm Date: 2011-04-27 03:06:03 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Use centralised methods for ms/tstate conversions. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tape.c trunk/libspectrum/test/test15.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-27 02:56:46 UTC (rev 4381) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-27 03:06:03 UTC (rev 4382) @@ -822,3 +822,5 @@ 20110427 libspectrum.h.in,tape.c: add comments for LIBSPECTRUM_TAPE_FLAGS_LENGTH_SHORT and LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG (Fred). +20110427 tape.c,test/test15.c: use centralised methods for ms/tstate conversions + (Fred). Modified: trunk/libspectrum/tape.c =================================================================== --- trunk/libspectrum/tape.c 2011-04-27 02:56:46 UTC (rev 4381) +++ trunk/libspectrum/tape.c 2011-04-27 03:06:03 UTC (rev 4382) @@ -526,8 +526,7 @@ case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ - *tstates = (block->pause * 69888)/20; /* FIXME: should vary with tstates - per frame */ + *tstates = libspectrum_ms_to_tstates( block->pause ); *end_of_block = 1; break; @@ -624,8 +623,7 @@ case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ - *tstates = (block->pause * 69888)/20; /* FIXME: should vary with tstates - per frame */ + *tstates = libspectrum_ms_to_tstates( block->pause ); *end_of_block = 1; break; @@ -733,8 +731,7 @@ case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ - *tstates = (block->pause * 69888)/20; /* FIXME: should vary with tstates - per frame */ + *tstates = libspectrum_ms_to_tstates( block->pause ); *end_of_block = 1; break; @@ -802,8 +799,7 @@ case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ - *tstates = ( block->pause * 69888 )/20; /* FIXME: should vary with tstates - per frame */ + *tstates = libspectrum_ms_to_tstates( block->pause ); *end_of_block = 1; break; @@ -963,8 +959,7 @@ case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ - *tstates = ( block->pause * 69888 )/20; /* FIXME: should vary with tstates - per frame */ + *tstates = libspectrum_ms_to_tstates( block->pause ); *end_of_block = 1; break; Modified: trunk/libspectrum/test/test15.c =================================================================== --- trunk/libspectrum/test/test15.c 2011-04-27 02:56:46 UTC (rev 4381) +++ trunk/libspectrum/test/test15.c 2011-04-27 03:06:03 UTC (rev 4382) @@ -17,7 +17,7 @@ { 1710, 2, 0 }, /* Bit 7 */ { 855, 2, 0 }, /* Bit 8 */ - { 8194368, 1, 0 }, /* Pause */ + { 8207500, 1, 0 }, /* Pause */ /* Turbo speed data block */ { 1000, 5, 0 }, /* Pilot */ @@ -41,7 +41,7 @@ { 400, 2, 0 }, /* Byte 4, bit 3 */ { 789, 2, 0 }, /* Byte 4, bit 4 */ - { 3448972, 1, 0 }, /* Pause */ + { 3454500, 1, 0 }, /* Pause */ /* Pure tone block */ { 535, 666, 0 }, @@ -55,7 +55,7 @@ { 1639, 16, 0 }, /* Byte 1, bits 1-8 */ { 552, 16, 0 }, /* Byte 2, bits 1-8 */ { 1639, 12, 0 }, /* Byte 3, bits 1-6 */ - { 1935897, 1, 0 }, /* Pause */ + { 1939000, 1, 0 }, /* Pause */ /* Pause block */ { 2159539, 1, 0 }, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-27 06:00:32
|
Revision: 4383 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4383&view=rev Author: fredm Date: 2011-04-27 06:00:26 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Use more centralised methods for ms/tstate conversions. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tape.c trunk/libspectrum/test/test15.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-27 03:06:03 UTC (rev 4382) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-27 06:00:26 UTC (rev 4383) @@ -824,3 +824,5 @@ LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG (Fred). 20110427 tape.c,test/test15.c: use centralised methods for ms/tstate conversions (Fred). +20110427 tape.c,test/test15.c: use more centralised methods for ms/tstate + conversions (Fred). Modified: trunk/libspectrum/tape.c =================================================================== --- trunk/libspectrum/tape.c 2011-04-27 03:06:03 UTC (rev 4382) +++ trunk/libspectrum/tape.c 2011-04-27 06:00:26 UTC (rev 4383) @@ -366,7 +366,8 @@ break; case LIBSPECTRUM_TAPE_BLOCK_PAUSE: - *tstates = ( block->types.pause.length * 69888 ) / 20; end_of_block = 1; + *tstates = libspectrum_ms_to_tstates( block->types.pause.length ); + end_of_block = 1; /* 0 ms pause => stop tape */ if( *tstates == 0 ) { *flags |= LIBSPECTRUM_TAPE_FLAGS_STOP; } break; Modified: trunk/libspectrum/test/test15.c =================================================================== --- trunk/libspectrum/test/test15.c 2011-04-27 03:06:03 UTC (rev 4382) +++ trunk/libspectrum/test/test15.c 2011-04-27 06:00:26 UTC (rev 4383) @@ -58,7 +58,7 @@ { 1939000, 1, 0 }, /* Pause */ /* Pause block */ - { 2159539, 1, 0 }, + { 2163000, 1, 0 }, /* Group start block */ { 0, 1, 0 }, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-27 06:14:54
|
Revision: 4384 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4384&view=rev Author: fredm Date: 2011-04-27 06:14:48 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Initialise machine_type to avoid a warning. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/z80.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-27 06:00:26 UTC (rev 4383) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-27 06:14:48 UTC (rev 4384) @@ -826,3 +826,4 @@ (Fred). 20110427 tape.c,test/test15.c: use more centralised methods for ms/tstate conversions (Fred). +20110427 z80.c: initialise machine_type to avoid a warning (Fred). Modified: trunk/libspectrum/z80.c =================================================================== --- trunk/libspectrum/z80.c 2011-04-27 06:00:26 UTC (rev 4383) +++ trunk/libspectrum/z80.c 2011-04-27 06:14:48 UTC (rev 4384) @@ -1274,7 +1274,7 @@ int i, bottom_16kb_ram; libspectrum_byte hardware_flag = 0; /* No special emulation features */ int second_memory_port = 0; /* By default, don't write the extra bytes */ - libspectrum_byte machine_byte; + libspectrum_byte machine_byte = Z80_MACHINE_48; size_t header_length; libspectrum_dword quarter_states; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-27 06:25:45
|
Revision: 4385 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4385&view=rev Author: fredm Date: 2011-04-27 06:25:39 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Test needed updating for ROM block duration fix. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/test/test.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-27 06:14:48 UTC (rev 4384) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-27 06:25:39 UTC (rev 4385) @@ -827,3 +827,4 @@ 20110427 tape.c,test/test15.c: use more centralised methods for ms/tstate conversions (Fred). 20110427 z80.c: initialise machine_type to avoid a warning (Fred). +20110427 test/test.c: test needed updating for ROM block duration fix (Fred). Modified: trunk/libspectrum/test/test.c =================================================================== --- trunk/libspectrum/test/test.c 2011-04-27 06:14:48 UTC (rev 4384) +++ trunk/libspectrum/test/test.c 2011-04-27 06:25:39 UTC (rev 4385) @@ -503,7 +503,7 @@ libspectrum_tape_iterator it; libspectrum_tape_block *block; libspectrum_dword expected_sizes[20] = { - 8228020, /* ROM */ + 15216886, /* ROM */ 3493371, /* Turbo */ 356310, /* Pure tone */ 1761, /* Pulses */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-27 06:39:27
|
Revision: 4386 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4386&view=rev Author: fredm Date: 2011-04-27 06:39:20 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Message time in the TZX is in seconds not ms. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tzx_read.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-27 06:25:39 UTC (rev 4385) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-27 06:39:20 UTC (rev 4386) @@ -828,3 +828,4 @@ conversions (Fred). 20110427 z80.c: initialise machine_type to avoid a warning (Fred). 20110427 test/test.c: test needed updating for ROM block duration fix (Fred). +20110427 tzx_read.c: message time in the TZX is in seconds not ms (Fred). Modified: trunk/libspectrum/tzx_read.c =================================================================== --- trunk/libspectrum/tzx_read.c 2011-04-27 06:25:39 UTC (rev 4385) +++ trunk/libspectrum/tzx_read.c 2011-04-27 06:39:20 UTC (rev 4386) @@ -865,8 +865,8 @@ block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_MESSAGE ); - /* Get the time */ - libspectrum_set_pause_ms( block, **ptr ); (*ptr)++; + /* Get the time in seconds */ + libspectrum_set_pause_ms( block, (**ptr) * 1000 ); (*ptr)++; /* Get the message itself */ error = tzx_read_string( ptr, end, &text ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-27 11:54:58
|
Revision: 4387 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4387&view=rev Author: fredm Date: 2011-04-27 11:54:52 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Directly store pause tstates values in blocks to allow access to either original values or native tstates values. Modified Paths: -------------- trunk/libspectrum/doc/libspectrum.txt trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tape.c trunk/libspectrum/tape_accessors.txt trunk/libspectrum/tape_block.c trunk/libspectrum/tape_block.h trunk/libspectrum/utilities.c Modified: trunk/libspectrum/doc/libspectrum.txt =================================================================== --- trunk/libspectrum/doc/libspectrum.txt 2011-04-27 06:39:20 UTC (rev 4386) +++ trunk/libspectrum/doc/libspectrum.txt 2011-04-27 11:54:52 UTC (rev 4387) @@ -1121,13 +1121,22 @@ int offsets[] SELECT -libspectrum_dword pause MESSAGE +libspectrum_dword pause GENERALISED_DATA + MESSAGE PAUSE PURE_DATA RAW_DATA ROM TURBO +libspectrum_dword pause_tstates GENERALISED_DATA + MESSAGE + PAUSE + PURE_DATA + RAW_DATA + ROM + TURBO + libspectrum_dword pilot_length TURBO size_t pilot_pulses TURBO Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-27 06:39:20 UTC (rev 4386) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-27 11:54:52 UTC (rev 4387) @@ -829,3 +829,6 @@ 20110427 z80.c: initialise machine_type to avoid a warning (Fred). 20110427 test/test.c: test needed updating for ROM block duration fix (Fred). 20110427 tzx_read.c: message time in the TZX is in seconds not ms (Fred). +20110427 doc/libspectrum.txt,tape.c,tape_accessors.txt,tape_block.[ch], + utilities.c: directly store pause tstates values in blocks to allow + access to either original values or native tstates values (Fred). Modified: trunk/libspectrum/tape.c =================================================================== --- trunk/libspectrum/tape.c 2011-04-27 06:39:20 UTC (rev 4386) +++ trunk/libspectrum/tape.c 2011-04-27 11:54:52 UTC (rev 4387) @@ -366,8 +366,7 @@ break; case LIBSPECTRUM_TAPE_BLOCK_PAUSE: - *tstates = libspectrum_ms_to_tstates( block->types.pause.length ); - end_of_block = 1; + *tstates = block->types.pause.length_tstates; end_of_block = 1; /* 0 ms pause => stop tape */ if( *tstates == 0 ) { *flags |= LIBSPECTRUM_TAPE_FLAGS_STOP; } break; @@ -527,7 +526,7 @@ case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ - *tstates = libspectrum_ms_to_tstates( block->pause ); + *tstates = block->pause_tstates; *end_of_block = 1; break; @@ -624,7 +623,7 @@ case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ - *tstates = libspectrum_ms_to_tstates( block->pause ); + *tstates = block->pause_tstates; *end_of_block = 1; break; @@ -732,7 +731,7 @@ case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ - *tstates = libspectrum_ms_to_tstates( block->pause ); + *tstates = block->pause_tstates; *end_of_block = 1; break; @@ -800,7 +799,7 @@ case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ - *tstates = libspectrum_ms_to_tstates( block->pause ); + *tstates = block->pause_tstates; *end_of_block = 1; break; @@ -960,7 +959,7 @@ case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ - *tstates = libspectrum_ms_to_tstates( block->pause ); + *tstates = block->pause_tstates; *end_of_block = 1; break; Modified: trunk/libspectrum/tape_accessors.txt =================================================================== --- trunk/libspectrum/tape_accessors.txt 2011-04-27 06:39:20 UTC (rev 4386) +++ trunk/libspectrum/tape_accessors.txt 2011-04-27 11:54:52 UTC (rev 4387) @@ -117,6 +117,15 @@ rom turbo +libspectrum_dword pause_tstates 0 -1 + generalised_data + message time_tstates + pause length_tstates + pure_data + raw_data + rom + turbo + libspectrum_dword pilot_length 0 -1 turbo Modified: trunk/libspectrum/tape_block.c =================================================================== --- trunk/libspectrum/tape_block.c 2011-04-27 06:39:20 UTC (rev 4386) +++ trunk/libspectrum/tape_block.c 2011-04-27 11:54:52 UTC (rev 4387) @@ -486,7 +486,7 @@ static libspectrum_dword rom_block_length( libspectrum_tape_rom_block *rom ) { - libspectrum_dword length = libspectrum_ms_to_tstates( rom->pause ); + libspectrum_dword length = rom->pause_tstates; size_t i; size_t edge_count = rom->length && rom->data[0] & 0x80 ? @@ -513,7 +513,7 @@ libspectrum_dword length = turbo->pilot_pulses * turbo->pilot_length + turbo->sync1_length + turbo->sync2_length + - libspectrum_ms_to_tstates( turbo->pause ); + turbo->pause_tstates; size_t i; if( turbo->length ) { int bits_set_in_last_byte = @@ -552,7 +552,7 @@ static libspectrum_dword pure_data_block_length( libspectrum_tape_pure_data_block *pure_data ) { - libspectrum_dword length = libspectrum_ms_to_tstates( pure_data->pause ); + libspectrum_dword length = pure_data->pause_tstates; size_t i; if( pure_data->length ) { int bits_set_in_last_byte = @@ -580,7 +580,7 @@ static libspectrum_dword raw_data_block_length( libspectrum_tape_raw_data_block *raw_data ) { - libspectrum_dword length = libspectrum_ms_to_tstates( raw_data->pause ); + libspectrum_dword length = raw_data->pause_tstates; length += ( LIBSPECTRUM_BITS_IN_BYTE * raw_data->length - ( LIBSPECTRUM_BITS_IN_BYTE - raw_data->bits_in_last_byte ) ) * @@ -647,7 +647,7 @@ case LIBSPECTRUM_TAPE_BLOCK_PURE_DATA: return pure_data_block_length( &block->types.pure_data ); case LIBSPECTRUM_TAPE_BLOCK_PAUSE: - return libspectrum_ms_to_tstates( block->types.pause.length ); + return block->types.pause.length_tstates; case LIBSPECTRUM_TAPE_BLOCK_RAW_DATA: return raw_data_block_length( &block->types.raw_data ); case LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE: Modified: trunk/libspectrum/tape_block.h =================================================================== --- trunk/libspectrum/tape_block.h 2011-04-27 06:39:20 UTC (rev 4386) +++ trunk/libspectrum/tape_block.h 2011-04-27 11:54:52 UTC (rev 4387) @@ -40,6 +40,7 @@ size_t length; /* How long is this block */ libspectrum_byte *data; /* The actual data */ libspectrum_dword pause; /* Pause after block (milliseconds) */ + libspectrum_dword pause_tstates; /* Pause after block (tstates) */ } libspectrum_tape_rom_block; @@ -67,6 +68,7 @@ size_t bits_in_last_byte; /* How many bits are in the last byte? */ libspectrum_byte *data; /* The actual data */ libspectrum_dword pause; /* Pause after data (in ms) */ + libspectrum_dword pause_tstates; /* Pause after block (tstates) */ libspectrum_dword pilot_length; /* Length of pilot pulse (in tstates) */ size_t pilot_pulses; /* Number of pilot pulses */ @@ -132,6 +134,7 @@ size_t bits_in_last_byte; /* How many bits are in the last byte? */ libspectrum_byte *data; /* The actual data */ libspectrum_dword pause; /* Pause after data (in ms) */ + libspectrum_dword pause_tstates; /* Pause after block (tstates) */ libspectrum_dword bit0_length, bit1_length; /* Length of (re)set bits */ @@ -159,6 +162,7 @@ size_t bits_in_last_byte; /* How many bits are in the last byte? */ libspectrum_byte *data; /* The actual data */ libspectrum_dword pause; /* Pause after data (in ms) */ + libspectrum_dword pause_tstates; /* Pause after block (tstates) */ libspectrum_dword bit_length; /* Bit length. *Not* pulse length! */ @@ -198,6 +202,7 @@ typedef struct libspectrum_tape_generalised_data_block { libspectrum_dword pause; /* Pause after data (in ms) */ + libspectrum_dword pause_tstates; /* Pause after block (tstates) */ libspectrum_tape_generalised_data_symbol_table pilot_table, data_table; @@ -228,10 +233,13 @@ } libspectrum_tape_generalised_data_block_state; -/* A pause block */ +/* A pause block - some formats use pause in ms, some use tstates. Fuse uses + tstates but wants to be able to write back the original value to a file + if re-saved so store both */ typedef struct libspectrum_tape_pause_block { libspectrum_dword length; + libspectrum_dword length_tstates; } libspectrum_tape_pause_block; @@ -285,6 +293,7 @@ typedef struct libspectrum_tape_message_block { int time; + int time_tstates; char *text; } libspectrum_tape_message_block; Modified: trunk/libspectrum/utilities.c =================================================================== --- trunk/libspectrum/utilities.c 2011-04-27 06:39:20 UTC (rev 4386) +++ trunk/libspectrum/utilities.c 2011-04-27 11:54:52 UTC (rev 4387) @@ -48,12 +48,15 @@ libspectrum_dword pause_ms ) { libspectrum_tape_block_set_pause( block, pause_ms ); + libspectrum_tape_block_set_pause_tstates( block, + libspectrum_ms_to_tstates( pause_ms ) ); } void libspectrum_set_pause_tstates( libspectrum_tape_block *block, libspectrum_dword pause_tstates ) { + libspectrum_tape_block_set_pause_tstates( block, pause_tstates ); libspectrum_tape_block_set_pause( block, libspectrum_tstates_to_ms( pause_tstates ) ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-27 12:52:38
|
Revision: 4388 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4388&view=rev Author: fredm Date: 2011-04-27 12:52:26 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Add read support for PZX tape files. Modified Paths: -------------- trunk/libspectrum/Makefile.am trunk/libspectrum/doc/libspectrum.3 trunk/libspectrum/doc/libspectrum.txt trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/internals.h trunk/libspectrum/libspectrum.c trunk/libspectrum/libspectrum.h.in trunk/libspectrum/tap.c trunk/libspectrum/tape.c trunk/libspectrum/tape_accessors.txt trunk/libspectrum/tape_block.c trunk/libspectrum/tape_block.h trunk/libspectrum/tzx_read.c Added Paths: ----------- trunk/libspectrum/pzx_read.c Modified: trunk/libspectrum/Makefile.am =================================================================== --- trunk/libspectrum/Makefile.am 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/Makefile.am 2011-04-27 12:52:26 UTC (rev 4388) @@ -35,6 +35,7 @@ memory.c \ microdrive.c \ plusd.c \ + pzx_read.c \ rzx.c \ sna.c \ snp.c \ Modified: trunk/libspectrum/doc/libspectrum.3 =================================================================== --- trunk/libspectrum/doc/libspectrum.3 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/doc/libspectrum.3 2011-04-27 12:52:26 UTC (rev 4388) @@ -45,7 +45,7 @@ Snapshots: .z80, .szx, .sna (all read/write), .zxs, .sp., .snp and +D snapshots (read only). .IP \(bu 2 -Tape images: .tzx, .tap, .spc, .sta, .ltp (read/write) and Warajevo .tap, +Tape images: .tzx, .tap, .spc, .sta, .ltp (read/write) and .pzx, Warajevo .tap, Z80Em and CSW version 1 (read only). .IP \(bu 2 Input recordings: .rzx (read/write). Modified: trunk/libspectrum/doc/libspectrum.txt =================================================================== --- trunk/libspectrum/doc/libspectrum.txt 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/doc/libspectrum.txt 2011-04-27 12:52:26 UTC (rev 4388) @@ -310,6 +310,7 @@ LIBSPECTRUM_ID_TAPE_SPC An SP-style .spc tape image LIBSPECTRUM_ID_TAPE_STA A Speculator-style .sta tape image LIBSPECTRUM_ID_TAPE_LTP A Nuclear ZX-style .ltp tape image +LIBSPECTRUM_ID_TAPE_PZX A .pzx tape image Versions of libspectrum previous to 0.5.0 used LIBSPECTRUM_ID_DISK_DSK for both plain and extended .dsk images, but this is now deprecated in @@ -993,10 +994,17 @@ LIBSPECTRUM_TAPE_BLOCK_CONCAT 0x5a -The following block is not defined in the TZX format +The following blocks are not defined in the TZX format LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE A run-length encoded list of pulses +The following two blocks are defined in the PZX format + +LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE A run-length encoded list of pulses with polarity specified +LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK A block of data without pilot or sync + pulses with bit encoding and polarity + specified + These values are defined in the `libspectrum_tape_type' enumeration. The `concatenation' block (0x5a) is recognised on input, but just skipped; hence it will never appear in a libspectrum_tape_block. @@ -1091,6 +1099,7 @@ size_t bits_in_last_byte PURE_DATA RAW_DATA TURBO + DATA_BLOCK size_t count PURE_TONE PULSES @@ -1098,18 +1107,22 @@ SELECT ARCHIVE_INFO HARDWARE + PULSE_SEQUENCE + DATA_BLOCK libspectrum_byte* data CUSTOM PURE_DATA RAW_DATA ROW TURBO + DATA_BLOCK size_t data_length CUSTOM PURE_DATA RAW_DATA ROM TURBO + DATA_BLOCK libspectrum_tape_generalised_data_symbol_table data_table GENERALISED_DATA @@ -1151,11 +1164,16 @@ libspectrum_dword pulse_length LENGTH libspectrum_dword pulse_lengths[] PULSES + PULSE_SEQUENCE +libspectrum_dword pulse_repeats[] PULSE_SEQUENCE + libspectrum_dword sync1_length TURBO libspectrum_dword sync2_length TURBO +libspectrum_dword tail_length DATA_BLOCK + char* text GROUP_START COMMENT MESSAGE @@ -1168,6 +1186,17 @@ int values[] HARDWARE +int level DATA_BLOCK + PAUSE + +libspectrum_byte bit0_pulse_count DATA_BLOCK + +libspectrum_byte bit1_pulse_count DATA_BLOCK + +libspectrum_word bit0_pulses[] DATA_BLOCK + +libspectrum_word bit1_pulses[] DATA_BLOCK + There is one further parameter which can be accessed for PURE_DATA, RAW_DATA, ROM and TURBO blocks, which is `libspectrum_tape_state_type state'. This determines the part of the block which is currently being @@ -1180,6 +1209,7 @@ LIBSPECTRUM_TAPE_STATE_SYNC2 /* Second sync pulse */ LIBSPECTRUM_TAPE_STATE_DATA1 /* First edge of a data bit */ LIBSPECTRUM_TAPE_STATE_DATA2 /* Second edge of a data bit */ +LIBSPECTRUM_TAPE_STATE_TAIL /* The tail pause following the last data bit */ LIBSPECTRUM_TAPE_STATE_PAUSE /* The pause at the end of a block */ Setting this value to anything other than Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-27 12:52:26 UTC (rev 4388) @@ -832,3 +832,7 @@ 20110427 doc/libspectrum.txt,tape.c,tape_accessors.txt,tape_block.[ch], utilities.c: directly store pause tstates values in blocks to allow access to either original values or native tstates values (Fred). +20110427 Makefile.am,doc/{libspectrum.3,libspectrum.txt},internals.h, + libspectrum.c,libspectrum.h.in,pzx_read.c,tap.c,tape.c, + tape_accessors.txt,tape_block.[ch],tzx_read.c: add read support for PZX + tape files (Fred). Modified: trunk/libspectrum/internals.h =================================================================== --- trunk/libspectrum/internals.h 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/internals.h 2011-04-27 12:52:26 UTC (rev 4388) @@ -166,6 +166,7 @@ extern const libspectrum_dword LIBSPECTRUM_TAPE_TIMING_SYNC2; extern const libspectrum_dword LIBSPECTRUM_TAPE_TIMING_DATA0; extern const libspectrum_dword LIBSPECTRUM_TAPE_TIMING_DATA1; +extern const libspectrum_dword LIBSPECTRUM_TAPE_TIMING_TAIL; /* Tape routines */ @@ -218,6 +219,10 @@ libspectrum_error libspectrum_wav_read( libspectrum_tape *tape, const char *filename ); +libspectrum_error +internal_pzx_read( libspectrum_tape *tape, const libspectrum_byte *buffer, + const size_t length ); + libspectrum_tape_block* libspectrum_tape_block_internal_init( libspectrum_tape_block_state *iterator, Modified: trunk/libspectrum/libspectrum.c =================================================================== --- trunk/libspectrum/libspectrum.c 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/libspectrum.c 2011-04-27 12:52:26 UTC (rev 4388) @@ -524,6 +524,7 @@ { LIBSPECTRUM_ID_TAPE_LTP, "ltp", 3, "\x11\0\0", 0, 3, 1 }, { LIBSPECTRUM_ID_TAPE_TZX, "tzx", 3, "ZXTape!", 0, 7, 4 }, { LIBSPECTRUM_ID_TAPE_WARAJEVO, "tap", 2, "\xff\xff\xff\xff", 8, 4, 2 }, + { LIBSPECTRUM_ID_TAPE_PZX, "pzx", 3, "PZXT", 0, 4, 4 }, { LIBSPECTRUM_ID_DISK_SCL, "scl", 3, "SINCLAIR", 0, 8, 4 }, { LIBSPECTRUM_ID_DISK_TRD, "trd", 3, NULL, 0, 0, 0 }, @@ -708,6 +709,7 @@ case LIBSPECTRUM_ID_TAPE_Z80EM: case LIBSPECTRUM_ID_TAPE_CSW: case LIBSPECTRUM_ID_TAPE_WAV: + case LIBSPECTRUM_ID_TAPE_PZX: *libspectrum_class = LIBSPECTRUM_CLASS_TAPE; return 0; case LIBSPECTRUM_ID_CARTRIDGE_IF2: Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/libspectrum.h.in 2011-04-27 12:52:26 UTC (rev 4388) @@ -210,6 +210,8 @@ LIBSPECTRUM_ID_DISK_OPD, /* .opu/.opd Opus Discovery disk image */ + LIBSPECTRUM_ID_TAPE_PZX, /* PZX tape image */ + } libspectrum_id_t; /* And 'classes' of file */ @@ -513,6 +515,10 @@ LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE = 0x100, + /* PZX format blocks */ + LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE, + LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK, + } libspectrum_tape_type; typedef struct libspectrum_tape_block libspectrum_tape_block; @@ -540,12 +546,13 @@ LIBSPECTRUM_TAPE_STATE_INVALID = 0, - LIBSPECTRUM_TAPE_STATE_PILOT, /* Pilot pulses */ - LIBSPECTRUM_TAPE_STATE_SYNC1, /* First sync pulse */ - LIBSPECTRUM_TAPE_STATE_SYNC2, /* Second sync pulse */ - LIBSPECTRUM_TAPE_STATE_DATA1, /* First edge of a data bit */ - LIBSPECTRUM_TAPE_STATE_DATA2, /* Second edge of a data bit */ - LIBSPECTRUM_TAPE_STATE_PAUSE, /* The pause at the end of a block */ + LIBSPECTRUM_TAPE_STATE_PILOT, /* Pilot pulses */ + LIBSPECTRUM_TAPE_STATE_SYNC1, /* First sync pulse */ + LIBSPECTRUM_TAPE_STATE_SYNC2, /* Second sync pulse */ + LIBSPECTRUM_TAPE_STATE_DATA1, /* First edge of a data bit */ + LIBSPECTRUM_TAPE_STATE_DATA2, /* Second edge of a data bit */ + LIBSPECTRUM_TAPE_STATE_PAUSE, /* The pause at the end of a block */ + LIBSPECTRUM_TAPE_STATE_TAIL, /* The pulse at the end of a block */ } libspectrum_tape_state_type; Added: trunk/libspectrum/pzx_read.c =================================================================== --- trunk/libspectrum/pzx_read.c (rev 0) +++ trunk/libspectrum/pzx_read.c 2011-04-27 12:52:26 UTC (rev 4388) @@ -0,0 +1,679 @@ +/* pzx_read.c: Routines for reading .pzx files + Copyright (c) 2001, 2002 Philip Kendall, Darren Salt + Copyright (c) 2011 Fredrick Meunier + + $Id$ + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + Author contact information: + + E-mail: phi...@sh... + +*/ + +#include <config.h> + +#include <math.h> +#include <stddef.h> +#include <stdio.h> +#include <string.h> + +#include "internals.h" + +/* Used for passing internal data around */ + +typedef struct pzx_context { + + libspectrum_word version; + +} pzx_context; + +static const libspectrum_byte PZX_VERSION_MAJOR = 1; +static const libspectrum_byte PZX_VERSION_MINOR = 0; + +/* Constants etc for each block type */ + +#define PZX_HEADER "PZXT" +struct info_t { + + const char *id; + int archive_info_id; + +}; + +/* Needs to be in strcmp order */ +static struct info_t info_ids[] = { + + { "Author", 0x02 }, + { "Comment", 0xff }, + { "Language", 0x04 }, + { "Origin", 0x08 }, + { "Price", 0x06 }, + { "Protection", 0x07 }, + { "Publisher", 0x01 }, + { "Type", 0x05 }, + { "Year", 0x03 }, + +}; + +static size_t info_ids_count = + sizeof( info_ids ) / sizeof( struct info_t ); + +#define PZX_PULSE "PULS" + +#define PZX_DATA "DATA" + +#define PZX_PAUSE "PAUS" + +#define PZX_BROWSE "BRWS" + +#define PZX_STOP "STOP" +static const libspectrum_byte PZXF_STOP48 = 1; + +/* TODO: an extension to be similar to the TZX Custom Block Picture type */ +#define PZX_INLAY "inly" + +static const char *signature = PZX_HEADER; +static const size_t signature_length = 4; + +static libspectrum_error +read_block( libspectrum_tape *tape, const libspectrum_byte **buffer, + const libspectrum_byte *end, pzx_context *ctx ); + +typedef libspectrum_error (*read_block_fn)( libspectrum_tape *tape, + const libspectrum_byte **buffer, + const libspectrum_byte *end, + size_t data_length, + pzx_context *ctx ); + +static libspectrum_error +pzx_read_data( const libspectrum_byte **ptr, const libspectrum_byte *end, + size_t length, libspectrum_byte **data ); + +static libspectrum_error +pzx_read_string( const libspectrum_byte **ptr, const libspectrum_byte *end, + char **dest ); + +static int +info_t_compar(const void *a, const void *b) +{ + char *key = (char *)a; + struct info_t *test = (struct info_t *)b; + return strcmp( key, test->id ); +} + +static int +get_id_byte( char *info_tag ) { + struct info_t *info = + (struct info_t*)bsearch( info_tag, info_ids, info_ids_count, + sizeof( struct info_t ), info_t_compar ); + return info == NULL ? -1 : info->archive_info_id; +} + +static libspectrum_error +read_pzxt_block( libspectrum_tape *tape, const libspectrum_byte **buffer, + const libspectrum_byte *end, size_t data_length, + pzx_context *ctx ) +{ + libspectrum_error error; + + size_t i = 0; + size_t count = 0; + int id; + int *ids = NULL; + char *info_tag = NULL; + char *string; + char **strings = NULL; + const libspectrum_byte *block_end = *buffer + data_length; + + if( data_length < 2 ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, + "read_pzxt_block: length %lu too short", + (unsigned long)data_length ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + ctx->version = (**buffer) << 8; (*buffer)++; + ctx->version |= **buffer; (*buffer)++; + + if( ctx->version < 0x0100 || ctx->version >= 0x0200 ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, + "read_pzxt_block: only version 1 pzx files are " + "supported" ); + return LIBSPECTRUM_ERROR_UNKNOWN; + } + + if( *buffer < block_end ) { + ids = libspectrum_malloc( sizeof( *ids ) ); + strings = libspectrum_malloc( sizeof( *strings ) ); + count = 1; + i = 0; + + ids[0] = 0x00; + + /* Read in the title string itself */ + error = pzx_read_string( buffer, block_end, &strings[0] ); + if( error ) { + libspectrum_free( strings[0] ); + return error; + } + } + + while( *buffer < block_end ) { + error = pzx_read_string( buffer, block_end, &info_tag ); + if( error ) { + size_t j; + for( j = 0; j < i; j++ ) libspectrum_free( strings[j] ); + libspectrum_free( strings ); libspectrum_free( ids ); + return error; + } + + /* Get the ID byte */ + id = get_id_byte( info_tag ); + + /* Read in the string itself */ + error = pzx_read_string( buffer, block_end, &string ); + if( error ) { + size_t j; + for( j = 0; j < i; j++ ) libspectrum_free( strings[j] ); + libspectrum_free( strings ); libspectrum_free( ids ); + return error; + } + + i = count++; + ids = libspectrum_realloc( ids, count * sizeof( *ids ) ); + strings = libspectrum_realloc( strings, count * sizeof( *strings ) ); + + if( id == -1 ) { + size_t new_len = strlen( info_tag ) + strlen( string ) + + strlen( ": " ) + 1; + char *comment = libspectrum_malloc( new_len ); + snprintf( comment, new_len, "%s: %s", info_tag, string ); + libspectrum_free( string ); + ids[i] = 0xff; + strings[i] = comment; + } else { + ids[i] = id; + strings[i] = string; + } + + libspectrum_free( info_tag ); + } + + if( count ) { + libspectrum_tape_block* block = + libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_ARCHIVE_INFO ); + + libspectrum_tape_block_set_count( block, count ); + libspectrum_tape_block_set_ids( block, ids ); + libspectrum_tape_block_set_texts( block, strings ); + + libspectrum_tape_append_block( tape, block ); + } + + return LIBSPECTRUM_ERROR_NONE; +} + + +static libspectrum_error +read_data_block( libspectrum_tape *tape, const libspectrum_byte **buffer, + const libspectrum_byte *end, size_t data_length, + pzx_context *ctx ) +{ + const libspectrum_byte *block_end = *buffer + data_length; + libspectrum_tape_block* block; + libspectrum_byte *data; + + libspectrum_error error; + + /* Check there's enough left in the buffer for all the metadata */ + if( data_length < 8 ) { + libspectrum_print_error( + LIBSPECTRUM_ERROR_CORRUPT, + "read_data_block: not enough data in buffer" + ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + /* Get the metadata */ + libspectrum_dword count = libspectrum_read_dword( buffer ); + int initial_level = !!(count & 0x80000000); + count &= 0x7fffffff; + size_t count_bytes = ceil( count / (double)LIBSPECTRUM_BITS_IN_BYTE ); + size_t bits_in_last_byte = + count % LIBSPECTRUM_BITS_IN_BYTE ? + count % LIBSPECTRUM_BITS_IN_BYTE : LIBSPECTRUM_BITS_IN_BYTE; + libspectrum_word tail = libspectrum_read_word( buffer ); + libspectrum_byte p0_count = **buffer; (*buffer)++; + libspectrum_byte p1_count = **buffer; (*buffer)++; + + /* need to confirm that we have enough length left for the pulse definitions + */ + if( data_length < 8 + 2*(p0_count + p1_count) ) { + libspectrum_print_error( + LIBSPECTRUM_ERROR_CORRUPT, + "read_data_block: not enough data in buffer" + ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + libspectrum_word *p0_pulses; + error = pzx_read_data( buffer, block_end, + p0_count * sizeof( libspectrum_word ), + (libspectrum_byte**)&p0_pulses ); + if( error ) return error; + + libspectrum_word *p1_pulses; + error = pzx_read_data( buffer, block_end, + p1_count * sizeof( libspectrum_word ), + (libspectrum_byte**)&p1_pulses ); + if( error ) { libspectrum_free( p0_pulses ); return error; } + + /* And the actual data */ + error = pzx_read_data( buffer, block_end, count_bytes, &data ); + if( error ) { + libspectrum_free( p0_pulses ); + libspectrum_free( p1_pulses ); + return error; + } + + block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK ); + + libspectrum_tape_block_set_count( block, count ); + libspectrum_tape_block_set_tail_length( block, tail ); + libspectrum_tape_block_set_level( block, initial_level ); + libspectrum_tape_block_set_bit0_pulse_count( block, p0_count ); + libspectrum_tape_block_set_bit0_pulses( block, p0_pulses ); + libspectrum_tape_block_set_bit1_pulse_count( block, p1_count ); + libspectrum_tape_block_set_bit1_pulses( block, p1_pulses ); + libspectrum_tape_block_set_data_length( block, count_bytes ); + libspectrum_tape_block_set_bits_in_last_byte( block, bits_in_last_byte ); + libspectrum_tape_block_set_data( block, data ); + + libspectrum_tape_append_block( tape, block ); + + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error +read_next_pulse( const libspectrum_byte **buffer, const libspectrum_byte *end, + size_t *pulse_repeats, libspectrum_dword *length ) +{ + /* While we have at least one int 16 left try to extract the next pulse */ + if( ( end - (*buffer) ) < (ptrdiff_t)2 ) goto pzx_corrupt; + + *pulse_repeats = 1; + *length = libspectrum_read_word( buffer ); + if( *length > 0x8000 ) { + if( ( end - (*buffer) ) < (ptrdiff_t)2 ) goto pzx_corrupt; + *pulse_repeats = *length & 0x7fff; + *length = libspectrum_read_word( buffer ); + } + if( *length >= 0x8000 ) { + if( ( end - (*buffer) ) < (ptrdiff_t)2 ) goto pzx_corrupt; + *length &= 0x7fff; + *length <<= 16; + *length |= libspectrum_read_word( buffer ); + } + + /* And return */ + return LIBSPECTRUM_ERROR_NONE; + +pzx_corrupt: + libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, + "read_next_pulse: not enough data in buffer" ); + return LIBSPECTRUM_ERROR_CORRUPT; +} + +static libspectrum_error +read_puls_block( libspectrum_tape *tape, const libspectrum_byte **buffer, + const libspectrum_byte *end, size_t data_length, + pzx_context *ctx ) +{ + size_t count = 0; + size_t pulse_repeats; + libspectrum_dword length; + libspectrum_tape_block *block; + libspectrum_error error; + size_t buffer_sizes = 64; + size_t *pulse_repeats_buffer = + libspectrum_malloc( buffer_sizes * sizeof( size_t ) ); + libspectrum_dword *lengths_buffer = + libspectrum_malloc( buffer_sizes * sizeof( libspectrum_dword ) ); + const libspectrum_byte *block_end = *buffer + data_length; + + while( ( block_end - (*buffer) ) > (ptrdiff_t)0 ) { + error = read_next_pulse( buffer, block_end, &pulse_repeats, &length ); + if( error ) { + libspectrum_free( pulse_repeats_buffer ); + libspectrum_free( lengths_buffer ); + return error; + } + pulse_repeats_buffer[ count ] = pulse_repeats; + lengths_buffer[ count ] = length; + count++; + if( buffer_sizes == count ) { + buffer_sizes *= 2; + pulse_repeats_buffer = + libspectrum_realloc( pulse_repeats_buffer, + buffer_sizes * sizeof( size_t ) ); + lengths_buffer = + libspectrum_realloc( lengths_buffer, + buffer_sizes * sizeof( libspectrum_dword ) ); + } + } + + if( count == 0 ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, + "read_puls_block: no pulses found in pulse block" ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + if( buffer_sizes != count ) { + pulse_repeats_buffer = + libspectrum_realloc( pulse_repeats_buffer, + count * sizeof( size_t ) ); + lengths_buffer = + libspectrum_realloc( lengths_buffer, + count * sizeof( libspectrum_dword ) ); + } + + block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE ); + + libspectrum_tape_block_set_count( block, count ); + libspectrum_tape_block_set_pulse_lengths( block, lengths_buffer ); + libspectrum_tape_block_set_pulse_repeats( block, pulse_repeats_buffer ); + + libspectrum_tape_append_block( tape, block ); + + /* And return */ + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error +read_paus_block( libspectrum_tape *tape, const libspectrum_byte **buffer, + const libspectrum_byte *end, size_t data_length, + pzx_context *ctx ) +{ + libspectrum_tape_block *block; + libspectrum_dword pause_tstates; + int initial_level; + + /* Check the pause actually exists */ + if( data_length < 2 ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, + "read_paus_block: not enough data in buffer" ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PAUSE ); + + pause_tstates = libspectrum_read_dword( buffer ); + initial_level = !!(pause_tstates & 0x80000000); + pause_tstates &= 0x7fffffff; + + /* Set the pause length */ + libspectrum_set_pause_tstates( block, pause_tstates ); + libspectrum_tape_block_set_level( block, initial_level ); + + libspectrum_tape_append_block( tape, block ); + + /* And return */ + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error +read_brws_block( libspectrum_tape *tape, const libspectrum_byte **buffer, + const libspectrum_byte *end, size_t data_length, + pzx_context *ctx ) +{ + libspectrum_tape_block* block; + char *text; + libspectrum_error error; + + block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_COMMENT ); + + /* Get the actual comment */ + error = pzx_read_string( buffer, *buffer + data_length, &text ); + if( error ) { libspectrum_free( block ); return error; } + libspectrum_tape_block_set_text( block, text ); + + libspectrum_tape_append_block( tape, block ); + + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error +read_stop_block( libspectrum_tape *tape, const libspectrum_byte **buffer, + const libspectrum_byte *end, size_t data_length, + pzx_context *ctx ) +{ + libspectrum_tape_block *block; + + if( data_length < 2 ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, + "tzx_read_stop: not enough data in buffer" ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + libspectrum_word flags = libspectrum_read_word( buffer ); + + if( flags == PZXF_STOP48 ) { + block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_STOP48 ); + } else { + /* General stop is a 0 duration pause */ + block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PAUSE ); + libspectrum_tape_block_set_pause( block, 0 ); + } + + libspectrum_tape_append_block( tape, block ); + + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error +skip_block( libspectrum_tape *tape GCC_UNUSED, + const libspectrum_byte **buffer, + const libspectrum_byte *end GCC_UNUSED, + size_t data_length, + pzx_context *ctx GCC_UNUSED ) +{ + *buffer += data_length; + return LIBSPECTRUM_ERROR_NONE; +} + +struct read_block_t { + + const char *id; + read_block_fn function; + +}; + +static struct read_block_t read_blocks[] = { + + { PZX_HEADER, read_pzxt_block }, + { PZX_PULSE, read_puls_block }, + { PZX_DATA, read_data_block }, + { PZX_PAUSE, read_paus_block }, + { PZX_BROWSE, read_brws_block }, + { PZX_STOP, read_stop_block }, + { PZX_INLAY, skip_block }, + +}; + +static size_t read_blocks_count = + sizeof( read_blocks ) / sizeof( struct read_block_t ); + +static libspectrum_error +read_block_header( char *id, libspectrum_dword *data_length, + const libspectrum_byte **buffer, + const libspectrum_byte *end ) +{ + if( end - *buffer < 8 ) { + libspectrum_print_error( + LIBSPECTRUM_ERROR_CORRUPT, + "read_block_header: not enough data for block header" + ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + memcpy( id, *buffer, 4 ); id[4] = '\0'; *buffer += 4; + *data_length = libspectrum_read_dword( buffer ); + + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error +read_block( libspectrum_tape *tape, const libspectrum_byte **buffer, + const libspectrum_byte *end, pzx_context *ctx ) +{ + char id[5]; + libspectrum_dword data_length; + libspectrum_error error; + size_t i; int done; + + error = read_block_header( id, &data_length, buffer, end ); + if( error ) return error; + + if( *buffer + data_length > end || *buffer + data_length < *buffer ) { + libspectrum_print_error( + LIBSPECTRUM_ERROR_CORRUPT, + "read_block: block length goes beyond end of file" + ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + done = 0; + + for( i = 0; !done && i < read_blocks_count; i++ ) { + + if( !memcmp( id, read_blocks[i].id, 4 ) ) { + error = read_blocks[i].function( tape, buffer, end, data_length, ctx ); + if( error ) return error; + done = 1; + } + + } + + if( !done ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, + "read_block: unknown block id '%s'", id ); + *buffer += data_length; + } + + return LIBSPECTRUM_ERROR_NONE; +} + +/* The main load function */ + +libspectrum_error +internal_pzx_read( libspectrum_tape *tape, const libspectrum_byte *buffer, + size_t length ) +{ + libspectrum_error error; + const libspectrum_byte *end = buffer + length; + pzx_context *ctx; + + if( end - buffer < 8 ) { + libspectrum_print_error( + LIBSPECTRUM_ERROR_CORRUPT, + "internal_pzx_read: not enough data for PZX header" + ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + if( memcmp( buffer, signature, signature_length ) ) { + libspectrum_print_error( + LIBSPECTRUM_ERROR_SIGNATURE, + "internal_pzx_read: wrong signature" + ); + return LIBSPECTRUM_ERROR_SIGNATURE; + } + + ctx = libspectrum_malloc( sizeof( *ctx ) ); + ctx->version = 0; + + while( buffer < end ) { + error = read_block( tape, &buffer, end, ctx ); + if( error ) { + libspectrum_free( ctx ); + return error; + } + } + + libspectrum_free( ctx ); + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error +pzx_read_data( const libspectrum_byte **ptr, const libspectrum_byte *end, + size_t length, libspectrum_byte **data ) +{ + /* Have we got enough bytes left in buffer? */ + if( ( end - (*ptr) ) < (ptrdiff_t)(length) ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, + "pzx_read_data: not enough data in buffer" ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + /* Allocate memory for the data; the check for *length is to avoid + the implementation-defined of malloc( 0 ) */ + if( length ) { + *data = libspectrum_malloc( ( length ) * sizeof( **data ) ); + /* Copy the block data across, and move along */ + memcpy( *data, *ptr, length ); *ptr += length; + } else { + *data = NULL; + } + + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error +pzx_read_string( const libspectrum_byte **ptr, const libspectrum_byte *end, + char **dest ) +{ + size_t length = 0; + char *ptr2; + size_t buffer_size = 64; + char *buffer = + libspectrum_malloc( buffer_size * sizeof( char ) ); + + while( **ptr != '\0' && *ptr < end ) { + if( length == buffer_size ) { + buffer_size *= 2; + buffer = libspectrum_realloc( buffer, buffer_size * sizeof( char ) ); + } + *(buffer + length++) = **ptr; (*ptr)++; + } + + /* Advance past the null terminator if it isn't the end of the block */ + if( **ptr == '\0' && *ptr < end ) (*ptr)++; + + *dest = libspectrum_malloc( (length + 1) * sizeof( libspectrum_byte ) ); + + strncpy( *dest, buffer, length ); + + /* Null terminate the string */ + (*dest)[length] = '\0'; + + /* Translate line endings */ + for( ptr2 = (*dest); *ptr2; ptr2++ ) if( *ptr2 == '\r' ) *ptr2 = '\n'; + + libspectrum_free( buffer ); + + return LIBSPECTRUM_ERROR_NONE; +} Property changes on: trunk/libspectrum/pzx_read.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/libspectrum/tap.c =================================================================== --- trunk/libspectrum/tap.c 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/tap.c 2011-04-27 12:52:26 UTC (rev 4388) @@ -177,6 +177,8 @@ case LIBSPECTRUM_TAPE_BLOCK_LOOP_START: /* Could do better? */ case LIBSPECTRUM_TAPE_BLOCK_LOOP_END: case LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE: + case LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE: + case LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK: error = skip_block( block, "conversion almost certainly won't work" ); if( error != LIBSPECTRUM_ERROR_NONE ) { libspectrum_free( *buffer ); return 1; } done = 1; Modified: trunk/libspectrum/tape.c =================================================================== --- trunk/libspectrum/tape.c 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/tape.c 2011-04-27 12:52:26 UTC (rev 4388) @@ -53,6 +53,7 @@ const libspectrum_dword LIBSPECTRUM_TAPE_TIMING_SYNC2 = 735; /*Sync 2*/ const libspectrum_dword LIBSPECTRUM_TAPE_TIMING_DATA0 = 855; /*Reset*/ const libspectrum_dword LIBSPECTRUM_TAPE_TIMING_DATA1 = 1710; /*Set*/ +const libspectrum_dword LIBSPECTRUM_TAPE_TIMING_TAIL = 945; /*Tail*/ /*** Local function prototypes ***/ @@ -107,6 +108,21 @@ libspectrum_tape_rle_pulse_block_state *state, libspectrum_dword *tstates, int *end_of_block ); +static libspectrum_error +pulse_sequence_edge( libspectrum_tape_pulse_sequence_block *block, + libspectrum_tape_pulse_sequence_block_state *state, + libspectrum_dword *tstates, int *end_of_block, + int *flags ); + +libspectrum_error +libspectrum_tape_data_block_next_bit( libspectrum_tape_data_block *block, + libspectrum_tape_data_block_state *state ); + +static libspectrum_error +data_block_edge( libspectrum_tape_data_block *block, + libspectrum_tape_data_block_state *state, + libspectrum_dword *tstates, int *end_of_block, int *flags ); + /*** Function definitions ****/ /* Allocate a list of blocks */ @@ -231,6 +247,9 @@ break; #endif /* #ifdef HAVE_LIB_AUDIOFILE */ + case LIBSPECTRUM_ID_TAPE_PZX: + error = internal_pzx_read( tape, buffer, length ); break; + default: libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, "libspectrum_tape_read: not a tape file" ); @@ -367,6 +386,11 @@ case LIBSPECTRUM_TAPE_BLOCK_PAUSE: *tstates = block->types.pause.length_tstates; end_of_block = 1; + if( block->types.pause.level == 0 ) { + *flags |= LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; + } else if( block->types.pause.level == 1 ) { + *flags |= LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH; + } /* 0 ms pause => stop tape */ if( *tstates == 0 ) { *flags |= LIBSPECTRUM_TAPE_FLAGS_STOP; } break; @@ -421,6 +445,20 @@ if( error ) return error; break; + case LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE: + error = pulse_sequence_edge( &(block->types.pulse_sequence), + &(it->block_state.pulse_sequence), tstates, + &end_of_block, flags ); + if( error ) return error; + break; + + case LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK: + error = data_block_edge( &(block->types.data_block), + &(it->block_state.data_block), tstates, + &end_of_block, flags ); + if( error ) return error; + break; + default: *tstates = 0; libspectrum_print_error( @@ -1021,6 +1059,131 @@ return LIBSPECTRUM_ERROR_NONE; } +static libspectrum_error +pulse_sequence_edge( libspectrum_tape_pulse_sequence_block *block, + libspectrum_tape_pulse_sequence_block_state *state, + libspectrum_dword *tstates, int *end_of_block, int *flags ) +{ + int new_level = state->level; + /* Get the length of this edge */ + *tstates = 0; + /* Skip past any 0 blocks until we find a non 0 block or reach the end of the + block, keeping track of the current mic level */ + while( !( *tstates || *end_of_block ) ) { + *tstates = block->lengths[ state->index ]; + new_level = !new_level; + /* Was that the last repeat of this pulse block? */ + if( ++(state->pulse_count) == block->pulse_repeats[ state->index ] ) { + state->index++; + /* Was that the last block available? */ + if( state->index >= block->count ) { + /* Next block */ + (*end_of_block) = 1; + } else { + /* Next pulse block */ + state->pulse_count = 0; + } + } + } + + if( new_level != state->level ) { + *flags |= new_level ? LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH : + LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; + state->level = new_level; + } else if( !(*tstates) ) { + /* If the net effect of this edge was 0 tstates and no level change, it was + much ado about nothing */ + *flags |= LIBSPECTRUM_TAPE_FLAGS_NO_EDGE; + } + + return LIBSPECTRUM_ERROR_NONE; +} + +libspectrum_error +libspectrum_tape_data_block_next_bit( libspectrum_tape_data_block *block, + libspectrum_tape_data_block_state *state ) +{ + int next_bit; + + /* Have we finished the current byte? */ + if( ++(state->bits_through_byte) == 8 ) { + + /* If so, have we finished the entire block? If so, all we've got + left after this is the tail at the end */ + if( ++(state->bytes_through_block) == block->length ) { + state->state = LIBSPECTRUM_TAPE_STATE_TAIL; + return LIBSPECTRUM_ERROR_NONE; + } + + /* If we've finished the current byte, but not the entire block, + get the next byte */ + state->current_byte = block->data[ state->bytes_through_block ]; + + /* If we're looking at the last byte, take account of the fact it + may have less than 8 bits in it */ + if( state->bytes_through_block == block->length-1 ) { + state->bits_through_byte = 8 - block->bits_in_last_byte; + } else { + state->bits_through_byte = 0; + } + } + + /* Get the high bit, and shift the byte out leftwards */ + next_bit = state->current_byte & 0x80; + state->current_byte <<= 1; + + /* And set state for another data bit */ + state->bit_pulses = ( next_bit ? block->bit1_pulses : block->bit0_pulses ); + state->pulse_count = ( next_bit ? block->bit1_pulse_count : + block->bit0_pulse_count ); + state->bit_flags = ( next_bit ? state->bit1_flags : state->bit0_flags ); + state->index = 0; + state->state = LIBSPECTRUM_TAPE_STATE_DATA1; + + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error +data_block_edge( libspectrum_tape_data_block *block, + libspectrum_tape_data_block_state *state, + libspectrum_dword *tstates, int *end_of_block, int *flags ) +{ + int error; + + switch( state->state ) { + + case LIBSPECTRUM_TAPE_STATE_DATA1: + /* The next pulse for a bit of data */ + *tstates = state->bit_pulses[ state->index ]; + *flags |= state->bit_flags; + if( ++(state->index) == state->pulse_count ) { + /* Followed by the next bit of data (or the end of data) */ + error = libspectrum_tape_data_block_next_bit( block, state ); + if( error ) return error; + } + break; + + case LIBSPECTRUM_TAPE_STATE_TAIL: + /* The pulse at the end of the block */ + *tstates = block->tail_length; + *end_of_block = 1; + break; + + default: + libspectrum_print_error( LIBSPECTRUM_ERROR_LOGIC, + "data_block_edge: unknown state %d", + state->state ); + return LIBSPECTRUM_ERROR_LOGIC; + + } + + *flags |= state->level ? LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH : + LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; + state->level = !state->level; + + return LIBSPECTRUM_ERROR_NONE; +} + /* Get the current block */ libspectrum_tape_block* libspectrum_tape_current_block( libspectrum_tape *tape ) @@ -1226,6 +1389,14 @@ strncpy( buffer, "RLE Pulse", length ); break; + case LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE: + strncpy( buffer, "Pulse Sequence", length ); + break; + + case LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK: + strncpy( buffer, "Data Block", length ); + break; + default: libspectrum_print_error( LIBSPECTRUM_ERROR_LOGIC, Modified: trunk/libspectrum/tape_accessors.txt =================================================================== --- trunk/libspectrum/tape_accessors.txt 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/tape_accessors.txt 2011-04-27 12:52:26 UTC (rev 4388) @@ -63,6 +63,7 @@ turbo size_t bits_in_last_byte 0 -1 + data_block pure_data raw_data turbo @@ -77,9 +78,12 @@ select archive_info hardware + pulse_sequence + data_block libspectrum_byte* data 0 NULL custom + data_block generalised_data pure_data raw_data @@ -89,6 +93,7 @@ size_t data_length 0 -1 custom length + data_block length pure_data length raw_data length rle_pulse length @@ -149,13 +154,20 @@ libspectrum_dword pulse_lengths 1 -1 pulses lengths + pulse_sequence lengths +size_t pulse_repeats 1 -1 + pulse_sequence + libspectrum_dword sync1_length 0 -1 turbo libspectrum_dword sync2_length 0 -1 turbo +libspectrum_dword tail_length 0 -1 + data_block + char* text 0 NULL group_start name comment @@ -171,3 +183,19 @@ int values 1 -1 hardware + +int level 0 -1 + pause + data_block initial_level + +libspectrum_byte bit0_pulse_count 0 -1 + data_block + +libspectrum_byte bit1_pulse_count 0 -1 + data_block + +libspectrum_word bit0_pulses 1 -1 + data_block + +libspectrum_word bit1_pulses 1 -1 + data_block Modified: trunk/libspectrum/tape_block.c =================================================================== --- trunk/libspectrum/tape_block.c 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/tape_block.c 2011-04-27 12:52:26 UTC (rev 4388) @@ -25,6 +25,8 @@ #include <config.h> +#include <math.h> + #include "tape_block.h" /* The number of pilot pulses for the standard ROM loader NB: These @@ -54,6 +56,9 @@ static libspectrum_error generalised_data_init( libspectrum_tape_generalised_data_block *block, libspectrum_tape_generalised_data_block_state *state ); +static libspectrum_error +data_block_init( libspectrum_tape_data_block *block, + libspectrum_tape_data_block_state *state ); libspectrum_tape_block* libspectrum_tape_block_alloc( libspectrum_tape_type type ) @@ -158,12 +163,23 @@ libspectrum_free( block->types.custom.data ); break; - /* Block types not present in .tzx follow here */ + /* Block types not present in .tzx follow here */ case LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE: libspectrum_free( block->types.rle_pulse.data ); break; + case LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE: + libspectrum_free( block->types.pulse_sequence.lengths ); + libspectrum_free( block->types.pulse_sequence.pulse_repeats ); + break; + + case LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK: + libspectrum_free( block->types.data_block.data ); + libspectrum_free( block->types.data_block.bit0_pulses ); + libspectrum_free( block->types.data_block.bit1_pulses ); + break; + case LIBSPECTRUM_TAPE_BLOCK_CONCAT: /* This should never occur */ default: libspectrum_print_error( LIBSPECTRUM_ERROR_LOGIC, @@ -222,6 +238,14 @@ case LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE: state->block_state.rle_pulse.index = 0; return LIBSPECTRUM_ERROR_NONE; + case LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE: + state->block_state.pulse_sequence.index = 0; + state->block_state.pulse_sequence.pulse_count = 0; + state->block_state.pulse_sequence.level = 1; + return LIBSPECTRUM_ERROR_NONE; + case LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK: + return data_block_init( &(block->types.data_block), + &(state->block_state.data_block) ); /* These blocks need no initialisation */ case LIBSPECTRUM_TAPE_BLOCK_PAUSE: @@ -329,6 +353,41 @@ return LIBSPECTRUM_ERROR_NONE; } +static libspectrum_error +data_block_init( libspectrum_tape_data_block *block, + libspectrum_tape_data_block_state *state ) +{ + libspectrum_error error; + + state->bit0_flags = 0; + state->bit1_flags = 0; + + /* If both bit0 and bit1 are two matching pulses, then assign them to be + flagged as short/long pulses respectively */ + if( block->bit0_pulse_count == 2 && block->bit1_pulse_count == 2 && + block->bit0_pulses[ 0 ] == block->bit0_pulses[ 1 ] && + block->bit1_pulses[ 0 ] == block->bit1_pulses[ 1 ] && + block->bit0_pulses[ 0 ] > 0 && block->bit1_pulses[ 0 ] > 0 ) { + if( block->bit0_pulses[ 0 ] < block->bit1_pulses[ 0 ] ) { + state->bit0_flags = LIBSPECTRUM_TAPE_FLAGS_LENGTH_SHORT; + state->bit1_flags = LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG; + } else if( block->bit0_pulses[ 0 ] > block->bit1_pulses[ 0 ] ) { + state->bit0_flags = LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG; + state->bit1_flags = LIBSPECTRUM_TAPE_FLAGS_LENGTH_SHORT; + } + } + + state->level = block->initial_level; + + /* We're just before the start of the data */ + state->bytes_through_block = -1; state->bits_through_byte = 7; + /* Set up the next bit */ + error = libspectrum_tape_data_block_next_bit( block, state ); + if( error ) return error; + + return LIBSPECTRUM_ERROR_NONE; +} + /* Does this block consist solely of metadata? */ int libspectrum_tape_block_metadata( libspectrum_tape_block *block ) @@ -347,6 +406,8 @@ case LIBSPECTRUM_TAPE_BLOCK_SELECT: case LIBSPECTRUM_TAPE_BLOCK_STOP48: case LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE: + case LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE: + case LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK: return 0; case LIBSPECTRUM_TAPE_BLOCK_GROUP_START: @@ -629,6 +690,61 @@ return length; } +static libspectrum_dword +pulse_sequence_block_length( + libspectrum_tape_pulse_sequence_block *pulses ) +{ + libspectrum_dword length = 0; + size_t i; + + for( i = 0; i < pulses->count; i++ ) + length += pulses->lengths[ i ] * pulses->pulse_repeats[ i ]; + + return length; +} + +static libspectrum_dword +data_block_length( libspectrum_tape_data_block *data_block ) +{ + libspectrum_dword length = 0; + size_t i; + if( data_block->count ) { + int bits_set_in_last_byte = + libspectrum_bits_set_n_bits( data_block->data[ data_block->length-1 ], + data_block->bits_in_last_byte ); + size_t bit0_length = 0; + size_t bit1_length = 0; + + for( i = 0; i < data_block->bit0_pulse_count; i++ ) { + bit0_length += data_block->bit0_pulses[ i ]; + } + bit0_length /= + data_block->bit0_pulse_count ? data_block->bit0_pulse_count : 1; + + for( i = 0; i < data_block->bit1_pulse_count; i++ ) { + bit1_length += data_block->bit1_pulses[ i ]; + } + bit1_length /= + data_block->bit1_pulse_count ? data_block->bit1_pulse_count : 1; + + for( i = 0; i < data_block->length-1; i++ ) { + libspectrum_byte data = data_block->data[ i ]; + length += convert_pulses_to_tstates( bit1_length, + bit0_length, + bits_set[ data ], + LIBSPECTRUM_BITS_IN_BYTE ); + } + + /* handle bits in last byte correctly */ + length += convert_pulses_to_tstates( bit1_length, + bit0_length, + bits_set_in_last_byte, + data_block->bits_in_last_byte ); + } + + return length; +} + libspectrum_dword libspectrum_tape_block_length( libspectrum_tape_block *block ) { @@ -654,6 +770,10 @@ return rle_pulse_block_length( &block->types.rle_pulse ); case LIBSPECTRUM_TAPE_BLOCK_GENERALISED_DATA: return generalised_data_block_length( &block->types.generalised_data ); + case LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE: + return pulse_sequence_block_length( &block->types.pulse_sequence ); + case LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK: + return data_block_length( &block->types.data_block ); case LIBSPECTRUM_TAPE_BLOCK_GROUP_START: case LIBSPECTRUM_TAPE_BLOCK_GROUP_END: case LIBSPECTRUM_TAPE_BLOCK_JUMP: Modified: trunk/libspectrum/tape_block.h =================================================================== --- trunk/libspectrum/tape_block.h 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/tape_block.h 2011-04-27 12:52:26 UTC (rev 4388) @@ -240,6 +240,7 @@ libspectrum_dword length; libspectrum_dword length_tstates; + int level; /* 0/1 for low and high, anything else for not specified */ } libspectrum_tape_pause_block; @@ -356,6 +357,66 @@ } libspectrum_tape_rle_pulse_block_state; +/* A PZX pulse sequence block */ +typedef struct libspectrum_tape_pulse_sequence_block { + + size_t count; + libspectrum_dword *lengths; /* Length of pulse (in tstates) */ + size_t *pulse_repeats; /* Number of pulses */ + +} libspectrum_tape_pulse_sequence_block; + +typedef struct libspectrum_tape_pulse_sequence_block_state { + + /* Private data */ + + size_t index; + size_t pulse_count; /* Number of pulses to go */ + int level; /* Mic level 0/1 */ + +} libspectrum_tape_pulse_sequence_block_state; + +/* A PZX data block */ +typedef struct libspectrum_tape_data_block { + + size_t count; /* Length of data in bits */ + int initial_level; /* Mic level 0/1 */ + libspectrum_byte *data; /* The actual data */ + libspectrum_dword tail_length; /* Length of tail pulse (in tstates) */ + + size_t bit0_pulse_count, bit1_pulse_count; /* Pulse count in (re)set bits */ + libspectrum_word *bit0_pulses; /* Reset bits pulses */ + libspectrum_word *bit1_pulses; /* Set bits pulses */ + + size_t length; /* Length of data in bytes */ + size_t bits_in_last_byte; /* How many bits are in the last byte? */ + +} libspectrum_tape_data_block; + +typedef struct libspectrum_tape_data_block_state { + + /* Private data */ + + libspectrum_tape_state_type state; + + int bit0_flags; /* Any flags to be set when bit0 is returned */ + int bit1_flags; /* Any flags to be set when bit1 is returned */ + + size_t bytes_through_block; + size_t bits_through_byte; /* How far through the data are we? */ + + libspectrum_byte current_byte; /* The current data byte; gets shifted out + as we read bits from it */ + size_t pulse_count; /* Pulse count in current bit */ + libspectrum_word *bit_pulses; /* Current bit pulses */ + int bit_flags; /* Any flags to be set when this bit is + returned */ + int level; /* Mic level 0/1 */ + + size_t index; /* Location in active pulse sequence */ + +} libspectrum_tape_data_block_state; + /* * The generic tape block */ @@ -393,6 +454,10 @@ libspectrum_tape_custom_block custom; libspectrum_tape_rle_pulse_block rle_pulse; + + libspectrum_tape_pulse_sequence_block pulse_sequence; + libspectrum_tape_data_block data_block; + } types; }; @@ -416,6 +481,8 @@ libspectrum_tape_raw_data_block_state raw_data; libspectrum_tape_generalised_data_block_state generalised_data; libspectrum_tape_rle_pulse_block_state rle_pulse; + libspectrum_tape_pulse_sequence_block_state pulse_sequence; + libspectrum_tape_data_block_state data_block; } block_state; @@ -433,7 +500,9 @@ libspectrum_tape_generalised_data_block_state *state, libspectrum_dword *tstates, int *end_of_block, int *flags ); +libspectrum_error +libspectrum_tape_data_block_next_bit( libspectrum_tape_data_block *block, + libspectrum_tape_data_block_state *state ); #endif /* #ifndef LIBSPECTRUM_TAPE_BLOCK_H */ - Modified: trunk/libspectrum/tzx_read.c =================================================================== --- trunk/libspectrum/tzx_read.c 2011-04-27 11:54:52 UTC (rev 4387) +++ trunk/libspectrum/tzx_read.c 2011-04-27 12:52:26 UTC (rev 4388) @@ -639,6 +639,7 @@ /* Get the pause length */ libspectrum_set_pause_ms( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); + libspectrum_tape_block_set_level( block, -1 ); /* No specific level */ (*ptr) += 2; libspectrum_tape_append_block( tape, block ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-29 13:54:12
|
Revision: 4396 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4396&view=rev Author: fredm Date: 2011-04-29 13:54:06 +0000 (Fri, 29 Apr 2011) Log Message: ----------- Use some more LIBSPECTRUM_BITS_IN_BYTE constants. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/wav.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-29 13:02:58 UTC (rev 4395) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-29 13:54:06 UTC (rev 4396) @@ -836,3 +836,4 @@ libspectrum.c,libspectrum.h.in,pzx_read.c,tap.c,tape.c, tape_accessors.txt,tape_block.[ch],tzx_read.c: add read support for PZX tape files (Fred). +20110429 wav.c: use some more LIBSPECTRUM_BITS_IN_BYTE constants (Fred). Modified: trunk/libspectrum/wav.c =================================================================== --- trunk/libspectrum/wav.c 2011-04-29 13:02:58 UTC (rev 4395) +++ trunk/libspectrum/wav.c 2011-04-29 13:54:06 UTC (rev 4396) @@ -38,6 +38,7 @@ { libspectrum_byte *buffer; size_t length; libspectrum_byte *tape_buffer; size_t tape_length; + size_t data_length; libspectrum_tape_block *block = NULL; int frames; @@ -128,10 +129,13 @@ libspectrum_tape_block_set_bit_length( block, 3500000/afGetRate( handle, track ) ); libspectrum_set_pause_ms( block, 0 ); - libspectrum_tape_block_set_bits_in_last_byte( block, length%8 ? length%8 : 8 ); - libspectrum_tape_block_set_data_length( block, tape_length/8 ); + libspectrum_tape_block_set_bits_in_last_byte( block, + length % LIBSPECTRUM_BITS_IN_BYTE ? + length % LIBSPECTRUM_BITS_IN_BYTE : LIBSPECTRUM_BITS_IN_BYTE ); + data_length = tape_length / LIBSPECTRUM_BITS_IN_BYTE; + libspectrum_tape_block_set_data_length( block, data_length ); - tape_buffer = libspectrum_calloc( tape_length/8, sizeof( *tape_buffer ) ); + tape_buffer = libspectrum_calloc( data_length, sizeof( *tape_buffer ) ); libspectrum_byte *from = buffer; libspectrum_byte *to = tape_buffer; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-04-29 13:56:45
|
Revision: 4397 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4397&view=rev Author: fredm Date: 2011-04-29 13:56:39 +0000 (Fri, 29 Apr 2011) Log Message: ----------- Have raw data blocks report the polarity of pulses. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tape.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-04-29 13:54:06 UTC (rev 4396) +++ trunk/libspectrum/hacking/ChangeLog 2011-04-29 13:56:39 UTC (rev 4397) @@ -837,3 +837,4 @@ tape_accessors.txt,tape_block.[ch],tzx_read.c: add read support for PZX tape files (Fred). 20110429 wav.c: use some more LIBSPECTRUM_BITS_IN_BYTE constants (Fred). +20110429 tape.c: have raw data blocks report the polarity of pulses (Fred). Modified: trunk/libspectrum/tape.c =================================================================== --- trunk/libspectrum/tape.c 2011-04-29 13:54:06 UTC (rev 4396) +++ trunk/libspectrum/tape.c 2011-04-29 13:56:39 UTC (rev 4397) @@ -98,7 +98,8 @@ static libspectrum_error raw_data_edge( libspectrum_tape_raw_data_block *block, libspectrum_tape_raw_data_block_state *state, - libspectrum_dword *tstates, int *end_of_block ); + libspectrum_dword *tstates, int *end_of_block, + int *flags ); static libspectrum_error jump_blocks( libspectrum_tape *tape, int offset ); @@ -373,7 +374,7 @@ break; case LIBSPECTRUM_TAPE_BLOCK_RAW_DATA: error = raw_data_edge( &(block->types.raw_data), &(it->block_state.raw_data), - tstates, &end_of_block ); + tstates, &end_of_block, flags ); if( error ) return error; break; @@ -386,11 +387,8 @@ case LIBSPECTRUM_TAPE_BLOCK_PAUSE: *tstates = block->types.pause.length_tstates; end_of_block = 1; - if( block->types.pause.level == 0 ) { - *flags |= LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; - } else if( block->types.pause.level == 1 ) { - *flags |= LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH; - } + *flags |= block->types.pause.level ? LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH : + LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; /* 0 ms pause => stop tape */ if( *tstates == 0 ) { *flags |= LIBSPECTRUM_TAPE_FLAGS_STOP; } break; @@ -827,12 +825,17 @@ static libspectrum_error raw_data_edge( libspectrum_tape_raw_data_block *block, libspectrum_tape_raw_data_block_state *state, - libspectrum_dword *tstates, int *end_of_block ) + libspectrum_dword *tstates, int *end_of_block, + int *flags ) { switch (state->state) { case LIBSPECTRUM_TAPE_STATE_DATA1: *tstates = state->bit_tstates; libspectrum_tape_raw_data_next_bit( block, state ); + /* Backwards as last bit is the state of the next bit as it has already been + updated*/ + *flags |= state->last_bit ? LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW : + LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH; break; case LIBSPECTRUM_TAPE_STATE_PAUSE: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-05-02 12:59:48
|
Revision: 4416 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4416&view=rev Author: fredm Date: 2011-05-02 12:59:42 +0000 (Mon, 02 May 2011) Log Message: ----------- Remove unneeded AM_SUBST_NOTMAKE macro as it doesn't get along with older autotools (patch #3295662) (thanks, Tom?\195?\161?\197?\161 Franke) (Sergio Baldov?\195?\173) Modified Paths: -------------- trunk/libspectrum/configure.in trunk/libspectrum/hacking/ChangeLog Modified: trunk/libspectrum/configure.in =================================================================== --- trunk/libspectrum/configure.in 2011-05-01 22:51:43 UTC (rev 4415) +++ trunk/libspectrum/configure.in 2011-05-02 12:59:42 UTC (rev 4416) @@ -74,9 +74,7 @@ fi fi AC_SUBST(WINDRES_OBJ) -AM_SUBST_NOTMAKE(WINDRES_OBJ) AC_SUBST(WINDRES_LDFLAGS) -AM_SUBST_NOTMAKE(WINDRES_LDFLAGS) dnl Check for big endianness AC_C_BIGENDIAN Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-05-01 22:51:43 UTC (rev 4415) +++ trunk/libspectrum/hacking/ChangeLog 2011-05-02 12:59:42 UTC (rev 4416) @@ -838,3 +838,6 @@ tape files (Fred). 20110429 wav.c: use some more LIBSPECTRUM_BITS_IN_BYTE constants (Fred). 20110429 tape.c: have raw data blocks report the polarity of pulses (Fred). +20100502 configure.in: remove unneeded AM_SUBST_NOTMAKE macro as it doesn't get + along with older autotools (patch #3295662) (thanks, Tomáš Franke) + (Sergio Baldoví) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-05-14 05:44:54
|
Revision: 4433 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4433&view=rev Author: fredm Date: 2011-05-14 05:44:47 +0000 (Sat, 14 May 2011) Log Message: ----------- Add support for the TZX set signal level block. Modified Paths: -------------- trunk/libspectrum/doc/libspectrum.txt trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.h.in trunk/libspectrum/tape.c trunk/libspectrum/tape_accessors.txt trunk/libspectrum/tape_block.c trunk/libspectrum/tape_block.h trunk/libspectrum/tzx_read.c trunk/libspectrum/tzx_write.c Modified: trunk/libspectrum/doc/libspectrum.txt =================================================================== --- trunk/libspectrum/doc/libspectrum.txt 2011-05-11 14:08:17 UTC (rev 4432) +++ trunk/libspectrum/doc/libspectrum.txt 2011-05-14 05:44:47 UTC (rev 4433) @@ -984,6 +984,7 @@ LIBSPECTRUM_TAPE_BLOCK_SELECT 0x28 LIBSPECTRUM_TAPE_BLOCK_STOP48 0x2a +LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL 0x2b LIBSPECTRUM_TAPE_BLOCK_COMMENT 0x30 LIBSPECTRUM_TAPE_BLOCK_MESSAGE 0x31 @@ -1188,6 +1189,7 @@ int level DATA_BLOCK PAUSE + SET_SIGNAL_LEVEL libspectrum_byte bit0_pulse_count DATA_BLOCK Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-05-11 14:08:17 UTC (rev 4432) +++ trunk/libspectrum/hacking/ChangeLog 2011-05-14 05:44:47 UTC (rev 4433) @@ -840,4 +840,7 @@ 20110429 tape.c: have raw data blocks report the polarity of pulses (Fred). 20100502 configure.in: remove unneeded AM_SUBST_NOTMAKE macro as it doesn't get along with older autotools (patch #3295662) (thanks, Tomáš Franke) - (Sergio Baldoví) + (Sergio Baldoví). +20100514 doc/libspectrum.txt,libspectrum.h.in,tape.c,tape_accessors.txt, + tape_block.[ch],tzx_read.c,tzx_write.c: add support for the TZX set + signal level block (Fred). Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2011-05-11 14:08:17 UTC (rev 4432) +++ trunk/libspectrum/libspectrum.h.in 2011-05-14 05:44:47 UTC (rev 4433) @@ -501,6 +501,7 @@ LIBSPECTRUM_TAPE_BLOCK_SELECT = 0x28, LIBSPECTRUM_TAPE_BLOCK_STOP48 = 0x2a, + LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL, LIBSPECTRUM_TAPE_BLOCK_COMMENT = 0x30, LIBSPECTRUM_TAPE_BLOCK_MESSAGE, Modified: trunk/libspectrum/tape.c =================================================================== --- trunk/libspectrum/tape.c 2011-05-11 14:08:17 UTC (rev 4432) +++ trunk/libspectrum/tape.c 2011-05-14 05:44:47 UTC (rev 4433) @@ -424,6 +424,12 @@ *tstates = 0; *flags |= LIBSPECTRUM_TAPE_FLAGS_STOP48; end_of_block = 1; break; + case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: + *tstates = 0; end_of_block = 1; + *flags |= block->types.set_signal_level.level ? + LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH : LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; + break; + /* For blocks which contain no Spectrum-readable data, return zero tstates and set end of block set so we instantly get the next block */ case LIBSPECTRUM_TAPE_BLOCK_GROUP_START: @@ -1371,6 +1377,10 @@ strncpy( buffer, "Stop Tape If In 48K Mode", length ); break; + case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: + strncpy( buffer, "Set Signal Level", length ); + break; + case LIBSPECTRUM_TAPE_BLOCK_COMMENT: strncpy( buffer, "Comment", length ); break; Modified: trunk/libspectrum/tape_accessors.txt =================================================================== --- trunk/libspectrum/tape_accessors.txt 2011-05-11 14:08:17 UTC (rev 4432) +++ trunk/libspectrum/tape_accessors.txt 2011-05-14 05:44:47 UTC (rev 4433) @@ -187,6 +187,7 @@ int level 0 -1 pause data_block initial_level + set_signal_level libspectrum_byte bit0_pulse_count 0 -1 data_block Modified: trunk/libspectrum/tape_block.c =================================================================== --- trunk/libspectrum/tape_block.c 2011-05-11 14:08:17 UTC (rev 4432) +++ trunk/libspectrum/tape_block.c 2011-05-14 05:44:47 UTC (rev 4433) @@ -139,6 +139,9 @@ case LIBSPECTRUM_TAPE_BLOCK_STOP48: break; + case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: + break; + case LIBSPECTRUM_TAPE_BLOCK_COMMENT: libspectrum_free( block->types.comment.text ); break; @@ -256,6 +259,7 @@ case LIBSPECTRUM_TAPE_BLOCK_LOOP_END: case LIBSPECTRUM_TAPE_BLOCK_SELECT: case LIBSPECTRUM_TAPE_BLOCK_STOP48: + case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: case LIBSPECTRUM_TAPE_BLOCK_COMMENT: case LIBSPECTRUM_TAPE_BLOCK_MESSAGE: case LIBSPECTRUM_TAPE_BLOCK_ARCHIVE_INFO: @@ -405,6 +409,7 @@ case LIBSPECTRUM_TAPE_BLOCK_LOOP_END: case LIBSPECTRUM_TAPE_BLOCK_SELECT: case LIBSPECTRUM_TAPE_BLOCK_STOP48: + case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: case LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE: case LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE: case LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK: @@ -780,6 +785,7 @@ case LIBSPECTRUM_TAPE_BLOCK_LOOP_START: case LIBSPECTRUM_TAPE_BLOCK_LOOP_END: case LIBSPECTRUM_TAPE_BLOCK_STOP48: + case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: case LIBSPECTRUM_TAPE_BLOCK_COMMENT: case LIBSPECTRUM_TAPE_BLOCK_MESSAGE: case LIBSPECTRUM_TAPE_BLOCK_ARCHIVE_INFO: Modified: trunk/libspectrum/tape_block.h =================================================================== --- trunk/libspectrum/tape_block.h 2011-05-11 14:08:17 UTC (rev 4432) +++ trunk/libspectrum/tape_block.h 2011-05-14 05:44:47 UTC (rev 4433) @@ -283,6 +283,13 @@ /* No `stop tape if in 48K mode' block as it contains no data */ +/* A set signal level block */ +typedef struct libspectrum_tape_set_signal_level_block { + + int level; /* Mic level 0/1 */ + +} libspectrum_tape_set_signal_level_block; + /* A comment block */ typedef struct libspectrum_tape_comment_block { @@ -446,6 +453,7 @@ /* No `stop tape if in 48K mode' block as it contains no data */ + libspectrum_tape_set_signal_level_block set_signal_level; libspectrum_tape_comment_block comment; libspectrum_tape_message_block message; libspectrum_tape_archive_info_block archive_info; Modified: trunk/libspectrum/tzx_read.c =================================================================== --- trunk/libspectrum/tzx_read.c 2011-05-11 14:08:17 UTC (rev 4432) +++ trunk/libspectrum/tzx_read.c 2011-05-14 05:44:47 UTC (rev 4433) @@ -78,6 +78,9 @@ tzx_read_stop( libspectrum_tape *tape, const libspectrum_byte **ptr, const libspectrum_byte *end ); static libspectrum_error +tzx_read_set_signal_level( libspectrum_tape *tape, const libspectrum_byte **ptr, + const libspectrum_byte *end ); +static libspectrum_error tzx_read_comment( libspectrum_tape *tape, const libspectrum_byte **ptr, const libspectrum_byte *end ); static libspectrum_error @@ -211,6 +214,11 @@ if( error ) { libspectrum_tape_clear( tape ); return error; } break; + case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: + error = tzx_read_set_signal_level( tape, &ptr, end ); + if( error ) { libspectrum_tape_clear( tape ); return error; } + break; + case LIBSPECTRUM_TAPE_BLOCK_COMMENT: error = tzx_read_comment( tape, &ptr, end ); if( error ) { libspectrum_tape_clear( tape ); return error; } @@ -823,6 +831,32 @@ } static libspectrum_error +tzx_read_set_signal_level( libspectrum_tape *tape, const libspectrum_byte **ptr, + const libspectrum_byte *end ) +{ + libspectrum_tape_block *block; + + /* Check the length field exists and signal level is available */ + if( end - (*ptr) < 5 ) { + libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, + "tzx_read_set_signal_level: not enough data in buffer" ); + return LIBSPECTRUM_ERROR_CORRUPT; + } + + /* But then just skip over it, as I don't care what it is */ + (*ptr) += 4; + + block = + libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL ); + + libspectrum_tape_block_set_level( block, !!(**ptr) ); (*ptr)++; + + libspectrum_tape_append_block( tape, block ); + + return LIBSPECTRUM_ERROR_NONE; +} + +static libspectrum_error tzx_read_comment( libspectrum_tape *tape, const libspectrum_byte **ptr, const libspectrum_byte *end ) { Modified: trunk/libspectrum/tzx_write.c =================================================================== --- trunk/libspectrum/tzx_write.c 2011-05-11 14:08:17 UTC (rev 4432) +++ trunk/libspectrum/tzx_write.c 2011-05-14 05:44:47 UTC (rev 4433) @@ -76,6 +76,10 @@ tzx_write_stop( libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ); static void +tzx_write_set_signal_level( libspectrum_tape_block *block, + libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length ); +static void tzx_write_comment( libspectrum_tape_block *block, libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ); static void @@ -192,6 +196,10 @@ tzx_write_stop( buffer, &ptr, length ); break; + case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: + tzx_write_set_signal_level( block, buffer, &ptr, length ); + break; + case LIBSPECTRUM_TAPE_BLOCK_COMMENT: tzx_write_comment( block, buffer, &ptr, length ); break; @@ -574,6 +582,20 @@ } static void +tzx_write_set_signal_level( libspectrum_tape_block *block, + libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length ) +{ + /* Make room for the ID byte, four length bytes and the level byte */ + libspectrum_make_room( buffer, 6, ptr, length ); + + *(*ptr)++ = LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL; + + libspectrum_write_dword( ptr, 1 ); + *(*ptr)++ = libspectrum_tape_block_level( block ); +} + +static void tzx_write_comment( libspectrum_tape_block *block, libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-05-14 14:10:14
|
Revision: 4436 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4436&view=rev Author: fredm Date: 2011-05-14 14:10:07 +0000 (Sat, 14 May 2011) Log Message: ----------- Tweak set signal level and pause blocks to correct level information. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tape.c trunk/libspectrum/tzx_read.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-05-14 05:52:06 UTC (rev 4435) +++ trunk/libspectrum/hacking/ChangeLog 2011-05-14 14:10:07 UTC (rev 4436) @@ -844,3 +844,5 @@ 20100514 doc/libspectrum.txt,libspectrum.h.in,tape.c,tape_accessors.txt, tape_block.[ch],tzx_read.c,tzx_write.c: add support for the TZX set signal level block (Fred). +20100514 tape.c,tzx_read.c: tweak set signal level and pause blocks to correct + level information (Fred). Modified: trunk/libspectrum/tape.c =================================================================== --- trunk/libspectrum/tape.c 2011-05-14 05:52:06 UTC (rev 4435) +++ trunk/libspectrum/tape.c 2011-05-14 14:10:07 UTC (rev 4436) @@ -387,8 +387,13 @@ case LIBSPECTRUM_TAPE_BLOCK_PAUSE: *tstates = block->types.pause.length_tstates; end_of_block = 1; - *flags |= block->types.pause.level ? LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH : - LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; + /* If the pause isn't a "don't care" level then set the appropriate pulse + level */ + if( block->types.pause.level != -1 && + block->types.pause.length_tstates ) { + *flags |= block->types.pause.level ? LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH : + LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; + } /* 0 ms pause => stop tape */ if( *tstates == 0 ) { *flags |= LIBSPECTRUM_TAPE_FLAGS_STOP; } break; @@ -426,8 +431,10 @@ case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: *tstates = 0; end_of_block = 1; + /* Inverted as the following block will flip the level before recording + the edge */ *flags |= block->types.set_signal_level.level ? - LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH : LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; + LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW : LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH; break; /* For blocks which contain no Spectrum-readable data, return zero Modified: trunk/libspectrum/tzx_read.c =================================================================== --- trunk/libspectrum/tzx_read.c 2011-05-14 05:52:06 UTC (rev 4435) +++ trunk/libspectrum/tzx_read.c 2011-05-14 14:10:07 UTC (rev 4436) @@ -647,7 +647,8 @@ /* Get the pause length */ libspectrum_set_pause_ms( block, (*ptr)[0] + (*ptr)[1] * 0x100 ); - libspectrum_tape_block_set_level( block, -1 ); /* No specific level */ + /* TZX format spec says pause is low */ + libspectrum_tape_block_set_level( block, 0 ); (*ptr) += 2; libspectrum_tape_append_block( tape, block ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-05-14 14:29:11
|
Revision: 4439 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4439&view=rev Author: fredm Date: 2011-05-14 14:29:04 +0000 (Sat, 14 May 2011) Log Message: ----------- Add support for writing PZX blocks to TZX files. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tzx_write.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-05-14 14:22:24 UTC (rev 4438) +++ trunk/libspectrum/hacking/ChangeLog 2011-05-14 14:29:04 UTC (rev 4439) @@ -846,3 +846,4 @@ signal level block (Fred). 20100514 tape.c,tzx_read.c: tweak set signal level and pause blocks to correct level information (Fred). +20100514 tzx_write.c: add support for writing PZX blocks to TZX files (Fred). Modified: trunk/libspectrum/tzx_write.c =================================================================== --- trunk/libspectrum/tzx_write.c 2011-05-14 14:22:24 UTC (rev 4438) +++ trunk/libspectrum/tzx_write.c 2011-05-14 14:29:04 UTC (rev 4439) @@ -100,6 +100,17 @@ libspectrum_byte **ptr, size_t *length, libspectrum_tape *tape, libspectrum_tape_iterator iterator ); +static void +add_pulses_block( size_t pulse_count, libspectrum_dword *lengths, + libspectrum_tape_block *block, libspectrum_byte **buffer, + libspectrum_byte **ptr, size_t *length ); +static void +tzx_write_pulse_sequence( libspectrum_tape_block *block, + libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length ); +static libspectrum_error +tzx_write_data_block( libspectrum_tape_block *block, libspectrum_byte **buffer, + libspectrum_byte **ptr, size_t *length ); static void tzx_write_empty_block( libspectrum_byte **buffer, libspectrum_byte **ptr, @@ -225,6 +236,14 @@ if( error != LIBSPECTRUM_ERROR_NONE ) { libspectrum_free( *buffer ); return error; } break; + case LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE: + tzx_write_pulse_sequence( block, buffer, &ptr, length ); + break; + case LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK: + error = tzx_write_data_block( block, buffer, &ptr, length ); + if( error != LIBSPECTRUM_ERROR_NONE ) { libspectrum_free( *buffer ); return error; } + break; + default: libspectrum_free( *buffer ); libspectrum_print_error( @@ -496,6 +515,36 @@ tzx_write_pause( libspectrum_tape_block *block, libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ) { + /* High pause when represented in the TZX format is really a set signal level + 1 and then a pulse as TZX format says that all pauses are low, a don't care + pause is a pulse too */ + if( libspectrum_tape_block_level( block ) != 0 ) { + libspectrum_tape_block *new_block; + if( libspectrum_tape_block_level( block ) == 1 ) { + new_block = + libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL ); + + libspectrum_tape_block_set_level( new_block, 1 ); + + tzx_write_set_signal_level( new_block, buffer, ptr, length ); + + libspectrum_free( new_block ); + } + + new_block = + libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PURE_TONE ); + + libspectrum_tape_block_set_pulse_length( new_block, + libspectrum_tape_block_pause_tstates( block ) ); + libspectrum_tape_block_set_count( new_block, 1 ); + + tzx_write_pure_tone( new_block, buffer, ptr, length ); + + libspectrum_free( new_block ); + + return; + } + libspectrum_make_room( buffer, 3, ptr, length ); *(*ptr)++ = LIBSPECTRUM_TAPE_BLOCK_PAUSE; libspectrum_write_word( ptr, libspectrum_tape_block_pause( block ) ); @@ -841,6 +890,149 @@ } static void +add_pulses_block( size_t pulse_count, libspectrum_dword *lengths, + libspectrum_tape_block *block, libspectrum_byte **buffer, + libspectrum_byte **ptr, size_t *length ) +{ + libspectrum_tape_block *pulses = + libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PULSES ); + + libspectrum_tape_block_set_count( pulses, pulse_count ); + libspectrum_tape_block_set_pulse_lengths( pulses, lengths ); + + tzx_write_pulses( pulses, buffer, ptr, length ); + + libspectrum_free( pulses ); +} + +/* Use ID 2B to set initial signal level, ID 12 Pure Tone for repeating pulses + and ID 13 Pulse Sequence for non-repeating */ +static void +tzx_write_pulse_sequence( libspectrum_tape_block *block, + libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length ) +{ + size_t count = libspectrum_tape_block_count( block ); + size_t i; + size_t uncommitted_pulse_count = 0; + libspectrum_dword *lengths = NULL; + + libspectrum_tape_block *new_block = + libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL ); + + libspectrum_tape_block_set_level( new_block, 0 ); + + tzx_write_set_signal_level( new_block, buffer, ptr, length ); + + libspectrum_free( new_block ); + + for( i = 0; i<count; i++ ) { + if( libspectrum_tape_block_pulse_repeats( block, i ) > 1 ) { + /* Close off any outstanding pulse blocks */ + if( uncommitted_pulse_count > 0 ) { + add_pulses_block( uncommitted_pulse_count, lengths, block, buffer, ptr, + length ); + uncommitted_pulse_count = 0; + lengths = NULL; + } + + libspectrum_tape_block *new_block = + libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PURE_TONE ); + + libspectrum_tape_block_set_pulse_length( new_block, + libspectrum_tape_block_pulse_lengths( block, i ) ); + libspectrum_tape_block_set_count( new_block, + libspectrum_tape_block_pulse_repeats( block, i ) ); + + tzx_write_pure_tone( new_block, buffer, ptr, length ); + + libspectrum_free( new_block ); + } else { + /* Queue up pulse */ + lengths = + libspectrum_realloc( lengths, + ( uncommitted_pulse_count + 1 ) * sizeof( *lengths ) ); + lengths[uncommitted_pulse_count++] = + libspectrum_tape_block_pulse_lengths( block, i ); + } + } + + /* Close off any outstanding pulse blocks */ + if( uncommitted_pulse_count > 0 ) { + add_pulses_block( uncommitted_pulse_count, lengths, block, buffer, ptr, + length ); + } +} + +/* Use ID 2B to set initial signal level, ID 14 Pure Data Block and a ID 12 + Pure Tone for the tail pulse */ +static libspectrum_error +tzx_write_data_block( libspectrum_tape_block *block, libspectrum_byte **buffer, + libspectrum_byte **ptr, size_t *length ) +{ + libspectrum_tape_block *new_block; + size_t data_length; + + /* Pure data block can only have two identical pulses for bit 0 and bit 1 */ + if( libspectrum_tape_block_bit0_pulse_count( block ) != 2 || + ( libspectrum_tape_block_bit0_pulses( block, 0 ) != + libspectrum_tape_block_bit0_pulses( block, 1 ) ) || + libspectrum_tape_block_bit1_pulse_count( block ) != 2 || + ( libspectrum_tape_block_bit1_pulses( block, 0 ) != + libspectrum_tape_block_bit1_pulses( block, 1 ) ) ) { + /* Could use generalised data block for these cases if a suitable test file + is located, right now I haven't seen any */ + return LIBSPECTRUM_ERROR_UNKNOWN; + } + + new_block = + libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL ); + + libspectrum_tape_block_set_level( new_block, + libspectrum_tape_block_level( block ) ); + + tzx_write_set_signal_level( new_block, buffer, ptr, length ); + + libspectrum_free( new_block ); + + new_block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PURE_DATA ); + + libspectrum_tape_block_set_bit0_length( new_block, + libspectrum_tape_block_bit0_pulses( block, 0 ) ); + libspectrum_tape_block_set_bit1_length( new_block, + libspectrum_tape_block_bit1_pulses( block, 0 ) ); + libspectrum_tape_block_set_bits_in_last_byte( new_block, + libspectrum_tape_block_bits_in_last_byte( block ) ); + libspectrum_set_pause_tstates( new_block, 0 ); + + /* And the actual data */ + data_length = libspectrum_tape_block_data_length( block ); + libspectrum_tape_block_set_data_length( new_block, data_length ); + libspectrum_byte *data = libspectrum_malloc( data_length * sizeof( *data ) ); + memcpy( data, libspectrum_tape_block_data( block ), data_length ); + libspectrum_tape_block_set_data( new_block, data ); + + tzx_write_data( new_block, buffer, ptr, length ); + + libspectrum_free( new_block ); + + if( libspectrum_tape_block_tail_length( block ) ) { + new_block = + libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PURE_TONE ); + + libspectrum_tape_block_set_pulse_length( new_block, + libspectrum_tape_block_tail_length( block ) ); + libspectrum_tape_block_set_count( new_block, 1 ); + + tzx_write_pure_tone( new_block, buffer, ptr, length ); + + libspectrum_free( new_block ); + } + + return LIBSPECTRUM_ERROR_NONE; +} + +static void tzx_write_empty_block( libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length, libspectrum_tape_type id ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-05-15 10:53:54
|
Revision: 4440 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4440&view=rev Author: fredm Date: 2011-05-15 10:53:47 +0000 (Sun, 15 May 2011) Log Message: ----------- Add support for the TZX set signal level block. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tap.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-05-14 14:29:04 UTC (rev 4439) +++ trunk/libspectrum/hacking/ChangeLog 2011-05-15 10:53:47 UTC (rev 4440) @@ -847,3 +847,4 @@ 20100514 tape.c,tzx_read.c: tweak set signal level and pause blocks to correct level information (Fred). 20100514 tzx_write.c: add support for writing PZX blocks to TZX files (Fred). +20100515 tap.c: add support for the TZX set signal level block (Fred). Modified: trunk/libspectrum/tap.c =================================================================== --- trunk/libspectrum/tap.c 2011-05-14 14:29:04 UTC (rev 4439) +++ trunk/libspectrum/tap.c 2011-05-15 10:53:47 UTC (rev 4440) @@ -187,6 +187,7 @@ case LIBSPECTRUM_TAPE_BLOCK_PAUSE: case LIBSPECTRUM_TAPE_BLOCK_JUMP: case LIBSPECTRUM_TAPE_BLOCK_SELECT: + case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: error = skip_block( block, "conversion may not work" ); if( error != LIBSPECTRUM_ERROR_NONE ) { libspectrum_free( *buffer ); return 1; } done = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2011-05-15 11:16:34
|
Revision: 4441 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4441&view=rev Author: fredm Date: 2011-05-15 11:16:28 +0000 (Sun, 15 May 2011) Log Message: ----------- Factor out common code for writing signal level and pure tone blocks. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/tzx_write.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-05-15 10:53:47 UTC (rev 4440) +++ trunk/libspectrum/hacking/ChangeLog 2011-05-15 11:16:28 UTC (rev 4441) @@ -848,3 +848,5 @@ level information (Fred). 20100514 tzx_write.c: add support for writing PZX blocks to TZX files (Fred). 20100515 tap.c: add support for the TZX set signal level block (Fred). +20100515 tzx_write.c: factor out common code for writing signal level and pure + tone blocks (Fred). Modified: trunk/libspectrum/tzx_write.c =================================================================== --- trunk/libspectrum/tzx_write.c 2011-05-15 10:53:47 UTC (rev 4440) +++ trunk/libspectrum/tzx_write.c 2011-05-15 11:16:28 UTC (rev 4441) @@ -40,6 +40,10 @@ tzx_write_turbo( libspectrum_tape_block *block, libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ); static void +add_pure_tone_block( libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length, libspectrum_dword pulse_length, + size_t count ); +static void tzx_write_pure_tone( libspectrum_tape_block *block, libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ); static void @@ -76,6 +80,9 @@ tzx_write_stop( libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ); static void +add_set_signal_level_block( libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length, int level ); +static void tzx_write_set_signal_level( libspectrum_tape_block *block, libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ); @@ -299,18 +306,28 @@ } static void -tzx_write_pure_tone( libspectrum_tape_block *block, libspectrum_byte **buffer, - libspectrum_byte **ptr, size_t *length ) +add_pure_tone_block( libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length, libspectrum_dword pulse_length, + size_t count ) { /* Make room for the ID byte and the data */ libspectrum_make_room( buffer, 5, ptr, length ); *(*ptr)++ = LIBSPECTRUM_TAPE_BLOCK_PURE_TONE; - libspectrum_write_word( ptr, libspectrum_tape_block_pulse_length( block ) ); - libspectrum_write_word( ptr, libspectrum_tape_block_count( block ) ); + libspectrum_write_word( ptr, pulse_length ); + libspectrum_write_word( ptr, count ); } static void +tzx_write_pure_tone( libspectrum_tape_block *block, libspectrum_byte **buffer, + libspectrum_byte **ptr, size_t *length ) +{ + add_pure_tone_block( buffer, ptr, length, + libspectrum_tape_block_pulse_length( block ), + libspectrum_tape_block_count( block ) ); +} + +static void tzx_write_pulses( libspectrum_tape_block *block, libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ) { @@ -519,29 +536,13 @@ 1 and then a pulse as TZX format says that all pauses are low, a don't care pause is a pulse too */ if( libspectrum_tape_block_level( block ) != 0 ) { - libspectrum_tape_block *new_block; if( libspectrum_tape_block_level( block ) == 1 ) { - new_block = - libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL ); - - libspectrum_tape_block_set_level( new_block, 1 ); - - tzx_write_set_signal_level( new_block, buffer, ptr, length ); - - libspectrum_free( new_block ); + add_set_signal_level_block( buffer, ptr, length, 1 ); } - new_block = - libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PURE_TONE ); + add_pure_tone_block( buffer, ptr, length, + libspectrum_tape_block_pause_tstates( block ), 1 ); - libspectrum_tape_block_set_pulse_length( new_block, - libspectrum_tape_block_pause_tstates( block ) ); - libspectrum_tape_block_set_count( new_block, 1 ); - - tzx_write_pure_tone( new_block, buffer, ptr, length ); - - libspectrum_free( new_block ); - return; } @@ -631,9 +632,8 @@ } static void -tzx_write_set_signal_level( libspectrum_tape_block *block, - libspectrum_byte **buffer, libspectrum_byte **ptr, - size_t *length ) +add_set_signal_level_block( libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length, int level ) { /* Make room for the ID byte, four length bytes and the level byte */ libspectrum_make_room( buffer, 6, ptr, length ); @@ -641,10 +641,19 @@ *(*ptr)++ = LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL; libspectrum_write_dword( ptr, 1 ); - *(*ptr)++ = libspectrum_tape_block_level( block ); + *(*ptr)++ = level; } static void +tzx_write_set_signal_level( libspectrum_tape_block *block, + libspectrum_byte **buffer, libspectrum_byte **ptr, + size_t *length ) +{ + add_set_signal_level_block( buffer, ptr, length, + libspectrum_tape_block_level( block ) ); +} + +static void tzx_write_comment( libspectrum_tape_block *block, libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ) { @@ -902,7 +911,7 @@ tzx_write_pulses( pulses, buffer, ptr, length ); - libspectrum_free( pulses ); + libspectrum_tape_block_free( pulses ); } /* Use ID 2B to set initial signal level, ID 12 Pure Tone for repeating pulses @@ -915,19 +924,14 @@ size_t count = libspectrum_tape_block_count( block ); size_t i; size_t uncommitted_pulse_count = 0; + size_t max_pulse_count = 0; libspectrum_dword *lengths = NULL; - libspectrum_tape_block *new_block = - libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL ); + add_set_signal_level_block( buffer, ptr, length, 0 ); - libspectrum_tape_block_set_level( new_block, 0 ); - - tzx_write_set_signal_level( new_block, buffer, ptr, length ); - - libspectrum_free( new_block ); - for( i = 0; i<count; i++ ) { - if( libspectrum_tape_block_pulse_repeats( block, i ) > 1 ) { + size_t pulse_repeats = libspectrum_tape_block_pulse_repeats( block, i ); + if( pulse_repeats > 1 ) { /* Close off any outstanding pulse blocks */ if( uncommitted_pulse_count > 0 ) { add_pulses_block( uncommitted_pulse_count, lengths, block, buffer, ptr, @@ -936,22 +940,16 @@ lengths = NULL; } - libspectrum_tape_block *new_block = - libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PURE_TONE ); - - libspectrum_tape_block_set_pulse_length( new_block, - libspectrum_tape_block_pulse_lengths( block, i ) ); - libspectrum_tape_block_set_count( new_block, - libspectrum_tape_block_pulse_repeats( block, i ) ); - - tzx_write_pure_tone( new_block, buffer, ptr, length ); - - libspectrum_free( new_block ); + add_pure_tone_block( buffer, ptr, length, + libspectrum_tape_block_pulse_lengths( block, i ), + pulse_repeats ); } else { + if( uncommitted_pulse_count == max_pulse_count ) { + max_pulse_count = uncommitted_pulse_count + 64; + lengths = + libspectrum_realloc( lengths, max_pulse_count * sizeof( *lengths ) ); + } /* Queue up pulse */ - lengths = - libspectrum_realloc( lengths, - ( uncommitted_pulse_count + 1 ) * sizeof( *lengths ) ); lengths[uncommitted_pulse_count++] = libspectrum_tape_block_pulse_lengths( block, i ); } @@ -970,7 +968,7 @@ tzx_write_data_block( libspectrum_tape_block *block, libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length ) { - libspectrum_tape_block *new_block; + libspectrum_tape_block *pure_data; size_t data_length; /* Pure data block can only have two identical pulses for bit 0 and bit 1 */ @@ -985,48 +983,32 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } - new_block = - libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL ); + tzx_write_set_signal_level( block, buffer, ptr, length ); - libspectrum_tape_block_set_level( new_block, - libspectrum_tape_block_level( block ) ); + pure_data = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PURE_DATA ); - tzx_write_set_signal_level( new_block, buffer, ptr, length ); - - libspectrum_free( new_block ); - - new_block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PURE_DATA ); - - libspectrum_tape_block_set_bit0_length( new_block, + libspectrum_tape_block_set_bit0_length( pure_data, libspectrum_tape_block_bit0_pulses( block, 0 ) ); - libspectrum_tape_block_set_bit1_length( new_block, + libspectrum_tape_block_set_bit1_length( pure_data, libspectrum_tape_block_bit1_pulses( block, 0 ) ); - libspectrum_tape_block_set_bits_in_last_byte( new_block, + libspectrum_tape_block_set_bits_in_last_byte( pure_data, libspectrum_tape_block_bits_in_last_byte( block ) ); - libspectrum_set_pause_tstates( new_block, 0 ); + libspectrum_set_pause_tstates( pure_data, 0 ); /* And the actual data */ data_length = libspectrum_tape_block_data_length( block ); - libspectrum_tape_block_set_data_length( new_block, data_length ); + libspectrum_tape_block_set_data_length( pure_data, data_length ); libspectrum_byte *data = libspectrum_malloc( data_length * sizeof( *data ) ); memcpy( data, libspectrum_tape_block_data( block ), data_length ); - libspectrum_tape_block_set_data( new_block, data ); + libspectrum_tape_block_set_data( pure_data, data ); - tzx_write_data( new_block, buffer, ptr, length ); + tzx_write_data( pure_data, buffer, ptr, length ); - libspectrum_free( new_block ); + libspectrum_tape_block_free( pure_data ); if( libspectrum_tape_block_tail_length( block ) ) { - new_block = - libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PURE_TONE ); - - libspectrum_tape_block_set_pulse_length( new_block, - libspectrum_tape_block_tail_length( block ) ); - libspectrum_tape_block_set_count( new_block, 1 ); - - tzx_write_pure_tone( new_block, buffer, ptr, length ); - - libspectrum_free( new_block ); + add_pure_tone_block( buffer, ptr, length, + libspectrum_tape_block_tail_length( block ), 1 ); } return LIBSPECTRUM_ERROR_NONE; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |