src/mess/machine/scsibus.c
| r7073 | r7074 | |
| 12 | 12 | |
| 13 | 13 | /* LOGLEVEL 0=no logging, 1=just commands and data, 2=everything ! */
|
| 14 | 14 | |
| 15 | | #define LOGLEVEL 0
|
| 15 | #define LOGLEVEL 1
|
| 16 | 16 | |
| 17 | 17 | #define LOG(level,...) if(LOGLEVEL>=level) logerror(__VA_ARGS__)
|
| 18 | 18 | |
| r7073 | r7074 | |
| 24 | 24 | |
| 25 | 25 | UINT8 linestate;
|
| 26 | 26 | UINT8 last_id;
|
| 27 | UINT8 phase;
|
| 28 | |
| 27 | 29 | UINT8 command[CMD_BUF_SIZE];
|
| 28 | | UINT8 data[DATA_BUF_SIZE];
|
| 29 | 30 | UINT8 cmd_idx;
|
| 31 | UINT8 is_linked;
|
| 32 | |
| 33 | UINT8 data[DATA_BUF_SIZE+RW_BUFFER_HEAD_BYTES];
|
| 30 | 34 | UINT16 data_idx;
|
| 31 | 35 | int xfer_count;
|
| 32 | 36 | int bytes_left;
|
| 33 | | UINT8 phase;
|
| 34 | | UINT8 is_linked;
|
| 37 | int data_last;
|
| 35 | 38 | |
| 36 | 39 | emu_timer *req_timer;
|
| 37 | 40 | emu_timer *ack_timer;
|
| 38 | 41 | |
| 39 | | UINT8 timer_flag;
|
| 40 | | |
| 41 | | running_machine *machine;
|
| 42 | | |
| 43 | 42 | UINT8 initialised;
|
| 44 | 43 | };
|
| 45 | 44 | |
| r7073 | r7074 | |
| 71 | 70 | |
| 72 | 71 | static void scsibus_read_data(scsibus_t *bus)
|
| 73 | 72 | { |
| 74 | | if(bus->bytes_left >= DATA_BUF_SIZE)
|
| 73 | bus->data_last = (bus->bytes_left >= DATA_BUF_SIZE) ? DATA_BUF_SIZE : bus->bytes_left;
|
| 74 | |
| 75 | logerror("SCSIBUS:scsibus_read_data bus->bytes_left=%04X, bus->data_last=%04X, bus->xfer_count=%04X\n",bus->bytes_left,bus->data_last,bus->xfer_count);
|
| 76 | |
| 77 | if (bus->data_last > 0)
|
| 75 | 78 | {
|
| 76 | | SCSIReadData(bus->devices[bus->last_id], bus->data, DATA_BUF_SIZE);
|
| 77 | | |
| 78 | | bus->bytes_left-=DATA_BUF_SIZE;
|
| 79 | SCSIReadData(bus->devices[bus->last_id], bus->data, bus->data_last);
|
| 80 | bus->bytes_left-=bus->data_last;
|
| 79 | 81 | bus->data_idx=0;
|
| 80 | | }
|
| 82 | }
|
| 81 | 83 | }
|
| 82 | 84 | |
| 83 | 85 | static void scsibus_write_data(scsibus_t *bus)
|
| r7073 | r7074 | |
| 103 | 105 | case SCSI_PHASE_DATAIN : |
| 104 | 106 | result=bus->data[bus->data_idx++];
|
| 105 | 107 | |
| 108 | if (bus->command[0]==0x37) logerror("SCSIBUS:scsi_data_r: data_idx=%04X, bytes_left=%04X, data_last=%04X\n",bus->data_idx,bus->bytes_left,bus->data_last);
|
| 106 | 109 | // check to see if we have reached the end of the block buffer
|
| 107 | 110 | // and that there is more data to read from the scsi disk
|
| 108 | | if((bus->data_idx==DATA_BUF_SIZE) && (bus->bytes_left>0))
|
| 111 | if((bus->data_idx==DATA_BUF_SIZE) && (bus->bytes_left>0) && IS_READ_COMMAND())
|
| 109 | 112 | {
|
| 110 | 113 | scsibus_read_data(bus);
|
| 111 | 114 | }
|
| r7073 | r7074 | |
| 143 | 146 | break;
|
| 144 | 147 | |
| 145 | 148 | case SCSI_PHASE_DATAOUT :
|
| 146 | | bus->data[bus->data_idx++]=data;
|
| 149 | |
| 150 | //LOG(1,"SCSIBUS:xfer_count=%02X, bytes_left=%02X data_idx=%02X\n",bus->xfer_count,bus->bytes_left,bus->data_idx);
|
| 151 | |
| 152 | // Write (blocks) and write buffer, just buffer it
|
| 153 | if(IS_WRITE_COMMAND() || IS_COMMAND(SCSI_CMD_BUFFER_WRITE) || IS_COMMAND(SCSI_CMD_MODE_SELECT))
|
| 154 | bus->data[bus->data_idx++]=data;
|
| 155 | |
| 156 | if(IS_COMMAND(SCSI_CMD_FORMAT_UNIT))
|
| 157 | {
|
| 158 | // Only store the first 4 bytes of the bad block list (the header)
|
| 159 | if(bus->data_idx<4)
|
| 160 | bus->data[bus->data_idx++]=data;
|
| 161 | else
|
| 162 | bus->data_idx++;
|
| 163 | |
| 164 | // When we have the first 3 bytes, calculate how many more are in the |
| 165 | // bad block list.
|
| 166 | if(bus->data_idx==3)
|
| 167 | {
|
| 168 | bus->xfer_count+=((bus->data[2]<<8)+bus->data[3]);
|
| 169 | bus->data_last=bus->xfer_count;
|
| 170 | }
|
| 171 | }
|
| 147 | 172 | |
| 148 | | // If the data buffer is full, flush it to the SCSI disk
|
| 149 | | if(bus->data_idx == DATA_BUF_SIZE)
|
| 173 | // If the data buffer is full, and we are writing blocks flush it to the SCSI disk
|
| 174 | if((bus->data_idx == DATA_BUF_SIZE) && IS_WRITE_COMMAND())
|
| 150 | 175 | scsibus_write_data(bus);
|
| 151 | 176 | break;
|
| 152 | 177 | }
|
| r7073 | r7074 | |
| 224 | 249 | {
|
| 225 | 250 | int byteno;
|
| 226 | 251 | |
| 227 | | logerror("sending command %0X to ScsiID %d\n",bus->command[0],bus->last_id);
|
| 252 | logerror("sending command 0x%02X to ScsiID %d\n",bus->command[0],bus->last_id);
|
| 228 | 253 | |
| 229 | 254 | for(byteno=0; byteno<bus->cmd_idx; byteno++)
|
| 230 | 255 | {
|
| r7073 | r7074 | |
| 233 | 258 | logerror("\n\n");
|
| 234 | 259 | }
|
| 235 | 260 | |
| 236 | | static void scsi_in_line_changed(const device_config *device, UINT8 line, UINT8 state)
|
| 261 | static void scsibus_exec_command(const device_config *device)
|
| 237 | 262 | {
|
| 238 | 263 | scsibus_t *bus = get_token(device);
|
| 264 | int command_local = 0;
|
| 239 | 265 | int newphase;
|
| 240 | 266 | |
| 267 | dump_command_bytes(bus);
|
| 268 | bus->is_linked=bus->command[bus->cmd_idx-1] & 0x01;
|
| 269 | |
| 270 | // Check for locally executed commands, and if found execute them
|
| 271 | switch (bus->command[0])
|
| 272 | {
|
| 273 | // Format unit
|
| 274 | case SCSI_CMD_FORMAT_UNIT :
|
| 275 | logerror("SCSIBUS: format unit bus->command[1]=%02X & 0x10\n",(bus->command[1] & 0x10));
|
| 276 | command_local=1;
|
| 277 | if((bus->command[1] & 0x10)==0x10)
|
| 278 | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAOUT);
|
| 279 | else
|
| 280 | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_STATUS);
|
| 281 | |
| 282 | bus->xfer_count=4;
|
| 283 | bus->data_last=bus->xfer_count;
|
| 284 | bus->bytes_left=0;
|
| 285 | break;
|
| 286 | |
| 287 | case SCSI_CMD_READ_DEFECT :
|
| 288 | logerror("SCSIBUS: read defect list\n");
|
| 289 | command_local=1;
|
| 290 | |
| 291 | bus->data[0] = 0x00;
|
| 292 | bus->data[1] = bus->command[2];
|
| 293 | bus->data[3] = 0x00; // defect list len msb
|
| 294 | bus->data[4] = 0x00; // defect list len lsb
|
| 295 | |
| 296 | bus->xfer_count=4;
|
| 297 | bus->data_last=bus->xfer_count;
|
| 298 | bus->bytes_left=0;
|
| 299 | SCSISetPhase(bus->devices[bus->last_id], SCSI_PHASE_DATAIN );
|
| 300 | break;
|
| 301 | |
| 302 | // write buffer |
| 303 | case SCSI_CMD_BUFFER_WRITE :
|
| 304 | logerror("SCSIBUS: write_buffer\n");
|
| 305 | command_local=1;
|
| 306 | bus->xfer_count=(bus->command[7]<<8)+bus->command[8];
|
| 307 | bus->data_last=bus->xfer_count;
|
| 308 | bus->bytes_left=0;
|
| 309 | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAOUT);
|
| 310 | break;
|
| 311 | |
| 312 | // read buffer
|
| 313 | case SCSI_CMD_BUFFER_READ :
|
| 314 | logerror("SCSIBUS: read_buffer\n");
|
| 315 | command_local=1;
|
| 316 | bus->xfer_count=(bus->command[7]<<8)+bus->command[8];
|
| 317 | bus->data_last=bus->xfer_count;
|
| 318 | bus->bytes_left=0;
|
| 319 | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAIN);
|
| 320 | break;
|
| 321 | }
|
| 322 | |
| 323 | |
| 324 | // Check for locally executed command, if not then pass it on
|
| 325 | // to the disk driver
|
| 326 | if(!command_local)
|
| 327 | {
|
| 328 | SCSISetCommand(bus->devices[bus->last_id], bus->command, bus->cmd_idx);
|
| 329 | SCSIExecCommand(bus->devices[bus->last_id], &bus->xfer_count);
|
| 330 | bus->bytes_left=bus->xfer_count;
|
| 331 | bus->data_last=bus->xfer_count;
|
| 332 | bus->data_idx=0;
|
| 333 | }
|
| 334 | |
| 335 | SCSIGetPhase(bus->devices[bus->last_id], &newphase);
|
| 336 | |
| 337 | scsi_change_phase(device,newphase);
|
| 338 | |
| 339 | LOG(1,"SCSIBUS:xfer_count=%02X, bytes_left=%02X data_idx=%02X\n",bus->xfer_count,bus->bytes_left,bus->data_idx);
|
| 340 | |
| 341 | // This is correct as we need to read from disk for commands other than just read data
|
| 342 | if ((bus->phase == SCSI_PHASE_DATAIN) && (!command_local))
|
| 343 | scsibus_read_data(bus);
|
| 344 | }
|
| 345 | |
| 346 | static int datain_done(scsibus_t *bus)
|
| 347 | {
|
| 348 | int result=0;
|
| 349 | |
| 350 | // Read data commands
|
| 351 | if(IS_READ_COMMAND() && (bus->data_idx == bus->data_last) && (bus->bytes_left == 0)) |
| 352 | result=1;
|
| 353 | else if (bus->data_idx==bus->data_last)
|
| 354 | result=1;
|
| 355 | |
| 356 | return result; |
| 357 | }
|
| 358 | |
| 359 | static int dataout_done(scsibus_t *bus)
|
| 360 | {
|
| 361 | int result=0;
|
| 362 | |
| 363 | // Write data commands
|
| 364 | if(IS_WRITE_COMMAND() && (bus->data_idx == 0) && (bus->bytes_left == 0)) |
| 365 | result=1;
|
| 366 | else if (bus->data_idx==bus->data_last)
|
| 367 | result=1;
|
| 368 | |
| 369 | return result;
|
| 370 | }
|
| 371 | |
| 372 | static void scsi_in_line_changed(const device_config *device, UINT8 line, UINT8 state)
|
| 373 | {
|
| 374 | scsibus_t *bus = get_token(device);
|
| 375 | |
| 241 | 376 | // Reset aborts and returns to bus free
|
| 242 | 377 | if((line==SCSI_LINE_RESET) && (state==0))
|
| 243 | 378 | {
|
| r7073 | r7074 | |
| 269 | 404 | // If the command is ready go and execute it
|
| 270 | 405 | if(bus->cmd_idx==get_scsi_cmd_len(bus->command[0]))
|
| 271 | 406 | {
|
| 272 | | dump_command_bytes(bus);
|
| 273 | | bus->is_linked=bus->command[bus->cmd_idx-1] & 0x01;
|
| 274 | | SCSISetCommand(bus->devices[bus->last_id], bus->command, bus->cmd_idx);
|
| 275 | | SCSIExecCommand(bus->devices[bus->last_id], &bus->xfer_count);
|
| 276 | | SCSIGetPhase(bus->devices[bus->last_id], &newphase);
|
| 277 | | |
| 278 | | scsi_change_phase(device,newphase);
|
| 279 | | |
| 280 | | bus->bytes_left=bus->xfer_count;
|
| 281 | | bus->data_idx=0;
|
| 282 | | |
| 283 | | if (bus->phase == SCSI_PHASE_DATAIN)
|
| 284 | | scsibus_read_data(bus);
|
| 407 | scsibus_exec_command(device);
|
| 285 | 408 | }
|
| 286 | 409 | else
|
| 287 | 410 | scsi_out_line_change(device,SCSI_LINE_REQ,0);
|
| r7073 | r7074 | |
| 296 | 419 | {
|
| 297 | 420 | if(state)
|
| 298 | 421 | {
|
| 299 | | if((bus->data_idx == DATA_BUF_SIZE-1) && (bus->bytes_left == 0))
|
| 422 | if(datain_done(bus))
|
| 300 | 423 | scsi_change_phase(device,SCSI_PHASE_STATUS);
|
| 301 | 424 | else
|
| 302 | 425 | scsi_out_line_change(device,SCSI_LINE_REQ,0);
|
| r7073 | r7074 | |
| 311 | 434 | {
|
| 312 | 435 | if(state)
|
| 313 | 436 | {
|
| 314 | | if((bus->data_idx == 0) && (bus->bytes_left == 0))
|
| 437 | if(dataout_done(bus))
|
| 315 | 438 | scsi_change_phase(device,SCSI_PHASE_STATUS);
|
| 316 | 439 | else
|
| 317 | 440 | scsi_out_line_change(device,SCSI_LINE_REQ,0);
|
| r7073 | r7074 | |
| 546 | 669 | // Setup req/ack timers |
| 547 | 670 | bus->req_timer=timer_alloc(device->machine, req_timer_callback, (void *)device);
|
| 548 | 671 | bus->ack_timer=timer_alloc(device->machine, ack_timer_callback, (void *)device);
|
| 549 | | |
| 550 | | //timer_adjust_periodic(bus->reqack_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(1));
|
| 551 | | |
| 552 | | bus->machine=device->machine;
|
| 553 | 672 | }
|
| 554 | 673 | |
| 555 | 674 | static DEVICE_STOP( scsibus )
|
src/mess/machine/rmnimbus.c
| r7073 | r7074 | |
| 37 | 37 | #define LATCH_INTS 1 |
| 38 | 38 | #define LOG_PORTS 0 |
| 39 | 39 | #define LOG_INTERRUPTS 0 |
| 40 | | #define LOG_INTERRUPTS_EXT 1 |
| 40 | #define LOG_INTERRUPTS_EXT |
| 41 | 41 | #define LOG_TIMER 0 |
| 42 | 42 | #define LOG_OPTIMIZATION 0 |
| 43 | | #define LOG_DMA 1 |
| 43 | #define LOG_DMA |
| 44 | 44 | #define CPU_RESUME_TRIGGER 7123 |
| 45 | 45 | #define LOG_KEYBOARD 0 |
| 46 | 46 | #define LOG_SIO 0 |
| 47 | 47 | #define LOG_DISK_FDD 0 |
| 48 | | #define LOG_DISK_HDD 1 |
| 49 | | #define LOG_DISK 1 |
| 48 | #define LOG_DISK_HDD 0 |
| 49 | #define LOG_DISK 0 |
| 50 | 50 | #define LOG_PC8031 0 |
| 51 | 51 | #define LOG_PC8031_186 0 |
| 52 | 52 | #define LOG_PC8031_PORT 0 |
| r7073 | r7074 | |
| 717 | 717 | /* otherwise, set a timer */ |
| 718 | 718 | else |
| 719 | 719 | { |
| 720 | | if (LOG_DMA) logerror("Initiated DMA %d - count = %04X, source = %04X, dest = %04X\n", which, d->count, d->source, d->dest); |
| 721 | | |
| 722 | 720 | d->finished = 0; |
| 723 | 721 | } |
| 724 | 722 | } |
| 725 | 723 | |
| 724 | if (LOG_DMA) logerror("Initiated DMA %d - count = %04X, source = %04X, dest = %04X\n", which, d->count, d->source, d->dest); |
| 725 | |
| 726 | 726 | /* set the new control register */ |
| 727 | 727 | d->control = new_control; |
| 728 | 728 | } |
| r7073 | r7074 | |
| 2163 | 2163 | |
| 2164 | 2164 | if((nimbus_drives.reg410_in & HDC_REQ_MASK)==0) |
| 2165 | 2165 | set_scsi_line(hdc,SCSI_LINE_ACK,0); |
| 2166 | |
| 2167 | nimbus_drives.drq_ff=0; |
| 2166 | 2168 | } |
| 2167 | 2169 | |
| 2168 | 2170 | static void hdc_drq(running_machine *machine) |
| r7073 | r7074 | |
| 2170 | 2172 | if(HDC_DRQ_ENABLED() && nimbus_drives.drq_ff) |
| 2171 | 2173 | { |
| 2172 | 2174 | drq_callback(machine,1); |
| 2173 | | nimbus_drives.drq_ff=0; |
| 2174 | 2175 | } |
| 2175 | 2176 | } |
| 2176 | 2177 | |
| 2177 | 2178 | void nimbus_scsi_linechange(const device_config *device, UINT8 line, UINT8 state) |
| 2178 | 2179 | { |
| 2179 | 2180 | UINT8 mask = 0; |
| 2181 | UINT8 last = 0; |
| 2180 | 2182 | |
| 2181 | 2183 | switch (line) |
| 2182 | 2184 | { |
| r7073 | r7074 | |
| 2187 | 2189 | case SCSI_LINE_MSG : mask=HDC_MSG_MASK; break; |
| 2188 | 2190 | } |
| 2189 | 2191 | |
| 2192 | last=nimbus_drives.reg410_in & mask; |
| 2193 | |
| 2190 | 2194 | if(state) |
| 2191 | 2195 | nimbus_drives.reg410_in|=mask; |
| 2192 | 2196 | else |
| r7073 | r7074 | |
| 2202 | 2206 | if(HDC_IRQ_ENABLED() && ((~nimbus_drives.reg410_in & HDC_INT_TRIGGER)==HDC_INT_TRIGGER)) |
| 2203 | 2207 | generate_disk_int(device->machine); |
| 2204 | 2208 | |
| 2205 | | if((nimbus_drives.reg410_in & HDC_CD_MASK)==HDC_CD_MASK) |
| 2209 | if(((nimbus_drives.reg410_in & HDC_CD_MASK)==HDC_CD_MASK) && (last!=0)) |
| 2206 | 2210 | { |
| 2207 | 2211 | nimbus_drives.drq_ff=1; |
| 2208 | 2212 | hdc_drq(device->machine); |