src/mess/machine/wd33c93.c
| r860 | r861 | |
| 18 | 18 | typedef struct |
| 19 | 19 | { |
| 20 | 20 | void *data; // device's "this" pointer |
| 21 | | pSCSIDispatch handler; // device's handler routine |
| 21 | pSCSIDispatch handler; // device's handler routine |
| 22 | 22 | } SCSIDev; |
| 23 | 23 | |
| 24 | 24 | static SCSIDev devices[8]; // SCSI IDs 0-7 |
| 25 | 25 | static struct WD33C93interface *intf; |
| 26 | 26 | |
| 27 | | // 33c93 (aka SBIC) registers |
| 28 | | enum |
| 29 | | { |
| 30 | | SBIC_myid = 0, |
| 31 | | SBIC_cdbsize = 0, |
| 32 | | SBIC_control = 1, |
| 33 | | SBIC_timeo = 2, |
| 34 | | SBIC_cdb1 = 3, |
| 35 | | SBIC_tsecs = 3, |
| 36 | | SBIC_cdb2 = 4, |
| 37 | | SBIC_theads = 4, |
| 38 | | SBIC_cdb3 = 5, |
| 39 | | SBIC_tcyl_hi = 5, |
| 40 | | SBIC_cdb4 = 6, |
| 41 | | SBIC_tcyl_lo = 6, |
| 42 | | SBIC_cdb5 = 7, |
| 43 | | SBIC_addr_hi = 7, |
| 44 | | SBIC_cdb6 = 8, |
| 45 | | SBIC_addr_2 = 8, |
| 46 | | SBIC_cdb7 = 9, |
| 47 | | SBIC_addr_3 = 9, |
| 48 | | SBIC_cdb8 = 10, |
| 49 | | SBIC_addr_lo = 10, |
| 50 | | SBIC_cdb9 = 11, |
| 51 | | SBIC_secno = 11, |
| 52 | | SBIC_cdb10 = 12, |
| 53 | | SBIC_headno = 12, |
| 54 | | SBIC_cdb11 = 13, |
| 55 | | SBIC_cylno_hi = 13, |
| 56 | | SBIC_cdb12 = 14, |
| 57 | | SBIC_cylno_lo = 14, |
| 58 | | SBIC_tlun = 15, |
| 59 | | SBIC_cmd_phase = 16, |
| 60 | | SBIC_syn = 17, |
| 61 | | SBIC_count_hi = 18, |
| 62 | | SBIC_count_med = 19, |
| 63 | | SBIC_count_lo = 20, |
| 64 | | SBIC_selid = 21, // dest ID (33c93 is initiator) |
| 65 | | SBIC_rselid = 22, // source ID (33c93 is target) |
| 66 | | SBIC_csr = 23, // CSI status |
| 67 | | SBIC_cmd = 24, |
| 68 | | SBIC_data = 25, |
| 69 | | SBIC_queue_tag = 26, |
| 70 | | SBIC_aux_status = 27, |
| 27 | /* wd register names */ |
| 28 | #define WD_OWN_ID 0x00 |
| 29 | #define WD_CONTROL 0x01 |
| 30 | #define WD_TIMEOUT_PERIOD 0x02 |
| 31 | #define WD_CDB_1 0x03 |
| 32 | #define WD_CDB_2 0x04 |
| 33 | #define WD_CDB_3 0x05 |
| 34 | #define WD_CDB_4 0x06 |
| 35 | #define WD_CDB_5 0x07 |
| 36 | #define WD_CDB_6 0x08 |
| 37 | #define WD_CDB_7 0x09 |
| 38 | #define WD_CDB_8 0x0a |
| 39 | #define WD_CDB_9 0x0b |
| 40 | #define WD_CDB_10 0x0c |
| 41 | #define WD_CDB_11 0x0d |
| 42 | #define WD_CDB_12 0x0e |
| 43 | #define WD_TARGET_LUN 0x0f |
| 44 | #define WD_COMMAND_PHASE 0x10 |
| 45 | #define WD_SYNCHRONOUS_TRANSFER 0x11 |
| 46 | #define WD_TRANSFER_COUNT_MSB 0x12 |
| 47 | #define WD_TRANSFER_COUNT 0x13 |
| 48 | #define WD_TRANSFER_COUNT_LSB 0x14 |
| 49 | #define WD_DESTINATION_ID 0x15 |
| 50 | #define WD_SOURCE_ID 0x16 |
| 51 | #define WD_SCSI_STATUS 0x17 |
| 52 | #define WD_COMMAND 0x18 |
| 53 | #define WD_DATA 0x19 |
| 54 | #define WD_QUEUE_TAG 0x1a |
| 55 | #define WD_AUXILIARY_STATUS 0x1f |
| 71 | 56 | |
| 72 | | SBIC_num_registers |
| 73 | | }; |
| 57 | /* WD commands */ |
| 58 | #define WD_CMD_RESET 0x00 |
| 59 | #define WD_CMD_ABORT 0x01 |
| 60 | #define WD_CMD_ASSERT_ATN 0x02 |
| 61 | #define WD_CMD_NEGATE_ACK 0x03 |
| 62 | #define WD_CMD_DISCONNECT 0x04 |
| 63 | #define WD_CMD_RESELECT 0x05 |
| 64 | #define WD_CMD_SEL_ATN 0x06 |
| 65 | #define WD_CMD_SEL 0x07 |
| 66 | #define WD_CMD_SEL_ATN_XFER 0x08 |
| 67 | #define WD_CMD_SEL_XFER 0x09 |
| 68 | #define WD_CMD_RESEL_RECEIVE 0x0a |
| 69 | #define WD_CMD_RESEL_SEND 0x0b |
| 70 | #define WD_CMD_WAIT_SEL_RECEIVE 0x0c |
| 71 | #define WD_CMD_SSCC 0x0d |
| 72 | #define WD_CMD_SND_DISC 0x0e |
| 73 | #define WD_CMD_SET_IDI 0x0f |
| 74 | #define WD_CMD_RCV_CMD 0x10 |
| 75 | #define WD_CMD_RCV_DATA 0x11 |
| 76 | #define WD_CMD_RCV_MSG_OUT 0x12 |
| 77 | #define WD_CMD_RCV 0x13 |
| 78 | #define WD_CMD_SND_STATUS 0x14 |
| 79 | #define WD_CMD_SND_DATA 0x15 |
| 80 | #define WD_CMD_SND_MSG_IN 0x16 |
| 81 | #define WD_CMD_SND 0x17 |
| 82 | #define WD_CMD_TRANS_ADDR 0x18 |
| 83 | #define WD_CMD_XFER_PAD 0x19 |
| 84 | #define WD_CMD_TRANS_INFO 0x20 |
| 85 | #define WD_CMD_TRANSFER_PAD 0x21 |
| 86 | #define WD_CMD_SBT_MODE 0x80 |
| 74 | 87 | |
| 75 | | #define SBIC_MyID_Advanced (0x08) // in myid register, enable "Advanced Features" |
| 88 | /* ASR register */ |
| 89 | #define ASR_INT 0x80 |
| 90 | #define ASR_LCI 0x40 |
| 91 | #define ASR_BSY 0x20 |
| 92 | #define ASR_CIP 0x10 |
| 93 | #define ASR_PE 0x02 |
| 94 | #define ASR_DBR 0x01 |
| 76 | 95 | |
| 77 | | #define SBIC_CSR_Reset (0x00) // reset |
| 78 | | #define SBIC_CSR_Reset_Adv (0x01) // reset w/adv. features |
| 79 | | #define SBIC_CSR_Selected (0x11) // selection complete, in initiator mode |
| 80 | | #define SBIC_CSR_XferComplete (0x16) // initiator mode completed |
| 81 | | #define SBIC_CSR_MIS_2 (0x88) |
| 96 | /* SCSI Bus Phases */ |
| 97 | #define PHS_DATA_OUT 0x00 |
| 98 | #define PHS_DATA_IN 0x01 |
| 99 | #define PHS_COMMAND 0x02 |
| 100 | #define PHS_STATUS 0x03 |
| 101 | #define PHS_MESS_OUT 0x06 |
| 102 | #define PHS_MESS_IN 0x07 |
| 82 | 103 | |
| 83 | | #define SBIC_AuxStat_DBR (0x01) // data buffer ready |
| 84 | | #define SBIC_AuxStat_CIP (0x10) // command in progress, chip is busy |
| 85 | | #define SBIC_AuxStat_BSY (0x20) // Level 2 command in progress |
| 86 | | #define SBIC_AuxStat_IRQ (0x80) // IRQ pending |
| 104 | /* Command Status Register definitions */ |
| 87 | 105 | |
| 88 | | static UINT8 n33C93_RegisterSelect; |
| 89 | | static UINT8 n33C93_Data; |
| 90 | | static UINT8 n33C93_Registers[SBIC_num_registers]; |
| 91 | | static UINT8 last_id; |
| 106 | /* reset state interrupts */ |
| 107 | #define CSR_RESET 0x00 |
| 108 | #define CSR_RESET_AF 0x01 |
| 92 | 109 | |
| 93 | | static TIMER_CALLBACK(wd33c93_irq) |
| 110 | /* successful completion interrupts */ |
| 111 | #define CSR_RESELECT 0x10 |
| 112 | #define CSR_SELECT 0x11 |
| 113 | #define CSR_SEL_XFER_DONE 0x16 |
| 114 | #define CSR_XFER_DONE 0x18 |
| 115 | |
| 116 | /* paused or aborted interrupts */ |
| 117 | #define CSR_MSGIN 0x20 |
| 118 | #define CSR_SDP 0x21 |
| 119 | #define CSR_SEL_ABORT 0x22 |
| 120 | #define CSR_RESEL_ABORT 0x25 |
| 121 | #define CSR_RESEL_ABORT_AM 0x27 |
| 122 | #define CSR_ABORT 0x28 |
| 123 | |
| 124 | /* terminated interrupts */ |
| 125 | #define CSR_INVALID 0x40 |
| 126 | #define CSR_UNEXP_DISC 0x41 |
| 127 | #define CSR_TIMEOUT 0x42 |
| 128 | #define CSR_PARITY 0x43 |
| 129 | #define CSR_PARITY_ATN 0x44 |
| 130 | #define CSR_BAD_STATUS 0x45 |
| 131 | #define CSR_UNEXP 0x48 |
| 132 | |
| 133 | /* service required interrupts */ |
| 134 | #define CSR_RESEL 0x80 |
| 135 | #define CSR_RESEL_AM 0x81 |
| 136 | #define CSR_DISC 0x85 |
| 137 | #define CSR_SRV_REQ 0x88 |
| 138 | |
| 139 | /* Own ID/CDB Size register */ |
| 140 | #define OWNID_EAF 0x08 |
| 141 | #define OWNID_EHP 0x10 |
| 142 | #define OWNID_RAF 0x20 |
| 143 | #define OWNID_FS_8 0x00 |
| 144 | #define OWNID_FS_12 0x40 |
| 145 | #define OWNID_FS_16 0x80 |
| 146 | |
| 147 | /* Control register */ |
| 148 | #define CTRL_HSP 0x01 |
| 149 | #define CTRL_HA 0x02 |
| 150 | #define CTRL_IDI 0x04 |
| 151 | #define CTRL_EDI 0x08 |
| 152 | #define CTRL_HHP 0x10 |
| 153 | #define CTRL_POLLED 0x00 |
| 154 | #define CTRL_BURST 0x20 |
| 155 | #define CTRL_BUS 0x40 |
| 156 | #define CTRL_DMA 0x80 |
| 157 | |
| 158 | /* Synchronous Transfer Register */ |
| 159 | #define STR_FSS 0x80 |
| 160 | |
| 161 | /* Destination ID register */ |
| 162 | #define DSTID_DPD 0x40 |
| 163 | #define DATA_OUT_DIR 0 |
| 164 | #define DATA_IN_DIR 1 |
| 165 | #define DSTID_SCC 0x80 |
| 166 | |
| 167 | /* Source ID register */ |
| 168 | #define SRCID_MASK 0x07 |
| 169 | #define SRCID_SIV 0x08 |
| 170 | #define SRCID_DSP 0x20 |
| 171 | #define SRCID_ES 0x40 |
| 172 | #define SRCID_ER 0x80 |
| 173 | |
| 174 | /* command handler definition */ |
| 175 | typedef void (*cmd_handler)(void); |
| 176 | |
| 177 | #define TEMP_INPUT_LEN 65536 |
| 178 | #define FIFO_SIZE 12 |
| 179 | |
| 180 | /* internal controller data definition */ |
| 181 | typedef struct |
| 94 | 182 | { |
| 95 | | int cmdtype = param; |
| 183 | UINT8 sasr; |
| 184 | UINT8 regs[WD_AUXILIARY_STATUS+1]; |
| 185 | UINT8 fifo[FIFO_SIZE]; |
| 186 | int fifo_pos; |
| 187 | UINT8 *temp_input; |
| 188 | int temp_input_pos; |
| 189 | UINT8 busphase; |
| 190 | UINT8 identify; |
| 191 | mame_timer *cmd_timer; |
| 192 | } _wd33c93_data; |
| 96 | 193 | |
| 97 | | // set IRQ flag |
| 98 | | n33C93_Registers[ SBIC_aux_status ] = SBIC_AuxStat_DBR | SBIC_AuxStat_IRQ; |
| 99 | | // clear busy flags |
| 100 | | n33C93_Registers[ SBIC_aux_status ] &= ~(SBIC_AuxStat_CIP | SBIC_AuxStat_BSY); |
| 194 | /* local instance of controller data */ |
| 195 | static _wd33c93_data scsi_data; |
| 101 | 196 | |
| 102 | | // do any additional stuff required by the command |
| 103 | | // (the driver may have done platform-specific DMA during the callback, we handle that here) |
| 104 | | switch (cmdtype) |
| 105 | | { |
| 106 | | case 1: // select w/ATN and transfer |
| 107 | | n33C93_Registers[ SBIC_csr ] = SBIC_CSR_XferComplete; |
| 108 | | n33C93_Registers[ SBIC_cmd_phase ] = 0x60; // command successfully completed |
| 109 | | break; |
| 110 | 197 | |
| 111 | | case 2: // select w/ATN, no transfer |
| 112 | | n33C93_Registers[ SBIC_csr ] = SBIC_CSR_Selected; |
| 113 | | n33C93_Registers[ SBIC_cmd_phase ] = 0x10; // target selected |
| 114 | | break; |
| 198 | /* convernience functions */ |
| 199 | static UINT8 wd33c93_getunit( void ) |
| 200 | { |
| 201 | /* return the destination unit id */ |
| 202 | return scsi_data.regs[WD_DESTINATION_ID] & SRCID_MASK; |
| 203 | } |
| 115 | 204 | |
| 116 | | default: |
| 117 | | break; |
| 118 | | } |
| 205 | static void wd33c93_set_xfer_count( int count ) |
| 206 | { |
| 207 | /* set the count */ |
| 208 | scsi_data.regs[ WD_TRANSFER_COUNT_LSB ] = count & 0xff; |
| 209 | scsi_data.regs[ WD_TRANSFER_COUNT ] = ( count >> 8 ) & 0xff; |
| 210 | scsi_data.regs[ WD_TRANSFER_COUNT_MSB ] = ( count >> 16 ) & 0xff; |
| 211 | } |
| 119 | 212 | |
| 120 | | // call the driver to handle this |
| 121 | | if (intf->irq_callback) |
| 213 | static int wd33c93_get_xfer_count( void ) |
| 214 | { |
| 215 | /* get the count */ |
| 216 | int count = scsi_data.regs[ WD_TRANSFER_COUNT_MSB ]; |
| 217 | |
| 218 | count <<= 8; |
| 219 | count |= scsi_data.regs[ WD_TRANSFER_COUNT ]; |
| 220 | count <<= 8; |
| 221 | count |= scsi_data.regs[ WD_TRANSFER_COUNT_LSB ]; |
| 222 | |
| 223 | return count; |
| 224 | } |
| 225 | |
| 226 | static void wd33c93_read_data(int bytes, UINT8 *pData) |
| 227 | { |
| 228 | UINT8 unit = wd33c93_getunit(); |
| 229 | |
| 230 | if ( devices[unit].handler ) |
| 122 | 231 | { |
| 123 | | intf->irq_callback(1); |
| 232 | devices[unit].handler(SCSIOP_READ_DATA, devices[unit].data, bytes, pData); |
| 124 | 233 | } |
| 234 | else |
| 235 | { |
| 236 | logerror("wd33c93: request for unknown device SCSI ID %d\n", unit); |
| 237 | } |
| 125 | 238 | } |
| 126 | 239 | |
| 127 | | static void wd33c93_immediate_irq(void) |
| 240 | static TIMER_CALLBACK(wd33c93_complete_cb) |
| 128 | 241 | { |
| 129 | | n33C93_Registers[ SBIC_aux_status ] = SBIC_AuxStat_DBR | SBIC_AuxStat_IRQ; |
| 130 | | n33C93_Registers[ SBIC_aux_status ] &= ~(SBIC_AuxStat_CIP | SBIC_AuxStat_BSY); |
| 242 | /* reset our timer */ |
| 243 | mame_timer_reset( scsi_data.cmd_timer, time_never ); |
| 244 | |
| 245 | /* set the new status */ |
| 246 | scsi_data.regs[WD_SCSI_STATUS] = param & 0xff; |
| 247 | |
| 248 | /* set interrupt pending */ |
| 249 | scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_INT; |
| 250 | |
| 251 | /* check for error conditions */ |
| 252 | if ( wd33c93_get_xfer_count() > 0 ) |
| 253 | { |
| 254 | /* set data buffer ready */ |
| 255 | scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_DBR; |
| 256 | } |
| 257 | else |
| 258 | { |
| 259 | /* clear data buffer ready */ |
| 260 | scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_DBR; |
| 261 | } |
| 262 | |
| 263 | /* clear command in progress and bus busy */ |
| 264 | scsi_data.regs[WD_AUXILIARY_STATUS] &= ~(ASR_CIP | ASR_BSY); |
| 265 | |
| 266 | /* if we have a callback, call it */ |
| 131 | 267 | if (intf && intf->irq_callback) |
| 132 | 268 | { |
| 133 | 269 | intf->irq_callback(1); |
| 134 | 270 | } |
| 135 | 271 | } |
| 136 | 272 | |
| 137 | | WRITE8_HANDLER(wd33c93_w) |
| 273 | static TIMER_CALLBACK(wd33c93_service_request) |
| 138 | 274 | { |
| 139 | | switch( offset ) |
| 275 | /* issue a message out request */ |
| 276 | wd33c93_complete_cb(NULL,CSR_SRV_REQ | scsi_data.busphase); |
| 277 | } |
| 278 | |
| 279 | static void wd33c93_complete_cmd( UINT8 status ) |
| 280 | { |
| 281 | /* fire off a timer to complete the command */ |
| 282 | mame_timer_adjust( scsi_data.cmd_timer, MAME_TIME_IN_USEC(1), status, time_zero ); |
| 283 | } |
| 284 | |
| 285 | /* command handlers */ |
| 286 | static void wd33c93_invalid_cmd( void ) |
| 287 | { |
| 288 | logerror( "Unknown/Unimplemented SCSI controller command: %02x (PC=%x)\n", scsi_data.regs[WD_COMMAND], activecpu_get_pc() ); |
| 289 | |
| 290 | /* complete the command */ |
| 291 | wd33c93_complete_cmd( CSR_INVALID ); |
| 292 | } |
| 293 | |
| 294 | static void wd33c93_reset_cmd( void ) |
| 295 | { |
| 296 | int advanced = 0; |
| 297 | |
| 298 | /* see if it wants us to reset with advanced features */ |
| 299 | if ( scsi_data.regs[WD_OWN_ID] & OWNID_EAF ) |
| 140 | 300 | { |
| 141 | | case 0: |
| 142 | | n33C93_RegisterSelect = data; |
| 143 | | break; |
| 144 | | case 1: |
| 145 | | n33C93_Data = data; |
| 146 | | // logerror("%x to WD register %x (PC=%x)\n", data, n33C93_RegisterSelect, activecpu_get_pc()); |
| 147 | | if( n33C93_RegisterSelect <= 0x16 ) |
| 301 | advanced = 1; |
| 302 | } |
| 303 | |
| 304 | /* clear out all registers */ |
| 305 | memset( scsi_data.regs, 0, sizeof( scsi_data.regs ) ); |
| 306 | |
| 307 | /* complete the command */ |
| 308 | wd33c93_complete_cmd(advanced ? CSR_RESET_AF : CSR_RESET); |
| 309 | } |
| 310 | |
| 311 | static void wd33c93_abort_cmd( void ) |
| 312 | { |
| 313 | /* complete the command */ |
| 314 | wd33c93_complete_cmd(CSR_ABORT); |
| 315 | } |
| 316 | |
| 317 | static void wd33c93_disconnect_cmd( void ) |
| 318 | { |
| 319 | /* complete the command */ |
| 320 | scsi_data.regs[WD_AUXILIARY_STATUS] &= ~(ASR_CIP | ASR_BSY); |
| 321 | } |
| 322 | |
| 323 | static void wd33c93_select_cmd( void ) |
| 324 | { |
| 325 | UINT8 unit = wd33c93_getunit(); |
| 326 | UINT8 newstatus; |
| 327 | |
| 328 | /* see if we can select that device */ |
| 329 | if ( devices[unit].handler ) |
| 330 | { |
| 331 | /* device is available - signal selection done */ |
| 332 | newstatus = CSR_SELECT; |
| 333 | |
| 334 | /* determine the next bus phase depending on the command */ |
| 335 | if ( (scsi_data.regs[WD_COMMAND] & 0x7f) == WD_CMD_SEL_ATN ) |
| 148 | 336 | { |
| 149 | | n33C93_Registers[ n33C93_RegisterSelect ] = data; |
| 337 | /* /ATN asserted during select: Move to Message Out Phase to read identify */ |
| 338 | scsi_data.busphase = PHS_MESS_OUT; |
| 150 | 339 | } |
| 151 | | if( n33C93_RegisterSelect == SBIC_cmd ) |
| 340 | else |
| 152 | 341 | { |
| 153 | | n33C93_Registers[ SBIC_aux_status ] |= SBIC_AuxStat_CIP; |
| 342 | /* No /ATN asserted: Move to Command Phase */ |
| 343 | scsi_data.busphase = PHS_COMMAND; |
| 344 | } |
| 345 | |
| 346 | /* queue up a service request out in the future */ |
| 347 | mame_timer_set( MAME_TIME_IN_USEC(50), 0, wd33c93_service_request ); |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | /* device is not available */ |
| 352 | newstatus = CSR_TIMEOUT; |
| 353 | } |
| 354 | |
| 355 | /* complete the command */ |
| 356 | wd33c93_complete_cmd(newstatus); |
| 357 | } |
| 154 | 358 | |
| 155 | | switch( n33C93_Data ) |
| 156 | | { |
| 157 | | case 0x00: /* Reset controller */ |
| 158 | | // this clears all the registers |
| 159 | | memset(n33C93_Registers, 0, sizeof(n33C93_Registers)); |
| 359 | static void wd33c93_selectxfer_cmd( void ) |
| 360 | { |
| 361 | UINT8 unit = wd33c93_getunit(); |
| 362 | UINT8 newstatus; |
| 363 | |
| 364 | /* see if we can select that device */ |
| 365 | if ( devices[unit].handler ) |
| 366 | { |
| 367 | if ( scsi_data.regs[WD_COMMAND_PHASE] < 0x45 ) |
| 368 | { |
| 369 | /* device is available */ |
| 370 | int xfercount; |
| 371 | |
| 372 | /* do the request */ |
| 373 | xfercount = devices[unit].handler(SCSIOP_EXEC_COMMAND, devices[unit].data, 0, &scsi_data.regs[WD_CDB_1]); |
| 160 | 374 | |
| 161 | | if( n33C93_Registers[ SBIC_myid ] & SBIC_MyID_Advanced ) |
| 162 | | { |
| 163 | | n33C93_Registers[ SBIC_csr ] = SBIC_CSR_Reset_Adv; |
| 164 | | } |
| 165 | | else |
| 166 | | { |
| 167 | | n33C93_Registers[ SBIC_csr ] = SBIC_CSR_Reset; |
| 168 | | } |
| 375 | /* set transfer count */ |
| 376 | wd33c93_set_xfer_count( xfercount ); |
| 377 | |
| 378 | /* transfer over the data now */ |
| 379 | memset( scsi_data.temp_input, 0, TEMP_INPUT_LEN ); |
| 380 | wd33c93_read_data( TEMP_INPUT_LEN, &scsi_data.temp_input[0] ); |
| 381 | scsi_data.temp_input_pos = 0; |
| 382 | } |
| 383 | |
| 384 | scsi_data.regs[WD_TARGET_LUN] = 0; |
| 385 | scsi_data.regs[WD_CONTROL] |= CTRL_EDI; |
| 386 | scsi_data.regs[WD_COMMAND_PHASE] = 0x60; |
| 387 | |
| 388 | /* signal transfer ready */ |
| 389 | newstatus = CSR_SEL_XFER_DONE; |
| 390 | |
| 391 | /* if allowed disconnect, queue a service request */ |
| 392 | if ( scsi_data.identify & 0x40 ) |
| 393 | { |
| 394 | /* queue disconnect message in */ |
| 395 | scsi_data.busphase = PHS_MESS_IN; |
| 396 | |
| 397 | /* queue up a service request out in the future */ |
| 398 | mame_timer_set( MAME_TIME_IN_MSEC(50), 0, wd33c93_service_request ); |
| 399 | } |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | /* device is not available */ |
| 404 | newstatus = CSR_TIMEOUT; |
| 405 | } |
| 406 | |
| 407 | /* complete the command */ |
| 408 | wd33c93_complete_cmd(newstatus); |
| 409 | } |
| 169 | 410 | |
| 170 | | wd33c93_immediate_irq(); |
| 411 | static void wd33c93_xferinfo_cmd( void ) |
| 412 | { |
| 413 | /* make the buffer available right away */ |
| 414 | scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_DBR; |
| 415 | |
| 416 | /* the command will be completed once the data is transferred */ |
| 417 | } |
| 171 | 418 | |
| 172 | | logerror("WD: Reset controller\n"); |
| 173 | | break; |
| 174 | | case 0x01: /* Abort */ |
| 175 | | logerror("WD: Abort\n"); |
| 176 | | wd33c93_immediate_irq(); |
| 177 | | break; |
| 178 | | case 0x04: /* Disconnect */ |
| 179 | | logerror("WD: Disconnect\n"); |
| 180 | | n33C93_Registers[ SBIC_aux_status ] &= ~(SBIC_AuxStat_CIP | SBIC_AuxStat_BSY); |
| 181 | | break; |
| 182 | | case 0x06: /* Select with ATN */ |
| 183 | | logerror("WD: Select with ATN: ID %d (SCSI cmd %02x)\n", n33C93_Registers[ SBIC_selid ]&7, n33C93_Registers[3]); |
| 419 | /* Command handlers */ |
| 420 | static cmd_handler wd33c93_cmds[0x22] = |
| 421 | { |
| 422 | &wd33c93_reset_cmd, /* 0x00 - WD_CMD_RESET */ |
| 423 | &wd33c93_abort_cmd, /* 0x01 - WD_CMD_ABORT */ |
| 424 | &wd33c93_invalid_cmd, /* 0x02 - WD_CMD_ASSERT_ATN (uninmplemented) */ |
| 425 | &wd33c93_invalid_cmd, /* 0x03 - WD_CMD_NEGATE_ACK (uninmplemented) */ |
| 426 | &wd33c93_disconnect_cmd,/* 0x04 - WD_CMD_DISCONNECT */ |
| 427 | &wd33c93_invalid_cmd, /* 0x05 - WD_CMD_RESELECT (uninmplemented) */ |
| 428 | &wd33c93_select_cmd, /* 0x06 - WD_CMD_SEL_ATN */ |
| 429 | &wd33c93_select_cmd, /* 0x07 - WD_CMD_SEL */ |
| 430 | &wd33c93_selectxfer_cmd,/* 0x08 - WD_CMD_SEL_ATN_XFER */ |
| 431 | &wd33c93_selectxfer_cmd,/* 0x09 - WD_CMD_SEL_XFER */ |
| 432 | &wd33c93_invalid_cmd, /* 0x0a - WD_CMD_RESEL_RECEIVE (uninmplemented) */ |
| 433 | &wd33c93_invalid_cmd, /* 0x0b - WD_CMD_RESEL_SEND (uninmplemented) */ |
| 434 | &wd33c93_invalid_cmd, /* 0x0c - WD_CMD_WAIT_SEL_RECEIVE (uninmplemented) */ |
| 435 | &wd33c93_invalid_cmd, /* 0x0d - WD_CMD_SSCC (uninmplemented) */ |
| 436 | &wd33c93_invalid_cmd, /* 0x0e - WD_CMD_SND_DISC (uninmplemented) */ |
| 437 | &wd33c93_invalid_cmd, /* 0x0f - WD_CMD_SET_IDI (uninmplemented) */ |
| 438 | &wd33c93_invalid_cmd, /* 0x10 - WD_CMD_RCV_CMD (uninmplemented) */ |
| 439 | &wd33c93_invalid_cmd, /* 0x11 - WD_CMD_RCV_DATA (uninmplemented) */ |
| 440 | &wd33c93_invalid_cmd, /* 0x12 - WD_CMD_RCV_MSG_OUT (uninmplemented) */ |
| 441 | &wd33c93_invalid_cmd, /* 0x13 - WD_CMD_RCV (uninmplemented) */ |
| 442 | &wd33c93_invalid_cmd, /* 0x14 - WD_CMD_SND_STATUS (uninmplemented) */ |
| 443 | &wd33c93_invalid_cmd, /* 0x15 - WD_CMD_SND_DATA (uninmplemented) */ |
| 444 | &wd33c93_invalid_cmd, /* 0x16 - WD_CMD_SND_MSG_IN (uninmplemented) */ |
| 445 | &wd33c93_invalid_cmd, /* 0x17 - WD_CMD_SND (uninmplemented) */ |
| 446 | &wd33c93_invalid_cmd, /* 0x18 - WD_CMD_TRANS_ADDR (uninmplemented) */ |
| 447 | &wd33c93_invalid_cmd, /* 0x19 - WD_CMD_XFER_PAD (uninmplemented) */ |
| 448 | &wd33c93_invalid_cmd, /* 0x1a - invalid */ |
| 449 | &wd33c93_invalid_cmd, /* 0x1b - invalid */ |
| 450 | &wd33c93_invalid_cmd, /* 0x1c - invalid */ |
| 451 | &wd33c93_invalid_cmd, /* 0x1d - invalid */ |
| 452 | &wd33c93_invalid_cmd, /* 0x1e - invalid */ |
| 453 | &wd33c93_invalid_cmd, /* 0x1f - invalid */ |
| 454 | &wd33c93_xferinfo_cmd, /* 0x20 - WD_CMD_TRANS_INFO) */ |
| 455 | &wd33c93_invalid_cmd /* 0x21 - WD_CMD_TRANSFER_PAD (uninmplemented) */ |
| 456 | }; |
| 184 | 457 | |
| 185 | | last_id = n33C93_Registers[ SBIC_selid ] & 7; |
| 458 | /* Handle pending commands */ |
| 459 | static void wd33c93_command( void ) |
| 460 | { |
| 461 | /* get the command */ |
| 462 | UINT8 cmd = scsi_data.regs[WD_COMMAND]; |
| 463 | |
| 464 | /* check if its within valid bounds */ |
| 465 | if ( (cmd & 0x7F) > WD_CMD_TRANSFER_PAD ) |
| 466 | { |
| 467 | wd33c93_invalid_cmd(); |
| 468 | return; |
| 469 | } |
| 470 | |
| 471 | /* call the command handler */ |
| 472 | (*wd33c93_cmds[cmd & 0x7F])(); |
| 473 | } |
| 186 | 474 | |
| 187 | | // we don't support this at this time |
| 188 | | n33C93_Registers[ SBIC_csr ] = 0x42; // SEL_TimeOut |
| 189 | | n33C93_Registers[ SBIC_cmd_phase ] = 0x00; // no device selected |
| 475 | WRITE8_HANDLER(wd33c93_w) |
| 476 | { |
| 477 | switch( offset ) |
| 478 | { |
| 479 | case 0: |
| 480 | { |
| 481 | /* update register select */ |
| 482 | scsi_data.sasr = data & 0x1f; |
| 483 | } |
| 484 | break; |
| 190 | 485 | |
| 191 | | wd33c93_clear_dma(); // no DMA |
| 486 | case 1: |
| 487 | { |
| 488 | logerror( "WD33C93: PC=%08x - Write REG=%02x, data = %02x\n", safe_activecpu_get_pc(), scsi_data.sasr, data ); |
| 489 | |
| 490 | /* update the register */ |
| 491 | scsi_data.regs[scsi_data.sasr] = data; |
| 192 | 492 | |
| 193 | | wd33c93_immediate_irq(); |
| 194 | | break; |
| 195 | | case 0x08: /* Select with ATN and transfer */ |
| 196 | | logerror("WD: Select with ATN and transfer: ID %d (SCSI cmd %02x)\n", n33C93_Registers[ SBIC_selid ]&7, n33C93_Registers[3]); |
| 493 | /* if we receive a command, schedule to process it */ |
| 494 | if ( scsi_data.sasr == WD_COMMAND ) |
| 495 | { |
| 496 | logerror( "WDC33C93: PC=%08x - Executing command %08x - unit %d\n", safe_activecpu_get_pc(), data, wd33c93_getunit() ); |
| 497 | |
| 498 | /* signal we're processing it */ |
| 499 | scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_CIP; |
| 197 | 500 | |
| 198 | | last_id = n33C93_Registers[ SBIC_selid ] & 7; |
| 199 | | |
| 200 | | if (devices[last_id].handler) |
| 501 | /* process the command */ |
| 502 | wd33c93_command(); |
| 503 | } |
| 504 | else if ( scsi_data.sasr == WD_CDB_1 ) |
| 505 | { |
| 506 | scsi_data.regs[WD_COMMAND_PHASE] = 0; |
| 507 | } |
| 508 | else if ( scsi_data.sasr == WD_DATA ) |
| 509 | { |
| 510 | /* if data was written, and we have a count, send to device */ |
| 511 | int count = wd33c93_get_xfer_count(); |
| 512 | |
| 513 | if ( scsi_data.regs[WD_COMMAND] & 0x80 ) |
| 514 | count = 1; |
| 515 | |
| 516 | if ( count-- > 0 ) |
| 201 | 517 | { |
| 202 | | int xfercount; |
| 203 | | |
| 204 | | xfercount = devices[last_id].handler(SCSIOP_EXEC_COMMAND, devices[last_id].data, 0, &n33C93_Registers[3]); |
| 205 | | |
| 206 | | n33C93_Registers[ SBIC_count_lo ] = xfercount & 0xff; |
| 207 | | n33C93_Registers[ SBIC_count_med ] = (xfercount>>8) & 0xff; |
| 208 | | n33C93_Registers[ SBIC_count_hi ] = (xfercount>>16) & 0xff; |
| 209 | | |
| 210 | | n33C93_Registers[ SBIC_rselid ] |= n33C93_Registers[ SBIC_selid ] & 7; |
| 211 | | |
| 212 | | mame_timer_set( MAME_TIME_IN_HZ( 16384 ), 1, wd33c93_irq ); |
| 518 | /* write to FIFO */ |
| 519 | if ( scsi_data.fifo_pos < FIFO_SIZE ) |
| 520 | { |
| 521 | scsi_data.fifo[scsi_data.fifo_pos++] = data; |
| 522 | } |
| 523 | |
| 524 | /* update count */ |
| 525 | wd33c93_set_xfer_count( count ); |
| 526 | |
| 527 | /* if we're done with the write, see where we're at */ |
| 528 | if ( count == 0 ) |
| 529 | { |
| 530 | scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_INT; |
| 531 | scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_DBR; |
| 532 | |
| 533 | switch( scsi_data.busphase ) |
| 534 | { |
| 535 | case PHS_MESS_OUT: |
| 536 | { |
| 537 | /* reset fifo */ |
| 538 | scsi_data.fifo_pos = 0; |
| 539 | |
| 540 | /* Message out phase. Data is probably SCSI Identify. Move to command phase. */ |
| 541 | scsi_data.busphase = PHS_COMMAND; |
| 542 | |
| 543 | scsi_data.identify = scsi_data.fifo[0]; |
| 544 | } |
| 545 | break; |
| 546 | |
| 547 | case PHS_COMMAND: |
| 548 | { |
| 549 | UINT8 unit = wd33c93_getunit(); |
| 550 | int xfercount; |
| 551 | |
| 552 | /* Execute the command. Depending on the command, we'll move to data in or out */ |
| 553 | xfercount = devices[unit].handler(SCSIOP_EXEC_COMMAND, devices[unit].data, 0, &scsi_data.fifo[0]); |
| 554 | |
| 555 | /* reset fifo */ |
| 556 | scsi_data.fifo_pos = 0; |
| 557 | |
| 558 | /* set the new count */ |
| 559 | wd33c93_set_xfer_count( xfercount ); |
| 560 | |
| 561 | /* update bus phase */ |
| 562 | if ( scsi_data.fifo[0] == 0x15 || scsi_data.fifo[0] == 0x55 ) /* MODE SELECT */ |
| 563 | { |
| 564 | scsi_data.busphase = PHS_DATA_OUT; |
| 565 | } |
| 566 | else |
| 567 | { |
| 568 | scsi_data.busphase = PHS_DATA_IN; |
| 569 | |
| 570 | /* load up all the response data now */ |
| 571 | memset( scsi_data.temp_input, 0, TEMP_INPUT_LEN ); |
| 572 | wd33c93_read_data( TEMP_INPUT_LEN, &scsi_data.temp_input[0] ); |
| 573 | scsi_data.temp_input_pos = 0; |
| 574 | } |
| 575 | } |
| 576 | break; |
| 577 | |
| 578 | case PHS_DATA_OUT: |
| 579 | { |
| 580 | /* write data out to device */ |
| 581 | wd33c93_write_data( scsi_data.fifo_pos, scsi_data.fifo ); |
| 582 | |
| 583 | /* reset fifo */ |
| 584 | scsi_data.fifo_pos = 0; |
| 585 | |
| 586 | /* move to status phase */ |
| 587 | scsi_data.busphase = PHS_STATUS; |
| 588 | } |
| 589 | break; |
| 590 | } |
| 591 | |
| 592 | /* complete the command */ |
| 593 | wd33c93_complete_cmd(CSR_XFER_DONE | scsi_data.busphase); |
| 594 | } |
| 213 | 595 | } |
| 214 | 596 | else |
| 215 | 597 | { |
| 216 | | n33C93_Registers[ SBIC_csr ] = 0x42; // SEL_TimeOut |
| 217 | | n33C93_Registers[ SBIC_cmd_phase ] = 0x00; // no device selected |
| 218 | | |
| 219 | | wd33c93_clear_dma(); // no DMA |
| 220 | | |
| 221 | | wd33c93_immediate_irq(); |
| 598 | logerror( "WD33C93: Sending data to device with transfer count = 0!. Ignoring...\n" ); |
| 222 | 599 | } |
| 223 | | break; |
| 224 | | default: |
| 225 | | logerror( "Unknown SCSI controller command: %02x (PC=%x)\n", n33C93_Data, activecpu_get_pc() ); |
| 226 | | break; |
| 227 | 600 | } |
| 601 | |
| 602 | /* auto-increment register select if not on special registers */ |
| 603 | if ( scsi_data.sasr != WD_COMMAND && scsi_data.sasr != WD_DATA && scsi_data.sasr != WD_AUXILIARY_STATUS ) |
| 604 | { |
| 605 | scsi_data.sasr = ( scsi_data.sasr + 1 ) & 0x1f; |
| 606 | } |
| 228 | 607 | } |
| 229 | | else if ( n33C93_RegisterSelect == SBIC_data) |
| 608 | break; |
| 609 | |
| 610 | default: |
| 230 | 611 | { |
| 231 | | // logerror("Write %02x to SBIC data (PC=%x)\n", n33C93_Data, activecpu_get_pc()); |
| 612 | logerror( "WD33C93: Write to invalid offset %d (data=%02x)\n", offset, data ); |
| 232 | 613 | } |
| 233 | | |
| 234 | | n33C93_RegisterSelect++; |
| 235 | 614 | break; |
| 236 | | default: |
| 237 | | // logerror("ERROR: unk 33c93 W offset %d\n", offset); |
| 238 | | break; |
| 239 | 615 | } |
| 240 | 616 | } |
| 241 | 617 | |
| 242 | 618 | READ8_HANDLER(wd33c93_r) |
| 243 | 619 | { |
| 244 | | UINT8 rv = 0; |
| 245 | | |
| 246 | 620 | switch( offset ) |
| 247 | 621 | { |
| 248 | | case 0: |
| 249 | | // if (activecpu_get_pc() != 0xbfc167d8) |
| 250 | | // logerror("Read WD aux status = %x (PC=%x)\n", n33C93_Registers[ SBIC_aux_status ], activecpu_get_pc()); |
| 251 | | rv = n33C93_Registers[ SBIC_aux_status ]; |
| 622 | case 0: |
| 623 | { |
| 624 | /* read aux status */ |
| 625 | return scsi_data.regs[WD_AUXILIARY_STATUS]; |
| 626 | } |
| 252 | 627 | break; |
| 253 | | case 1: |
| 254 | | // logerror("Read WD register %x = %x (PC=%x)\n", n33C93_RegisterSelect, n33C93_Registers[ n33C93_RegisterSelect ], activecpu_get_pc()); |
| 255 | | |
| 256 | | // ack IRQ on status read |
| 257 | | if (n33C93_RegisterSelect == SBIC_csr) |
| 628 | |
| 629 | case 1: |
| 258 | 630 | { |
| 259 | | n33C93_Registers[ SBIC_aux_status ] &= ~SBIC_AuxStat_IRQ; |
| 260 | | if (intf && intf->irq_callback) |
| 631 | UINT8 ret; |
| 632 | |
| 633 | /* if reading status, clear irq flag */ |
| 634 | if ( scsi_data.sasr == WD_SCSI_STATUS ) |
| 261 | 635 | { |
| 262 | | intf->irq_callback(1); |
| 636 | scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_INT; |
| 637 | |
| 638 | if (intf && intf->irq_callback) |
| 639 | { |
| 640 | intf->irq_callback(0); |
| 641 | } |
| 642 | |
| 643 | logerror( "WD33C93: PC=%08x - Status read (%02x)\n", safe_activecpu_get_pc(), scsi_data.regs[WD_SCSI_STATUS] ); |
| 263 | 644 | } |
| 645 | else if ( scsi_data.sasr == WD_DATA ) |
| 646 | { |
| 647 | /* we're going to be doing synchronous reads */ |
| 648 | |
| 649 | /* get the transfer count */ |
| 650 | int count = wd33c93_get_xfer_count(); |
| 651 | |
| 652 | if ( count <= 0 && scsi_data.busphase == PHS_MESS_IN ) |
| 653 | { |
| 654 | scsi_data.regs[WD_DATA] = 0x00; |
| 655 | |
| 656 | /* move to disconnect */ |
| 657 | wd33c93_complete_cmd(CSR_DISC); |
| 658 | } |
| 659 | else |
| 660 | { |
| 661 | /* make sure we still have data to send */ |
| 662 | if ( count-- > 0 ) |
| 663 | { |
| 664 | scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_INT; |
| 665 | |
| 666 | /* read in one byte */ |
| 667 | if ( scsi_data.temp_input_pos < TEMP_INPUT_LEN ) |
| 668 | scsi_data.regs[WD_DATA] = scsi_data.temp_input[scsi_data.temp_input_pos++]; |
| 669 | |
| 670 | /* update the count */ |
| 671 | wd33c93_set_xfer_count( count ); |
| 672 | |
| 673 | /* transfer finished, see where we're at */ |
| 674 | if ( count == 0 ) |
| 675 | { |
| 676 | if ( scsi_data.regs[WD_COMMAND_PHASE] != 0x60 ) |
| 677 | { |
| 678 | /* move to status phase */ |
| 679 | scsi_data.busphase = PHS_STATUS; |
| 680 | |
| 681 | /* complete the command */ |
| 682 | wd33c93_complete_cmd(CSR_XFER_DONE | scsi_data.busphase); |
| 683 | } |
| 684 | else |
| 685 | { |
| 686 | scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_INT; |
| 687 | scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_DBR; |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | else |
| 692 | { |
| 693 | scsi_data.regs[WD_DATA] = 0; |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | /* get the register value */ |
| 699 | ret = scsi_data.regs[scsi_data.sasr]; |
| 700 | |
| 701 | /* auto-increment register select if not on special registers */ |
| 702 | if ( scsi_data.sasr != WD_COMMAND && scsi_data.sasr != WD_DATA && scsi_data.sasr != WD_AUXILIARY_STATUS ) |
| 703 | { |
| 704 | scsi_data.sasr = ( scsi_data.sasr + 1 ) & 0x1f; |
| 705 | } |
| 706 | |
| 707 | return ret; |
| 264 | 708 | } |
| 265 | | |
| 266 | | rv = n33C93_Registers[ n33C93_RegisterSelect ]; |
| 267 | | n33C93_RegisterSelect++; |
| 709 | |
| 710 | default: |
| 711 | { |
| 712 | logerror( "WD33C93: Read from invalid offset %d\n", offset ); |
| 713 | } |
| 268 | 714 | break; |
| 269 | | default: |
| 270 | | // logerror("ERROR: unk 33c93 R offset %d\n", offset); |
| 271 | | break; |
| 272 | 715 | } |
| 273 | 716 | |
| 274 | | return rv; |
| 717 | return 0; |
| 275 | 718 | } |
| 276 | 719 | |
| 277 | 720 | extern void wd33c93_init( struct WD33C93interface *interface ) |
| r860 | r861 | |
| 281 | 724 | // save interface pointer for later |
| 282 | 725 | intf = interface; |
| 283 | 726 | |
| 284 | | memset(n33C93_Registers, 0, sizeof(n33C93_Registers)); |
| 727 | memset(&scsi_data, 0, sizeof(scsi_data)); |
| 285 | 728 | memset(devices, 0, sizeof(devices)); |
| 286 | | n33C93_RegisterSelect = 0; |
| 287 | 729 | |
| 288 | 730 | // try to open the devices |
| 289 | 731 | for (i = 0; i < interface->scsidevs->devs_present; i++) |
| 290 | 732 | { |
| 291 | 733 | devices[interface->scsidevs->devices[i].scsiID].handler = interface->scsidevs->devices[i].handler; |
| 292 | 734 | interface->scsidevs->devices[i].handler(SCSIOP_ALLOC_INSTANCE, &devices[interface->scsidevs->devices[i].scsiID].data, interface->scsidevs->devices[i].diskID, (UINT8 *)NULL); |
| 293 | | } |
| 735 | } |
| 736 | |
| 737 | /* allocate a timer for commands */ |
| 738 | scsi_data.cmd_timer = mame_timer_alloc(wd33c93_complete_cb); |
| 739 | |
| 740 | scsi_data.temp_input = auto_malloc( TEMP_INPUT_LEN ); |
| 294 | 741 | |
| 295 | | state_save_register_item_array("wd33c93", 0, n33C93_Registers); |
| 296 | | state_save_register_item("wd33c93", 0, n33C93_RegisterSelect); |
| 742 | // state_save_register_item_array("wd33c93", 0, scsi_data); |
| 297 | 743 | } |
| 298 | 744 | |
| 299 | | void wd33c93_read_data(int bytes, UINT8 *pData) |
| 745 | void wd33c93_get_dma_data( int bytes, UINT8 *pData ) |
| 300 | 746 | { |
| 301 | | if (devices[last_id].handler) |
| 747 | int len = bytes; |
| 748 | |
| 749 | if ( len > wd33c93_get_xfer_count() ) |
| 750 | len = wd33c93_get_xfer_count(); |
| 751 | |
| 752 | if ( len == 0 ) |
| 753 | return; |
| 754 | |
| 755 | if ( (scsi_data.temp_input_pos+len) >= TEMP_INPUT_LEN ) |
| 302 | 756 | { |
| 303 | | devices[last_id].handler(SCSIOP_READ_DATA, devices[last_id].data, bytes, pData); |
| 757 | logerror( "Reading past end of buffer, increase TEMP_INPUT_LEN size\n" ); |
| 758 | len = TEMP_INPUT_LEN - len; |
| 304 | 759 | } |
| 305 | | else |
| 306 | | { |
| 307 | | logerror("wd33c93: request for unknown device SCSI ID %d\n", last_id); |
| 308 | | } |
| 760 | |
| 761 | memcpy( pData, &scsi_data.temp_input[scsi_data.temp_input_pos], len ); |
| 762 | scsi_data.temp_input_pos += len; |
| 763 | len = wd33c93_get_xfer_count() - len; |
| 764 | wd33c93_set_xfer_count(len); |
| 309 | 765 | } |
| 310 | 766 | |
| 311 | 767 | void wd33c93_write_data(int bytes, UINT8 *pData) |
| 312 | 768 | { |
| 313 | | if (devices[last_id].handler) |
| 769 | UINT8 unit = wd33c93_getunit(); |
| 770 | |
| 771 | if (devices[unit].handler) |
| 314 | 772 | { |
| 315 | | devices[last_id].handler(SCSIOP_WRITE_DATA, devices[last_id].data, bytes, pData); |
| 773 | devices[unit].handler(SCSIOP_WRITE_DATA, devices[unit].data, bytes, pData); |
| 316 | 774 | } |
| 317 | 775 | else |
| 318 | 776 | { |
| 319 | | logerror("wd33c93: request for unknown device SCSI ID %d\n", last_id); |
| 777 | logerror("wd33c93: request for unknown device SCSI ID %d\n", unit); |
| 320 | 778 | } |
| 321 | 779 | } |
| 322 | 780 | |
| r860 | r861 | |
| 336 | 794 | |
| 337 | 795 | void wd33c93_clear_dma(void) |
| 338 | 796 | { |
| 339 | | // indicate DMA completed by clearing the transfer count |
| 340 | | n33C93_Registers[ SBIC_count_lo ] = 0; |
| 341 | | n33C93_Registers[ SBIC_count_med ] = 0; |
| 342 | | n33C93_Registers[ SBIC_count_hi ] = 0; |
| 797 | /* indicate DMA completed by clearing the transfer count */ |
| 798 | wd33c93_set_xfer_count(0); |
| 799 | scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_DBR; |
| 343 | 800 | } |
| 344 | 801 | |
| 345 | 802 | int wd33c93_get_dma_count(void) |
| 346 | 803 | { |
| 347 | | return n33C93_Registers[ SBIC_count_lo ] | n33C93_Registers[ SBIC_count_med ]<<8 | n33C93_Registers[ SBIC_count_hi ]<<16; |
| 804 | return wd33c93_get_xfer_count(); |
| 348 | 805 | } |