diff --git a/stella/src/emucore/OSystem.cxx b/stella/src/emucore/OSystem.cxx index e1c969433..2d026df9c 100644 --- a/stella/src/emucore/OSystem.cxx +++ b/stella/src/emucore/OSystem.cxx @@ -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 @@ -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(); diff --git a/stella/src/macosx/SerialPortMACOSX.cxx b/stella/src/macosx/SerialPortMACOSX.cxx new file mode 100644 index 000000000..349556129 --- /dev/null +++ b/stella/src/macosx/SerialPortMACOSX.cxx @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +#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; +} diff --git a/stella/src/macosx/SerialPortMACOSX.hxx b/stella/src/macosx/SerialPortMACOSX.hxx new file mode 100644 index 000000000..8ded78d2e --- /dev/null +++ b/stella/src/macosx/SerialPortMACOSX.hxx @@ -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