Search
lxdream.org :: lxdream/src/gdrom/gdrom.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.h
changeset 644:ccae4bfa5f82
prev613:c2dd87f947b2
next678:35eb00945316
author nkeynes
date Wed Apr 16 23:47:32 2008 +0000 (16 years ago)
permissions -rw-r--r--
last change Add check for objective-c compiler (for mac) and set the language if found
view annotate diff log raw
     1 /**
     2  * $Id$
     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"
    25 #include <glib.h>
    27 #define MAX_SECTOR_SIZE 2352
    29 typedef uint16_t gdrom_error_t;
    31 struct gdrom_toc {
    32     uint32_t track[99];
    33     uint32_t first, last, leadout;
    34 };
    36 #define GDROM_PREGAP 150  /* Sectors */
    38 extern uint32_t gdrom_sector_size[];
    39 #define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
    40 /**
    41  * Track data type enumeration for cd images and devices. This somewhat
    42  * conflates the real track mode with the format of the image file, but
    43  * it manages to make sense so far.
    44  */
    45 typedef enum {
    46     GDROM_MODE0,          // Mode 0 - should never actually see this
    47 /* Data-only modes (image file contains only the user data) */
    48     GDROM_MODE1,          // Standard CD-Rom Mode 1 data track
    49     GDROM_MODE2_FORMLESS, // Mode 2 data track with no sub-structure (rare)
    50     GDROM_MODE2_FORM1,    // Mode 2/Form 1 data track (standard for multisession)
    51     GDROM_MODE2_FORM2,    // Mode 2/Form 2 data track (also fairly uncommon).
    52     GDROM_CDDA,           // Standard audio track
    54 /* This one is somewhat special - the image file contains the 2336 bytes of
    55  * "extended user data", which in turn contains either a form 1 or form 2
    56  * sector. In other words it's a raw mode2 XA sector without the 16-byte header.
    57  */
    58     GDROM_SEMIRAW_MODE2,
    59 /* Raw modes (image contains the full 2352-byte sector). Split into XA/Non-XA
    60  * here for convenience, although it's really a session level flag. */
    61     GDROM_RAW_XA,
    62     GDROM_RAW_NONXA,
    63 } gdrom_track_mode_t;
    65 /* The disc register indicates the current contents of the drive. When open
    66  * contains 0x06.
    67  */
    68 #define IDE_DISC_READY 0x01 /* ored with above */
    69 #define IDE_DISC_IDLE  0x02 /* ie spun-down */
    70 #define IDE_DISC_NONE  0x06
    72 #define IDE_DISC_AUDIO   0x00
    73 #define IDE_DISC_CDROM   0x10
    74 #define IDE_DISC_CDROMXA 0x20
    75 #define IDE_DISC_GDROM   0x80
    77 #define TRACK_PRE_EMPHASIS   0x10
    78 #define TRACK_COPY_PERMITTED 0x20
    79 #define TRACK_DATA           0x40
    80 #define TRACK_FOUR_CHANNEL   0x80
    82 typedef struct gdrom_track {
    83     gdrom_track_mode_t mode;
    84     uint8_t flags;        /* Track flags */
    85     int      session;     /* session # containing this track */
    86     uint32_t lba;         /* start sector address */
    87     uint32_t sector_size; /* For convenience, determined by mode */
    88     uint32_t sector_count;
    89     uint32_t offset; /* File offset of start of track - image files only */
    90     FILE *file;
    91 } *gdrom_track_t;
    93 typedef struct gdrom_disc {
    94     /**
    95      * Read a single sector from the disc at the specified logical address.
    96      * @param disc pointer to the disc structure
    97      * @param lba logical address to read from
    98      * @param mode mode field from the read command
    99      * @param buf buffer to receive data (at least MAX_SECTOR_SIZE bytes)
   100      * @param length unsigned int to receive the number of bytes actually read.
   101      * @return PKT_ERR_OK on success, or another PKT_ERR_* code on failure.
   102      */
   103     gdrom_error_t (*read_sector)( struct gdrom_disc *disc,
   104 				  uint32_t lba, int mode, 
   105 				  unsigned char *buf, uint32_t *length );
   107     /**
   108      * Read the TOC from the disc and write it into the specified buffer.
   109      * The method is responsible for returning the data in gd-rom
   110      * format.
   111      * @param disc pointer to the disc structure
   112      * @param buf buffer to receive data (0x198 bytes long)
   113      */
   114     gdrom_error_t (*read_toc)(struct gdrom_disc *disc, unsigned char *buf);
   116     /**
   117      * Read the information for the specified sector and return it in the
   118      * supplied buffer. 
   119      * @param disc pointer to the disc structure
   120      * @param session of interest. If 0, return end of disc information.
   121      * @param buf buffer to receive data (6 bytes)
   122      */
   123     gdrom_error_t (*read_session)(struct gdrom_disc *disc, int session, unsigned char *buf);
   125     /**
   126      * Read the position information (subchannel) for the specified sector
   127      * and return it in the supplied buffer. This method does not need to
   128      * write the first 4 bytes of the buffer.
   129      * @param disc pointer to the disc structure
   130      * @param lba sector to get position information for
   131      * @param buf buffer to receive data (14 bytes)
   132      */
   133     gdrom_error_t (*read_position)(struct gdrom_disc *disc, uint32_t lba, unsigned char *buf);
   135     /**
   136      * Return the current disc status, expressed as a combination of the 
   137      * IDE_DISC_* flags above.
   138      * @param disc pointer to the disc structure
   139      * @return an integer status value.
   140      */
   141     int (*drive_status)(struct gdrom_disc *disc);
   143     /**
   144      * Begin playing audio from the given lba address on the disc.
   145      */
   146     gdrom_error_t (*play_audio)(struct gdrom_disc *disc, uint32_t lba, uint32_t endlba);
   148     /**
   149      * Executed once per time slice to perform house-keeping operations 
   150      * (checking disc status, media changed, etc).
   151      */
   152     uint32_t (*run_time_slice)( struct gdrom_disc *disc, uint32_t nanosecs );
   154     /**
   155      * Close the disc and release any storage or resources allocated including
   156      * the disc structure itself.
   157      */
   158     void (*close)( struct gdrom_disc *disc );
   159     const gchar *name; /* Device name / Image filename */
   160 } *gdrom_disc_t;
   163 typedef struct gdrom_image {
   164     struct gdrom_disc disc;
   165     int disc_type;
   166     int track_count;
   167     struct gdrom_track track[99];
   168     gchar mcn[14]; /* Media catalogue number */
   169     FILE *file; /* Open file stream */
   170 } *gdrom_image_t;
   172 /**
   173  *
   174  */
   175 typedef struct gdrom_image_class {
   176     const gchar *name;
   177     const gchar *extension;
   178     gboolean (*is_valid_file)(FILE *f);
   179     gdrom_disc_t (*open_image_file)(const gchar *filename, FILE *f);
   180 } *gdrom_image_class_t;
   182 extern struct gdrom_image_class nrg_image_class;
   183 extern struct gdrom_image_class cdi_image_class;
   184 extern struct gdrom_image_class gdi_image_class;
   185 extern struct gdrom_image_class cdrom_device_class;
   187 /**
   188  * Construct a new image file using the default methods.
   189  */
   190 gdrom_disc_t gdrom_image_new( const gchar *filename, FILE *f );
   192 /**
   193  * Open an image file
   194  */
   195 gdrom_disc_t gdrom_image_open( const gchar *filename );
   197 /**
   198  * Dump image info
   199  */
   200 void gdrom_image_dump_info( gdrom_disc_t d );
   202 /**
   203  * Destroy an image data structure without closing the file
   204  * (Intended for use from image loaders only)
   205  */
   206 void gdrom_image_destroy_no_close( gdrom_disc_t d );
   208 /**
   209  * Retrieve the disc table of contents, and write it into the buffer in the 
   210  * format expected by the DC.
   211  * @return 0 on success, error code on failure (eg no disc mounted)
   212  */
   213 gdrom_error_t gdrom_get_toc( unsigned char *buf );
   215 /**
   216  * Retrieve the short (6-byte) session info, and write it into the buffer.
   217  * @return 0 on success, error code on failure.
   218  */
   219 gdrom_error_t gdrom_get_info( unsigned char *buf, int session );
   221 gdrom_track_t gdrom_get_track( int track_no );
   223 uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
   225 /**
   226  * Shortcut to open and mount an image file
   227  * @return true on success
   228  */
   229 gboolean gdrom_mount_image( const gchar *filename );
   231 void gdrom_mount_disc( gdrom_disc_t disc );
   233 void gdrom_unmount_disc( void );
   235 gboolean gdrom_is_mounted( void );
   237 gdrom_disc_t gdrom_get_current_disc();
   239 GList *gdrom_get_native_devices();
   241 uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
   242 			     int mode, unsigned char *buf, uint32_t *length );
   244 /**
   245  * Given a base filename (eg for a .cue file), generate the path for the given
   246  * find_name relative to the original file. 
   247  * @return a newly allocated string.
   248  */
   249 gchar *gdrom_get_relative_filename( const gchar *base_name, const gchar *find_name );
   251 #endif
.