Search
lxdream.org :: lxdream/src/gdrom/ide.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/ide.c
changeset 2:42349f6ea216
next15:5194dd0fdb60
author nkeynes
date Sat Aug 21 06:15:49 2004 +0000 (15 years ago)
permissions -rw-r--r--
last change Commit changes into cvs
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gdrom/ide.c Sat Aug 21 06:15:49 2004 +0000
1.3 @@ -0,0 +1,127 @@
1.4 +/*
1.5 + * ide.c 31 Mar 2004 - IDE Interface implementation
1.6 + *
1.7 + * Copyright (c) 2004 Nathan Keynes. Distribution and modification permitted
1.8 + * under the terms of the GNU General Public License version 2 or later.
1.9 + */
1.10 +#include <stdlib.h>
1.11 +#include "ide.h"
1.12 +
1.13 +#define MAX_WRITE_BUF 4096;
1.14 +
1.15 +struct ide_registers idereg;
1.16 +
1.17 +static char command_buffer[12];
1.18 +
1.19 +/* "\0\0\0\0\xb4\x19\0\0\x08SE REV 6.42990316" */
1.20 +char gdrom_ident[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x19, 0x00,
1.21 + 0x00, 0x08, 0x53, 0x45, 0x20, 0x20, 0x20, 0x20,
1.22 + 0x20, 0x20, 0x52, 0x65, 0x76, 0x20, 0x36, 0x2e,
1.23 + 0x34, 0x32, 0x39, 0x39, 0x30, 0x33, 0x31, 0x36 };
1.24 +
1.25 +
1.26 +void set_write_buffer( char *buf, int len )
1.27 +{
1.28 + idereg.status |= IDE_ST_DATA;
1.29 + idereg.data = buf;
1.30 + idereg.datalen = len;
1.31 + idereg.writeptr = (uint16_t *)buf;
1.32 + idereg.readptr = NULL;
1.33 +}
1.34 +
1.35 +void set_read_buffer( char *buf, int len )
1.36 +{
1.37 + idereg.status |= IDE_ST_DATA;
1.38 + idereg.data = buf;
1.39 + idereg.datalen = len;
1.40 + idereg.readptr = (uint16_t *)buf;
1.41 + idereg.writeptr = NULL;
1.42 + idereg.lba1 = len&0xFF;
1.43 + idereg.lba2 = len>>8;
1.44 +}
1.45 +
1.46 +void ide_clear_interrupt( void )
1.47 +{
1.48 + /* TODO */
1.49 +}
1.50 +
1.51 +void ide_reset( void )
1.52 +{
1.53 + ide_clear_interrupt();
1.54 + idereg.error = 0x01;
1.55 + idereg.count = 0x01;
1.56 + idereg.lba0 = 0x21;
1.57 + idereg.lba1 = 0x14;
1.58 + idereg.lba2 = 0xeb;
1.59 + idereg.feature = 0; /* Indeterminate really */
1.60 + idereg.status = 0x00;
1.61 + idereg.device = 0x00;
1.62 + idereg.disc = IDE_DISC_GDROM | IDE_DISC_READY;
1.63 +}
1.64 +
1.65 +uint16_t ide_read_data_pio( void ) {
1.66 + if( idereg.readptr == NULL )
1.67 + return 0xFFFF;
1.68 + uint16_t rv = *idereg.readptr++;
1.69 + idereg.datalen-=2;
1.70 + if( idereg.datalen <=0 ) {
1.71 + idereg.readptr = NULL;
1.72 + idereg.status &= ~IDE_ST_DATA;
1.73 + }
1.74 + return rv;
1.75 +}
1.76 +
1.77 +void ide_write_data_pio( uint16_t val ) {
1.78 + if( idereg.writeptr == NULL )
1.79 + return;
1.80 + *idereg.writeptr++ = val;
1.81 + idereg.datalen-=2;
1.82 + if( idereg.datalen <= 0 ) {
1.83 + idereg.writeptr = NULL;
1.84 + idereg.status &= ~IDE_ST_DATA;
1.85 + ide_write_buffer( idereg.data );
1.86 + }
1.87 +}
1.88 +
1.89 +void ide_write_control( uint8_t val ) {
1.90 + /* TODO: In theory we can cause a soft-reset here, but the DC doesn't
1.91 + * appear to support it.
1.92 + */
1.93 +}
1.94 +
1.95 +void ide_write_command( uint8_t val ) {
1.96 + idereg.command = val;
1.97 + switch( val ) {
1.98 + case IDE_CMD_RESET_DEVICE:
1.99 + ide_reset();
1.100 + break;
1.101 + case IDE_CMD_PACKET:
1.102 + set_write_buffer(command_buffer,12);
1.103 + break;
1.104 + default:
1.105 + WARN( "IDE: Unimplemented command: %02X", val );
1.106 + }
1.107 + idereg.status |= IDE_ST_READY | IDE_ST_SERV;
1.108 +}
1.109 +
1.110 +void ide_write_buffer( char *data ) {
1.111 + uint16_t length;
1.112 + switch( idereg.command ) {
1.113 + case IDE_CMD_PACKET:
1.114 + /* Okay we have the packet in the command buffer */
1.115 + WARN( "ATAPI: Received Packet command: %02X", data[0] );
1.116 +
1.117 + switch( command_buffer[0] ) {
1.118 + case PKT_CMD_IDENTIFY:
1.119 + /* NB: Bios sets data[4] = 0x08, no idea what this is for;
1.120 + * different values here appear to have no effect.
1.121 + */
1.122 + length = *((uint16_t*)(data+2));
1.123 + if( length > sizeof(gdrom_ident) )
1.124 + length = sizeof(gdrom_ident);
1.125 + set_read_buffer(gdrom_ident, length);
1.126 + break;
1.127 + }
1.128 + break;
1.129 + }
1.130 +}
.