2 * Copyright (c) 2010, Wei Mingzhi <whistler@openoffice.org>.
5 * Based on: Cdrom for Psemu Pro like Emulators
6 * By: linuzappz <linuzappz@hotmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses>.
32 #define _(x) gettext(x)
43 #include <sys/ioctl.h>
50 #include "psemu_plugin_defs.h"
52 #if defined (__linux__)
54 #include <linux/cdrom.h>
55 #include <scsi/scsi.h>
58 #ifndef CDROMSETSPINDOWN
59 #define CDROMSETSPINDOWN 0x531e
62 #define DEV_DEF "/dev/cdrom"
67 unsigned char cdmsf_min0; /* start minute */
68 unsigned char cdmsf_sec0; /* start second */
69 unsigned char cdmsf_frame0; /* start frame */
70 unsigned char cdmsf_min1; /* end minute */
71 unsigned char cdmsf_sec1; /* end second */
72 unsigned char cdmsf_frame1; /* end frame */
77 #define CD_MSF_OFFSET 150
78 #define CD_FRAMESIZE_SUB 96
80 #if defined (__FreeBSD__)
81 #define DEV_DEF "/dev/cd0"
86 #if !defined (USE_LIBCDIO) && !defined (_MACOSX)
92 extern char CdromDev[256];
95 extern long CacheSize;
103 #ifndef CD_FRAMESIZE_RAW
104 #define CD_FRAMESIZE_RAW 2352
107 #define DATA_SIZE (CD_FRAMESIZE_RAW - 12)
110 #define SPINDOWN_VENDOR_SPECIFIC 0x00
111 #define SPINDOWN_125MS 0x01
112 #define SPINDOWN_250MS 0x02
113 #define SPINDOWN_500MS 0x03
114 #define SPINDOWN_1S 0x04
115 #define SPINDOWN_2S 0x05
116 #define SPINDOWN_4S 0x06
117 #define SPINDOWN_8S 0x07
118 #define SPINDOWN_16S 0x08
119 #define SPINDOWN_32S 0x09
120 #define SPINDOWN_1MIN 0x0A
121 #define SPINDOWN_2MIN 0x0B
122 #define SPINDOWN_4MIN 0x0C
123 #define SPINDOWN_8MIN 0x0D
124 #define SPINDOWN_16MIN 0x0E
125 #define SPINDOWN_32MIN 0x0F
127 typedef struct _MMC_READ_CD {
128 unsigned char Code; // 0xBE
130 unsigned char RelativeAddress : 1;
132 unsigned char ExpectedSectorType : 3;
133 unsigned char Lun : 3;
135 unsigned char StartingLBA[4];
136 unsigned char TransferBlocks[3];
139 unsigned char ErrorFlags : 2;
140 unsigned char IncludeEDC : 1;
141 unsigned char IncludeUserData : 1;
142 unsigned char HeaderCode : 2;
143 unsigned char IncludeSyncData : 1;
145 unsigned char SubChannelSelection : 3;
151 #define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */
152 #define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */
156 unsigned long Status;
157 unsigned char Time[3]; // current playing time
162 unsigned char ControlAndADR;
163 unsigned char TrackNumber;
164 unsigned char IndexNumber;
165 unsigned char TrackRelativeAddress[3];
166 unsigned char Filler;
167 unsigned char AbsoluteAddress[3];
168 unsigned char CRC[2];
173 struct cdrom_msf msf;
174 unsigned char buf[CD_FRAMESIZE_RAW];
184 unsigned char* GetBNormal();
185 unsigned char* GetBThreaded();
193 #define PRINTF printf
195 #define PRINTF(...) /* */
198 unsigned int msf_to_lba(char m, char s, char f);
199 void lba_to_msf(unsigned int s, unsigned char *msf);
200 void DecodeRawSubData(unsigned char *subbuffer);
201 unsigned short calcCrc(unsigned char *d, int len);
204 void CloseCdHandle();
205 int IsCdHandleOpen();
206 long GetTN(unsigned char *buffer);
207 long GetTD(unsigned char track, unsigned char *buffer);
208 long GetTE(unsigned char track, unsigned char *m, unsigned char *s, unsigned char *f);
209 long ReadSector(crdata *cr);
210 long PlayCDDA(unsigned char *sector);
212 long GetStatus(int playing, struct CdrStat *stat);
213 unsigned char *ReadSub(const unsigned char *time);