Search
lxdream.org :: lxdream/src/gdrom/ide.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/ide.c
changeset 138:afabd7e6d26d
prev125:49bf45f8210a
next140:d26f4899898d
author nkeynes
date Sun Apr 30 01:51:08 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Add Nero file format handler and general gdrom disc hooks
file annotate diff log raw
1.1 --- a/src/gdrom/ide.c Wed Mar 22 14:29:02 2006 +0000
1.2 +++ b/src/gdrom/ide.c Sun Apr 30 01:51:08 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: ide.c,v 1.8 2006-03-22 14:29:02 nkeynes Exp $
1.6 + * $Id: ide.c,v 1.9 2006-04-30 01:51:08 nkeynes Exp $
1.7 *
1.8 * IDE interface implementation
1.9 *
1.10 @@ -18,23 +18,32 @@
1.11
1.12 #define MODULE ide_module
1.13
1.14 +#include <assert.h>
1.15 #include <stdlib.h>
1.16 #include "dream.h"
1.17 #include "asic.h"
1.18 #include "gdrom/ide.h"
1.19 #include "gdrom/gdrom.h"
1.20
1.21 -#define MAX_WRITE_BUF 4096;
1.22 +#define MAX_WRITE_BUF 4096
1.23 +#define MAX_SECTOR_SIZE 2352 /* Audio sector */
1.24 +#define DEFAULT_DATA_SECTORS 8
1.25
1.26 -void ide_init( void );
1.27 -void ide_init( void );
1.28 +static void ide_init( void );
1.29 +static void ide_reset( void );
1.30 +static void ide_save_state( FILE *f );
1.31 +static int ide_load_state( FILE *f );
1.32 +static void ide_raise_interrupt( void );
1.33 +static void ide_clear_interrupt( void );
1.34
1.35 struct dreamcast_module ide_module = { "IDE", ide_init, ide_reset, NULL, NULL,
1.36 - NULL, NULL, NULL };
1.37 + NULL, ide_save_state, ide_load_state };
1.38
1.39 struct ide_registers idereg;
1.40
1.41 static unsigned char command_buffer[12];
1.42 +unsigned char *data_buffer = NULL;
1.43 +uint32_t data_buffer_len = 0;
1.44
1.45 /* "\0\0\0\0\xb4\x19\0\0\x08SE REV 6.42990316" */
1.46 unsigned char gdrom_ident[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x19, 0x00,
1.47 @@ -43,7 +52,38 @@
1.48 0x34, 0x32, 0x39, 0x39, 0x30, 0x33, 0x31, 0x36 };
1.49
1.50
1.51 -gdrom_disc_t gdrom_disc = NULL;
1.52 +static void ide_init( void )
1.53 +{
1.54 + ide_reset();
1.55 + data_buffer_len = DEFAULT_DATA_SECTORS;
1.56 + data_buffer = malloc( MAX_SECTOR_SIZE * data_buffer_len );
1.57 + assert( data_buffer != NULL );
1.58 +}
1.59 +
1.60 +static void ide_reset( void )
1.61 +{
1.62 + ide_clear_interrupt();
1.63 + idereg.error = 0x01;
1.64 + idereg.count = 0x01;
1.65 + idereg.lba0 = /* 0x21; */ 0x81;
1.66 + idereg.lba1 = 0x14;
1.67 + idereg.lba2 = 0xeb;
1.68 + idereg.feature = 0; /* Indeterminate really */
1.69 + idereg.status = 0x00;
1.70 + idereg.device = 0x00;
1.71 + idereg.disc = gdrom_is_mounted() ? IDE_DISC_NONE : (IDE_DISC_CDROM|IDE_DISC_READY);
1.72 +}
1.73 +
1.74 +static void ide_save_state( FILE *f )
1.75 +{
1.76 +
1.77 +
1.78 +}
1.79 +
1.80 +static int ide_load_state( FILE *f )
1.81 +{
1.82 + return 0;
1.83 +}
1.84
1.85 static void ide_set_write_buffer( unsigned char *buf, int len )
1.86 {
1.87 @@ -90,25 +130,6 @@
1.88 idereg.error = error_code;
1.89 }
1.90
1.91 -void ide_init( void )
1.92 -{
1.93 -
1.94 -}
1.95 -
1.96 -void ide_reset( void )
1.97 -{
1.98 - ide_clear_interrupt();
1.99 - idereg.error = 0x01;
1.100 - idereg.count = 0x01;
1.101 - idereg.lba0 = /* 0x21; */ 0x81;
1.102 - idereg.lba1 = 0x14;
1.103 - idereg.lba2 = 0xeb;
1.104 - idereg.feature = 0; /* Indeterminate really */
1.105 - idereg.status = 0x00;
1.106 - idereg.device = 0x00;
1.107 - idereg.disc = (gdrom_disc == NULL ? IDE_DISC_NONE : (IDE_DISC_CDROM|IDE_DISC_READY));
1.108 -}
1.109 -
1.110 uint8_t ide_read_status( void )
1.111 {
1.112 if( (idereg.status & IDE_ST_BUSY) == 0 )
1.113 @@ -200,7 +221,7 @@
1.114
1.115 void ide_packet_command( unsigned char *cmd )
1.116 {
1.117 - uint32_t length;
1.118 + uint32_t length, datalen;
1.119 uint32_t lba;
1.120 int blocksize = idereg.lba1 + (idereg.lba2<<8);
1.121
1.122 @@ -219,22 +240,28 @@
1.123 ide_set_read_buffer(gdrom_ident, length, blocksize);
1.124 break;
1.125 case PKT_CMD_READ_TOC:
1.126 -
1.127 + if( !gdrom_get_toc( data_buffer ) ) {
1.128 + ide_set_error( 0x50 );
1.129 + return;
1.130 + }
1.131 + ide_set_read_buffer( data_buffer, sizeof( struct gdrom_toc ), blocksize );
1.132 break;
1.133 case PKT_CMD_READ_SECTOR:
1.134 lba = cmd[2] << 16 | cmd[3] << 8 | cmd[4];
1.135 length = cmd[8] << 16 | cmd[9] << 8 | cmd[10]; /* blocks */
1.136 - if( gdrom_disc == NULL ) {
1.137 + if( length > data_buffer_len ) {
1.138 + do {
1.139 + data_buffer_len = data_buffer_len << 1;
1.140 + } while( data_buffer_len < length );
1.141 + data_buffer = realloc( data_buffer, data_buffer_len );
1.142 + }
1.143 +
1.144 + datalen = gdrom_read_sectors( lba, length, data_buffer );
1.145 + if( datalen == 0 ) {
1.146 ide_set_error( 0x50 );
1.147 return;
1.148 }
1.149 - /*
1.150 - if( gdrom_disc->read_data_sectors( lba, length ) == FALSE ) {
1.151 - ide_set_error( 0x50 );
1.152 - return;
1.153 - }
1.154 -
1.155 - */
1.156 + ide_set_read_buffer( data_buffer, datalen, blocksize );
1.157 break;
1.158 }
1.159 }
.