-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
123 lines (92 loc) · 2.21 KB
/
main.c
File metadata and controls
123 lines (92 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// SPDX-License-Identifier: MIT
// Sample code for parsing and loading a BIN/CUE disc image
// and then reading a sector
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "cue.h"
static const char* m_cue_keywords[] = {
"4CH",
"AIFF",
"AUDIO",
"BINARY",
"CATALOG",
"CDG",
"CDI/2336",
"CDI/2352",
"CDTEXTFILE",
"DCP",
"FILE",
"FLAGS",
"INDEX",
"ISRC",
"MODE1/2048",
"MODE1/2352",
"MODE2/2336",
"MODE2/2352",
"MOTOROLA",
"MP3",
"PERFORMER",
"POSTGAP",
"PRE",
"PREGAP",
"REM",
"SCMS",
"SONGWRITER",
"TITLE",
"TRACK",
"WAVE",
0
};
#define MSF_TO_LBA(m, s, f) ((m * 4500) + (s * 75) + f)
int main(int argc, const char* argv[]) {
struct cue_state* cue = cue_create();
cue_init(cue);
int r = cue_parse(cue, argv[1]);
if (r) {
printf("Couldn't parse CUE file \"%s\" (%u)\n", argv[1], r);
return r;
}
printf("Parsed CUE file \'%s\'. Track count: %llu\n",
argv[1],
cue->tracks->size
);
r = cue_load(cue, LD_FILE);
if (r) {
printf("Couldn't load CUE image \"%s\" (%u)\n", argv[1], r);
return r;
}
printf("Loaded CUE image\n");
node_t* track = list_front(cue->tracks);
while (track) {
struct cue_track* ct = track->data;
printf(" track %u: mode=%s start=%u end=%u pregap=%u in \'%s\'\n",
ct->number,
m_cue_keywords[ct->mode],
ct->start,
ct->end,
ct->pregap,
ct->file->name
);
track = track->next;
}
uint8_t* buf = malloc(2352);
int lba = MSF_TO_LBA(0, 2, 16);
cue_read(cue, lba, buf);
for (int y = 0; y < 0x10; y++) {
printf("%08x: ", ((lba - 150) * 0x930) + (y << 4));
for (int x = 0; x < 0x10; x++) {
printf("%02x ", buf[x + (y * 0x10)]);
}
putchar('|');
for (int x = 0; x < 0x10; x++) {
printf("%c", isprint(buf[x + (y * 0x10)]) ? buf[x + (y * 0x10)] : '.');
}
printf("|\n");
}
free(buf);
printf("Destroying CUE... ");
cue_destroy(cue);
printf("done\n");
return 0;
}