Search
lxdream.org :: lxdream/src/gdrom/gdrom.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.h
changeset 678:35eb00945316
prev644:ccae4bfa5f82
next709:18c39a8e504c
author nkeynes
date Thu May 29 11:00:26 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Split gdrom.h into public and private gddriver.h
Reorganize gdrom mount to use a disc change hook
file annotate diff log raw
1.1 --- a/src/gdrom/gdrom.h Sun Mar 02 11:38:08 2008 +0000
1.2 +++ b/src/gdrom/gdrom.h Thu May 29 11:00:26 2008 +0000
1.3 @@ -1,9 +1,8 @@
1.4 /**
1.5 * $Id$
1.6 *
1.7 - * This file defines the structures and functions used by the GD-Rom
1.8 - * disc driver. (ie, the modules that supply a CD image to be used by the
1.9 - * system).
1.10 + * This file defines the public structures and functions exported by the
1.11 + * GD-Rom subsystem
1.12 *
1.13 * Copyright (c) 2005 Nathan Keynes.
1.14 *
1.15 @@ -18,176 +17,20 @@
1.16 * GNU General Public License for more details.
1.17 */
1.18
1.19 -#ifndef dream_gdrom_H
1.20 -#define dream_gdrom_H 1
1.21 +#ifndef lxdream_gdrom_H
1.22 +#define lxdream_gdrom_H 1
1.23
1.24 -#include "dream.h"
1.25 -#include <glib.h>
1.26 -
1.27 -#define MAX_SECTOR_SIZE 2352
1.28 +#include "lxdream.h"
1.29 +#include "hook.h"
1.30 +#include <glib/glist.h>
1.31
1.32 typedef uint16_t gdrom_error_t;
1.33
1.34 -struct gdrom_toc {
1.35 - uint32_t track[99];
1.36 - uint32_t first, last, leadout;
1.37 -};
1.38 +typedef struct gdrom_disc *gdrom_disc_t;
1.39
1.40 -#define GDROM_PREGAP 150 /* Sectors */
1.41 +typedef gboolean (*gdrom_disc_change_hook_t)( gdrom_disc_t new_disc, const gchar *new_disc_name, void *user_data );
1.42
1.43 -extern uint32_t gdrom_sector_size[];
1.44 -#define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
1.45 -/**
1.46 - * Track data type enumeration for cd images and devices. This somewhat
1.47 - * conflates the real track mode with the format of the image file, but
1.48 - * it manages to make sense so far.
1.49 - */
1.50 -typedef enum {
1.51 - GDROM_MODE0, // Mode 0 - should never actually see this
1.52 -/* Data-only modes (image file contains only the user data) */
1.53 - GDROM_MODE1, // Standard CD-Rom Mode 1 data track
1.54 - GDROM_MODE2_FORMLESS, // Mode 2 data track with no sub-structure (rare)
1.55 - GDROM_MODE2_FORM1, // Mode 2/Form 1 data track (standard for multisession)
1.56 - GDROM_MODE2_FORM2, // Mode 2/Form 2 data track (also fairly uncommon).
1.57 - GDROM_CDDA, // Standard audio track
1.58 -
1.59 -/* This one is somewhat special - the image file contains the 2336 bytes of
1.60 - * "extended user data", which in turn contains either a form 1 or form 2
1.61 - * sector. In other words it's a raw mode2 XA sector without the 16-byte header.
1.62 - */
1.63 - GDROM_SEMIRAW_MODE2,
1.64 -/* Raw modes (image contains the full 2352-byte sector). Split into XA/Non-XA
1.65 - * here for convenience, although it's really a session level flag. */
1.66 - GDROM_RAW_XA,
1.67 - GDROM_RAW_NONXA,
1.68 -} gdrom_track_mode_t;
1.69 -
1.70 -/* The disc register indicates the current contents of the drive. When open
1.71 - * contains 0x06.
1.72 - */
1.73 -#define IDE_DISC_READY 0x01 /* ored with above */
1.74 -#define IDE_DISC_IDLE 0x02 /* ie spun-down */
1.75 -#define IDE_DISC_NONE 0x06
1.76 -
1.77 -#define IDE_DISC_AUDIO 0x00
1.78 -#define IDE_DISC_CDROM 0x10
1.79 -#define IDE_DISC_CDROMXA 0x20
1.80 -#define IDE_DISC_GDROM 0x80
1.81 -
1.82 -#define TRACK_PRE_EMPHASIS 0x10
1.83 -#define TRACK_COPY_PERMITTED 0x20
1.84 -#define TRACK_DATA 0x40
1.85 -#define TRACK_FOUR_CHANNEL 0x80
1.86 -
1.87 -typedef struct gdrom_track {
1.88 - gdrom_track_mode_t mode;
1.89 - uint8_t flags; /* Track flags */
1.90 - int session; /* session # containing this track */
1.91 - uint32_t lba; /* start sector address */
1.92 - uint32_t sector_size; /* For convenience, determined by mode */
1.93 - uint32_t sector_count;
1.94 - uint32_t offset; /* File offset of start of track - image files only */
1.95 - FILE *file;
1.96 -} *gdrom_track_t;
1.97 -
1.98 -typedef struct gdrom_disc {
1.99 - /**
1.100 - * Read a single sector from the disc at the specified logical address.
1.101 - * @param disc pointer to the disc structure
1.102 - * @param lba logical address to read from
1.103 - * @param mode mode field from the read command
1.104 - * @param buf buffer to receive data (at least MAX_SECTOR_SIZE bytes)
1.105 - * @param length unsigned int to receive the number of bytes actually read.
1.106 - * @return PKT_ERR_OK on success, or another PKT_ERR_* code on failure.
1.107 - */
1.108 - gdrom_error_t (*read_sector)( struct gdrom_disc *disc,
1.109 - uint32_t lba, int mode,
1.110 - unsigned char *buf, uint32_t *length );
1.111 -
1.112 - /**
1.113 - * Read the TOC from the disc and write it into the specified buffer.
1.114 - * The method is responsible for returning the data in gd-rom
1.115 - * format.
1.116 - * @param disc pointer to the disc structure
1.117 - * @param buf buffer to receive data (0x198 bytes long)
1.118 - */
1.119 - gdrom_error_t (*read_toc)(struct gdrom_disc *disc, unsigned char *buf);
1.120 -
1.121 - /**
1.122 - * Read the information for the specified sector and return it in the
1.123 - * supplied buffer.
1.124 - * @param disc pointer to the disc structure
1.125 - * @param session of interest. If 0, return end of disc information.
1.126 - * @param buf buffer to receive data (6 bytes)
1.127 - */
1.128 - gdrom_error_t (*read_session)(struct gdrom_disc *disc, int session, unsigned char *buf);
1.129 -
1.130 - /**
1.131 - * Read the position information (subchannel) for the specified sector
1.132 - * and return it in the supplied buffer. This method does not need to
1.133 - * write the first 4 bytes of the buffer.
1.134 - * @param disc pointer to the disc structure
1.135 - * @param lba sector to get position information for
1.136 - * @param buf buffer to receive data (14 bytes)
1.137 - */
1.138 - gdrom_error_t (*read_position)(struct gdrom_disc *disc, uint32_t lba, unsigned char *buf);
1.139 -
1.140 - /**
1.141 - * Return the current disc status, expressed as a combination of the
1.142 - * IDE_DISC_* flags above.
1.143 - * @param disc pointer to the disc structure
1.144 - * @return an integer status value.
1.145 - */
1.146 - int (*drive_status)(struct gdrom_disc *disc);
1.147 -
1.148 - /**
1.149 - * Begin playing audio from the given lba address on the disc.
1.150 - */
1.151 - gdrom_error_t (*play_audio)(struct gdrom_disc *disc, uint32_t lba, uint32_t endlba);
1.152 -
1.153 - /**
1.154 - * Executed once per time slice to perform house-keeping operations
1.155 - * (checking disc status, media changed, etc).
1.156 - */
1.157 - uint32_t (*run_time_slice)( struct gdrom_disc *disc, uint32_t nanosecs );
1.158 -
1.159 - /**
1.160 - * Close the disc and release any storage or resources allocated including
1.161 - * the disc structure itself.
1.162 - */
1.163 - void (*close)( struct gdrom_disc *disc );
1.164 - const gchar *name; /* Device name / Image filename */
1.165 -} *gdrom_disc_t;
1.166 -
1.167 -
1.168 -typedef struct gdrom_image {
1.169 - struct gdrom_disc disc;
1.170 - int disc_type;
1.171 - int track_count;
1.172 - struct gdrom_track track[99];
1.173 - gchar mcn[14]; /* Media catalogue number */
1.174 - FILE *file; /* Open file stream */
1.175 -} *gdrom_image_t;
1.176 -
1.177 -/**
1.178 - *
1.179 - */
1.180 -typedef struct gdrom_image_class {
1.181 - const gchar *name;
1.182 - const gchar *extension;
1.183 - gboolean (*is_valid_file)(FILE *f);
1.184 - gdrom_disc_t (*open_image_file)(const gchar *filename, FILE *f);
1.185 -} *gdrom_image_class_t;
1.186 -
1.187 -extern struct gdrom_image_class nrg_image_class;
1.188 -extern struct gdrom_image_class cdi_image_class;
1.189 -extern struct gdrom_image_class gdi_image_class;
1.190 -extern struct gdrom_image_class cdrom_device_class;
1.191 -
1.192 -/**
1.193 - * Construct a new image file using the default methods.
1.194 - */
1.195 -gdrom_disc_t gdrom_image_new( const gchar *filename, FILE *f );
1.196 +DECLARE_HOOK(gdrom_disc_change_hook, gdrom_disc_change_hook_t);
1.197
1.198 /**
1.199 * Open an image file
1.200 @@ -199,28 +42,6 @@
1.201 */
1.202 void gdrom_image_dump_info( gdrom_disc_t d );
1.203
1.204 -/**
1.205 - * Destroy an image data structure without closing the file
1.206 - * (Intended for use from image loaders only)
1.207 - */
1.208 -void gdrom_image_destroy_no_close( gdrom_disc_t d );
1.209 -
1.210 -/**
1.211 - * Retrieve the disc table of contents, and write it into the buffer in the
1.212 - * format expected by the DC.
1.213 - * @return 0 on success, error code on failure (eg no disc mounted)
1.214 - */
1.215 -gdrom_error_t gdrom_get_toc( unsigned char *buf );
1.216 -
1.217 -/**
1.218 - * Retrieve the short (6-byte) session info, and write it into the buffer.
1.219 - * @return 0 on success, error code on failure.
1.220 - */
1.221 -gdrom_error_t gdrom_get_info( unsigned char *buf, int session );
1.222 -
1.223 -gdrom_track_t gdrom_get_track( int track_no );
1.224 -
1.225 -uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
1.226
1.227 /**
1.228 * Shortcut to open and mount an image file
1.229 @@ -236,16 +57,27 @@
1.230
1.231 gdrom_disc_t gdrom_get_current_disc();
1.232
1.233 +const gchar *gdrom_get_current_disc_name();
1.234 +
1.235 GList *gdrom_get_native_devices();
1.236
1.237 uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
1.238 int mode, unsigned char *buf, uint32_t *length );
1.239
1.240 +
1.241 /**
1.242 - * Given a base filename (eg for a .cue file), generate the path for the given
1.243 - * find_name relative to the original file.
1.244 - * @return a newly allocated string.
1.245 + * Retrieve the disc table of contents, and write it into the buffer in the
1.246 + * format expected by the DC.
1.247 + * @return 0 on success, error code on failure (eg no disc mounted)
1.248 */
1.249 -gchar *gdrom_get_relative_filename( const gchar *base_name, const gchar *find_name );
1.250 +gdrom_error_t gdrom_get_toc( unsigned char *buf );
1.251 +
1.252 +/**
1.253 + * Retrieve the short (6-byte) session info, and write it into the buffer.
1.254 + * @return 0 on success, error code on failure.
1.255 + */
1.256 +gdrom_error_t gdrom_get_info( unsigned char *buf, int session );
1.257 +
1.258 +uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
1.259
1.260 #endif
.