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#include "qemu-common.h"
29#include "scsi.h"
30
31static void lba_to_msf(uint8_t *buf, int lba)
32{
33 lba += 150;
34 buf[0] = (lba / 75) / 60;
35 buf[1] = (lba / 75) % 60;
36 buf[2] = lba % 75;
37}
38
39
40
41int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track)
42{
43 uint8_t *q;
44 int len;
45
46 if (start_track > 1 && start_track != 0xaa)
47 return -1;
48 q = buf + 2;
49 *q++ = 1;
50 *q++ = 1;
51 if (start_track <= 1) {
52 *q++ = 0;
53 *q++ = 0x14;
54 *q++ = 1;
55 *q++ = 0;
56 if (msf) {
57 *q++ = 0;
58 lba_to_msf(q, 0);
59 q += 3;
60 } else {
61
62 cpu_to_be32wu((uint32_t *)q, 0);
63 q += 4;
64 }
65 }
66
67 *q++ = 0;
68 *q++ = 0x16;
69 *q++ = 0xaa;
70 *q++ = 0;
71 if (msf) {
72 *q++ = 0;
73 lba_to_msf(q, nb_sectors);
74 q += 3;
75 } else {
76 cpu_to_be32wu((uint32_t *)q, nb_sectors);
77 q += 4;
78 }
79 len = q - buf;
80 cpu_to_be16wu((uint16_t *)buf, len - 2);
81 return len;
82}
83
84
85int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num)
86{
87 uint8_t *q;
88 int len;
89
90 q = buf + 2;
91 *q++ = 1;
92 *q++ = 1;
93
94 *q++ = 1;
95 *q++ = 0x14;
96 *q++ = 0;
97 *q++ = 0xa0;
98 *q++ = 0;
99 *q++ = 0;
100 *q++ = 0;
101 *q++ = 0;
102 *q++ = 1;
103 *q++ = 0x00;
104 *q++ = 0x00;
105
106 *q++ = 1;
107 *q++ = 0x14;
108 *q++ = 0;
109 *q++ = 0xa1;
110 *q++ = 0;
111 *q++ = 0;
112 *q++ = 0;
113 *q++ = 0;
114 *q++ = 1;
115 *q++ = 0x00;
116 *q++ = 0x00;
117
118 *q++ = 1;
119 *q++ = 0x14;
120 *q++ = 0;
121 *q++ = 0xa2;
122 *q++ = 0;
123 *q++ = 0;
124 *q++ = 0;
125 if (msf) {
126 *q++ = 0;
127 lba_to_msf(q, nb_sectors);
128 q += 3;
129 } else {
130 cpu_to_be32wu((uint32_t *)q, nb_sectors);
131 q += 4;
132 }
133
134 *q++ = 1;
135 *q++ = 0x14;
136 *q++ = 0;
137 *q++ = 1;
138 *q++ = 0;
139 *q++ = 0;
140 *q++ = 0;
141 if (msf) {
142 *q++ = 0;
143 lba_to_msf(q, 0);
144 q += 3;
145 } else {
146 *q++ = 0;
147 *q++ = 0;
148 *q++ = 0;
149 *q++ = 0;
150 }
151
152 len = q - buf;
153 cpu_to_be16wu((uint16_t *)buf, len - 2);
154 return len;
155}
156