Search
lxdream.org :: lxdream/src/gdrom/gdrom.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.h
changeset 489:45c8ddcf52cb
prev468:3a49695e081a
next492:84e33e4dda1c
author nkeynes
date Sun Nov 04 05:07:49 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Test for presence of linux/cdrom.h at configure time, and only build the
linux driver if it's found successfully
file annotate diff log raw
nkeynes@125
     1
/**
nkeynes@489
     2
 * $Id: gdrom.h,v 1.15 2007-11-04 05:07:49 nkeynes Exp $
nkeynes@125
     3
 *
nkeynes@125
     4
 * This file defines the structures and functions used by the GD-Rom
nkeynes@125
     5
 * disc driver. (ie, the modules that supply a CD image to be used by the
nkeynes@125
     6
 * system).
nkeynes@125
     7
 *
nkeynes@125
     8
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@125
     9
 *
nkeynes@125
    10
 * This program is free software; you can redistribute it and/or modify
nkeynes@125
    11
 * it under the terms of the GNU General Public License as published by
nkeynes@125
    12
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@125
    13
 * (at your option) any later version.
nkeynes@125
    14
 *
nkeynes@125
    15
 * This program is distributed in the hope that it will be useful,
nkeynes@125
    16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@125
    17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@125
    18
 * GNU General Public License for more details.
nkeynes@125
    19
 */
nkeynes@125
    20
nkeynes@125
    21
#ifndef dream_gdrom_H
nkeynes@125
    22
#define dream_gdrom_H 1
nkeynes@125
    23
nkeynes@125
    24
#include "dream.h"
nkeynes@464
    25
#include <glib.h>
nkeynes@125
    26
nkeynes@342
    27
#define MAX_SECTOR_SIZE 2352
nkeynes@342
    28
nkeynes@149
    29
typedef uint16_t gdrom_error_t;
nkeynes@149
    30
nkeynes@138
    31
struct gdrom_toc {
nkeynes@142
    32
    uint32_t track[99];
nkeynes@125
    33
    uint32_t first, last, leadout;
nkeynes@138
    34
};
nkeynes@138
    35
nkeynes@138
    36
#define GDROM_PREGAP 150  /* Sectors */
nkeynes@138
    37
nkeynes@138
    38
extern uint32_t gdrom_sector_size[];
nkeynes@138
    39
#define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
nkeynes@138
    40
typedef enum {
nkeynes@138
    41
    GDROM_MODE1,
nkeynes@138
    42
    GDROM_MODE2,
nkeynes@138
    43
    GDROM_MODE2_XA1,
nkeynes@138
    44
    GDROM_MODE2_XA2,
nkeynes@138
    45
    GDROM_CDDA,
nkeynes@143
    46
    GDROM_GD,
nkeynes@143
    47
    GDROM_RAW
nkeynes@138
    48
} gdrom_track_mode_t;
nkeynes@138
    49
nkeynes@138
    50
/* The disc register indicates the current contents of the drive. When open
nkeynes@138
    51
 * contains 0x06.
nkeynes@138
    52
 */
nkeynes@138
    53
#define IDE_DISC_AUDIO 0x00
nkeynes@138
    54
#define IDE_DISC_NONE  0x06
nkeynes@138
    55
#define IDE_DISC_CDROM 0x20
nkeynes@138
    56
#define IDE_DISC_GDROM 0x80
nkeynes@138
    57
#define IDE_DISC_READY 0x01 /* ored with above */
nkeynes@138
    58
#define IDE_DISC_IDLE  0x02 /* ie spun-down */
nkeynes@138
    59
nkeynes@142
    60
#define TRACK_PRE_EMPHASIS   0x10
nkeynes@142
    61
#define TRACK_COPY_PERMITTED 0x20
nkeynes@142
    62
#define TRACK_DATA           0x40
nkeynes@142
    63
#define TRACK_FOUR_CHANNEL   0x80
nkeynes@142
    64
nkeynes@245
    65
typedef struct gdrom_track {
nkeynes@138
    66
    gdrom_track_mode_t mode;
nkeynes@142
    67
    uint8_t flags;        /* Track flags */
nkeynes@138
    68
    int      session;     /* session # containing this track */
nkeynes@138
    69
    uint32_t lba;         /* start sector address */
nkeynes@138
    70
    uint32_t sector_size; /* For convenience, determined by mode */
nkeynes@138
    71
    uint32_t sector_count;
nkeynes@138
    72
    uint32_t offset; /* File offset of start of track - image files only */
nkeynes@245
    73
} *gdrom_track_t;
nkeynes@125
    74
nkeynes@342
    75
typedef struct gdrom_disc {
nkeynes@342
    76
    /**
nkeynes@342
    77
     * Read a single sector from the disc at the specified logical address.
nkeynes@342
    78
     * @param disc pointer to the disc structure
nkeynes@342
    79
     * @param lba logical address to read from
nkeynes@342
    80
     * @param mode mode field from the read command
nkeynes@342
    81
     * @param buf buffer to receive data (at least MAX_SECTOR_SIZE bytes)
nkeynes@342
    82
     * @param length unsigned int to receive the number of bytes actually read.
nkeynes@342
    83
     * @return PKT_ERR_OK on success, or another PKT_ERR_* code on failure.
nkeynes@342
    84
     */
nkeynes@342
    85
    gdrom_error_t (*read_sector)( struct gdrom_disc *disc,
nkeynes@342
    86
				  uint32_t lba, int mode, 
nkeynes@422
    87
				  unsigned char *buf, uint32_t *length );
nkeynes@342
    88
    
nkeynes@342
    89
    /**
nkeynes@342
    90
     * Read the TOC from the disc and write it into the specified buffer.
nkeynes@342
    91
     * The method is responsible for returning the data in gd-rom
nkeynes@342
    92
     * format.
nkeynes@342
    93
     * @param disc pointer to the disc structure
nkeynes@342
    94
     * @param buf buffer to receive data (0x198 bytes long)
nkeynes@342
    95
     */
nkeynes@422
    96
    gdrom_error_t (*read_toc)(struct gdrom_disc *disc, unsigned char *buf);
nkeynes@125
    97
nkeynes@342
    98
    /**
nkeynes@342
    99
     * Read the information for the specified sector and return it in the
nkeynes@342
   100
     * supplied buffer. 
nkeynes@342
   101
     * @param disc pointer to the disc structure
nkeynes@342
   102
     * @param session of interest. If 0, return end of disc information.
nkeynes@342
   103
     * @param buf buffer to receive data (6 bytes)
nkeynes@342
   104
     */
nkeynes@422
   105
    gdrom_error_t (*read_session)(struct gdrom_disc *disc, int session, unsigned char *buf);
nkeynes@342
   106
nkeynes@342
   107
    /**
nkeynes@342
   108
     * Read the position information (subchannel) for the specified sector
nkeynes@342
   109
     * and return it in the supplied buffer. This method does not need to
nkeynes@342
   110
     * write the first 4 bytes of the buffer.
nkeynes@342
   111
     * @param disc pointer to the disc structure
nkeynes@342
   112
     * @param lba sector to get position information for
nkeynes@342
   113
     * @param buf buffer to receive data (14 bytes)
nkeynes@342
   114
     */
nkeynes@422
   115
    gdrom_error_t (*read_position)(struct gdrom_disc *disc, uint32_t lba, unsigned char *buf);
nkeynes@342
   116
nkeynes@342
   117
    /**
nkeynes@342
   118
     * Return the current disc status, expressed as a combination of the 
nkeynes@342
   119
     * IDE_DISC_* flags above.
nkeynes@342
   120
     * @param disc pointer to the disc structure
nkeynes@342
   121
     * @return an integer status value.
nkeynes@342
   122
     */
nkeynes@342
   123
    int (*drive_status)(struct gdrom_disc *disc);
nkeynes@342
   124
nkeynes@342
   125
    /**
nkeynes@342
   126
     * Begin playing audio from the given lba address on the disc.
nkeynes@342
   127
     */
nkeynes@433
   128
    gdrom_error_t (*play_audio)(struct gdrom_disc *disc, uint32_t lba, uint32_t endlba);
nkeynes@342
   129
nkeynes@342
   130
    /**
nkeynes@342
   131
     * Executed once per time slice to perform house-keeping operations 
nkeynes@342
   132
     * (checking disc status, media changed, etc).
nkeynes@342
   133
     */
nkeynes@342
   134
    uint32_t (*run_time_slice)( struct gdrom_disc *disc, uint32_t nanosecs );
nkeynes@342
   135
nkeynes@342
   136
    /**
nkeynes@342
   137
     * Close the disc and release any storage or resources allocated including
nkeynes@342
   138
     * the disc structure itself.
nkeynes@342
   139
     */
nkeynes@342
   140
    void (*close)( struct gdrom_disc *disc );
nkeynes@464
   141
    const gchar *name; /* Device name / Image filename */
nkeynes@342
   142
} *gdrom_disc_t;
nkeynes@342
   143
nkeynes@342
   144
nkeynes@342
   145
typedef struct gdrom_image {
nkeynes@342
   146
    struct gdrom_disc disc;
nkeynes@138
   147
    int disc_type;
nkeynes@138
   148
    int track_count;
nkeynes@138
   149
    struct gdrom_track track[99];
nkeynes@138
   150
    gchar mcn[14]; /* Media catalogue number */
nkeynes@342
   151
    FILE *file; /* Open file stream */
nkeynes@342
   152
} *gdrom_image_t;
nkeynes@125
   153
nkeynes@138
   154
/**
nkeynes@168
   155
 *
nkeynes@168
   156
 */
nkeynes@168
   157
typedef struct gdrom_image_class {
nkeynes@168
   158
    const gchar *name;
nkeynes@168
   159
    const gchar *extension;
nkeynes@168
   160
    gboolean (*is_valid_file)(FILE *f);
nkeynes@168
   161
    gdrom_disc_t (*open_image_file)(const gchar *filename, FILE *f);
nkeynes@168
   162
} *gdrom_image_class_t;
nkeynes@168
   163
nkeynes@168
   164
extern struct gdrom_image_class nrg_image_class;
nkeynes@168
   165
extern struct gdrom_image_class cdi_image_class;
nkeynes@489
   166
extern struct gdrom_image_class cdrom_device_class;
nkeynes@168
   167
nkeynes@168
   168
/**
nkeynes@138
   169
 * Construct a new image file using the default methods.
nkeynes@138
   170
 */
nkeynes@464
   171
gdrom_disc_t gdrom_image_new( const gchar *filename, FILE *f );
nkeynes@125
   172
nkeynes@138
   173
/**
nkeynes@138
   174
 * Open an image file
nkeynes@138
   175
 */
nkeynes@138
   176
gdrom_disc_t gdrom_image_open( const gchar *filename );
nkeynes@138
   177
nkeynes@138
   178
/**
nkeynes@422
   179
 * Dump image info
nkeynes@422
   180
 */
nkeynes@422
   181
void gdrom_image_dump_info( gdrom_disc_t d );
nkeynes@422
   182
nkeynes@422
   183
/**
nkeynes@468
   184
 * Destroy an image data structure without closing the file
nkeynes@468
   185
 * (Intended for use from image loaders only)
nkeynes@468
   186
 */
nkeynes@468
   187
void gdrom_image_destroy_no_close( gdrom_disc_t d );
nkeynes@468
   188
nkeynes@468
   189
/**
nkeynes@138
   190
 * Retrieve the disc table of contents, and write it into the buffer in the 
nkeynes@138
   191
 * format expected by the DC.
nkeynes@149
   192
 * @return 0 on success, error code on failure (eg no disc mounted)
nkeynes@138
   193
 */
nkeynes@422
   194
gdrom_error_t gdrom_get_toc( unsigned char *buf );
nkeynes@149
   195
nkeynes@149
   196
/**
nkeynes@152
   197
 * Retrieve the short (6-byte) session info, and write it into the buffer.
nkeynes@149
   198
 * @return 0 on success, error code on failure.
nkeynes@149
   199
 */
nkeynes@422
   200
gdrom_error_t gdrom_get_info( unsigned char *buf, int session );
nkeynes@138
   201
nkeynes@245
   202
gdrom_track_t gdrom_get_track( int track_no );
nkeynes@245
   203
nkeynes@245
   204
uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
nkeynes@245
   205
nkeynes@138
   206
/**
nkeynes@138
   207
 * Shortcut to open and mount an image file
nkeynes@433
   208
 * @return true on success
nkeynes@138
   209
 */
nkeynes@433
   210
gboolean gdrom_mount_image( const gchar *filename );
nkeynes@138
   211
nkeynes@138
   212
void gdrom_mount_disc( gdrom_disc_t disc );
nkeynes@138
   213
nkeynes@138
   214
void gdrom_unmount_disc( void );
nkeynes@138
   215
nkeynes@138
   216
gboolean gdrom_is_mounted( void );
nkeynes@138
   217
nkeynes@464
   218
gdrom_disc_t gdrom_get_current_disc();
nkeynes@464
   219
nkeynes@464
   220
GList *gdrom_get_native_devices();
nkeynes@464
   221
nkeynes@138
   222
uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
nkeynes@422
   223
			     int mode, unsigned char *buf, uint32_t *length );
nkeynes@125
   224
nkeynes@125
   225
#endif
.