From de5a387f473b8bead311e7e54c0624d8197caba3 Mon Sep 17 00:00:00 2001 From: stephena Date: Fri, 11 Apr 2008 01:28:35 +0000 Subject: [PATCH] And now AVox output works in Linux. I can't believe the stupid mistake I was making, shadowing an instance variable with a local one. I must be losing it :) git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1464 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/emucore/AtariVox.cxx | 4 +-- stella/src/emucore/m6502/src/M6502Hi.cxx | 3 +- stella/src/unix/SerialPortUNIX.cxx | 38 ++++++++++++++++++++---- stella/src/unix/SerialPortUNIX.hxx | 10 +++++-- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/stella/src/emucore/AtariVox.cxx b/stella/src/emucore/AtariVox.cxx index dda201b56..52f4efc5d 100644 --- a/stella/src/emucore/AtariVox.cxx +++ b/stella/src/emucore/AtariVox.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: AtariVox.cxx,v 1.11 2008-04-11 00:29:15 stephena Exp $ +// $Id: AtariVox.cxx,v 1.12 2008-04-11 01:28:35 stephena Exp $ //============================================================================ #ifdef SPEAKJET_EMULATION @@ -38,7 +38,6 @@ AtariVox::AtariVox(Jack jack, const Event& event, const SerialPort& port) #ifdef SPEAKJET_EMULATION mySpeakJet = new SpeakJet(); #endif - mySerialPort->openPort("", -1, -1, -1, -1); myDigitalPinState[One] = myDigitalPinState[Two] = @@ -53,7 +52,6 @@ AtariVox::~AtariVox() #ifdef SPEAKJET_EMULATION delete mySpeakJet; #endif - mySerialPort->closePort(); } diff --git a/stella/src/emucore/m6502/src/M6502Hi.cxx b/stella/src/emucore/m6502/src/M6502Hi.cxx index b2cca05f1..c31291f14 100644 --- a/stella/src/emucore/m6502/src/M6502Hi.cxx +++ b/stella/src/emucore/m6502/src/M6502Hi.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: M6502Hi.cxx,v 1.21 2008-02-06 13:45:22 stephena Exp $ +// $Id: M6502Hi.cxx,v 1.22 2008-04-11 01:28:35 stephena Exp $ //============================================================================ #include "M6502Hi.hxx" @@ -62,7 +62,6 @@ inline uInt8 M6502High::peek(uInt16 address) } #endif - uInt8 result = mySystem->peek(address); myLastAccessWasRead = true; return result; diff --git a/stella/src/unix/SerialPortUNIX.cxx b/stella/src/unix/SerialPortUNIX.cxx index ffae7a037..d6dc4b1e6 100644 --- a/stella/src/unix/SerialPortUNIX.cxx +++ b/stella/src/unix/SerialPortUNIX.cxx @@ -13,14 +13,23 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: SerialPortUNIX.cxx,v 1.2 2008-04-09 17:19:15 stephena Exp $ +// $Id: SerialPortUNIX.cxx,v 1.3 2008-04-11 01:28:35 stephena Exp $ //============================================================================ +#include +#include +#include +#include +#include +#include +#include + #include "SerialPortUNIX.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SerialPortUNIX::SerialPortUNIX() - : SerialPort() + : SerialPort(), + myHandle(0) { } @@ -33,17 +42,36 @@ SerialPortUNIX::~SerialPortUNIX() bool SerialPortUNIX::openPort(const string& device, int baud, int data, int stop, int parity) { - return false; + myHandle = open("/dev/ttyUSB0", 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 SerialPortUNIX::closePort() { + if(myHandle) + close(myHandle); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool SerialPortUNIX::writeByte(const uInt8 data) +bool SerialPortUNIX::writeByte(const uInt8* data) { - cerr << "SerialPortUNIX::writeByte " << (int)data << endl; + if(myHandle) + { +// cerr << "SerialPortUNIX::writeByte " << (int)(*data) << endl; + return write(myHandle, data, 1) == 1; + } return false; } diff --git a/stella/src/unix/SerialPortUNIX.hxx b/stella/src/unix/SerialPortUNIX.hxx index 372d1d75b..8e2886fe8 100644 --- a/stella/src/unix/SerialPortUNIX.hxx +++ b/stella/src/unix/SerialPortUNIX.hxx @@ -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: SerialPortUNIX.hxx,v 1.2 2008-04-09 17:19:16 stephena Exp $ +// $Id: SerialPortUNIX.hxx,v 1.3 2008-04-11 01:28:35 stephena Exp $ //============================================================================ #ifndef SERIALPORT_UNIX_HXX @@ -26,7 +26,7 @@ it seems to be Linux-only, and reading isn't actually supported at all. @author Stephen Anthony - @version $Id: SerialPortUNIX.hxx,v 1.2 2008-04-09 17:19:16 stephena Exp $ + @version $Id: SerialPortUNIX.hxx,v 1.3 2008-04-11 01:28:35 stephena Exp $ */ class SerialPortUNIX : public SerialPort { @@ -58,7 +58,11 @@ class SerialPortUNIX : public SerialPort @param data The byte to write to the port @return True if a byte was written, else false */ - bool writeByte(const uInt8 data); + bool writeByte(const uInt8* data); + + private: + // File descriptor for serial connection + int myHandle; }; #endif