Previous 199869 Revisions Next

r20090 Saturday 5th January, 2013 at 22:03:02 UTC by Oliver Stöneberg
fixed reading of NRG images / bail out on unsupported tracks in NRG images / cleanups (nw)
[src/lib/util]chdcd.c

trunk/src/lib/util/chdcd.c
r20089r20090
313313
314314   astring path = astring(tocfname);
315315
316   infile = fopen(tocfname, "rt");
316   infile = fopen(tocfname, "rb");
317317   path = get_file_path(path);
318318
319319   if (infile == (FILE *)NULL)
r20089r20090
364364      if (!memcmp(buffer, "DAOX", 4))
365365      {
366366         // skip second chunk size and UPC code
367         read_uint32(infile);
367368         fseek(infile, 16, SEEK_CUR);
368369
369         read_uint32(infile);
370370         fread(&start, 1, 1, infile);
371371         fread(&end, 1, 1, infile);
372372
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);
374374
375375         outtoc.numtrks = (end-start) + 1;
376376
r20089r20090
378378         for (track = start; track <= end; track++)
379379         {
380380            UINT32 size, mode;
381            UINT64 index0, index1, index2;
381            UINT64 index0, index1, track_end;
382382
383383            fseek(infile, 12, SEEK_CUR);   // skip ISRC code
384384            size = read_uint16(infile);
385385            mode = read_uint32(infile);
386386            index0 = read_uint64(infile);
387387            index1 = read_uint64(infile);
388            index2 = read_uint64(infile);
388            track_end = read_uint64(infile);
389389
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);
391391            outinfo.track[track-1].fname.cpy(tocfname);
392392            outinfo.track[track-1].offset = offset + (UINT32)(index1-index0);
393393            outinfo.track[track-1].idx0offs = 0;
r20089r20090
395395
396396            switch (mode>>24)
397397            {
398               case 0x00:   // 2048 byte data
398               case 0x0000:   // 2048 byte data
399399                  outtoc.tracks[track-1].trktype = CD_TRACK_MODE1;
400400                  outinfo.track[track-1].swap = false;
401401                  break;
402402
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
403413               case 0x06:   // 2352 byte mode 2 raw
404414                  outtoc.tracks[track-1].trktype = CD_TRACK_MODE2_RAW;
405415                  outinfo.track[track-1].swap = false;
406416                  break;
407417
408               case 0x07:   // 2352 byte audio
418               case 0x0700:   // 2352 byte audio
409419                  outtoc.tracks[track-1].trktype = CD_TRACK_AUDIO;
410420                  outinfo.track[track-1].swap = true;
411421                  break;
412422
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
413438               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;
416442            }
417443
418444            outtoc.tracks[track-1].datasize = size;
r20089r20090
421447            outtoc.tracks[track-1].subsize = 0;
422448
423449            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;
425451            outtoc.tracks[track-1].postgap = 0;
426452            outtoc.tracks[track-1].pgtype = 0;
427453            outtoc.tracks[track-1].pgsub = CD_SUB_NONE;
r20089r20090
429455            outtoc.tracks[track-1].pgsubsize = 0;
430456            outtoc.tracks[track-1].padframes = 0;
431457
432            offset += (UINT32)index2-index1;
458            offset += (UINT32)track_end-index1;
433459         }
434460      }
435461
r20089r20090
888914            }
889915         }
890916      }
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);
892918   }
893919
894920   return CHDERR_NONE;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team