trunk/src/lib/util/chdcd.c
| r20089 | r20090 | |
| 313 | 313 | |
| 314 | 314 | astring path = astring(tocfname); |
| 315 | 315 | |
| 316 | | infile = fopen(tocfname, "rt"); |
| 316 | infile = fopen(tocfname, "rb"); |
| 317 | 317 | path = get_file_path(path); |
| 318 | 318 | |
| 319 | 319 | if (infile == (FILE *)NULL) |
| r20089 | r20090 | |
| 364 | 364 | if (!memcmp(buffer, "DAOX", 4)) |
| 365 | 365 | { |
| 366 | 366 | // skip second chunk size and UPC code |
| 367 | read_uint32(infile); |
| 367 | 368 | fseek(infile, 16, SEEK_CUR); |
| 368 | 369 | |
| 369 | | read_uint32(infile); |
| 370 | 370 | fread(&start, 1, 1, infile); |
| 371 | 371 | fread(&end, 1, 1, infile); |
| 372 | 372 | |
| 373 | | // printf("TOC type: %08x. Start track %d End track: %d\n", toc_type, start, end); |
| 373 | // printf("Start track %d End track: %d\n", start, end); |
| 374 | 374 | |
| 375 | 375 | outtoc.numtrks = (end-start) + 1; |
| 376 | 376 | |
| r20089 | r20090 | |
| 378 | 378 | for (track = start; track <= end; track++) |
| 379 | 379 | { |
| 380 | 380 | UINT32 size, mode; |
| 381 | | UINT64 index0, index1, index2; |
| 381 | UINT64 index0, index1, track_end; |
| 382 | 382 | |
| 383 | 383 | fseek(infile, 12, SEEK_CUR); // skip ISRC code |
| 384 | 384 | size = read_uint16(infile); |
| 385 | 385 | mode = read_uint32(infile); |
| 386 | 386 | index0 = read_uint64(infile); |
| 387 | 387 | index1 = read_uint64(infile); |
| 388 | | index2 = read_uint64(infile); |
| 388 | track_end = read_uint64(infile); |
| 389 | 389 | |
| 390 | | // printf("Track %d: sector size %d mode %x index0 %llx index1 %llx index2 %llx (pregap %d sectors, length %d sectors)\n", track, size, mode, index0, index1, index2, (UINT32)(index1-index0)/size, (UINT32)(index2-index1)/size); |
| 390 | // printf("Track %d: sector size %d mode %x index0 %llx index1 %llx track_end %llx (pregap %d sectors, length %d sectors)\n", track, size, mode, index0, index1, track_end, (UINT32)(index1-index0)/size, (UINT32)(track_end-index1)/size); |
| 391 | 391 | outinfo.track[track-1].fname.cpy(tocfname); |
| 392 | 392 | outinfo.track[track-1].offset = offset + (UINT32)(index1-index0); |
| 393 | 393 | outinfo.track[track-1].idx0offs = 0; |
| r20089 | r20090 | |
| 395 | 395 | |
| 396 | 396 | switch (mode>>24) |
| 397 | 397 | { |
| 398 | | case 0x00: // 2048 byte data |
| 398 | case 0x0000: // 2048 byte data |
| 399 | 399 | outtoc.tracks[track-1].trktype = CD_TRACK_MODE1; |
| 400 | 400 | outinfo.track[track-1].swap = false; |
| 401 | 401 | break; |
| 402 | 402 | |
| 403 | case 0x0300: // Mode 2 Form 1 |
| 404 | printf("ERROR: Mode 2 Form 1 tracks not supported, contant MAMEDEV!\n"); |
| 405 | fclose(infile); |
| 406 | return CHDERR_NOT_SUPPORTED; |
| 407 | |
| 408 | case 0x0500: // raw data |
| 409 | printf("ERROR: Raw data tracks not supported, contant MAMEDEV!\n"); |
| 410 | fclose(infile); |
| 411 | return CHDERR_NOT_SUPPORTED; |
| 412 | |
| 403 | 413 | case 0x06: // 2352 byte mode 2 raw |
| 404 | 414 | outtoc.tracks[track-1].trktype = CD_TRACK_MODE2_RAW; |
| 405 | 415 | outinfo.track[track-1].swap = false; |
| 406 | 416 | break; |
| 407 | 417 | |
| 408 | | case 0x07: // 2352 byte audio |
| 418 | case 0x0700: // 2352 byte audio |
| 409 | 419 | outtoc.tracks[track-1].trktype = CD_TRACK_AUDIO; |
| 410 | 420 | outinfo.track[track-1].swap = true; |
| 411 | 421 | break; |
| 412 | 422 | |
| 423 | case 0x0f00: // raw data with sub-channel |
| 424 | printf("ERROR: Raw data tracks with sub-channel not supported, contant MAMEDEV!\n"); |
| 425 | fclose(infile); |
| 426 | return CHDERR_NOT_SUPPORTED; |
| 427 | |
| 428 | case 0x1000: // audio with sub-channel |
| 429 | printf("ERROR: Audio tracks with sub-channel not supported, contant MAMEDEV!\n"); |
| 430 | fclose(infile); |
| 431 | return CHDERR_NOT_SUPPORTED; |
| 432 | |
| 433 | case 0x1100: // raw Mode 2 Form 1 with sub-channel |
| 434 | printf("ERROR: Raw Mode 2 Form 1 tracks with sub-channel not supported, contant MAMEDEV!\n"); |
| 435 | fclose(infile); |
| 436 | return CHDERR_NOT_SUPPORTED; |
| 437 | |
| 413 | 438 | default: |
| 414 | | printf("ERROR: Unknown track type %x, contact MAMEDEV!\n", mode>>24); |
| 415 | | break; |
| 439 | printf("ERROR: Unknown track type %x, contact MAMEDEV!\n", mode); |
| 440 | fclose(infile); |
| 441 | return CHDERR_NOT_SUPPORTED; |
| 416 | 442 | } |
| 417 | 443 | |
| 418 | 444 | outtoc.tracks[track-1].datasize = size; |
| r20089 | r20090 | |
| 421 | 447 | outtoc.tracks[track-1].subsize = 0; |
| 422 | 448 | |
| 423 | 449 | outtoc.tracks[track-1].pregap = (UINT32)(index1-index0)/size; |
| 424 | | outtoc.tracks[track-1].frames = (UINT32)(index2-index1)/size; |
| 450 | outtoc.tracks[track-1].frames = (UINT32)(track_end-index1)/size; |
| 425 | 451 | outtoc.tracks[track-1].postgap = 0; |
| 426 | 452 | outtoc.tracks[track-1].pgtype = 0; |
| 427 | 453 | outtoc.tracks[track-1].pgsub = CD_SUB_NONE; |
| r20089 | r20090 | |
| 429 | 455 | outtoc.tracks[track-1].pgsubsize = 0; |
| 430 | 456 | outtoc.tracks[track-1].padframes = 0; |
| 431 | 457 | |
| 432 | | offset += (UINT32)index2-index1; |
| 458 | offset += (UINT32)track_end-index1; |
| 433 | 459 | } |
| 434 | 460 | } |
| 435 | 461 | |
| r20089 | r20090 | |
| 888 | 914 | } |
| 889 | 915 | } |
| 890 | 916 | } |
| 891 | | printf("trk %d: %d frames @ offset %d\n", trknum+1, outtoc.tracks[trknum].frames, outinfo.track[trknum].offset); |
| 917 | //printf("trk %d: %d frames @ offset %d\n", trknum+1, outtoc.tracks[trknum].frames, outinfo.track[trknum].offset); |
| 892 | 918 | } |
| 893 | 919 | |
| 894 | 920 | return CHDERR_NONE; |