2 * QEMU ATAPI CD-ROM Emulator
4 * Copyright (c) 2006 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 /* ??? Most of the ATAPI emulation is still in ide.c. It should be moved
30 static void lba_to_msf(uint8_t *buf
, int lba
)
33 buf
[0] = (lba
/ 75) / 60;
34 buf
[1] = (lba
/ 75) % 60;
38 /* same toc as bochs. Return -1 if error or the toc length */
40 int cdrom_read_toc(int nb_sectors
, uint8_t *buf
, int msf
, int start_track
)
45 if (start_track
> 1 && start_track
!= 0xaa)
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 */
56 *q
++ = 0; /* reserved */
61 cpu_to_be32wu((uint32_t *)q
, 0);
66 *q
++ = 0; /* reserved */
67 *q
++ = 0x16; /* ADR, control */
68 *q
++ = 0xaa; /* track number */
69 *q
++ = 0; /* reserved */
71 *q
++ = 0; /* reserved */
72 lba_to_msf(q
, nb_sectors
);
75 cpu_to_be32wu((uint32_t *)q
, nb_sectors
);
79 cpu_to_be16wu((uint16_t *)buf
, len
- 2);
83 /* mostly same info as PearPc */
84 int cdrom_read_toc_raw(int nb_sectors
, uint8_t *buf
, int msf
, int session_num
)
90 *q
++ = 1; /* first session */
91 *q
++ = 1; /* last session */
93 *q
++ = 1; /* session number */
94 *q
++ = 0x14; /* data track */
95 *q
++ = 0; /* track number */
96 *q
++ = 0xa0; /* lead-in */
101 *q
++ = 1; /* first track */
102 *q
++ = 0x00; /* disk type */
105 *q
++ = 1; /* session number */
106 *q
++ = 0x14; /* data track */
107 *q
++ = 0; /* track number */
111 *q
++ = 0; /* frame */
113 *q
++ = 1; /* last track */
117 *q
++ = 1; /* session number */
118 *q
++ = 0x14; /* data track */
119 *q
++ = 0; /* track number */
120 *q
++ = 0xa2; /* lead-out */
123 *q
++ = 0; /* frame */
125 *q
++ = 0; /* reserved */
126 lba_to_msf(q
, nb_sectors
);
129 cpu_to_be32wu((uint32_t *)q
, nb_sectors
);
133 *q
++ = 1; /* session number */
134 *q
++ = 0x14; /* ADR, control */
135 *q
++ = 0; /* track number */
136 *q
++ = 1; /* point */
139 *q
++ = 0; /* frame */
152 cpu_to_be16wu((uint16_t *)buf
, len
- 2);