Search
lxdream.org :: lxdream :: r143:9446fb6df0c5
lxdream 0.9.1
released Jun 29
Download Now
changeset143:9446fb6df0c5
parent142:2f631c3a3946
child144:7f0714e89aaa
authornkeynes
dateWed May 03 12:52:38 2006 +0000 (14 years ago)
Add (track) mode parameter to read sectors call
Fix missing interrupt on end-of-packet read.
src/gdrom/gdrom.c
src/gdrom/gdrom.h
src/gdrom/ide.c
src/gdrom/packet.h
1.1 --- a/src/gdrom/gdrom.c Tue May 02 14:09:11 2006 +0000
1.2 +++ b/src/gdrom/gdrom.c Wed May 03 12:52:38 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gdrom.c,v 1.2 2006-05-02 14:09:11 nkeynes Exp $
1.6 + * $Id: gdrom.c,v 1.3 2006-05-03 12:52:38 nkeynes Exp $
1.7 *
1.8 * GD-Rom access functions.
1.9 *
1.10 @@ -20,10 +20,11 @@
1.11
1.12 #include "gdrom/ide.h"
1.13 #include "gdrom/gdrom.h"
1.14 +#include "gdrom/packet.h"
1.15 #include "dream.h"
1.16
1.17 static void gdrom_image_destroy( gdrom_disc_t );
1.18 -static uint32_t gdrom_image_read_sectors( gdrom_disc_t, uint32_t, uint32_t, char * );
1.19 +static uint32_t gdrom_image_read_sectors( gdrom_disc_t, uint32_t, uint32_t, int, char *, uint32_t * );
1.20
1.21
1.22 gdrom_disc_t gdrom_disc = NULL;
1.23 @@ -59,7 +60,8 @@
1.24 }
1.25
1.26 static uint32_t gdrom_image_read_sectors( gdrom_disc_t disc, uint32_t sector,
1.27 - uint32_t sector_count, char *buf )
1.28 + uint32_t sector_count, int mode, char *buf,
1.29 + uint32_t *length )
1.30 {
1.31 int i, track = -1, track_offset, read_len;
1.32
1.33 @@ -71,21 +73,24 @@
1.34 }
1.35 }
1.36 if( track == -1 )
1.37 - return 0;
1.38 + return PKT_ERR_BADREAD;
1.39 + if( mode == GDROM_GD && disc->track[i].mode != GDROM_GD )
1.40 + return PKT_ERR_BADREADMODE;
1.41
1.42 track_offset = disc->track[track].sector_size * (sector - disc->track[track].lba);
1.43 read_len = disc->track[track].sector_size * sector_count;
1.44 fseek( disc->file, disc->track[track].offset + track_offset, SEEK_SET );
1.45 fread( buf, disc->track[track].sector_size, sector_count, disc->file );
1.46 - return read_len;
1.47 + *length = read_len;
1.48 + return PKT_ERR_OK;
1.49 }
1.50
1.51 uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
1.52 - char *buf )
1.53 + int mode, char *buf, uint32_t *length )
1.54 {
1.55 if( gdrom_disc == NULL )
1.56 - return 0; /* No media */
1.57 - return gdrom_disc->read_sectors( gdrom_disc, sector, sector_count, buf );
1.58 + return PKT_ERR_NODISC; /* No media */
1.59 + return gdrom_disc->read_sectors( gdrom_disc, sector, sector_count, mode, buf, length );
1.60 }
1.61
1.62
2.1 --- a/src/gdrom/gdrom.h Tue May 02 14:09:11 2006 +0000
2.2 +++ b/src/gdrom/gdrom.h Wed May 03 12:52:38 2006 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: gdrom.h,v 1.3 2006-05-02 14:09:11 nkeynes Exp $
2.6 + * $Id: gdrom.h,v 1.4 2006-05-03 12:52:38 nkeynes Exp $
2.7 *
2.8 * This file defines the structures and functions used by the GD-Rom
2.9 * disc driver. (ie, the modules that supply a CD image to be used by the
2.10 @@ -38,7 +38,8 @@
2.11 GDROM_MODE2_XA1,
2.12 GDROM_MODE2_XA2,
2.13 GDROM_CDDA,
2.14 - GDROM_GD
2.15 + GDROM_GD,
2.16 + GDROM_RAW
2.17 } gdrom_track_mode_t;
2.18
2.19 /* The disc register indicates the current contents of the drive. When open
2.20 @@ -76,7 +77,7 @@
2.21 FILE *file; /* Stream, for image files */
2.22 uint32_t (*read_sectors)( struct gdrom_disc *disc,
2.23 uint32_t lba, uint32_t sector_count,
2.24 - char *buf );
2.25 + int mode, char *buf, uint32_t *length );
2.26 void (*close)( struct gdrom_disc *disc );
2.27 } *gdrom_disc_t;
2.28
2.29 @@ -110,6 +111,6 @@
2.30 gboolean gdrom_is_mounted( void );
2.31
2.32 uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
2.33 - char *buf );
2.34 + int mode, char *buf, uint32_t *length );
2.35
2.36 #endif
3.1 --- a/src/gdrom/ide.c Tue May 02 14:09:11 2006 +0000
3.2 +++ b/src/gdrom/ide.c Wed May 03 12:52:38 2006 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: ide.c,v 1.11 2006-05-02 14:09:11 nkeynes Exp $
3.6 + * $Id: ide.c,v 1.12 2006-05-03 12:52:38 nkeynes Exp $
3.7 *
3.8 * IDE interface implementation
3.9 *
3.10 @@ -72,7 +72,7 @@
3.11 idereg.feature = 0; /* Indeterminate really */
3.12 idereg.status = 0x00;
3.13 idereg.device = 0x00;
3.14 - idereg.disc = gdrom_is_mounted() ? IDE_DISC_NONE : (IDE_DISC_CDROM|IDE_DISC_READY);
3.15 + idereg.disc = gdrom_is_mounted() ? (IDE_DISC_CDROM|IDE_DISC_READY) : IDE_DISC_NONE;
3.16 }
3.17
3.18 static void ide_save_state( FILE *f )
3.19 @@ -147,6 +147,7 @@
3.20 if( idereg.datalen <=0 ) {
3.21 idereg.readptr = NULL;
3.22 idereg.status &= ~IDE_ST_DATA;
3.23 + ide_raise_interrupt();
3.24 } else if( idereg.blockleft <= 0 ) {
3.25 ide_raise_interrupt();
3.26 idereg.blockleft = idereg.blocksize;
3.27 @@ -223,8 +224,8 @@
3.28 void ide_set_packet_error( uint16_t error )
3.29 {
3.30 idereg.gdrom_error = error;
3.31 + idereg.error = (error & 0x0F) << 4;
3.32 if( error != 0 ) {
3.33 - idereg.error = (error & 0x0F) << 4;
3.34 idereg.status = 0x51;
3.35 }
3.36 }
3.37 @@ -237,7 +238,8 @@
3.38 void ide_packet_command( unsigned char *cmd )
3.39 {
3.40 uint32_t length, datalen;
3.41 - uint32_t lba;
3.42 + uint32_t lba, status;
3.43 + int mode;
3.44 int blocksize = idereg.lba1 + (idereg.lba2<<8);
3.45
3.46 ide_raise_interrupt( );
3.47 @@ -295,14 +297,22 @@
3.48 data_buffer = realloc( data_buffer, data_buffer_len );
3.49 }
3.50
3.51 - if( !gdrom_is_mounted() ) {
3.52 - ide_set_packet_error( PKT_ERR_NODISC );
3.53 + switch( cmd[1] ) {
3.54 + case 0x20: mode = GDROM_MODE1; break;
3.55 + case 0x24: mode = GDROM_GD; break;
3.56 + case 0x28: mode = GDROM_MODE1; break; /* ??? */
3.57 + case 0x30: mode = GDROM_RAW; break;
3.58 + default:
3.59 + ERROR( "Unrecognized read mode '%02X' in GD-Rom read request", cmd[1] );
3.60 + ide_set_packet_error( PKT_ERR_BADFIELD );
3.61 return;
3.62 }
3.63
3.64 - datalen = gdrom_read_sectors( lba, length, data_buffer );
3.65 - if( datalen == 0 ) {
3.66 - ide_set_packet_error( 0x05 );
3.67 + status = gdrom_read_sectors( lba, length, mode, data_buffer, &data_buffer_len );
3.68 + if( status != 0 ) {
3.69 + ide_set_packet_error( status );
3.70 + data_buffer[6] = (lba >> 8) & 0xFF;
3.71 + data_buffer[7] = lba & 0xFF;
3.72 return;
3.73 }
3.74 ide_set_read_buffer( data_buffer, datalen, blocksize );
4.1 --- a/src/gdrom/packet.h Tue May 02 14:09:11 2006 +0000
4.2 +++ b/src/gdrom/packet.h Wed May 03 12:52:38 2006 +0000
4.3 @@ -1,5 +1,5 @@
4.4 /**
4.5 - * $Id: packet.h,v 1.1 2006-05-02 14:09:11 nkeynes Exp $
4.6 + * $Id: packet.h,v 1.2 2006-05-03 12:52:38 nkeynes Exp $
4.7 *
4.8 * This file defines the command codes and any other flags used by the
4.9 * GD-Rom ATAPI packet commands.
4.10 @@ -56,7 +56,8 @@
4.11 #define PKT_ERR_NODISC 0x3A02
4.12 #define PKT_ERR_BADCMD 0x2005
4.13 #define PKT_ERR_BADFIELD 0x2405
4.14 -
4.15 +#define PKT_ERR_BADREAD 0x0030
4.16 +#define PKT_ERR_BADREADMODE 0x6405 /* Illegal mode for this track */
4.17
4.18 #define IDE_READ_MODE1 0x20
4.19 #define IDE_READ_RAW 0x30
.