Search
lxdream.org :: lxdream :: r245:a1d0655a88d3
lxdream 0.9.1
released Jun 29
Download Now
changeset245:a1d0655a88d3
parent244:4c2b7291d3b0
child246:98054d036a24
authornkeynes
dateTue Dec 19 09:52:56 2006 +0000 (13 years ago)
Work in progress: 0x40,1 (read status)
src/gdrom/gdrom.c
src/gdrom/gdrom.h
src/gdrom/ide.c
src/gdrom/ide.h
src/gdrom/packet.h
1.1 --- a/src/gdrom/gdrom.c Tue Dec 19 09:51:35 2006 +0000
1.2 +++ b/src/gdrom/gdrom.c Tue Dec 19 09:52:56 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gdrom.c,v 1.10 2006-12-14 12:31:38 nkeynes Exp $
1.6 + * $Id: gdrom.c,v 1.11 2006-12-19 09:52:56 nkeynes Exp $
1.7 *
1.8 * GD-Rom access functions.
1.9 *
1.10 @@ -137,6 +137,7 @@
1.11 // return PKT_ERR_BADREADMODE;
1.12 // break;
1.13 case GDROM_MODE1:
1.14 + case GDROM_MODE2_XA1:
1.15 switch( track->mode ) {
1.16 case GDROM_MODE1:
1.17 case GDROM_MODE2_XA1:
1.18 @@ -258,6 +259,27 @@
1.19
1.20 }
1.21
1.22 +gdrom_track_t gdrom_get_track( int trackno ) {
1.23 + if( gdrom_disc == NULL || trackno < 1 || trackno > 99 ) {
1.24 + return NULL;
1.25 + } else {
1.26 + return &gdrom_disc->track[trackno-1];
1.27 + }
1.28 +}
1.29 +
1.30 +uint8_t gdrom_get_track_no_by_lba( uint32_t lba ) {
1.31 + int i;
1.32 + if( gdrom_disc != NULL ) {
1.33 + for( i=0; i<gdrom_disc->track_count; i++ ) {
1.34 + if( gdrom_disc->track[i].lba <= lba &&
1.35 + lba <= (gdrom_disc->track[i].lba + gdrom_disc->track[i].sector_count) ) {
1.36 + return i+1;
1.37 + }
1.38 + }
1.39 + }
1.40 + return -1;
1.41 +}
1.42 +
1.43 void gdrom_mount_disc( gdrom_disc_t disc )
1.44 {
1.45 gdrom_unmount_disc();
2.1 --- a/src/gdrom/gdrom.h Tue Dec 19 09:51:35 2006 +0000
2.2 +++ b/src/gdrom/gdrom.h Tue Dec 19 09:52:56 2006 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: gdrom.h,v 1.8 2006-12-14 12:31:38 nkeynes Exp $
2.6 + * $Id: gdrom.h,v 1.9 2006-12-19 09:52:56 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 @@ -59,7 +59,7 @@
2.11 #define TRACK_DATA 0x40
2.12 #define TRACK_FOUR_CHANNEL 0x80
2.13
2.14 -struct gdrom_track {
2.15 +typedef struct gdrom_track {
2.16 gdrom_track_mode_t mode;
2.17 uint8_t flags; /* Track flags */
2.18 int session; /* session # containing this track */
2.19 @@ -67,7 +67,7 @@
2.20 uint32_t sector_size; /* For convenience, determined by mode */
2.21 uint32_t sector_count;
2.22 uint32_t offset; /* File offset of start of track - image files only */
2.23 -};
2.24 +} *gdrom_track_t;
2.25
2.26
2.27 typedef struct gdrom_disc {
2.28 @@ -120,6 +120,10 @@
2.29 */
2.30 gdrom_error_t gdrom_get_info( char *buf, int session );
2.31
2.32 +gdrom_track_t gdrom_get_track( int track_no );
2.33 +
2.34 +uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
2.35 +
2.36 /**
2.37 * Shortcut to open and mount an image file
2.38 */
3.1 --- a/src/gdrom/ide.c Tue Dec 19 09:51:35 2006 +0000
3.2 +++ b/src/gdrom/ide.c Tue Dec 19 09:52:56 2006 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: ide.c,v 1.17 2006-12-15 10:18:39 nkeynes Exp $
3.6 + * $Id: ide.c,v 1.18 2006-12-19 09:52:56 nkeynes Exp $
3.7 *
3.8 * IDE interface implementation
3.9 *
3.10 @@ -134,6 +134,9 @@
3.11 memset( idereg.gdrom_sense, '\0', 10 );
3.12 idereg.data_offset = -1;
3.13 idereg.data_length = -1;
3.14 + idereg.last_read_track = 1;
3.15 + idereg.last_read_lba = 150;
3.16 + idereg.last_read_count = 0;
3.17 }
3.18
3.19 static void ide_save_state( FILE *f )
3.20 @@ -454,9 +457,9 @@
3.21 lba = cmd[2] << 16 | cmd[3] << 8 | cmd[4];
3.22 length = cmd[8] << 16 | cmd[9] << 8 | cmd[10]; /* blocks */
3.23 switch( cmd[1] ) {
3.24 - case 0x20: mode = GDROM_MODE1; break;
3.25 + case 0x20: mode = GDROM_MODE1; break; /* TODO - might be unchecked? */
3.26 case 0x24: mode = GDROM_GD; break;
3.27 - case 0x28: mode = GDROM_MODE1; break; /* ??? */
3.28 + case 0x28: mode = GDROM_MODE2_XA1; break; /* ??? */
3.29 case 0x30: mode = GDROM_RAW; break;
3.30 default:
3.31 ERROR( "Unrecognized read mode '%02X' in GD-Rom read request", cmd[1] );
3.32 @@ -479,6 +482,9 @@
3.33 idereg.gdrom_sense[6] = (lba >> 8) & 0xFF;
3.34 idereg.gdrom_sense[7] = lba & 0xFF;
3.35 } else {
3.36 + idereg.last_read_count += length;
3.37 + idereg.last_read_lba = lba + length;
3.38 + idereg.last_read_track = gdrom_get_track_no_by_lba( idereg.last_read_lba );
3.39 ide_start_packet_read( datalen, blocksize );
3.40 }
3.41 break;
3.42 @@ -487,6 +493,39 @@
3.43 ide_set_packet_result( PKT_ERR_OK );
3.44 ide_raise_interrupt();
3.45 break;
3.46 + case PKT_CMD_STATUS:
3.47 + length = cmd[4];
3.48 + if( !gdrom_is_mounted() ) {
3.49 + ide_set_packet_result( PKT_ERR_NODISC );
3.50 + } else {
3.51 + switch( cmd[1] ) {
3.52 + case 0:
3.53 + break;
3.54 + case 1:
3.55 + if( length > 16 ) {
3.56 + length = 16;
3.57 + }
3.58 + data_buffer[0] = 0x00;
3.59 + data_buffer[1] = 0x15; /* ??? */
3.60 + data_buffer[2] = 0x00;
3.61 + data_buffer[3] = 0x0E;
3.62 + data_buffer[4] = gdrom_get_track(idereg.last_read_track)->flags;
3.63 + data_buffer[5] = idereg.last_read_track;
3.64 + data_buffer[6] = 0x01; /* ?? */
3.65 + data_buffer[7] = (idereg.last_read_count >> 16) & 0xFF;
3.66 + data_buffer[8] = (idereg.last_read_count >> 8) & 0xFF;
3.67 + data_buffer[9] = idereg.last_read_count & 0xFF;
3.68 + data_buffer[10] = (idereg.last_read_lba >> 24) & 0xFF;
3.69 + data_buffer[11] = (idereg.last_read_lba >> 16) & 0xFF;
3.70 + data_buffer[12] = (idereg.last_read_lba >> 8) & 0xFF;
3.71 + data_buffer[13] = idereg.last_read_lba & 0xFF;
3.72 + data_buffer[14] = 0x00;
3.73 + data_buffer[15] = 0x00;
3.74 + ide_start_packet_read( length, blocksize );
3.75 + break;
3.76 + }
3.77 + }
3.78 + break;
3.79 case PKT_CMD_71:
3.80 /* This is a weird one. As far as I can tell it returns random garbage
3.81 * (and not even the same length each time, never mind the same data).
4.1 --- a/src/gdrom/ide.h Tue Dec 19 09:51:35 2006 +0000
4.2 +++ b/src/gdrom/ide.h Tue Dec 19 09:52:56 2006 +0000
4.3 @@ -1,5 +1,5 @@
4.4 /**
4.5 - * $Id: ide.h,v 1.9 2006-12-15 10:18:39 nkeynes Exp $
4.6 + * $Id: ide.h,v 1.10 2006-12-19 09:52:56 nkeynes Exp $
4.7 *
4.8 * This file defines the interface and structures of the dreamcast's IDE
4.9 * port. Note that the register definitions are in asic.h, as the registers
4.10 @@ -41,6 +41,7 @@
4.11
4.12 /* Internal IDE state */
4.13 uint8_t intrq_pending; /* Flag to indicate if the INTRQ line is active */
4.14 + gboolean interface_enabled;
4.15 int state;
4.16
4.17 /* Sense response for the last executed packet command */
4.18 @@ -55,6 +56,11 @@
4.19
4.20 int block_length; /* Used to determine the transfer unit size */
4.21 int block_left; /* Bytes remaining in the current block */
4.22 +
4.23 + /* Status reporting information */
4.24 + uint8_t last_read_track;
4.25 + uint32_t last_read_lba;
4.26 + uint32_t last_read_count;
4.27 };
4.28
4.29 #define IDE_STATE_IDLE 0
5.1 --- a/src/gdrom/packet.h Tue Dec 19 09:51:35 2006 +0000
5.2 +++ b/src/gdrom/packet.h Tue Dec 19 09:52:56 2006 +0000
5.3 @@ -1,5 +1,5 @@
5.4 /**
5.5 - * $Id: packet.h,v 1.4 2006-06-15 10:32:42 nkeynes Exp $
5.6 + * $Id: packet.h,v 1.5 2006-12-19 09:52:56 nkeynes Exp $
5.7 *
5.8 * This file defines the command codes and any other flags used by the
5.9 * GD-Rom ATAPI packet commands.
5.10 @@ -25,14 +25,14 @@
5.11 * 12
5.12 * 13 Request Sense
5.13 * 14 Read TOC
5.14 - * 15
5.15 + * 15 Read session info
5.16 * 16
5.17 * 20
5.18 * 21
5.19 * 22
5.20 * 30 Read CD
5.21 * 31
5.22 - * 40
5.23 + * 40 Read Status ?
5.24 * 50
5.25 * 51
5.26 * 52
5.27 @@ -52,6 +52,8 @@
5.28 #define PKT_CMD_READ_TOC 0x14
5.29 #define PKT_CMD_SESSION_INFO 0x15
5.30 #define PKT_CMD_READ_SECTOR 0x30
5.31 +#define PKT_CMD_PLAY_CD 0x20 /* ? */
5.32 +#define PKT_CMD_STATUS 0x40
5.33 #define PKT_CMD_SPIN_UP 0x70 /* ??? */
5.34 #define PKT_CMD_71 0x71 /* ??? seems to return garbage */
5.35
.