src/mess/machine/fm_scsi.c
| r0 | r9491 | |
| 1 | /* |
| 2 | * |
| 3 | * Implementation of Fujitsu FMR-50, FMR-60 and FM-Towns SCSI hardware |
| 4 | * |
| 5 | * |
| 6 | |
| 7 | info from Toshiya Takeda's e-FMR50 source (the Towns uses the same controller?) |
| 8 | 0xc30 = Data register |
| 9 | 0xc32 = Status register (read) |
| 10 | bit 7 = REQ |
| 11 | bit 6 = I/O |
| 12 | bit 5 = MSG |
| 13 | bit 4 = C/D |
| 14 | bit 3 = BUSY |
| 15 | bit 1 = INT |
| 16 | bit 0 = PERR |
| 17 | 0xc32 = Control register (write) |
| 18 | bit 7 = WEN |
| 19 | bit 6 = IMSK |
| 20 | bit 4 = ATN |
| 21 | bit 2 = SEL |
| 22 | bit 1 = DMAE |
| 23 | bit 0 = RST |
| 24 | */ |
| 25 | #include "emu.h" |
| 26 | #include "fm_scsi.h" |
| 27 | #include "machine/devhelpr.h" |
| 28 | |
| 29 | /* |
| 30 | * Device config |
| 31 | */ |
| 32 | |
| 33 | const device_type FMSCSI = fmscsi_device_config::static_alloc_device_config; |
| 34 | |
| 35 | GENERIC_DEVICE_CONFIG_SETUP(fmscsi, "FM-SCSI") |
| 36 | |
| 37 | void fmscsi_device_config::device_config_complete() |
| 38 | { |
| 39 | // copy static configuration if present |
| 40 | const FMSCSIinterface *intf = reinterpret_cast<const FMSCSIinterface *>(static_config()); |
| 41 | if (intf != NULL) |
| 42 | *static_cast<FMSCSIinterface *>(this) = *intf; |
| 43 | |
| 44 | // otherwise, initialize it to defaults |
| 45 | else |
| 46 | { |
| 47 | scsidevs = NULL; |
| 48 | memset(&irq_callback,0,sizeof(irq_callback)); |
| 49 | memset(&drq_callback,0,sizeof(drq_callback)); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Device |
| 55 | */ |
| 56 | |
| 57 | fmscsi_device::fmscsi_device(running_machine &machine, const fmscsi_device_config &config) |
| 58 | : device_t(machine, config), |
| 59 | m_config(config) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | void fmscsi_device::device_start() |
| 64 | { |
| 65 | int x; |
| 66 | |
| 67 | m_input_lines = 0; |
| 68 | m_output_lines = 0; |
| 69 | m_data = 0; |
| 70 | m_command_index = 0; |
| 71 | m_last_id = 0; |
| 72 | m_target = 0; |
| 73 | m_phase = SCSI_PHASE_BUS_FREE; |
| 74 | |
| 75 | devcb_resolve_write_line(&m_irq_func,&m_config.irq_callback,this); |
| 76 | devcb_resolve_write_line(&m_drq_func,&m_config.drq_callback,this); |
| 77 | |
| 78 | memset(m_SCSIdevices,0,sizeof(m_SCSIdevices)); |
| 79 | |
| 80 | // initialise SCSI devices, if any present |
| 81 | for(x=0;x<m_config.scsidevs->devs_present;x++) |
| 82 | { |
| 83 | SCSIAllocInstance(machine, m_config.scsidevs->devices[x].scsiClass, |
| 84 | &m_SCSIdevices[m_config.scsidevs->devices[x].scsiID], |
| 85 | m_config.scsidevs->devices[x].diskregion ); |
| 86 | } |
| 87 | |
| 88 | // allocate read timer |
| 89 | m_transfer_timer = device_timer_alloc(*this,TIMER_TRANSFER); |
| 90 | } |
| 91 | |
| 92 | void fmscsi_device::device_reset() |
| 93 | { |
| 94 | m_input_lines = 0; |
| 95 | m_output_lines = 0; |
| 96 | m_data = 0; |
| 97 | m_command_index = 0; |
| 98 | m_last_id = 0; |
| 99 | m_target = 0; |
| 100 | m_result_length = 0; |
| 101 | m_result_index = 0; |
| 102 | |
| 103 | m_phase = SCSI_PHASE_BUS_FREE; |
| 104 | fmscsi_rescan(); |
| 105 | } |
| 106 | |
| 107 | void fmscsi_device::device_stop() |
| 108 | { |
| 109 | int x; |
| 110 | |
| 111 | // clean up the devices |
| 112 | for (x=0;x<m_config.scsidevs->devs_present;x++) |
| 113 | { |
| 114 | SCSIDeleteInstance( m_SCSIdevices[m_config.scsidevs->devices[x].scsiID] ); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // get the length of a SCSI command based on it's command byte type |
| 119 | int fmscsi_device::get_scsi_cmd_len(UINT8 cbyte) |
| 120 | { |
| 121 | int group; |
| 122 | |
| 123 | group = (cbyte>>5) & 7; |
| 124 | |
| 125 | if (group == 0) return 6; |
| 126 | if (group == 1 || group == 2) return 10; |
| 127 | if (group == 5) return 12; |
| 128 | |
| 129 | fatalerror("fmscsi: Unknown SCSI command group %d", group); |
| 130 | |
| 131 | return 6; |
| 132 | } |
| 133 | |
| 134 | void fmscsi_device::fmscsi_rescan() |
| 135 | { |
| 136 | int i; |
| 137 | |
| 138 | // try to open the devices |
| 139 | for (i = 0; i < m_config.scsidevs->devs_present; i++) |
| 140 | { |
| 141 | // if a device wasn't already allocated |
| 142 | // if (!m_SCSIdevices[m_config.scsidevs->devices[i].scsiID]) |
| 143 | { |
| 144 | SCSIDeleteInstance( m_SCSIdevices[m_config.scsidevs->devices[i].scsiID] ); |
| 145 | SCSIAllocInstance( machine, |
| 146 | m_config.scsidevs->devices[i].scsiClass, |
| 147 | &m_SCSIdevices[m_config.scsidevs->devices[i].scsiID], |
| 148 | m_config.scsidevs->devices[i].diskregion ); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void fmscsi_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 154 | { |
| 155 | switch(id) |
| 156 | { |
| 157 | case TIMER_TRANSFER: |
| 158 | set_input_line(FMSCSI_LINE_REQ,1); |
| 159 | //logerror("FMSCSI: timer triggered: %i/%i\n",m_result_index,m_result_length); |
| 160 | if(m_output_lines & FMSCSI_LINE_DMAE) |
| 161 | { |
| 162 | devcb_call_write_line(&m_drq_func,1); |
| 163 | } |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | UINT8 fmscsi_device::fmscsi_data_r(void) |
| 169 | { |
| 170 | // read from data bus |
| 171 | // ACK is automatic on accessing the data bus, so REQ will go low. |
| 172 | set_input_line(FMSCSI_LINE_REQ,0); |
| 173 | |
| 174 | if(m_phase == SCSI_PHASE_DATAIN) |
| 175 | { |
| 176 | m_data = m_buffer[m_result_index % 512]; |
| 177 | //logerror("FMSCSI: DATAIN phase read data %02x\n",m_data); |
| 178 | m_result_index++; |
| 179 | if(m_result_index % 512 == 0) |
| 180 | SCSIReadData(m_SCSIdevices[m_target],m_buffer,512); // read next sector |
| 181 | |
| 182 | if(m_result_index >= m_result_length) |
| 183 | { |
| 184 | // end of data transfer |
| 185 | set_phase(SCSI_PHASE_STATUS); |
| 186 | if(m_output_lines & FMSCSI_LINE_DMAE) |
| 187 | { |
| 188 | devcb_call_write_line(&m_drq_func,0); |
| 189 | } |
| 190 | timer_adjust_periodic(m_transfer_timer,attotime_zero,0,attotime_never); // stop timer |
| 191 | logerror("FMSCSI: Stopping transfer : (%i/%i)\n",m_result_index,m_result_length); |
| 192 | } |
| 193 | return m_data; |
| 194 | } |
| 195 | |
| 196 | if(m_phase == SCSI_PHASE_MESSAGE_IN) |
| 197 | { |
| 198 | m_data = 0; // command complete message |
| 199 | set_phase(SCSI_PHASE_BUS_FREE); |
| 200 | m_command_index = 0; |
| 201 | return m_data; |
| 202 | } |
| 203 | |
| 204 | if(m_phase == SCSI_PHASE_STATUS) |
| 205 | { |
| 206 | m_data = 0; // no errors |
| 207 | // no command complete message? |
| 208 | set_phase(SCSI_PHASE_BUS_FREE); |
| 209 | m_command_index = 0; |
| 210 | //set_input_line(FMSCSI_LINE_REQ,1); // raise REQ yet again |
| 211 | return m_data; |
| 212 | } |
| 213 | |
| 214 | return m_data; |
| 215 | } |
| 216 | |
| 217 | void fmscsi_device::fmscsi_data_w(UINT8 data) |
| 218 | { |
| 219 | int phase; |
| 220 | |
| 221 | // write to data bus |
| 222 | m_data = data; |
| 223 | //logerror("FMSCSI: data write %02x\n",data); |
| 224 | |
| 225 | // ACK is automatic on accessing the data bus, so REQ will go low. |
| 226 | set_input_line(FMSCSI_LINE_REQ,0); |
| 227 | |
| 228 | if(m_phase == SCSI_PHASE_BUS_FREE) |
| 229 | { |
| 230 | // select target |
| 231 | switch(data & 0x7f) |
| 232 | { |
| 233 | case 0x01: m_target = 0; break; |
| 234 | case 0x02: m_target = 1; break; |
| 235 | case 0x04: m_target = 2; break; |
| 236 | case 0x08: m_target = 3; break; |
| 237 | case 0x10: m_target = 4; break; |
| 238 | } |
| 239 | } |
| 240 | if(m_phase == SCSI_PHASE_COMMAND) |
| 241 | { |
| 242 | m_command[m_command_index] = data; |
| 243 | logerror("FMSCSI: writing command byte %02x [%i]\n",data,m_command_index); |
| 244 | m_command_index++; |
| 245 | if(m_command_index >= get_scsi_cmd_len(m_command[0])) |
| 246 | { |
| 247 | // command complete |
| 248 | SCSISetCommand(m_SCSIdevices[m_target],m_command,m_command_index); |
| 249 | SCSIExecCommand(m_SCSIdevices[m_target],&m_result_length); |
| 250 | SCSIGetPhase(m_SCSIdevices[m_target],&phase); |
| 251 | set_phase(phase); |
| 252 | if(m_command[0] == 1) // rezero unit command - not implemented in SCSI code |
| 253 | set_phase(SCSI_PHASE_STATUS); |
| 254 | if(phase == SCSI_PHASE_STATUS) |
| 255 | set_input_line(FMSCSI_LINE_REQ,1); |
| 256 | if(phase == SCSI_PHASE_DATAIN) |
| 257 | { |
| 258 | // start transfer timer |
| 259 | timer_adjust_periodic(m_transfer_timer,attotime_zero,0,ATTOTIME_IN_HZ(3000000)); // arbitrary value for now |
| 260 | SCSIReadData(m_SCSIdevices[m_target],m_buffer,512); |
| 261 | m_result_index = 0; |
| 262 | logerror("FMSCSI: Starting transfer (%i)\n",m_result_length); |
| 263 | } |
| 264 | |
| 265 | logerror("FMSCSI: Command %02x sent, result length = %i\n",m_command[0],m_result_length); |
| 266 | } |
| 267 | else |
| 268 | { |
| 269 | set_input_line(FMSCSI_LINE_REQ,1); |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | void fmscsi_device::set_phase(int phase) |
| 275 | { |
| 276 | m_phase = phase; |
| 277 | logerror("FMSCSI: phase set to %i\n",m_phase); |
| 278 | // set input lines accordingly |
| 279 | switch(phase) |
| 280 | { |
| 281 | case SCSI_PHASE_BUS_FREE: |
| 282 | set_input_line(FMSCSI_LINE_BSY,0); |
| 283 | set_input_line(FMSCSI_LINE_CD,0); |
| 284 | set_input_line(FMSCSI_LINE_MSG,0); |
| 285 | set_input_line(FMSCSI_LINE_IO,0); |
| 286 | set_input_line(FMSCSI_LINE_REQ,0); |
| 287 | break; |
| 288 | case SCSI_PHASE_COMMAND: |
| 289 | set_input_line(FMSCSI_LINE_BSY,1); |
| 290 | set_input_line(FMSCSI_LINE_CD,1); |
| 291 | set_input_line(FMSCSI_LINE_MSG,0); |
| 292 | set_input_line(FMSCSI_LINE_IO,0); |
| 293 | set_input_line(FMSCSI_LINE_REQ,1); |
| 294 | break; |
| 295 | case SCSI_PHASE_STATUS: |
| 296 | set_input_line(FMSCSI_LINE_CD,1); |
| 297 | set_input_line(FMSCSI_LINE_MSG,0); |
| 298 | set_input_line(FMSCSI_LINE_IO,1); |
| 299 | set_input_line(FMSCSI_LINE_REQ,1); |
| 300 | break; |
| 301 | case SCSI_PHASE_DATAIN: |
| 302 | set_input_line(FMSCSI_LINE_CD,0); |
| 303 | set_input_line(FMSCSI_LINE_MSG,0); |
| 304 | set_input_line(FMSCSI_LINE_IO,1); |
| 305 | set_input_line(FMSCSI_LINE_REQ,1); |
| 306 | break; |
| 307 | case SCSI_PHASE_DATAOUT: |
| 308 | set_input_line(FMSCSI_LINE_CD,0); |
| 309 | set_input_line(FMSCSI_LINE_MSG,0); |
| 310 | set_input_line(FMSCSI_LINE_IO,0); |
| 311 | set_input_line(FMSCSI_LINE_REQ,1); |
| 312 | break; |
| 313 | case SCSI_PHASE_MESSAGE_IN: |
| 314 | set_input_line(FMSCSI_LINE_CD,1); |
| 315 | set_input_line(FMSCSI_LINE_MSG,1); |
| 316 | set_input_line(FMSCSI_LINE_IO,1); |
| 317 | set_input_line(FMSCSI_LINE_REQ,1); |
| 318 | break; |
| 319 | case SCSI_PHASE_MESSAGE_OUT: |
| 320 | set_input_line(FMSCSI_LINE_CD,1); |
| 321 | set_input_line(FMSCSI_LINE_MSG,1); |
| 322 | set_input_line(FMSCSI_LINE_IO,0); |
| 323 | set_input_line(FMSCSI_LINE_REQ,1); |
| 324 | break; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | int fmscsi_device::get_phase(void) |
| 329 | { |
| 330 | return m_phase; |
| 331 | } |
| 332 | |
| 333 | void fmscsi_device::set_input_line(UINT8 line, UINT8 state) |
| 334 | { |
| 335 | if(line == FMSCSI_LINE_REQ) |
| 336 | { |
| 337 | if(state != 0 && !(m_input_lines & FMSCSI_LINE_REQ)) // low to high |
| 338 | { |
| 339 | if(m_output_lines & FMSCSI_LINE_IMSK && m_phase == SCSI_PHASE_COMMAND) |
| 340 | { |
| 341 | //set_input_line(FMSCSI_LINE_INT,1); |
| 342 | devcb_call_write_line(&m_irq_func,1); |
| 343 | } |
| 344 | } |
| 345 | if(state == 0 && (m_input_lines & FMSCSI_LINE_REQ)) // high to low |
| 346 | { |
| 347 | if(m_output_lines & FMSCSI_LINE_IMSK && m_phase == SCSI_PHASE_COMMAND) |
| 348 | { |
| 349 | //set_input_line(FMSCSI_LINE_INT,0); |
| 350 | devcb_call_write_line(&m_irq_func,0); |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | if(state != 0) |
| 355 | m_input_lines |= line; |
| 356 | else |
| 357 | m_input_lines &= ~line; |
| 358 | // logerror("FMSCSI: input line %02x set to %i\n",line,state); |
| 359 | } |
| 360 | |
| 361 | UINT8 fmscsi_device::get_input_line(UINT8 line) |
| 362 | { |
| 363 | return m_input_lines & line; |
| 364 | } |
| 365 | |
| 366 | void fmscsi_device::set_output_line(UINT8 line, UINT8 state) |
| 367 | { |
| 368 | device_image_interface* image; |
| 369 | |
| 370 | if(line == FMSCSI_LINE_RST && state != 0) |
| 371 | { |
| 372 | device_reset(); |
| 373 | logerror("FMSCSI: reset\n"); |
| 374 | } |
| 375 | |
| 376 | if(line == FMSCSI_LINE_SEL) |
| 377 | { |
| 378 | image = dynamic_cast<device_image_interface*>(machine->device(m_config.scsidevs->devices[m_target].diskregion)); |
| 379 | if(state != 0 && !(m_output_lines & FMSCSI_LINE_SEL)) // low to high transition |
| 380 | { |
| 381 | if (image->exists()) // if device is mounted |
| 382 | { |
| 383 | set_phase(SCSI_PHASE_COMMAND); |
| 384 | m_data = 0x08; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | // TODO: ATN functionality |
| 390 | |
| 391 | if(state != 0) |
| 392 | m_output_lines |= line; |
| 393 | else |
| 394 | m_output_lines &= ~line; |
| 395 | // logerror("FMSCSI: output line %02x set to %i\n",line,state); |
| 396 | } |
| 397 | |
| 398 | UINT8 fmscsi_device::get_output_line(UINT8 line) |
| 399 | { |
| 400 | return m_output_lines & line; |
| 401 | } |
| 402 | |
| 403 | UINT8 fmscsi_device::fmscsi_status_r(void) |
| 404 | { |
| 405 | // status inputs |
| 406 | return m_input_lines; |
| 407 | } |
| 408 | |
| 409 | void fmscsi_device::fmscsi_control_w(UINT8 data) |
| 410 | { |
| 411 | // control outputs |
| 412 | set_output_line(FMSCSI_LINE_RST,data & FMSCSI_LINE_RST); |
| 413 | set_output_line(FMSCSI_LINE_DMAE,data & FMSCSI_LINE_DMAE); |
| 414 | set_output_line(FMSCSI_LINE_IMSK,data & FMSCSI_LINE_IMSK); |
| 415 | set_output_line(FMSCSI_LINE_ATN,data & FMSCSI_LINE_ATN); |
| 416 | set_output_line(FMSCSI_LINE_WEN,data & FMSCSI_LINE_WEN); |
| 417 | set_output_line(FMSCSI_LINE_SEL,data & FMSCSI_LINE_SEL); |
| 418 | logerror("FMSCSI: control write %02x\n",data); |
| 419 | } |
| 420 | |
| 421 | READ8_MEMBER( fmscsi_device::fmscsi_r ) |
| 422 | { |
| 423 | switch(offset & 0x01) |
| 424 | { |
| 425 | case 0x00: |
| 426 | return fmscsi_data_r(); |
| 427 | case 0x01: |
| 428 | return fmscsi_status_r(); |
| 429 | } |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | WRITE8_MEMBER( fmscsi_device::fmscsi_w ) |
| 434 | { |
| 435 | switch(offset & 0x01) |
| 436 | { |
| 437 | case 0x00: |
| 438 | fmscsi_data_w(data); |
| 439 | break; |
| 440 | case 0x01: |
| 441 | fmscsi_control_w(data); |
| 442 | break; |
| 443 | } |
| 444 | } |
src/mess/machine/fm_scsi.h
| r0 | r9491 | |
| 1 | /* |
| 2 | * fm_scsi.h |
| 3 | * |
| 4 | * SCSI controller used in Fujitsu FMR-50, FMR-60, and FM-Towns |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef FM_SCSI_H_ |
| 9 | #define FM_SCSI_H_ |
| 10 | |
| 11 | #include "machine/scsidev.h" |
| 12 | |
| 13 | // SCSI input lines (from target) |
| 14 | #define FMSCSI_LINE_REQ 0x80 |
| 15 | #define FMSCSI_LINE_IO 0x40 |
| 16 | #define FMSCSI_LINE_MSG 0x20 |
| 17 | #define FMSCSI_LINE_CD 0x10 |
| 18 | #define FMSCSI_LINE_BSY 0x08 |
| 19 | #define FMSCSI_LINE_INT 0x02 |
| 20 | #define FMSCSI_LINE_PERR 0x01 |
| 21 | |
| 22 | // SCSI output lines (to target) |
| 23 | #define FMSCSI_LINE_WEN 0x80 |
| 24 | #define FMSCSI_LINE_IMSK 0x40 |
| 25 | #define FMSCSI_LINE_ATN 0x10 |
| 26 | #define FMSCSI_LINE_SEL 0x04 |
| 27 | #define FMSCSI_LINE_DMAE 0x02 |
| 28 | #define FMSCSI_LINE_RST 0x01 |
| 29 | |
| 30 | // these aren't defined in scsi.h |
| 31 | #define SCSI_PHASE_BUS_FREE 8 |
| 32 | #define SCSI_PHASE_SELECT 9 |
| 33 | |
| 34 | struct FMSCSIinterface |
| 35 | { |
| 36 | const SCSIConfigTable *scsidevs; /* SCSI devices */ |
| 37 | devcb_write_line irq_callback; /* irq callback */ |
| 38 | devcb_write_line drq_callback; /* drq callback */ |
| 39 | }; |
| 40 | |
| 41 | #define MDRV_FMSCSI_ADD(_tag, _intrf) \ |
| 42 | MDRV_DEVICE_ADD(_tag, FMSCSI, 0) \ |
| 43 | MDRV_DEVICE_CONFIG(_intrf) |
| 44 | |
| 45 | class fmscsi_device_config : public device_config, public FMSCSIinterface |
| 46 | { |
| 47 | friend class fmscsi_device; |
| 48 | |
| 49 | // construction/destruction |
| 50 | fmscsi_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 51 | |
| 52 | public: |
| 53 | // allocators |
| 54 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 55 | virtual device_t *alloc_device(running_machine &machine) const; |
| 56 | |
| 57 | protected: |
| 58 | // device_config overrides |
| 59 | virtual void device_config_complete(); |
| 60 | }; |
| 61 | |
| 62 | class fmscsi_device : public device_t |
| 63 | { |
| 64 | friend class fmscsi_device_config; |
| 65 | |
| 66 | // construction/destruction |
| 67 | fmscsi_device(running_machine &machine, const fmscsi_device_config &config); |
| 68 | |
| 69 | public: |
| 70 | // any publically accessible interfaces needed for runtime |
| 71 | UINT8 fmscsi_data_r(void); |
| 72 | void fmscsi_data_w(UINT8 data); |
| 73 | UINT8 fmscsi_status_r(void); |
| 74 | void fmscsi_control_w(UINT8 data); |
| 75 | DECLARE_READ8_MEMBER( fmscsi_r ); |
| 76 | DECLARE_WRITE8_MEMBER( fmscsi_w ); |
| 77 | |
| 78 | void set_phase(int phase); |
| 79 | int get_phase(void); |
| 80 | void set_input_line(UINT8 line, UINT8 state); |
| 81 | UINT8 get_input_line(UINT8 line); |
| 82 | void set_output_line(UINT8 line, UINT8 state); |
| 83 | UINT8 get_output_line(UINT8 line); |
| 84 | |
| 85 | protected: |
| 86 | // device-level overrides (none are required, but these are common) |
| 87 | virtual void device_start(); |
| 88 | virtual void device_reset(); |
| 89 | virtual void device_stop(); |
| 90 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 91 | |
| 92 | private: |
| 93 | // internal device state goes here |
| 94 | const fmscsi_device_config &m_config; |
| 95 | static const device_timer_id TIMER_TRANSFER = 0; |
| 96 | |
| 97 | void fmscsi_rescan(void); |
| 98 | int get_scsi_cmd_len(UINT8 cbyte); |
| 99 | |
| 100 | devcb_resolved_write_line m_irq_func; |
| 101 | devcb_resolved_write_line m_drq_func; |
| 102 | |
| 103 | SCSIInstance* m_SCSIdevices[8]; |
| 104 | UINT8 m_command[32]; |
| 105 | UINT8 m_result[32]; |
| 106 | UINT8 m_command_index; |
| 107 | int m_result_length; |
| 108 | UINT32 m_result_index; |
| 109 | UINT8 m_input_lines; |
| 110 | UINT8 m_output_lines; |
| 111 | UINT8 m_data; |
| 112 | UINT8 m_last_id; |
| 113 | UINT8 m_phase; |
| 114 | UINT8 m_target; |
| 115 | UINT8 m_buffer[512]; |
| 116 | emu_timer* m_transfer_timer; |
| 117 | }; |
| 118 | |
| 119 | extern const device_type FMSCSI; |
| 120 | |
| 121 | #endif /* FM_SCSI_H_ */ |
src/mess/drivers/fmtowns.c
| r9490 | r9491 | |
| 128 | 128 | #include "machine/nvram.h" |
| 129 | 129 | #include "devices/harddriv.h" |
| 130 | 130 | #include "machine/scsi.h" |
| 131 | | #include "machine/scsibus.h" |
| 131 | #include "machine/fm_scsi.h" |
| 132 | 132 | |
| 133 | 133 | // CD controller IRQ types |
| 134 | 134 | #define TOWNS_CD_IRQ_MPU 1 |
| r9490 | r9491 | |
| 323 | 323 | towns_state* state = space->machine->driver_data<towns_state>(); |
| 324 | 324 | running_device* dev = state->dma_1; |
| 325 | 325 | |
| 326 | | logerror("DMA#1: read register %i\n",offset); |
| 326 | // logerror("DMA#1: read register %i\n",offset); |
| 327 | 327 | return upd71071_r(dev,offset); |
| 328 | 328 | } |
| 329 | 329 | |
| r9490 | r9491 | |
| 332 | 332 | towns_state* state = space->machine->driver_data<towns_state>(); |
| 333 | 333 | running_device* dev = state->dma_1; |
| 334 | 334 | |
| 335 | | logerror("DMA#1: wrote 0x%02x to register %i\n",data,offset); |
| 335 | // logerror("DMA#1: wrote 0x%02x to register %i\n",data,offset); |
| 336 | 336 | upd71071_w(dev,offset,data); |
| 337 | 337 | } |
| 338 | 338 | |
| r9490 | r9491 | |
| 370 | 370 | |
| 371 | 371 | static WRITE_LINE_DEVICE_HANDLER( towns_mb8877a_drq_w ) |
| 372 | 372 | { |
| 373 | | upd71071_dmarq(device, state, 0); |
| 373 | towns_state* tstate = device->machine->driver_data<towns_state>(); |
| 374 | upd71071_dmarq(tstate->dma_1, state, 0); |
| 374 | 375 | } |
| 375 | 376 | |
| 376 | 377 | static READ8_HANDLER(towns_floppy_r) |
| r9490 | r9491 | |
| 1763 | 1764 | } |
| 1764 | 1765 | |
| 1765 | 1766 | // SCSI controller - I/O ports 0xc30 and 0xc32 |
| 1766 | | // info from Toshiya Takeda's e-FMR50 source (the Towns uses the same controller?) |
| 1767 | | // 0xc30 = Data register |
| 1768 | | // 0xc32 = Status register (read) |
| 1769 | | // bit 7 = REQ |
| 1770 | | // bit 6 = IO |
| 1771 | | // bit 5 = MSG |
| 1772 | | // bit 4 = CD |
| 1773 | | // bit 3 = BUSY |
| 1774 | | // bit 1 = INT |
| 1775 | | // bit 0 = PERR |
| 1776 | | // 0xc32 = Control register (write) |
| 1777 | | // bit 7 = WEN |
| 1778 | | // bit 6 = IMSK |
| 1779 | | // bit 4 = ATN |
| 1780 | | // bit 2 = SEL |
| 1781 | | // bit 1 = DMAE |
| 1782 | | // bit 0 = RST |
| 1767 | static UINT16 towns_scsi_dma_r(running_machine* machine) |
| 1768 | { |
| 1769 | towns_state* state = machine->driver_data<towns_state>(); |
| 1770 | return state->scsi->fmscsi_data_r(); |
| 1771 | } |
| 1772 | |
| 1773 | static void towns_scsi_dma_w(running_machine* machine, UINT16 data) |
| 1774 | { |
| 1775 | towns_state* state = machine->driver_data<towns_state>(); |
| 1776 | state->scsi->fmscsi_data_w(data & 0xff); |
| 1777 | } |
| 1778 | |
| 1779 | WRITE_LINE_DEVICE_HANDLER( towns_scsi_irq ) |
| 1780 | { |
| 1781 | towns_state* tstate = device->machine->driver_data<towns_state>(); |
| 1782 | pic8259_ir0_w(tstate->pic_slave, state); |
| 1783 | if(IRQ_LOG) |
| 1784 | logerror("PIC: IRQ8 (SCSI) set to %i\n",state); |
| 1785 | } |
| 1786 | |
| 1787 | WRITE_LINE_DEVICE_HANDLER( towns_scsi_drq ) |
| 1788 | { |
| 1789 | towns_state* tstate = device->machine->driver_data<towns_state>(); |
| 1790 | upd71071_dmarq(tstate->dma_1,state,1); // SCSI HDs use channel 1 |
| 1791 | } |
| 1792 | /* |
| 1783 | 1793 | static READ8_HANDLER(towns_scsi_r) |
| 1784 | 1794 | { |
| 1785 | 1795 | towns_state* state = space->machine->driver_data<towns_state>(); |
| r9490 | r9491 | |
| 1788 | 1798 | switch(offset) |
| 1789 | 1799 | { |
| 1790 | 1800 | case 0x00: |
| 1801 | set_scsi_line(state->scsibus,SCSI_LINE_ACK,0); |
| 1791 | 1802 | return scsi_data_r(state->scsibus); |
| 1792 | 1803 | case 0x02: |
| 1793 | 1804 | ret |= (get_scsi_line(state->scsibus,SCSI_LINE_REQ)) ? 0x00 : 0x80; |
| r9490 | r9491 | |
| 1807 | 1818 | { |
| 1808 | 1819 | case 0x00: |
| 1809 | 1820 | scsi_data_w(state->scsibus,data); |
| 1810 | | set_scsi_line(state->scsibus,SCSI_LINE_ACK,0); |
| 1811 | 1821 | logerror("SCSI data write %02x\n",data); |
| 1812 | 1822 | break; |
| 1813 | 1823 | case 0x02: |
| 1814 | 1824 | set_scsi_line(state->scsibus,SCSI_LINE_SEL,data & 0x04); |
| 1825 | set_scsi_line(state->scsibus,SCSI_LINE_RESET,data & 0x01); |
| 1815 | 1826 | if(data & 0x01) |
| 1816 | | { |
| 1817 | | set_scsi_line(state->scsibus,SCSI_LINE_RESET,data & 0x01); |
| 1818 | | } |
| 1827 | init_scsibus(state->scsibus); |
| 1819 | 1828 | logerror("SCSI control write %02x\n",data); |
| 1820 | 1829 | break; |
| 1821 | 1830 | } |
| r9490 | r9491 | |
| 1860 | 1869 | } |
| 1861 | 1870 | |
| 1862 | 1871 | } |
| 1863 | | |
| 1872 | */ |
| 1864 | 1873 | // Volume ports - I/O ports 0x4e0-0x4e3 |
| 1865 | 1874 | // 0x4e0 = input volume level |
| 1866 | 1875 | // 0x4e1 = input channel select |
| r9490 | r9491 | |
| 2088 | 2097 | // Keyboard (8042 MCU) |
| 2089 | 2098 | AM_RANGE(0x0600,0x0607) AM_READWRITE8(towns_keyboard_r, towns_keyboard_w,0x00ff00ff) |
| 2090 | 2099 | // SCSI controller |
| 2091 | | AM_RANGE(0x0c30,0x0c33) AM_READWRITE8(towns_scsi_r,towns_scsi_w,0xffffffff) |
| 2100 | AM_RANGE(0x0c30,0x0c33) AM_DEVREADWRITE8_MODERN("scsi",fmscsi_device,fmscsi_r,fmscsi_w,0x00ff00ff) |
| 2092 | 2101 | // CMOS |
| 2093 | 2102 | AM_RANGE(0x3000,0x3fff) AM_READWRITE8(towns_cmos8_r, towns_cmos8_w,0x00ff00ff) |
| 2094 | 2103 | // Something (MS-DOS wants this 0x41ff to be 1) |
| r9490 | r9491 | |
| 2331 | 2340 | state->towns_cd.read_timer = timer_alloc(machine,towns_cdrom_read_byte,(void*)machine->device("dma_1")); |
| 2332 | 2341 | |
| 2333 | 2342 | cpu_set_irq_callback(machine->device("maincpu"), towns_irq_callback); |
| 2334 | | init_scsibus(machine->device("scsibus")); |
| 2335 | 2343 | } |
| 2336 | 2344 | |
| 2337 | 2345 | static DRIVER_INIT( marty ) |
| r9490 | r9491 | |
| 2354 | 2362 | state->messram = machine->device("messram"); |
| 2355 | 2363 | state->cdrom = machine->device("cdrom"); |
| 2356 | 2364 | state->cdda = machine->device("cdda"); |
| 2357 | | state->scsibus = machine->device("scsibus"); |
| 2365 | state->scsi = machine->device<fmscsi_device>("scsi"); |
| 2358 | 2366 | state->hd0 = machine->device("harddisk0"); |
| 2359 | 2367 | state->hd1 = machine->device("harddisk1"); |
| 2360 | 2368 | state->hd2 = machine->device("harddisk2"); |
| r9490 | r9491 | |
| 2443 | 2451 | static const upd71071_intf towns_dma_config = |
| 2444 | 2452 | { |
| 2445 | 2453 | "maincpu", |
| 2446 | | 1000000, |
| 2447 | | { towns_fdc_dma_r, 0, 0, towns_cdrom_dma_r }, |
| 2448 | | { towns_fdc_dma_w, 0, 0, 0 } |
| 2454 | 4000000, |
| 2455 | { towns_fdc_dma_r, towns_scsi_dma_r, 0, towns_cdrom_dma_r }, |
| 2456 | { towns_fdc_dma_w, towns_scsi_dma_w, 0, 0 } |
| 2449 | 2457 | }; |
| 2450 | 2458 | |
| 2451 | 2459 | static const ym3438_interface ym3438_intf = |
| r9490 | r9491 | |
| 2458 | 2466 | towns_pcm_irq |
| 2459 | 2467 | }; |
| 2460 | 2468 | |
| 2461 | | static const SCSIConfigTable towns_scsi_device_table = |
| 2469 | static const SCSIConfigTable towns_scsi_devtable = |
| 2462 | 2470 | { |
| 2463 | 2471 | 5, /* 5 SCSI devices */ |
| 2464 | 2472 | { |
| r9490 | r9491 | |
| 2470 | 2478 | } |
| 2471 | 2479 | }; |
| 2472 | 2480 | |
| 2473 | | static const SCSIBus_interface towns_scsi_config = |
| 2481 | static const FMSCSIinterface towns_scsi_config = |
| 2474 | 2482 | { |
| 2475 | | &towns_scsi_device_table, |
| 2476 | | &towns_scsi_linechange |
| 2483 | &towns_scsi_devtable, |
| 2484 | DEVCB_LINE(towns_scsi_irq), |
| 2485 | DEVCB_LINE(towns_scsi_drq) |
| 2477 | 2486 | }; |
| 2478 | 2487 | |
| 2479 | 2488 | static const gfx_layout fnt_chars_16x16 = |
| r9490 | r9491 | |
| 2550 | 2559 | MDRV_HARDDISK_ADD("harddisk2") |
| 2551 | 2560 | MDRV_HARDDISK_ADD("harddisk3") |
| 2552 | 2561 | MDRV_HARDDISK_ADD("harddisk4") |
| 2553 | | MDRV_SCSIBUS_ADD("scsibus",towns_scsi_config) |
| 2562 | MDRV_FMSCSI_ADD("scsi",towns_scsi_config) |
| 2554 | 2563 | |
| 2555 | 2564 | MDRV_UPD71071_ADD("dma_1",towns_dma_config) |
| 2556 | 2565 | MDRV_UPD71071_ADD("dma_2",towns_dma_config) |