Search
lxdream.org :: lxdream/src/gdrom/gdrom.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.h
changeset 237:6f1a429c9d12
prev168:203a72138e16
next245:a1d0655a88d3
author nkeynes
date Thu Dec 14 12:31:38 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Add preliminary linux native CD driver support
file annotate diff log raw
nkeynes@125
     1
/**
nkeynes@237
     2
 * $Id: gdrom.h,v 1.8 2006-12-14 12:31:38 nkeynes Exp $
nkeynes@125
     3
 *
nkeynes@125
     4
 * This file defines the structures and functions used by the GD-Rom
nkeynes@125
     5
 * disc driver. (ie, the modules that supply a CD image to be used by the
nkeynes@125
     6
 * system).
nkeynes@125
     7
 *
nkeynes@125
     8
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@125
     9
 *
nkeynes@125
    10
 * This program is free software; you can redistribute it and/or modify
nkeynes@125
    11
 * it under the terms of the GNU General Public License as published by
nkeynes@125
    12
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@125
    13
 * (at your option) any later version.
nkeynes@125
    14
 *
nkeynes@125
    15
 * This program is distributed in the hope that it will be useful,
nkeynes@125
    16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@125
    17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@125
    18
 * GNU General Public License for more details.
nkeynes@125
    19
 */
nkeynes@125
    20
nkeynes@125
    21
#ifndef dream_gdrom_H
nkeynes@125
    22
#define dream_gdrom_H 1
nkeynes@125
    23
nkeynes@125
    24
#include "dream.h"
nkeynes@125
    25
nkeynes@149
    26
typedef uint16_t gdrom_error_t;
nkeynes@149
    27
nkeynes@138
    28
struct gdrom_toc {
nkeynes@142
    29
    uint32_t track[99];
nkeynes@125
    30
    uint32_t first, last, leadout;
nkeynes@138
    31
};
nkeynes@138
    32
nkeynes@138
    33
#define GDROM_PREGAP 150  /* Sectors */
nkeynes@138
    34
nkeynes@138
    35
extern uint32_t gdrom_sector_size[];
nkeynes@138
    36
#define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
nkeynes@138
    37
typedef enum {
nkeynes@138
    38
    GDROM_MODE1,
nkeynes@138
    39
    GDROM_MODE2,
nkeynes@138
    40
    GDROM_MODE2_XA1,
nkeynes@138
    41
    GDROM_MODE2_XA2,
nkeynes@138
    42
    GDROM_CDDA,
nkeynes@143
    43
    GDROM_GD,
nkeynes@143
    44
    GDROM_RAW
nkeynes@138
    45
} gdrom_track_mode_t;
nkeynes@138
    46
nkeynes@138
    47
/* The disc register indicates the current contents of the drive. When open
nkeynes@138
    48
 * contains 0x06.
nkeynes@138
    49
 */
nkeynes@138
    50
#define IDE_DISC_AUDIO 0x00
nkeynes@138
    51
#define IDE_DISC_NONE  0x06
nkeynes@138
    52
#define IDE_DISC_CDROM 0x20
nkeynes@138
    53
#define IDE_DISC_GDROM 0x80
nkeynes@138
    54
#define IDE_DISC_READY 0x01 /* ored with above */
nkeynes@138
    55
#define IDE_DISC_IDLE  0x02 /* ie spun-down */
nkeynes@138
    56
nkeynes@142
    57
#define TRACK_PRE_EMPHASIS   0x10
nkeynes@142
    58
#define TRACK_COPY_PERMITTED 0x20
nkeynes@142
    59
#define TRACK_DATA           0x40
nkeynes@142
    60
#define TRACK_FOUR_CHANNEL   0x80
nkeynes@142
    61
nkeynes@138
    62
struct gdrom_track {
nkeynes@138
    63
    gdrom_track_mode_t mode;
nkeynes@142
    64
    uint8_t flags;        /* Track flags */
nkeynes@138
    65
    int      session;     /* session # containing this track */
nkeynes@138
    66
    uint32_t lba;         /* start sector address */
nkeynes@138
    67
    uint32_t sector_size; /* For convenience, determined by mode */
nkeynes@138
    68
    uint32_t sector_count;
nkeynes@138
    69
    uint32_t offset; /* File offset of start of track - image files only */
nkeynes@138
    70
};
nkeynes@125
    71
nkeynes@125
    72
nkeynes@125
    73
typedef struct gdrom_disc {
nkeynes@138
    74
    int disc_type;
nkeynes@138
    75
    int track_count;
nkeynes@138
    76
    struct gdrom_track track[99];
nkeynes@138
    77
    gchar mcn[14]; /* Media catalogue number */
nkeynes@138
    78
    const gchar *filename; /* Image filename */
nkeynes@138
    79
    FILE *file; /* Stream, for image files */
nkeynes@152
    80
    gdrom_error_t (*read_sectors)( struct gdrom_disc *disc,
nkeynes@138
    81
			      uint32_t lba, uint32_t sector_count,
nkeynes@143
    82
			      int mode, char *buf, uint32_t *length );
nkeynes@138
    83
    void (*close)( struct gdrom_disc *disc );
nkeynes@125
    84
} *gdrom_disc_t;
nkeynes@125
    85
nkeynes@138
    86
/**
nkeynes@168
    87
 *
nkeynes@168
    88
 */
nkeynes@168
    89
typedef struct gdrom_image_class {
nkeynes@168
    90
    const gchar *name;
nkeynes@168
    91
    const gchar *extension;
nkeynes@168
    92
    gboolean (*is_valid_file)(FILE *f);
nkeynes@168
    93
    gdrom_disc_t (*open_image_file)(const gchar *filename, FILE *f);
nkeynes@168
    94
} *gdrom_image_class_t;
nkeynes@168
    95
nkeynes@168
    96
extern struct gdrom_image_class nrg_image_class;
nkeynes@168
    97
extern struct gdrom_image_class cdi_image_class;
nkeynes@237
    98
extern struct gdrom_image_class linux_device_class;
nkeynes@168
    99
nkeynes@168
   100
/**
nkeynes@138
   101
 * Construct a new image file using the default methods.
nkeynes@138
   102
 */
nkeynes@138
   103
gdrom_disc_t gdrom_image_new( FILE *file );
nkeynes@125
   104
nkeynes@138
   105
/**
nkeynes@138
   106
 * Open an image file
nkeynes@138
   107
 */
nkeynes@138
   108
gdrom_disc_t gdrom_image_open( const gchar *filename );
nkeynes@138
   109
nkeynes@138
   110
/**
nkeynes@138
   111
 * Retrieve the disc table of contents, and write it into the buffer in the 
nkeynes@138
   112
 * format expected by the DC.
nkeynes@149
   113
 * @return 0 on success, error code on failure (eg no disc mounted)
nkeynes@138
   114
 */
nkeynes@149
   115
gdrom_error_t gdrom_get_toc( char *buf );
nkeynes@149
   116
nkeynes@149
   117
/**
nkeynes@152
   118
 * Retrieve the short (6-byte) session info, and write it into the buffer.
nkeynes@149
   119
 * @return 0 on success, error code on failure.
nkeynes@149
   120
 */
nkeynes@152
   121
gdrom_error_t gdrom_get_info( char *buf, int session );
nkeynes@138
   122
nkeynes@138
   123
/**
nkeynes@138
   124
 * Shortcut to open and mount an image file
nkeynes@138
   125
 */
nkeynes@138
   126
gdrom_disc_t gdrom_mount_image( const gchar *filename );
nkeynes@138
   127
nkeynes@138
   128
void gdrom_mount_disc( gdrom_disc_t disc );
nkeynes@138
   129
nkeynes@138
   130
void gdrom_unmount_disc( void );
nkeynes@138
   131
nkeynes@138
   132
gboolean gdrom_is_mounted( void );
nkeynes@138
   133
nkeynes@138
   134
uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
nkeynes@143
   135
			     int mode, char *buf, uint32_t *length );
nkeynes@125
   136
nkeynes@125
   137
#endif
.