Search
lxdream.org :: lxdream :: r678:35eb00945316
lxdream 0.9.1
released Jun 29
Download Now
changeset678:35eb00945316
parent677:3ee62740ff8f
child679:f5ae66677a49
authornkeynes
dateThu May 29 11:00:26 2008 +0000 (11 years ago)
Split gdrom.h into public and private gddriver.h
Reorganize gdrom mount to use a disc change hook
src/drivers/cd_linux.c
src/drivers/cd_none.c
src/gdrom/cdi.c
src/gdrom/edc_ecc.c
src/gdrom/gddriver.h
src/gdrom/gdi.c
src/gdrom/gdimage.c
src/gdrom/gdrom.c
src/gdrom/gdrom.h
src/gdrom/ide.c
src/gdrom/nrg.c
src/gtkui/gdrom_menu.c
src/gtkui/gtkui.c
src/gui.h
src/hook.h
src/main.c
1.1 --- a/src/drivers/cd_linux.c Thu May 29 10:50:25 2008 +0000
1.2 +++ b/src/drivers/cd_linux.c Thu May 29 11:00:26 2008 +0000
1.3 @@ -26,7 +26,7 @@
1.4 #include <fstab.h>
1.5 #include <fcntl.h>
1.6
1.7 -#include "gdrom/gdrom.h"
1.8 +#include "gdrom/gddriver.h"
1.9 #include "gdrom/packet.h"
1.10 #include "dream.h"
1.11
2.1 --- a/src/drivers/cd_none.c Thu May 29 10:50:25 2008 +0000
2.2 +++ b/src/drivers/cd_none.c Thu May 29 11:00:26 2008 +0000
2.3 @@ -16,7 +16,7 @@
2.4 * GNU General Public License for more details.
2.5 */
2.6
2.7 -#include "gdrom/gdrom.h"
2.8 +#include "gdrom/gddriver.h"
2.9
2.10 static gboolean cdnone_image_is_valid( FILE *f );
2.11 static gdrom_disc_t cdnone_open_device( const gchar *filename, FILE *f );
3.1 --- a/src/gdrom/cdi.c Thu May 29 10:50:25 2008 +0000
3.2 +++ b/src/gdrom/cdi.c Thu May 29 11:00:26 2008 +0000
3.3 @@ -22,7 +22,7 @@
3.4 #include <fcntl.h>
3.5 #include <errno.h>
3.6 #include <sys/stat.h>
3.7 -#include "gdrom/gdrom.h"
3.8 +#include "gdrom/gddriver.h"
3.9
3.10 #define CDI_V2_ID 0x80000004
3.11 #define CDI_V3_ID 0x80000005
4.1 --- a/src/gdrom/edc_ecc.c Thu May 29 10:50:25 2008 +0000
4.2 +++ b/src/gdrom/edc_ecc.c Thu May 29 11:00:26 2008 +0000
4.3 @@ -43,7 +43,7 @@
4.4 #include <stdint.h>
4.5 #include <stdio.h>
4.6 #include <string.h>
4.7 -#include "gdrom.h"
4.8 +#include "gdrom/gddriver.h"
4.9 #include "ecc.h"
4.10
4.11 #define xaligned(a, s) ((((uintptr_t)(a)) & (s)) == 0 )
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/src/gdrom/gddriver.h Thu May 29 11:00:26 2008 +0000
5.3 @@ -0,0 +1,205 @@
5.4 +/**
5.5 + * $Id: gdrom.h 662 2008-03-02 11:38:08Z nkeynes $
5.6 + *
5.7 + * This file defines the structures and functions used by the GD-Rom
5.8 + * disc drivers. (ie, the modules that supply a CD image to be used by the
5.9 + * system).
5.10 + *
5.11 + * Copyright (c) 2005 Nathan Keynes.
5.12 + *
5.13 + * This program is free software; you can redistribute it and/or modify
5.14 + * it under the terms of the GNU General Public License as published by
5.15 + * the Free Software Foundation; either version 2 of the License, or
5.16 + * (at your option) any later version.
5.17 + *
5.18 + * This program is distributed in the hope that it will be useful,
5.19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.21 + * GNU General Public License for more details.
5.22 + */
5.23 +
5.24 +#ifndef lxdream_gdrom_driver_H
5.25 +#define lxdream_gdrom_driver_H 1
5.26 +
5.27 +#include <stdio.h>
5.28 +#include "lxdream.h"
5.29 +#include "gdrom/gdrom.h"
5.30 +#include <glib/gstrfuncs.h>
5.31 +
5.32 +#define MAX_SECTOR_SIZE 2352
5.33 +
5.34 +struct gdrom_toc {
5.35 + uint32_t track[99];
5.36 + uint32_t first, last, leadout;
5.37 +};
5.38 +
5.39 +#define GDROM_PREGAP 150 /* Sectors */
5.40 +
5.41 +extern uint32_t gdrom_sector_size[];
5.42 +#define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
5.43 +/**
5.44 + * Track data type enumeration for cd images and devices. This somewhat
5.45 + * conflates the real track mode with the format of the image file, but
5.46 + * it manages to make sense so far.
5.47 + */
5.48 +typedef enum {
5.49 + GDROM_MODE0, // Mode 0 - should never actually see this
5.50 +/* Data-only modes (image file contains only the user data) */
5.51 + GDROM_MODE1, // Standard CD-Rom Mode 1 data track
5.52 + GDROM_MODE2_FORMLESS, // Mode 2 data track with no sub-structure (rare)
5.53 + GDROM_MODE2_FORM1, // Mode 2/Form 1 data track (standard for multisession)
5.54 + GDROM_MODE2_FORM2, // Mode 2/Form 2 data track (also fairly uncommon).
5.55 + GDROM_CDDA, // Standard audio track
5.56 +
5.57 +/* This one is somewhat special - the image file contains the 2336 bytes of
5.58 + * "extended user data", which in turn contains either a form 1 or form 2
5.59 + * sector. In other words it's a raw mode2 XA sector without the 16-byte header.
5.60 + */
5.61 + GDROM_SEMIRAW_MODE2,
5.62 +/* Raw modes (image contains the full 2352-byte sector). Split into XA/Non-XA
5.63 + * here for convenience, although it's really a session level flag. */
5.64 + GDROM_RAW_XA,
5.65 + GDROM_RAW_NONXA,
5.66 +} gdrom_track_mode_t;
5.67 +
5.68 +/* The disc register indicates the current contents of the drive. When open
5.69 + * contains 0x06.
5.70 + */
5.71 +#define IDE_DISC_READY 0x01 /* ored with above */
5.72 +#define IDE_DISC_IDLE 0x02 /* ie spun-down */
5.73 +#define IDE_DISC_NONE 0x06
5.74 +
5.75 +#define IDE_DISC_AUDIO 0x00
5.76 +#define IDE_DISC_CDROM 0x10
5.77 +#define IDE_DISC_CDROMXA 0x20
5.78 +#define IDE_DISC_GDROM 0x80
5.79 +
5.80 +#define TRACK_PRE_EMPHASIS 0x10
5.81 +#define TRACK_COPY_PERMITTED 0x20
5.82 +#define TRACK_DATA 0x40
5.83 +#define TRACK_FOUR_CHANNEL 0x80
5.84 +
5.85 +typedef struct gdrom_track {
5.86 + gdrom_track_mode_t mode;
5.87 + uint8_t flags; /* Track flags */
5.88 + int session; /* session # containing this track */
5.89 + uint32_t lba; /* start sector address */
5.90 + uint32_t sector_size; /* For convenience, determined by mode */
5.91 + uint32_t sector_count;
5.92 + uint32_t offset; /* File offset of start of track - image files only */
5.93 + FILE *file;
5.94 +} *gdrom_track_t;
5.95 +
5.96 +struct gdrom_disc {
5.97 + /**
5.98 + * Read a single sector from the disc at the specified logical address.
5.99 + * @param disc pointer to the disc structure
5.100 + * @param lba logical address to read from
5.101 + * @param mode mode field from the read command
5.102 + * @param buf buffer to receive data (at least MAX_SECTOR_SIZE bytes)
5.103 + * @param length unsigned int to receive the number of bytes actually read.
5.104 + * @return PKT_ERR_OK on success, or another PKT_ERR_* code on failure.
5.105 + */
5.106 + gdrom_error_t (*read_sector)( struct gdrom_disc *disc,
5.107 + uint32_t lba, int mode,
5.108 + unsigned char *buf, uint32_t *length );
5.109 +
5.110 + /**
5.111 + * Read the TOC from the disc and write it into the specified buffer.
5.112 + * The method is responsible for returning the data in gd-rom
5.113 + * format.
5.114 + * @param disc pointer to the disc structure
5.115 + * @param buf buffer to receive data (0x198 bytes long)
5.116 + */
5.117 + gdrom_error_t (*read_toc)(struct gdrom_disc *disc, unsigned char *buf);
5.118 +
5.119 + /**
5.120 + * Read the information for the specified sector and return it in the
5.121 + * supplied buffer.
5.122 + * @param disc pointer to the disc structure
5.123 + * @param session of interest. If 0, return end of disc information.
5.124 + * @param buf buffer to receive data (6 bytes)
5.125 + */
5.126 + gdrom_error_t (*read_session)(struct gdrom_disc *disc, int session, unsigned char *buf);
5.127 +
5.128 + /**
5.129 + * Read the position information (subchannel) for the specified sector
5.130 + * and return it in the supplied buffer. This method does not need to
5.131 + * write the first 4 bytes of the buffer.
5.132 + * @param disc pointer to the disc structure
5.133 + * @param lba sector to get position information for
5.134 + * @param buf buffer to receive data (14 bytes)
5.135 + */
5.136 + gdrom_error_t (*read_position)(struct gdrom_disc *disc, uint32_t lba, unsigned char *buf);
5.137 +
5.138 + /**
5.139 + * Return the current disc status, expressed as a combination of the
5.140 + * IDE_DISC_* flags above.
5.141 + * @param disc pointer to the disc structure
5.142 + * @return an integer status value.
5.143 + */
5.144 + int (*drive_status)(struct gdrom_disc *disc);
5.145 +
5.146 + /**
5.147 + * Begin playing audio from the given lba address on the disc.
5.148 + */
5.149 + gdrom_error_t (*play_audio)(struct gdrom_disc *disc, uint32_t lba, uint32_t endlba);
5.150 +
5.151 + /**
5.152 + * Executed once per time slice to perform house-keeping operations
5.153 + * (checking disc status, media changed, etc).
5.154 + */
5.155 + uint32_t (*run_time_slice)( struct gdrom_disc *disc, uint32_t nanosecs );
5.156 +
5.157 + /**
5.158 + * Close the disc and release any storage or resources allocated including
5.159 + * the disc structure itself.
5.160 + */
5.161 + void (*close)( struct gdrom_disc *disc );
5.162 + const gchar *name; /* Device name / Image filename */
5.163 +};
5.164 +
5.165 +typedef struct gdrom_image {
5.166 + struct gdrom_disc disc;
5.167 + int disc_type;
5.168 + int track_count;
5.169 + struct gdrom_track track[99];
5.170 + gchar mcn[14]; /* Media catalogue number */
5.171 + FILE *file; /* Open file stream */
5.172 +} *gdrom_image_t;
5.173 +
5.174 +/**
5.175 + *
5.176 + */
5.177 +typedef struct gdrom_image_class {
5.178 + const gchar *name;
5.179 + const gchar *extension;
5.180 + gboolean (*is_valid_file)(FILE *f);
5.181 + gdrom_disc_t (*open_image_file)(const gchar *filename, FILE *f);
5.182 +} *gdrom_image_class_t;
5.183 +
5.184 +extern struct gdrom_image_class nrg_image_class;
5.185 +extern struct gdrom_image_class cdi_image_class;
5.186 +extern struct gdrom_image_class gdi_image_class;
5.187 +extern struct gdrom_image_class cdrom_device_class;
5.188 +
5.189 +/**
5.190 + * Construct a new image file using the default methods.
5.191 + */
5.192 +gdrom_disc_t gdrom_image_new( const gchar *filename, FILE *f );
5.193 +
5.194 +/**
5.195 + * Destroy an image data structure without closing the file
5.196 + * (Intended for use from image loaders only)
5.197 + */
5.198 +void gdrom_image_destroy_no_close( gdrom_disc_t d );
5.199 +
5.200 +
5.201 +/**
5.202 + * Given a base filename (eg for a .cue file), generate the path for the given
5.203 + * find_name relative to the original file.
5.204 + * @return a newly allocated string.
5.205 + */
5.206 +gchar *gdrom_get_relative_filename( const gchar *base_name, const gchar *find_name );
5.207 +
5.208 +#endif
6.1 --- a/src/gdrom/gdi.c Thu May 29 10:50:25 2008 +0000
6.2 +++ b/src/gdrom/gdi.c Thu May 29 11:00:26 2008 +0000
6.3 @@ -23,7 +23,7 @@
6.4 #include <errno.h>
6.5 #include <sys/stat.h>
6.6 #include <glib/gutils.h>
6.7 -#include "gdrom/gdrom.h"
6.8 +#include "gdrom/gddriver.h"
6.9
6.10
6.11 static gboolean gdi_image_is_valid( FILE *f );
7.1 --- a/src/gdrom/gdimage.c Thu May 29 10:50:25 2008 +0000
7.2 +++ b/src/gdrom/gdimage.c Thu May 29 11:00:26 2008 +0000
7.3 @@ -19,7 +19,7 @@
7.4 #include <assert.h>
7.5 #include <netinet/in.h>
7.6
7.7 -#include "gdrom/gdrom.h"
7.8 +#include "gdrom/gddriver.h"
7.9 #include "gdrom/packet.h"
7.10 #include "ecc.h"
7.11 #include "bootstrap.h"
8.1 --- a/src/gdrom/gdrom.c Thu May 29 10:50:25 2008 +0000
8.2 +++ b/src/gdrom/gdrom.c Thu May 29 11:00:26 2008 +0000
8.3 @@ -20,13 +20,22 @@
8.4 #include <stdio.h>
8.5 #include <fcntl.h>
8.6 #include <errno.h>
8.7 +#include <glib/gutils.h>
8.8 #include "gdrom/ide.h"
8.9 #include "gdrom/gdrom.h"
8.10 +#include "gdrom/gddriver.h"
8.11 #include "gdrom/packet.h"
8.12 #include "dream.h"
8.13
8.14 extern gdrom_disc_t gdrom_disc;
8.15
8.16 +DEFINE_HOOK( gdrom_disc_change_hook, gdrom_disc_change_hook_t )
8.17 +
8.18 +gdrom_fire_disc_changed( gdrom_disc_t disc )
8.19 +{
8.20 + CALL_HOOKS( gdrom_disc_change_hook, disc, disc == NULL ? NULL : disc->name );
8.21 +}
8.22 +
8.23 gdrom_image_class_t gdrom_image_classes[] = { &cdrom_device_class,
8.24 &nrg_image_class,
8.25 &cdi_image_class,
8.26 @@ -89,17 +98,20 @@
8.27
8.28 void gdrom_mount_disc( gdrom_disc_t disc )
8.29 {
8.30 - gdrom_unmount_disc();
8.31 - gdrom_disc = disc;
8.32 - gdrom_image_dump_info( disc );
8.33 + if( disc != gdrom_disc ) {
8.34 + gdrom_unmount_disc();
8.35 + gdrom_disc = disc;
8.36 + gdrom_image_dump_info( disc );
8.37 + gdrom_fire_disc_changed( disc );
8.38 + }
8.39 }
8.40
8.41 gboolean gdrom_mount_image( const gchar *filename )
8.42 {
8.43 gdrom_disc_t disc = gdrom_image_open(filename);
8.44 if( disc != NULL ) {
8.45 - gdrom_mount_disc( disc );
8.46 - return TRUE;
8.47 + gdrom_mount_disc( disc );
8.48 + return TRUE;
8.49 }
8.50 return FALSE;
8.51 }
8.52 @@ -107,7 +119,8 @@
8.53 void gdrom_unmount_disc( )
8.54 {
8.55 if( gdrom_disc != NULL ) {
8.56 - gdrom_disc->close(gdrom_disc);
8.57 + gdrom_disc->close(gdrom_disc);
8.58 + gdrom_fire_disc_changed(NULL);
8.59 }
8.60 gdrom_disc = NULL;
8.61
8.62 @@ -118,6 +131,15 @@
8.63 return gdrom_disc;
8.64 }
8.65
8.66 +const gchar *gdrom_get_current_disc_name()
8.67 +{
8.68 + if( gdrom_disc == NULL ) {
8.69 + return NULL;
8.70 + } else {
8.71 + return gdrom_disc->name;
8.72 + }
8.73 +}
8.74 +
8.75 gchar *gdrom_get_relative_filename( const gchar *base_name, const gchar *rel_name )
8.76 {
8.77 gchar *dirname = g_path_get_dirname(base_name);
9.1 --- a/src/gdrom/gdrom.h Thu May 29 10:50:25 2008 +0000
9.2 +++ b/src/gdrom/gdrom.h Thu May 29 11:00:26 2008 +0000
9.3 @@ -1,9 +1,8 @@
9.4 /**
9.5 * $Id$
9.6 *
9.7 - * This file defines the structures and functions used by the GD-Rom
9.8 - * disc driver. (ie, the modules that supply a CD image to be used by the
9.9 - * system).
9.10 + * This file defines the public structures and functions exported by the
9.11 + * GD-Rom subsystem
9.12 *
9.13 * Copyright (c) 2005 Nathan Keynes.
9.14 *
9.15 @@ -18,176 +17,20 @@
9.16 * GNU General Public License for more details.
9.17 */
9.18
9.19 -#ifndef dream_gdrom_H
9.20 -#define dream_gdrom_H 1
9.21 +#ifndef lxdream_gdrom_H
9.22 +#define lxdream_gdrom_H 1
9.23
9.24 -#include "dream.h"
9.25 -#include <glib.h>
9.26 -
9.27 -#define MAX_SECTOR_SIZE 2352
9.28 +#include "lxdream.h"
9.29 +#include "hook.h"
9.30 +#include <glib/glist.h>
9.31
9.32 typedef uint16_t gdrom_error_t;
9.33
9.34 -struct gdrom_toc {
9.35 - uint32_t track[99];
9.36 - uint32_t first, last, leadout;
9.37 -};
9.38 +typedef struct gdrom_disc *gdrom_disc_t;
9.39
9.40 -#define GDROM_PREGAP 150 /* Sectors */
9.41 +typedef gboolean (*gdrom_disc_change_hook_t)( gdrom_disc_t new_disc, const gchar *new_disc_name, void *user_data );
9.42
9.43 -extern uint32_t gdrom_sector_size[];
9.44 -#define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x]
9.45 -/**
9.46 - * Track data type enumeration for cd images and devices. This somewhat
9.47 - * conflates the real track mode with the format of the image file, but
9.48 - * it manages to make sense so far.
9.49 - */
9.50 -typedef enum {
9.51 - GDROM_MODE0, // Mode 0 - should never actually see this
9.52 -/* Data-only modes (image file contains only the user data) */
9.53 - GDROM_MODE1, // Standard CD-Rom Mode 1 data track
9.54 - GDROM_MODE2_FORMLESS, // Mode 2 data track with no sub-structure (rare)
9.55 - GDROM_MODE2_FORM1, // Mode 2/Form 1 data track (standard for multisession)
9.56 - GDROM_MODE2_FORM2, // Mode 2/Form 2 data track (also fairly uncommon).
9.57 - GDROM_CDDA, // Standard audio track
9.58 -
9.59 -/* This one is somewhat special - the image file contains the 2336 bytes of
9.60 - * "extended user data", which in turn contains either a form 1 or form 2
9.61 - * sector. In other words it's a raw mode2 XA sector without the 16-byte header.
9.62 - */
9.63 - GDROM_SEMIRAW_MODE2,
9.64 -/* Raw modes (image contains the full 2352-byte sector). Split into XA/Non-XA
9.65 - * here for convenience, although it's really a session level flag. */
9.66 - GDROM_RAW_XA,
9.67 - GDROM_RAW_NONXA,
9.68 -} gdrom_track_mode_t;
9.69 -
9.70 -/* The disc register indicates the current contents of the drive. When open
9.71 - * contains 0x06.
9.72 - */
9.73 -#define IDE_DISC_READY 0x01 /* ored with above */
9.74 -#define IDE_DISC_IDLE 0x02 /* ie spun-down */
9.75 -#define IDE_DISC_NONE 0x06
9.76 -
9.77 -#define IDE_DISC_AUDIO 0x00
9.78 -#define IDE_DISC_CDROM 0x10
9.79 -#define IDE_DISC_CDROMXA 0x20
9.80 -#define IDE_DISC_GDROM 0x80
9.81 -
9.82 -#define TRACK_PRE_EMPHASIS 0x10
9.83 -#define TRACK_COPY_PERMITTED 0x20
9.84 -#define TRACK_DATA 0x40
9.85 -#define TRACK_FOUR_CHANNEL 0x80
9.86 -
9.87 -typedef struct gdrom_track {
9.88 - gdrom_track_mode_t mode;
9.89 - uint8_t flags; /* Track flags */
9.90 - int session; /* session # containing this track */
9.91 - uint32_t lba; /* start sector address */
9.92 - uint32_t sector_size; /* For convenience, determined by mode */
9.93 - uint32_t sector_count;
9.94 - uint32_t offset; /* File offset of start of track - image files only */
9.95 - FILE *file;
9.96 -} *gdrom_track_t;
9.97 -
9.98 -typedef struct gdrom_disc {
9.99 - /**
9.100 - * Read a single sector from the disc at the specified logical address.
9.101 - * @param disc pointer to the disc structure
9.102 - * @param lba logical address to read from
9.103 - * @param mode mode field from the read command
9.104 - * @param buf buffer to receive data (at least MAX_SECTOR_SIZE bytes)
9.105 - * @param length unsigned int to receive the number of bytes actually read.
9.106 - * @return PKT_ERR_OK on success, or another PKT_ERR_* code on failure.
9.107 - */
9.108 - gdrom_error_t (*read_sector)( struct gdrom_disc *disc,
9.109 - uint32_t lba, int mode,
9.110 - unsigned char *buf, uint32_t *length );
9.111 -
9.112 - /**
9.113 - * Read the TOC from the disc and write it into the specified buffer.
9.114 - * The method is responsible for returning the data in gd-rom
9.115 - * format.
9.116 - * @param disc pointer to the disc structure
9.117 - * @param buf buffer to receive data (0x198 bytes long)
9.118 - */
9.119 - gdrom_error_t (*read_toc)(struct gdrom_disc *disc, unsigned char *buf);
9.120 -
9.121 - /**
9.122 - * Read the information for the specified sector and return it in the
9.123 - * supplied buffer.
9.124 - * @param disc pointer to the disc structure
9.125 - * @param session of interest. If 0, return end of disc information.
9.126 - * @param buf buffer to receive data (6 bytes)
9.127 - */
9.128 - gdrom_error_t (*read_session)(struct gdrom_disc *disc, int session, unsigned char *buf);
9.129 -
9.130 - /**
9.131 - * Read the position information (subchannel) for the specified sector
9.132 - * and return it in the supplied buffer. This method does not need to
9.133 - * write the first 4 bytes of the buffer.
9.134 - * @param disc pointer to the disc structure
9.135 - * @param lba sector to get position information for
9.136 - * @param buf buffer to receive data (14 bytes)
9.137 - */
9.138 - gdrom_error_t (*read_position)(struct gdrom_disc *disc, uint32_t lba, unsigned char *buf);
9.139 -
9.140 - /**
9.141 - * Return the current disc status, expressed as a combination of the
9.142 - * IDE_DISC_* flags above.
9.143 - * @param disc pointer to the disc structure
9.144 - * @return an integer status value.
9.145 - */
9.146 - int (*drive_status)(struct gdrom_disc *disc);
9.147 -
9.148 - /**
9.149 - * Begin playing audio from the given lba address on the disc.
9.150 - */
9.151 - gdrom_error_t (*play_audio)(struct gdrom_disc *disc, uint32_t lba, uint32_t endlba);
9.152 -
9.153 - /**
9.154 - * Executed once per time slice to perform house-keeping operations
9.155 - * (checking disc status, media changed, etc).
9.156 - */
9.157 - uint32_t (*run_time_slice)( struct gdrom_disc *disc, uint32_t nanosecs );
9.158 -
9.159 - /**
9.160 - * Close the disc and release any storage or resources allocated including
9.161 - * the disc structure itself.
9.162 - */
9.163 - void (*close)( struct gdrom_disc *disc );
9.164 - const gchar *name; /* Device name / Image filename */
9.165 -} *gdrom_disc_t;
9.166 -
9.167 -
9.168 -typedef struct gdrom_image {
9.169 - struct gdrom_disc disc;
9.170 - int disc_type;
9.171 - int track_count;
9.172 - struct gdrom_track track[99];
9.173 - gchar mcn[14]; /* Media catalogue number */
9.174 - FILE *file; /* Open file stream */
9.175 -} *gdrom_image_t;
9.176 -
9.177 -/**
9.178 - *
9.179 - */
9.180 -typedef struct gdrom_image_class {
9.181 - const gchar *name;
9.182 - const gchar *extension;
9.183 - gboolean (*is_valid_file)(FILE *f);
9.184 - gdrom_disc_t (*open_image_file)(const gchar *filename, FILE *f);
9.185 -} *gdrom_image_class_t;
9.186 -
9.187 -extern struct gdrom_image_class nrg_image_class;
9.188 -extern struct gdrom_image_class cdi_image_class;
9.189 -extern struct gdrom_image_class gdi_image_class;
9.190 -extern struct gdrom_image_class cdrom_device_class;
9.191 -
9.192 -/**
9.193 - * Construct a new image file using the default methods.
9.194 - */
9.195 -gdrom_disc_t gdrom_image_new( const gchar *filename, FILE *f );
9.196 +DECLARE_HOOK(gdrom_disc_change_hook, gdrom_disc_change_hook_t);
9.197
9.198 /**
9.199 * Open an image file
9.200 @@ -199,28 +42,6 @@
9.201 */
9.202 void gdrom_image_dump_info( gdrom_disc_t d );
9.203
9.204 -/**
9.205 - * Destroy an image data structure without closing the file
9.206 - * (Intended for use from image loaders only)
9.207 - */
9.208 -void gdrom_image_destroy_no_close( gdrom_disc_t d );
9.209 -
9.210 -/**
9.211 - * Retrieve the disc table of contents, and write it into the buffer in the
9.212 - * format expected by the DC.
9.213 - * @return 0 on success, error code on failure (eg no disc mounted)
9.214 - */
9.215 -gdrom_error_t gdrom_get_toc( unsigned char *buf );
9.216 -
9.217 -/**
9.218 - * Retrieve the short (6-byte) session info, and write it into the buffer.
9.219 - * @return 0 on success, error code on failure.
9.220 - */
9.221 -gdrom_error_t gdrom_get_info( unsigned char *buf, int session );
9.222 -
9.223 -gdrom_track_t gdrom_get_track( int track_no );
9.224 -
9.225 -uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
9.226
9.227 /**
9.228 * Shortcut to open and mount an image file
9.229 @@ -236,16 +57,27 @@
9.230
9.231 gdrom_disc_t gdrom_get_current_disc();
9.232
9.233 +const gchar *gdrom_get_current_disc_name();
9.234 +
9.235 GList *gdrom_get_native_devices();
9.236
9.237 uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
9.238 int mode, unsigned char *buf, uint32_t *length );
9.239
9.240 +
9.241 /**
9.242 - * Given a base filename (eg for a .cue file), generate the path for the given
9.243 - * find_name relative to the original file.
9.244 - * @return a newly allocated string.
9.245 + * Retrieve the disc table of contents, and write it into the buffer in the
9.246 + * format expected by the DC.
9.247 + * @return 0 on success, error code on failure (eg no disc mounted)
9.248 */
9.249 -gchar *gdrom_get_relative_filename( const gchar *base_name, const gchar *find_name );
9.250 +gdrom_error_t gdrom_get_toc( unsigned char *buf );
9.251 +
9.252 +/**
9.253 + * Retrieve the short (6-byte) session info, and write it into the buffer.
9.254 + * @return 0 on success, error code on failure.
9.255 + */
9.256 +gdrom_error_t gdrom_get_info( unsigned char *buf, int session );
9.257 +
9.258 +uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
9.259
9.260 #endif
10.1 --- a/src/gdrom/ide.c Thu May 29 10:50:25 2008 +0000
10.2 +++ b/src/gdrom/ide.c Thu May 29 11:00:26 2008 +0000
10.3 @@ -28,7 +28,7 @@
10.4 #include "mem.h"
10.5 #include "asic.h"
10.6 #include "gdrom/ide.h"
10.7 -#include "gdrom/gdrom.h"
10.8 +#include "gdrom/gddriver.h"
10.9 #include "gdrom/packet.h"
10.10
10.11 #define MAX_WRITE_BUF 4096
11.1 --- a/src/gdrom/nrg.c Thu May 29 10:50:25 2008 +0000
11.2 +++ b/src/gdrom/nrg.c Thu May 29 11:00:26 2008 +0000
11.3 @@ -21,7 +21,7 @@
11.4 #include <stdio.h>
11.5 #include <errno.h>
11.6 #include <glib/gtypes.h>
11.7 -#include "gdrom/gdrom.h"
11.8 +#include "gdrom/gddriver.h"
11.9 #include "dream.h"
11.10
11.11 static gboolean nrg_image_is_valid( FILE *f );
12.1 --- a/src/gtkui/gdrom_menu.c Thu May 29 10:50:25 2008 +0000
12.2 +++ b/src/gtkui/gdrom_menu.c Thu May 29 11:00:26 2008 +0000
12.3 @@ -89,27 +89,27 @@
12.4
12.5 void gdrom_menu_update_all()
12.6 {
12.7 - gdrom_disc_t disc = gdrom_get_current_disc();
12.8 + const gchar *disc_name = gdrom_get_current_disc_name();
12.9 gint posn = 0;
12.10 GList *ptr;
12.11
12.12 gdrom_menu_adjusting = TRUE;
12.13
12.14 - if( disc != NULL ) {
12.15 - posn = gdrom_menu_find_item( disc->name );
12.16 - if( posn == -1 ) {
12.17 - posn = gdrom_menu_add_recent_item( disc->name );
12.18 - gdrom_menu_rebuild_all();
12.19 - }
12.20 + if( disc_name != NULL ) {
12.21 + posn = gdrom_menu_find_item( disc_name );
12.22 + if( posn == -1 ) {
12.23 + posn = gdrom_menu_add_recent_item( disc_name );
12.24 + gdrom_menu_rebuild_all();
12.25 + }
12.26 }
12.27
12.28 for( ptr = gdrom_menu_list; ptr != NULL; ptr = g_list_next(ptr) ) {
12.29 - GtkWidget *menu = GTK_WIDGET(ptr->data);
12.30 - GList *children = gtk_container_get_children( GTK_CONTAINER(menu) );
12.31 - GList *item = g_list_nth( children, posn );
12.32 - assert( item != NULL );
12.33 - gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(item->data), TRUE );
12.34 - g_list_free(children);
12.35 + GtkWidget *menu = GTK_WIDGET(ptr->data);
12.36 + GList *children = gtk_container_get_children( GTK_CONTAINER(menu) );
12.37 + GList *item = g_list_nth( children, posn );
12.38 + assert( item != NULL );
12.39 + gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(item->data), TRUE );
12.40 + g_list_free(children);
12.41 }
12.42
12.43 gdrom_menu_adjusting = FALSE;
12.44 @@ -118,10 +118,16 @@
12.45 void gdrom_menu_empty_callback( GtkWidget *widget, gpointer user_data )
12.46 {
12.47 if( !gdrom_menu_adjusting ) {
12.48 - gdrom_unmount_disc();
12.49 - gdrom_menu_update_all();
12.50 - lxdream_set_global_config_value( CONFIG_GDROM, NULL );
12.51 - lxdream_save_config();
12.52 + gdrom_unmount_disc();
12.53 + lxdream_set_global_config_value( CONFIG_GDROM, NULL );
12.54 + lxdream_save_config();
12.55 + }
12.56 +}
12.57 +
12.58 +void gdrom_menu_disc_changed( gdrom_disc_t disc, const gchar *name, void *user_data )
12.59 +{
12.60 + if( !gdrom_menu_adjusting ) {
12.61 + gdrom_menu_update_all();
12.62 }
12.63 }
12.64
12.65 @@ -129,12 +135,11 @@
12.66 {
12.67 gboolean result = FALSE;
12.68 if( filename != NULL ) {
12.69 - result = gdrom_mount_image(filename);
12.70 + result = gdrom_mount_image(filename);
12.71 }
12.72 if( result ) {
12.73 - gdrom_menu_update_all();
12.74 - lxdream_set_global_config_value( CONFIG_GDROM, filename );
12.75 - lxdream_save_config();
12.76 + lxdream_set_global_config_value( CONFIG_GDROM, filename );
12.77 + lxdream_save_config();
12.78 }
12.79 return result;
12.80 }
12.81 @@ -142,8 +147,8 @@
12.82 void gdrom_menu_open_image_callback( GtkWidget *widget, gpointer user_data )
12.83 {
12.84 if( !gdrom_menu_adjusting ) {
12.85 - const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
12.86 - open_file_dialog( _("Open..."), gdrom_menu_open_file, NULL, NULL, dir );
12.87 + const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
12.88 + open_file_dialog( _("Open..."), gdrom_menu_open_file, NULL, NULL, dir );
12.89 }
12.90 }
12.91
12.92 @@ -228,6 +233,7 @@
12.93 void gdrom_menu_init()
12.94 {
12.95 const gchar *recent = lxdream_get_config_value( CONFIG_RECENT );
12.96 + register_gdrom_disc_change_hook( gdrom_menu_disc_changed, NULL );
12.97 gdrom_device_list = gdrom_get_native_devices();
12.98 if( recent != NULL ) {
12.99 gchar **list = g_strsplit(recent, ":", 5);
13.1 --- a/src/gtkui/gtkui.c Thu May 29 10:50:25 2008 +0000
13.2 +++ b/src/gtkui/gtkui.c Thu May 29 11:00:26 2008 +0000
13.3 @@ -16,20 +16,19 @@
13.4 * GNU General Public License for more details.
13.5 */
13.6
13.7 -#include "lxdream.h"
13.8 +#include <time.h>
13.9 +#include <stdlib.h>
13.10 +#include <unistd.h>
13.11 #include <sys/time.h>
13.12 -#include <time.h>
13.13 -#include <unistd.h>
13.14 #include <glib/gi18n.h>
13.15 #include <gtk/gtkversion.h>
13.16 +#include "lxdream.h"
13.17 #include "dreamcast.h"
13.18 +#include "dream.h"
13.19 #include "display.h"
13.20 #include "gdrom/gdrom.h"
13.21 #include "gtkui/gtkui.h"
13.22
13.23 -/* Base GUI clock is 10ms */
13.24 -#define GUI_TICK_PERIOD 10000000
13.25 -
13.26 void gtk_gui_start( void );
13.27 void gtk_gui_stop( void );
13.28 void gtk_gui_alloc_resources ( void );
13.29 @@ -370,36 +369,36 @@
13.30 {
13.31 gtk_gui_nanos += nanosecs;
13.32 if( gtk_gui_nanos > GUI_TICK_PERIOD ) { /* 10 ms */
13.33 - gtk_gui_nanos -= GUI_TICK_PERIOD;
13.34 - gtk_gui_ticks ++;
13.35 - uint32_t current_period = gtk_gui_ticks * GUI_TICK_PERIOD;
13.36 + gtk_gui_nanos -= GUI_TICK_PERIOD;
13.37 + gtk_gui_ticks ++;
13.38 + uint32_t current_period = gtk_gui_ticks * GUI_TICK_PERIOD;
13.39
13.40 - // Run the event loop
13.41 - while( gtk_events_pending() )
13.42 - gtk_main_iteration();
13.43 + // Run the event loop
13.44 + while( gtk_events_pending() )
13.45 + gtk_main_iteration();
13.46
13.47 - struct timeval tv;
13.48 - gettimeofday(&tv,NULL);
13.49 - uint32_t ns = ((tv.tv_sec - gtk_gui_lasttv.tv_sec) * 1000000000) +
13.50 - (tv.tv_usec - gtk_gui_lasttv.tv_usec)*1000;
13.51 - if( (ns * 1.05) < current_period ) {
13.52 - // We've gotten ahead - sleep for a little bit
13.53 - struct timespec tv;
13.54 - tv.tv_sec = 0;
13.55 - tv.tv_nsec = current_period - ns;
13.56 - nanosleep(&tv, &tv);
13.57 - }
13.58 + struct timeval tv;
13.59 + gettimeofday(&tv,NULL);
13.60 + uint32_t ns = ((tv.tv_sec - gtk_gui_lasttv.tv_sec) * 1000000000) +
13.61 + (tv.tv_usec - gtk_gui_lasttv.tv_usec)*1000;
13.62 + if( (ns * 1.05) < current_period ) {
13.63 + // We've gotten ahead - sleep for a little bit
13.64 + struct timespec tv;
13.65 + tv.tv_sec = 0;
13.66 + tv.tv_nsec = current_period - ns;
13.67 + nanosleep(&tv, &tv);
13.68 + }
13.69
13.70 - /* Update the display every 10 ticks (ie 10 times a second) and
13.71 - * save the current tv value */
13.72 - if( gtk_gui_ticks > 10 ) {
13.73 - gtk_gui_ticks -= 10;
13.74 -
13.75 - double speed = (float)( (double)current_period * 100.0 / ns );
13.76 - gtk_gui_lasttv.tv_sec = tv.tv_sec;
13.77 - gtk_gui_lasttv.tv_usec = tv.tv_usec;
13.78 - main_window_set_speed( main_win, speed );
13.79 - }
13.80 + /* Update the display every 10 ticks (ie 10 times a second) and
13.81 + * save the current tv value */
13.82 + if( gtk_gui_ticks > 10 ) {
13.83 + gtk_gui_ticks -= 10;
13.84 +
13.85 + double speed = (float)( (double)current_period * 100.0 / ns );
13.86 + gtk_gui_lasttv.tv_sec = tv.tv_sec;
13.87 + gtk_gui_lasttv.tv_usec = tv.tv_usec;
13.88 + main_window_set_speed( main_win, speed );
13.89 + }
13.90 }
13.91 return nanosecs;
13.92 }
14.1 --- a/src/gui.h Thu May 29 10:50:25 2008 +0000
14.2 +++ b/src/gui.h Thu May 29 11:00:26 2008 +0000
14.3 @@ -21,6 +21,9 @@
14.4
14.5 #include <glib/gtypes.h>
14.6
14.7 +/* Base GUI clock is 10ms */
14.8 +#define GUI_TICK_PERIOD 10000000
14.9 +
14.10 /**
14.11 * GUI-provided method to scan the command line for standard arguments,
14.12 * invoked prior to regular command line processing. The command line
14.13 @@ -60,9 +63,4 @@
14.14 */
14.15 void gui_update_io_activity( io_activity_type activity, gboolean active );
14.16
14.17 -/**
14.18 - * Open a gdrom filename via the menu. FIXME: Should be generic
14.19 - */
14.20 -gboolean gdrom_menu_open_file( const char *filename );
14.21 -
14.22 #endif /* __lxdream_gui_H */
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/src/hook.h Thu May 29 11:00:26 2008 +0000
15.3 @@ -0,0 +1,82 @@
15.4 +/**
15.5 + * $Id: hook.h 662 2008-03-02 11:38:08Z nkeynes $
15.6 + *
15.7 + * This file defines some useful generic macros for hooks
15.8 + *
15.9 + * Copyright (c) 2008 Nathan Keynes.
15.10 + *
15.11 + * This program is free software; you can redistribute it and/or modify
15.12 + * it under the terms of the GNU General Public License as published by
15.13 + * the Free Software Foundation; either version 2 of the License, or
15.14 + * (at your option) any later version.
15.15 + *
15.16 + * This program is distributed in the hope that it will be useful,
15.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15.19 + * GNU General Public License for more details.
15.20 + */
15.21 +
15.22 +#ifndef lxdream_hook_H
15.23 +#define lxdream_hook_H 1
15.24 +
15.25 +#include <assert.h>
15.26 +
15.27 +/**
15.28 + * Hook functions are generally useful, so we'd let to limit the overhead (and
15.29 + * opportunity for stupid bugs) by minimizing the amount of code involved. Glib
15.30 + * has GHook (and of course signals), but they don't actually simplify anything
15.31 + * at this level.
15.32 + *
15.33 + * Hence, the gratuitous macro abuse here.
15.34 + *
15.35 + * Usage:
15.36 + *
15.37 + * In header file:
15.38 + *
15.39 + * DECLARE_HOOK( hook_name, hook_fn_type );
15.40 + *
15.41 + * In implementation file:
15.42 + *
15.43 + * DEFINE_HOOK( hook_name, hook_fn_type );
15.44 + *
15.45 + */
15.46 +#define DECLARE_HOOK( name, fn_type ) \
15.47 + void register_##name( fn_type fn, void *user_data ); \
15.48 + void unregister_##name( fn_type fn, void *user_data );
15.49 +
15.50 +#define FOREACH_HOOK( h, name ) struct name##_hook_struct *h; for( h = name##_hook_list; h != NULL; h = h->next )
15.51 +
15.52 +#define CALL_HOOKS( name, args... ) FOREACH_HOOK(h, name) { h->fn(args, h->user_data); }
15.53 +
15.54 +#define DEFINE_HOOK( name, fn_type ) \
15.55 + struct name##_hook_struct { \
15.56 + fn_type fn; \
15.57 + void *user_data; \
15.58 + struct name##_hook_struct *next; \
15.59 + } *name##_hook_list = NULL; \
15.60 + void register_##name( fn_type fn, void *user_data ) { \
15.61 + struct name##_hook_struct *h = malloc(sizeof(struct name##_hook_struct)); \
15.62 + assert(h != NULL); \
15.63 + h->fn = fn; \
15.64 + h->user_data = user_data; \
15.65 + h->next = name##_hook_list; \
15.66 + name##_hook_list = h; \
15.67 + } \
15.68 + void unregister_##name( fn_type fn, void *user_data ) { \
15.69 + struct name##_hook_struct *last = NULL, *h = name##_hook_list; \
15.70 + while( h != NULL ) { \
15.71 + if( h->fn == fn && h->user_data == user_data ) { \
15.72 + if( last == NULL ) { \
15.73 + name##_hook_list = h->next; \
15.74 + } else { \
15.75 + last->next = h->next; \
15.76 + } \
15.77 + free( h ); \
15.78 + } \
15.79 + last = h; \
15.80 + h = h->next; \
15.81 + }\
15.82 + }
15.83 +
15.84 +
15.85 +#endif /* !lxdream_hook_H */
15.86 \ No newline at end of file
16.1 --- a/src/main.c Thu May 29 10:50:25 2008 +0000
16.2 +++ b/src/main.c Thu May 29 11:00:26 2008 +0000
16.3 @@ -17,6 +17,7 @@
16.4 * GNU General Public License for more details.
16.5 */
16.6
16.7 +#include <stdlib.h>
16.8 #include <unistd.h>
16.9 #include <getopt.h>
16.10 #include <glib/gi18n.h>
16.11 @@ -178,7 +179,7 @@
16.12 INFO( "%s! ready...", APP_NAME );
16.13
16.14 for( ; optind < argc; optind++ ) {
16.15 - gboolean ok = gdrom_menu_open_file(argv[optind]);
16.16 + gboolean ok = gdrom_mount_image(argv[optind]);
16.17 if( !ok ) {
16.18 ok = file_load_magic( argv[optind] );
16.19 }
16.20 @@ -191,14 +192,14 @@
16.21 }
16.22
16.23 if( disc_file != NULL ) {
16.24 - gdrom_menu_open_file( disc_file );
16.25 + gdrom_mount_image( disc_file );
16.26 }
16.27
16.28 if( gdrom_get_current_disc() == NULL ) {
16.29 - disc_file = lxdream_get_config_value( CONFIG_GDROM );
16.30 - if( disc_file != NULL ) {
16.31 - gdrom_menu_open_file( disc_file );
16.32 - }
16.33 + disc_file = lxdream_get_config_value( CONFIG_GDROM );
16.34 + if( disc_file != NULL ) {
16.35 + gdrom_mount_image( disc_file );
16.36 + }
16.37 }
16.38
16.39 sh4_set_use_xlat( use_xlat );
.