Search
lxdream.org :: lxdream/src/gdrom/gdrom.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.h
changeset 492:84e33e4dda1c
prev489:45c8ddcf52cb
next561:533f6b478071
author nkeynes
date Tue Nov 06 08:35:16 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Issue #37: Add nulldc GDI format
view annotate diff log raw
     1 /**
     2  * $Id: gdrom.h,v 1.16 2007-11-06 08:35:16 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"
    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 typedef enum {
    41     GDROM_MODE1,
    42     GDROM_MODE2,
    43     GDROM_MODE2_XA1,
    44     GDROM_MODE2_XA2,
    45     GDROM_CDDA,
    46     GDROM_GD,
    47     GDROM_RAW
    48 } gdrom_track_mode_t;
    50 /* The disc register indicates the current contents of the drive. When open
    51  * contains 0x06.
    52  */
    53 #define IDE_DISC_AUDIO 0x00
    54 #define IDE_DISC_NONE  0x06
    55 #define IDE_DISC_CDROM 0x20
    56 #define IDE_DISC_GDROM 0x80
    57 #define IDE_DISC_READY 0x01 /* ored with above */
    58 #define IDE_DISC_IDLE  0x02 /* ie spun-down */
    60 #define TRACK_PRE_EMPHASIS   0x10
    61 #define TRACK_COPY_PERMITTED 0x20
    62 #define TRACK_DATA           0x40
    63 #define TRACK_FOUR_CHANNEL   0x80
    65 typedef struct gdrom_track {
    66     gdrom_track_mode_t mode;
    67     uint8_t flags;        /* Track flags */
    68     int      session;     /* session # containing this track */
    69     uint32_t lba;         /* start sector address */
    70     uint32_t sector_size; /* For convenience, determined by mode */
    71     uint32_t sector_count;
    72     uint32_t offset; /* File offset of start of track - image files only */
    73     FILE *file;
    74 } *gdrom_track_t;
    76 typedef struct gdrom_disc {
    77     /**
    78      * Read a single sector from the disc at the specified logical address.
    79      * @param disc pointer to the disc structure
    80      * @param lba logical address to read from
    81      * @param mode mode field from the read command
    82      * @param buf buffer to receive data (at least MAX_SECTOR_SIZE bytes)
    83      * @param length unsigned int to receive the number of bytes actually read.
    84      * @return PKT_ERR_OK on success, or another PKT_ERR_* code on failure.
    85      */
    86     gdrom_error_t (*read_sector)( struct gdrom_disc *disc,
    87 				  uint32_t lba, int mode, 
    88 				  unsigned char *buf, uint32_t *length );
    90     /**
    91      * Read the TOC from the disc and write it into the specified buffer.
    92      * The method is responsible for returning the data in gd-rom
    93      * format.
    94      * @param disc pointer to the disc structure
    95      * @param buf buffer to receive data (0x198 bytes long)
    96      */
    97     gdrom_error_t (*read_toc)(struct gdrom_disc *disc, unsigned char *buf);
    99     /**
   100      * Read the information for the specified sector and return it in the
   101      * supplied buffer. 
   102      * @param disc pointer to the disc structure
   103      * @param session of interest. If 0, return end of disc information.
   104      * @param buf buffer to receive data (6 bytes)
   105      */
   106     gdrom_error_t (*read_session)(struct gdrom_disc *disc, int session, unsigned char *buf);
   108     /**
   109      * Read the position information (subchannel) for the specified sector
   110      * and return it in the supplied buffer. This method does not need to
   111      * write the first 4 bytes of the buffer.
   112      * @param disc pointer to the disc structure
   113      * @param lba sector to get position information for
   114      * @param buf buffer to receive data (14 bytes)
   115      */
   116     gdrom_error_t (*read_position)(struct gdrom_disc *disc, uint32_t lba, unsigned char *buf);
   118     /**
   119      * Return the current disc status, expressed as a combination of the 
   120      * IDE_DISC_* flags above.
   121      * @param disc pointer to the disc structure
   122      * @return an integer status value.
   123      */
   124     int (*drive_status)(struct gdrom_disc *disc);
   126     /**
   127      * Begin playing audio from the given lba address on the disc.
   128      */
   129     gdrom_error_t (*play_audio)(struct gdrom_disc *disc, uint32_t lba, uint32_t endlba);
   131     /**
   132      * Executed once per time slice to perform house-keeping operations 
   133      * (checking disc status, media changed, etc).
   134      */
   135     uint32_t (*run_time_slice)( struct gdrom_disc *disc, uint32_t nanosecs );
   137     /**
   138      * Close the disc and release any storage or resources allocated including
   139      * the disc structure itself.
   140      */
   141     void (*close)( struct gdrom_disc *disc );
   142     const gchar *name; /* Device name / Image filename */
   143 } *gdrom_disc_t;
   146 typedef struct gdrom_image {
   147     struct gdrom_disc disc;
   148     int disc_type;
   149     int track_count;
   150     struct gdrom_track track[99];
   151     gchar mcn[14]; /* Media catalogue number */
   152     FILE *file; /* Open file stream */
   153 } *gdrom_image_t;
   155 /**
   156  *
   157  */
   158 typedef struct gdrom_image_class {
   159     const gchar *name;
   160     const gchar *extension;
   161     gboolean (*is_valid_file)(FILE *f);
   162     gdrom_disc_t (*open_image_file)(const gchar *filename, FILE *f);
   163 } *gdrom_image_class_t;
   165 extern struct gdrom_image_class nrg_image_class;
   166 extern struct gdrom_image_class cdi_image_class;
   167 extern struct gdrom_image_class gdi_image_class;
   168 extern struct gdrom_image_class cdrom_device_class;
   170 /**
   171  * Construct a new image file using the default methods.
   172  */
   173 gdrom_disc_t gdrom_image_new( const gchar *filename, FILE *f );
   175 /**
   176  * Open an image file
   177  */
   178 gdrom_disc_t gdrom_image_open( const gchar *filename );
   180 /**
   181  * Dump image info
   182  */
   183 void gdrom_image_dump_info( gdrom_disc_t d );
   185 /**
   186  * Destroy an image data structure without closing the file
   187  * (Intended for use from image loaders only)
   188  */
   189 void gdrom_image_destroy_no_close( gdrom_disc_t d );
   191 /**
   192  * Retrieve the disc table of contents, and write it into the buffer in the 
   193  * format expected by the DC.
   194  * @return 0 on success, error code on failure (eg no disc mounted)
   195  */
   196 gdrom_error_t gdrom_get_toc( unsigned char *buf );
   198 /**
   199  * Retrieve the short (6-byte) session info, and write it into the buffer.
   200  * @return 0 on success, error code on failure.
   201  */
   202 gdrom_error_t gdrom_get_info( unsigned char *buf, int session );
   204 gdrom_track_t gdrom_get_track( int track_no );
   206 uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
   208 /**
   209  * Shortcut to open and mount an image file
   210  * @return true on success
   211  */
   212 gboolean gdrom_mount_image( const gchar *filename );
   214 void gdrom_mount_disc( gdrom_disc_t disc );
   216 void gdrom_unmount_disc( void );
   218 gboolean gdrom_is_mounted( void );
   220 gdrom_disc_t gdrom_get_current_disc();
   222 GList *gdrom_get_native_devices();
   224 uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
   225 			     int mode, unsigned char *buf, uint32_t *length );
   227 #endif
.