trunk/src/lib/formats/tzx_cas.c
r249947 | r249948 | |
335 | 335 | } |
336 | 336 | |
337 | 337 | |
338 | | static int tzx_handle_symbol(INT16 **buffer, const UINT8 *symtable, UINT8 symbol, int maxp) |
| 338 | INLINE int tzx_handle_symbol(INT16 **buffer, const UINT8 *symtable, UINT8 symbol, int maxp) |
339 | 339 | { |
340 | 340 | int size = 0; |
341 | 341 | const UINT8 *cursymb = symtable + (2 * maxp + 1)*symbol; |
342 | 342 | |
343 | 343 | UINT8 starttype = cursymb[0]; |
344 | 344 | |
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); |
346 | 346 | |
347 | 347 | switch (starttype) |
348 | 348 | { |
r249947 | r249948 | |
376 | 376 | // shorter lists can be terminated with a pulse_length of 0 |
377 | 377 | if (pulse_length != 0) |
378 | 378 | { |
| 379 | |
| 380 | |
379 | 381 | int samples = tcycles_to_samplecount(pulse_length); |
380 | 382 | tzx_output_wave(buffer, samples); |
381 | 383 | size += samples; |
r249947 | r249948 | |
384 | 386 | } |
385 | 387 | else |
386 | 388 | { |
387 | | toggle_wave_data(); // ? |
| 389 | toggle_wave_data(); |
388 | 390 | i = maxp; |
389 | 391 | continue; |
390 | 392 | } |
391 | 393 | } |
392 | 394 | |
| 395 | //toggle_wave_data(); |
393 | 396 | |
394 | 397 | return size; |
395 | 398 | } |
396 | 399 | |
| 400 | INLINE 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 | |
397 | 422 | static 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 ) |
398 | 423 | { |
399 | 424 | int size = 0; |
r249947 | r249948 | |
415 | 440 | for (int j = 0; j < repetitions; j++) |
416 | 441 | { |
417 | 442 | size += tzx_handle_symbol(buffer, symtable, symbol, npp); |
| 443 | // toggle_wave_data(); |
418 | 444 | } |
419 | 445 | |
420 | 446 | |
r249947 | r249948 | |
430 | 456 | |
431 | 457 | if (totd > 0) |
432 | 458 | { |
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); |
434 | 460 | |
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; |
437 | 463 | |
438 | 464 | int NB = ceil(compute_log2(asd)); // number of bits needed to represent each symbol |
439 | 465 | 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 | } |
440 | 483 | } |
441 | 484 | else |
442 | 485 | { |