From b5ae4a8876c8c057c432ff0ecbaa9e108c03dfe2 Mon Sep 17 00:00:00 2001 From: Joakim Larsson Edstrom Date: Thu, 26 Sep 2019 13:51:13 +0200 Subject: [PATCH] i8251.cpp: modernized debug printouts --- src/devices/machine/i8251.cpp | 96 +++++++++++++++-------------------- 1 file changed, 40 insertions(+), 56 deletions(-) diff --git a/src/devices/machine/i8251.cpp b/src/devices/machine/i8251.cpp index 1712796e64d..5c1638acffd 100644 --- a/src/devices/machine/i8251.cpp +++ b/src/devices/machine/i8251.cpp @@ -23,9 +23,20 @@ To Do: #include "emu.h" #include "i8251.h" -//#define VERBOSE 1 +#define LOG_STAT (1U << 1) +#define LOG_COM (1U << 2) +#define LOG_MODE (1U << 3) +#define LOG_BITS (1U << 4) + +//#define VERBOSE (LOG_BITS|LOG_GENERAL) +//#define LOG_OUTPUT_STREAM std::cout + #include "logmacro.h" +#define LOGSTAT(...) LOGMASKED(LOG_STAT, __VA_ARGS__) +#define LOGCOM(...) LOGMASKED(LOG_COM, __VA_ARGS__) +#define LOGMODE(...) LOGMASKED(LOG_MODE, __VA_ARGS__) +#define LOGBITS(...) LOGMASKED(LOG_BITS, __VA_ARGS__) //************************************************************************** // DEVICE DEFINITIONS @@ -153,6 +164,7 @@ void i8251_device::receive_clock() //logerror("I8251\n"); /* get bit received from other side and update receive register */ + //LOGBITS("8251: Rx Sampled %d\n", m_rxd); receive_register_update_bit(m_rxd); if (is_receive_register_synchronized()) m_rxc_count = sync ? m_br_factor : (3 * m_br_factor / 2); @@ -316,7 +328,9 @@ bool i8251_device::is_tx_enabled() const void i8251_device::check_for_tx_start() { if (is_tx_enabled() && (m_status & (I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY)) == I8251_STATUS_TX_EMPTY) + { start_tx(); + } } /*------------------------------------------------- @@ -357,6 +371,7 @@ void i8251_device::transmit_clock() if (!is_transmit_register_empty()) { uint8_t data = transmit_register_get_data_bit(); + LOGBITS("8251: Tx Present a %d\n", data); m_txd_handler(data); } } @@ -454,6 +469,7 @@ void i8251_device::device_reset() /* no character to read by cpu */ /* transmitter is ready and is empty */ m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; + LOGSTAT("status is reset to %02x\n", m_status); m_mode_byte = 0; m_command = 0; m_rx_data = 0; @@ -478,67 +494,26 @@ void i8251_device::device_reset() void i8251_device::command_w(uint8_t data) { /* command */ - LOG("I8251: Command byte\n"); - m_command = data; - LOG("Command byte: %02x\n", data); - - if (BIT(data, 7)) - LOG("hunt mode\n"); - - if (BIT(data, 5)) - LOG("/rts set to 0\n"); - else - LOG("/rts set to 1\n"); - - if (BIT(data, 2)) - LOG("receive enable\n"); - else - LOG("receive disable\n"); - - if (BIT(data, 1)) - LOG("/dtr set to 0\n"); - else - LOG("/dtr set to 1\n"); - - if (BIT(data, 0)) - LOG("transmit enable\n"); - else - LOG("transmit disable\n"); - - - /* bit 7: - 0 = normal operation - 1 = hunt mode - bit 6: - 0 = normal operation - 1 = internal reset - bit 5: - 0 = /RTS set to 1 - 1 = /RTS set to 0 - bit 4: - 0 = normal operation - 1 = reset error flag - bit 3: - 0 = normal operation - 1 = send break character - bit 2: - 0 = receive disable - 1 = receive enable - bit 1: - 0 = /DTR set to 1 - 1 = /DTR set to 0 - bit 0: - 0 = transmit disable - 1 = transmit enable - */ + LOG("I8251: Command byte: %02x\n", data); + LOGCOM(" Tx enable: %d\n", data & 0x01 ? 1 : 0); // bit 0: 0 = transmit disable 1 = transmit enable + LOGCOM(" DTR : %d\n", data & 0x02 ? 1 : 0); // bit 1: 0 = /DTR set to 1 1 = /DTR set to 0 + LOGCOM(" Rx enable: %d\n", data & 0x04 ? 1 : 0); // bit 2: 0 = receive disable 1 = receive enable + LOGCOM(" Send BRK : %d\n", data & 0x08 ? 1 : 0); // bit 3: 0 = normal operation 1 = send break character + LOGCOM(" Err reset: %d\n", data & 0x10 ? 1 : 0); // bit 4: 0 = normal operation 1 = reset error flag + LOGCOM(" RTS : %d\n", data & 0x20 ? 1 : 0); // bit 5: 0 = /RTS set to 1 1 = /RTS set to 0 + LOGCOM(" Reset : %d\n", data & 0x40 ? 1 : 0); // bit 6: 0 = normal operation 1 = internal reset + LOGCOM(" Hunt mode: %d\n", data & 0x80 ? 1 : 0); // bit 7: 0 = normal operation 1 = hunt mode m_rts_handler(!BIT(data, 5)); m_dtr_handler(!BIT(data, 1)); if (BIT(data, 4)) + { + LOGSTAT("status errors are reset\n"); m_status &= ~(I8251_STATUS_PARITY_ERROR | I8251_STATUS_OVERRUN_ERROR | I8251_STATUS_FRAMING_ERROR); + } if (BIT(data, 6)) { @@ -596,7 +571,6 @@ void i8251_device::mode_w(uint8_t data) 3 = x64 Synchronous - bit 7: Number of sync characters 0 = 1 character 1 = 2 character @@ -746,6 +720,7 @@ uint8_t i8251_device::status_r() // Syndet always goes off after status read update_syndet(false); + return status; } @@ -763,6 +738,7 @@ void i8251_device::data_w(uint8_t data) /* writing clears */ m_status &=~I8251_STATUS_TX_READY; + LOGSTAT("8251: status cleared TX_READY by data_w\n"); update_tx_ready(); // Store state of tx enable when writing to DB buffer @@ -788,11 +764,17 @@ void i8251_device::receive_character(uint8_t ch) m_rx_data = ch; + LOGSTAT("status RX READY test %02x\n", m_status); /* char has not been read and another has arrived! */ if (m_status & I8251_STATUS_RX_READY) + { m_status |= I8251_STATUS_OVERRUN_ERROR; + LOGSTAT("status overrun set\n"); + } + LOGSTAT("status pre RX READY set %02x\n", m_status); m_status |= I8251_STATUS_RX_READY; + LOGSTAT("status post RX READY set %02x\n", m_status); update_rx_ready(); } @@ -810,6 +792,7 @@ uint8_t i8251_device::data_r() if (!machine().side_effects_disabled()) { m_status &= ~I8251_STATUS_RX_READY; + LOGSTAT("status RX_READY cleared\n"); update_rx_ready(); } return m_rx_data; @@ -836,7 +819,8 @@ void i8251_device::write(offs_t offset, uint8_t data) WRITE_LINE_MEMBER(i8251_device::write_rxd) { m_rxd = state; -// device_serial_interface::rx_w(state); + LOGBITS("8251: Presented a %d\n", m_rxd); + // device_serial_interface::rx_w(state); } WRITE_LINE_MEMBER(i8251_device::write_cts)