Search
lxdream.org :: lxdream/src/gdrom/gddriver.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gddriver.h
changeset 709:18c39a8e504c
prev678:35eb00945316
next720:b5594d1ac80a
author nkeynes
date Wed Jun 25 10:40:45 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Commit OSX CD-ROM driver work-in-progress
view annotate diff log raw
     1 /**
     2  * $Id: gdrom.h 662 2008-03-02 11:38:08Z nkeynes $
     3  *
     4  * This file defines the structures and functions used by the GD-Rom
     5  * disc drivers. (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 lxdream_gdrom_driver_H
    22 #define lxdream_gdrom_driver_H 1
    24 #include <stdio.h>
    25 #include "lxdream.h"
    26 #include "gdrom/gdrom.h"
    27 #include <glib/gstrfuncs.h>
    29 #define MAX_SECTOR_SIZE 2352
    32 struct gdrom_toc {
    33     uint32_t track[99];
    34     uint32_t first, last, leadout;
    35 };
    37 #define GDROM_PREGAP 150  /* Sectors */
    39 extern uint32_t gdrom_sector_size[];
    40 #define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
    41 /**
    42  * Track data type enumeration for cd images and devices. This somewhat
    43  * conflates the real track mode with the format of the image file, but
    44  * it manages to make sense so far.
    45  */
    46 typedef enum {
    47     GDROM_MODE0,          // Mode 0 - should never actually see this
    48 /* Data-only modes (image file contains only the user data) */
    49     GDROM_MODE1,          // Standard CD-Rom Mode 1 data track
    50     GDROM_MODE2_FORMLESS, // Mode 2 data track with no sub-structure (rare)
    51     GDROM_MODE2_FORM1,    // Mode 2/Form 1 data track (standard for multisession)
    52     GDROM_MODE2_FORM2,    // Mode 2/Form 2 data track (also fairly uncommon).
    53     GDROM_CDDA,           // Standard audio track
    55 /* This one is somewhat special - the image file contains the 2336 bytes of
    56  * "extended user data", which in turn contains either a form 1 or form 2
    57  * sector. In other words it's a raw mode2 XA sector without the 16-byte header.
    58  */
    59     GDROM_SEMIRAW_MODE2,
    60 /* Raw modes (image contains the full 2352-byte sector). Split into XA/Non-XA
    61  * here for convenience, although it's really a session level flag. */
    62     GDROM_RAW_XA,
    63     GDROM_RAW_NONXA,
    64 } gdrom_track_mode_t;
    66 /* The disc register indicates the current contents of the drive. When open
    67  * contains 0x06.
    68  */
    69 #define IDE_DISC_READY 0x01 /* ored with above */
    70 #define IDE_DISC_IDLE  0x02 /* ie spun-down */
    71 #define IDE_DISC_NONE  0x06
    73 #define IDE_DISC_AUDIO   0x00
    74 #define IDE_DISC_CDROM   0x10
    75 #define IDE_DISC_CDROMXA 0x20
    76 #define IDE_DISC_GDROM   0x80
    78 #define TRACK_PRE_EMPHASIS   0x10
    79 #define TRACK_COPY_PERMITTED 0x20
    80 #define TRACK_DATA           0x40
    81 #define TRACK_FOUR_CHANNEL   0x80
    83 typedef struct gdrom_track {
    84     gdrom_track_mode_t mode;
    85     uint8_t flags;        /* Track flags */
    86     int      session;     /* session # containing this track */
    87     uint32_t lba;         /* start sector address */
    88     uint32_t sector_size; /* For convenience, determined by mode */
    89     uint32_t sector_count;
    90     uint32_t offset; /* File offset of start of track - image files only */
    91     FILE *file;
    92 } *gdrom_track_t;
    94 struct gdrom_disc {
    95     /**
    96      * Read a single sector from the disc at the specified logical address.
    97      * @param disc pointer to the disc structure
    98      * @param lba logical address to read from
    99      * @param mode mode field from the read command
   100      * @param buf buffer to receive data (at least MAX_SECTOR_SIZE bytes)
   101      * @param length unsigned int to receive the number of bytes actually read.
   102      * @return PKT_ERR_OK on success, or another PKT_ERR_* code on failure.
   103      */
   104     gdrom_error_t (*read_sector)( struct gdrom_disc *disc,
   105                   uint32_t lba, int mode, 
   106                   unsigned char *buf, uint32_t *length );
   108     /**
   109      * Read the TOC from the disc and write it into the specified buffer.
   110      * The method is responsible for returning the data in gd-rom
   111      * format.
   112      * @param disc pointer to the disc structure
   113      * @param buf buffer to receive data (0x198 bytes long)
   114      */
   115     gdrom_error_t (*read_toc)(struct gdrom_disc *disc, unsigned char *buf);
   117     /**
   118      * Read the information for the specified sector and return it in the
   119      * supplied buffer. 
   120      * @param disc pointer to the disc structure
   121      * @param session of interest. If 0, return end of disc information.
   122      * @param buf buffer to receive data (6 bytes)
   123      */
   124     gdrom_error_t (*read_session)(struct gdrom_disc *disc, int session, unsigned char *buf);
   126     /**
   127      * Read the position information (subchannel) for the specified sector
   128      * and return it in the supplied buffer. This method does not need to
   129      * write the first 4 bytes of the buffer.
   130      * @param disc pointer to the disc structure
   131      * @param lba sector to get position information for
   132      * @param buf buffer to receive data (14 bytes)
   133      */
   134     gdrom_error_t (*read_position)(struct gdrom_disc *disc, uint32_t lba, unsigned char *buf);
   136     /**
   137      * Return the current disc status, expressed as a combination of the 
   138      * IDE_DISC_* flags above.
   139      * @param disc pointer to the disc structure
   140      * @return an integer status value.
   141      */
   142     int (*drive_status)(struct gdrom_disc *disc);
   144     /**
   145      * Begin playing audio from the given lba address on the disc.
   146      */
   147     gdrom_error_t (*play_audio)(struct gdrom_disc *disc, uint32_t lba, uint32_t endlba);
   149     /**
   150      * Executed once per time slice to perform house-keeping operations 
   151      * (checking disc status, media changed, etc).
   152      */
   153     uint32_t (*run_time_slice)( struct gdrom_disc *disc, uint32_t nanosecs );
   155     /**
   156      * Close the disc and release any storage or resources allocated including
   157      * the disc structure itself.
   158      */
   159     void (*close)( struct gdrom_disc *disc );
   160     const gchar *name; /* Device name / Image filename */
   161 };
   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  * Destroy an image data structure without closing the file
   194  * (Intended for use from image loaders only)
   195  */
   196 void gdrom_image_destroy_no_close( gdrom_disc_t d );
   199 /**
   200  * Given a base filename (eg for a .cue file), generate the path for the given
   201  * find_name relative to the original file. 
   202  * @return a newly allocated string.
   203  */
   204 gchar *gdrom_get_relative_filename( const gchar *base_name, const gchar *find_name );
   206 gdrom_device_t gdrom_device_new( const gchar *name, const gchar *dev_name );
   208 void gdrom_device_destroy( gdrom_device_t dev );
   210 #endif
.