src/mess/machine/x68k_hdc.c
| r2731 | r2732 | |
| 17 | 17 | |
| 18 | 18 | #include "x68k_hdc.h"
|
| 19 | 19 | |
| 20 | static TIMER_CALLBACK( req_delay )
|
| 21 | {
|
| 22 | sasi_ctrl_t* sasi = ptr;
|
| 23 | sasi->req = 1;
|
| 24 | sasi->status_port |= 0x01;
|
| 25 | }
|
| 26 | |
| 20 | 27 | DEVICE_START( x68k_hdc )
|
| 21 | 28 | {
|
| 22 | 29 | sasi_ctrl_t* sasi = device->token;
|
| r2731 | r2732 | |
| 24 | 31 | assert(device->machine != NULL);
|
| 25 | 32 | |
| 26 | 33 | sasi->status = 0x00;
|
| 34 | sasi->status_port = 0x00;
|
| 27 | 35 | sasi->phase = SASI_PHASE_BUSFREE;
|
| 28 | 36 | }
|
| 29 | 37 | |
| 30 | 38 | WRITE16_DEVICE_HANDLER( x68k_hdc_w )
|
| 31 | 39 | {
|
| 32 | | // SASI HDC - HDDs are not a required system component, so this is something to be done later
|
| 40 | sasi_ctrl_t* sasi = device->token;
|
| 41 | |
| 42 | switch(offset)
|
| 43 | {
|
| 44 | case 0x00: // data I/O
|
| 45 | if(sasi->phase == SASI_PHASE_WRITE)
|
| 46 | {
|
| 47 | if(sasi->transfer_byte_count == 0)
|
| 48 | {
|
| 49 | switch(sasi->command[0])
|
| 50 | {
|
| 51 | case SASI_CMD_SPECIFY:
|
| 52 | sasi->transfer_byte_total = 10;
|
| 53 | break;
|
| 54 | default:
|
| 55 | sasi->transfer_byte_total = 0x800;
|
| 56 | }
|
| 57 | }
|
| 58 | // TODO: Do something with written data
|
| 59 | |
| 60 | if(sasi->command[0] == SASI_CMD_SPECIFY)
|
| 61 | {
|
| 62 | logerror("SPECIFY: wrote 0x%02x\n",data);
|
| 63 | }
|
| 64 | |
| 65 | sasi->req = 0;
|
| 66 | sasi->status_port &= ~0x01;
|
| 67 | timer_set(ATTOTIME_IN_NSEC(450),sasi,0,req_delay);
|
| 68 | sasi->transfer_byte_count++;
|
| 69 | if(sasi->transfer_byte_count >= sasi->transfer_byte_total)
|
| 70 | {
|
| 71 | // End of transfer
|
| 72 | sasi->phase = SASI_PHASE_STATUS;
|
| 73 | sasi->io = 1;
|
| 74 | sasi->status_port |= 0x04;
|
| 75 | sasi->cd = 1;
|
| 76 | sasi->status_port |= 0x08;
|
| 77 | logerror("SASI: Write transfer complete\n");
|
| 78 | }
|
| 79 | }
|
| 80 | if(sasi->phase == SASI_PHASE_COMMAND)
|
| 81 | {
|
| 82 | if(sasi->command_byte_count == 0)
|
| 83 | {
|
| 84 | // first command byte
|
| 85 | sasi->current_command = data;
|
| 86 | switch(data >> 5) // high 3 bits determine command class, and therefore, length
|
| 87 | {
|
| 88 | case 0:
|
| 89 | sasi->command_byte_total = 6;
|
| 90 | break;
|
| 91 | case 1:
|
| 92 | sasi->command_byte_total = 10;
|
| 93 | break;
|
| 94 | case 2:
|
| 95 | sasi->command_byte_total = 8;
|
| 96 | break;
|
| 97 | default:
|
| 98 | sasi->command_byte_total = 6;
|
| 99 | }
|
| 100 | }
|
| 101 | sasi->command[sasi->command_byte_count] = data;
|
| 102 | // reset REQ temporarily
|
| 103 | sasi->req = 0;
|
| 104 | sasi->status_port &= ~0x01;
|
| 105 | timer_set(ATTOTIME_IN_NSEC(450),sasi,0,req_delay);
|
| 106 | |
| 107 | sasi->command_byte_count++;
|
| 108 | if(sasi->command_byte_count >= sasi->command_byte_total)
|
| 109 | {
|
| 110 | // End of command
|
| 111 | // TODO: Actually execute SASI command
|
| 112 | |
| 113 | switch(sasi->command[0])
|
| 114 | {
|
| 115 | case SASI_CMD_REZERO_UNIT:
|
| 116 | sasi->phase = SASI_PHASE_STATUS;
|
| 117 | sasi->io = 1; // Output
|
| 118 | sasi->status_port |= 0x04; // C/D remains the same
|
| 119 | logerror("SASI: REZERO UNIT\n");
|
| 120 | break;
|
| 121 | case SASI_CMD_REQUEST_SENSE:
|
| 122 | sasi->phase = SASI_PHASE_READ;
|
| 123 | sasi->io = 1;
|
| 124 | sasi->status_port |= 0x04;
|
| 125 | sasi->cd = 0;
|
| 126 | sasi->status_port &= ~0x08;
|
| 127 | sasi->transfer_byte_count = 0;
|
| 128 | sasi->transfer_byte_total = 0;
|
| 129 | logerror("SASI: REQUEST SENSE\n");
|
| 130 | break;
|
| 131 | case SASI_CMD_SPECIFY:
|
| 132 | sasi->phase = SASI_PHASE_WRITE;
|
| 133 | sasi->io = 0;
|
| 134 | sasi->status_port &= ~0x04;
|
| 135 | sasi->cd = 0; // Data
|
| 136 | sasi->status_port &= ~0x08;
|
| 137 | sasi->transfer_byte_count = 0;
|
| 138 | sasi->transfer_byte_total = 0;
|
| 139 | logerror("SASI: SPECIFY\n");
|
| 140 | break;
|
| 141 | default:
|
| 142 | sasi->phase = SASI_PHASE_STATUS;
|
| 143 | sasi->io = 1; // Output
|
| 144 | sasi->status_port |= 0x04; // C/D remains the same
|
| 145 | sasi->status = 0x02;
|
| 146 | logerror("SASI: Invalid or unimplemented SASI command (0x%02x) recieved.\n",sasi->command[0]);
|
| 147 | }
|
| 148 | }
|
| 149 | }
|
| 150 | break;
|
| 151 | case 0x01:
|
| 152 | if(data == 0)
|
| 153 | {
|
| 154 | if(sasi->phase == SASI_PHASE_SELECTION)
|
| 155 | {
|
| 156 | // Go to Command phase
|
| 157 | sasi->phase = SASI_PHASE_COMMAND;
|
| 158 | sasi->cd = 1; // data port expects a command or status
|
| 159 | sasi->status_port |= 0x08;
|
| 160 | sasi->command_byte_count = 0;
|
| 161 | sasi->command_byte_total = 0;
|
| 162 | timer_set(ATTOTIME_IN_NSEC(45),sasi,0,req_delay);
|
| 163 | }
|
| 164 | }
|
| 165 | break;
|
| 166 | case 0x02:
|
| 167 | break;
|
| 168 | case 0x03:
|
| 169 | if(data != 0)
|
| 170 | {
|
| 171 | if(sasi->phase == SASI_PHASE_BUSFREE)
|
| 172 | {
|
| 173 | // Go to Selection phase
|
| 174 | sasi->phase = SASI_PHASE_SELECTION;
|
| 175 | sasi->bsy = 1; // HDC is now busy
|
| 176 | sasi->status_port |= 0x02;
|
| 177 | }
|
| 178 | }
|
| 179 | break;
|
| 180 | }
|
| 181 | |
| 33 | 182 | logerror("SASI: write to HDC, offset %04x, data %04x\n",offset,data);
|
| 34 | 183 | }
|
| 35 | 184 | |
| 36 | 185 | READ16_DEVICE_HANDLER( x68k_hdc_r )
|
| 37 | 186 | {
|
| 38 | | logerror("SASI: [%08x] read from HDC, offset %04x\n",activecpu_get_pc(),offset);
|
| 187 | sasi_ctrl_t* sasi = device->token;
|
| 188 | int retval;
|
| 189 | |
| 39 | 190 | switch(offset)
|
| 40 | 191 | {
|
| 41 | 192 | case 0x00:
|
| 193 | if(sasi->phase == SASI_PHASE_MESSAGE)
|
| 194 | {
|
| 195 | sasi->phase = SASI_PHASE_BUSFREE;
|
| 196 | sasi->msg = 0;
|
| 197 | sasi->cd = 0;
|
| 198 | sasi->io = 0;
|
| 199 | sasi->bsy = 0;
|
| 200 | sasi->req = 0;
|
| 201 | sasi->status = 0;
|
| 202 | sasi->status_port = 0; // reset all status bits to 0
|
| 203 | return 0x00;
|
| 204 | }
|
| 205 | if(sasi->phase == SASI_PHASE_STATUS)
|
| 206 | {
|
| 207 | sasi->phase = SASI_PHASE_MESSAGE;
|
| 208 | sasi->msg = 1;
|
| 209 | sasi->status_port |= 0x10;
|
| 210 | // reset REQ temporarily
|
| 211 | sasi->req = 0;
|
| 212 | sasi->status_port &= ~0x01;
|
| 213 | timer_set(ATTOTIME_IN_NSEC(450),sasi,0,req_delay);
|
| 214 | |
| 215 | return sasi->status;
|
| 216 | }
|
| 217 | if(sasi->phase == SASI_PHASE_READ)
|
| 218 | {
|
| 219 | if(sasi->transfer_byte_count == 0)
|
| 220 | {
|
| 221 | switch(sasi->command[0])
|
| 222 | {
|
| 223 | case SASI_CMD_REQUEST_SENSE:
|
| 224 | // set up sense bytes
|
| 225 | sasi->sense[0] = 0x01; // "No index signal"
|
| 226 | sasi->sense[1] = 0;
|
| 227 | sasi->sense[2] = 0;
|
| 228 | sasi->sense[3] = 0;
|
| 229 | if(sasi->command[3] == 0)
|
| 230 | sasi->transfer_byte_total = 4;
|
| 231 | else
|
| 232 | sasi->transfer_byte_total = sasi->command[3];
|
| 233 | break;
|
| 234 | default:
|
| 235 | sasi->transfer_byte_total = 0;
|
| 236 | }
|
| 237 | }
|
| 238 |
|
| 239 | switch(sasi->command[0])
|
| 240 | {
|
| 241 | case SASI_CMD_REQUEST_SENSE:
|
| 242 | retval = sasi->sense[sasi->transfer_byte_count];
|
| 243 | logerror("REQUEST SENSE: read value 0x%02x\n",retval);
|
| 244 | break;
|
| 245 | default:
|
| 246 | retval = 0;
|
| 247 | }
|
| 248 | |
| 249 | sasi->req = 0;
|
| 250 | sasi->status_port &= ~0x01;
|
| 251 | timer_set(ATTOTIME_IN_NSEC(450),sasi,0,req_delay);
|
| 252 | sasi->transfer_byte_count++;
|
| 253 | if(sasi->transfer_byte_count >= sasi->transfer_byte_total)
|
| 254 | {
|
| 255 | // End of transfer
|
| 256 | sasi->phase = SASI_PHASE_STATUS;
|
| 257 | sasi->io = 1;
|
| 258 | sasi->status_port |= 0x04;
|
| 259 | sasi->cd = 1;
|
| 260 | sasi->status_port |= 0x08;
|
| 261 | logerror("SASI: Read transfer complete\n");
|
| 262 | }
|
| 263 | |
| 264 | return retval;
|
| 265 | }
|
| 42 | 266 | return 0x00;
|
| 43 | 267 | case 0x01:
|
| 44 | | return 0x00;
|
| 268 | logerror("SASI: [%08x] read from status port, read 0x%02x\n",activecpu_get_pc(),sasi->status_port);
|
| 269 | return sasi->status_port;
|
| 45 | 270 | case 0x02:
|
| 46 | | return 0x00;
|
| 271 | return 0xff; // write-only
|
| 47 | 272 | case 0x03:
|
| 48 | | return 0x00;
|
| 273 | return 0xff; // write-only
|
| 49 | 274 | default:
|
| 50 | 275 | return 0xff;
|
| 51 | 276 | }
|
src/mess/machine/x68k_hdc.h
| r2731 | r2732 | |
| 15 | 15 | SASI_PHASE_COMMAND,
|
| 16 | 16 | SASI_PHASE_DATA,
|
| 17 | 17 | SASI_PHASE_STATUS,
|
| 18 | | SASI_PHASE_MESSAGE
|
| 18 | SASI_PHASE_MESSAGE,
|
| 19 | SASI_PHASE_READ,
|
| 20 | SASI_PHASE_WRITE
|
| 19 | 21 | };
|
| 20 | 22 | |
| 23 | // SASI commands, based on the SASI standard
|
| 24 | enum
|
| 25 | {
|
| 26 | // Class 0 (6-byte) commands
|
| 27 | SASI_CMD_TEST_UNIT_READY = 0,
|
| 28 | SASI_CMD_REZERO_UNIT,
|
| 29 | SASI_CMD_RESERVED_02,
|
| 30 | SASI_CMD_REQUEST_SENSE,
|
| 31 | SASI_CMD_FORMAT_UNIT,
|
| 32 | SASI_CMD_RESERVED_05,
|
| 33 | SASI_CMD_RESERVED_06,
|
| 34 | SASI_CMD_RESERVED_07,
|
| 35 | SASI_CMD_READ,
|
| 36 | SASI_CMD_RESERVED_09,
|
| 37 | SASI_CMD_WRITE,
|
| 38 | SASI_CMD_SEEK,
|
| 39 | SASI_CMD_RESERVED_0C,
|
| 40 | SASI_CMD_RESERVED_0D,
|
| 41 | SASI_CMD_RESERVED_0E,
|
| 42 | SASI_CMD_WRITE_FILE_MARK,
|
| 43 | SASI_CMD_INVALID_10,
|
| 44 | SASI_CMD_INVALID_11,
|
| 45 | SASI_CMD_RESERVE_UNIT,
|
| 46 | SASI_CMD_RELEASE_UNIT,
|
| 47 | SASI_CMD_INVALID_14,
|
| 48 | SASI_CMD_INVALID_15,
|
| 49 | SASI_CMD_READ_CAPACITY,
|
| 50 | SASI_CMD_INVALID_17,
|
| 51 | SASI_CMD_INVALID_18,
|
| 52 | SASI_CMD_INVALID_19,
|
| 53 | SASI_CMD_READ_DIAGNOSTIC,
|
| 54 | SASI_CMD_WRITE_DIAGNOSTIC,
|
| 55 | SASI_CMD_INVALID_1C,
|
| 56 | SASI_CMD_INVALID_1D,
|
| 57 | SASI_CMD_INVALID_1E,
|
| 58 | SASI_CMD_INQUIRY,
|
| 59 | // Class 1 commands (yes, just the one)
|
| 60 | SASI_CMD_RESERVED_20,
|
| 61 | SASI_CMD_RESERVED_21,
|
| 62 | SASI_CMD_RESERVED_22,
|
| 63 | SASI_CMD_SET_BLOCK_LIMITS = 0x28,
|
| 64 | // Class 2 commands
|
| 65 | SASI_CMD_EXTENDED_ADDRESS_READ = 0x48,
|
| 66 | SASI_CMD_INVALID_49,
|
| 67 | SASI_CMD_EXTENDED_ADDRESS_WRITE,
|
| 68 | SASI_CMD_WRITE_AND_VERIFY = 0x54,
|
| 69 | SASI_CMD_VERIFY,
|
| 70 | SASI_CMD_INVALID_56,
|
| 71 | SASI_CMD_SEARCH_DATA_HIGH,
|
| 72 | SASI_CMD_SEARCH_DATA_EQUAL,
|
| 73 | SASI_CMD_SEARCH_DATA_LOW,
|
| 74 | // controller-specific commands
|
| 75 | SASI_CMD_SPECIFY = 0xc2
|
| 76 | };
|
| 77 | |
| 21 | 78 | typedef struct _sasi_ctrl_t sasi_ctrl_t;
|
| 22 | 79 | struct _sasi_ctrl_t
|
| 23 | 80 | {
|
| r2731 | r2732 | |
| 26 | 83 | unsigned char status; // status phase output
|
| 27 | 84 | unsigned char message;
|
| 28 | 85 | unsigned char command[10];
|
| 86 | unsigned char sense[4];
|
| 87 | int command_byte_count;
|
| 88 | int command_byte_total;
|
| 89 | int current_command;
|
| 90 | int transfer_byte_count;
|
| 91 | int transfer_byte_total;
|
| 92 | int msg; // MSG
|
| 93 | int cd; // C/D (Command/Data)
|
| 94 | int bsy; // BSY
|
| 95 | int io; // I/O
|
| 96 | int req; // REQ
|
| 29 | 97 | };
|
| 30 | 98 | |
| 31 | 99 | DEVICE_START( x68k_hdc );
|