Search
lxdream.org :: lxdream/src/gdrom/gddriver.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gddriver.h
changeset 678:35eb00945316
next709:18c39a8e504c
author nkeynes
date Thu Jun 19 04:40:37 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Refactor the gd-rom list management out of the GUI (devices, recent files, etc).
Add gd-rom list to the cocoa UI.
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gdrom/gddriver.h Thu Jun 19 04:40:37 2008 +0000
1.3 @@ -0,0 +1,205 @@
1.4 +/**
1.5 + * $Id: gdrom.h 662 2008-03-02 11:38:08Z nkeynes $
1.6 + *
1.7 + * This file defines the structures and functions used by the GD-Rom
1.8 + * disc drivers. (ie, the modules that supply a CD image to be used by the
1.9 + * system).
1.10 + *
1.11 + * Copyright (c) 2005 Nathan Keynes.
1.12 + *
1.13 + * This program is free software; you can redistribute it and/or modify
1.14 + * it under the terms of the GNU General Public License as published by
1.15 + * the Free Software Foundation; either version 2 of the License, or
1.16 + * (at your option) any later version.
1.17 + *
1.18 + * This program is distributed in the hope that it will be useful,
1.19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.21 + * GNU General Public License for more details.
1.22 + */
1.23 +
1.24 +#ifndef lxdream_gdrom_driver_H
1.25 +#define lxdream_gdrom_driver_H 1
1.26 +
1.27 +#include <stdio.h>
1.28 +#include "lxdream.h"
1.29 +#include "gdrom/gdrom.h"
1.30 +#include <glib/gstrfuncs.h>
1.31 +
1.32 +#define MAX_SECTOR_SIZE 2352
1.33 +
1.34 +struct gdrom_toc {
1.35 + uint32_t track[99];
1.36 + uint32_t first, last, leadout;
1.37 +};
1.38 +
1.39 +#define GDROM_PREGAP 150 /* Sectors */
1.40 +
1.41 +extern uint32_t gdrom_sector_size[];
1.42 +#define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
1.43 +/**
1.44 + * Track data type enumeration for cd images and devices. This somewhat
1.45 + * conflates the real track mode with the format of the image file, but
1.46 + * it manages to make sense so far.
1.47 + */
1.48 +typedef enum {
1.49 + GDROM_MODE0, // Mode 0 - should never actually see this
1.50 +/* Data-only modes (image file contains only the user data) */
1.51 + GDROM_MODE1, // Standard CD-Rom Mode 1 data track
1.52 + GDROM_MODE2_FORMLESS, // Mode 2 data track with no sub-structure (rare)
1.53 + GDROM_MODE2_FORM1, // Mode 2/Form 1 data track (standard for multisession)
1.54 + GDROM_MODE2_FORM2, // Mode 2/Form 2 data track (also fairly uncommon).
1.55 + GDROM_CDDA, // Standard audio track
1.56 +
1.57 +/* This one is somewhat special - the image file contains the 2336 bytes of
1.58 + * "extended user data", which in turn contains either a form 1 or form 2
1.59 + * sector. In other words it's a raw mode2 XA sector without the 16-byte header.
1.60 + */
1.61 + GDROM_SEMIRAW_MODE2,
1.62 +/* Raw modes (image contains the full 2352-byte sector). Split into XA/Non-XA
1.63 + * here for convenience, although it's really a session level flag. */
1.64 + GDROM_RAW_XA,
1.65 + GDROM_RAW_NONXA,
1.66 +} gdrom_track_mode_t;
1.67 +
1.68 +/* The disc register indicates the current contents of the drive. When open
1.69 + * contains 0x06.
1.70 + */
1.71 +#define IDE_DISC_READY 0x01 /* ored with above */
1.72 +#define IDE_DISC_IDLE 0x02 /* ie spun-down */
1.73 +#define IDE_DISC_NONE 0x06
1.74 +
1.75 +#define IDE_DISC_AUDIO 0x00
1.76 +#define IDE_DISC_CDROM 0x10
1.77 +#define IDE_DISC_CDROMXA 0x20
1.78 +#define IDE_DISC_GDROM 0x80
1.79 +
1.80 +#define TRACK_PRE_EMPHASIS 0x10
1.81 +#define TRACK_COPY_PERMITTED 0x20
1.82 +#define TRACK_DATA 0x40
1.83 +#define TRACK_FOUR_CHANNEL 0x80
1.84 +
1.85 +typedef struct gdrom_track {
1.86 + gdrom_track_mode_t mode;
1.87 + uint8_t flags; /* Track flags */
1.88 + int session; /* session # containing this track */
1.89 + uint32_t lba; /* start sector address */
1.90 + uint32_t sector_size; /* For convenience, determined by mode */
1.91 + uint32_t sector_count;
1.92 + uint32_t offset; /* File offset of start of track - image files only */
1.93 + FILE *file;
1.94 +} *gdrom_track_t;
1.95 +
1.96 +struct gdrom_disc {
1.97 + /**
1.98 + * Read a single sector from the disc at the specified logical address.
1.99 + * @param disc pointer to the disc structure
1.100 + * @param lba logical address to read from
1.101 + * @param mode mode field from the read command
1.102 + * @param buf buffer to receive data (at least MAX_SECTOR_SIZE bytes)
1.103 + * @param length unsigned int to receive the number of bytes actually read.
1.104 + * @return PKT_ERR_OK on success, or another PKT_ERR_* code on failure.
1.105 + */
1.106 + gdrom_error_t (*read_sector)( struct gdrom_disc *disc,
1.107 + uint32_t lba, int mode,
1.108 + unsigned char *buf, uint32_t *length );
1.109 +
1.110 + /**
1.111 + * Read the TOC from the disc and write it into the specified buffer.
1.112 + * The method is responsible for returning the data in gd-rom
1.113 + * format.
1.114 + * @param disc pointer to the disc structure
1.115 + * @param buf buffer to receive data (0x198 bytes long)
1.116 + */
1.117 + gdrom_error_t (*read_toc)(struct gdrom_disc *disc, unsigned char *buf);
1.118 +
1.119 + /**
1.120 + * Read the information for the specified sector and return it in the
1.121 + * supplied buffer.
1.122 + * @param disc pointer to the disc structure
1.123 + * @param session of interest. If 0, return end of disc information.
1.124 + * @param buf buffer to receive data (6 bytes)
1.125 + */
1.126 + gdrom_error_t (*read_session)(struct gdrom_disc *disc, int session, unsigned char *buf);
1.127 +
1.128 + /**
1.129 + * Read the position information (subchannel) for the specified sector
1.130 + * and return it in the supplied buffer. This method does not need to
1.131 + * write the first 4 bytes of the buffer.
1.132 + * @param disc pointer to the disc structure
1.133 + * @param lba sector to get position information for
1.134 + * @param buf buffer to receive data (14 bytes)
1.135 + */
1.136 + gdrom_error_t (*read_position)(struct gdrom_disc *disc, uint32_t lba, unsigned char *buf);
1.137 +
1.138 + /**
1.139 + * Return the current disc status, expressed as a combination of the
1.140 + * IDE_DISC_* flags above.
1.141 + * @param disc pointer to the disc structure
1.142 + * @return an integer status value.
1.143 + */
1.144 + int (*drive_status)(struct gdrom_disc *disc);
1.145 +
1.146 + /**
1.147 + * Begin playing audio from the given lba address on the disc.
1.148 + */
1.149 + gdrom_error_t (*play_audio)(struct gdrom_disc *disc, uint32_t lba, uint32_t endlba);
1.150 +
1.151 + /**
1.152 + * Executed once per time slice to perform house-keeping operations
1.153 + * (checking disc status, media changed, etc).
1.154 + */
1.155 + uint32_t (*run_time_slice)( struct gdrom_disc *disc, uint32_t nanosecs );
1.156 +
1.157 + /**
1.158 + * Close the disc and release any storage or resources allocated including
1.159 + * the disc structure itself.
1.160 + */
1.161 + void (*close)( struct gdrom_disc *disc );
1.162 + const gchar *name; /* Device name / Image filename */
1.163 +};
1.164 +
1.165 +typedef struct gdrom_image {
1.166 + struct gdrom_disc disc;
1.167 + int disc_type;
1.168 + int track_count;
1.169 + struct gdrom_track track[99];
1.170 + gchar mcn[14]; /* Media catalogue number */
1.171 + FILE *file; /* Open file stream */
1.172 +} *gdrom_image_t;
1.173 +
1.174 +/**
1.175 + *
1.176 + */
1.177 +typedef struct gdrom_image_class {
1.178 + const gchar *name;
1.179 + const gchar *extension;
1.180 + gboolean (*is_valid_file)(FILE *f);
1.181 + gdrom_disc_t (*open_image_file)(const gchar *filename, FILE *f);
1.182 +} *gdrom_image_class_t;
1.183 +
1.184 +extern struct gdrom_image_class nrg_image_class;
1.185 +extern struct gdrom_image_class cdi_image_class;
1.186 +extern struct gdrom_image_class gdi_image_class;
1.187 +extern struct gdrom_image_class cdrom_device_class;
1.188 +
1.189 +/**
1.190 + * Construct a new image file using the default methods.
1.191 + */
1.192 +gdrom_disc_t gdrom_image_new( const gchar *filename, FILE *f );
1.193 +
1.194 +/**
1.195 + * Destroy an image data structure without closing the file
1.196 + * (Intended for use from image loaders only)
1.197 + */
1.198 +void gdrom_image_destroy_no_close( gdrom_disc_t d );
1.199 +
1.200 +
1.201 +/**
1.202 + * Given a base filename (eg for a .cue file), generate the path for the given
1.203 + * find_name relative to the original file.
1.204 + * @return a newly allocated string.
1.205 + */
1.206 +gchar *gdrom_get_relative_filename( const gchar *base_name, const gchar *find_name );
1.207 +
1.208 +#endif
.