mirror of https://github.com/stella-emu/stella.git
Added SerialPort classes for OSX. I still have to test if it actually
compiles though. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1474 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
f7a1d3d147
commit
d45f6bef60
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: OSystem.cxx,v 1.123 2008-04-11 17:56:34 stephena Exp $
|
||||
// $Id: OSystem.cxx,v 1.124 2008-04-14 15:12:55 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <cassert>
|
||||
|
@ -38,8 +38,8 @@
|
|||
#include "SerialPortUNIX.hxx"
|
||||
#elif defined(WIN32)
|
||||
#include "SerialPortWin32.hxx"
|
||||
//#elif defined(MAC_OSX)
|
||||
// #include "SerialPortMACOSX.hxx"
|
||||
#elif defined(MAC_OSX)
|
||||
#include "SerialPortMACOSX.hxx"
|
||||
#endif
|
||||
|
||||
#include "FSNode.hxx"
|
||||
|
@ -222,8 +222,8 @@ bool OSystem::create()
|
|||
mySerialPort = new SerialPortUNIX();
|
||||
#elif defined(WIN32)
|
||||
mySerialPort = new SerialPortWin32();
|
||||
//#elif defined(MAC_OSX)
|
||||
// mySerialPort = new SerialPortMACOSX();
|
||||
#elif defined(MAC_OSX)
|
||||
mySerialPort = new SerialPortMACOSX();
|
||||
#else
|
||||
// Create an 'empty' serial port
|
||||
mySerialPort = new SerialPort();
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
//============================================================================
|
||||
//
|
||||
// SSSS tt lll lll
|
||||
// SS SS tt ll ll
|
||||
// SS tttttt eeee ll ll aaaa
|
||||
// SSSS tt ee ee ll ll aa
|
||||
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
||||
// SS SS tt ee ll ll aa aa
|
||||
// SSSS ttt eeeee llll llll aaaaa
|
||||
//
|
||||
// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: SerialPortMACOSX.cxx,v 1.1 2008-04-14 15:12:55 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/termios.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/filio.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "SerialPortMACOSX.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SerialPortMACOSX::SerialPortMACOSX()
|
||||
: SerialPort(),
|
||||
myHandle(0)
|
||||
{
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SerialPortMACOSX::~SerialPortMACOSX()
|
||||
{
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool SerialPortMACOSX::openPort(const string& device)
|
||||
{
|
||||
myHandle = open(device.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
if(myHandle <= 0)
|
||||
return false;
|
||||
|
||||
struct termios termios;
|
||||
memset(&termios, 0, sizeof(struct termios));
|
||||
|
||||
termios.c_cflag = CREAD | CLOCAL;
|
||||
termios.c_cflag |= B19200;
|
||||
termios.c_cflag |= CS8;
|
||||
tcflush(myHandle, TCIFLUSH);
|
||||
tcsetattr(myHandle, TCSANOW, &termios);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void SerialPortMACOSX::closePort()
|
||||
{
|
||||
if(myHandle)
|
||||
close(myHandle);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool SerialPortMACOSX::writeByte(const uInt8* data)
|
||||
{
|
||||
if(myHandle)
|
||||
{
|
||||
// cerr << "SerialPortMACOSX::writeByte " << (int)(*data) << endl;
|
||||
return write(myHandle, data, 1) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
//============================================================================
|
||||
//
|
||||
// SSSS tt lll lll
|
||||
// SS SS tt ll ll
|
||||
// SS tttttt eeee ll ll aaaa
|
||||
// SSSS tt ee ee ll ll aa
|
||||
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
||||
// SS SS tt ee ll ll aa aa
|
||||
// SSSS ttt eeeee llll llll aaaaa
|
||||
//
|
||||
// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: SerialPortMACOSX.hxx,v 1.1 2008-04-14 15:12:55 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef SERIALPORT_UNIX_HXX
|
||||
#define SERIALPORT_UNIX_HXX
|
||||
|
||||
#include "SerialPort.hxx"
|
||||
|
||||
/**
|
||||
Implement reading and writing from a serial port under OSX. For now,
|
||||
reading isn't actually supported at all.
|
||||
|
||||
@author Stephen Anthony & D. Spice
|
||||
@version $Id: SerialPortMACOSX.hxx,v 1.1 2008-04-14 15:12:55 stephena Exp $
|
||||
*/
|
||||
class SerialPortMACOSX : public SerialPort
|
||||
{
|
||||
public:
|
||||
SerialPortMACOSX();
|
||||
virtual ~SerialPortMACOSX();
|
||||
|
||||
/**
|
||||
Open the given serial port with the specified attributes.
|
||||
|
||||
@param device The name of the port
|
||||
@return False on any errors, else true
|
||||
*/
|
||||
bool openPort(const string& device);
|
||||
|
||||
/**
|
||||
Close a previously opened serial port.
|
||||
*/
|
||||
void closePort();
|
||||
|
||||
/**
|
||||
Write a byte to the serial port.
|
||||
|
||||
@param data The byte to write to the port
|
||||
@return True if a byte was written, else false
|
||||
*/
|
||||
bool writeByte(const uInt8* data);
|
||||
|
||||
private:
|
||||
// File descriptor for serial connection
|
||||
int myHandle;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue