Success! Or at least a little bit :) I have 'Man Goes Down' correctly sending output to the AVox through the AVox USB adaptor in Windows. Now that I know that it's actually possible in Stella, it should be relatively simple to do the same in Linux and OSX. Still TODO is add an appropriate UI for selecting the serial/com port to use; right now it's hardcoded.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1463 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2008-04-11 00:29:15 +00:00
parent e28bb7b889
commit b508d668c2
6 changed files with 193 additions and 11 deletions

View File

@ -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;
}

View File

@ -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 <cassert>
@ -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

View File

@ -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

View File

@ -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 <windows.h>
#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;
}

View File

@ -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

View File

@ -382,6 +382,10 @@
RelativePath=".\SDL_win32_main.c"
>
</File>
<File
RelativePath=".\SerialPortWin32.cxx"
>
</File>
<File
RelativePath="..\win32\SettingsWin32.cxx"
>
@ -944,6 +948,10 @@
RelativePath="..\common\RectList.hxx"
>
</File>
<File
RelativePath=".\SerialPortWin32.hxx"
>
</File>
<File
RelativePath="..\win32\SettingsWin32.hxx"
>