Mercurial > repos > blastem
annotate cdimage.c @ 2189:6b33ce6bc740
Add an explicit p alias for the print command now that printf prevents use of it as an implicit alias
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 20 Aug 2022 11:41:41 -0700 |
parents | 9209858b2f74 |
children | a8af8d898a7c |
rev | line source |
---|---|
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <ctype.h> |
2074
c5323c02dde4
Fix windows build error
Michael Pavone <pavone@retrodev.com>
parents:
2062
diff
changeset
|
2 #include <string.h> |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "system.h" |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "util.h" |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 static char* cmd_start(char *cur) |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 while (*cur && isblank(*cur)) |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 cur++; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 return cur; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
16 static char* cmd_start_sameline(char *cur) |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
17 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
18 while (*cur && isblank(*cur) && *cur != '\n') |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
19 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
20 cur++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
21 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
22 return cur; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
23 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
24 |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
25 static char* word_end(char *cur) |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
26 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
27 while (*cur && !isblank(*cur)) |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
28 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
29 cur++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
30 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
31 return cur; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
32 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
33 |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 static char* next_line(char *cur) |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 while (*cur && *cur != '\n') |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 cur++; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 if (*cur) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 return cur + 1; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 return NULL; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
46 static char* next_blank(char *cur) |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
47 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
48 while (*cur && !isblank(*cur)) |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
49 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
50 cur++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
51 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
52 return cur; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
53 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
54 |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 static uint32_t timecode_to_lba(char *timecode) |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 char *end; |
2149
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
58 int seconds = 0, minutes = 0; |
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
59 int frames = strtol(timecode, &end, 10); |
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
60 if (end && *end == ':') { |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 timecode = end + 1; |
2149
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
62 seconds = frames; |
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
63 frames = strtol(timecode, &end, 10); |
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
64 if (end && *end == ':') { |
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
65 minutes = seconds; |
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
66 seconds = frames; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 timecode = end + 1; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 frames = strtol(timecode, NULL, 10); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 seconds += minutes * 60; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 return seconds * 75 + frames; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 |
2080 | 76 enum { |
77 FAKE_DATA = 1, | |
78 FAKE_AUDIO, | |
79 }; | |
80 | |
81 static uint8_t bin_seek(system_media *media, uint32_t sector) | |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
82 { |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
83 media->cur_sector = sector; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
84 uint32_t lba = sector; |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
85 uint32_t track; |
2080 | 86 for (track = 0; track < media->num_tracks; track++) |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
87 { |
2080 | 88 if (lba < media->tracks[track].fake_pregap) { |
89 media->in_fake_pregap = media->tracks[track].type == TRACK_DATA ? FAKE_DATA : FAKE_AUDIO; | |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
90 break; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
91 } |
2080 | 92 lba -= media->tracks[track].fake_pregap; |
93 if (lba < media->tracks[track].start_lba) { | |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
94 if (media->tracks[track].fake_pregap) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
95 media->in_fake_pregap = media->tracks[track].type == TRACK_DATA ? FAKE_DATA : FAKE_AUDIO; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
96 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
97 media->in_fake_pregap = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
98 } |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
99 break; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
100 } |
2080 | 101 if (lba < media->tracks[track].end_lba) { |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
102 media->in_fake_pregap = 0; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
103 break; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
104 } |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
105 } |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
106 if (track < media->num_tracks) { |
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
107 media->cur_track = track; |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
108 if (!media->in_fake_pregap) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
109 if (track) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
110 lba -= media->tracks[track - 1].end_lba; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
111 } |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
112 if (media->tracks[track].has_subcodes) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
113 if (!media->tmp_buffer) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
114 media->tmp_buffer = calloc(1, 96); |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
115 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
116 fseek(media->tracks[track].f, media->tracks[track].file_offset + (lba + 1) * media->tracks[track].sector_bytes - 96, SEEK_SET); |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
117 int bytes = fread(media->tmp_buffer, 1, 96, media->tracks[track].f); |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
118 if (bytes != 96) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
119 fprintf(stderr, "Only read %d subcode bytes\n", bytes); |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
120 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
121 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
122 fseek(media->tracks[track].f, media->tracks[track].file_offset + lba * media->tracks[track].sector_bytes, SEEK_SET); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
123 } |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
124 } |
2080 | 125 return track; |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
126 } |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
127 |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
128 static uint8_t fake_read(uint32_t sector, uint32_t offset) |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
129 { |
2142
d9151d0894c7
Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents:
2140
diff
changeset
|
130 if (!offset || offset == 11 || (offset >= 16)) { |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
131 return 0; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
132 //TODO: error detection and correction bytes |
2142
d9151d0894c7
Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents:
2140
diff
changeset
|
133 } else if (offset < 11) { |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
134 return 0xFF; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
135 } else if (offset == 12) { |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
136 uint32_t minute = (sector / 75) / 60; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
137 return (minute % 10) | ((minute / 10 ) << 4); |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
138 } else if (offset == 13) { |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
139 uint32_t seconds = (sector / 75) % 60; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
140 return (seconds % 10) | ((seconds / 10 ) << 4); |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
141 } else if (offset == 14) { |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
142 uint32_t frames = sector % 75; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
143 return (frames % 10) | ((frames / 10 ) << 4); |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
144 } else { |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
145 return 1; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
146 } |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
147 } |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
148 |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
149 static uint8_t bin_read(system_media *media, uint32_t offset) |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
150 { |
2080 | 151 if (media->in_fake_pregap == FAKE_DATA) { |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
152 return fake_read(media->cur_sector, offset); |
2080 | 153 } else if (media->in_fake_pregap == FAKE_AUDIO) { |
154 return 0; | |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
155 } else if ((media->tracks[media->cur_track].sector_bytes < 2352 && offset < 16) || offset > (media->tracks[media->cur_track].sector_bytes + 16)) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
156 return fake_read(media->cur_sector, offset); |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
157 } else { |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
158 if (media->tracks[media->cur_track].need_swap) { |
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
159 if (offset & 1) { |
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
160 return media->byte_storage; |
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
161 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
162 media->byte_storage = fgetc(media->tracks[media->cur_track].f); |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
163 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
164 return fgetc(media->tracks[media->cur_track].f); |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
165 } |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
166 } |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
167 |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
168 static uint8_t bin_subcode_read(system_media *media, uint32_t offset) |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
169 { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
170 if (media->in_fake_pregap || !media->tracks[media->cur_track].has_subcodes) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
171 //TODO: Fake PQ subcodes |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
172 return 0; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
173 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
174 //TODO: Translate "cooked" subcodes back to raw format |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
175 return media->tmp_buffer[offset]; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
176 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
177 |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 uint8_t parse_cue(system_media *media) |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 char *line = media->buffer; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 media->num_tracks = 0; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 do { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 char *cmd = cmd_start(line); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 if (cmd) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 if (startswith(cmd, "TRACK ")) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 media->num_tracks++; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 line = next_line(cmd); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 } else { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 line = NULL; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 } while (line); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 track_info *tracks = calloc(sizeof(track_info), media->num_tracks); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 media->tracks = tracks; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 line = media->buffer; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 int track = -1; |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
197 uint8_t audio_byte_swap = 0; |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
198 FILE *f = NULL; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
199 int track_of_file = -1; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
200 uint8_t has_index_0 = 0; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 do { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 char *cmd = cmd_start(line); |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
203 if (*cmd) { |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 if (startswith(cmd, "TRACK ")) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 track++; |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
206 track_of_file++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
207 has_index_0 = 0; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 cmd += 6; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 char *end; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 int file_track = strtol(cmd, &end, 10); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 if (file_track != (track + 1)) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 warning("Expected track %d, but found track %d in CUE sheet\n", track + 1, file_track); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
214 tracks[track].f = f; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
215 |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
216 |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 cmd = cmd_start(end); |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
218 if (*cmd) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
219 if (startswith(cmd, "AUDIO")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
220 tracks[track].type = TRACK_AUDIO; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
221 tracks[track].need_swap = audio_byte_swap; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
222 tracks[track].sector_bytes = 2352; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
223 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
224 tracks[track].type = TRACK_DATA; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
225 tracks[track].need_swap = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
226 tracks[track].sector_bytes = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
227 char *slash = strchr(cmd, '/'); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
228 if (slash) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
229 tracks[track].sector_bytes = atoi(slash+1); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
230 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
231 if (!tracks[track].sector_bytes) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
232 warning("Missing sector size for data track %d in cue", track + 1); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
233 tracks[track].sector_bytes = 2352; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
234 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
235 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
236 |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 } else if (startswith(cmd, "FILE ")) { |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
239 cmd += 5; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
240 cmd = strchr(cmd, '"'); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
241 if (cmd) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
242 cmd++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
243 char *end = strchr(cmd, '"'); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
244 if (end) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
245 char *fname; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
246 //TODO: zipped BIN/CUE support |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
247 if (is_absolute_path(cmd)) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
248 fname = malloc(end-cmd + 1); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
249 memcpy(fname, cmd, end-cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
250 fname[end-cmd] = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
251 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
252 size_t dirlen = strlen(media->dir); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
253 fname = malloc(dirlen + 1 + (end-cmd) + 1); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
254 memcpy(fname, media->dir, dirlen); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
255 fname[dirlen] = PATH_SEP[0]; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
256 memcpy(fname + dirlen + 1, cmd, end-cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
257 fname[dirlen + 1 + (end-cmd)] = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
258 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
259 f = fopen(fname, "rb"); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
260 if (!f) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
261 fatal_error("Failed to open %s specified by FILE command in CUE sheet %s.%s\n", fname, media->name, media->extension); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
262 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
263 free(fname); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
264 track_of_file = -1; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
265 for (end++; *end && *end != '\n' && *end != '\r'; end++) |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
266 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
267 if (!isspace(*end)) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
268 if (startswith(end, "BINARY")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
269 audio_byte_swap = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
270 } else if (startswith(end, "MOTOROLA")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
271 audio_byte_swap = 1; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
272 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
273 warning("Unsupported FILE type in CUE sheet. Only BINARY and MOTOROLA are supported\n"); |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
274 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
275 break; |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
276 } |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 } else if (track >= 0) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 if (startswith(cmd, "PREGAP ")) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 tracks[track].fake_pregap = timecode_to_lba(cmd + 7); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 } else if (startswith(cmd, "INDEX ")) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 char *after; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 int index = strtol(cmd + 6, &after, 10); |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
286 uint8_t has_start_lba = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
287 uint32_t start_lba; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 if (!index) { |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
289 tracks[track].pregap_lba = start_lba = timecode_to_lba(after); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
290 has_index_0 = 1; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
291 has_start_lba = 1; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 } else if (index == 1) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 tracks[track].start_lba = timecode_to_lba(after); |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
294 if (!has_index_0) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
295 start_lba = tracks[track].start_lba; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
296 has_start_lba = 1; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
297 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
298 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
299 if (has_start_lba) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
300 if (track > 0) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
301 tracks[track-1].end_lba = start_lba; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
302 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
303 if (track_of_file > 0) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
304 tracks[track].file_offset = tracks[track-1].file_offset + tracks[track-1].end_lba * tracks[track-1].sector_bytes; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
305 if (track_of_file > 1) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
306 tracks[track].file_offset -= tracks[track-2].end_lba * tracks[track-1].sector_bytes; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
307 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
308 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
309 tracks[track].file_offset = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
310 } |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
311 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
314 if (cmd && *cmd) { |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 line = next_line(cmd); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 } else { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 line = NULL; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 } else { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 line = NULL; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 } while (line); |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
323 if (media->num_tracks > 0 && media->tracks[0].f) { |
2143
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
324 //end of last track in a file is implictly based on the size |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
325 f = tracks[0].f; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
326 uint32_t offset = 0; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
327 for (int track = 0; track < media->num_tracks; track++) { |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
328 if (track == media->num_tracks - 1 && tracks[track].f) { |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
329 uint32_t start_lba =tracks[track].fake_pregap ? tracks[track].start_lba : tracks[track].pregap_lba; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
330 tracks[track].end_lba = start_lba + (file_size(tracks[track].f) - tracks[track].file_offset)/ tracks[track].sector_bytes; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
331 } else if (tracks[track].f != f) { |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
332 uint32_t start_lba =tracks[track-1].fake_pregap ? tracks[track-1].start_lba : tracks[track-1].pregap_lba; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
333 tracks[track-1].end_lba = start_lba + (file_size(tracks[track-1].f) - tracks[track-1].file_offset)/ tracks[track-1].sector_bytes; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
334 offset = tracks[track-1].end_lba; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
335 } |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
336 if (!tracks[track].fake_pregap) { |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
337 tracks[track].pregap_lba += offset; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
338 } |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
339 tracks[track].start_lba += offset; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
340 tracks[track].end_lba += offset; |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
341 } |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
342 //replace cue sheet with first sector |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 free(media->buffer); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 media->buffer = calloc(2048, 1); |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
345 if (tracks[0].type == TRACK_DATA && tracks[0].sector_bytes == 2352) { |
2062
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
346 // if the first track is a data track, don't trust the CUE sheet and look at the MM:SS:FF from first sector |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
347 uint8_t msf[3]; |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
348 fseek(tracks[0].f, 12, SEEK_SET); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
349 if (sizeof(msf) == fread(msf, 1, sizeof(msf), tracks[0].f)) { |
2062
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
350 tracks[0].fake_pregap = msf[2] + (msf[0] * 60 + msf[1]) * 75; |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
351 } |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
352 } else if (!tracks[0].start_lba && !tracks[0].fake_pregap) { |
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
353 tracks[0].fake_pregap = 2 * 75; |
2062
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
354 } |
07ed42bd7b4c
Some progress on CDC and CDD emulation. Now passes first 3 "CDC INIT" tests in mcd-verificator
Michael Pavone <pavone@retrodev.com>
parents:
2061
diff
changeset
|
355 |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
356 fseek(tracks[0].f, tracks[0].sector_bytes >= 2352 ? 16 : 0, SEEK_SET); |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
357 media->size = fread(media->buffer, 1, 2048, tracks[0].f); |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
358 media->seek = bin_seek; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
359 media->read = bin_read; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
360 media->read_subcodes = bin_subcode_read; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
362 uint8_t valid = media->num_tracks > 0 && media->tracks[0].f != NULL; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
363 media->type = valid ? MEDIA_CDROM : MEDIA_CART; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
364 return valid; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
365 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
366 |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
367 uint8_t parse_toc(system_media *media) |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
368 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
369 char *line = media->buffer; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
370 media->num_tracks = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
371 do { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
372 char *cmd = cmd_start(line); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
373 if (cmd) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
374 if (startswith(cmd, "TRACK ")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
375 media->num_tracks++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
376 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
377 line = next_line(cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
378 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
379 line = NULL; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
380 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
381 } while (line); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
382 track_info *tracks = calloc(sizeof(track_info), media->num_tracks); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
383 media->tracks = tracks; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
384 line = media->buffer; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
385 char *last_file_name = NULL; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
386 FILE *f = NULL; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
387 int track = -1; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
388 do { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
389 char *cmd = cmd_start(line); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
390 if (*cmd) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
391 if (startswith(cmd, "TRACK ")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
392 track++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
393 cmd = cmd_start(cmd + 6); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
394 if (startswith(cmd, "AUDIO")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
395 tracks[track].type = TRACK_AUDIO; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
396 tracks[track].sector_bytes = 2352; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
397 tracks[track].need_swap = 1; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
398 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
399 tracks[track].type = TRACK_DATA; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
400 tracks[track].need_swap = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
401 if (startswith(cmd, "MODE1_RAW") || startswith(cmd, "MODE2_RAW")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
402 tracks[track].sector_bytes = 2352; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
403 } else if (startswith(cmd, "MODE2_FORM2")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
404 tracks[track].sector_bytes = 2324; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
405 } else if (startswith(cmd, "MODE1") || startswith(cmd, "MODE2_FORM1")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
406 tracks[track].sector_bytes = 2048; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
407 } else if (startswith(cmd, "MODE2")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
408 tracks[track].sector_bytes = 2336; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
409 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
410 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
411 cmd = word_end(cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
412 if (*cmd && *cmd != '\n') { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
413 cmd = cmd_start_sameline(cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
414 if (*cmd && *cmd != '\n') { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
415 //TODO: record whether subcode is in raw format or not |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
416 if (startswith(cmd, "RW_RAW")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
417 tracks[track].sector_bytes += 96; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
418 tracks[track].has_subcodes = SUBCODES_RAW; |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
419 } else if (startswith(cmd, "RW")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
420 tracks[track].sector_bytes += 96; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
421 tracks[track].has_subcodes = SUBCODES_COOKED; |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
422 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
423 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
424 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
425 if (track) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
426 tracks[track].start_lba = tracks[track].pregap_lba = tracks[track].end_lba = tracks[track-1].end_lba; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
427 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
428 } else if (track >= 0) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
429 uint8_t is_datafile = startswith(cmd, "DATAFILE"); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
430 if (is_datafile || startswith(cmd, "FILE")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
431 |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
432 if (tracks[track].f) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
433 warning("TOC file has more than one file for track %d, only one is supported\n", track + 1); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
434 } else { |
2140
6d0de02a068a
Fix bug in TOC parser
Michael Pavone <pavone@retrodev.com>
parents:
2122
diff
changeset
|
435 cmd += is_datafile ? 8 : 4; |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
436 char *fname_start = strchr(cmd, '"'); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
437 if (fname_start) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
438 ++fname_start; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
439 char *fname_end = strchr(fname_start, '"'); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
440 if (fname_end) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
441 if (!last_file_name || strncmp(last_file_name, fname_start, fname_end-fname_start)) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
442 free(last_file_name); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
443 last_file_name = calloc(1, 1 + fname_end-fname_start); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
444 memcpy(last_file_name, fname_start, fname_end-fname_start); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
445 char *fname; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
446 //TODO: zipped BIN/TOC support |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
447 if (is_absolute_path(last_file_name)) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
448 fname = last_file_name; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
449 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
450 size_t dirlen = strlen(media->dir); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
451 fname = malloc(dirlen + 1 + (fname_end-fname_start) + 1); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
452 memcpy(fname, media->dir, dirlen); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
453 fname[dirlen] = PATH_SEP[0]; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
454 memcpy(fname + dirlen + 1, fname_start, fname_end-fname_start); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
455 fname[dirlen + 1 + (fname_end-fname_start)] = 0; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
456 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
457 f = fopen(fname, "rb"); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
458 if (!f) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
459 fatal_error("Failed to open %s specified by DATAFILE command in TOC file %s.%s\n", fname, media->name, media->extension); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
460 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
461 if (fname != last_file_name) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
462 free(fname); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
463 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
464 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
465 tracks[track].f = f; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
466 cmd = fname_end + 1; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
467 cmd = cmd_start_sameline(cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
468 if (*cmd == '#') { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
469 char *end; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
470 tracks[track].file_offset = strtol(cmd + 1, &end, 10); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
471 cmd = cmd_start_sameline(end); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
472 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
473 if (!is_datafile) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
474 if (isdigit(*cmd)) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
475 uint32_t start = timecode_to_lba(cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
476 tracks[track].file_offset += start * tracks[track].sector_bytes; |
2149
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
477 cmd = cmd_start_sameline(cmd); |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
478 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
479 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
480 if (isdigit(*cmd)) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
481 uint32_t length = timecode_to_lba(cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
482 tracks[track].end_lba += length; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
483 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
484 long fsize = file_size(f); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
485 tracks[track].end_lba += fsize - tracks[track].file_offset; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
486 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
487 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
488 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
489 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
490 } else if (startswith(cmd, "SILENCE")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
491 cmd = cmd_start_sameline(cmd + 7); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
492 tracks[track].fake_pregap += timecode_to_lba(cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
493 } else if (startswith(cmd, "START")) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
494 cmd = cmd_start_sameline(cmd + 5); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
495 tracks[track].start_lba = tracks[track].pregap_lba + timecode_to_lba(cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
496 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
497 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
498 if (cmd && *cmd) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
499 line = next_line(cmd); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
500 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
501 line = NULL; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
502 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
503 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
504 line = NULL; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
505 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
506 } while (line); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
507 if (media->num_tracks > 0 && media->tracks[0].f) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
508 //replace cue sheet with first sector |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
509 free(media->buffer); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
510 media->buffer = calloc(2048, 1); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
511 if (tracks[0].type == TRACK_DATA && tracks[0].sector_bytes == 2352) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
512 // if the first track is a data track, don't trust the TOC file and look at the MM:SS:FF from first sector |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
513 uint8_t msf[3]; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
514 fseek(tracks[0].f, 12, SEEK_SET); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
515 if (sizeof(msf) == fread(msf, 1, sizeof(msf), tracks[0].f)) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
516 tracks[0].fake_pregap = msf[2] + (msf[0] * 60 + msf[1]) * 75; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
517 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
518 } else if (!tracks[0].start_lba && !tracks[0].fake_pregap) { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
519 tracks[0].fake_pregap = 2 * 75; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
520 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
521 |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
522 fseek(tracks[0].f, tracks[0].sector_bytes == 2352 ? 16 : 0, SEEK_SET); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
523 media->size = fread(media->buffer, 1, 2048, tracks[0].f); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
524 media->seek = bin_seek; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
525 media->read = bin_read; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
526 media->read_subcodes = bin_subcode_read; |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
527 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
528 uint8_t valid = media->num_tracks > 0 && media->tracks[0].f != NULL; |
2061
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
2059
diff
changeset
|
529 media->type = valid ? MEDIA_CDROM : MEDIA_CART; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
2059
diff
changeset
|
530 return valid; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 } |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
532 |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
533 uint32_t make_iso_media(system_media *media, const char *filename) |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
534 { |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
535 FILE *f = fopen(filename, "rb"); |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
536 if (!f) { |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
537 return 0; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
538 } |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
539 media->buffer = calloc(2048, 1); |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
540 media->size = fread(media->buffer, 1, 2048, f); |
2079
5a2b759f6b2d
BIOS doesn't like it if TOC read happens too quickly
Michael Pavone <pavone@retrodev.com>
parents:
2076
diff
changeset
|
541 media->num_tracks = 1; |
5a2b759f6b2d
BIOS doesn't like it if TOC read happens too quickly
Michael Pavone <pavone@retrodev.com>
parents:
2076
diff
changeset
|
542 media->tracks = calloc(sizeof(track_info), 1); |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
543 media->tracks[0] = (track_info){ |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
544 .f = f, |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
545 .file_offset = 0, |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
546 .fake_pregap = 2 * 75, |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
547 .start_lba = 0, |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
548 .end_lba = file_size(f), |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
549 .sector_bytes = 2048, |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
550 .has_subcodes = SUBCODES_NONE, |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
551 .need_swap = 0, |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
552 .type = TRACK_DATA |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
553 }; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
554 media->type = MEDIA_CDROM; |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
555 media->seek = bin_seek; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
556 media->read = bin_read; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
557 media->read_subcodes = bin_subcode_read; |
2076
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
558 return media->size; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
559 } |