2 * $Id: gdrom.h,v 1.8 2006-12-14 12:31:38 nkeynes Exp $
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
8 * Copyright (c) 2005 Nathan Keynes.
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.
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.
22 #define dream_gdrom_H 1
26 typedef uint16_t gdrom_error_t;
30 uint32_t first, last, leadout;
33 #define GDROM_PREGAP 150 /* Sectors */
35 extern uint32_t gdrom_sector_size[];
36 #define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
47 /* The disc register indicates the current contents of the drive. When open
50 #define IDE_DISC_AUDIO 0x00
51 #define IDE_DISC_NONE 0x06
52 #define IDE_DISC_CDROM 0x20
53 #define IDE_DISC_GDROM 0x80
54 #define IDE_DISC_READY 0x01 /* ored with above */
55 #define IDE_DISC_IDLE 0x02 /* ie spun-down */
57 #define TRACK_PRE_EMPHASIS 0x10
58 #define TRACK_COPY_PERMITTED 0x20
59 #define TRACK_DATA 0x40
60 #define TRACK_FOUR_CHANNEL 0x80
63 gdrom_track_mode_t mode;
64 uint8_t flags; /* Track flags */
65 int session; /* session # containing this track */
66 uint32_t lba; /* start sector address */
67 uint32_t sector_size; /* For convenience, determined by mode */
68 uint32_t sector_count;
69 uint32_t offset; /* File offset of start of track - image files only */
73 typedef struct gdrom_disc {
76 struct gdrom_track track[99];
77 gchar mcn[14]; /* Media catalogue number */
78 const gchar *filename; /* Image filename */
79 FILE *file; /* Stream, for image files */
80 gdrom_error_t (*read_sectors)( struct gdrom_disc *disc,
81 uint32_t lba, uint32_t sector_count,
82 int mode, char *buf, uint32_t *length );
83 void (*close)( struct gdrom_disc *disc );
89 typedef struct gdrom_image_class {
91 const gchar *extension;
92 gboolean (*is_valid_file)(FILE *f);
93 gdrom_disc_t (*open_image_file)(const gchar *filename, FILE *f);
94 } *gdrom_image_class_t;
96 extern struct gdrom_image_class nrg_image_class;
97 extern struct gdrom_image_class cdi_image_class;
98 extern struct gdrom_image_class linux_device_class;
101 * Construct a new image file using the default methods.
103 gdrom_disc_t gdrom_image_new( FILE *file );
108 gdrom_disc_t gdrom_image_open( const gchar *filename );
111 * Retrieve the disc table of contents, and write it into the buffer in the
112 * format expected by the DC.
113 * @return 0 on success, error code on failure (eg no disc mounted)
115 gdrom_error_t gdrom_get_toc( char *buf );
118 * Retrieve the short (6-byte) session info, and write it into the buffer.
119 * @return 0 on success, error code on failure.
121 gdrom_error_t gdrom_get_info( char *buf, int session );
124 * Shortcut to open and mount an image file
126 gdrom_disc_t gdrom_mount_image( const gchar *filename );
128 void gdrom_mount_disc( gdrom_disc_t disc );
130 void gdrom_unmount_disc( void );
132 gboolean gdrom_is_mounted( void );
134 uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
135 int mode, char *buf, uint32_t *length );
.