diff --git a/stella/src/emucore/AtariVox.cxx b/stella/src/emucore/AtariVox.cxx index fa0fcd764..dda201b56 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.10 2008-04-09 17:19:15 stephena Exp $ +// $Id: AtariVox.cxx,v 1.11 2008-04-11 00:29:15 stephena Exp $ //============================================================================ #ifdef SPEAKJET_EMULATION @@ -39,6 +39,8 @@ AtariVox::AtariVox(Jack jack, const Event& event, const SerialPort& port) mySpeakJet = new SpeakJet(); #endif + mySerialPort->openPort("", -1, -1, -1, -1); + myDigitalPinState[One] = myDigitalPinState[Two] = myDigitalPinState[Three] = myDigitalPinState[Four] = true; @@ -51,6 +53,8 @@ AtariVox::~AtariVox() #ifdef SPEAKJET_EMULATION delete mySpeakJet; #endif + + mySerialPort->closePort(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -175,7 +179,7 @@ void AtariVox::shiftIn(bool value) #ifdef SPEAKJET_EMULATION mySpeakJet->write(data); #endif - mySerialPort->writeByte(data); + mySerialPort->writeByte(&data); } myShiftRegister = 0; } diff --git a/stella/src/emucore/OSystem.cxx b/stella/src/emucore/OSystem.cxx index 9bdfed6d2..3b00fb439 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.121 2008-03-31 00:59:30 stephena Exp $ +// $Id: OSystem.cxx,v 1.122 2008-04-11 00:29:15 stephena Exp $ //============================================================================ #include @@ -36,8 +36,8 @@ #include "SerialPort.hxx" #if defined(UNIX) #include "SerialPortUNIX.hxx" -//#elif defined(WIN32) -// #include "SerialPortWin32.hxx" +#elif defined(WIN32) + #include "SerialPortWin32.hxx" //#elif defined(MAC_OSX) // #include "SerialPortMACOSX.hxx" #endif @@ -220,8 +220,8 @@ bool OSystem::create() // a real serial port on the system #if defined(UNIX) mySerialPort = new SerialPortUNIX(); -//#elif defined(WIN32) -// mySerialPort = new SerialPortWin32(); +#elif defined(WIN32) + mySerialPort = new SerialPortWin32(); //#elif defined(MAC_OSX) // mySerialPort = new SerialPortMACOSX(); #else diff --git a/stella/src/emucore/SerialPort.hxx b/stella/src/emucore/SerialPort.hxx index 44c8483ff..4058ed2be 100644 --- a/stella/src/emucore/SerialPort.hxx +++ b/stella/src/emucore/SerialPort.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: SerialPort.hxx,v 1.2 2008-04-09 17:19:15 stephena Exp $ +// $Id: SerialPort.hxx,v 1.3 2008-04-11 00:29:15 stephena Exp $ //============================================================================ #ifndef SERIALPORT_HXX @@ -27,7 +27,7 @@ but it may be used for other devices in the future. @author Stephen Anthony - @version $Id: SerialPort.hxx,v 1.2 2008-04-09 17:19:15 stephena Exp $ + @version $Id: SerialPort.hxx,v 1.3 2008-04-11 00:29:15 stephena Exp $ */ class SerialPort { @@ -60,7 +60,7 @@ class SerialPort @param data Destination for the byte read from the port @return True if a byte was read, else false */ - virtual bool readByte(uInt8& data) { return false; } + virtual bool readByte(uInt8* data) { return false; } /** Write a byte to the serial port. @@ -68,7 +68,7 @@ class SerialPort @param data The byte to write to the port @return True if a byte was written, else false */ - virtual bool writeByte(const uInt8 data) { return false; } + virtual bool writeByte(const uInt8* data) { return false; } }; #endif diff --git a/stella/src/win32/SerialPortWin32.cxx b/stella/src/win32/SerialPortWin32.cxx new file mode 100644 index 000000000..508c6f596 --- /dev/null +++ b/stella/src/win32/SerialPortWin32.cxx @@ -0,0 +1,103 @@ +//============================================================================ +// +// 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: SerialPortWin32.cxx,v 1.1 2008-04-11 00:29:15 stephena Exp $ +//============================================================================ + +#include + +#include "SerialPortWin32.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SerialPortWin32::SerialPortWin32() + : SerialPort(), + myHandle(NULL) +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SerialPortWin32::~SerialPortWin32() +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool SerialPortWin32::openPort(const string& device, int baud, int data, + int stop, int parity) +{ + if(!myHandle) + { + // + // Get Selected COM (or other if prefix has changed) port name from list box + // +// GetDlgItemText(IDC_CMB_PORTS, str); + + myHandle = CreateFile("COM3", GENERIC_READ|GENERIC_WRITE, 0, + NULL, OPEN_EXISTING, 0, NULL); + + if(myHandle) + { + DCB dcb; + COMMTIMEOUTS cto; + + FillMemory(&dcb, sizeof(dcb), 0); + dcb.DCBlength = sizeof(dcb); + if(!BuildCommDCB("19200,n,8,1", &dcb)) + return false; + + memset(&dcb, 0, sizeof(DCB)); + dcb.BaudRate = CBR_19200; + dcb.ByteSize = 8; + dcb.Parity = NOPARITY; + dcb.StopBits = ONESTOPBIT; + // dcb.fOutxCtsFlow = TRUE; + // dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; + SetCommState(myHandle, &dcb); + +// cto.ReadIntervalTimeout = 0; +// cto.ReadTotalTimeoutMultiplier = 0; +// cto.ReadTotalTimeoutConstant = 0; +// cto.WriteTotalTimeoutMultiplier = 0; +// cto.WriteTotalTimeoutConstant = 0; +// SetCommTimeouts(myHandle, &cto); + } + else + return false; + } + return true; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void SerialPortWin32::closePort() +{ + if(myHandle) + { +cerr << "port closed\n"; + CloseHandle(myHandle); + myHandle = NULL; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool SerialPortWin32::writeByte(const uInt8* data) +{ + if(myHandle) + { + cerr << "SerialPortWin32::write " << (int)(*data) << endl; + + DWORD written; + return WriteFile(myHandle, data, 1, &written, 0) == TRUE; + } + return false; +} diff --git a/stella/src/win32/SerialPortWin32.hxx b/stella/src/win32/SerialPortWin32.hxx new file mode 100644 index 000000000..f7363a4c8 --- /dev/null +++ b/stella/src/win32/SerialPortWin32.hxx @@ -0,0 +1,67 @@ +//============================================================================ +// +// 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: SerialPortWin32.hxx,v 1.1 2008-04-11 00:29:15 stephena Exp $ +//============================================================================ + +#ifndef SERIALPORT_WIN32_HXX +#define SERIALPORT_WIN32_HXX + +#include "SerialPort.hxx" + +/** + Implement reading and writing from a serial port under Windows systems. + + @author Stephen Anthony + @version $Id: SerialPortWin32.hxx,v 1.1 2008-04-11 00:29:15 stephena Exp $ +*/ +class SerialPortWin32 : public SerialPort +{ + public: + SerialPortWin32(); + virtual ~SerialPortWin32(); + + /** + Open the given serial port with the specified attributes. + + @param device The name of the port + @param baud Baud rate + @param data Number of data bits + @param stop Number of stop bits + @param parity Type of parity bit (0=none, 1=odd, 2=even) + + @return False on any errors, else true + */ + bool openPort(const string& device, int baud, int data, int stop, int parity); + + /** + 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: + // Handle to serial port + HANDLE myHandle; +}; + +#endif diff --git a/stella/src/win32/Stella.vcproj b/stella/src/win32/Stella.vcproj index 55c25f87a..d9043add2 100755 --- a/stella/src/win32/Stella.vcproj +++ b/stella/src/win32/Stella.vcproj @@ -382,6 +382,10 @@ RelativePath=".\SDL_win32_main.c" > + + @@ -944,6 +948,10 @@ RelativePath="..\common\RectList.hxx" > + +