mirror of
https://github.com/holub/mame
synced 2025-04-18 22:49:58 +03:00
pty: first step of pseudo terminal implementation
Conflicts: scripts/src/bus.lua
This commit is contained in:
parent
8e4ced4b53
commit
f8cb153519
@ -1531,6 +1531,8 @@ if (BUSES["RS232"]~=null) then
|
||||
MAME_DIR .. "src/devices/bus/rs232/printer.h",
|
||||
MAME_DIR .. "src/devices/bus/rs232/rs232.c",
|
||||
MAME_DIR .. "src/devices/bus/rs232/rs232.h",
|
||||
MAME_DIR .. "src/devices/bus/rs232/pty.c",
|
||||
MAME_DIR .. "src/devices/bus/rs232/pty.h",
|
||||
MAME_DIR .. "src/devices/bus/rs232/ser_mouse.c",
|
||||
MAME_DIR .. "src/devices/bus/rs232/ser_mouse.h",
|
||||
MAME_DIR .. "src/devices/bus/rs232/terminal.c",
|
||||
|
@ -79,6 +79,8 @@ files {
|
||||
MAME_DIR .. "src/emu/dinvram.h",
|
||||
MAME_DIR .. "src/emu/dioutput.c",
|
||||
MAME_DIR .. "src/emu/dioutput.h",
|
||||
MAME_DIR .. "src/emu/dipty.c",
|
||||
MAME_DIR .. "src/emu/dipty.h",
|
||||
MAME_DIR .. "src/emu/dirtc.c",
|
||||
MAME_DIR .. "src/emu/dirtc.h",
|
||||
MAME_DIR .. "src/emu/diserial.c",
|
||||
|
@ -103,6 +103,7 @@ device_rs232_port_interface::~device_rs232_port_interface()
|
||||
#include "null_modem.h"
|
||||
#include "printer.h"
|
||||
#include "terminal.h"
|
||||
#include "pty.h"
|
||||
|
||||
SLOT_INTERFACE_START( default_rs232_devices )
|
||||
SLOT_INTERFACE("keyboard", SERIAL_KEYBOARD)
|
||||
@ -110,4 +111,5 @@ SLOT_INTERFACE_START( default_rs232_devices )
|
||||
SLOT_INTERFACE("null_modem", NULL_MODEM)
|
||||
SLOT_INTERFACE("printer", SERIAL_PRINTER)
|
||||
SLOT_INTERFACE("terminal", SERIAL_TERMINAL)
|
||||
SLOT_INTERFACE("pty", PSEUDO_TERMINAL)
|
||||
SLOT_INTERFACE_END
|
||||
|
148
src/emu/bus/rs232/pty.c
Normal file
148
src/emu/bus/rs232/pty.c
Normal file
@ -0,0 +1,148 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:F. Ulivi
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include "pty.h"
|
||||
|
||||
#define FU_TEST
|
||||
|
||||
static const int TIMER_POLL = 1;
|
||||
|
||||
pseudo_terminal_device::pseudo_terminal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
|
||||
device_t(mconfig, PSEUDO_TERMINAL, "Pseudo terminal", tag, owner, clock, "pseudo_terminal", __FILE__),
|
||||
device_serial_interface(mconfig, *this),
|
||||
device_rs232_port_interface(mconfig, *this),
|
||||
device_pty_interface(mconfig, *this),
|
||||
m_rs232_txbaud(*this, "RS232_TXBAUD"),
|
||||
m_rs232_rxbaud(*this, "RS232_RXBAUD"),
|
||||
m_rs232_startbits(*this, "RS232_STARTBITS"),
|
||||
m_rs232_databits(*this, "RS232_DATABITS"),
|
||||
m_rs232_parity(*this, "RS232_PARITY"),
|
||||
m_rs232_stopbits(*this, "RS232_STOPBITS"),
|
||||
m_input_count(0),
|
||||
m_input_index(0)
|
||||
{
|
||||
}
|
||||
|
||||
WRITE_LINE_MEMBER(pseudo_terminal_device::update_serial)
|
||||
{
|
||||
int startbits = convert_startbits(m_rs232_startbits->read());
|
||||
int databits = convert_databits(m_rs232_databits->read());
|
||||
parity_t parity = convert_parity(m_rs232_parity->read());
|
||||
stop_bits_t stopbits = convert_stopbits(m_rs232_stopbits->read());
|
||||
|
||||
set_data_frame(startbits, databits, parity, stopbits);
|
||||
|
||||
int txbaud = convert_baud(m_rs232_txbaud->read());
|
||||
set_tra_rate(txbaud);
|
||||
|
||||
int rxbaud = convert_baud(m_rs232_rxbaud->read());
|
||||
set_rcv_rate(rxbaud);
|
||||
|
||||
output_rxd(1);
|
||||
|
||||
// TODO: make this configurable
|
||||
output_dcd(0);
|
||||
output_dsr(0);
|
||||
output_cts(0);
|
||||
}
|
||||
|
||||
static INPUT_PORTS_START(pseudo_terminal)
|
||||
MCFG_RS232_BAUD("RS232_TXBAUD", RS232_BAUD_9600, "TX Baud", pseudo_terminal_device, update_serial)
|
||||
MCFG_RS232_BAUD("RS232_RXBAUD", RS232_BAUD_9600, "RX Baud", pseudo_terminal_device, update_serial)
|
||||
MCFG_RS232_STARTBITS("RS232_STARTBITS", RS232_STARTBITS_1, "Start Bits", pseudo_terminal_device, update_serial)
|
||||
MCFG_RS232_DATABITS("RS232_DATABITS", RS232_DATABITS_8, "Data Bits", pseudo_terminal_device, update_serial)
|
||||
MCFG_RS232_PARITY("RS232_PARITY", RS232_PARITY_NONE, "Parity", pseudo_terminal_device, update_serial)
|
||||
MCFG_RS232_STOPBITS("RS232_STOPBITS", RS232_STOPBITS_1, "Stop Bits", pseudo_terminal_device, update_serial)
|
||||
INPUT_PORTS_END
|
||||
|
||||
ioport_constructor pseudo_terminal_device::device_input_ports() const
|
||||
{
|
||||
return INPUT_PORTS_NAME(pseudo_terminal);
|
||||
}
|
||||
|
||||
void pseudo_terminal_device::device_start()
|
||||
{
|
||||
m_timer_poll = timer_alloc(TIMER_POLL);
|
||||
|
||||
if (open()) {
|
||||
#ifdef FU_TEST
|
||||
printf("slave PTY = %s\n" , slave_name());
|
||||
#endif
|
||||
} else {
|
||||
#ifdef FU_TEST
|
||||
puts("Opening PTY failed");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void pseudo_terminal_device::device_reset()
|
||||
{
|
||||
update_serial(0);
|
||||
queue();
|
||||
}
|
||||
|
||||
void pseudo_terminal_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case TIMER_POLL:
|
||||
queue();
|
||||
break;
|
||||
|
||||
default:
|
||||
device_serial_interface::device_timer(timer, id, param, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void pseudo_terminal_device::tra_callback()
|
||||
{
|
||||
output_rxd(transmit_register_get_data_bit());
|
||||
}
|
||||
|
||||
void pseudo_terminal_device::tra_complete()
|
||||
{
|
||||
queue();
|
||||
}
|
||||
|
||||
void pseudo_terminal_device::rcv_complete()
|
||||
{
|
||||
receive_register_extract();
|
||||
write(get_received_char());
|
||||
}
|
||||
|
||||
void pseudo_terminal_device::queue(void)
|
||||
{
|
||||
if (is_transmit_register_empty())
|
||||
{
|
||||
if (m_input_index == m_input_count)
|
||||
{
|
||||
m_input_index = 0;
|
||||
int tmp = read(m_input_buffer , sizeof(m_input_buffer));
|
||||
if (tmp > 0) {
|
||||
m_input_count = tmp;
|
||||
} else {
|
||||
m_input_count = 0;
|
||||
}
|
||||
#ifdef FU_TEST
|
||||
if (m_input_count) {
|
||||
printf("read %u\n" , m_input_count);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (m_input_count != 0)
|
||||
{
|
||||
transmit_register_setup(m_input_buffer[ m_input_index++ ]);
|
||||
|
||||
m_timer_poll->adjust(attotime::never);
|
||||
}
|
||||
else
|
||||
{
|
||||
int txbaud = convert_baud(m_rs232_txbaud->read());
|
||||
m_timer_poll->adjust(attotime::from_hz(txbaud));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const device_type PSEUDO_TERMINAL = &device_creator<pseudo_terminal_device>;
|
51
src/emu/bus/rs232/pty.h
Normal file
51
src/emu/bus/rs232/pty.h
Normal file
@ -0,0 +1,51 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:F. Ulivi
|
||||
//
|
||||
#ifndef _RS232_PTY_H_
|
||||
#define _RS232_PTY_H_
|
||||
|
||||
#include "rs232.h"
|
||||
|
||||
class pseudo_terminal_device : public device_t,
|
||||
public device_serial_interface,
|
||||
public device_rs232_port_interface,
|
||||
public device_pty_interface
|
||||
{
|
||||
public:
|
||||
pseudo_terminal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
|
||||
|
||||
virtual DECLARE_WRITE_LINE_MEMBER( input_txd ) {
|
||||
device_serial_interface::rx_w(state);
|
||||
}
|
||||
|
||||
DECLARE_WRITE_LINE_MEMBER(update_serial);
|
||||
|
||||
protected:
|
||||
virtual ioport_constructor device_input_ports() const;
|
||||
virtual void device_start();
|
||||
virtual void device_reset();
|
||||
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
|
||||
|
||||
virtual void tra_callback();
|
||||
virtual void tra_complete();
|
||||
virtual void rcv_complete();
|
||||
|
||||
private:
|
||||
required_ioport m_rs232_txbaud;
|
||||
required_ioport m_rs232_rxbaud;
|
||||
required_ioport m_rs232_startbits;
|
||||
required_ioport m_rs232_databits;
|
||||
required_ioport m_rs232_parity;
|
||||
required_ioport m_rs232_stopbits;
|
||||
|
||||
UINT8 m_input_buffer[ 1024 ];
|
||||
UINT32 m_input_count;
|
||||
UINT32 m_input_index;
|
||||
emu_timer *m_timer_poll;
|
||||
|
||||
void queue(void);
|
||||
};
|
||||
|
||||
extern const device_type PSEUDO_TERMINAL;
|
||||
|
||||
#endif /* _RS232_PTY_H_ */
|
80
src/emu/dipty.c
Normal file
80
src/emu/dipty.c
Normal file
@ -0,0 +1,80 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:F.Ulivi
|
||||
/***************************************************************************
|
||||
|
||||
dipty.h
|
||||
|
||||
Device PTY interface
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#include "emu.h"
|
||||
#include "osdcore.h"
|
||||
|
||||
device_pty_interface::device_pty_interface(const machine_config &mconfig, device_t &device)
|
||||
: device_interface(device, "pty"),
|
||||
m_pty_master(NULL),
|
||||
m_slave_name(),
|
||||
m_opened(false)
|
||||
{
|
||||
}
|
||||
|
||||
device_pty_interface::~device_pty_interface()
|
||||
{
|
||||
}
|
||||
|
||||
bool device_pty_interface::open(void)
|
||||
{
|
||||
if (!m_opened) {
|
||||
char buffer[ 128 ];
|
||||
|
||||
if (osd_openpty(&m_pty_master , buffer , sizeof(buffer)) == FILERR_NONE) {
|
||||
m_opened = true;
|
||||
m_slave_name.assign(buffer);
|
||||
} else {
|
||||
m_opened = false;
|
||||
m_pty_master = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return m_opened;
|
||||
}
|
||||
|
||||
void device_pty_interface::close(void)
|
||||
{
|
||||
if (m_opened) {
|
||||
osd_close(m_pty_master);
|
||||
m_opened = false;
|
||||
}
|
||||
}
|
||||
|
||||
ssize_t device_pty_interface::read(UINT8 *rx_chars , size_t count)
|
||||
{
|
||||
UINT32 actual_bytes;
|
||||
|
||||
if (m_opened && osd_read(m_pty_master, rx_chars, 0, count, &actual_bytes) == FILERR_NONE) {
|
||||
return actual_bytes;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void device_pty_interface::write(UINT8 tx_char)
|
||||
{
|
||||
UINT32 actual_bytes;
|
||||
|
||||
if (m_opened) {
|
||||
osd_write(m_pty_master, &tx_char, 0, 1, &actual_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
bool device_pty_interface::is_slave_connected(void) const
|
||||
{
|
||||
// TODO: really check for slave status
|
||||
return m_opened;
|
||||
}
|
||||
|
||||
const char *device_pty_interface::slave_name(void) const
|
||||
{
|
||||
return m_slave_name.c_str();
|
||||
}
|
46
src/emu/dipty.h
Normal file
46
src/emu/dipty.h
Normal file
@ -0,0 +1,46 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:F.Ulivi
|
||||
/***************************************************************************
|
||||
|
||||
dipty.h
|
||||
|
||||
Device PTY interface
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __EMU_H__
|
||||
#error Dont include this file directly; include emu.h instead.
|
||||
#endif
|
||||
|
||||
#ifndef __DIPTY_H__
|
||||
#define __DIPTY_H__
|
||||
|
||||
class device_pty_interface : public device_interface
|
||||
{
|
||||
public:
|
||||
// construction/destruction
|
||||
device_pty_interface(const machine_config &mconfig, device_t &device);
|
||||
virtual ~device_pty_interface();
|
||||
|
||||
bool open(void);
|
||||
void close(void);
|
||||
|
||||
ssize_t read(UINT8 *rx_chars , size_t count);
|
||||
void write(UINT8 tx_char);
|
||||
|
||||
bool is_slave_connected(void) const;
|
||||
|
||||
const char *slave_name(void) const;
|
||||
|
||||
protected:
|
||||
osd_file *m_pty_master;
|
||||
std::string m_slave_name;
|
||||
bool m_opened;
|
||||
};
|
||||
|
||||
// iterator
|
||||
typedef device_interface_iterator<device_pty_interface> pty_interface_iterator;
|
||||
|
||||
#endif /* __DIPTY_H__ */
|
@ -78,6 +78,7 @@ typedef device_t * (*machine_config_constructor)(machine_config &config, device_
|
||||
#include "schedule.h"
|
||||
#include "timer.h"
|
||||
#include "dinetwork.h"
|
||||
#include "dipty.h"
|
||||
|
||||
// machine and driver configuration
|
||||
#include "mconfig.h"
|
||||
|
@ -165,6 +165,25 @@ file_error osd_read(osd_file *file, void *buffer, UINT64 offset, UINT32 length,
|
||||
-----------------------------------------------------------------------------*/
|
||||
file_error osd_write(osd_file *file, const void *buffer, UINT64 offset, UINT32 length, UINT32 *actual);
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
osd_openpty: create a new PTY pair
|
||||
|
||||
Parameters:
|
||||
|
||||
file - pointer to an osd_file * to receive the handle of the master
|
||||
side of the newly-created PTY; this is only valid if the function
|
||||
returns FILERR_NONE
|
||||
|
||||
name - pointer to memory where slave filename will be stored
|
||||
|
||||
name_len - space allocated for name
|
||||
|
||||
Return value:
|
||||
|
||||
a file_error describing any error that occurred while creating the
|
||||
PTY, or FILERR_NONE if no error occurred
|
||||
-----------------------------------------------------------------------------*/
|
||||
file_error osd_openpty(osd_file **file, char *name, size_t name_len);
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
osd_truncate: change the size of an open file
|
||||
|
@ -359,6 +359,25 @@ file_error osd_write(osd_file *file, const void *buffer, UINT64 offset, UINT32 c
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_openpty
|
||||
//============================================================
|
||||
|
||||
file_error osd_openpty(osd_file **file, char *name, size_t name_len)
|
||||
{
|
||||
file_error res;
|
||||
UINT64 filesize;
|
||||
|
||||
if ((res = osd_open(sdlfile_ptty_identifier , 0 , file , &filesize)) != FILERR_NONE) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = sdl_slave_name_ptty(*file , name , name_len)) != FILERR_NONE) {
|
||||
osd_close(*file);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_truncate
|
||||
|
@ -46,5 +46,6 @@ file_error sdl_open_ptty(const char *path, UINT32 openflags, osd_file **file, UI
|
||||
file_error sdl_read_ptty(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual);
|
||||
file_error sdl_write_ptty(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual);
|
||||
file_error sdl_close_ptty(osd_file *file);
|
||||
file_error sdl_slave_name_ptty(osd_file *file , char *name , size_t name_len);
|
||||
|
||||
file_error error_to_file_error(UINT32 error);
|
||||
|
@ -28,6 +28,9 @@
|
||||
#elif defined(SDLMAME_HAIKU)
|
||||
# include <bsd/pty.h>
|
||||
#endif
|
||||
#if defined(SDLMAME_LINUX)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "sdlfile.h"
|
||||
|
||||
@ -39,68 +42,87 @@ const char *sdlfile_ptty_identifier = "/dev/pts";
|
||||
|
||||
file_error sdl_open_ptty(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize)
|
||||
{
|
||||
int master;
|
||||
int aslave;
|
||||
char name[100];
|
||||
int master;
|
||||
int aslave;
|
||||
struct termios tios;
|
||||
int oldflags;
|
||||
|
||||
if (openpty(&master, &aslave, name, NULL, NULL) >= 0)
|
||||
{
|
||||
printf("Slave of device %s is %s\n", path, name );
|
||||
fcntl(master, F_SETFL, O_NONBLOCK);
|
||||
(*file)->handle = master;
|
||||
*filesize = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FILERR_ACCESS_DENIED;
|
||||
}
|
||||
memset(&tios , 0 , sizeof(tios));
|
||||
cfmakeraw(&tios);
|
||||
|
||||
return FILERR_NONE;
|
||||
if (openpty(&master, &aslave, NULL, &tios, NULL) >= 0)
|
||||
{
|
||||
oldflags = fcntl(master, F_GETFL, 0);
|
||||
if (oldflags == -1) {
|
||||
close(master);
|
||||
return FILERR_FAILURE;
|
||||
}
|
||||
|
||||
fcntl(master, F_SETFL, oldflags | O_NONBLOCK);
|
||||
close(aslave);
|
||||
(*file)->handle = master;
|
||||
*filesize = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FILERR_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
file_error sdl_read_ptty(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
|
||||
{
|
||||
ssize_t result;
|
||||
ssize_t result;
|
||||
|
||||
result = read(file->handle, buffer, count);
|
||||
result = read(file->handle, buffer, count);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
return error_to_file_error(errno);
|
||||
}
|
||||
if (result < 0)
|
||||
{
|
||||
return error_to_file_error(errno);
|
||||
}
|
||||
|
||||
if (actual != NULL )
|
||||
{
|
||||
*actual = result;
|
||||
}
|
||||
if (actual != NULL )
|
||||
{
|
||||
*actual = result;
|
||||
}
|
||||
|
||||
return FILERR_NONE;
|
||||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
file_error sdl_write_ptty(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
|
||||
{
|
||||
ssize_t result;
|
||||
result = write(file->handle, buffer, count);
|
||||
ssize_t result;
|
||||
result = write(file->handle, buffer, count);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
return error_to_file_error(errno);
|
||||
}
|
||||
if (result < 0)
|
||||
{
|
||||
return error_to_file_error(errno);
|
||||
}
|
||||
|
||||
if (actual != NULL )
|
||||
{
|
||||
*actual = result;
|
||||
}
|
||||
if (actual != NULL )
|
||||
{
|
||||
*actual = result;
|
||||
}
|
||||
|
||||
return FILERR_NONE;
|
||||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
file_error sdl_close_ptty(osd_file *file)
|
||||
{
|
||||
close(file->handle);
|
||||
osd_free(file);
|
||||
close(file->handle);
|
||||
osd_free(file);
|
||||
|
||||
return FILERR_NONE;
|
||||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
file_error sdl_slave_name_ptty(osd_file *file , char *name , size_t name_len)
|
||||
{
|
||||
if (ptsname_r(file->handle , name , name_len) < 0) {
|
||||
return FILERR_INVALID_ACCESS;
|
||||
}
|
||||
|
||||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
#else
|
||||
@ -110,21 +132,27 @@ const char *sdlfile_ptty_identifier = "";
|
||||
|
||||
file_error sdl_open_ptty(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize)
|
||||
{
|
||||
return FILERR_ACCESS_DENIED;
|
||||
return FILERR_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
file_error sdl_read_ptty(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
|
||||
{
|
||||
return FILERR_ACCESS_DENIED;
|
||||
return FILERR_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
file_error sdl_write_ptty(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
|
||||
{
|
||||
return FILERR_ACCESS_DENIED;
|
||||
return FILERR_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
file_error sdl_close_ptty(osd_file *file)
|
||||
{
|
||||
return FILERR_ACCESS_DENIED;
|
||||
return FILERR_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
file_error sdl_slave_name_ptty(osd_file *file)
|
||||
{
|
||||
return FILERR_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user