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