src/mess/formats/tzx_cas.c
| r1435 | r1436 | |
| 70 | 70 | static INT16 wave_data; |
| 71 | 71 | static int block_count; |
| 72 | 72 | static UINT8** blocks; |
| 73 | static float t_scale = 1; /* for scaling T-states to the 4MHz CPC */ |
| 73 | 74 | |
| 74 | 75 | static void toggle_wave_data(void) { |
| 75 | 76 | if ( wave_data == WAVE_LOW ) { |
| r1435 | r1436 | |
| 184 | 185 | } |
| 185 | 186 | |
| 186 | 187 | INLINE int millisec_to_samplecount( int millisec ) { |
| 187 | | return (int) ( ( millisec * ( (double)TZX_WAV_FREQUENCY / 3500000 ) ) / 1000.0 ); |
| 188 | return (int) ( millisec * ( (double)TZX_WAV_FREQUENCY / 1000.0 ) ); |
| 188 | 189 | } |
| 189 | 190 | |
| 190 | 191 | INLINE int tcycles_to_samplecount( int tcycles ) { |
| 191 | | return (int) ( 0.5 + ( ( (double)TZX_WAV_FREQUENCY / 3500000 ) * (double)tcycles ) ); |
| 192 | return (int) ( ( 0.5 + ( ( (double)TZX_WAV_FREQUENCY / 3500000 ) * (double)tcycles ) ) * t_scale ); |
| 192 | 193 | } |
| 193 | 194 | |
| 194 | 195 | static void tzx_output_wave( INT16 **buffer, int length ) { |
| r1435 | r1436 | |
| 256 | 257 | tzx_output_wave( buffer, rest_pause_samples ); |
| 257 | 258 | size += rest_pause_samples; |
| 258 | 259 | } |
| 260 | else /* default value for pause is 1000ms */ |
| 261 | { |
| 262 | int start_pause_samples = millisec_to_samplecount( 1 ); |
| 263 | int rest_pause_samples = millisec_to_samplecount( 1000 - 1 ); |
| 264 | |
| 265 | tzx_output_wave( buffer, start_pause_samples ); |
| 266 | size += start_pause_samples; |
| 267 | wave_data = WAVE_LOW; |
| 268 | tzx_output_wave( buffer, rest_pause_samples ); |
| 269 | size += rest_pause_samples; |
| 270 | } |
| 259 | 271 | return size; |
| 260 | 272 | } |
| 261 | 273 | |
| r1435 | r1436 | |
| 404 | 416 | static int tzx_cas_fill_wave( INT16 *buffer, int length, UINT8 *bytes ) { |
| 405 | 417 | INT16 *p = buffer; |
| 406 | 418 | int size = 0; |
| 419 | t_scale = 1.0; |
| 407 | 420 | size = tzx_cas_do_work( &p ); |
| 408 | 421 | return size; |
| 409 | 422 | } |
| 410 | 423 | |
| 424 | static int cdt_cas_fill_wave( INT16 *buffer, int length, UINT8 *bytes ) { |
| 425 | INT16 *p = buffer; |
| 426 | int size = 0; |
| 427 | t_scale = (40 / 35); /* scale to 4MHz */ |
| 428 | size = tzx_cas_do_work( &p ); |
| 429 | return size; |
| 430 | } |
| 431 | |
| 411 | 432 | static int tap_cas_to_wav_size( const UINT8 *casdata, int caslen ) { |
| 412 | 433 | int size = 0; |
| 413 | 434 | const UINT8 *p = casdata; |
| r1435 | r1436 | |
| 461 | 482 | 0 /* trailer_samples */ |
| 462 | 483 | }; |
| 463 | 484 | |
| 485 | static struct CassetteLegacyWaveFiller cdt_legacy_fill_wave = { |
| 486 | cdt_cas_fill_wave, /* fill_wave */ |
| 487 | -1, /* chunk_size */ |
| 488 | 0, /* chunk_samples */ |
| 489 | tzx_cas_to_wav_size, /* chunk_sample_calc */ |
| 490 | TZX_WAV_FREQUENCY, /* sample_frequency */ |
| 491 | 0, /* header_samples */ |
| 492 | 0 /* trailer_samples */ |
| 493 | }; |
| 494 | |
| 464 | 495 | static casserr_t tzx_cassette_identify( cassette_image *cassette, struct CassetteOptions *opts ) { |
| 465 | 496 | return cassette_legacy_identify( cassette, opts, &tzx_legacy_fill_wave ); |
| 466 | 497 | } |
| r1435 | r1436 | |
| 469 | 500 | return cassette_legacy_identify( cassette, opts, &tap_legacy_fill_wave ); |
| 470 | 501 | } |
| 471 | 502 | |
| 503 | static casserr_t cdt_cassette_identify( cassette_image *cassette, struct CassetteOptions *opts ) { |
| 504 | return cassette_legacy_identify( cassette, opts, &cdt_legacy_fill_wave ); |
| 505 | } |
| 506 | |
| 472 | 507 | static casserr_t tzx_cassette_load( cassette_image *cassette ) { |
| 473 | 508 | return cassette_legacy_construct( cassette, &tzx_legacy_fill_wave ); |
| 474 | 509 | } |
| r1435 | r1436 | |
| 477 | 512 | return cassette_legacy_construct( cassette, &tap_legacy_fill_wave ); |
| 478 | 513 | } |
| 479 | 514 | |
| 515 | static casserr_t cdt_cassette_load( cassette_image *cassette ) { |
| 516 | return cassette_legacy_construct( cassette, &cdt_legacy_fill_wave ); |
| 517 | } |
| 518 | |
| 480 | 519 | static struct CassetteFormat tzx_cassette_format = { |
| 481 | 520 | "tzx", |
| 482 | 521 | tzx_cassette_identify, |
| r1435 | r1436 | |
| 491 | 530 | NULL |
| 492 | 531 | }; |
| 493 | 532 | |
| 533 | struct CassetteFormat cdt_cassette_format = { |
| 534 | "cdt", |
| 535 | cdt_cassette_identify, |
| 536 | cdt_cassette_load, |
| 537 | NULL |
| 538 | }; |
| 539 | |
| 494 | 540 | CASSETTE_FORMATLIST_START(tzx_cassette_formats) |
| 495 | 541 | CASSETTE_FORMAT(tzx_cassette_format) |
| 496 | 542 | CASSETTE_FORMAT(tap_cassette_format) |
| 497 | 543 | CASSETTE_FORMATLIST_END |
| 498 | 544 | |
| 545 | CASSETTE_FORMATLIST_START(cdt_cassette_formats) |
| 546 | CASSETTE_FORMAT(cdt_cassette_format) |
| 547 | CASSETTE_FORMATLIST_END |
| 548 | |