Search
lxdream.org :: lxdream/src/gdrom/gdrom.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.h
changeset 245:a1d0655a88d3
prev237:6f1a429c9d12
next342:850502f0e8de
author nkeynes
date Thu Jan 11 12:14:11 2007 +0000 (17 years ago)
permissions -rw-r--r--
last change Always return TRUE at end of execute instruction (oops)
view annotate diff log raw
     1 /**
     2  * $Id: gdrom.h,v 1.9 2006-12-19 09:52:56 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"
    26 typedef uint16_t gdrom_error_t;
    28 struct gdrom_toc {
    29     uint32_t track[99];
    30     uint32_t first, last, leadout;
    31 };
    33 #define GDROM_PREGAP 150  /* Sectors */
    35 extern uint32_t gdrom_sector_size[];
    36 #define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
    37 typedef enum {
    38     GDROM_MODE1,
    39     GDROM_MODE2,
    40     GDROM_MODE2_XA1,
    41     GDROM_MODE2_XA2,
    42     GDROM_CDDA,
    43     GDROM_GD,
    44     GDROM_RAW
    45 } gdrom_track_mode_t;
    47 /* The disc register indicates the current contents of the drive. When open
    48  * contains 0x06.
    49  */
    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
    62 typedef struct gdrom_track {
    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 */
    70 } *gdrom_track_t;
    73 typedef struct gdrom_disc {
    74     int disc_type;
    75     int track_count;
    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 );
    84 } *gdrom_disc_t;
    86 /**
    87  *
    88  */
    89 typedef struct gdrom_image_class {
    90     const gchar *name;
    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;
   100 /**
   101  * Construct a new image file using the default methods.
   102  */
   103 gdrom_disc_t gdrom_image_new( FILE *file );
   105 /**
   106  * Open an image file
   107  */
   108 gdrom_disc_t gdrom_image_open( const gchar *filename );
   110 /**
   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)
   114  */
   115 gdrom_error_t gdrom_get_toc( char *buf );
   117 /**
   118  * Retrieve the short (6-byte) session info, and write it into the buffer.
   119  * @return 0 on success, error code on failure.
   120  */
   121 gdrom_error_t gdrom_get_info( char *buf, int session );
   123 gdrom_track_t gdrom_get_track( int track_no );
   125 uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
   127 /**
   128  * Shortcut to open and mount an image file
   129  */
   130 gdrom_disc_t gdrom_mount_image( const gchar *filename );
   132 void gdrom_mount_disc( gdrom_disc_t disc );
   134 void gdrom_unmount_disc( void );
   136 gboolean gdrom_is_mounted( void );
   138 uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
   139 			     int mode, char *buf, uint32_t *length );
   141 #endif
.