4 * Global cdrom definitions.
6 * Copyright (c) 2009 Nathan Keynes.
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.
20 #define cdrom_defs_H 1
24 #include <glib/gtypes.h>
31 typedef uint32_t cdrom_lba_t;
32 typedef uint32_t cdrom_count_t;
34 /** Tracks are numbered 1..99, with 0 reserved for errors */
35 typedef uint8_t cdrom_trackno_t;
37 typedef uint8_t cdrom_sessionno_t;
39 typedef const struct cdrom_track *cdrom_track_t;
40 typedef struct cdrom_disc *cdrom_disc_t;
42 /** sector read mode - values are based on the MMC READ CD command. */
43 typedef uint16_t cdrom_read_mode_t;
44 #define CDROM_READ_ANY (0<<2)
45 #define CDROM_READ_CDDA (1<<2)
46 #define CDROM_READ_MODE1 (2<<2)
47 #define CDROM_READ_MODE2 (3<<2)
48 #define CDROM_READ_MODE2_FORM1 (4<<2)
49 #define CDROM_READ_MODE2_FORM2 (5<<2)
51 #define CDROM_READ_NONE 0x0000
52 #define CDROM_READ_SYNC 0x8000
53 #define CDROM_READ_DATA 0x1000
54 #define CDROM_READ_ECC 0x0800
55 #define CDROM_READ_HEADER 0x2000
56 #define CDROM_READ_SUBHEADER 0x4000
57 #define CDROM_READ_RAW 0xF800 /* Read full sector */
58 #define CDROM_READ_TYPE(x) ((x) & 0x1C)
59 #define CDROM_READ_FIELDS(x) ((x) & 0xF800)
61 /** Actual sector mode */
63 SECTOR_UNKNOWN, // Unknown sector mode
64 SECTOR_CDDA, // Standard audio track
66 SECTOR_MODE1, // Standard CD-Rom Mode 1 data track
67 SECTOR_MODE2_FORMLESS, // Mode 2 data track with no sub-structure (rare)
68 SECTOR_MODE2_FORM1, // Mode 2/Form 1 data track (standard for multisession)
69 SECTOR_MODE2_FORM2, // Mode 2/Form 2 data track (also fairly uncommon).
71 /* 2336-byte Mode 2 XA sector with subheader and ecc data */
73 /* 2352-byte raw data sector in an XA session */
75 /* 2352-byte raw data sector in a non-XA session */
80 extern const uint32_t cdrom_sector_size[];
81 extern const uint32_t cdrom_sector_read_mode[];
82 #define CDROM_MAX_SECTOR_SIZE 2352
83 #define CDROM_MAX_TRACKS 99
84 #define CDROM_MSF_START 150 /* MSF numbering starts after the initial pregap */
85 #define CDROM_FRAMES_PER_SECOND 75
86 #define CDROM_SECONDS_PER_MINUTE 60
87 #define CDROM_FRAMES_PER_MINUTE (CDROM_FRAMES_PER_SECOND*CDROM_SECONDS_PER_MINUTE)
88 #define CDROM_PREGAP 150 /* Standard pregap, in frames */
89 #define CDROM_SECTOR_SIZE(x) cdrom_sector_size[x]
90 #define CDROM_SECTOR_READ_MODE(x) cdrom_sector_read_mode[x]
91 #define MSFTOLBA( m,s,f ) ((f) + ((s)*CDROM_FRAMES_PER_SECOND) + ((m)*CDROM_FRAMES_PER_MINUTE) - CDROM_MSF_START)
94 * Convert an 8-bit BCD number to integer form.
97 uint8_t static inline BCDTOU8( uint8_t bcd )
99 return (bcd & 0x0F) + (((bcd & 0xF0)>>4)*10);
103 * Convert a 32 bit BCD-encoded MSF address to the
104 * equivalent LBA form.
107 cdrom_lba_t static inline BCD_MSFTOLBA( uint32_t msf )
109 msf = GUINT32_FROM_BE(msf);
110 int f = BCDTOU8(msf);
111 int s = BCDTOU8(msf>>8);
112 int m = BCDTOU8(msf>>16);
113 return MSFTOLBA(m,s,f);
117 typedef uint8_t cdrom_type_t;
118 #define CDROM_TYPE_NONXA 0x00 /* Audio or straight mode-1 data */
119 #define CDROM_TYPE_CDI 0x10
120 #define CDROM_TYPE_XA 0x20
121 #define CDROM_TYPE_GD 0x80 /* SEGA only */
124 /* Error codes are defined as MMC sense data - low byte is the sense key,
125 * next byte, is the ASC code, and third byte is the ASCQ (not currently used)
127 typedef uint32_t cdrom_error_t;
128 #define CDROM_ERROR_OK 0x0000
129 #define CDROM_ERROR_NODISC 0x3A02
130 #define CDROM_ERROR_BADCMD 0x2005
131 #define CDROM_ERROR_BADFIELD 0x2405
132 #define CDROM_ERROR_BADREAD 0x3002
133 #define CDROM_ERROR_BADREADMODE 0x6405 /* Illegal mode for this track */
134 #define CDROM_ERROR_READERROR 0x1103 /* Read failed due to uncorrectable error */
135 #define CDROM_ERROR_RESET 0x2906
141 #endif /* !cdrom_defs_H */
.