2 * ide.c 31 Mar 2004 - IDE Interface implementation
4 * Copyright (c) 2004 Nathan Keynes. Distribution and modification permitted
5 * under the terms of the GNU General Public License version 2 or later.
11 #define MAX_WRITE_BUF 4096;
13 void ide_init( void );
14 void ide_init( void );
16 struct dreamcast_module ide_module = { "IDE", ide_init, ide_reset, NULL, NULL,
19 struct ide_registers idereg;
21 static char command_buffer[12];
23 /* "\0\0\0\0\xb4\x19\0\0\x08SE REV 6.42990316" */
24 char gdrom_ident[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x19, 0x00,
25 0x00, 0x08, 0x53, 0x45, 0x20, 0x20, 0x20, 0x20,
26 0x20, 0x20, 0x52, 0x65, 0x76, 0x20, 0x36, 0x2e,
27 0x34, 0x32, 0x39, 0x39, 0x30, 0x33, 0x31, 0x36 };
30 void set_write_buffer( char *buf, int len )
32 idereg.status |= IDE_ST_DATA;
35 idereg.writeptr = (uint16_t *)buf;
36 idereg.readptr = NULL;
39 void set_read_buffer( char *buf, int len )
41 idereg.status |= IDE_ST_DATA;
44 idereg.readptr = (uint16_t *)buf;
45 idereg.writeptr = NULL;
46 idereg.lba1 = len&0xFF;
50 void ide_clear_interrupt( void )
60 void ide_reset( void )
62 ide_clear_interrupt();
68 idereg.feature = 0; /* Indeterminate really */
71 idereg.disc = IDE_DISC_GDROM | IDE_DISC_READY;
74 uint16_t ide_read_data_pio( void ) {
75 if( idereg.readptr == NULL )
77 uint16_t rv = *idereg.readptr++;
79 if( idereg.datalen <=0 ) {
80 idereg.readptr = NULL;
81 idereg.status &= ~IDE_ST_DATA;
86 void ide_write_data_pio( uint16_t val ) {
87 if( idereg.writeptr == NULL )
89 *idereg.writeptr++ = val;
91 if( idereg.datalen <= 0 ) {
92 idereg.writeptr = NULL;
93 idereg.status &= ~IDE_ST_DATA;
94 ide_write_buffer( idereg.data );
98 void ide_write_control( uint8_t val ) {
99 /* TODO: In theory we can cause a soft-reset here, but the DC doesn't
100 * appear to support it.
104 void ide_write_command( uint8_t val ) {
105 idereg.command = val;
107 case IDE_CMD_RESET_DEVICE:
111 set_write_buffer(command_buffer,12);
114 WARN( "IDE: Unimplemented command: %02X", val );
116 idereg.status |= IDE_ST_READY | IDE_ST_SERV;
119 void ide_write_buffer( char *data ) {
121 switch( idereg.command ) {
123 /* Okay we have the packet in the command buffer */
124 WARN( "ATAPI: Received Packet command: %02X", data[0] );
126 switch( command_buffer[0] ) {
127 case PKT_CMD_IDENTIFY:
128 /* NB: Bios sets data[4] = 0x08, no idea what this is for;
129 * different values here appear to have no effect.
131 length = *((uint16_t*)(data+2));
132 if( length > sizeof(gdrom_ident) )
133 length = sizeof(gdrom_ident);
134 set_read_buffer(gdrom_ident, length);
.