Search
lxdream.org :: lxdream/src/gdrom/gdrom.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.h
changeset 342:850502f0e8de
prev245:a1d0655a88d3
next422:61a0598e07ff
author nkeynes
date Wed Jan 31 10:58:42 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Refactor gdrom module to be more conducive to real device support
file annotate diff log raw
nkeynes@125
     1
/**
nkeynes@342
     2
 * $Id: gdrom.h,v 1.10 2007-01-31 10:58:42 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@125
    25
nkeynes@342
    26
#define MAX_SECTOR_SIZE 2352
nkeynes@342
    27
nkeynes@149
    28
typedef uint16_t gdrom_error_t;
nkeynes@149
    29
nkeynes@138
    30
struct gdrom_toc {
nkeynes@142
    31
    uint32_t track[99];
nkeynes@125
    32
    uint32_t first, last, leadout;
nkeynes@138
    33
};
nkeynes@138
    34
nkeynes@138
    35
#define GDROM_PREGAP 150  /* Sectors */
nkeynes@138
    36
nkeynes@138
    37
extern uint32_t gdrom_sector_size[];
nkeynes@138
    38
#define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
nkeynes@138
    39
typedef enum {
nkeynes@138
    40
    GDROM_MODE1,
nkeynes@138
    41
    GDROM_MODE2,
nkeynes@138
    42
    GDROM_MODE2_XA1,
nkeynes@138
    43
    GDROM_MODE2_XA2,
nkeynes@138
    44
    GDROM_CDDA,
nkeynes@143
    45
    GDROM_GD,
nkeynes@143
    46
    GDROM_RAW
nkeynes@138
    47
} gdrom_track_mode_t;
nkeynes@138
    48
nkeynes@138
    49
/* The disc register indicates the current contents of the drive. When open
nkeynes@138
    50
 * contains 0x06.
nkeynes@138
    51
 */
nkeynes@138
    52
#define IDE_DISC_AUDIO 0x00
nkeynes@138
    53
#define IDE_DISC_NONE  0x06
nkeynes@138
    54
#define IDE_DISC_CDROM 0x20
nkeynes@138
    55
#define IDE_DISC_GDROM 0x80
nkeynes@138
    56
#define IDE_DISC_READY 0x01 /* ored with above */
nkeynes@138
    57
#define IDE_DISC_IDLE  0x02 /* ie spun-down */
nkeynes@138
    58
nkeynes@142
    59
#define TRACK_PRE_EMPHASIS   0x10
nkeynes@142
    60
#define TRACK_COPY_PERMITTED 0x20
nkeynes@142
    61
#define TRACK_DATA           0x40
nkeynes@142
    62
#define TRACK_FOUR_CHANNEL   0x80
nkeynes@142
    63
nkeynes@245
    64
typedef struct gdrom_track {
nkeynes@138
    65
    gdrom_track_mode_t mode;
nkeynes@142
    66
    uint8_t flags;        /* Track flags */
nkeynes@138
    67
    int      session;     /* session # containing this track */
nkeynes@138
    68
    uint32_t lba;         /* start sector address */
nkeynes@138
    69
    uint32_t sector_size; /* For convenience, determined by mode */
nkeynes@138
    70
    uint32_t sector_count;
nkeynes@138
    71
    uint32_t offset; /* File offset of start of track - image files only */
nkeynes@245
    72
} *gdrom_track_t;
nkeynes@125
    73
nkeynes@342
    74
typedef struct gdrom_disc {
nkeynes@342
    75
    /**
nkeynes@342
    76
     * Read a single sector from the disc at the specified logical address.
nkeynes@342
    77
     * @param disc pointer to the disc structure
nkeynes@342
    78
     * @param lba logical address to read from
nkeynes@342
    79
     * @param mode mode field from the read command
nkeynes@342
    80
     * @param buf buffer to receive data (at least MAX_SECTOR_SIZE bytes)
nkeynes@342
    81
     * @param length unsigned int to receive the number of bytes actually read.
nkeynes@342
    82
     * @return PKT_ERR_OK on success, or another PKT_ERR_* code on failure.
nkeynes@342
    83
     */
nkeynes@342
    84
    gdrom_error_t (*read_sector)( struct gdrom_disc *disc,
nkeynes@342
    85
				  uint32_t lba, int mode, 
nkeynes@342
    86
				  char *buf, uint32_t *length );
nkeynes@342
    87
    
nkeynes@342
    88
    /**
nkeynes@342
    89
     * Read the TOC from the disc and write it into the specified buffer.
nkeynes@342
    90
     * The method is responsible for returning the data in gd-rom
nkeynes@342
    91
     * format.
nkeynes@342
    92
     * @param disc pointer to the disc structure
nkeynes@342
    93
     * @param buf buffer to receive data (0x198 bytes long)
nkeynes@342
    94
     */
nkeynes@342
    95
    gdrom_error_t (*read_toc)(struct gdrom_disc *disc, char *buf);
nkeynes@125
    96
nkeynes@342
    97
    /**
nkeynes@342
    98
     * Read the information for the specified sector and return it in the
nkeynes@342
    99
     * supplied buffer. 
nkeynes@342
   100
     * @param disc pointer to the disc structure
nkeynes@342
   101
     * @param session of interest. If 0, return end of disc information.
nkeynes@342
   102
     * @param buf buffer to receive data (6 bytes)
nkeynes@342
   103
     */
nkeynes@342
   104
    gdrom_error_t (*read_session)(struct gdrom_disc *disc, int session, char *buf);
nkeynes@342
   105
nkeynes@342
   106
    /**
nkeynes@342
   107
     * Read the position information (subchannel) for the specified sector
nkeynes@342
   108
     * and return it in the supplied buffer. This method does not need to
nkeynes@342
   109
     * write the first 4 bytes of the buffer.
nkeynes@342
   110
     * @param disc pointer to the disc structure
nkeynes@342
   111
     * @param lba sector to get position information for
nkeynes@342
   112
     * @param buf buffer to receive data (14 bytes)
nkeynes@342
   113
     */
nkeynes@342
   114
    gdrom_error_t (*read_position)(struct gdrom_disc *disc, uint32_t lba, char *buf);
nkeynes@342
   115
nkeynes@342
   116
    /**
nkeynes@342
   117
     * Return the current disc status, expressed as a combination of the 
nkeynes@342
   118
     * IDE_DISC_* flags above.
nkeynes@342
   119
     * @param disc pointer to the disc structure
nkeynes@342
   120
     * @return an integer status value.
nkeynes@342
   121
     */
nkeynes@342
   122
    int (*drive_status)(struct gdrom_disc *disc);
nkeynes@342
   123
nkeynes@342
   124
    /**
nkeynes@342
   125
     * Begin playing audio from the given lba address on the disc.
nkeynes@342
   126
     */
nkeynes@342
   127
    gdrom_error_t (*play_audio)(struct gdrom_disc *disc, uint32_t lba);
nkeynes@342
   128
nkeynes@342
   129
    /**
nkeynes@342
   130
     * Executed once per time slice to perform house-keeping operations 
nkeynes@342
   131
     * (checking disc status, media changed, etc).
nkeynes@342
   132
     */
nkeynes@342
   133
    uint32_t (*run_time_slice)( struct gdrom_disc *disc, uint32_t nanosecs );
nkeynes@342
   134
nkeynes@342
   135
    /**
nkeynes@342
   136
     * Close the disc and release any storage or resources allocated including
nkeynes@342
   137
     * the disc structure itself.
nkeynes@342
   138
     */
nkeynes@342
   139
    void (*close)( struct gdrom_disc *disc );
nkeynes@342
   140
} *gdrom_disc_t;
nkeynes@342
   141
nkeynes@342
   142
nkeynes@342
   143
typedef struct gdrom_image {
nkeynes@342
   144
    struct gdrom_disc disc;
nkeynes@138
   145
    int disc_type;
nkeynes@138
   146
    int track_count;
nkeynes@138
   147
    struct gdrom_track track[99];
nkeynes@138
   148
    gchar mcn[14]; /* Media catalogue number */
nkeynes@138
   149
    const gchar *filename; /* Image filename */
nkeynes@342
   150
    FILE *file; /* Open file stream */
nkeynes@342
   151
} *gdrom_image_t;
nkeynes@125
   152
nkeynes@138
   153
/**
nkeynes@168
   154
 *
nkeynes@168
   155
 */
nkeynes@168
   156
typedef struct gdrom_image_class {
nkeynes@168
   157
    const gchar *name;
nkeynes@168
   158
    const gchar *extension;
nkeynes@168
   159
    gboolean (*is_valid_file)(FILE *f);
nkeynes@168
   160
    gdrom_disc_t (*open_image_file)(const gchar *filename, FILE *f);
nkeynes@168
   161
} *gdrom_image_class_t;
nkeynes@168
   162
nkeynes@168
   163
extern struct gdrom_image_class nrg_image_class;
nkeynes@168
   164
extern struct gdrom_image_class cdi_image_class;
nkeynes@237
   165
extern struct gdrom_image_class linux_device_class;
nkeynes@168
   166
nkeynes@168
   167
/**
nkeynes@138
   168
 * Construct a new image file using the default methods.
nkeynes@138
   169
 */
nkeynes@138
   170
gdrom_disc_t gdrom_image_new( FILE *file );
nkeynes@125
   171
nkeynes@138
   172
/**
nkeynes@138
   173
 * Open an image file
nkeynes@138
   174
 */
nkeynes@138
   175
gdrom_disc_t gdrom_image_open( const gchar *filename );
nkeynes@138
   176
nkeynes@138
   177
/**
nkeynes@138
   178
 * Retrieve the disc table of contents, and write it into the buffer in the 
nkeynes@138
   179
 * format expected by the DC.
nkeynes@149
   180
 * @return 0 on success, error code on failure (eg no disc mounted)
nkeynes@138
   181
 */
nkeynes@149
   182
gdrom_error_t gdrom_get_toc( char *buf );
nkeynes@149
   183
nkeynes@149
   184
/**
nkeynes@152
   185
 * Retrieve the short (6-byte) session info, and write it into the buffer.
nkeynes@149
   186
 * @return 0 on success, error code on failure.
nkeynes@149
   187
 */
nkeynes@152
   188
gdrom_error_t gdrom_get_info( char *buf, int session );
nkeynes@138
   189
nkeynes@245
   190
gdrom_track_t gdrom_get_track( int track_no );
nkeynes@245
   191
nkeynes@245
   192
uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
nkeynes@245
   193
nkeynes@138
   194
/**
nkeynes@138
   195
 * Shortcut to open and mount an image file
nkeynes@138
   196
 */
nkeynes@138
   197
gdrom_disc_t gdrom_mount_image( const gchar *filename );
nkeynes@138
   198
nkeynes@138
   199
void gdrom_mount_disc( gdrom_disc_t disc );
nkeynes@138
   200
nkeynes@138
   201
void gdrom_unmount_disc( void );
nkeynes@138
   202
nkeynes@138
   203
gboolean gdrom_is_mounted( void );
nkeynes@138
   204
nkeynes@138
   205
uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
nkeynes@143
   206
			     int mode, char *buf, uint32_t *length );
nkeynes@125
   207
nkeynes@125
   208
#endif
.