Search
lxdream.org :: lxdream/src/drivers/cdrom/defs.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/cdrom/defs.h
changeset 1296:30ecee61f811
prev1178:e55ec927d55d
author nkeynes
date Sat Jan 26 14:00:48 2013 +1000 (9 years ago)
permissions -rw-r--r--
last change Change glib includes to #include <glib.h> rather than the individual
headers, as recent glib versions are breaking on this
file annotate diff log raw
nkeynes@1097
     1
/**
nkeynes@1097
     2
 * $Id$
nkeynes@1097
     3
 *
nkeynes@1097
     4
 * Global cdrom definitions.
nkeynes@1097
     5
 *
nkeynes@1097
     6
 * Copyright (c) 2009 Nathan Keynes.
nkeynes@1097
     7
 *
nkeynes@1097
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@1097
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@1097
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@1097
    11
 * (at your option) any later version.
nkeynes@1097
    12
 *
nkeynes@1097
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@1097
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@1097
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@1097
    16
 * GNU General Public License for more details.
nkeynes@1097
    17
 */
nkeynes@1097
    18
nkeynes@1097
    19
#ifndef cdrom_defs_H
nkeynes@1097
    20
#define cdrom_defs_H 1
nkeynes@1097
    21
nkeynes@1097
    22
#include "lxdream.h"
nkeynes@1097
    23
#include <stdint.h>
nkeynes@1296
    24
#include <glib.h>
nkeynes@1097
    25
nkeynes@1097
    26
nkeynes@1097
    27
#ifdef __cplusplus
nkeynes@1097
    28
extern "C" {
nkeynes@1097
    29
#endif
nkeynes@1097
    30
nkeynes@1097
    31
typedef uint32_t cdrom_lba_t;
nkeynes@1097
    32
typedef uint32_t cdrom_count_t;
nkeynes@1097
    33
nkeynes@1097
    34
/** Tracks are numbered 1..99, with 0 reserved for errors */
nkeynes@1097
    35
typedef uint8_t  cdrom_trackno_t;
nkeynes@1097
    36
nkeynes@1097
    37
typedef uint8_t  cdrom_sessionno_t;
nkeynes@1097
    38
nkeynes@1097
    39
typedef const struct cdrom_track *cdrom_track_t;
nkeynes@1097
    40
typedef struct cdrom_disc *cdrom_disc_t;
nkeynes@1097
    41
nkeynes@1097
    42
/** sector read mode - values are based on the MMC READ CD command. */
nkeynes@1097
    43
typedef uint16_t cdrom_read_mode_t;
nkeynes@1097
    44
#define CDROM_READ_ANY         (0<<2)
nkeynes@1097
    45
#define CDROM_READ_CDDA        (1<<2)
nkeynes@1097
    46
#define CDROM_READ_MODE1       (2<<2)
nkeynes@1097
    47
#define CDROM_READ_MODE2       (3<<2)
nkeynes@1097
    48
#define CDROM_READ_MODE2_FORM1 (4<<2)
nkeynes@1097
    49
#define CDROM_READ_MODE2_FORM2 (5<<2)
nkeynes@1097
    50
nkeynes@1097
    51
#define CDROM_READ_NONE      0x0000
nkeynes@1097
    52
#define CDROM_READ_SYNC      0x8000
nkeynes@1097
    53
#define CDROM_READ_DATA      0x1000
nkeynes@1097
    54
#define CDROM_READ_ECC       0x0800
nkeynes@1097
    55
#define CDROM_READ_HEADER    0x2000
nkeynes@1097
    56
#define CDROM_READ_SUBHEADER 0x4000
nkeynes@1097
    57
#define CDROM_READ_RAW       0xF800 /* Read full sector */
nkeynes@1097
    58
#define CDROM_READ_TYPE(x)   ((x) & 0x1C)
nkeynes@1097
    59
#define CDROM_READ_FIELDS(x) ((x) & 0xF800)
nkeynes@1097
    60
nkeynes@1097
    61
/** Actual sector mode */
nkeynes@1097
    62
typedef enum {
nkeynes@1097
    63
    SECTOR_UNKNOWN,        // Unknown sector mode
nkeynes@1097
    64
    SECTOR_CDDA,           // Standard audio track
nkeynes@1097
    65
    /* Data-only modes */
nkeynes@1097
    66
    SECTOR_MODE1,          // Standard CD-Rom Mode 1 data track
nkeynes@1097
    67
    SECTOR_MODE2_FORMLESS, // Mode 2 data track with no sub-structure (rare)
nkeynes@1097
    68
    SECTOR_MODE2_FORM1,    // Mode 2/Form 1 data track (standard for multisession)
nkeynes@1097
    69
    SECTOR_MODE2_FORM2,    // Mode 2/Form 2 data track (also fairly uncommon).
nkeynes@1097
    70
nkeynes@1097
    71
    /* 2336-byte Mode 2 XA sector with subheader and ecc data */
nkeynes@1097
    72
    SECTOR_SEMIRAW_MODE2,
nkeynes@1097
    73
    /* 2352-byte raw data sector in an XA session */
nkeynes@1097
    74
    SECTOR_RAW_XA,
nkeynes@1097
    75
    /* 2352-byte raw data sector in a non-XA session */
nkeynes@1097
    76
    SECTOR_RAW_NONXA,
nkeynes@1178
    77
    /* CDDA + subchannel data */
nkeynes@1178
    78
    SECTOR_CDDA_SUBCHANNEL
nkeynes@1097
    79
} sector_mode_t;
nkeynes@1097
    80
nkeynes@1097
    81
nkeynes@1097
    82
extern const uint32_t cdrom_sector_size[];
nkeynes@1097
    83
extern const uint32_t cdrom_sector_read_mode[];
nkeynes@1097
    84
#define CDROM_MAX_SECTOR_SIZE    2352
nkeynes@1097
    85
#define CDROM_MAX_TRACKS         99
nkeynes@1097
    86
#define CDROM_MSF_START          150 /* MSF numbering starts after the initial pregap */
nkeynes@1097
    87
#define CDROM_FRAMES_PER_SECOND  75
nkeynes@1097
    88
#define CDROM_SECONDS_PER_MINUTE 60
nkeynes@1097
    89
#define CDROM_FRAMES_PER_MINUTE  (CDROM_FRAMES_PER_SECOND*CDROM_SECONDS_PER_MINUTE)
nkeynes@1097
    90
#define CDROM_PREGAP             150  /* Standard pregap, in frames */
nkeynes@1097
    91
#define CDROM_SECTOR_SIZE(x)     cdrom_sector_size[x]
nkeynes@1097
    92
#define CDROM_SECTOR_READ_MODE(x) cdrom_sector_read_mode[x]
nkeynes@1097
    93
#define MSFTOLBA( m,s,f ) ((f) + ((s)*CDROM_FRAMES_PER_SECOND) + ((m)*CDROM_FRAMES_PER_MINUTE) - CDROM_MSF_START)
nkeynes@1097
    94
nkeynes@1097
    95
/**
nkeynes@1097
    96
 * Convert an 8-bit BCD number to integer form.
nkeynes@1097
    97
 * Eg, 0x79 => 79
nkeynes@1097
    98
 */
nkeynes@1097
    99
uint8_t static inline BCDTOU8( uint8_t bcd )
nkeynes@1097
   100
{
nkeynes@1097
   101
    return (bcd & 0x0F) + (((bcd & 0xF0)>>4)*10);
nkeynes@1097
   102
}
nkeynes@1097
   103
nkeynes@1097
   104
/**
nkeynes@1097
   105
 * Convert a 32 bit BCD-encoded MSF address to the
nkeynes@1097
   106
 * equivalent LBA form.
nkeynes@1097
   107
 * Eg, 0x
nkeynes@1097
   108
 */
nkeynes@1097
   109
cdrom_lba_t static inline BCD_MSFTOLBA( uint32_t msf )
nkeynes@1097
   110
{
nkeynes@1097
   111
    msf = GUINT32_FROM_BE(msf);
nkeynes@1097
   112
    int f = BCDTOU8(msf);
nkeynes@1097
   113
    int s = BCDTOU8(msf>>8);
nkeynes@1097
   114
    int m = BCDTOU8(msf>>16);
nkeynes@1097
   115
    return MSFTOLBA(m,s,f);
nkeynes@1097
   116
}
nkeynes@1097
   117
nkeynes@1097
   118
/* Disc types */
nkeynes@1097
   119
typedef uint8_t cdrom_type_t;
nkeynes@1097
   120
#define CDROM_TYPE_NONXA 0x00  /* Audio or straight mode-1 data */
nkeynes@1097
   121
#define CDROM_TYPE_CDI   0x10
nkeynes@1097
   122
#define CDROM_TYPE_XA    0x20
nkeynes@1097
   123
#define CDROM_TYPE_GD    0x80  /* SEGA only */
nkeynes@1097
   124
nkeynes@1097
   125
nkeynes@1097
   126
/* Error codes are defined as MMC sense data - low byte is the sense key,
nkeynes@1097
   127
 * next byte, is the ASC code, and third byte is the ASCQ (not currently used)
nkeynes@1097
   128
 */
nkeynes@1097
   129
typedef uint32_t cdrom_error_t;
nkeynes@1097
   130
#define CDROM_ERROR_OK        0x0000
nkeynes@1097
   131
#define CDROM_ERROR_NODISC    0x3A02
nkeynes@1097
   132
#define CDROM_ERROR_BADCMD    0x2005
nkeynes@1097
   133
#define CDROM_ERROR_BADFIELD  0x2405
nkeynes@1097
   134
#define CDROM_ERROR_BADREAD   0x3002
nkeynes@1097
   135
#define CDROM_ERROR_BADREADMODE 0x6405  /* Illegal mode for this track */
nkeynes@1097
   136
#define CDROM_ERROR_READERROR 0x1103    /* Read failed due to uncorrectable error */
nkeynes@1097
   137
#define CDROM_ERROR_RESET     0x2906
nkeynes@1097
   138
nkeynes@1097
   139
#ifdef __cplusplus
nkeynes@1097
   140
}
nkeynes@1097
   141
#endif
nkeynes@1097
   142
nkeynes@1097
   143
#endif /* !cdrom_defs_H */
.