mirror of
https://github.com/holub/mame
synced 2025-04-22 08:22:15 +03:00
Merge pull request #401 from fulivi/pty_dev3
PTY support for u*x OSes [F.Ulivi]
This commit is contained in:
commit
fb179e042c
@ -1548,6 +1548,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",
|
||||
@ -192,6 +194,8 @@ files {
|
||||
MAME_DIR .. "src/emu/ui/imgcntrl.h",
|
||||
MAME_DIR .. "src/emu/ui/info.c",
|
||||
MAME_DIR .. "src/emu/ui/info.h",
|
||||
MAME_DIR .. "src/emu/ui/info_pty.c",
|
||||
MAME_DIR .. "src/emu/ui/info_pty.h",
|
||||
MAME_DIR .. "src/emu/ui/inputmap.c",
|
||||
MAME_DIR .. "src/emu/ui/inputmap.h",
|
||||
MAME_DIR .. "src/emu/ui/selgame.c",
|
||||
|
138
src/devices/bus/rs232/pty.c
Normal file
138
src/devices/bus/rs232/pty.c
Normal file
@ -0,0 +1,138 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:F. Ulivi
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include "pty.h"
|
||||
|
||||
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);
|
||||
|
||||
open();
|
||||
}
|
||||
|
||||
void pseudo_terminal_device::device_stop()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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>;
|
52
src/devices/bus/rs232/pty.h
Normal file
52
src/devices/bus/rs232/pty.h
Normal file
@ -0,0 +1,52 @@
|
||||
// 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_stop();
|
||||
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_ */
|
@ -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
|
||||
|
85
src/emu/dipty.c
Normal file
85
src/emu/dipty.c
Normal file
@ -0,0 +1,85 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
bool device_pty_interface::is_open(void) const
|
||||
{
|
||||
return m_opened;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
48
src/emu/dipty.h
Normal file
48
src/emu/dipty.h
Normal file
@ -0,0 +1,48 @@
|
||||
// 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);
|
||||
|
||||
bool is_open(void) const;
|
||||
|
||||
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"
|
||||
|
44
src/emu/ui/info_pty.c
Normal file
44
src/emu/ui/info_pty.c
Normal file
@ -0,0 +1,44 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:F.Ulivi
|
||||
/***************************************************************************
|
||||
|
||||
ui/info_pty.c
|
||||
|
||||
Information screen on pseudo terminals
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#include "emu.h"
|
||||
#include "ui/menu.h"
|
||||
#include "ui/info_pty.h"
|
||||
|
||||
ui_menu_pty_info::ui_menu_pty_info(running_machine &machine, render_container *container) :
|
||||
ui_menu(machine, container)
|
||||
{
|
||||
}
|
||||
|
||||
ui_menu_pty_info::~ui_menu_pty_info()
|
||||
{
|
||||
}
|
||||
|
||||
void ui_menu_pty_info::populate()
|
||||
{
|
||||
item_append("Pseudo terminals", NULL, MENU_FLAG_DISABLE, NULL);
|
||||
item_append("", NULL, MENU_FLAG_DISABLE, NULL);
|
||||
|
||||
pty_interface_iterator iter(machine().root_device());
|
||||
for (device_pty_interface *pty = iter.first(); pty != NULL; pty = iter.next()) {
|
||||
const char *port_name = pty->device().owner()->tag() + 1;
|
||||
if (pty->is_open()) {
|
||||
item_append(port_name , pty->slave_name() , MENU_FLAG_DISABLE , NULL);
|
||||
} else {
|
||||
item_append(port_name , "[failed]" , MENU_FLAG_DISABLE , NULL);
|
||||
}
|
||||
item_append("", NULL, MENU_FLAG_DISABLE, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void ui_menu_pty_info::handle()
|
||||
{
|
||||
process(0);
|
||||
}
|
24
src/emu/ui/info_pty.h
Normal file
24
src/emu/ui/info_pty.h
Normal file
@ -0,0 +1,24 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:F.Ulivi
|
||||
/***************************************************************************
|
||||
|
||||
ui/info_pty.h
|
||||
|
||||
Information screen on pseudo terminals
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __UI_INFO_PTY_H__
|
||||
#define __UI_INFO_PTY_H__
|
||||
|
||||
class ui_menu_pty_info : public ui_menu {
|
||||
public:
|
||||
ui_menu_pty_info(running_machine &machine, render_container *container);
|
||||
virtual ~ui_menu_pty_info();
|
||||
virtual void populate();
|
||||
virtual void handle();
|
||||
};
|
||||
|
||||
#endif // __UI_INFO_PTY_H__
|
@ -22,6 +22,7 @@
|
||||
#include "ui/barcode.h"
|
||||
#include "ui/cheatopt.h"
|
||||
#include "ui/info.h"
|
||||
#include "ui/info_pty.h"
|
||||
#include "ui/inputmap.h"
|
||||
#include "ui/mainmenu.h"
|
||||
#include "ui/miscmenu.h"
|
||||
@ -90,6 +91,10 @@ void ui_menu_main::populate()
|
||||
item_append("Tape Control", NULL, 0, (void *)TAPE_CONTROL);
|
||||
}
|
||||
|
||||
pty_interface_iterator ptyiter(machine().root_device());
|
||||
if (ptyiter.first() != NULL) {
|
||||
item_append("Pseudo terminals", NULL, 0, (void *)PTY_INFO);
|
||||
}
|
||||
if (machine().ioport().has_bioses())
|
||||
item_append("Bios Selection", NULL, 0, (void *)BIOS_SELECTION);
|
||||
|
||||
@ -191,6 +196,10 @@ void ui_menu_main::handle()
|
||||
ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_tape_control(machine(), container, NULL)));
|
||||
break;
|
||||
|
||||
case PTY_INFO:
|
||||
ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_pty_info(machine(), container)));
|
||||
break;
|
||||
|
||||
case SLOT_DEVICES:
|
||||
ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_slot_devices(machine(), container)));
|
||||
break;
|
||||
|
@ -44,7 +44,8 @@ private:
|
||||
CHEAT,
|
||||
SELECT_GAME,
|
||||
BIOS_SELECTION,
|
||||
BARCODE_READ
|
||||
BARCODE_READ,
|
||||
PTY_INFO
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
@ -101,6 +101,14 @@ file_error osd_write(osd_file *file, const void *buffer, UINT64 offset, UINT32 l
|
||||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_openpty
|
||||
//============================================================
|
||||
|
||||
file_error osd_openpty(osd_file **file, char *name, size_t name_len)
|
||||
{
|
||||
return FILERR_FAILURE;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_truncate
|
||||
|
@ -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);
|
||||
|
@ -32,3 +32,8 @@ file_error sdl_close_ptty(osd_file *file)
|
||||
{
|
||||
return FILERR_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
file_error sdl_slave_name_ptty(osd_file *file)
|
||||
{
|
||||
return FILERR_ACCESS_DENIED;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
// copyright-holders:Olivier Galibert, R. Belmont
|
||||
//============================================================
|
||||
//
|
||||
// sdlptty_unix.c - SDL psuedo tty access functions
|
||||
// sdlptty_unix.c - SDL pseudo tty access functions
|
||||
//
|
||||
// SDLMAME by Olivier Galibert and R. Belmont
|
||||
//
|
||||
@ -28,6 +28,7 @@
|
||||
#elif defined(SDLMAME_HAIKU)
|
||||
# include <bsd/pty.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sdlfile.h"
|
||||
|
||||
@ -39,68 +40,91 @@ 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)
|
||||
{
|
||||
const char *slave_name = ptsname(file->handle);
|
||||
|
||||
if (slave_name == NULL || strlen(slave_name) >= name_len) {
|
||||
return FILERR_INVALID_ACCESS;
|
||||
}
|
||||
|
||||
strcpy(name , slave_name);
|
||||
|
||||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
#else
|
||||
@ -110,21 +134,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
|
||||
|
@ -235,6 +235,14 @@ file_error osd_write(osd_file *file, const void *buffer, UINT64 offset, UINT32 l
|
||||
return FILERR_NONE;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_openpty
|
||||
//============================================================
|
||||
|
||||
file_error osd_openpty(osd_file **file, char *name, size_t name_len)
|
||||
{
|
||||
return FILERR_FAILURE;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_truncate
|
||||
|
Loading…
Reference in New Issue
Block a user