Search
lxdream.org :: lxdream/src/gdrom/gdrom.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.c
changeset 152:d42a4c5cc709
prev149:d88dd2e9a190
next154:d62f7b49934b
author nkeynes
date Tue May 23 13:11:45 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Clean up the buffer and i/o handling
Implement save/load state
file annotate diff log raw
1.1 --- a/src/gdrom/gdrom.c Sat May 20 06:24:49 2006 +0000
1.2 +++ b/src/gdrom/gdrom.c Tue May 23 13:11:45 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gdrom.c,v 1.4 2006-05-20 06:24:49 nkeynes Exp $
1.6 + * $Id: gdrom.c,v 1.5 2006-05-23 13:11:45 nkeynes Exp $
1.7 *
1.8 * GD-Rom access functions.
1.9 *
1.10 @@ -24,7 +24,7 @@
1.11 #include "dream.h"
1.12
1.13 static void gdrom_image_destroy( gdrom_disc_t );
1.14 -static uint32_t gdrom_image_read_sectors( gdrom_disc_t, uint32_t, uint32_t, int, char *, uint32_t * );
1.15 +static gdrom_error_t gdrom_image_read_sectors( gdrom_disc_t, uint32_t, uint32_t, int, char *, uint32_t * );
1.16
1.17
1.18 gdrom_disc_t gdrom_disc = NULL;
1.19 @@ -59,28 +59,56 @@
1.20 free( disc );
1.21 }
1.22
1.23 -static uint32_t gdrom_image_read_sectors( gdrom_disc_t disc, uint32_t sector,
1.24 - uint32_t sector_count, int mode, char *buf,
1.25 - uint32_t *length )
1.26 +static gdrom_error_t gdrom_image_read_sectors( gdrom_disc_t disc, uint32_t sector,
1.27 + uint32_t sector_count, int mode, char *buf,
1.28 + uint32_t *length )
1.29 {
1.30 - int i, track = -1, track_offset, read_len;
1.31 + int i, file_offset, read_len;
1.32 + struct gdrom_track *track = NULL;
1.33
1.34 for( i=0; i<disc->track_count; i++ ) {
1.35 if( disc->track[i].lba <= sector &&
1.36 (sector + sector_count) <= (disc->track[i].lba + disc->track[i].sector_count) ) {
1.37 - track = i;
1.38 + track = &disc->track[i];
1.39 break;
1.40 }
1.41 }
1.42 - if( track == -1 )
1.43 + if( track == NULL )
1.44 return PKT_ERR_BADREAD;
1.45 - if( mode == GDROM_GD && disc->track[i].mode != GDROM_GD )
1.46 +
1.47 + file_offset = track->offset + track->sector_size * (sector - track->lba);
1.48 + read_len = track->sector_size * sector_count;
1.49 + fseek( disc->file, file_offset, SEEK_SET );
1.50 +
1.51 + switch( mode ) {
1.52 + case GDROM_GD:
1.53 + if( track->mode != GDROM_GD )
1.54 + return PKT_ERR_BADREADMODE;
1.55 + break;
1.56 + case GDROM_MODE1:
1.57 + switch( track->mode ) {
1.58 + case GDROM_MODE1:
1.59 + case GDROM_MODE2_XA1:
1.60 + fread( buf, track->sector_size, sector_count, disc->file );
1.61 + break;
1.62 + case GDROM_MODE2:
1.63 + read_len = sector_count * 2048;
1.64 + while( sector_count > 0 ) {
1.65 + fread( buf, 2048, 1, disc->file );
1.66 + file_offset += track->sector_size;
1.67 + buf += 2048;
1.68 + fseek( disc->file, file_offset, SEEK_SET );
1.69 + sector_count--;
1.70 + }
1.71 + break;
1.72 + default:
1.73 + return PKT_ERR_BADREADMODE;
1.74 + }
1.75 + break;
1.76 + default:
1.77 return PKT_ERR_BADREADMODE;
1.78 -
1.79 - track_offset = disc->track[track].sector_size * (sector - disc->track[track].lba);
1.80 - read_len = disc->track[track].sector_size * sector_count;
1.81 - fseek( disc->file, disc->track[track].offset + track_offset, SEEK_SET );
1.82 - fread( buf, disc->track[track].sector_size, sector_count, disc->file );
1.83 + }
1.84 +
1.85 *length = read_len;
1.86 return PKT_ERR_OK;
1.87 }
1.88 @@ -125,20 +153,36 @@
1.89 return PKT_ERR_OK;
1.90 }
1.91
1.92 -gdrom_error_t gdrom_get_info( char *buf )
1.93 +gdrom_error_t gdrom_get_info( char *buf, int session )
1.94 {
1.95 if( gdrom_disc == NULL )
1.96 return PKT_ERR_NODISC;
1.97 struct gdrom_track *last_track = &gdrom_disc->track[gdrom_disc->track_count-1];
1.98 unsigned int end_of_disc = last_track->lba + last_track->sector_count;
1.99 -
1.100 - buf[0] = 0x01; /* Unknown. First session? */
1.101 + int i;
1.102 + buf[0] = 0x01; /* Disc status? */
1.103 buf[1] = 0;
1.104 - buf[2] = last_track->session+1; /* last session */
1.105 - buf[3] = (end_of_disc >> 16) & 0xFF;
1.106 - buf[4] = (end_of_disc >> 8) & 0xFF;
1.107 - buf[5] = end_of_disc & 0xFF;
1.108 - return PKT_ERR_OK;
1.109 +
1.110 + if( session == 0 ) {
1.111 + buf[2] = last_track->session+1; /* last session */
1.112 + buf[3] = (end_of_disc >> 16) & 0xFF;
1.113 + buf[4] = (end_of_disc >> 8) & 0xFF;
1.114 + buf[5] = end_of_disc & 0xFF;
1.115 + return PKT_ERR_OK;
1.116 + } else {
1.117 + session--;
1.118 + for( i=0; i<gdrom_disc->track_count; i++ ) {
1.119 + if( gdrom_disc->track[i].session == session ) {
1.120 + buf[2] = i+1; /* first track of session */
1.121 + buf[3] = (gdrom_disc->track[i].lba >> 16) & 0xFF;
1.122 + buf[4] = (gdrom_disc->track[i].lba >> 8) & 0xFF;
1.123 + buf[5] = gdrom_disc->track[i].lba & 0xFF;
1.124 + return PKT_ERR_OK;
1.125 + }
1.126 + }
1.127 + return PKT_ERR_BADFIELD; /* No such session */
1.128 + }
1.129 +
1.130 }
1.131
1.132 void gdrom_mount_disc( gdrom_disc_t disc )
.