root / hw / cdrom.c @ a06e5a3c
History | View | Annotate | Download (4.1 kB)
1 |
/*
|
---|---|
2 |
* QEMU ATAPI CD-ROM Emulator
|
3 |
*
|
4 |
* Copyright (c) 2006 Fabrice Bellard
|
5 |
*
|
6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 |
* of this software and associated documentation files (the "Software"), to deal
|
8 |
* in the Software without restriction, including without limitation the rights
|
9 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 |
* copies of the Software, and to permit persons to whom the Software is
|
11 |
* furnished to do so, subject to the following conditions:
|
12 |
*
|
13 |
* The above copyright notice and this permission notice shall be included in
|
14 |
* all copies or substantial portions of the Software.
|
15 |
*
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 |
* THE SOFTWARE.
|
23 |
*/
|
24 |
|
25 |
/* ??? Most of the ATAPI emulation is still in ide.c. It should be moved
|
26 |
here. */
|
27 |
|
28 |
#include <vl.h> |
29 |
|
30 |
static void lba_to_msf(uint8_t *buf, int lba) |
31 |
{ |
32 |
lba += 150;
|
33 |
buf[0] = (lba / 75) / 60; |
34 |
buf[1] = (lba / 75) % 60; |
35 |
buf[2] = lba % 75; |
36 |
} |
37 |
|
38 |
/* same toc as bochs. Return -1 if error or the toc length */
|
39 |
/* XXX: check this */
|
40 |
int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track) |
41 |
{ |
42 |
uint8_t *q; |
43 |
int len;
|
44 |
|
45 |
if (start_track > 1 && start_track != 0xaa) |
46 |
return -1; |
47 |
q = buf + 2;
|
48 |
*q++ = 1; /* first session */ |
49 |
*q++ = 1; /* last session */ |
50 |
if (start_track <= 1) { |
51 |
*q++ = 0; /* reserved */ |
52 |
*q++ = 0x14; /* ADR, control */ |
53 |
*q++ = 1; /* track number */ |
54 |
*q++ = 0; /* reserved */ |
55 |
if (msf) {
|
56 |
*q++ = 0; /* reserved */ |
57 |
lba_to_msf(q, 0);
|
58 |
q += 3;
|
59 |
} else {
|
60 |
/* sector 0 */
|
61 |
cpu_to_be32wu((uint32_t *)q, 0);
|
62 |
q += 4;
|
63 |
} |
64 |
} |
65 |
/* lead out track */
|
66 |
*q++ = 0; /* reserved */ |
67 |
*q++ = 0x16; /* ADR, control */ |
68 |
*q++ = 0xaa; /* track number */ |
69 |
*q++ = 0; /* reserved */ |
70 |
if (msf) {
|
71 |
*q++ = 0; /* reserved */ |
72 |
lba_to_msf(q, nb_sectors); |
73 |
q += 3;
|
74 |
} else {
|
75 |
cpu_to_be32wu((uint32_t *)q, nb_sectors); |
76 |
q += 4;
|
77 |
} |
78 |
len = q - buf; |
79 |
cpu_to_be16wu((uint16_t *)buf, len - 2);
|
80 |
return len;
|
81 |
} |
82 |
|
83 |
/* mostly same info as PearPc */
|
84 |
int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num) |
85 |
{ |
86 |
uint8_t *q; |
87 |
int len;
|
88 |
|
89 |
q = buf + 2;
|
90 |
*q++ = 1; /* first session */ |
91 |
*q++ = 1; /* last session */ |
92 |
|
93 |
*q++ = 1; /* session number */ |
94 |
*q++ = 0x14; /* data track */ |
95 |
*q++ = 0; /* track number */ |
96 |
*q++ = 0xa0; /* lead-in */ |
97 |
*q++ = 0; /* min */ |
98 |
*q++ = 0; /* sec */ |
99 |
*q++ = 0; /* frame */ |
100 |
*q++ = 0;
|
101 |
*q++ = 1; /* first track */ |
102 |
*q++ = 0x00; /* disk type */ |
103 |
*q++ = 0x00;
|
104 |
|
105 |
*q++ = 1; /* session number */ |
106 |
*q++ = 0x14; /* data track */ |
107 |
*q++ = 0; /* track number */ |
108 |
*q++ = 0xa1;
|
109 |
*q++ = 0; /* min */ |
110 |
*q++ = 0; /* sec */ |
111 |
*q++ = 0; /* frame */ |
112 |
*q++ = 0;
|
113 |
*q++ = 1; /* last track */ |
114 |
*q++ = 0x00;
|
115 |
*q++ = 0x00;
|
116 |
|
117 |
*q++ = 1; /* session number */ |
118 |
*q++ = 0x14; /* data track */ |
119 |
*q++ = 0; /* track number */ |
120 |
*q++ = 0xa2; /* lead-out */ |
121 |
*q++ = 0; /* min */ |
122 |
*q++ = 0; /* sec */ |
123 |
*q++ = 0; /* frame */ |
124 |
if (msf) {
|
125 |
*q++ = 0; /* reserved */ |
126 |
lba_to_msf(q, nb_sectors); |
127 |
q += 3;
|
128 |
} else {
|
129 |
cpu_to_be32wu((uint32_t *)q, nb_sectors); |
130 |
q += 4;
|
131 |
} |
132 |
|
133 |
*q++ = 1; /* session number */ |
134 |
*q++ = 0x14; /* ADR, control */ |
135 |
*q++ = 0; /* track number */ |
136 |
*q++ = 1; /* point */ |
137 |
*q++ = 0; /* min */ |
138 |
*q++ = 0; /* sec */ |
139 |
*q++ = 0; /* frame */ |
140 |
if (msf) {
|
141 |
*q++ = 0;
|
142 |
lba_to_msf(q, 0);
|
143 |
q += 3;
|
144 |
} else {
|
145 |
*q++ = 0;
|
146 |
*q++ = 0;
|
147 |
*q++ = 0;
|
148 |
*q++ = 0;
|
149 |
} |
150 |
|
151 |
len = q - buf; |
152 |
cpu_to_be16wu((uint16_t *)buf, len - 2);
|
153 |
return len;
|
154 |
} |
155 |
|
156 |
|