From 784a36b87f9322ada13d4e3296934c20dea16ecf Mon Sep 17 00:00:00 2001 From: Michael Zapf Date: Sun, 25 Aug 2013 15:22:30 +0000 Subject: [PATCH] (MESS) ti99: Fixed dropouts in RS232, caused by sdlsocket/corefile wiping the input buffer on next write. --- src/mess/machine/ti99/ti_rs232.c | 23 ++++++++++++++++++++--- src/mess/machine/ti99/ti_rs232.h | 14 +++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/mess/machine/ti99/ti_rs232.c b/src/mess/machine/ti99/ti_rs232.c index c5ea561df38..a47dfb9dbe4 100644 --- a/src/mess/machine/ti99/ti_rs232.c +++ b/src/mess/machine/ti99/ti_rs232.c @@ -684,7 +684,6 @@ void ti_rs232_pio_device::receive_data_or_line_state(int uartind) { device_image_interface *serial; UINT8 buffer; - int len = 0; serial = dynamic_cast(m_serdev[uartind]); @@ -700,8 +699,15 @@ void ti_rs232_pio_device::receive_data_or_line_state(int uartind) // elapsed, we can get a new value. if (m_time_hold[uartind] > 1.0) { - len = serial->fread(&buffer, 1); - if (len==0) return; + // Buffer empty? + if (m_bufpos[uartind] == m_buflen[uartind]) + { + // Get all out of sdlsocket + m_buflen[uartind] = serial->fread(m_recvbuf[uartind], 512); + m_bufpos[uartind] = 0; + if (m_buflen[uartind]==0) return; + } + buffer = m_recvbuf[uartind][m_bufpos[uartind]++]; } else { @@ -1030,6 +1036,15 @@ void ti_rs232_pio_device::device_start() m_serdev[0] = subdevice("serdev0"); m_serdev[1] = subdevice("serdev1"); m_piodev = subdevice("piodev"); + // Prepare the receive buffers + m_recvbuf[0] = (UINT8*)malloc(512); + m_recvbuf[1] = (UINT8*)malloc(512); +} + +void ti_rs232_pio_device::device_stop() +{ + if (m_recvbuf[0] != NULL) free(m_recvbuf[0]); + if (m_recvbuf[1] != NULL) free(m_recvbuf[1]); } void ti_rs232_pio_device::device_reset() @@ -1047,6 +1062,8 @@ void ti_rs232_pio_device::device_reset() m_recv_mode[0] = RECV_MODE_NORMAL; m_recv_mode[1] = RECV_MODE_NORMAL; + m_bufpos[0] = m_bufpos[1] = m_buflen[0] = m_buflen[1] = 0; + if (m_genmod) { m_select_mask = 0x1fe000; diff --git a/src/mess/machine/ti99/ti_rs232.h b/src/mess/machine/ti99/ti_rs232.h index 004b56c96a4..a21e6e6ec33 100644 --- a/src/mess/machine/ti99/ti_rs232.h +++ b/src/mess/machine/ti99/ti_rs232.h @@ -49,6 +49,7 @@ public: protected: virtual void device_start(void); virtual void device_reset(void); + virtual void device_stop(void); virtual const rom_entry *device_rom_region(void) const; virtual machine_config_constructor device_mconfig_additions() const; virtual ioport_constructor device_input_ports() const; @@ -66,13 +67,24 @@ private: void output_exception(int uartind, int param, UINT8 value); void ctrl_callback(int uartind, int type, UINT8 data); + // UART chips tms9902_device* m_uart[2]; + // Connected images (file or socket connection) that represent the + // devices that are connected to the serial adapters ti_rs232_attached_device* m_serdev[2]; + // Connected image (file) that represents the device connected to the + // parallel interface ti_pio_attached_device* m_piodev; address_space* m_space; UINT8* m_dsrrom; - UINT8 m_signals[2]; // Latches the state of the output lines for UART0/UART1 + // Input buffer for each UART. We have to copy the contents of sdlsocket here + // because the buffer in corefile will be lost on the next write operation + UINT8* m_recvbuf[2]; + int m_bufpos[2], m_buflen[2]; + + // Latches the state of the output lines for UART0/UART1 + UINT8 m_signals[2]; int m_recv_mode[2]; // May be NORMAL or ESC // Baud rate management