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