Previous 199869 Revisions Next

r41436 Wednesday 28th October, 2015 at 19:35:16 UTC by David Haywood
not yet correct (nw)
[src/lib/formats]tzx_cas.c

trunk/src/lib/formats/tzx_cas.c
r249947r249948
335335}
336336
337337
338static int tzx_handle_symbol(INT16 **buffer, const UINT8 *symtable, UINT8 symbol, int maxp)
338INLINE int tzx_handle_symbol(INT16 **buffer, const UINT8 *symtable, UINT8 symbol, int maxp)
339339{
340340   int size = 0;
341341   const UINT8 *cursymb = symtable + (2 * maxp + 1)*symbol;
342342
343343   UINT8 starttype = cursymb[0];
344344
345   printf("start polarity %01x (max number of symbols is %d)\n", starttype, maxp);
345//   printf("start polarity %01x (max number of symbols is %d)\n", starttype, maxp);
346346
347347   switch (starttype)
348348   {
r249947r249948
376376      // shorter lists can be terminated with a pulse_length of 0
377377      if (pulse_length != 0)
378378      {
379         
380
379381         int samples = tcycles_to_samplecount(pulse_length);
380382         tzx_output_wave(buffer, samples);
381383         size += samples;
r249947r249948
384386      }
385387      else
386388      {
387         toggle_wave_data(); // ?
389         toggle_wave_data();
388390         i = maxp;
389391         continue;
390392      }
391393   }
392394
395   //toggle_wave_data();
393396
394397   return size;
395398}
396399
400INLINE int stream_get_bit(const UINT8 *bytes, UINT8 &stream_bit, UINT32 &stream_byte)
401{
402   // get bit here
403   UINT8 retbit = 0;
404
405   UINT8 byte = bytes[stream_byte];
406   byte = byte << stream_bit;
407
408   if (byte & 0x80) retbit = 1;
409
410
411   stream_bit++;
412
413   if (stream_bit == 8)
414   {
415      stream_bit = 0;
416      stream_byte++;
417   }
418
419   return retbit;
420}
421
397422static int tzx_handle_generalized(INT16 **buffer, const UINT8 *bytes, int pause, int data_size, UINT32 totp, int npp, int asp, UINT32 totd, int npd, int asd )
398423{
399424   int size = 0;
r249947r249948
415440         for (int j = 0; j < repetitions; j++)
416441         {
417442            size += tzx_handle_symbol(buffer, symtable, symbol, npp);
443         //   toggle_wave_data();
418444         }
419445
420446
r249947r249948
430456
431457   if (totd > 0)
432458   {
433      printf("data block table %04x\n", totd);
459      printf("data block table %04x (has %0d symbols, max symbol length is %d)\n", totd, asd, npd);
434460
435   //   const UINT8 *symtable = bytes;
436   //   const UINT8 *table2 = bytes + (2 * npd + 1)*asd;
461      const UINT8 *symtable = bytes;
462      const UINT8 *table2 = bytes + (2 * npd + 1)*asd;
437463
438464      int NB = ceil(compute_log2(asd)); // number of bits needed to represent each symbol
439465      printf("NB is %d\n", NB);
466
467      UINT8 stream_bit = 0;
468      UINT32 stream_byte = 0;
469
470      for (int i = 0; i < totd; i++)
471      {
472         UINT8 symbol = 0;
473         
474         for (int j = 0; j < NB; j++)
475         {
476            symbol |= stream_get_bit(table2, stream_bit, stream_byte) << j;
477         }
478
479         size += tzx_handle_symbol(buffer, symtable, symbol, npd);
480
481         //toggle_wave_data();
482      }
440483   }
441484   else
442485   {


Previous 199869 Revisions Next


© 1997-2024 The MAME Team