Search
lxdream.org :: lxdream :: r142:2f631c3a3946
lxdream 0.9.1
released Jun 29
Download Now
changeset142:2f631c3a3946
parent141:1f563629ab2a
child143:9446fb6df0c5
authornkeynes
dateTue May 02 14:09:11 2006 +0000 (14 years ago)
Add packet.h
Implement read toc, request sense, test ready commands.
Fix failure to clear error status on new command
src/gdrom/gdrom.c
src/gdrom/gdrom.h
src/gdrom/ide.c
src/gdrom/ide.h
src/gdrom/nrg.c
src/gdrom/packet.h
1.1 --- a/src/gdrom/gdrom.c Tue May 02 14:08:29 2006 +0000
1.2 +++ b/src/gdrom/gdrom.c Tue May 02 14:09:11 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gdrom.c,v 1.1 2006-04-30 01:51:08 nkeynes Exp $
1.6 + * $Id: gdrom.c,v 1.2 2006-05-02 14:09:11 nkeynes Exp $
1.7 *
1.8 * GD-Rom access functions.
1.9 *
1.10 @@ -65,7 +65,7 @@
1.11
1.12 for( i=0; i<disc->track_count; i++ ) {
1.13 if( disc->track[i].lba <= sector &&
1.14 - disc->track[i].lba + disc->track[i].sector_count <= sector + sector_count ) {
1.15 + (sector + sector_count) <= (disc->track[i].lba + disc->track[i].sector_count) ) {
1.16 track = i;
1.17 break;
1.18 }
1.19 @@ -102,8 +102,21 @@
1.20
1.21 gboolean gdrom_get_toc( char *buf )
1.22 {
1.23 + struct gdrom_toc *toc = (struct gdrom_toc *)buf;
1.24 + int i;
1.25 +
1.26 if( gdrom_disc == NULL )
1.27 return FALSE;
1.28 +
1.29 + for( i=0; i<gdrom_disc->track_count; i++ ) {
1.30 + toc->track[i] = htonl( gdrom_disc->track[i].lba ) | gdrom_disc->track[i].flags;
1.31 + }
1.32 + toc->first = 0x0100 | gdrom_disc->track[0].flags;
1.33 + toc->last = (gdrom_disc->track_count<<8) | gdrom_disc->track[i-1].flags;
1.34 + toc->leadout = htonl(gdrom_disc->track[i-1].lba + gdrom_disc->track[i-1].sector_count) |
1.35 + gdrom_disc->track[i-1].flags;
1.36 + for( ;i<99; i++ )
1.37 + toc->track[i] = 0xFFFFFFFF;
1.38 return TRUE;
1.39 }
1.40
2.1 --- a/src/gdrom/gdrom.h Tue May 02 14:08:29 2006 +0000
2.2 +++ b/src/gdrom/gdrom.h Tue May 02 14:09:11 2006 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: gdrom.h,v 1.2 2006-04-30 01:51:08 nkeynes Exp $
2.6 + * $Id: gdrom.h,v 1.3 2006-05-02 14:09:11 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 @@ -24,7 +24,7 @@
2.11 #include "dream.h"
2.12
2.13 struct gdrom_toc {
2.14 - uint32_t tracks[99];
2.15 + uint32_t track[99];
2.16 uint32_t first, last, leadout;
2.17 };
2.18
2.19 @@ -51,8 +51,14 @@
2.20 #define IDE_DISC_READY 0x01 /* ored with above */
2.21 #define IDE_DISC_IDLE 0x02 /* ie spun-down */
2.22
2.23 +#define TRACK_PRE_EMPHASIS 0x10
2.24 +#define TRACK_COPY_PERMITTED 0x20
2.25 +#define TRACK_DATA 0x40
2.26 +#define TRACK_FOUR_CHANNEL 0x80
2.27 +
2.28 struct gdrom_track {
2.29 gdrom_track_mode_t mode;
2.30 + uint8_t flags; /* Track flags */
2.31 int session; /* session # containing this track */
2.32 uint32_t lba; /* start sector address */
2.33 uint32_t sector_size; /* For convenience, determined by mode */
3.1 --- a/src/gdrom/ide.c Tue May 02 14:08:29 2006 +0000
3.2 +++ b/src/gdrom/ide.c Tue May 02 14:09:11 2006 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: ide.c,v 1.10 2006-04-30 12:22:31 nkeynes Exp $
3.6 + * $Id: ide.c,v 1.11 2006-05-02 14:09:11 nkeynes Exp $
3.7 *
3.8 * IDE interface implementation
3.9 *
3.10 @@ -24,6 +24,7 @@
3.11 #include "asic.h"
3.12 #include "gdrom/ide.h"
3.13 #include "gdrom/gdrom.h"
3.14 +#include "gdrom/packet.h"
3.15
3.16 #define MAX_WRITE_BUF 4096
3.17 #define MAX_SECTOR_SIZE 2352 /* Audio sector */
3.18 @@ -216,9 +217,23 @@
3.19 default:
3.20 WARN( "IDE: Unimplemented command: %02X", val );
3.21 }
3.22 - idereg.status |= IDE_ST_READY | IDE_ST_SERV;
3.23 + idereg.status = (idereg.status | IDE_ST_READY | IDE_ST_SERV) & (~IDE_ST_ERROR);
3.24 }
3.25
3.26 +void ide_set_packet_error( uint16_t error )
3.27 +{
3.28 + idereg.gdrom_error = error;
3.29 + if( error != 0 ) {
3.30 + idereg.error = (error & 0x0F) << 4;
3.31 + idereg.status = 0x51;
3.32 + }
3.33 +}
3.34 +
3.35 +/**
3.36 + * Execute a packet command. This particular method is responsible for parsing
3.37 + * the command buffers (12 bytes), and generating the appropriate responses,
3.38 + * although the actual implementation is mostly delegated to gdrom.c
3.39 + */
3.40 void ide_packet_command( unsigned char *cmd )
3.41 {
3.42 uint32_t length, datalen;
3.43 @@ -230,13 +245,19 @@
3.44 WARN( "ATAPI: Received Packet command: %02X", cmd[0] );
3.45 fwrite_dump( (unsigned char *)cmd, 12, stderr );
3.46 switch( cmd[0] ) {
3.47 + case PKT_CMD_TEST_READY:
3.48 + if( !gdrom_is_mounted() ) {
3.49 + ide_set_packet_error( PKT_ERR_NODISC );
3.50 + return;
3.51 + }
3.52 + ide_set_packet_error( 0 );
3.53 + idereg.status = 0x50;
3.54 + return;
3.55 + break;
3.56 case PKT_CMD_IDENTIFY:
3.57 - /* NB: Bios sets cmd[4] = 0x08, no idea what this is for;
3.58 - * different values here appear to have no effect.
3.59 - */
3.60 lba = cmd[2];
3.61 if( lba >= sizeof(gdrom_ident) ) {
3.62 - ide_set_error(0x50);
3.63 + ide_set_error(PKT_ERR_BADFIELD);
3.64 return;
3.65 }
3.66 length = cmd[4];
3.67 @@ -244,12 +265,25 @@
3.68 length = sizeof(gdrom_ident) - lba;
3.69 ide_set_read_buffer(gdrom_ident + lba, length, blocksize);
3.70 break;
3.71 + case PKT_CMD_SENSE:
3.72 + memset( data_buffer, 0, 10 );
3.73 + length = cmd[4];
3.74 + if( length > 10 )
3.75 + length = 10;
3.76 + data_buffer[0] = 0xf0;
3.77 + data_buffer[2] = idereg.gdrom_error & 0xFF;
3.78 + data_buffer[8] = (idereg.gdrom_error >> 8) & 0xFF;
3.79 + ide_set_read_buffer( data_buffer, length , blocksize );
3.80 + break;
3.81 case PKT_CMD_READ_TOC:
3.82 if( !gdrom_get_toc( data_buffer ) ) {
3.83 - ide_set_error( 0x50 );
3.84 + ide_set_packet_error( PKT_ERR_NODISC ); /* No disc in drive */
3.85 return;
3.86 }
3.87 - ide_set_read_buffer( data_buffer, sizeof( struct gdrom_toc ), blocksize );
3.88 + length = (cmd[3]<<8) | cmd[4];
3.89 + if( length > sizeof(struct gdrom_toc) )
3.90 + length = sizeof(struct gdrom_toc);
3.91 + ide_set_read_buffer( data_buffer, length, blocksize );
3.92 break;
3.93 case PKT_CMD_READ_SECTOR:
3.94 lba = cmd[2] << 16 | cmd[3] << 8 | cmd[4];
3.95 @@ -260,15 +294,24 @@
3.96 } while( data_buffer_len < length );
3.97 data_buffer = realloc( data_buffer, data_buffer_len );
3.98 }
3.99 -
3.100 +
3.101 + if( !gdrom_is_mounted() ) {
3.102 + ide_set_packet_error( PKT_ERR_NODISC );
3.103 + return;
3.104 + }
3.105 +
3.106 datalen = gdrom_read_sectors( lba, length, data_buffer );
3.107 if( datalen == 0 ) {
3.108 - ide_set_error( 0x50 );
3.109 + ide_set_packet_error( 0x05 );
3.110 return;
3.111 }
3.112 ide_set_read_buffer( data_buffer, datalen, blocksize );
3.113 break;
3.114 + default:
3.115 + ide_set_packet_error( PKT_ERR_BADCMD ); /* Invalid command */
3.116 + return;
3.117 }
3.118 + ide_set_packet_error( PKT_ERR_OK );
3.119 }
3.120
3.121 void ide_write_buffer( unsigned char *data, int datalen ) {
4.1 --- a/src/gdrom/ide.h Tue May 02 14:08:29 2006 +0000
4.2 +++ b/src/gdrom/ide.h Tue May 02 14:09:11 2006 +0000
4.3 @@ -1,5 +1,5 @@
4.4 /**
4.5 - * $Id: ide.h,v 1.5 2006-04-30 01:51:08 nkeynes Exp $
4.6 + * $Id: ide.h,v 1.6 2006-05-02 14:09:11 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 @@ -46,6 +46,7 @@
4.11 */
4.12 unsigned char *data;
4.13 uint16_t *readptr, *writeptr;
4.14 + uint16_t gdrom_error; /* Lo-byte = error code, Hi-byte = subcode */
4.15 int datalen;
4.16 int blocksize; /* Used to determine the transfer unit size */
4.17 int blockleft; /* Bytes remaining in the current block */
4.18 @@ -72,14 +73,6 @@
4.19 #define IDE_XFER_MULTI_DMA 0x20
4.20 #define IDE_XFER_ULTRA_DMA 0x40
4.21
4.22 -
4.23 -
4.24 -#define PKT_CMD_RESET 0x00 /* Wild-ass guess */
4.25 -#define PKT_CMD_IDENTIFY 0x11
4.26 -#define PKT_CMD_SENSE 0x13
4.27 -#define PKT_CMD_READ_TOC 0x14
4.28 -#define PKT_CMD_READ_SECTOR 0x30
4.29 -
4.30 extern struct ide_registers idereg;
4.31
4.32 /* Note: control can be written at any time - all other registers are writable
5.1 --- a/src/gdrom/nrg.c Tue May 02 14:08:29 2006 +0000
5.2 +++ b/src/gdrom/nrg.c Tue May 02 14:09:11 2006 +0000
5.3 @@ -1,5 +1,5 @@
5.4 /**
5.5 - * $Id: nrg.c,v 1.1 2006-04-30 01:51:08 nkeynes Exp $
5.6 + * $Id: nrg.c,v 1.2 2006-05-02 14:09:11 nkeynes Exp $
5.7 *
5.8 * Nero (NRG) CD file format. File information stolen shamelessly from
5.9 * libcdio.
5.10 @@ -198,7 +198,7 @@
5.11 }
5.12 } else { /* Track-start address */
5.13 disc->track[track].lba = msf_to_lba( cue->addr );
5.14 -
5.15 + disc->track[track].flags = cue->type;
5.16 }
5.17 }
5.18 }
5.19 @@ -236,6 +236,10 @@
5.20 disc->close(disc);
5.21 return NULL;
5.22 }
5.23 + if( disc->track[track_id].mode == GDROM_CDDA )
5.24 + disc->track[track_id].flags = 0x01;
5.25 + else
5.26 + disc->track[track_id].flags = 0x01 | TRACK_DATA;
5.27 disc->track[track_id].sector_size = GDROM_SECTOR_SIZE(disc->track[track_id].mode);
5.28 disc->track[track_id].sector_count = ntohl(etnf->length) /
5.29 disc->track[track_id].sector_size;
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/src/gdrom/packet.h Tue May 02 14:09:11 2006 +0000
6.3 @@ -0,0 +1,62 @@
6.4 +/**
6.5 + * $Id: packet.h,v 1.1 2006-05-02 14:09:11 nkeynes Exp $
6.6 + *
6.7 + * This file defines the command codes and any other flags used by the
6.8 + * GD-Rom ATAPI packet commands.
6.9 + *
6.10 + * Copyright (c) 2005 Nathan Keynes.
6.11 + *
6.12 + * This program is free software; you can redistribute it and/or modify
6.13 + * it under the terms of the GNU General Public License as published by
6.14 + * the Free Software Foundation; either version 2 of the License, or
6.15 + * (at your option) any later version.
6.16 + *
6.17 + * This program is distributed in the hope that it will be useful,
6.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.20 + * GNU General Public License for more details.
6.21 + */
6.22 +
6.23 +/**
6.24 + * Valid command codes (hex):
6.25 + * 00 Test
6.26 + * 10
6.27 + * 11 Inquiry
6.28 + * 12
6.29 + * 13 Request Sense
6.30 + * 14 Read TOC
6.31 + * 15
6.32 + * 16
6.33 + * 20
6.34 + * 21
6.35 + * 22
6.36 + * 30 Read CD
6.37 + * 31
6.38 + * 40
6.39 + * 50
6.40 + * 51
6.41 + * 52
6.42 + * 53
6.43 + * 54
6.44 + * 55
6.45 + * 70
6.46 + * 71
6.47 + * 72
6.48 + * 73
6.49 + * FE
6.50 + */
6.51 +
6.52 +#define PKT_CMD_TEST_READY 0x00
6.53 +#define PKT_CMD_IDENTIFY 0x11
6.54 +#define PKT_CMD_SENSE 0x13
6.55 +#define PKT_CMD_READ_TOC 0x14
6.56 +#define PKT_CMD_READ_SECTOR 0x30
6.57 +
6.58 +#define PKT_ERR_OK 0x0000
6.59 +#define PKT_ERR_NODISC 0x3A02
6.60 +#define PKT_ERR_BADCMD 0x2005
6.61 +#define PKT_ERR_BADFIELD 0x2405
6.62 +
6.63 +
6.64 +#define IDE_READ_MODE1 0x20
6.65 +#define IDE_READ_RAW 0x30
.