Mercurial > repos > blastem
annotate cdimage.c @ 2247:08a16de0e4cb
Fix settings save path of TMSS ROM setting
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 24 Nov 2022 00:54:18 -0800 |
parents | a8af8d898a7c |
children | 646d1797f20d |
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> |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2149
diff
changeset
|
3 #include <stdlib.h> |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "system.h" |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "util.h" |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 static char* cmd_start(char *cur) |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 while (*cur && isblank(*cur)) |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 cur++; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 return cur; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
17 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
|
18 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
19 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
|
20 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
21 cur++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
22 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
23 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
|
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 |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
26 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
|
27 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
28 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
|
29 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
30 cur++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
31 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
32 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
|
33 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
34 |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 static char* next_line(char *cur) |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 while (*cur && *cur != '\n') |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 cur++; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 if (*cur) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 return cur + 1; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 return NULL; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
47 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
|
48 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
49 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
|
50 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
51 cur++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
52 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
53 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
|
54 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
55 |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 static uint32_t timecode_to_lba(char *timecode) |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 char *end; |
2149
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
59 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
|
60 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
|
61 if (end && *end == ':') { |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 timecode = end + 1; |
2149
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
63 seconds = frames; |
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
64 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
|
65 if (end && *end == ':') { |
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
66 minutes = seconds; |
9209858b2f74
Fix a couple of bugs in the TOC file parser
Michael Pavone <pavone@retrodev.com>
parents:
2143
diff
changeset
|
67 seconds = frames; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 timecode = end + 1; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 frames = strtol(timecode, NULL, 10); |
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 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 seconds += minutes * 60; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 return seconds * 75 + frames; |
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 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 |
2080 | 77 enum { |
78 FAKE_DATA = 1, | |
79 FAKE_AUDIO, | |
80 }; | |
81 | |
82 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
|
83 { |
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 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
|
85 uint32_t lba = sector; |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
86 uint32_t track; |
2080 | 87 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
|
88 { |
2080 | 89 if (lba < media->tracks[track].fake_pregap) { |
90 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
|
91 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
|
92 } |
2080 | 93 lba -= media->tracks[track].fake_pregap; |
94 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
|
95 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
|
96 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
|
97 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
98 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
|
99 } |
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
|
100 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
|
101 } |
2080 | 102 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
|
103 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
|
104 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
|
105 } |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
106 } |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
107 if (track < media->num_tracks) { |
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 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
|
112 } |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
113 if (media->tracks[track].has_subcodes) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
114 if (!media->tmp_buffer) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
115 media->tmp_buffer = calloc(1, 96); |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
116 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
117 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
|
118 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
|
119 if (bytes != 96) { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
120 fprintf(stderr, "Only read %d subcode bytes\n", bytes); |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
121 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
122 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
123 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
|
124 } |
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
|
125 } |
2080 | 126 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
|
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 |
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 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
|
130 { |
2142
d9151d0894c7
Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents:
2140
diff
changeset
|
131 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
|
132 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
|
133 //TODO: error detection and correction bytes |
2142
d9151d0894c7
Fix some CD-ROM emulation issues
Michael Pavone <pavone@retrodev.com>
parents:
2140
diff
changeset
|
134 } 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
|
135 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
|
136 } 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
|
137 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
|
138 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
|
139 } 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
|
140 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
|
141 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
|
142 } 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
|
143 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
|
144 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
|
145 } 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
|
146 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
|
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 |
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 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
|
151 { |
2080 | 152 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
|
153 return fake_read(media->cur_sector, offset); |
2080 | 154 } else if (media->in_fake_pregap == FAKE_AUDIO) { |
155 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
|
156 } 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
|
157 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
|
158 } else { |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
159 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
|
160 if (offset & 1) { |
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
161 return media->byte_storage; |
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
162 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
163 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
|
164 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
165 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
|
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 } |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
168 |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
169 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
|
170 { |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
171 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
|
172 //TODO: Fake PQ subcodes |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
173 return 0; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
174 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
175 //TODO: Translate "cooked" subcodes back to raw format |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
176 return media->tmp_buffer[offset]; |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
177 } |
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
178 |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 uint8_t parse_cue(system_media *media) |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 char *line = media->buffer; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 media->num_tracks = 0; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 do { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 char *cmd = cmd_start(line); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 if (cmd) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 if (startswith(cmd, "TRACK ")) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 media->num_tracks++; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 line = next_line(cmd); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 } else { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 line = NULL; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 } while (line); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 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
|
195 media->tracks = tracks; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 line = media->buffer; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 int track = -1; |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
198 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
|
199 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
|
200 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
|
201 uint8_t has_index_0 = 0; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 do { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 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
|
204 if (*cmd) { |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 if (startswith(cmd, "TRACK ")) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 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
|
207 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
|
208 has_index_0 = 0; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 cmd += 6; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 char *end; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 int file_track = strtol(cmd, &end, 10); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 if (file_track != (track + 1)) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 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
|
214 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
215 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
|
216 |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
217 |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 } else { |
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].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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
232 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
|
233 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
|
234 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
|
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 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
237 |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 } 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
|
240 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
|
241 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
|
242 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
|
243 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 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
|
245 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
|
246 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
|
247 //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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
260 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
|
261 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
|
262 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
|
263 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
264 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
|
265 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
|
266 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
|
267 { |
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 (!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
|
269 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
|
270 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
|
271 } 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
|
272 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
|
273 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
274 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
|
275 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
276 break; |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
277 } |
2059
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 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 } else if (track >= 0) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 if (startswith(cmd, "PREGAP ")) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 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
|
284 } else if (startswith(cmd, "INDEX ")) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 char *after; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 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
|
287 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
|
288 uint32_t start_lba; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 has_start_lba = 1; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 } else if (index == 1) { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 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
|
295 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
|
296 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
|
297 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
|
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 } |
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 (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
|
301 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
|
302 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
|
303 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 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
|
308 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
309 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
310 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
|
311 } |
2059
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 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
315 if (cmd && *cmd) { |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 line = next_line(cmd); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 } else { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 line = NULL; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 } else { |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 line = NULL; |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 } |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 } 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
|
324 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
|
325 //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
|
326 f = tracks[0].f; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
327 uint32_t offset = 0; |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
328 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
|
329 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
|
330 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
|
331 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
|
332 } 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
|
333 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
|
334 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
|
335 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
|
336 } |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
337 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
|
338 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
|
339 } |
67f20f9188b0
Fix support for CUE sheets that refer to multiple files
Michael Pavone <pavone@retrodev.com>
parents:
2142
diff
changeset
|
340 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
|
341 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
|
342 } |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 //replace cue sheet with first sector |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 free(media->buffer); |
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 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
|
346 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
|
347 // 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 } |
2089
0db3af42dd72
Fix some byte order stuff for audio tracks
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
353 } 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
|
354 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
|
355 } |
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
|
356 |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
357 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
|
358 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
|
359 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
|
360 media->read = bin_read; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
361 media->read_subcodes = bin_subcode_read; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 } |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
363 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
|
364 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
|
365 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
|
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 |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
368 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
|
369 { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
370 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
|
371 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
|
372 do { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
373 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
|
374 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
|
375 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
|
376 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
|
377 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
378 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
|
379 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
380 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
|
381 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
382 } 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 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
|
389 do { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
390 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
|
391 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
|
392 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
|
393 track++; |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
394 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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 } else { |
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].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
|
401 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
|
402 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
|
403 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
|
404 } 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
|
405 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
|
406 } 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
|
407 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
|
408 } 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
|
409 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
|
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 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
412 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
|
413 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
|
414 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
|
415 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
|
416 //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
|
417 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
|
418 tracks[track].sector_bytes += 96; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
419 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
|
420 } 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
|
421 tracks[track].sector_bytes += 96; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
422 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
|
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 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
426 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
|
427 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
|
428 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
429 } 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
|
430 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
|
431 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
|
432 |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
433 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
|
434 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
|
435 } else { |
2140
6d0de02a068a
Fix bug in TOC parser
Michael Pavone <pavone@retrodev.com>
parents:
2122
diff
changeset
|
436 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
|
437 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
|
438 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
|
439 ++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 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 //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
|
448 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
|
449 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
|
450 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
451 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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
458 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
|
459 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
|
460 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
|
461 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
462 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
|
463 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
|
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 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
466 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 } |
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 (!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
|
475 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
|
476 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
|
477 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
|
478 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
|
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 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
481 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
|
482 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
|
483 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
|
484 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
485 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
|
486 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
|
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 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
491 } 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
|
492 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
|
493 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
|
494 } 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
|
495 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
|
496 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
|
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 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
499 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
|
500 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
|
501 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
502 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
|
503 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
504 } else { |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
505 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
|
506 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
507 } 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
|
508 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
|
509 //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
|
510 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
|
511 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
|
512 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
|
513 // 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
519 } 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
|
520 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
|
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 |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
523 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
|
524 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
|
525 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
|
526 media->read = bin_read; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
527 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
|
528 } |
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
529 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
|
530 media->type = valid ? MEDIA_CDROM : MEDIA_CART; |
7c1760b5b3e5
Implemented basic TOC functionality of CDD MCU
Michael Pavone <pavone@retrodev.com>
parents:
2059
diff
changeset
|
531 return valid; |
2059
6399a776e981
Add basic support for BIN/CUE images
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 } |
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
|
533 |
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 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
|
535 { |
2114
2449c88cea36
Enhance support for CUE files and add initial support for cdrdao TOC files
Michael Pavone <pavone@retrodev.com>
parents:
2089
diff
changeset
|
536 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
|
537 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
|
538 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
|
539 } |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
540 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
|
541 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
|
542 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
|
543 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
|
544 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
|
545 .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
|
546 .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
|
547 .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
|
548 .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
|
549 .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
|
550 .sector_bytes = 2048, |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
551 .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
|
552 .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
|
553 .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
|
554 }; |
3f29e2726522
Added basic support for ISO images for games that only have a data track
Michael Pavone <pavone@retrodev.com>
parents:
2074
diff
changeset
|
555 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
|
556 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
|
557 media->read = bin_read; |
2116
cd057d6fe030
Initial stab at subcode emulation
Michael Pavone <pavone@retrodev.com>
parents:
2114
diff
changeset
|
558 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
|
559 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
|
560 } |