From cd9d21051f028fed8ca427449128bc3007249f55 Mon Sep 17 00:00:00 2001 From: stephena Date: Sat, 29 Mar 2008 19:15:57 +0000 Subject: [PATCH] Fixed bit-rot with AtariVox stuff, and updated some of its documentation. It now compiles and runs against the latest controller changes. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1451 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/common/SoundSDL.cxx | 7 +- stella/src/emucore/AtariVox.cxx | 149 ++++++++++++++++---------------- stella/src/emucore/AtariVox.hxx | 29 ++----- stella/src/emucore/Console.cxx | 6 +- stella/src/emucore/M6532.cxx | 43 +++++---- stella/src/emucore/SpeakJet.cxx | 21 +++-- stella/src/emucore/SpeakJet.hxx | 6 +- 7 files changed, 127 insertions(+), 134 deletions(-) diff --git a/stella/src/common/SoundSDL.cxx b/stella/src/common/SoundSDL.cxx index 262cd8541..9d0dec5b8 100644 --- a/stella/src/common/SoundSDL.cxx +++ b/stella/src/common/SoundSDL.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: SoundSDL.cxx,v 1.40 2008-02-06 13:45:19 stephena Exp $ +// $Id: SoundSDL.cxx,v 1.41 2008-03-29 19:15:57 stephena Exp $ //============================================================================ #ifdef SOUND_SUPPORT @@ -31,6 +31,9 @@ #include "System.hxx" #include "OSystem.hxx" +#include "Console.hxx" +#include "AtariVox.hxx" + #include "SoundSDL.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -406,7 +409,7 @@ void SoundSDL::callback(void* udata, uInt8* stream, int len) SoundSDL* sound = (SoundSDL*)udata; sound->processFragment(stream, (Int32)len); #ifdef ATARIVOX_SUPPORT - cerr << "SoundSDL::callback(): len==" << len << endl; +// cerr << "SoundSDL::callback(): len==" << len << endl; // See if we need sound from the AtariVox AtariVox *vox = sound->myOSystem->console().atariVox(); diff --git a/stella/src/emucore/AtariVox.cxx b/stella/src/emucore/AtariVox.cxx index 2d81e74e8..09c84632b 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.6 2008-02-06 13:45:20 stephena Exp $ +// $Id: AtariVox.cxx,v 1.7 2008-03-29 19:15:57 stephena Exp $ //============================================================================ #ifdef ATARIVOX_SUPPORT @@ -21,49 +21,87 @@ #include "Event.hxx" #include "AtariVox.hxx" #include "SpeakJet.hxx" +#include "System.hxx" #define DEBUG_ATARIVOX 0 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AtariVox::AtariVox(Jack jack, const Event& event) - : Controller(jack, event), - mySpeakJet(0), - mySystem(0), - myPinState(0), - myShiftCount(0), - myShiftRegister(0), - myLastDataWriteCycle(0) + : Controller(jack, event, Controller::AtariVox), + mySpeakJet(0), + myPinState(0), + myShiftCount(0), + myShiftRegister(0), + myLastDataWriteCycle(0) { - myType = Controller::AtariVox; mySpeakJet = new SpeakJet(); + + myDigitalPinState[One] = myDigitalPinState[Two] = + myDigitalPinState[Three] = myDigitalPinState[Four] = true; + + myAnalogPinValue[Five] = myAnalogPinValue[Nine] = maximumResistance; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AtariVox::~AtariVox() { + delete mySpeakJet; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void AtariVox::setSystem(System *system) { - mySystem = system; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool AtariVox::read(DigitalPin pin) +void AtariVox::write(DigitalPin pin, bool value) { - // For now, always return true, meaning the device is ready -/* if(DEBUG_ATARIVOX) - cerr << "AtariVox: read from SWCHA" << endl; -*/ - return true; + cerr << "AtariVox: write to SWCHA" << endl; + + // Change the pin state based on value + switch(pin) + { + // Pin 1: SpeakJet DATA + // output serial data to the speakjet + case One: + clockDataIn(value); + break; + + // Pin 2: SpeakJet READY + case Two: + // TODO - see how this is used + break; + + // Pin 3: EEPROM SDA + // output data to the 24LC256 EEPROM using the I2C protocol + case Three: + // TODO - implement this + if(DEBUG_ATARIVOX) + cerr << "AtariVox: value " + << value + << " written to SDA line at cycle " + << mySystem->cycles() + << endl; + break; + + // Pin 4: EEPROM SCL + // output clock data to the 24LC256 EEPROM using the I2C protocol + case Four: + // TODO - implement this + if(DEBUG_ATARIVOX) + cerr << "AtariVox: value " + << value + << " written to SCLK line at cycle " + << mySystem->cycles() + << endl; + break; + + case Six: + // Not connected + break; + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Int32 AtariVox::read(AnalogPin) +void AtariVox::update() { - // Analog pins are not connected in AtariVox, so we have infinite resistance - return maximumResistance; + // Nothing to do, this seems to be an output-only device for now } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -85,22 +123,25 @@ void AtariVox::clockDataIn(bool value) << ")" << endl; - if(value && (myShiftCount == 0)) { + if(value && (myShiftCount == 0)) + { if(DEBUG_ATARIVOX) cerr << "value && (myShiftCount == 0), returning" << endl; return; } - if(cycle < myLastDataWriteCycle || cycle > myLastDataWriteCycle + 1000) { - // If this is the first write this frame, or if it's been a long time - // since the last write, start a new data byte. + // If this is the first write this frame, or if it's been a long time + // since the last write, start a new data byte. + if(cycle < myLastDataWriteCycle || cycle > myLastDataWriteCycle + 1000) + { myShiftRegister = 0; myShiftCount = 0; } - if(cycle < myLastDataWriteCycle || cycle >= myLastDataWriteCycle + 62) { - // If this is the first write this frame, or if it's been 62 cycles - // since the last write, shift this bit into the current byte. + // If this is the first write this frame, or if it's been 62 cycles + // since the last write, shift this bit into the current byte. + if(cycle < myLastDataWriteCycle || cycle >= myLastDataWriteCycle + 62) + { if(DEBUG_ATARIVOX) cerr << "cycle >= myLastDataWriteCycle + 62, shiftIn(" << value << ")" << endl; @@ -115,7 +156,8 @@ void AtariVox::shiftIn(bool value) { myShiftRegister >>= 1; myShiftRegister |= (value << 15); - if(++myShiftCount == 10) { + if(++myShiftCount == 10) + { myShiftCount = 0; myShiftRegister >>= 6; if(!(myShiftRegister & (1<<9))) @@ -132,49 +174,4 @@ void AtariVox::shiftIn(bool value) } } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void AtariVox::write(DigitalPin pin, bool value) -{ - if(DEBUG_ATARIVOX) - cerr << "AtariVox: write to SWCHA" << endl; - - // Change the pin state based on value - switch(pin) - { - // Pin 1 is the DATA line, used to output serial data to the - // speakjet - case One: - clockDataIn(value); - break; - - // Pin 2 is the SDA line, used to output data to the 24LC256 - // serial EEPROM, using the I2C protocol. - // I'm not even trying to emulate this right now :( - case Two: - if(DEBUG_ATARIVOX) - cerr << "AtariVox: value " - << value - << " written to SDA line at cycle " - << mySystem->cycles() - << endl; - break; - - // Pin 2 is the SCLK line, used to output clock data to the 24LC256 - // serial EEPROM, using the I2C protocol. - // I'm not even trying to emulate this right now :( - case Three: - if(DEBUG_ATARIVOX) - cerr << "AtariVox: value " - << value - << " written to SCLK line at cycle " - << mySystem->cycles() - << endl; - break; - - case Four: - default: - break; - } -} - #endif diff --git a/stella/src/emucore/AtariVox.hxx b/stella/src/emucore/AtariVox.hxx index 0a8781879..65ce24082 100644 --- a/stella/src/emucore/AtariVox.hxx +++ b/stella/src/emucore/AtariVox.hxx @@ -14,7 +14,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: AtariVox.hxx,v 1.8 2008-02-06 13:45:20 stephena Exp $ +// $Id: AtariVox.hxx,v 1.9 2008-03-29 19:15:57 stephena Exp $ //============================================================================ #ifdef ATARIVOX_SUPPORT @@ -33,7 +33,7 @@ driver code. @author B. Watson - @version $Id: AtariVox.hxx,v 1.8 2008-02-06 13:45:20 stephena Exp $ + @version $Id: AtariVox.hxx,v 1.9 2008-03-29 19:15:57 stephena Exp $ */ class AtariVox : public Controller { @@ -52,25 +52,6 @@ class AtariVox : public Controller virtual ~AtariVox(); public: - /** - Read the value of the specified digital pin for this controller. - - @param pin The pin of the controller jack to read - @return The state of the pin - */ - virtual bool read(DigitalPin pin); - - /** - Read the resistance at the specified analog pin for this controller. - The returned value is the resistance measured in ohms. - - The AtariVox doesn't use the analog pins. - - @param pin The pin of the controller jack to read - @return The resistance at the specified pin - */ - virtual Int32 read(AnalogPin pin); - /** Write the given value to the specified digital pin for this controller. Writing is only allowed to the pins associated @@ -81,6 +62,12 @@ class AtariVox : public Controller */ virtual void write(DigitalPin pin, bool value); + /** + Update the entire digital and analog pin state according to the + events currently set. + */ + virtual void update(); + SpeakJet* getSpeakJet() { return mySpeakJet; } private: diff --git a/stella/src/emucore/Console.cxx b/stella/src/emucore/Console.cxx index 9956c64d2..83d5fb034 100644 --- a/stella/src/emucore/Console.cxx +++ b/stella/src/emucore/Console.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: Console.cxx,v 1.133 2008-03-22 17:35:02 stephena Exp $ +// $Id: Console.cxx,v 1.134 2008-03-29 19:15:57 stephena Exp $ //============================================================================ #include @@ -63,6 +63,7 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props) : myOSystem(osystem), myProperties(props), + vox(0), myDisplayFormat("NTSC"), myFramerate(60), myUserPaletteDefined(false) @@ -149,7 +150,8 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props) #ifdef ATARIVOX_SUPPORT else if(right == "ATARIVOX") { - myControllers[rightPort] = new AtariVox(Controller::Right, *myEvent); +cerr << "atarivox added as right controller\n"; + myControllers[rightPort] = vox = new AtariVox(Controller::Right, *myEvent); } #endif else diff --git a/stella/src/emucore/M6532.cxx b/stella/src/emucore/M6532.cxx index 61142d394..62a061ba3 100644 --- a/stella/src/emucore/M6532.cxx +++ b/stella/src/emucore/M6532.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: M6532.cxx,v 1.14 2008-03-24 20:31:31 stephena Exp $ +// $Id: M6532.cxx,v 1.15 2008-03-29 19:15:57 stephena Exp $ //============================================================================ #include @@ -28,7 +28,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - M6532::M6532(const Console& console) - : myConsole(console) + : myConsole(console) { // Randomize the 128 bytes of memory class Random random; @@ -247,24 +247,29 @@ void M6532::poke(uInt16 addr, uInt8 value) { myDDRA = value; #ifdef ATARIVOX_SUPPORT - /* - 20060608 bkw: Not the most elegant thing in the world... - When a bit in the DDR is set as input, +5V is placed on its output - pin. When it's set as output, either +5V or 0V (depending on the - contents of SWCHA) will be placed on the output pin. - The standard macros for the AtariVox use this fact to send data - to the port. + /* + 20060608 bkw: Not the most elegant thing in the world... + When a bit in the DDR is set as input, +5V is placed on its output + pin. When it's set as output, either +5V or 0V (depending on the + contents of SWCHA) will be placed on the output pin. + The standard macros for the AtariVox use this fact to send data + to the port. - This code isn't 100% correct: it assumes the SWCHA bits are all 0. - This is good enough to emulate the AtariVox, if the programmer is - using SWACNT to do output (e.g. the SPKOUT macro from speakjet.inc) - and if he's leaving SWCHA alone. + This code isn't 100% correct: it assumes the SWCHA bits are all 0. + This is good enough to emulate the AtariVox, if the programmer is + using SWACNT to do output (e.g. the SPKOUT macro from speakjet.inc) + and if he's leaving SWCHA alone. - The inaccuracy here means that wrongly-written code will still - be able to drive the emulated AtariVox, even though it wouldn't - work on real hardware. - */ - Controller &c = myConsole.controller(Controller::Right); + The inaccuracy here means that wrongly-written code will still + be able to drive the emulated AtariVox, even though it wouldn't + work on real hardware. + */ + // TODO - Fix this properly in the core + // Any time the core code needs to know what type of controller + // is connected, it's by definition a bug + // A real Atari doesn't 'know' that an AVox is connected, so we + // shouldn't either + Controller& c = myConsole.controller(Controller::Right); if(c.type() == Controller::AtariVox) { c.write(Controller::One, !(value & 0x01)); @@ -405,7 +410,7 @@ bool M6532::load(Deserializer& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - M6532::M6532(const M6532& c) - : myConsole(c.myConsole) + : myConsole(c.myConsole) { assert(false); } diff --git a/stella/src/emucore/SpeakJet.cxx b/stella/src/emucore/SpeakJet.cxx index e393fcc0d..98a41f27b 100644 --- a/stella/src/emucore/SpeakJet.cxx +++ b/stella/src/emucore/SpeakJet.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: SpeakJet.cxx,v 1.7 2008-02-06 13:45:22 stephena Exp $ +// $Id: SpeakJet.cxx,v 1.8 2008-03-29 19:15:57 stephena Exp $ //============================================================================ #ifdef ATARIVOX_SUPPORT @@ -23,7 +23,6 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SpeakJet::SpeakJet() { - // Initialize output buffers. Each one points to the next element, // except the last, which points back to the first. SpeechBuffer *first = &outputBuffers[0]; @@ -87,7 +86,7 @@ void SpeakJet::write(uInt8 code) { // TODO: clean up this mess. const char *rsynthPhones = xlatePhoneme(code); - cerr << "rsynth: \"" << rsynthPhones << "\"" << endl; +// cerr << "rsynth: \"" << rsynthPhones << "\"" << endl; int len = strlen(rsynthPhones); if(ourInputCount + len + 1 >= INPUT_BUFFER_SIZE) { @@ -96,14 +95,14 @@ void SpeakJet::write(uInt8 code) } uInt32 sem = SDL_SemValue(ourInputSemaphore); - cerr << "write() waiting on semaphore (value " << sem << ")" << endl; +// cerr << "write() waiting on semaphore (value " << sem << ")" << endl; SDL_SemWait(ourInputSemaphore); - cerr << "write() got semaphore" << endl; +// cerr << "write() got semaphore" << endl; for(int i=0; icontents[ourCurrentWritePosition++] = output; diff --git a/stella/src/emucore/SpeakJet.hxx b/stella/src/emucore/SpeakJet.hxx index bf878987a..1fd8bff9e 100644 --- a/stella/src/emucore/SpeakJet.hxx +++ b/stella/src/emucore/SpeakJet.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: SpeakJet.hxx,v 1.8 2008-02-06 13:45:22 stephena Exp $ +// $Id: SpeakJet.hxx,v 1.9 2008-03-29 19:15:57 stephena Exp $ //============================================================================ #ifdef ATARIVOX_SUPPORT @@ -77,7 +77,7 @@ anyway). @author B. Watson - @version $Id: SpeakJet.hxx,v 1.8 2008-02-06 13:45:22 stephena Exp $ + @version $Id: SpeakJet.hxx,v 1.9 2008-03-29 19:15:57 stephena Exp $ */ #include "bspf.hxx" @@ -115,7 +115,7 @@ class SpeakJet */ SpeakJet(); - ~SpeakJet(); + virtual ~SpeakJet(); public: /**