diff options
Diffstat (limited to 'src/devices/machine/ncr539x.cpp')
-rw-r--r-- | src/devices/machine/ncr539x.cpp | 132 |
1 files changed, 38 insertions, 94 deletions
diff --git a/src/devices/machine/ncr539x.cpp b/src/devices/machine/ncr539x.cpp index ac7cfcd7698..eedc81e2d05 100644 --- a/src/devices/machine/ncr539x.cpp +++ b/src/devices/machine/ncr539x.cpp @@ -13,8 +13,14 @@ #include "emu.h" #include "ncr539x.h" -#define VERBOSE (0) -#define VERBOSE_READS (0) +#define LOG_GENERAL (1U << 0) +#define LOG_READS (1U << 1) + +//#define VERBOSE (LOG_GENERAL | LOG_READS) +//#define LOG_OUTPUT_FUNC printf +#include "logmacro.h" + +#define LOGREADS(...) LOGMASKED(LOG_READS, __VA_ARGS__) enum { @@ -50,8 +56,6 @@ enum #define CR2_GENERATE_REGISTER_PARITY 0x02 #define CR2_GENERATE_DATA_PARITY 0x01 -#if VERBOSE -#if VERBOSE_READS static const char *rdregs[16] = { "Transfer count LSB", // 0 "Transfer count MSB", // 1 @@ -70,7 +74,6 @@ static const char *rdregs[16] = { "Transfer count HSB/Chip ID", "0xF" }; -#endif static const char *wrregs[16] = { "Start Transfer count LSB", @@ -90,7 +93,6 @@ static const char *wrregs[16] = { "Start Transfer count HSB", "Data Alignment" }; -#endif // get the length of a SCSI command based on its command byte type static int get_cmd_len(int cbyte) @@ -110,14 +112,14 @@ static int get_cmd_len(int cbyte) // LIVE DEVICE //************************************************************************** -const device_type NCR539X = device_creator<ncr539x_device>; +DEFINE_DEVICE_TYPE(NCR539X, ncr539x_device, "ncr539x", "NCR/AMD 5394/5396 SCSI") //------------------------------------------------- // ncr539x_device - constructor/destructor //------------------------------------------------- ncr539x_device::ncr539x_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : - legacy_scsi_host_adapter(mconfig, NCR539X, "539x SCSI", tag, owner, clock, "ncr539x", __FILE__), + legacy_scsi_host_adapter(mconfig, NCR539X, tag, owner, clock), m_out_irq_cb(*this), m_out_drq_cb(*this) { @@ -199,9 +201,7 @@ void ncr539x_device::device_timer(emu_timer &timer, device_timer_id tid, int par m_fifo_ptr = 0; m_selected = true; - #if VERBOSE - printf("Selecting w/o ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); - #endif + LOG("Selecting w/o ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); // if DMA is not enabled, there should already be a command loaded into the FIFO if (!(m_command & 0x80)) @@ -212,9 +212,7 @@ void ncr539x_device::device_timer(emu_timer &timer, device_timer_id tid, int par } else { - #if VERBOSE - printf("Select failed, no device @ ID %d!\n", m_last_id); - #endif + LOG("Select failed, no device @ ID %d!\n", m_last_id); m_status |= MAIN_STATUS_INTERRUPT; m_irq_status |= IRQ_STATUS_DISCONNECTED; } @@ -230,9 +228,7 @@ void ncr539x_device::device_timer(emu_timer &timer, device_timer_id tid, int par m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND; m_fifo_ptr = 0; m_selected = true; - #if VERBOSE - printf("Selecting with ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); - #endif + LOG("Selecting with ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); // if DMA is not enabled, there should already be a command loaded into the FIFO if (!(m_command & 0x80)) @@ -243,9 +239,7 @@ void ncr539x_device::device_timer(emu_timer &timer, device_timer_id tid, int par } else { - #if VERBOSE - printf("Select failed, no device @ ID %d!\n", m_last_id); - #endif + LOG("Select failed, no device @ ID %d!\n", m_last_id); m_status |= MAIN_STATUS_INTERRUPT; m_irq_status |= IRQ_STATUS_DISCONNECTED; } @@ -253,9 +247,7 @@ void ncr539x_device::device_timer(emu_timer &timer, device_timer_id tid, int par break; case 0x11: // initiator command complete - #if VERBOSE - printf("Initiator command complete\n"); - #endif + LOG("Initiator command complete\n"); m_irq_status = IRQ_STATUS_SERVICE_REQUEST; m_status &= ~7; // clear phase bits m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_DATAIN; // go to data in phase (?) @@ -272,9 +264,7 @@ void ncr539x_device::device_timer(emu_timer &timer, device_timer_id tid, int par break; case 0x12: // message accepted - #if VERBOSE - printf("Message accepted\n"); - #endif + LOG("Message accepted\n"); m_irq_status = IRQ_STATUS_SERVICE_REQUEST; m_status |= MAIN_STATUS_INTERRUPT; m_out_irq_cb(ASSERT_LINE); @@ -294,11 +284,7 @@ READ8_MEMBER( ncr539x_device::read ) { uint8_t rv = 0; - #if VERBOSE - #if VERBOSE_READS - printf("539x: Read @ %s (%02x) (PC=%x) (status %02x irq_status %02x)\n", rdregs[offset], offset, space.device().safe_pc(), m_status, m_irq_status); - #endif - #endif + LOGREADS("539x: Read @ %s (%02x) (PC=%x) (status %02x irq_status %02x)\n", rdregs[offset], offset, space.device().safe_pc(), m_status, m_irq_status); switch (offset) { @@ -327,9 +313,7 @@ READ8_MEMBER( ncr539x_device::read ) m_xfer_count--; update_fifo_internal_state(fifo_bytes); - #if VERBOSE - printf("Read %02x from FIFO[%d], FIFO now contains %d bytes (PC=%x, m_buffer_remaining %x)\n", rv, m_fifo_read_ptr-1, fifo_bytes, space.device().safe_pc(), m_buffer_remaining); - #endif + LOG("Read %02x from FIFO[%d], FIFO now contains %d bytes (PC=%x, m_buffer_remaining %x)\n", rv, m_fifo_read_ptr-1, fifo_bytes, space.device().safe_pc(), m_buffer_remaining); if (fifo_bytes == 0) { @@ -348,15 +332,11 @@ READ8_MEMBER( ncr539x_device::read ) m_buffer_remaining -= fifo_fill_size; m_fifo_ptr = 0; update_fifo_internal_state(fifo_fill_size); - #if VERBOSE - printf("Refreshing FIFO (%x remaining from transfer, %x in buffer, %x in total)\n", m_xfer_count, m_buffer_remaining, m_total_data); - #endif + LOG("Refreshing FIFO (%x remaining from transfer, %x in buffer, %x in total)\n", m_xfer_count, m_buffer_remaining, m_total_data); } else { - #if VERBOSE - printf("FIFO empty, asserting service request (buffer_remaining %x)\n", m_buffer_remaining); - #endif + LOG("FIFO empty, asserting service request (buffer_remaining %x)\n", m_buffer_remaining); m_irq_status = IRQ_STATUS_SERVICE_REQUEST; m_status &= 0x7; // clear everything but the phase bits m_status |= MAIN_STATUS_INTERRUPT | MAIN_STATUS_COUNT_TO_ZERO; @@ -365,9 +345,7 @@ READ8_MEMBER( ncr539x_device::read ) // if no data at all, drop the phase if ((m_buffer_remaining + m_total_data) == 0) { - #if VERBOSE - printf("Out of data, setting phase STATUS\n"); - #endif + LOG("Out of data, setting phase STATUS\n"); m_status &= ~0x7; m_status |= SCSI_PHASE_STATUS; } @@ -436,10 +414,8 @@ READ8_MEMBER( ncr539x_device::read ) WRITE8_MEMBER( ncr539x_device::write ) { - #if VERBOSE //if (offset != 2) - printf("539x: Write %02x @ %s (%02x) (PC=%x)\n", data, wrregs[offset], offset, space.device().safe_pc()); - #endif + LOG("539x: Write %02x @ %s (%02x) (PC=%x)\n", data, wrregs[offset], offset, space.device().safe_pc()); switch (offset) { @@ -509,9 +485,7 @@ WRITE8_MEMBER( ncr539x_device::write ) int phase; phase = get_phase(); - #if VERBOSE - printf("Information transfer: phase %d buffer remaining %x\n", phase, m_buffer_remaining); - #endif + LOG("Information transfer: phase %d buffer remaining %x\n", phase, m_buffer_remaining); if (phase == SCSI_PHASE_DATAIN) // target -> initiator transfer { @@ -525,9 +499,7 @@ WRITE8_MEMBER( ncr539x_device::write ) amtToGet = m_total_data; } - #if VERBOSE - printf("amtToGet = %x\n", amtToGet); - #endif + LOG("amtToGet = %x\n", amtToGet); if (amtToGet > 0) { @@ -554,9 +526,7 @@ WRITE8_MEMBER( ncr539x_device::write ) fifo_fill_size = m_dma_size; } - #if VERBOSE - printf("filling FIFO from buffer[%x] for %x bytes\n", m_buffer_offset, fifo_fill_size); - #endif + LOG("filling FIFO from buffer[%x] for %x bytes\n", m_buffer_offset, fifo_fill_size); memcpy(m_fifo, &m_buffer[m_buffer_offset], fifo_fill_size); m_buffer_offset += fifo_fill_size; @@ -570,9 +540,7 @@ WRITE8_MEMBER( ncr539x_device::write ) m_status |= MAIN_STATUS_COUNT_TO_ZERO; - #if VERBOSE - printf("Information transfer: put %02x bytes into FIFO (dma size %x) (buffer remaining %x)\n", m_fifo_internal_state & 0x1f, m_dma_size, m_buffer_remaining); - #endif + LOG("Information transfer: put %02x bytes into FIFO (dma size %x) (buffer remaining %x)\n", m_fifo_internal_state & 0x1f, m_dma_size, m_buffer_remaining); } else if (phase == SCSI_PHASE_DATAOUT) { @@ -581,9 +549,7 @@ WRITE8_MEMBER( ncr539x_device::write ) { m_xfer_count = 0x10000; } - #if VERBOSE - printf("dma_size %x, xfer_count %x\n", m_dma_size, m_xfer_count); - #endif + LOG("dma_size %x, xfer_count %x\n", m_dma_size, m_xfer_count); m_status &= ~MAIN_STATUS_COUNT_TO_ZERO; m_fifo_ptr = 0; m_buffer_offset = 0; @@ -593,9 +559,7 @@ WRITE8_MEMBER( ncr539x_device::write ) break; case 0x24: // Terminate steps - #if VERBOSE - printf("Terminate steps\n"); - #endif + LOG("Terminate steps\n"); m_irq_status = IRQ_STATUS_SUCCESS | IRQ_STATUS_DISCONNECTED; m_status |= MAIN_STATUS_INTERRUPT; m_out_irq_cb(ASSERT_LINE); @@ -604,18 +568,14 @@ WRITE8_MEMBER( ncr539x_device::write ) break; case 0x27: // Disconnect - #if VERBOSE - printf("Disconnect\n"); - #endif + LOG("Disconnect\n"); m_irq_status = IRQ_STATUS_SUCCESS; m_status |= MAIN_STATUS_INTERRUPT; m_out_irq_cb(ASSERT_LINE); break; case 0x44: // Enable selection/reselection - #if VERBOSE - printf("Enable selection/reselection\n"); - #endif + LOG("Enable selection/reselection\n"); m_irq_status = IRQ_STATUS_SUCCESS; m_status |= MAIN_STATUS_INTERRUPT; m_out_irq_cb(ASSERT_LINE); @@ -630,9 +590,7 @@ WRITE8_MEMBER( ncr539x_device::write ) m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND; m_fifo_ptr = 0; m_selected = true; - #if VERBOSE - printf("Reselecting with ATN3, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); - #endif + LOG("Reselecting with ATN3, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); // if DMA is not enabled, there should already be a command loaded into the FIFO if (!(m_command & 0x80)) @@ -643,9 +601,7 @@ WRITE8_MEMBER( ncr539x_device::write ) } else { - #if VERBOSE - printf("Reselect with ATN3 failed, no device @ ID %d!\n", m_last_id); - #endif + LOG("Reselect with ATN3 failed, no device @ ID %d!\n", m_last_id); m_status |= MAIN_STATUS_INTERRUPT; m_irq_status |= IRQ_STATUS_DISCONNECTED; } @@ -653,9 +609,7 @@ WRITE8_MEMBER( ncr539x_device::write ) break; default: // other commands are not instantaneous - #if VERBOSE - printf("Setting timer for command %02x\n", data); - #endif + LOG("Setting timer for command %02x\n", data); // 1x commands happen much faster if ((m_command & 0x70) == 0x10) { @@ -733,9 +687,7 @@ void ncr539x_device::exec_fifo() length = get_length(); phase = get_phase(); - #if VERBOSE - printf("Command executed (id %d), new phase %d, length %x\n", m_last_id, phase, length); - #endif + LOG("Command executed (id %d), new phase %d, length %x\n", m_last_id, phase, length); m_buffer_offset = m_buffer_size; m_buffer_remaining = 0; @@ -759,9 +711,7 @@ void ncr539x_device::fifo_write(uint8_t data) if (phase != SCSI_PHASE_DATAOUT) { - #if VERBOSE - printf("539x: Write %02x @ FIFO[%x]\n", data, m_fifo_ptr); - #endif + LOG("539x: Write %02x @ FIFO[%x]\n", data, m_fifo_ptr); m_fifo[m_fifo_ptr++] = data; update_fifo_internal_state(m_fifo_ptr); @@ -775,9 +725,7 @@ void ncr539x_device::fifo_write(uint8_t data) m_buffer[m_buffer_offset++] = data; m_xfer_count--; m_total_data--; - #if VERBOSE - printf("539x: Write %02x @ buffer[%x], xfer_count %x, total %x\n", data, m_buffer_offset-1, m_xfer_count, m_total_data); - #endif + LOG("539x: Write %02x @ buffer[%x], xfer_count %x, total %x\n", data, m_buffer_offset-1, m_xfer_count, m_total_data); // default to flushing our entire buffer int flush_size = m_buffer_size; @@ -790,9 +738,7 @@ void ncr539x_device::fifo_write(uint8_t data) if ((m_buffer_offset == flush_size) || (m_xfer_count == 0)) { - #if VERBOSE - printf("Flushing buffer to device, %x bytes left in buffer (%x total)\n", m_xfer_count, m_total_data); - #endif + LOG("Flushing buffer to device, %x bytes left in buffer (%x total)\n", m_xfer_count, m_total_data); write_data(m_buffer, flush_size); m_buffer_offset = 0; @@ -805,9 +751,7 @@ void ncr539x_device::fifo_write(uint8_t data) if ((m_xfer_count == 0) && (m_total_data == 0)) { - #if VERBOSE - printf("End of write, asserting service request\n"); - #endif + LOG("End of write, asserting service request\n"); m_buffer_offset = 0; m_irq_status = IRQ_STATUS_SERVICE_REQUEST; |