src/lib/formats/uef_cas.c
| r11471 | r11472 | |
| 126 | 126 | |
| 127 | 127 | err = inflateInit2( &d_stream, -MAX_WBITS ); |
| 128 | 128 | if ( err != Z_OK ) { |
| 129 | | logerror( "inflateInit2 error: %d\n", err ); |
| 129 | LOG_FORMATS( "inflateInit2 error: %d\n", err ); |
| 130 | 130 | goto cleanup; |
| 131 | 131 | } |
| 132 | 132 | err = inflate( &d_stream, Z_NO_FLUSH ); |
| 133 | 133 | if ( err != Z_STREAM_END && err != Z_OK ) { |
| 134 | | logerror( "inflate error: %d\n", err ); |
| 134 | LOG_FORMATS( "inflate error: %d\n", err ); |
| 135 | 135 | goto cleanup; |
| 136 | 136 | } |
| 137 | 137 | err = inflateEnd( &d_stream ); |
| 138 | 138 | if ( err != Z_OK ) { |
| 139 | | logerror( "inflateEnd error: %d\n", err ); |
| 139 | LOG_FORMATS( "inflateEnd error: %d\n", err ); |
| 140 | 140 | goto cleanup; |
| 141 | 141 | } |
| 142 | 142 | caslen = inflate_size; |
| r11471 | r11472 | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | if ( caslen < 18 ) { |
| 147 | | logerror( "uef_cas_to_wav_size: cassette image too small\n" ); |
| 147 | LOG_FORMATS( "uef_cas_to_wav_size: cassette image too small\n" ); |
| 148 | 148 | goto cleanup; |
| 149 | 149 | } |
| 150 | 150 | if ( memcmp( casdata, UEF_HEADER, sizeof(UEF_HEADER) ) ) { |
| 151 | | logerror( "uef_cas_to_wav_size: cassette image has incompatible header\n" ); |
| 151 | LOG_FORMATS( "uef_cas_to_wav_size: cassette image has incompatible header\n" ); |
| 152 | 152 | goto cleanup; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | | logerror( "UEF: Determinig tape size\n" ); |
| 155 | LOG_FORMATS( "UEF: Determinig tape size\n" ); |
| 156 | 156 | size = 0; |
| 157 | 157 | pos = sizeof(UEF_HEADER) + 2; |
| 158 | 158 | while( pos < caslen ) { |
| r11471 | r11472 | |
| 167 | 167 | break; |
| 168 | 168 | case 0x0101: /* multiplexed data block */ |
| 169 | 169 | case 0x0103: |
| 170 | | logerror( "Unsupported chunk type: %04x\n", chunk_type ); |
| 170 | LOG_FORMATS( "Unsupported chunk type: %04x\n", chunk_type ); |
| 171 | 171 | break; |
| 172 | 172 | case 0x0102: /* explicit tape data block */ |
| 173 | 173 | size += ( ( chunk_length * 10 ) - casdata[pos] ) * 4; |
| 174 | 174 | break; |
| 175 | 175 | case 0x0104: |
| 176 | | logerror( "Unsupported chunk type: %04x\n", chunk_type ); |
| 176 | LOG_FORMATS( "Unsupported chunk type: %04x\n", chunk_type ); |
| 177 | 177 | break; |
| 178 | 178 | case 0x0110: |
| 179 | 179 | baud_length = ( casdata[pos+1] << 8 ) | casdata[pos]; |
| 180 | 180 | size += baud_length * 2; |
| 181 | 181 | break; |
| 182 | 182 | case 0x0111: |
| 183 | | logerror( "Unsupported chunk type: %04x\n", chunk_type ); |
| 183 | LOG_FORMATS( "Unsupported chunk type: %04x\n", chunk_type ); |
| 184 | 184 | break; |
| 185 | 185 | case 0x0112: |
| 186 | 186 | baud_length = ( casdata[pos+1] << 8 ) | casdata[pos]; |
| r11471 | r11472 | |
| 193 | 193 | case 0x0114: |
| 194 | 194 | case 0x0115: |
| 195 | 195 | case 0x0120: |
| 196 | | logerror( "Unsupported chunk type: %04x\n", chunk_type ); |
| 196 | LOG_FORMATS( "Unsupported chunk type: %04x\n", chunk_type ); |
| 197 | 197 | break; |
| 198 | 198 | } |
| 199 | 199 | pos += chunk_length; |
| r11471 | r11472 | |
| 259 | 259 | break; |
| 260 | 260 | case 0x0101: /* multiplexed data block */ |
| 261 | 261 | case 0x0103: |
| 262 | | logerror( "Unsupported chunk type: %04x\n", chunk_type ); |
| 262 | LOG_FORMATS( "Unsupported chunk type: %04x\n", chunk_type ); |
| 263 | 263 | break; |
| 264 | 264 | case 0x0102: /* explicit tape data block */ |
| 265 | 265 | j = ( chunk_length * 10 ) - bytes[pos]; |
src/lib/formats/tzx_cas.c
| r11471 | r11472 | |
| 222 | 222 | int size = 0; |
| 223 | 223 | |
| 224 | 224 | /* Uncomment this to include into error.log a fully detailed analysis of each block */ |
| 225 | | // 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); |
| 225 | // LOG_FORMATS("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); |
| 226 | 226 | |
| 227 | 227 | /* PILOT */ |
| 228 | 228 | for ( ; pilot_length > 0; pilot_length--) |
| r11471 | r11472 | |
| 279 | 279 | |
| 280 | 280 | static void ascii_block_common_log( const char *block_type_string, UINT8 block_type ) |
| 281 | 281 | { |
| 282 | | logerror("%s (type %02x) encountered.\n", block_type_string, block_type); |
| 283 | | logerror("This block contains info on the .tzx file you are loading.\n"); |
| 284 | | logerror("Please include the following info in your bug reports, if the image has issue in M.E.S.S.\n"); |
| 282 | LOG_FORMATS("%s (type %02x) encountered.\n", block_type_string, block_type); |
| 283 | LOG_FORMATS("This block contains info on the .tzx file you are loading.\n"); |
| 284 | LOG_FORMATS("Please include the following info in your bug reports, if the image has issue in M.E.S.S.\n"); |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | static const char *const archive_ident[] = |
| r11471 | r11472 | |
| 324 | 324 | UINT8 block_type = cur_block[0]; |
| 325 | 325 | |
| 326 | 326 | /* Uncomment this to include into error.log a list of the types each block */ |
| 327 | | // logerror("tzx_cas_fill_wave: block %d, block_type %02x\n", current_block, block_type); |
| 327 | // LOG_FORMATS("tzx_cas_fill_wave: block %d, block_type %02x\n", current_block, block_type); |
| 328 | 328 | |
| 329 | 329 | switch (block_type) |
| 330 | 330 | { |
| r11471 | r11472 | |
| 386 | 386 | case 0x17: /* C64 Turbo Tape Data Block */ // Deprecated in TZX 1.20 |
| 387 | 387 | case 0x34: /* Emulation Info */ // Deprecated in TZX 1.20 |
| 388 | 388 | case 0x40: /* Snapshot Block */ // Deprecated in TZX 1.20 |
| 389 | | logerror("Deprecated block type (%02x) encountered.\n", block_type); |
| 390 | | logerror("Please look for an updated .tzx file.\n"); |
| 389 | LOG_FORMATS("Deprecated block type (%02x) encountered.\n", block_type); |
| 390 | LOG_FORMATS("Please look for an updated .tzx file.\n"); |
| 391 | 391 | current_block++; |
| 392 | 392 | break; |
| 393 | 393 | case 0x30: /* Text Description */ |
| 394 | 394 | ascii_block_common_log("Text Description Block", block_type); |
| 395 | 395 | for (data_size = 0; data_size < cur_block[1]; data_size++) |
| 396 | | logerror("%c", cur_block[2 + data_size]); |
| 397 | | logerror("\n"); |
| 396 | LOG_FORMATS("%c", cur_block[2 + data_size]); |
| 397 | LOG_FORMATS("\n"); |
| 398 | 398 | current_block++; |
| 399 | 399 | break; |
| 400 | 400 | case 0x31: /* Message Block */ |
| 401 | 401 | ascii_block_common_log("Message Block", block_type); |
| 402 | | logerror("Expected duration of the message display: %02x\n", cur_block[1]); |
| 403 | | logerror("Message: \n"); |
| 402 | LOG_FORMATS("Expected duration of the message display: %02x\n", cur_block[1]); |
| 403 | LOG_FORMATS("Message: \n"); |
| 404 | 404 | for (data_size = 0; data_size < cur_block[2]; data_size++) |
| 405 | 405 | { |
| 406 | | logerror("%c", cur_block[3 + data_size]); |
| 406 | LOG_FORMATS("%c", cur_block[3 + data_size]); |
| 407 | 407 | if (cur_block[3 + data_size] == 0x0d) |
| 408 | | logerror("\n"); |
| 408 | LOG_FORMATS("\n"); |
| 409 | 409 | } |
| 410 | | logerror("\n"); |
| 410 | LOG_FORMATS("\n"); |
| 411 | 411 | current_block++; |
| 412 | 412 | break; |
| 413 | 413 | case 0x32: /* Archive Info */ |
| r11471 | r11472 | |
| 417 | 417 | for (data_size = 0; data_size < cur_block[3]; data_size++) // data_size = number of text blocks, in this case |
| 418 | 418 | { |
| 419 | 419 | if (cur_block[4 + text_size] < 0x09) { |
| 420 | | logerror("%s: \n", archive_ident[cur_block[4 + text_size]]); |
| 420 | LOG_FORMATS("%s: \n", archive_ident[cur_block[4 + text_size]]); |
| 421 | 421 | } |
| 422 | 422 | else { |
| 423 | | logerror("Comment(s): \n"); |
| 423 | LOG_FORMATS("Comment(s): \n"); |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | for (i = 0; i < cur_block[4 + text_size + 1]; i++) |
| 427 | 427 | { |
| 428 | | logerror("%c", cur_block[4 + text_size + 2 + i]); |
| 428 | LOG_FORMATS("%c", cur_block[4 + text_size + 2 + i]); |
| 429 | 429 | } |
| 430 | 430 | text_size += 2 + i; |
| 431 | 431 | } |
| 432 | | logerror("\n"); |
| 432 | LOG_FORMATS("\n"); |
| 433 | 433 | if (text_size != total_size) |
| 434 | | logerror("Malformed Archive Info Block (Text length different from the declared one).\n Please verify your tape image.\n"); |
| 434 | LOG_FORMATS("Malformed Archive Info Block (Text length different from the declared one).\n Please verify your tape image.\n"); |
| 435 | 435 | current_block++; |
| 436 | 436 | break; |
| 437 | 437 | case 0x33: /* Hardware Type */ |
| 438 | 438 | ascii_block_common_log("Hardware Type Block", block_type); |
| 439 | 439 | for (data_size = 0; data_size < cur_block[1]; data_size++) // data_size = number of hardware blocks, in this case |
| 440 | 440 | { |
| 441 | | logerror("Hardware Type %02x - Hardware ID %02x - ", cur_block[2 + data_size * 3], cur_block[2 + data_size * 3 + 1]); |
| 442 | | logerror("%s \n ", hw_info[cur_block[2 + data_size * 3 + 2]]); |
| 441 | LOG_FORMATS("Hardware Type %02x - Hardware ID %02x - ", cur_block[2 + data_size * 3], cur_block[2 + data_size * 3 + 1]); |
| 442 | LOG_FORMATS("%s \n ", hw_info[cur_block[2 + data_size * 3 + 2]]); |
| 443 | 443 | } |
| 444 | 444 | current_block++; |
| 445 | 445 | break; |
| r11471 | r11472 | |
| 447 | 447 | ascii_block_common_log("Custom Info Block", block_type); |
| 448 | 448 | for (data_size = 0; data_size < 10; data_size++) |
| 449 | 449 | { |
| 450 | | logerror("%c", cur_block[1 + data_size]); |
| 450 | LOG_FORMATS("%c", cur_block[1 + data_size]); |
| 451 | 451 | } |
| 452 | | logerror(":\n"); |
| 452 | LOG_FORMATS(":\n"); |
| 453 | 453 | text_size = cur_block[11] + (cur_block[12] << 8) + (cur_block[13] << 16) + (cur_block[14] << 24); |
| 454 | 454 | for (data_size = 0; data_size < text_size; data_size++) |
| 455 | | logerror("%c", cur_block[15 + data_size]); |
| 456 | | logerror("\n"); |
| 455 | LOG_FORMATS("%c", cur_block[15 + data_size]); |
| 456 | LOG_FORMATS("\n"); |
| 457 | 457 | current_block++; |
| 458 | 458 | break; |
| 459 | 459 | case 0x5A: /* "Glue" Block */ |
| 460 | | logerror("Glue Block (type %02x) encountered.\n", block_type); |
| 461 | | logerror("Please use a .tzx handling utility to split the merged tape files.\n"); |
| 460 | LOG_FORMATS("Glue Block (type %02x) encountered.\n", block_type); |
| 461 | LOG_FORMATS("Please use a .tzx handling utility to split the merged tape files.\n"); |
| 462 | 462 | current_block++; |
| 463 | 463 | break; |
| 464 | 464 | case 0x15: /* Direct Recording */ |
| r11471 | r11472 | |
| 475 | 475 | case 0x2A: /* Stop Tape if in 48K Mode */ |
| 476 | 476 | case 0x2B: /* Set signal level */ |
| 477 | 477 | default: |
| 478 | | logerror("Unsupported block type (%02x) encountered.\n", block_type); |
| 478 | LOG_FORMATS("Unsupported block type (%02x) encountered.\n", block_type); |
| 479 | 479 | current_block++; |
| 480 | 480 | break; |
| 481 | 481 | } |
| r11471 | r11472 | |
| 490 | 490 | /* Header size plus major and minor version number */ |
| 491 | 491 | if (caslen < 10) |
| 492 | 492 | { |
| 493 | | logerror("tzx_cas_to_wav_size: cassette image too small\n"); |
| 493 | LOG_FORMATS("tzx_cas_to_wav_size: cassette image too small\n"); |
| 494 | 494 | goto cleanup; |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /* Check for correct header */ |
| 498 | 498 | if (memcmp(casdata, TZX_HEADER, sizeof(TZX_HEADER))) |
| 499 | 499 | { |
| 500 | | logerror("tzx_cas_to_wav_size: cassette image has incompatible header\n"); |
| 500 | LOG_FORMATS("tzx_cas_to_wav_size: cassette image has incompatible header\n"); |
| 501 | 501 | goto cleanup; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /* Check major version number in header */ |
| 505 | 505 | if (casdata[0x08] > SUPPORTED_VERSION_MAJOR) |
| 506 | 506 | { |
| 507 | | logerror("tzx_cas_to_wav_size: unsupported version\n"); |
| 507 | LOG_FORMATS("tzx_cas_to_wav_size: unsupported version\n"); |
| 508 | 508 | goto cleanup; |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | tzx_cas_get_blocks(casdata, caslen); |
| 512 | 512 | |
| 513 | | logerror("tzx_cas_to_wav_size: %d blocks found\n", block_count); |
| 513 | LOG_FORMATS("tzx_cas_to_wav_size: %d blocks found\n", block_count); |
| 514 | 514 | |
| 515 | 515 | if (block_count == 0) |
| 516 | 516 | { |
| 517 | | logerror("tzx_cas_to_wav_size: no blocks found!\n"); |
| 517 | LOG_FORMATS("tzx_cas_to_wav_size: no blocks found!\n"); |
| 518 | 518 | goto cleanup; |
| 519 | 519 | } |
| 520 | 520 | |
| r11471 | r11472 | |
| 554 | 554 | int data_size = p[0] + (p[1] << 8); |
| 555 | 555 | int pilot_length = (p[2] == 0x00) ? 8064 : 3220; /* TZX specification */ |
| 556 | 556 | // int pilot_length = (p[2] == 0x00) ? 8063 : 3223; /* worldofspectrum */ |
| 557 | | logerror("tap_cas_to_wav_size: Handling TAP block containing 0x%X bytes", data_size); |
| 557 | LOG_FORMATS("tap_cas_to_wav_size: Handling TAP block containing 0x%X bytes", data_size); |
| 558 | 558 | p += 2; |
| 559 | 559 | size += tzx_cas_handle_block(NULL, p, 1000, data_size, 2168, pilot_length, 667, 735, 855, 1710, 8); |
| 560 | | logerror(", total size is now: %d\n", size); |
| 560 | LOG_FORMATS(", total size is now: %d\n", size); |
| 561 | 561 | p += data_size; |
| 562 | 562 | } |
| 563 | 563 | return size; |
| r11471 | r11472 | |
| 573 | 573 | int data_size = bytes[0] + (bytes[1] << 8); |
| 574 | 574 | int pilot_length = (bytes[2] == 0x00) ? 8064 : 3220; /* TZX specification */ |
| 575 | 575 | // int pilot_length = (bytes[2] == 0x00) ? 8063 : 3223; /* worldofspectrum */ |
| 576 | | logerror("tap_cas_fill_wave: Handling TAP block containing 0x%X bytes\n", data_size); |
| 576 | LOG_FORMATS("tap_cas_fill_wave: Handling TAP block containing 0x%X bytes\n", data_size); |
| 577 | 577 | bytes += 2; |
| 578 | 578 | size += tzx_cas_handle_block(&p, bytes, 1000, data_size, 2168, pilot_length, 667, 735, 855, 1710, 8); |
| 579 | 579 | bytes += data_size; |
src/lib/formats/csw_cas.c
| r11471 | r11472 | |
| 57 | 57 | int bsize=0; |
| 58 | 58 | |
| 59 | 59 | if ( memcmp( casdata, CSW_HEADER, sizeof(CSW_HEADER) ) ) { |
| 60 | | logerror( "csw_cas_to_wav_size: cassette image has incompatible header\n" ); |
| 60 | LOG_FORMATS( "csw_cas_to_wav_size: cassette image has incompatible header\n" ); |
| 61 | 61 | goto cleanup; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | if (casdata[0x16]!=0x1a) { |
| 65 | | logerror( "csw_cas_to_wav_size: Terminator Code Not Found\n" ); |
| 65 | LOG_FORMATS( "csw_cas_to_wav_size: Terminator Code Not Found\n" ); |
| 66 | 66 | goto cleanup; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | MajorRevision=casdata[0x17]; |
| 70 | 70 | MinorRevision=casdata[0x18]; |
| 71 | 71 | |
| 72 | | logerror("Version %d : %d\n",MajorRevision,MinorRevision); |
| 72 | LOG_FORMATS("Version %d : %d\n",MajorRevision,MinorRevision); |
| 73 | 73 | |
| 74 | 74 | if (casdata[0x17]!=2){ |
| 75 | | logerror( "csw_cas_to_wav_size: Unsuported Major Version\n" ); |
| 75 | LOG_FORMATS( "csw_cas_to_wav_size: Unsuported Major Version\n" ); |
| 76 | 76 | goto cleanup; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | SampleRate=get_leuint32(casdata+0x19); |
| 80 | | logerror("Sample rate %d\n",SampleRate); |
| 80 | LOG_FORMATS("Sample rate %d\n",SampleRate); |
| 81 | 81 | |
| 82 | 82 | NumberOfPulses=get_leuint32(casdata+0x1d); |
| 83 | | logerror("Number Of Pulses %d\n",NumberOfPulses); |
| 83 | LOG_FORMATS("Number Of Pulses %d\n",NumberOfPulses); |
| 84 | 84 | |
| 85 | 85 | |
| 86 | 86 | CompressionType=casdata[0x21]; |
| 87 | 87 | Flags=casdata[0x22]; |
| 88 | 88 | HeaderExtensionLength=casdata[0x23]; |
| 89 | 89 | |
| 90 | | logerror("CompressionType %d Flast %d HeaderExtensionLength %d\n",CompressionType,Flags,HeaderExtensionLength); |
| 90 | LOG_FORMATS("CompressionType %d Flast %d HeaderExtensionLength %d\n",CompressionType,Flags,HeaderExtensionLength); |
| 91 | 91 | |
| 92 | 92 | mycaslen=caslen; |
| 93 | 93 | //from here on down for now I am assuming it is compressed csw file. |
| r11471 | r11472 | |
| 111 | 111 | |
| 112 | 112 | err = inflateInit( &d_stream ); |
| 113 | 113 | if ( err != Z_OK ) { |
| 114 | | logerror( "inflateInit2 error: %d\n", err ); |
| 114 | LOG_FORMATS( "inflateInit2 error: %d\n", err ); |
| 115 | 115 | goto cleanup; |
| 116 | 116 | } |
| 117 | 117 | |
| r11471 | r11472 | |
| 136 | 136 | while (err==Z_OK); |
| 137 | 137 | |
| 138 | 138 | if ( err != Z_STREAM_END ) { |
| 139 | | logerror( "inflate error: %d\n", err ); |
| 139 | LOG_FORMATS( "inflate error: %d\n", err ); |
| 140 | 140 | goto cleanup; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | err = inflateEnd( &d_stream ); |
| 144 | 144 | if ( err != Z_OK ) { |
| 145 | | logerror( "inflateEnd error: %d\n", err ); |
| 145 | LOG_FORMATS( "inflateEnd error: %d\n", err ); |
| 146 | 146 | goto cleanup; |
| 147 | 147 | } |
| 148 | 148 | |
| r11471 | r11472 | |
| 186 | 186 | int i; |
| 187 | 187 | |
| 188 | 188 | |
| 189 | | logerror("Length %d\n",length); |
| 189 | LOG_FORMATS("Length %d\n",length); |
| 190 | 190 | |
| 191 | 191 | SampleRate=get_leuint32(bytes+0x19); |
| 192 | | logerror("Sample rate %d\n",SampleRate); |
| 192 | LOG_FORMATS("Sample rate %d\n",SampleRate); |
| 193 | 193 | |
| 194 | 194 | NumberOfPulses=get_leuint32(bytes+0x1d); |
| 195 | | logerror("Number Of Pulses %d\n",NumberOfPulses); |
| 195 | LOG_FORMATS("Number Of Pulses %d\n",NumberOfPulses); |
| 196 | 196 | |
| 197 | 197 | CompressionType=bytes[0x21]; |
| 198 | 198 | Flags=bytes[0x22]; |
| r11471 | r11472 | |
| 205 | 205 | Bit=100; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | | logerror("CompressionType %d Flast %d HeaderExtensionLength %d\n",CompressionType,Flags,HeaderExtensionLength); |
| 208 | LOG_FORMATS("CompressionType %d Flast %d HeaderExtensionLength %d\n",CompressionType,Flags,HeaderExtensionLength); |
| 209 | 209 | |
| 210 | 210 | |
| 211 | 211 | //from here on down for now I am assuming it is compressed csw file. |
| r11471 | r11472 | |
| 229 | 229 | |
| 230 | 230 | err = inflateInit( &d_stream ); |
| 231 | 231 | if ( err != Z_OK ) { |
| 232 | | logerror( "inflateInit2 error: %d\n", err ); |
| 232 | LOG_FORMATS( "inflateInit2 error: %d\n", err ); |
| 233 | 233 | goto cleanup; |
| 234 | 234 | } |
| 235 | 235 | |
| r11471 | r11472 | |
| 258 | 258 | while (err==Z_OK); |
| 259 | 259 | |
| 260 | 260 | if ( err != Z_STREAM_END ) { |
| 261 | | logerror( "inflate error: %d\n", err ); |
| 261 | LOG_FORMATS( "inflate error: %d\n", err ); |
| 262 | 262 | goto cleanup; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | err = inflateEnd( &d_stream ); |
| 266 | 266 | if ( err != Z_OK ) { |
| 267 | | logerror( "inflateEnd error: %d\n", err ); |
| 267 | LOG_FORMATS( "inflateEnd error: %d\n", err ); |
| 268 | 268 | goto cleanup; |
| 269 | 269 | } |
| 270 | 270 | |
src/lib/formats/d64_dsk.c
| r11471 | r11472 | |
| 280 | 280 | |
| 281 | 281 | if (sector_error != ERROR_00) |
| 282 | 282 | { |
| 283 | | logerror("D64 error %s head %u track %u sector %u\n", ERROR_CODE[sector_error], head, dos_track, sector); |
| 283 | LOG_FORMATS("D64 error %s head %u track %u sector %u\n", ERROR_CODE[sector_error], head, dos_track, sector); |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | return sector_error; |
| r11471 | r11472 | |
| 707 | 707 | |
| 708 | 708 | if (LOG) |
| 709 | 709 | { |
| 710 | | logerror("D64 size: %04x\n", (UINT32)floppy_image_size(floppy)); |
| 711 | | logerror("D64 heads: %u\n", heads); |
| 712 | | logerror("D64 tracks: %u\n", dos_tracks); |
| 713 | | logerror("D64 DOS version: %s\n", DOS_VERSION[dos]); |
| 714 | | logerror("D64 error codes: %s\n", has_errors ? "yes" : "no"); |
| 710 | LOG_FORMATS("D64 size: %04x\n", (UINT32)floppy_image_size(floppy)); |
| 711 | LOG_FORMATS("D64 heads: %u\n", heads); |
| 712 | LOG_FORMATS("D64 tracks: %u\n", dos_tracks); |
| 713 | LOG_FORMATS("D64 DOS version: %s\n", DOS_VERSION[dos]); |
| 714 | LOG_FORMATS("D64 error codes: %s\n", has_errors ? "yes" : "no"); |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | /* clear track data offsets */ |
| r11471 | r11472 | |
| 746 | 746 | |
| 747 | 747 | if (LOG) |
| 748 | 748 | { |
| 749 | | logerror("D64 head %u track %u data offset: %04x\n", head, track + 1, tag->track_offset[head][track]); |
| 750 | | if (has_errors) logerror("D64 head %u track %u error offset: %04x\n", head, track + 1, tag->error_offset[head][track]); |
| 749 | LOG_FORMATS("D64 head %u track %u data offset: %04x\n", head, track + 1, tag->track_offset[head][track]); |
| 750 | if (has_errors) LOG_FORMATS("D64 head %u track %u error offset: %04x\n", head, track + 1, tag->error_offset[head][track]); |
| 751 | 751 | } |
| 752 | 752 | } |
| 753 | 753 | } |
| r11471 | r11472 | |
| 779 | 779 | |
| 780 | 780 | if (LOG) |
| 781 | 781 | { |
| 782 | | logerror("D64 head %u track %.1f data offset: %04x\n", head, get_dos_track(track), tag->track_offset[head][track]); |
| 783 | | if (has_errors) logerror("D64 head %u track %.1f error offset: %04x\n", head, get_dos_track(track), tag->error_offset[head][track]); |
| 782 | LOG_FORMATS("D64 head %u track %.1f data offset: %04x\n", head, get_dos_track(track), tag->track_offset[head][track]); |
| 783 | if (has_errors) LOG_FORMATS("D64 head %u track %.1f error offset: %04x\n", head, get_dos_track(track), tag->error_offset[head][track]); |
| 784 | 784 | } |
| 785 | 785 | } |
| 786 | 786 | } |
| r11471 | r11472 | |
| 794 | 794 | { |
| 795 | 795 | tag->speed_zone[track] = DOS25_SPEED_ZONE[track]; |
| 796 | 796 | |
| 797 | | if (LOG) logerror("D64 track %u speed zone: %u\n", track + 1, tag->speed_zone[track]); |
| 797 | if (LOG) LOG_FORMATS("D64 track %u speed zone: %u\n", track + 1, tag->speed_zone[track]); |
| 798 | 798 | } |
| 799 | 799 | else |
| 800 | 800 | { |
| 801 | 801 | tag->speed_zone[track] = DOS1_SPEED_ZONE[track / 2]; |
| 802 | 802 | |
| 803 | | if (LOG) logerror("D64 track %.1f speed zone: %u\n", get_dos_track(track), tag->speed_zone[track]); |
| 803 | if (LOG) LOG_FORMATS("D64 track %.1f speed zone: %u\n", get_dos_track(track), tag->speed_zone[track]); |
| 804 | 804 | } |
| 805 | 805 | } |
| 806 | 806 | |
| r11471 | r11472 | |
| 819 | 819 | tag->id1 = id[0]; |
| 820 | 820 | tag->id2 = id[1]; |
| 821 | 821 | |
| 822 | | if (LOG) logerror("D64 format ID: %02x%02x\n", id[0], id[1]); |
| 822 | if (LOG) LOG_FORMATS("D64 format ID: %02x%02x\n", id[0], id[1]); |
| 823 | 823 | |
| 824 | 824 | /* read errors */ |
| 825 | 825 | if (tag->has_errors) |
| 826 | 826 | { |
| 827 | | if (LOG) logerror("D64 error blocks: %u %u\n", errors_size, track_offset); |
| 827 | if (LOG) LOG_FORMATS("D64 error blocks: %u %u\n", errors_size, track_offset); |
| 828 | 828 | floppy_image_read(floppy, tag->error, track_offset, errors_size); |
| 829 | 829 | } |
| 830 | 830 | else |
src/lib/formats/g64_dsk.c
| r11471 | r11472 | |
| 154 | 154 | memset(buffer, 0, buflen); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | | if (LOG) logerror("G64 track %.1f length %u\n", get_dos_track(track), track_length); |
| 157 | if (LOG) LOG_FORMATS("G64 track %.1f length %u\n", get_dos_track(track), track_length); |
| 158 | 158 | |
| 159 | 159 | return FLOPPY_ERROR_SUCCESS; |
| 160 | 160 | } |
| r11471 | r11472 | |
| 247 | 247 | /* version */ |
| 248 | 248 | floppy_image_read(floppy, header, pos, 0x0c); pos += 0xc; |
| 249 | 249 | tag->version = header[8]; |
| 250 | | if (LOG) logerror("G64 version: %u\n", tag->version); |
| 250 | if (LOG) LOG_FORMATS("G64 version: %u\n", tag->version); |
| 251 | 251 | |
| 252 | 252 | /* number of half tracks */ |
| 253 | 253 | tag->heads = 1; |
| 254 | 254 | tag->tracks = header[9]; |
| 255 | | if (LOG) logerror("G64 tracks: %u\n", tag->tracks); |
| 255 | if (LOG) LOG_FORMATS("G64 tracks: %u\n", tag->tracks); |
| 256 | 256 | |
| 257 | 257 | /* size of each stored half track */ |
| 258 | 258 | tag->track_size = (header[11] << 8) | header[10]; |
| 259 | | if (LOG) logerror("G64 track size: %04x\n", tag->track_size); |
| 259 | if (LOG) LOG_FORMATS("G64 track size: %04x\n", tag->track_size); |
| 260 | 260 | |
| 261 | 261 | /* data offsets */ |
| 262 | 262 | for (i = 0; i < tag->tracks; i++) |
| r11471 | r11472 | |
| 264 | 264 | floppy_image_read(floppy, header, pos, 4); pos += 4; |
| 265 | 265 | tag->track_offset[i] = (header[3] << 24) | (header[2] << 16) | (header[1] << 8) | header[0]; |
| 266 | 266 | |
| 267 | | if (LOG) logerror("G64 track %.1f data offset: %04x\n", get_dos_track(i), tag->track_offset[i]); |
| 267 | if (LOG) LOG_FORMATS("G64 track %.1f data offset: %04x\n", get_dos_track(i), tag->track_offset[i]); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /* speed zone offsets */ |
| r11471 | r11472 | |
| 276 | 276 | if (LOG) |
| 277 | 277 | { |
| 278 | 278 | if (tag->speed_zone_offset[i] < 4) { |
| 279 | | logerror("G64 track %.1f speed zone: %u\n", get_dos_track(i), tag->speed_zone_offset[i]); |
| 279 | LOG_FORMATS("G64 track %.1f speed zone: %u\n", get_dos_track(i), tag->speed_zone_offset[i]); |
| 280 | 280 | } else { |
| 281 | | logerror("G64 track %.1f speed zone offset: %04x\n", get_dos_track(i), tag->speed_zone_offset[i]); |
| 281 | LOG_FORMATS("G64 track %.1f speed zone offset: %04x\n", get_dos_track(i), tag->speed_zone_offset[i]); |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | } |
src/lib/formats/primoptp.c
| r11471 | r11472 | |
| 90 | 90 | while (i < length) |
| 91 | 91 | { |
| 92 | 92 | size_in_samples += PRIMO_PAUSE_LENGTH; |
| 93 | | logerror ("Samples (pause): %d\n", size_in_samples); |
| 93 | LOG_FORMATS ("Samples (pause): %d\n", size_in_samples); |
| 94 | 94 | |
| 95 | 95 | size_in_samples += PRIMO_FILE_PILOT_LENGTH; |
| 96 | | logerror ("Samples (file pilot): %d\n", size_in_samples); |
| 96 | LOG_FORMATS ("Samples (file pilot): %d\n", size_in_samples); |
| 97 | 97 | |
| 98 | 98 | /* file size with header */ |
| 99 | 99 | file_size = *(b+1) + *(b+2)*256; |
| 100 | 100 | b += 3; |
| 101 | | logerror ("File size (with header): %d\n", file_size); |
| 101 | LOG_FORMATS ("File size (with header): %d\n", file_size); |
| 102 | 102 | |
| 103 | 103 | /* b is now set on the first data byte of file |
| 104 | 104 | it means first byte (type) of block */ |
| r11471 | r11472 | |
| 107 | 107 | while (j < file_size-3) |
| 108 | 108 | { |
| 109 | 109 | size_in_samples += PRIMO_BLOCK_PILOT_LENGTH; |
| 110 | | logerror ("Samples (block pilot): %d\n", size_in_samples); |
| 110 | LOG_FORMATS ("Samples (block pilot): %d\n", size_in_samples); |
| 111 | 111 | |
| 112 | 112 | /* block size without header but including CRC byte */ |
| 113 | 113 | block_size = *(b+1) + *(b+2)*256; |
| r11471 | r11472 | |
| 121 | 121 | size_in_samples += number_of_1 * PRIMO_BIT_1_LENGTH; |
| 122 | 122 | size_in_samples += number_of_0 * PRIMO_BIT_0_LENGTH; |
| 123 | 123 | |
| 124 | | logerror ("Samples (block data): %d\n", size_in_samples); |
| 124 | LOG_FORMATS ("Samples (block data): %d\n", size_in_samples); |
| 125 | 125 | |
| 126 | | logerror ("\tBlock size: %d\n", block_size); |
| 126 | LOG_FORMATS ("\tBlock size: %d\n", block_size); |
| 127 | 127 | |
| 128 | 128 | b += block_size; |
| 129 | 129 | |
| r11471 | r11472 | |
| 149 | 149 | UINT32 file_size = 0; |
| 150 | 150 | UINT16 block_size = 0; |
| 151 | 151 | |
| 152 | | logerror ("Image size: %d\n", length); |
| 152 | LOG_FORMATS ("Image size: %d\n", length); |
| 153 | 153 | |
| 154 | 154 | while (i < primo_tape_image_length) |
| 155 | 155 | { |
| 156 | | logerror ("Beginning Primo file\n"); |
| 156 | LOG_FORMATS ("Beginning Primo file\n"); |
| 157 | 157 | /* pause */ |
| 158 | 158 | p = primo_emit_level (p, PRIMO_PAUSE_LENGTH, PRIMO_WAVEENTRY_ZERO); |
| 159 | 159 | |
| 160 | | logerror ("Samples (pause): %ld\n", (long int)(p-buffer)); |
| 160 | LOG_FORMATS ("Samples (pause): %ld\n", (long int)(p-buffer)); |
| 161 | 161 | |
| 162 | 162 | /* file pilot */ |
| 163 | 163 | for (k=0; k<512; k++) |
| 164 | 164 | p = primo_output_byte (p, 0xaa); |
| 165 | 165 | |
| 166 | | logerror ("Samples (file pilot): %ld\n", (long int)(p-buffer)); |
| 166 | LOG_FORMATS ("Samples (file pilot): %ld\n", (long int)(p-buffer)); |
| 167 | 167 | |
| 168 | 168 | /* file size with header */ |
| 169 | 169 | file_size = *(b+1) + *(b+2)*256; |
| 170 | 170 | b += 3; |
| 171 | 171 | |
| 172 | | logerror ("File size: %d\n", file_size); |
| 172 | LOG_FORMATS ("File size: %d\n", file_size); |
| 173 | 173 | |
| 174 | 174 | /* b is now set on the first data byte of file |
| 175 | 175 | it means first byte (block type) of block header */ |
| r11471 | r11472 | |
| 184 | 184 | for (k=0; k<3; k++) |
| 185 | 185 | p = primo_output_byte (p, 0xd3); |
| 186 | 186 | |
| 187 | | logerror ("Samples (block pilot): %ld\n", (long int)(p-buffer)); |
| 187 | LOG_FORMATS ("Samples (block pilot): %ld\n", (long int)(p-buffer)); |
| 188 | 188 | |
| 189 | 189 | /* block size without header but including CRC byte */ |
| 190 | 190 | block_size = *(b+1) + *(b+2)*256; |
| r11471 | r11472 | |
| 193 | 193 | for (k=0; k<block_size; k++) |
| 194 | 194 | p = primo_output_byte (p, *(b+k)); |
| 195 | 195 | |
| 196 | | logerror ("Samples (block data): %ld\n", (long int)(p-buffer)); |
| 196 | LOG_FORMATS ("Samples (block data): %ld\n", (long int)(p-buffer)); |
| 197 | 197 | |
| 198 | 198 | b += block_size; |
| 199 | 199 | |
| r11471 | r11472 | |
| 202 | 202 | j += block_size+3; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | | logerror ("Primo file finished\n"); |
| 206 | | logerror ("i = %d\n", i); |
| 205 | LOG_FORMATS ("Primo file finished\n"); |
| 206 | LOG_FORMATS ("i = %d\n", i); |
| 207 | 207 | i += file_size; |
| 208 | | logerror ("i = %d\n", i); |
| 208 | LOG_FORMATS ("i = %d\n", i); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | | logerror ("End of fill_wave/n"); |
| 211 | LOG_FORMATS ("End of fill_wave/n"); |
| 212 | 212 | |
| 213 | 213 | return p - buffer; |
| 214 | 214 | } |
src/lib/formats/oric_tap.c
| r11471 | r11472 | |
| 240 | 240 | { |
| 241 | 241 | if (data==ORIC_SYNC_BYTE) |
| 242 | 242 | { |
| 243 | | logerror("found sync byte!\n"); |
| 243 | LOG_FORMATS("found sync byte!\n"); |
| 244 | 244 | /* found first sync byte */ |
| 245 | 245 | oric.cassette_state = ORIC_CASSETTE_GOT_SYNC_BYTE; |
| 246 | 246 | } |
| r11471 | r11472 | |
| 254 | 254 | /* 0.25 second pause */ |
| 255 | 255 | count += oric_seconds_to_samples(0.25); |
| 256 | 256 | |
| 257 | | logerror("found end of sync bytes!\n"); |
| 257 | LOG_FORMATS("found end of sync bytes!\n"); |
| 258 | 258 | |
| 259 | 259 | /* oric writes approx 512 bytes */ |
| 260 | 260 | /* found end of sync bytes */ |
| r11471 | r11472 | |
| 265 | 265 | |
| 266 | 266 | if (data==0x024) |
| 267 | 267 | { |
| 268 | | //logerror("reading header!\n"); |
| 268 | //LOG_FORMATS("reading header!\n"); |
| 269 | 269 | count+=oric_calculate_byte_size_in_samples(0x024); |
| 270 | 270 | |
| 271 | 271 | oric.cassette_state = ORIC_CASSETTE_READ_HEADER; |
| r11471 | r11472 | |
| 285 | 285 | |
| 286 | 286 | if (oric.data_count==oric.data_length) |
| 287 | 287 | { |
| 288 | | //logerror("finished reading header!\n"); |
| 288 | //LOG_FORMATS("finished reading header!\n"); |
| 289 | 289 | oric.cassette_state = ORIC_CASSETTE_READ_FILENAME; |
| 290 | 290 | } |
| 291 | 291 | } |
| r11471 | r11472 | |
| 299 | 299 | if (data==0) |
| 300 | 300 | { |
| 301 | 301 | UINT16 end, start; |
| 302 | | logerror("got end of filename\n"); |
| 302 | LOG_FORMATS("got end of filename\n"); |
| 303 | 303 | |
| 304 | 304 | /* 100 1 bits to seperate header from data */ |
| 305 | 305 | for (i=0; i<100; i++) |
| r11471 | r11472 | |
| 326 | 326 | |
| 327 | 327 | if (oric.data_count==oric.data_length) |
| 328 | 328 | { |
| 329 | | logerror("finished writing data!\n"); |
| 329 | LOG_FORMATS("finished writing data!\n"); |
| 330 | 330 | oric.cassette_state = ORIC_CASSETTE_SEARCHING_FOR_SYNC_BYTE; |
| 331 | 331 | } |
| 332 | 332 | } |
| r11471 | r11472 | |
| 380 | 380 | { |
| 381 | 381 | if (data==ORIC_SYNC_BYTE) |
| 382 | 382 | { |
| 383 | | logerror("found sync byte!\n"); |
| 383 | LOG_FORMATS("found sync byte!\n"); |
| 384 | 384 | /* found first sync byte */ |
| 385 | 385 | oric.cassette_state = ORIC_CASSETTE_GOT_SYNC_BYTE; |
| 386 | 386 | } |
| r11471 | r11472 | |
| 394 | 394 | /* 0.25 second pause */ |
| 395 | 395 | p = oric_fill_pause(p, oric_seconds_to_samples(0.25)); |
| 396 | 396 | |
| 397 | | logerror("found end of sync bytes!\n"); |
| 397 | LOG_FORMATS("found end of sync bytes!\n"); |
| 398 | 398 | /* found end of sync bytes */ |
| 399 | 399 | for (i=0; i<ORIC_LEADER_LENGTH; i++) |
| 400 | 400 | { |
| r11471 | r11472 | |
| 403 | 403 | |
| 404 | 404 | if (data==0x024) |
| 405 | 405 | { |
| 406 | | //logerror("reading header!\n"); |
| 406 | //LOG_FORMATS("reading header!\n"); |
| 407 | 407 | p = oric_output_byte(p,data); |
| 408 | 408 | oric.cassette_state = ORIC_CASSETTE_READ_HEADER; |
| 409 | 409 | oric.data_count = 0; |
| r11471 | r11472 | |
| 421 | 421 | |
| 422 | 422 | if (oric.data_count==oric.data_length) |
| 423 | 423 | { |
| 424 | | //logerror("finished reading header!\n"); |
| 424 | //LOG_FORMATS("finished reading header!\n"); |
| 425 | 425 | oric.cassette_state = ORIC_CASSETTE_READ_FILENAME; |
| 426 | 426 | } |
| 427 | 427 | } |
| r11471 | r11472 | |
| 435 | 435 | if (data==0) |
| 436 | 436 | { |
| 437 | 437 | UINT16 end, start; |
| 438 | | logerror("got end of filename\n"); |
| 438 | LOG_FORMATS("got end of filename\n"); |
| 439 | 439 | |
| 440 | 440 | /* oric includes a small delay, but I don't see |
| 441 | 441 | it being 1 bits */ |
| r11471 | r11472 | |
| 463 | 463 | |
| 464 | 464 | if (oric.data_count==oric.data_length) |
| 465 | 465 | { |
| 466 | | logerror("finished writing data!\n"); |
| 466 | LOG_FORMATS("finished writing data!\n"); |
| 467 | 467 | oric.cassette_state = ORIC_CASSETTE_SEARCHING_FOR_SYNC_BYTE; |
| 468 | 468 | } |
| 469 | 469 | } |
src/lib/formats/ti99_dsk.c
| r11471 | r11472 | |
| 331 | 331 | && (geometry->density <= 4) && (totsecs >= 2) && (! memcmp(vib.id, "DSK", 3)) |
| 332 | 332 | && (file_size == totsecs*256)) |
| 333 | 333 | { |
| 334 | | logerror("SDF/VIB consistent; tracks = %d, heads = %d, sectors = %d\n", geometry->tracksperside, geometry->sides, geometry->secspertrack); |
| 334 | LOG_FORMATS("SDF/VIB consistent; tracks = %d, heads = %d, sectors = %d\n", geometry->tracksperside, geometry->sides, geometry->secspertrack); |
| 335 | 335 | return 100; |
| 336 | 336 | } |
| 337 | | logerror("SDF/VIB not consistent; guessing format\n"); |
| 337 | LOG_FORMATS("SDF/VIB not consistent; guessing format\n"); |
| 338 | 338 | |
| 339 | 339 | // So that was not consistent. We guess the size from the file size |
| 340 | 340 | // and assume that the VIB did not contain reliable data. For the |
| r11471 | r11472 | |
| 409 | 409 | break; |
| 410 | 410 | |
| 411 | 411 | default: |
| 412 | | logerror("Unrecognized disk image geometry\n"); |
| 412 | LOG_FORMATS("Unrecognized disk image geometry\n"); |
| 413 | 413 | return 0; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | | logerror("SDF geometry guess: tracks = %d, heads = %d, sectors = %d\n", geometry->tracksperside, geometry->sides, geometry->secspertrack); |
| 416 | LOG_FORMATS("SDF geometry guess: tracks = %d, heads = %d, sectors = %d\n", geometry->tracksperside, geometry->sides, geometry->secspertrack); |
| 417 | 417 | return 100; |
| 418 | 418 | } |
| 419 | 419 | |
| r11471 | r11472 | |
| 663 | 663 | if (current_pos==TI99DSK_BLOCKNOTFOUND) |
| 664 | 664 | { |
| 665 | 665 | /* If neither, forget about this process completely. */ |
| 666 | | logerror("Cannot find lead-in for track %d, head %d.\n", track, head); |
| 666 | LOG_FORMATS("Cannot find lead-in for track %d, head %d.\n", track, head); |
| 667 | 667 | return FLOPPY_ERROR_INVALIDIMAGE; |
| 668 | 668 | } |
| 669 | 669 | gap1 = 6; |
| r11471 | r11472 | |
| 682 | 682 | { |
| 683 | 683 | /* Forget about the rest. */ |
| 684 | 684 | if (found) break; /* we were already successful, so all ok */ |
| 685 | | logerror("Cannot find gap1 for track %d, head %d.\n", track, head); |
| 685 | LOG_FORMATS("Cannot find gap1 for track %d, head %d.\n", track, head); |
| 686 | 686 | return FLOPPY_ERROR_INVALIDIMAGE; |
| 687 | 687 | } |
| 688 | 688 | found = TRUE; |
| r11471 | r11472 | |
| 703 | 703 | new_pos = find_block(track_image, current_pos, buflen, 0x00, gap2); |
| 704 | 704 | if (current_pos==TI99DSK_BLOCKNOTFOUND) |
| 705 | 705 | { |
| 706 | | logerror("Cannot find gap2 for track %d, head %d.\n", imgtrack, head); |
| 706 | LOG_FORMATS("Cannot find gap2 for track %d, head %d.\n", imgtrack, head); |
| 707 | 707 | return FLOPPY_ERROR_INVALIDIMAGE; |
| 708 | 708 | } |
| 709 | 709 | else |
| r11471 | r11472 | |
| 719 | 719 | current_pos += SECTOR_SIZE; |
| 720 | 720 | } |
| 721 | 721 | else |
| 722 | | logerror("DAM not found. Not writing write sector %d\n", sector); |
| 722 | LOG_FORMATS("DAM not found. Not writing write sector %d\n", sector); |
| 723 | 723 | /* else not found, ignore this sector. */ |
| 724 | 724 | } |
| 725 | 725 | } |
| r11471 | r11472 | |
| 727 | 727 | { |
| 728 | 728 | // else the sector head data do not match the |
| 729 | 729 | // current track and head. Ignore the sector. |
| 730 | | logerror("Wrong track: wtrack=%d, imgtrack=%d, whead=%d, imghead=%d\n",wtrack,imgtrack, whead,head); |
| 730 | LOG_FORMATS("Wrong track: wtrack=%d, imgtrack=%d, whead=%d, imghead=%d\n",wtrack,imgtrack, whead,head); |
| 731 | 731 | } |
| 732 | 732 | } |
| 733 | 733 | else |
| r11471 | r11472 | |
| 924 | 924 | UINT64 size; |
| 925 | 925 | size = floppy_image_size(floppy); |
| 926 | 926 | *vote = ti99_sdf_guess_geometry(floppy, size, NULL); |
| 927 | | logerror("SDF voting %d\n", *vote); |
| 927 | LOG_FORMATS("SDF voting %d\n", *vote); |
| 928 | 928 | return FLOPPY_ERROR_SUCCESS; |
| 929 | 929 | } |
| 930 | 930 | |
| r11471 | r11472 | |
| 936 | 936 | struct ti99dsk_geometry geometry; |
| 937 | 937 | struct FloppyCallbacks *callbacks; |
| 938 | 938 | struct ti99dsk_tag *tag; |
| 939 | | logerror("Reading image as SDF\n"); |
| 939 | LOG_FORMATS("Reading image as SDF\n"); |
| 940 | 940 | |
| 941 | 941 | if (params) |
| 942 | 942 | { |
| r11471 | r11472 | |
| 1116 | 1116 | current_pos = find_block(track, 0, 50, 0x00, 22); |
| 1117 | 1117 | if (current_pos==TI99DSK_BLOCKNOTFOUND) |
| 1118 | 1118 | { |
| 1119 | | logerror("Lead-in not found\n"); |
| 1119 | LOG_FORMATS("Lead-in not found\n"); |
| 1120 | 1120 | retval = FLOPPY_ERROR_SEEKERROR; |
| 1121 | 1121 | } |
| 1122 | 1122 | else |
| r11471 | r11472 | |
| 1132 | 1132 | } |
| 1133 | 1133 | else |
| 1134 | 1134 | { |
| 1135 | | logerror("IDAM or DAM not found\n"); |
| 1135 | LOG_FORMATS("IDAM or DAM not found\n"); |
| 1136 | 1136 | retval = FLOPPY_ERROR_SEEKERROR; |
| 1137 | 1137 | } |
| 1138 | 1138 | } |
| r11471 | r11472 | |
| 1144 | 1144 | int track_start = find_block(track, 0, 100, 0x4e, 40); |
| 1145 | 1145 | if (track_start==TI99DSK_BLOCKNOTFOUND) |
| 1146 | 1146 | { |
| 1147 | | logerror("Lead-in not found\n"); |
| 1147 | LOG_FORMATS("Lead-in not found\n"); |
| 1148 | 1148 | retval = FLOPPY_ERROR_SEEKERROR; |
| 1149 | 1149 | } |
| 1150 | 1150 | else |
| r11471 | r11472 | |
| 1153 | 1153 | current_pos = find_block(track, track_start, track_start+10, 0x00, 10); |
| 1154 | 1154 | if (current_pos==TI99DSK_BLOCKNOTFOUND) |
| 1155 | 1155 | { |
| 1156 | | logerror("Pre-gap not found\n"); |
| 1156 | LOG_FORMATS("Pre-gap not found\n"); |
| 1157 | 1157 | retval = FLOPPY_ERROR_SEEKERROR; |
| 1158 | 1158 | } |
| 1159 | 1159 | else |
| r11471 | r11472 | |
| 1170 | 1170 | } |
| 1171 | 1171 | else |
| 1172 | 1172 | { |
| 1173 | | logerror("Sync/IDAM/DAM not found\n"); |
| 1173 | LOG_FORMATS("Sync/IDAM/DAM not found\n"); |
| 1174 | 1174 | retval = FLOPPY_ERROR_SEEKERROR; |
| 1175 | 1175 | } |
| 1176 | 1176 | } |
| r11471 | r11472 | |
| 1378 | 1378 | { |
| 1379 | 1379 | if (determine_offset(tag->format, track_data, &tag->first_idam)==FLOPPY_ERROR_SEEKERROR) |
| 1380 | 1380 | { |
| 1381 | | logerror("could not determine offset\n"); |
| 1381 | LOG_FORMATS("could not determine offset\n"); |
| 1382 | 1382 | return FLOPPY_ERROR_SEEKERROR; |
| 1383 | 1383 | } |
| 1384 | 1384 | } |
| r11471 | r11472 | |
| 1408 | 1408 | break; |
| 1409 | 1409 | } |
| 1410 | 1410 | } |
| 1411 | | logerror("Sector not found.\n"); |
| 1411 | LOG_FORMATS("Sector not found.\n"); |
| 1412 | 1412 | return FLOPPY_ERROR_SEEKERROR; |
| 1413 | 1413 | } |
| 1414 | 1414 | |
| r11471 | r11472 | |
| 1764 | 1764 | /* MFM failed. */ |
| 1765 | 1765 | if (determine_offset(TI99_FM, track_data, &first_idam)==FLOPPY_ERROR_SEEKERROR) |
| 1766 | 1766 | { |
| 1767 | | logerror("IDAM not found. Unformatted disk.\n"); |
| 1767 | LOG_FORMATS("IDAM not found. Unformatted disk.\n"); |
| 1768 | 1768 | |
| 1769 | 1769 | // FM failed as well. Disk is not formatted. We assume |
| 1770 | 1770 | // a format that fits into the space provided by the file. |
| r11471 | r11472 | |
| 1774 | 1774 | free(track_data); |
| 1775 | 1775 | if (size < 130120 || size > 2078720) |
| 1776 | 1776 | { |
| 1777 | | logerror("Unknown format size: %d\n", (int)size); |
| 1777 | LOG_FORMATS("Unknown format size: %d\n", (int)size); |
| 1778 | 1778 | return 0; |
| 1779 | 1779 | } |
| 1780 | 1780 | if (size >= 130120 && size < 260240) |
| r11471 | r11472 | |
| 1888 | 1888 | state = 0; |
| 1889 | 1889 | } |
| 1890 | 1890 | } |
| 1891 | | logerror("Determined %d sectors\n", idamcnt); |
| 1891 | LOG_FORMATS("Determined %d sectors\n", idamcnt); |
| 1892 | 1892 | |
| 1893 | 1893 | // Now calculate the geometry |
| 1894 | 1894 | // The track size, in theory, may change due to reformatting, |
| r11471 | r11472 | |
| 1912 | 1912 | if (determine_offset(format, track_data, &first_idam)==FLOPPY_ERROR_SEEKERROR) |
| 1913 | 1913 | { |
| 1914 | 1914 | /* error ... what now? */ |
| 1915 | | logerror("Error when reading last track. Image broken.\n"); |
| 1915 | LOG_FORMATS("Error when reading last track. Image broken.\n"); |
| 1916 | 1916 | free(track_data); |
| 1917 | 1917 | return 50; |
| 1918 | 1918 | } |
| r11471 | r11472 | |
| 1930 | 1930 | } |
| 1931 | 1931 | else |
| 1932 | 1932 | { |
| 1933 | | logerror("Error: Last track has invalid first IDAM: head = %d.\n", track_data[first_idam+2]); |
| 1933 | LOG_FORMATS("Error: Last track has invalid first IDAM: head = %d.\n", track_data[first_idam+2]); |
| 1934 | 1934 | } |
| 1935 | 1935 | |
| 1936 | 1936 | } |
| r11471 | r11472 | |
| 1942 | 1942 | |
| 1943 | 1943 | if (geometry->tracksperside < 35 || geometry->tracksperside > 80) |
| 1944 | 1944 | { |
| 1945 | | logerror("Unsupported track count: %d\n", geometry->tracksperside); |
| 1945 | LOG_FORMATS("Unsupported track count: %d\n", geometry->tracksperside); |
| 1946 | 1946 | free(track_data); |
| 1947 | 1947 | return 0; |
| 1948 | 1948 | } |
| r11471 | r11472 | |
| 1956 | 1956 | UINT64 size; |
| 1957 | 1957 | size = floppy_image_size(floppy); |
| 1958 | 1958 | *vote = ti99_tdf_guess_geometry(floppy, size, NULL); |
| 1959 | | logerror("TDF voting %d\n", *vote); |
| 1959 | LOG_FORMATS("TDF voting %d\n", *vote); |
| 1960 | 1960 | return FLOPPY_ERROR_SUCCESS; |
| 1961 | 1961 | } |
| 1962 | 1962 | |
| r11471 | r11472 | |
| 1965 | 1965 | struct ti99dsk_geometry geometry; |
| 1966 | 1966 | struct FloppyCallbacks *callbacks; |
| 1967 | 1967 | struct ti99dsk_tag *tag; |
| 1968 | | logerror("Reading image as TDF\n"); |
| 1968 | LOG_FORMATS("Reading image as TDF\n"); |
| 1969 | 1969 | if (params) |
| 1970 | 1970 | { |
| 1971 | 1971 | /* create */ |
src/lib/formats/fdi_dsk.c
| r11471 | r11472 | |
| 240 | 240 | |
| 241 | 241 | if (LOG) |
| 242 | 242 | { |
| 243 | | logerror("FDI creator: %s\n", header.creator); |
| 244 | | logerror("FDI comment: %s\n", header.comment); |
| 245 | | logerror("FDI version: %u\n", tag->version); |
| 246 | | logerror("FDI tracks: %u\n", tag->tracks); |
| 247 | | logerror("FDI heads: %u\n", tag->heads); |
| 248 | | logerror("FDI media type: %s\"\n", MEDIA_TYPE[header.type]); |
| 249 | | logerror("FDI rotation speed: %u\n", header.rotspeed + 128); |
| 250 | | if (header.flags & FLAGS_WRITE_PROTECTED) logerror("FDI is write protected\n"); |
| 251 | | if (header.flags & FLAGS_INDEX_SYNC) logerror("FDI is index synchronized\n"); |
| 252 | | logerror("FDI media TPI: %u\n", TRACKS_PER_INCH[header.tpi]); |
| 253 | | logerror("FDI head TPI: %u\n", TRACKS_PER_INCH[header.headwidth]); |
| 243 | LOG_FORMATS("FDI creator: %s\n", header.creator); |
| 244 | LOG_FORMATS("FDI comment: %s\n", header.comment); |
| 245 | LOG_FORMATS("FDI version: %u\n", tag->version); |
| 246 | LOG_FORMATS("FDI tracks: %u\n", tag->tracks); |
| 247 | LOG_FORMATS("FDI heads: %u\n", tag->heads); |
| 248 | LOG_FORMATS("FDI media type: %s\"\n", MEDIA_TYPE[header.type]); |
| 249 | LOG_FORMATS("FDI rotation speed: %u\n", header.rotspeed + 128); |
| 250 | if (header.flags & FLAGS_WRITE_PROTECTED) LOG_FORMATS("FDI is write protected\n"); |
| 251 | if (header.flags & FLAGS_INDEX_SYNC) LOG_FORMATS("FDI is index synchronized\n"); |
| 252 | LOG_FORMATS("FDI media TPI: %u\n", TRACKS_PER_INCH[header.tpi]); |
| 253 | LOG_FORMATS("FDI head TPI: %u\n", TRACKS_PER_INCH[header.headwidth]); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /* find track offsets */ |
| r11471 | r11472 | |
| 261 | 261 | UINT8 type = header.track[track].type; |
| 262 | 262 | int size = header.track[track].size * 256; |
| 263 | 263 | |
| 264 | | if (LOG) logerror("FDI track %u type %02x size %u offset %u\n", track, type, size, offset); |
| 264 | if (LOG) LOG_FORMATS("FDI track %u type %02x size %u offset %u\n", track, type, size, offset); |
| 265 | 265 | |
| 266 | 266 | tag->track_offset[track] = offset; |
| 267 | 267 | tag->track_type[track] = type; |