Previous 15994 Revisions Next

r5272 Saturday 18th July, 2009 at 21:10:34 UTC by Fabio Priuli
Added basic logging for info/comment blocks to TZX files.
Info are not (and won't be) used directly by the emulator, but they can help to improve bug reports.

Also, updated to v1.20 TZX specs, by deprecating some block types.
[docs]messnew.txt
[src/mess/formats]tzx_cas.c

src/mess/formats/tzx_cas.c
r5271r5272
7373static UINT8**   blocks;
7474static float t_scale = 1;  /* for scaling T-states to the 4MHz CPC */
7575
76static void toggle_wave_data(void) {
77   if ( wave_data == WAVE_LOW ) {
76static void toggle_wave_data(void)
77{
78   if (wave_data == WAVE_LOW)
79   {
7880      wave_data = WAVE_HIGH;
79   } else {
81   }
82   else
83   {
8084      wave_data = WAVE_LOW;
8185   }
8286}
8387
84static void tzx_cas_get_blocks( const UINT8 *casdata, int caslen ) {
88static void tzx_cas_get_blocks( const UINT8 *casdata, int caslen )
89{
8590   int pos = sizeof(TZX_HEADER) + 2;
8691   int max_block_count = INITIAL_MAX_BLOCK_COUNT;
8792
8893   blocks = alloc_array_clear_or_die(UINT8*, max_block_count);
8994   block_count = 0;
9095
91   while( pos < caslen ) {
96   while (pos < caslen)
97   {
9298      UINT32 datasize;
9399      UINT8 blocktype = casdata[pos];
94100
95      if ( block_count == max_block_count ) {
101      if (block_count == max_block_count)
102      {
96103         void   *old_blocks = blocks;
97104         int   old_max_block_count = max_block_count;
98105
99106         max_block_count = max_block_count + BLOCK_COUNT_INCREMENTS;
100107         blocks = auto_alloc_array(NULL /*machine*/, UINT8*, max_block_count);   // SHOULD NOT BE USING auto_alloc_array()
101         memcpy( blocks, old_blocks, old_max_block_count * sizeof(UINT8*) );
108         memcpy(blocks, old_blocks, old_max_block_count * sizeof(UINT8*));
102109      }
103110
104111      blocks[block_count] = (UINT8*)&casdata[pos];
105112
106113      pos += 1;
107114
108      switch( blocktype ) {
115      switch (blocktype)
116      {
109117      case 0x10:
110118         pos += 2;
111         datasize = casdata[pos] + ( casdata[pos+1] << 8 );
119         datasize = casdata[pos] + (casdata[pos + 1] << 8);
112120         pos += 2 + datasize;
113121         break;
114122      case 0x11:
115123         pos += 0x0f;
116         datasize = casdata[pos] + ( casdata[pos+1] << 8 ) + ( casdata[pos+2] << 16 );
124         datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16);
117125         pos += 3 + datasize;
118126         break;
119127      case 0x12:
r5271r5272
125133         break;
126134      case 0x14:
127135         pos += 7;
128         datasize = casdata[pos] + ( casdata[pos+1] << 8 ) + ( casdata[pos+2] << 16 );
136         datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16);
129137         pos += 3 + datasize;
130138         break;
131139      case 0x15:
132140         pos += 5;
133         datasize = casdata[pos] + ( casdata[pos+1] << 8 ) + ( casdata[pos+2] << 16 );
141         datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16);
134142         pos += 3 + datasize;
135143         break;
136144      case 0x20: case 0x23: case 0x24:
r5271r5272
143151      case 0x22: case 0x25: case 0x27:
144152         break;
145153      case 0x26:
146         datasize = casdata[pos] + ( casdata[pos+1] << 8 );
154         datasize = casdata[pos] + (casdata[pos + 1] << 8);
147155         pos += 2 + 2 * datasize;
148156         break;
149157      case 0x28: case 0x32:
150         datasize = casdata[pos] + ( casdata[pos+1] << 8 );
158         datasize = casdata[pos] + (casdata[pos + 1] << 8);
151159         pos += 2 + datasize;
152160         break;
153161      case 0x31:
r5271r5272
164172         break;
165173      case 0x35:
166174         pos += 0x10;
167         datasize = casdata[pos] + ( casdata[pos+1] << 8 ) + ( casdata[pos+2] << 16 ) + ( casdata[pos+3] << 24 );
175         datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16) + (casdata[pos + 3] << 24);
168176         pos += 4 + datasize;
169177         break;
170178      case 0x40:
171179         pos += 1;
172         datasize = casdata[pos] + ( casdata[pos+1] << 8 ) + ( casdata[pos+2] << 16 );
180         datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16);
173181         pos += 3 + datasize;
174182         break;
175183      case 0x5A:
176184         pos += 9;
177185         break;
178186      default:
179         datasize = casdata[pos] + ( casdata[pos+1] << 8 ) + ( casdata[pos+2] << 16 ) + ( casdata[pos+3] << 24 );
187         datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16) + (casdata[pos + 3] << 24);
180188         pos += 4 + datasize;
181189         break;
182190      }
r5271r5272
186194   free(blocks);
187195}
188196
189INLINE int millisec_to_samplecount( int millisec ) {
190   return (int) ( millisec * ( (double)TZX_WAV_FREQUENCY / 1000.0 ) );
197INLINE int millisec_to_samplecount( int millisec )
198{
199   return (int) (millisec * ((double)TZX_WAV_FREQUENCY / 1000.0));
191200}
192201
193INLINE int tcycles_to_samplecount( int tcycles ) {
194   return (int) ( ( 0.5 + ( ( (double)TZX_WAV_FREQUENCY / 3500000 ) * (double)tcycles ) ) * t_scale );
202INLINE int tcycles_to_samplecount( int tcycles )
203{
204   return (int) ((0.5 + (((double)TZX_WAV_FREQUENCY / 3500000) * (double)tcycles)) * t_scale);
195205}
196206
197static void tzx_output_wave( INT16 **buffer, int length ) {
198   if ( buffer == NULL ) {
207static void tzx_output_wave( INT16 **buffer, int length )
208{
209   if (buffer == NULL)
210   {
199211      return;
200212   }
201213
202   for( ; length > 0; length-- ) {
214   for ( ; length > 0; length--)
215   {
203216      **buffer = wave_data;
204217      *buffer = *buffer + 1;
205218   }
206219}
207220
208static int tzx_cas_handle_block( INT16 **buffer, const UINT8 *bytes, int pause, int data_size, int pilot, int pilot_length, int sync1, int sync2, int bit0, int bit1, int bits_in_last_byte ) {
209   int pilot_samples = tcycles_to_samplecount( pilot );
210   int sync1_samples = tcycles_to_samplecount( sync1 );
211   int sync2_samples = tcycles_to_samplecount( sync2 );
212   int bit0_samples = tcycles_to_samplecount( bit0 );
213   int bit1_samples = tcycles_to_samplecount( bit1 );
221static int tzx_cas_handle_block( INT16 **buffer, const UINT8 *bytes, int pause, int data_size, int pilot, int pilot_length, int sync1, int sync2, int bit0, int bit1, int bits_in_last_byte )
222{
223   int pilot_samples = tcycles_to_samplecount(pilot);
224   int sync1_samples = tcycles_to_samplecount(sync1);
225   int sync2_samples = tcycles_to_samplecount(sync2);
226   int bit0_samples = tcycles_to_samplecount(bit0);
227   int bit1_samples = tcycles_to_samplecount(bit1);
214228   int data_index;
215229   int size = 0;
216230
217   logerror( "tzx_cas_block_size: pilot_length = %d, pilot_samples = %d, sync1_samples = %d, sync2_samples = %d, bit0_samples = %d, bit1_samples = %d\n", pilot_length, pilot_samples, sync1_samples, sync2_samples, bit0_samples, bit1_samples );
231   /* Uncomment this to include into error.log a fully detailed analysis of each block */
232//   logerror("tzx_cas_block_size: pilot_length = %d, pilot_samples = %d, sync1_samples = %d, sync2_samples = %d, bit0_samples = %d, bit1_samples = %d\n", pilot_length, pilot_samples, sync1_samples, sync2_samples, bit0_samples, bit1_samples);
218233
219234   /* PILOT */
220   for( ; pilot_length > 0; pilot_length-- ) {
221      tzx_output_wave( buffer, pilot_samples );
235   for ( ; pilot_length > 0; pilot_length--)
236   {
237      tzx_output_wave(buffer, pilot_samples);
222238      size += pilot_samples;
223239      toggle_wave_data();
224240   }
225241   /* SYNC1 */
226   if ( sync1_samples > 0 ) {
227      tzx_output_wave( buffer, sync1_samples );
242   if (sync1_samples > 0)
243   {
244      tzx_output_wave(buffer, sync1_samples);
228245      size += sync1_samples;
229246      toggle_wave_data();
230247   }
231248   /* SYNC2 */
232   if ( sync2_samples > 0 ) {
233      tzx_output_wave( buffer, sync2_samples );
249   if (sync2_samples > 0)
250   {
251      tzx_output_wave(buffer, sync2_samples);
234252      size += sync2_samples;
235253      toggle_wave_data();
236254   }
237255   /* data */
238   for( data_index = 0; data_index < data_size; data_index++ ) {
239      UINT8   byte = bytes[data_index];
240      int   bits_to_go = ( data_index == ( data_size - 1 ) ) ? bits_in_last_byte : 8;
241      for( ; bits_to_go > 0; byte <<= 1, bits_to_go-- ) {
242         int   bit_samples = ( byte & 0x80 ) ? bit1_samples : bit0_samples;
243         tzx_output_wave( buffer, bit_samples );
256   for (data_index = 0; data_index < data_size; data_index++)
257   {
258      UINT8 byte = bytes[data_index];
259      int   bits_to_go = (data_index == (data_size - 1)) ? bits_in_last_byte : 8;
260
261      for ( ; bits_to_go > 0; byte <<= 1, bits_to_go--)
262      {
263         int   bit_samples = (byte & 0x80) ? bit1_samples : bit0_samples;
264         tzx_output_wave(buffer, bit_samples);
244265         size += bit_samples;
245266         toggle_wave_data();
246         tzx_output_wave( buffer, bit_samples );
267         tzx_output_wave(buffer, bit_samples);
247268         size += bit_samples;
248269         toggle_wave_data();
249270      }
250271   }
251272   /* pause */
252   if ( pause > 0 ) {
253      int start_pause_samples = millisec_to_samplecount( 1 );
254      int rest_pause_samples = millisec_to_samplecount( pause - 1 );
273   if (pause > 0)
274   {
275      int start_pause_samples = millisec_to_samplecount(1);
276      int rest_pause_samples = millisec_to_samplecount(pause - 1);
255277
256      tzx_output_wave( buffer, start_pause_samples );
278      tzx_output_wave(buffer, start_pause_samples);
257279      size += start_pause_samples;
258280      wave_data = WAVE_LOW;
259      tzx_output_wave( buffer, rest_pause_samples );
281      tzx_output_wave(buffer, rest_pause_samples);
260282      size += rest_pause_samples;
261283   }
262    return size;
284   return size;
263285}
264286
265/*
266  Will go through blocks and calculate number of samples needed.
267  If buffer is not NULL the sample data will also be written.
268 */
269static int tzx_cas_do_work( INT16 **buffer ) {
287static void ascii_block_common_log( const char *block_type_string, UINT8 block_type )
288{
289   logerror("%s (type %02x) encountered.\n", block_type_string, block_type);
290   logerror("This block contains info on the .tzx file you are loading.\n");
291   logerror("Please include the following info in your bug reports, if the image has issue in M.E.S.S.\n");
292}
293
294static const char *const archive_ident[] =
295{
296   "Full title",
297   "Software house/publisher",
298   "Author(s)",
299   "Year of publication",
300   "Language",
301   "Game/utility type",
302   "Price",
303   "Protection scheme/loader",
304   "Origin",
305};
306
307static const char *const hw_info[] =
308{
309   "Tape runs on this machine / this hardware",
310   "Tape needs this machine / this hardware",
311   "Tape runs on this machine / this hardware, but does not require its special features",
312   "Tape does not run on this machine / this hardware",
313};
314
315/*  Will go through blocks and calculate number of samples needed.
316If buffer is not NULL the sample data will also be written. */
317static int tzx_cas_do_work( INT16 **buffer )
318{
270319   int   current_block = 0;
271320   int   size = 0;
272321
273322   wave_data = WAVE_LOW;
274323
275   while( current_block < block_count ) {
324   while (current_block < block_count)
325   {
276326      int   pause_time;
277      int   data_size;
327      int   data_size, text_size, total_size, i;
278328      int   pilot, pilot_length, sync1, sync2;
279329      int   bit0, bit1, bits_in_last_byte;
280      UINT8   *cur_block = blocks[current_block];
281      UINT8   block_type =cur_block[0];
282      logerror( "tzx_cas_fill_wave: block %d, block_type %02x\n", current_block, block_type );
283      switch( block_type ) {
330      UINT8 *cur_block = blocks[current_block];
331      UINT8 block_type = cur_block[0];
332
333   /* Uncomment this to include into error.log a list of the types each block */
334//      logerror("tzx_cas_fill_wave: block %d, block_type %02x\n", current_block, block_type);
335
336      switch (block_type)
337      {
284338      case 0x10:   /* Standard Speed Data Block (.TAP block) */
285         pause_time = cur_block[1] + ( cur_block[2] << 8 );
286         data_size = cur_block[3] + ( cur_block[4] << 8 );
287         pilot_length = ( cur_block[5] == 0x00 ) ?  8064 : 3220;
288         size += tzx_cas_handle_block( buffer, &cur_block[5], pause_time, data_size, 2168, pilot_length, 667, 735, 855, 1710, 8 );
339         pause_time = cur_block[1] + (cur_block[2] << 8);
340         data_size = cur_block[3] + (cur_block[4] << 8);
341         pilot_length = (cur_block[5] == 0x00) ?  8064 : 3220;
342         size += tzx_cas_handle_block(buffer, &cur_block[5], pause_time, data_size, 2168, pilot_length, 667, 735, 855, 1710, 8);
289343         current_block++;
290344         break;
291345      case 0x11:   /* Turbo Loading Data Block */
292         pilot = cur_block[1] + ( cur_block[2] << 8 );
293         sync1 = cur_block[3] + ( cur_block[4] << 8 );
294         sync2 = cur_block[5] + ( cur_block[6] << 8 );
295         bit0 = cur_block[7] + ( cur_block[8] << 8 );
296         bit1 = cur_block[9] + ( cur_block[10] << 8 );
297         pilot_length = cur_block[11] + ( cur_block[12] << 8 );
346         pilot = cur_block[1] + (cur_block[2] << 8);
347         sync1 = cur_block[3] + (cur_block[4] << 8);
348         sync2 = cur_block[5] + (cur_block[6] << 8);
349         bit0 = cur_block[7] + (cur_block[8] << 8);
350         bit1 = cur_block[9] + (cur_block[10] << 8);
351         pilot_length = cur_block[11] + (cur_block[12] << 8);
298352         bits_in_last_byte = cur_block[13];
299         pause_time = cur_block[14] + ( cur_block[15] << 8 );
300         data_size = cur_block[16] + ( cur_block[17] << 8 ) + ( cur_block[18] << 16 );
301         size += tzx_cas_handle_block( buffer, &cur_block[19], pause_time, data_size, pilot, pilot_length, sync1, sync2, bit0, bit1, bits_in_last_byte );
353         pause_time = cur_block[14] + (cur_block[15] << 8);
354         data_size = cur_block[16] + (cur_block[17] << 8) + (cur_block[18] << 16);
355         size += tzx_cas_handle_block(buffer, &cur_block[19], pause_time, data_size, pilot, pilot_length, sync1, sync2, bit0, bit1, bits_in_last_byte);
302356         current_block++;
303357         break;
304358      case 0x12:   /* Pure Tone */
305         pilot = cur_block[1] + ( cur_block[2] << 8 );
306         pilot_length = cur_block[3] + ( cur_block[4] << 8 );
307         size += tzx_cas_handle_block( buffer, cur_block, 0, 0, pilot, pilot_length, 0, 0, 0, 0, 0 );
359         pilot = cur_block[1] + (cur_block[2] << 8);
360         pilot_length = cur_block[3] + (cur_block[4] << 8);
361         size += tzx_cas_handle_block(buffer, cur_block, 0, 0, pilot, pilot_length, 0, 0, 0, 0, 0);
308362         current_block++;
309363         break;
310364      case 0x13:   /* Sequence of Pulses of Different Lengths */
311         for( data_size = 0; data_size < cur_block[1]; data_size++ ) {
312            pilot = cur_block[2 + 2*data_size] + ( cur_block[3 + 2*data_size] << 8 );
313            size += tzx_cas_handle_block( buffer, cur_block, 0, 0, pilot, 1, 0, 0, 0, 0, 0 );
365         for (data_size = 0; data_size < cur_block[1]; data_size++)
366         {
367            pilot = cur_block[2 + 2 * data_size] + (cur_block[3 + 2 * data_size] << 8);
368            size += tzx_cas_handle_block(buffer, cur_block, 0, 0, pilot, 1, 0, 0, 0, 0, 0);
314369         }
315370         current_block++;
316371         break;
317372      case 0x14:   /* Pure Data Block */
318         bit0 = cur_block[1] + ( cur_block[2] << 8 );
319         bit1 = cur_block[3] + ( cur_block[4] << 8 );
373         bit0 = cur_block[1] + (cur_block[2] << 8);
374         bit1 = cur_block[3] + (cur_block[4] << 8);
320375         bits_in_last_byte = cur_block[5];
321         pause_time = cur_block[6] + ( cur_block[7] << 8 );
322         data_size = cur_block[8] + ( cur_block[9] << 8 ) + ( cur_block[10] << 16 );
323         size += tzx_cas_handle_block( buffer, &cur_block[11], pause_time, data_size, 0, 0, 0, 0, bit0, bit1, bits_in_last_byte );
376         pause_time = cur_block[6] + (cur_block[7] << 8);
377         data_size = cur_block[8] + (cur_block[9] << 8) + (cur_block[10] << 16);
378         size += tzx_cas_handle_block(buffer, &cur_block[11], pause_time, data_size, 0, 0, 0, 0, bit0, bit1, bits_in_last_byte);
324379         current_block++;
325380         break;
326      case 0x15:   /* Direct Recording */
327      case 0x16:   /* C64 ROM Type Data Block */
328      case 0x17:   /* C64 Turbo Tape Data Block */
329         logerror( "Unsupported block type (%02x) encountered\n", block_type );
330         current_block++;
331         break;
332381      case 0x20:   /* Pause (Silence) or 'Stop the Tape' Command */
333         pause_time = cur_block[1] + ( cur_block[2] << 8 );
334         if ( pause_time == 0 ) {
335            /* pause = 0 is used to let an emulator automagically stop the tape
336               in MESS we do not do that, so we insert a 5 second pause.
337             */
382         pause_time = cur_block[1] + (cur_block[2] << 8);
383         if (pause_time == 0)
384         {
385            /* pause = 0 is used to let an emulator automagically stop the tape
386               in MESS we do not do that, so we insert a 5 second pause. */
338387            pause_time = 5000;
339388         }
340         size += tzx_cas_handle_block( buffer, cur_block, pause_time, 0, 0, 0, 0, 0, 0, 0, 0 );
389         size += tzx_cas_handle_block(buffer, cur_block, pause_time, 0, 0, 0, 0, 0, 0, 0, 0);
341390         current_block++;
342391         break;
392      case 0x16:   /* C64 ROM Type Data Block */      // Deprecated in TZX 1.20
393      case 0x17:   /* C64 Turbo Tape Data Block */      // Deprecated in TZX 1.20
394      case 0x34:   /* Emulation Info */            // Deprecated in TZX 1.20
395      case 0x40:   /* Snapshot Block */            // Deprecated in TZX 1.20
396         logerror("Deprecated block type (%02x) encountered.\n", block_type);
397         logerror("Please look for an updated .tzx file.\n");
398         current_block++;
399         break;
400      case 0x30:   /* Text Description */
401         ascii_block_common_log("Text Description Block", block_type);
402         for (data_size = 0; data_size < cur_block[1]; data_size++)
403            logerror("%c", cur_block[2 + data_size]);
404         logerror("\n");
405         current_block++;
406         break;
407      case 0x31:   /* Message Block */
408         ascii_block_common_log("Message Block", block_type);
409         logerror("Expected duration of the message display: %02x\n", cur_block[1]);
410         logerror("Message: \n");
411         for (data_size = 0; data_size < cur_block[2]; data_size++)
412         {
413            logerror("%c", cur_block[3 + data_size]);
414            if (cur_block[3 + data_size] == 0x0d)
415               logerror("\n");
416         }
417         logerror("\n");
418         current_block++;
419         break;
420      case 0x32:   /* Archive Info */
421         ascii_block_common_log("Archive Info Block", block_type);
422         total_size = cur_block[1] + (cur_block[2] << 8);
423         text_size = 0;
424         for (data_size = 0; data_size < cur_block[3]; data_size++)   // data_size = number of text blocks, in this case
425         {
426            if (cur_block[4 + text_size] < 0x09)
427               logerror("%s: \n", archive_ident[cur_block[4 + text_size]]);
428            else
429               logerror("Comment(s): \n");
430
431            for (i = 0; i < cur_block[4 + text_size + 1]; i++)
432            {
433               logerror("%c", cur_block[4 + text_size + 2 + i]);
434            }
435            text_size += 2 + i;
436         }
437         logerror("\n");
438         if (text_size != total_size)
439            logerror("Malformed Archive Info Block (Text length different from the declared one).\n Please verify your tape image.\n");
440         current_block++;
441         break;
442      case 0x33:   /* Hardware Type */
443         ascii_block_common_log("Hardware Type Block", block_type);
444         for (data_size = 0; data_size < cur_block[1]; data_size++)   // data_size = number of hardware blocks, in this case
445         {
446            logerror("Hardware Type %02x - Hardware ID %02x - ", cur_block[2 + data_size * 3], cur_block[2 + data_size * 3 + 1]);
447            logerror("%s \n ", hw_info[cur_block[2 + data_size * 3 + 2]]);
448         }
449         current_block++;
450         break;
451      case 0x35:   /* Custom Info Block */
452         ascii_block_common_log("Custom Info Block", block_type);
453         for (data_size = 0; data_size < 10; data_size++)
454         {
455            logerror("%c", cur_block[1 + data_size]);
456         }
457         logerror(":\n");
458         text_size = cur_block[11] + (cur_block[12] << 8) + (cur_block[13] << 16) + (cur_block[14] << 24);
459         for (data_size = 0; data_size < text_size; data_size++)
460            logerror("%c", cur_block[15 + data_size]);
461         logerror("\n");
462         current_block++;
463         break;
464      case 0x5A:   /* "Glue" Block */
465         logerror("Glue Block (type %02x) encountered.\n", block_type);
466         logerror("Please use a .tzx handling utility to split the merged tape files.\n");
467         current_block++;
468         break;
469      case 0x15:   /* Direct Recording */
470      case 0x18:   /* CSW Recording */
471      case 0x19:   /* Generalized Data Block */
343472      case 0x21:   /* Group Start */
344473      case 0x22:   /* Group End */
345474      case 0x23:   /* Jump To Block */
r5271r5272
349478      case 0x27:   /* Return From Sequence */
350479      case 0x28:   /* Select Block */
351480      case 0x2A:   /* Stop Tape if in 48K Mode */
352      case 0x30:   /* Text Description */
353      case 0x31:   /* Message Block */
354      case 0x32:   /* Archive Info */
355      case 0x33:   /* Hardware Type */
356      case 0x34:   /* Emulation Info */
357      case 0x35:   /* Custom Info Block */
358      case 0x40:   /* Snapshot Block */
359      case 0x5A:   /* Merge Block */
481      case 0x2B:   /* Set signal level */
360482      default:
361         logerror( "Unsupported block type (%02x) encountered\n", block_type );
483         logerror("Unsupported block type (%02x) encountered.\n", block_type);
362484         current_block++;
363485         break;
364486      }
r5271r5272
366488   return size;
367489}
368490
369static int tzx_cas_to_wav_size( const UINT8 *casdata, int caslen ) {
491static int tzx_cas_to_wav_size( const UINT8 *casdata, int caslen )
492{
370493   int size = 0;
371494
372495   /* Header size plus major and minor version number */
373   if ( caslen < 10 ) {
374      logerror( "tzx_cas_to_wav_size: cassette image too small\n" );
496   if (caslen < 10)
497   {
498      logerror("tzx_cas_to_wav_size: cassette image too small\n");
375499      goto cleanup;
376500   }
377501
378502   /* Check for correct header */
379   if ( memcmp( casdata, TZX_HEADER, sizeof(TZX_HEADER) ) ) {
380      logerror( "tzx_cas_to_wav_size: cassette image has incompatible header\n" );
503   if (memcmp(casdata, TZX_HEADER, sizeof(TZX_HEADER)))
504   {
505      logerror("tzx_cas_to_wav_size: cassette image has incompatible header\n");
381506      goto cleanup;
382507   }
383508
384509   /* Check major version number in header */
385   if ( casdata[0x08] > SUPPORTED_VERSION_MAJOR ) {
386      logerror( "tzx_cas_to_wav_size: unsupported version\n" );
510   if (casdata[0x08] > SUPPORTED_VERSION_MAJOR)
511   {
512      logerror("tzx_cas_to_wav_size: unsupported version\n");
387513      goto cleanup;
388514   }
389515
390   tzx_cas_get_blocks( casdata, caslen );
516   tzx_cas_get_blocks(casdata, caslen);
391517
392   logerror( "tzx_cas_to_wav_size: %d blocks found\n", block_count );
518   logerror("tzx_cas_to_wav_size: %d blocks found\n", block_count);
393519
394   if ( block_count == 0 ) {
395      logerror( "tzx_cas_to_wav_size: no blocks found!\n" );
520   if (block_count == 0)
521   {
522      logerror("tzx_cas_to_wav_size: no blocks found!\n");
396523      goto cleanup;
397524   }
398525
399   size = tzx_cas_do_work( NULL );
526   size = tzx_cas_do_work(NULL);
400527
401528   return size;
402529
r5271r5272
404531   return -1;
405532}
406533
407static int tzx_cas_fill_wave( INT16 *buffer, int length, UINT8 *bytes ) {
408   INT16   *p = buffer;
534static int tzx_cas_fill_wave( INT16 *buffer, int length, UINT8 *bytes )
535{
536   INT16 *p = buffer;
409537   int   size = 0;
410538   t_scale = 1.0;
411   size = tzx_cas_do_work( &p );
539   size = tzx_cas_do_work(&p);
412540   return size;
413541}
414542
415static int cdt_cas_fill_wave( INT16 *buffer, int length, UINT8 *bytes ) {
416   INT16   *p = buffer;
543static int cdt_cas_fill_wave( INT16 *buffer, int length, UINT8 *bytes )
544{
545   INT16 *p = buffer;
417546   int   size = 0;
418547   t_scale = (40 / 35);  /* scale to 4MHz */
419   size = tzx_cas_do_work( &p );
548   size = tzx_cas_do_work(&p);
420549   return size;
421550}
422551
423static int tap_cas_to_wav_size( const UINT8 *casdata, int caslen ) {
552static int tap_cas_to_wav_size( const UINT8 *casdata, int caslen )
553{
424554   int size = 0;
425555   const UINT8 *p = casdata;
426556
427   while( p < casdata + caslen ) {
428      int data_size = p[0] + ( p[1] << 8 );
429      int pilot_length = ( p[2] == 0x00 ) ? 8064 : 3220;   /* TZX specification */
430//      int pilot_length = ( p[2] == 0x00 ) ? 8063 : 3223;   /* worldofspectrum */
431      logerror( "tap_cas_to_wav_size: Handling TAP block containing 0x%X bytes", data_size );
557   while (p < casdata + caslen)
558   {
559      int data_size = p[0] + (p[1] << 8);
560      int pilot_length = (p[2] == 0x00) ? 8064 : 3220;   /* TZX specification */
561//      int pilot_length = (p[2] == 0x00) ? 8063 : 3223;   /* worldofspectrum */
562      logerror("tap_cas_to_wav_size: Handling TAP block containing 0x%X bytes", data_size);
432563      p += 2;
433      size += tzx_cas_handle_block( NULL, p, 1000, data_size, 2168, pilot_length, 667, 735, 855, 1710, 8 );
434      logerror( ", total size is now: %d\n", size );
564      size += tzx_cas_handle_block(NULL, p, 1000, data_size, 2168, pilot_length, 667, 735, 855, 1710, 8);
565      logerror(", total size is now: %d\n", size);
435566      p += data_size;
436567   }
437568   return size;
438569}
439570
440static int tap_cas_fill_wave( INT16 *buffer, int length, UINT8 *bytes ) {
571static int tap_cas_fill_wave( INT16 *buffer, int length, UINT8 *bytes )
572{
441573   INT16 *p = buffer;
442574   int size = 0;
443575
444   while( size < length ) {
445      int data_size = bytes[0] + ( bytes[1] << 8 );
446      int pilot_length = ( bytes[2] == 0x00 ) ? 8064 : 3220;   /* TZX specification */
447//      int pilot_length = ( bytes[2] == 0x00 ) ? 8063 : 3223;   /* worldofspectrum */
448      logerror( "tap_cas_fill_wave: Handling TAP block containing 0x%X bytes\n", data_size );
576   while (size < length)
577   {
578      int data_size = bytes[0] + (bytes[1] << 8);
579      int pilot_length = (bytes[2] == 0x00) ? 8064 : 3220;   /* TZX specification */
580//      int pilot_length = (bytes[2] == 0x00) ? 8063 : 3223;   /* worldofspectrum */
581      logerror("tap_cas_fill_wave: Handling TAP block containing 0x%X bytes\n", data_size);
449582      bytes += 2;
450      size += tzx_cas_handle_block( &p, bytes, 1000, data_size, 2168, pilot_length, 667, 735, 855, 1710, 8 );
583      size += tzx_cas_handle_block(&p, bytes, 1000, data_size, 2168, pilot_length, 667, 735, 855, 1710, 8);
451584      bytes += data_size;
452585   }
453586   return size;
454587}
455588
456static const struct CassetteLegacyWaveFiller tzx_legacy_fill_wave = {
589static const struct CassetteLegacyWaveFiller tzx_legacy_fill_wave =
590{
457591   tzx_cas_fill_wave,         /* fill_wave */
458592   -1,               /* chunk_size */
459593   0,               /* chunk_samples */
r5271r5272
463597   0               /* trailer_samples */
464598};
465599
466static const struct CassetteLegacyWaveFiller tap_legacy_fill_wave = {
600static const struct CassetteLegacyWaveFiller tap_legacy_fill_wave =
601{
467602   tap_cas_fill_wave,         /* fill_wave */
468603   -1,               /* chunk_size */
469604   0,               /* chunk_samples */
r5271r5272
473608   0               /* trailer_samples */
474609};
475610
476static const struct CassetteLegacyWaveFiller cdt_legacy_fill_wave = {
611static const struct CassetteLegacyWaveFiller cdt_legacy_fill_wave =
612{
477613   cdt_cas_fill_wave,         /* fill_wave */
478614   -1,               /* chunk_size */
479615   0,               /* chunk_samples */
r5271r5272
483619   0               /* trailer_samples */
484620};
485621
486static casserr_t tzx_cassette_identify( cassette_image *cassette, struct CassetteOptions *opts ) {
487   return cassette_legacy_identify( cassette, opts, &tzx_legacy_fill_wave );
622static casserr_t tzx_cassette_identify( cassette_image *cassette, struct CassetteOptions *opts )
623{
624   return cassette_legacy_identify(cassette, opts, &tzx_legacy_fill_wave);
488625}
489626
490static casserr_t tap_cassette_identify( cassette_image *cassette, struct CassetteOptions *opts ) {
491   return cassette_legacy_identify( cassette, opts, &tap_legacy_fill_wave );
627static casserr_t tap_cassette_identify( cassette_image *cassette, struct CassetteOptions *opts )
628{
629   return cassette_legacy_identify(cassette, opts, &tap_legacy_fill_wave);
492630}
493631
494static casserr_t cdt_cassette_identify( cassette_image *cassette, struct CassetteOptions *opts ) {
495   return cassette_legacy_identify( cassette, opts, &cdt_legacy_fill_wave );
632static casserr_t cdt_cassette_identify( cassette_image *cassette, struct CassetteOptions *opts )
633{
634   return cassette_legacy_identify(cassette, opts, &cdt_legacy_fill_wave);
496635}
497636
498static casserr_t tzx_cassette_load( cassette_image *cassette ) {
499   return cassette_legacy_construct( cassette, &tzx_legacy_fill_wave );
637static casserr_t tzx_cassette_load( cassette_image *cassette )
638{
639   return cassette_legacy_construct(cassette, &tzx_legacy_fill_wave);
500640}
501641
502static casserr_t tap_cassette_load( cassette_image *cassette ) {
503   return cassette_legacy_construct( cassette, &tap_legacy_fill_wave );
642static casserr_t tap_cassette_load( cassette_image *cassette )
643{
644   return cassette_legacy_construct(cassette, &tap_legacy_fill_wave);
504645}
505646
506static casserr_t cdt_cassette_load( cassette_image *cassette ) {
507   return cassette_legacy_construct( cassette, &cdt_legacy_fill_wave );
647static casserr_t cdt_cassette_load( cassette_image *cassette )
648{
649   return cassette_legacy_construct(cassette, &cdt_legacy_fill_wave);
508650}
509651
510static const struct CassetteFormat tzx_cassette_format = {
652static const struct CassetteFormat tzx_cassette_format =
653{
511654   "tzx",
512655   tzx_cassette_identify,
513656   tzx_cassette_load,
514657   NULL
515658};
516659
517static const struct CassetteFormat tap_cassette_format = {
660static const struct CassetteFormat tap_cassette_format =
661{
518662   "tap",
519663   tap_cassette_identify,
520664   tap_cassette_load,
521665   NULL
522666};
523667
524static const struct CassetteFormat cdt_cassette_format = {
668static const struct CassetteFormat cdt_cassette_format =
669{
525670   "cdt",
526671   cdt_cassette_identify,
527672   cdt_cassette_load,
docs/messnew.txt
r5271r5272
8787- [SEGA CD] Rearranged sets and added new and better dumps. [Justin Kerk, TmEE,
8888  segaloco]
8989
90- [SPECTRUM] Added logging support for Text/Message/Archive/Hardware/Custom
91  Blocks in TZX files. Info are not (and won't be) used directly by the
92  emulator, but can be of use to improve bug reports. Also, updated TZX
93  support to v1.20 by deprecating some block types. [Fabio Priuli]
94
9095- [TI85] TI-83 now works [Xander]
9196
9297- [TI85] Fixed TI-82/TI-83 on/off and NVRAM, added a DSW to TI-83 for the

Previous 15994 Revisions Next


© 1998-2018 The MESS Team