Search
lxdream.org :: lxdream/src/gdrom/ide.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/ide.c
changeset 254:7c9e34c37670
prev250:84e056e12a19
next256:8bac2f96ca1b
author nkeynes
date Thu Dec 21 10:15:54 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Fix 0x40,0x01 in accordance with test results
Add reset flag to fail first packet command (also as per tests)
file annotate diff log raw
1.1 --- a/src/gdrom/ide.c Tue Dec 19 11:58:12 2006 +0000
1.2 +++ b/src/gdrom/ide.c Thu Dec 21 10:15:54 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: ide.c,v 1.19 2006-12-19 11:58:12 nkeynes Exp $
1.6 + * $Id: ide.c,v 1.20 2006-12-21 10:15:54 nkeynes Exp $
1.7 *
1.8 * IDE interface implementation
1.9 *
1.10 @@ -143,7 +143,7 @@
1.11 idereg.lba1 = 0x14;
1.12 idereg.lba2 = 0xeb;
1.13 idereg.feature = 0; /* Indeterminate really */
1.14 - idereg.status = 0x50;
1.15 + idereg.status = 0x00;
1.16 idereg.device = 0x00;
1.17 idereg.disc = gdrom_is_mounted() ? (IDE_DISC_CDROM|IDE_DISC_READY) : IDE_DISC_NONE;
1.18 idereg.state = IDE_STATE_IDLE;
1.19 @@ -152,7 +152,7 @@
1.20 idereg.data_length = -1;
1.21 idereg.last_read_track = 1;
1.22 idereg.last_read_lba = 150;
1.23 - idereg.last_read_count = 0;
1.24 + idereg.was_reset = TRUE;
1.25 }
1.26
1.27 static void ide_save_state( FILE *f )
1.28 @@ -186,6 +186,7 @@
1.29 idereg.gdrom_sense[2] = result & 0xFF;
1.30 idereg.gdrom_sense[8] = (result >> 8) & 0xFF;
1.31 idereg.error = (result & 0x0F) << 4;
1.32 + idereg.count = 3;
1.33 if( result != 0 ) {
1.34 idereg.status = 0x51;
1.35 ide_raise_interrupt();
1.36 @@ -200,7 +201,7 @@
1.37 static void ide_start_command_packet_write( )
1.38 {
1.39 idereg.state = IDE_STATE_CMD_WRITE;
1.40 - idereg.status = IDE_STATUS_DRDY | IDE_STATUS_DRQ;
1.41 + idereg.status = 0x58;
1.42 idereg.error = idereg.feature & 0x03; /* Copy values of OVL/DMA */
1.43 idereg.count = IDE_COUNT_CD;
1.44 idereg.data_offset = 0;
1.45 @@ -221,7 +222,7 @@
1.46 idereg.status = 0xD0;
1.47 } else {
1.48 idereg.state = IDE_STATE_PIO_READ;
1.49 - idereg.status = IDE_STATUS_DRDY | IDE_STATUS_DRQ;
1.50 + idereg.status = 0x58;
1.51 idereg.lba1 = length & 0xFF;
1.52 idereg.lba2 = (length >> 8) & 0xFF;
1.53 // idereg.lba1 = blocksize & 0xFF;
1.54 @@ -278,6 +279,7 @@
1.55 idereg.state = IDE_STATE_IDLE;
1.56 idereg.status &= ~IDE_STATUS_DRQ;
1.57 idereg.data_offset = -1;
1.58 + idereg.count = 3; /* complete */
1.59 ide_raise_interrupt();
1.60 } else if( idereg.block_left <= 0 ) {
1.61 idereg.block_left = idereg.block_length;
1.62 @@ -312,6 +314,7 @@
1.63 idereg.data_offset = -1;
1.64 idereg.state = IDE_STATE_IDLE;
1.65 idereg.status = 0x50;
1.66 + idereg.count = 0x03;
1.67 ide_raise_interrupt();
1.68 asic_event( EVENT_IDE_DMA );
1.69 }
1.70 @@ -393,12 +396,14 @@
1.71 default:
1.72 WARN( "IDE: unimplemented feature: %02X", idereg.feature );
1.73 }
1.74 - ide_raise_interrupt( );
1.75 + idereg.status = 0x50;
1.76 + idereg.error = 0x00;
1.77 + idereg.lba1 = 0x00;
1.78 + idereg.lba2 = 0x00;
1.79 break;
1.80 default:
1.81 WARN( "IDE: Unimplemented command: %02X", val );
1.82 }
1.83 - idereg.status = (idereg.status | IDE_STATUS_DRDY | IDE_STATUS_SERV) & (~IDE_STATUS_CHK);
1.84 }
1.85
1.86 /**
1.87 @@ -417,6 +422,13 @@
1.88 INFO( "ATAPI packet: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
1.89 cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7],
1.90 cmd[8], cmd[9], cmd[10], cmd[11] );
1.91 +
1.92 + if( cmd[0] != PKT_CMD_SENSE && idereg.was_reset ) {
1.93 + ide_set_packet_result( PKT_ERR_RESET );
1.94 + idereg.was_reset = FALSE;
1.95 + return;
1.96 + }
1.97 +
1.98 switch( cmd[0] ) {
1.99 case PKT_CMD_TEST_READY:
1.100 if( !gdrom_is_mounted() ) {
1.101 @@ -503,7 +515,6 @@
1.102 idereg.gdrom_sense[6] = (lba >> 8) & 0xFF;
1.103 idereg.gdrom_sense[7] = lba & 0xFF;
1.104 } else {
1.105 - idereg.last_read_count += length;
1.106 idereg.last_read_lba = lba + length;
1.107 idereg.last_read_track = gdrom_get_track_no_by_lba( idereg.last_read_lba );
1.108 ide_start_packet_read( datalen, blocksize );
1.109 @@ -528,25 +539,25 @@
1.110 ide_start_packet_read( length, blocksize );
1.111 break;
1.112 case 1:
1.113 - if( length > 16 ) {
1.114 - length = 16;
1.115 + if( length > 14 ) {
1.116 + length = 14;
1.117 }
1.118 + gdrom_track_t track = gdrom_get_track(idereg.last_read_track);
1.119 + int offset = idereg.last_read_lba - track->lba;
1.120 data_buffer[0] = 0x00;
1.121 data_buffer[1] = 0x15; /* ??? */
1.122 data_buffer[2] = 0x00;
1.123 data_buffer[3] = 0x0E;
1.124 - data_buffer[4] = gdrom_get_track(idereg.last_read_track)->flags;
1.125 + data_buffer[4] = track->flags;
1.126 data_buffer[5] = idereg.last_read_track;
1.127 data_buffer[6] = 0x01; /* ?? */
1.128 - data_buffer[7] = (idereg.last_read_count >> 16) & 0xFF;
1.129 - data_buffer[8] = (idereg.last_read_count >> 8) & 0xFF;
1.130 - data_buffer[9] = idereg.last_read_count & 0xFF;
1.131 + data_buffer[7] = (offset >> 16) & 0xFF;
1.132 + data_buffer[8] = (offset >> 8) & 0xFF;
1.133 + data_buffer[9] = offset & 0xFF;
1.134 data_buffer[10] = (idereg.last_read_lba >> 24) & 0xFF;
1.135 data_buffer[11] = (idereg.last_read_lba >> 16) & 0xFF;
1.136 data_buffer[12] = (idereg.last_read_lba >> 8) & 0xFF;
1.137 data_buffer[13] = idereg.last_read_lba & 0xFF;
1.138 - data_buffer[14] = 0x00;
1.139 - data_buffer[15] = 0x00;
1.140 ide_start_packet_read( length, blocksize );
1.141 break;
1.142 }
.