From f52220573019182df7e2e55435ab11131f43a50a Mon Sep 17 00:00:00 2001 From: Michael Zapf Date: Sat, 9 Jul 2022 22:55:17 +0200 Subject: ti99: Improved TIPI stability in communication with real Raspberry Pis --- src/devices/bus/ti99/peb/tipi.cpp | 53 ++++++++++++++++++++++++--------------- src/devices/bus/ti99/peb/tipi.h | 2 ++ 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/devices/bus/ti99/peb/tipi.cpp b/src/devices/bus/ti99/peb/tipi.cpp index 0c08299ace3..92f45710d33 100644 --- a/src/devices/bus/ti99/peb/tipi.cpp +++ b/src/devices/bus/ti99/peb/tipi.cpp @@ -80,12 +80,12 @@ #define LOG_EPROM (1U<<2) #define LOG_CRU (1U<<3) #define LOG_PORTS (1U<<4) -#define LOG_CONFIG (1U<<5) -#define LOG_RPI (1U<<6) -#define LOG_QUEUE (1U<<7) -#define LOG_PROT (1U<<8) +#define LOG_RPI (1U<<5) +#define LOG_QUEUE (1U<<6) +#define LOG_PROT (1U<<7) +#define LOG_DETAIL (1U<<8) -#define VERBOSE ( LOG_GENERAL | LOG_WARN | LOG_CONFIG ) +#define VERBOSE ( LOG_GENERAL | LOG_WARN ) #define RASPI "rpi" #include "logmacro.h" @@ -103,6 +103,7 @@ tipi_card_device::tipi_card_device(const machine_config &mconfig, const char *ta m_dsr(false), m_portaccess(false), m_waitinit(false), + m_syncmode(true), m_rpiconn(false), m_tc(0), m_rd(0), @@ -263,7 +264,11 @@ void tipi_card_device::cruwrite(offs_t offset, uint8_t data) break; case 1: LOGMASKED(LOG_CRU, "CRU Bit 1 %s\n", (data!=0)? "on" : "off"); - if (data != 0) send("RESET"); + if (data != 0) + { + LOGMASKED(LOG_RPI, "Sending RESET\n"); + send("RESET"); + } break; default: LOGMASKED(LOG_CRU, "Unknown CRU Bit %d\n", bit); @@ -274,7 +279,7 @@ void tipi_card_device::cruwrite(offs_t offset, uint8_t data) void tipi_card_device::send(const char* message) { - if (m_rpiconn) + if (m_rpiconn && m_connected) { *m_send_stream << message; m_wsclient->send(m_send_stream); @@ -283,11 +288,11 @@ void tipi_card_device::send(const char* message) void tipi_card_device::send(u8* message, int len) { - if (m_rpiconn) + if (m_rpiconn && m_connected) { for (int i=0; i < len; i++) { - LOGMASKED(LOG_RPI, "Sending byte %02x\n", message[i]); + LOGMASKED(LOG_DETAIL, "Sending byte %02x\n", message[i]); *m_send_stream << message[i]; } m_wsclient->send(m_send_stream, nullptr, 130); // binary (10000010) @@ -462,25 +467,36 @@ void tipi_card_device::websocket_opened() LOG("Connection established\n"); m_connected = true; m_rc = 0; - if (m_waitinit) m_slot->set_ready(ASSERT_LINE); } void tipi_card_device::websocket_incoming(std::shared_ptr message) { + // Caution: Message is an istream, so the string method consumes the Message + // Size is not changed, nor is fin_rsv_opcode + std::string msg; + switch (message->fin_rsv_opcode & 0x0f) { case 1: + msg = message->string(); // Text message is "RD=xxx" or "RC=xxx" with xxx=decimal number - LOGMASKED(LOG_RPI, "Got text message: %s\n", message->string()); - if (message->string().find("RD=")==0) + + LOGMASKED(LOG_RPI, "Got text message: %s\n", msg); + + if (msg.find("RD=")==0) { m_indqueue.push(std::stoi(message->string().substr(3))); } - if (message->string().find("RC=")==0) + if (msg.find("RC=")==0) { m_rc = std::stoi(message->string().substr(3)); } + if (msg.find("ASYNC")==0) + { + LOG("TIPI server offers ASYNC communication\n"); + m_syncmode = false; + } break; case 2: @@ -575,11 +591,13 @@ void tipi_card_device::device_reset() { m_cru_base = (ioport("SW1")->read()) << 8; m_waitinit = (ioport("WAIT")->read()!=0); - m_syncmode = (ioport("MODE")->read()!=0); + m_syncmode = true; m_address = 0; m_dsr = false; m_portaccess = false; - if (!m_rpiconn) LOGMASKED(LOG_CONFIG, "No Raspberry Pi connected\n"); + if (!m_rpiconn) LOGMASKED(LOG_WARN, "No Raspberry Pi connected\n"); + + // READY=0 is ignored at this point because the CPU is being reset at this time open_websocket(0); m_connected = false; m_lasttc = 0; @@ -621,11 +639,6 @@ INPUT_PORTS_START( tipi ) PORT_CONFNAME(0x01, 0x00, "Wait for initialization") PORT_CONFSETTING( 0x00, DEF_STR( Off ) ) PORT_CONFSETTING( 0x01, DEF_STR( On ) ) - PORT_START("MODE") - PORT_CONFNAME(0x01, 0x00, "Transfer mode") - PORT_CONFSETTING( 0x00, "async" ) - PORT_CONFSETTING( 0x01, "sync" ) - INPUT_PORTS_END void tipi_card_device::device_add_mconfig(machine_config &config) diff --git a/src/devices/bus/ti99/peb/tipi.h b/src/devices/bus/ti99/peb/tipi.h index abd2808daf9..3703e246599 100644 --- a/src/devices/bus/ti99/peb/tipi.h +++ b/src/devices/bus/ti99/peb/tipi.h @@ -51,6 +51,8 @@ private: void websocket_incoming(std::shared_ptr message); void websocket_error(const std::error_code& code); void websocket_closed(int i, const std::string& msg); + void websocket_debug(const char* msg, int i); + TIMER_CALLBACK_MEMBER(open_websocket); void send(const char* message); -- cgit v1.2.3