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 1097:d4807997e450
next1178:e55ec927d55d
author nkeynes
date Sun Jan 31 18:35:06 2010 +1000 (12 years ago)
permissions -rw-r--r--
last change Refactor CDROM host support
- Completely separate GDROM hardware (in gdrom/gdrom.c) from generic CDROM
support (now in drivers/cdrom)
- Add concept of 'sector sources' that can be mixed and matched to create
cdrom discs (makes support of arbitrary disc types much simpler)
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@1097
    24
#include <glib/gtypes.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@1097
    77
} sector_mode_t;
nkeynes@1097
    78
nkeynes@1097
    79
nkeynes@1097
    80
extern const uint32_t cdrom_sector_size[];
nkeynes@1097
    81
extern const uint32_t cdrom_sector_read_mode[];
nkeynes@1097
    82
#define CDROM_MAX_SECTOR_SIZE    2352
nkeynes@1097
    83
#define CDROM_MAX_TRACKS         99
nkeynes@1097
    84
#define CDROM_MSF_START          150 /* MSF numbering starts after the initial pregap */
nkeynes@1097
    85
#define CDROM_FRAMES_PER_SECOND  75
nkeynes@1097
    86
#define CDROM_SECONDS_PER_MINUTE 60
nkeynes@1097
    87
#define CDROM_FRAMES_PER_MINUTE  (CDROM_FRAMES_PER_SECOND*CDROM_SECONDS_PER_MINUTE)
nkeynes@1097
    88
#define CDROM_PREGAP             150  /* Standard pregap, in frames */
nkeynes@1097
    89
#define CDROM_SECTOR_SIZE(x)     cdrom_sector_size[x]
nkeynes@1097
    90
#define CDROM_SECTOR_READ_MODE(x) cdrom_sector_read_mode[x]
nkeynes@1097
    91
#define MSFTOLBA( m,s,f ) ((f) + ((s)*CDROM_FRAMES_PER_SECOND) + ((m)*CDROM_FRAMES_PER_MINUTE) - CDROM_MSF_START)
nkeynes@1097
    92
nkeynes@1097
    93
/**
nkeynes@1097
    94
 * Convert an 8-bit BCD number to integer form.
nkeynes@1097
    95
 * Eg, 0x79 => 79
nkeynes@1097
    96
 */
nkeynes@1097
    97
uint8_t static inline BCDTOU8( uint8_t bcd )
nkeynes@1097
    98
{
nkeynes@1097
    99
    return (bcd & 0x0F) + (((bcd & 0xF0)>>4)*10);
nkeynes@1097
   100
}
nkeynes@1097
   101
nkeynes@1097
   102
/**
nkeynes@1097
   103
 * Convert a 32 bit BCD-encoded MSF address to the
nkeynes@1097
   104
 * equivalent LBA form.
nkeynes@1097
   105
 * Eg, 0x
nkeynes@1097
   106
 */
nkeynes@1097
   107
cdrom_lba_t static inline BCD_MSFTOLBA( uint32_t msf )
nkeynes@1097
   108
{
nkeynes@1097
   109
    msf = GUINT32_FROM_BE(msf);
nkeynes@1097
   110
    int f = BCDTOU8(msf);
nkeynes@1097
   111
    int s = BCDTOU8(msf>>8);
nkeynes@1097
   112
    int m = BCDTOU8(msf>>16);
nkeynes@1097
   113
    return MSFTOLBA(m,s,f);
nkeynes@1097
   114
}
nkeynes@1097
   115
nkeynes@1097
   116
/* Disc types */
nkeynes@1097
   117
typedef uint8_t cdrom_type_t;
nkeynes@1097
   118
#define CDROM_TYPE_NONXA 0x00  /* Audio or straight mode-1 data */
nkeynes@1097
   119
#define CDROM_TYPE_CDI   0x10
nkeynes@1097
   120
#define CDROM_TYPE_XA    0x20
nkeynes@1097
   121
#define CDROM_TYPE_GD    0x80  /* SEGA only */
nkeynes@1097
   122
nkeynes@1097
   123
nkeynes@1097
   124
/* Error codes are defined as MMC sense data - low byte is the sense key,
nkeynes@1097
   125
 * next byte, is the ASC code, and third byte is the ASCQ (not currently used)
nkeynes@1097
   126
 */
nkeynes@1097
   127
typedef uint32_t cdrom_error_t;
nkeynes@1097
   128
#define CDROM_ERROR_OK        0x0000
nkeynes@1097
   129
#define CDROM_ERROR_NODISC    0x3A02
nkeynes@1097
   130
#define CDROM_ERROR_BADCMD    0x2005
nkeynes@1097
   131
#define CDROM_ERROR_BADFIELD  0x2405
nkeynes@1097
   132
#define CDROM_ERROR_BADREAD   0x3002
nkeynes@1097
   133
#define CDROM_ERROR_BADREADMODE 0x6405  /* Illegal mode for this track */
nkeynes@1097
   134
#define CDROM_ERROR_READERROR 0x1103    /* Read failed due to uncorrectable error */
nkeynes@1097
   135
#define CDROM_ERROR_RESET     0x2906
nkeynes@1097
   136
nkeynes@1097
   137
#ifdef __cplusplus
nkeynes@1097
   138
}
nkeynes@1097
   139
#endif
nkeynes@1097
   140
nkeynes@1097
   141
#endif /* !cdrom_defs_H */
.