diff --git a/stella/src/emucore/Deserializer.cxx b/stella/src/emucore/Deserializer.cxx index be9055c3a..b3896ff11 100644 --- a/stella/src/emucore/Deserializer.cxx +++ b/stella/src/emucore/Deserializer.cxx @@ -13,14 +13,13 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Deserializer.cxx,v 1.7 2005-12-17 01:23:07 stephena Exp $ +// $Id: Deserializer.cxx,v 1.8 2005-12-17 22:48:24 stephena Exp $ //============================================================================ #include "Deserializer.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deserializer::Deserializer(void) - : myStream(0) { } @@ -34,7 +33,7 @@ Deserializer::~Deserializer(void) bool Deserializer::open(const string& fileName) { close(); - myStream = new ifstream(fileName.c_str(), ios::in | ios::binary); + myStream.open(fileName.c_str(), ios::in | ios::binary); return isOpen(); } @@ -42,31 +41,24 @@ bool Deserializer::open(const string& fileName) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Deserializer::close(void) { - if(myStream) - { - if(myStream->is_open()) - myStream->close(); - - delete myStream; - myStream = (ifstream*) 0; - } + myStream.close(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Deserializer::isOpen(void) { - return myStream && myStream->is_open(); + return myStream && myStream.is_open(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int Deserializer::getInt(void) { - if(myStream->eof()) + if(myStream.eof()) throw "Deserializer: end of file"; int val = 0; unsigned char buf[4]; - myStream->read((char*)buf, 4); + myStream.read((char*)buf, 4); for(int i = 0; i < 4; ++i) val += (int)(buf[i]) << (i<<3); @@ -79,9 +71,9 @@ string Deserializer::getString(void) int len = getInt(); string str; str.resize((string::size_type)len); - myStream->read(&str[0], (streamsize)len); + myStream.read(&str[0], (streamsize)len); - if(myStream->bad()) + if(myStream.bad()) throw "Deserializer: file read failed"; return str; @@ -93,9 +85,6 @@ bool Deserializer::getBool(void) bool result = false; int b = getInt(); - if(myStream->bad()) - throw "Deserializer: file read failed"; - if(b == (int)TruePattern) result = true; else if(b == (int)FalsePattern) diff --git a/stella/src/emucore/Deserializer.hxx b/stella/src/emucore/Deserializer.hxx index 1f64bc6a3..63ee80185 100644 --- a/stella/src/emucore/Deserializer.hxx +++ b/stella/src/emucore/Deserializer.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: Deserializer.hxx,v 1.8 2005-12-17 01:23:07 stephena Exp $ +// $Id: Deserializer.hxx,v 1.9 2005-12-17 22:48:24 stephena Exp $ //============================================================================ #ifndef DESERIALIZER_HXX @@ -31,7 +31,7 @@ return. @author Stephen Anthony - @version $Id: Deserializer.hxx,v 1.8 2005-12-17 01:23:07 stephena Exp $ + @version $Id: Deserializer.hxx,v 1.9 2005-12-17 22:48:24 stephena Exp $ */ class Deserializer { @@ -92,7 +92,7 @@ class Deserializer private: // The stream to get the deserialized data from. - ifstream* myStream; + fstream myStream; enum { TruePattern = 0xfab1fab2, diff --git a/stella/src/emucore/Event.hxx b/stella/src/emucore/Event.hxx index 58d355e8b..88e9776c6 100644 --- a/stella/src/emucore/Event.hxx +++ b/stella/src/emucore/Event.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: Event.hxx,v 1.16 2005-12-12 19:04:03 stephena Exp $ +// $Id: Event.hxx,v 1.17 2005-12-17 22:48:24 stephena Exp $ //============================================================================ #ifndef EVENT_HXX @@ -27,7 +27,7 @@ class Serializer; /** @author Bradford W. Mott - @version $Id: Event.hxx,v 1.16 2005-12-12 19:04:03 stephena Exp $ + @version $Id: Event.hxx,v 1.17 2005-12-17 22:48:24 stephena Exp $ */ class Event { @@ -53,10 +53,14 @@ class Event BoosterGripZeroTrigger, BoosterGripZeroBooster, BoosterGripOneTrigger, BoosterGripOneBooster, - PaddleZeroResistance, PaddleZeroFire, PaddleZeroDecrease, PaddleZeroIncrease, - PaddleOneResistance, PaddleOneFire, PaddleOneDecrease, PaddleOneIncrease, - PaddleTwoResistance, PaddleTwoFire, PaddleTwoDecrease, PaddleTwoIncrease, - PaddleThreeResistance, PaddleThreeFire, PaddleThreeDecrease, PaddleThreeIncrease, + PaddleZeroResistance, PaddleZeroFire, + PaddleZeroDecrease, PaddleZeroIncrease, PaddleZeroAnalog, + PaddleOneResistance, PaddleOneFire, + PaddleOneDecrease, PaddleOneIncrease, PaddleOneAnalog, + PaddleTwoResistance, PaddleTwoFire, + PaddleTwoDecrease, PaddleTwoIncrease, PaddleTwoAnalog, + PaddleThreeResistance, PaddleThreeFire, + PaddleThreeDecrease, PaddleThreeIncrease, PaddleThreeAnalog, KeyboardZero1, KeyboardZero2, KeyboardZero3, KeyboardZero4, KeyboardZero5, KeyboardZero6, diff --git a/stella/src/emucore/EventHandler.cxx b/stella/src/emucore/EventHandler.cxx index f1abfd975..f95d945a7 100644 --- a/stella/src/emucore/EventHandler.cxx +++ b/stella/src/emucore/EventHandler.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: EventHandler.cxx,v 1.128 2005-12-16 14:41:14 stephena Exp $ +// $Id: EventHandler.cxx,v 1.129 2005-12-17 22:48:24 stephena Exp $ //============================================================================ #include @@ -1052,42 +1052,6 @@ void EventHandler::handleJoyAxisEvent(int stick, int axis, int value) Event::Type eventAxisNeg = myJoyAxisTable[stick][axis][0]; Event::Type eventAxisPos = myJoyAxisTable[stick][axis][1]; - // Paddle emulation *REALLY* complicates this method - if(value == 0) - { - if(0)//stick is analog && (isPaddleEvent(eventAxisNeg) || isPaddleEvent(eventAxisPos))) - { - // deal with zero value for analog input - } - else - { - // Turn off both events, since we don't know exactly which one - // was previously activated. - handleEvent(eventAxisNeg, 0); - handleEvent(eventAxisPos, 0); - } - } - else if(value < 0) - { - if(0)//stick is analog && isPaddleEvent(eventAxisNeg)) - { - // turn on paddle event defined here - } - else - handleEvent(eventAxisNeg, 1); - } - else // value > 0 - { - if(0)//stick is analog && isPaddleEvent(eventAxisPos)) - { - // turn on paddle event defined here - } - else - handleEvent(eventAxisPos, 1); - } - -/* - // FIXME - This isn't ready for production use just yet ... // Determine what type of axis we're dealing with // Figure out the actual type if it's undefined JoyAxisType type = myJoyAxisType[stick][axis]; @@ -1100,69 +1064,43 @@ void EventHandler::handleJoyAxisEvent(int stick, int axis, int value) type = myJoyAxisType[stick][axis] = JA_ANALOG; } - // Make use of an analog axis/stick for those events that are analog - // in nature (currently only paddle resistance). - // If an event is analog in nature but the axis is digital, then - // emulate the analog values. - switch((int)type) + // Paddle emulation *REALLY* complicates this method + if(type == JA_ANALOG) { - case JA_ANALOG: - switch((int)eventAxisNeg) - { - case Event::PaddleZeroResistance: - case Event::PaddleOneResistance: - case Event::PaddleTwoResistance: - case Event::PaddleThreeResistance: - { - if(value > 0) break; - int resistance = (int) (1000000.0 * -value / 32767); - myEvent->set(eventAxisNeg, resistance); - return; - break; - } - } - switch((int)eventAxisPos) - { - case Event::PaddleZeroResistance: - case Event::PaddleOneResistance: - case Event::PaddleTwoResistance: - case Event::PaddleThreeResistance: - { - if(value < 0) return; - int resistance = (int) (1000000.0 * value / 32767); - myEvent->set(eventAxisPos, resistance); - return; - break; - } - } - break; - - case JA_DIGITAL: - switch((int)eventAxisNeg) - { - case Event::PaddleZeroResistance: - case Event::PaddleOneResistance: - case Event::PaddleTwoResistance: - case Event::PaddleThreeResistance: - if(value > 0) break; - cerr << "paddle resistance - from digital axis\n"; - return; - break; - } - switch((int)eventAxisPos) - { - case Event::PaddleZeroResistance: - case Event::PaddleOneResistance: - case Event::PaddleTwoResistance: - case Event::PaddleThreeResistance: - if(value < 0) return; - cerr << "paddle resistance + from digital axis\n"; - return; - break; - } - break; + int idx = -1; + switch((int)eventAxisNeg) + { + case Event::PaddleZeroAnalog: + idx = 0; + break; + case Event::PaddleOneAnalog: + idx = 1; + break; + case Event::PaddleTwoAnalog: + idx = 2; + break; + case Event::PaddleThreeAnalog: + idx = 3; + break; + } + if(idx >= 0) + { + int resistance = (int)(1000000.0 * (32767 - value) / 65534); + myEvent->set(Paddle_Resistance[idx], resistance); + return; + } } -*/ + + // Otherwise, we know the event is digital + if(value == 0) + { + // Turn off both events, since we don't know exactly which one + // was previously activated. + handleEvent(eventAxisNeg, 0); + handleEvent(eventAxisPos, 0); + } + else + handleEvent(value < 0 ? eventAxisNeg : eventAxisPos, 1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1391,7 +1329,12 @@ void EventHandler::setActionMappings() buf.str(""); buf << "J" << stick << " axis " << axis; if(eventIsAnalog(event)) + { + myJoyAxisTable[stick][axis][0] = event; + myJoyAxisTable[stick][axis][1] = event; + dir = 2; // Immediately exit the inner loop after this iteration buf << " abs"; + } else if(dir == 0) buf << " neg"; else @@ -1764,18 +1707,10 @@ inline bool EventHandler::eventIsAnalog(Event::Type event) { switch((int)event) { - case Event::PaddleZeroResistance: - case Event::PaddleZeroDecrease: - case Event::PaddleZeroIncrease: - case Event::PaddleOneResistance: - case Event::PaddleOneDecrease: - case Event::PaddleOneIncrease: - case Event::PaddleTwoResistance: - case Event::PaddleTwoDecrease: - case Event::PaddleTwoIncrease: - case Event::PaddleThreeResistance: - case Event::PaddleThreeDecrease: - case Event::PaddleThreeIncrease: + case Event::PaddleZeroAnalog: + case Event::PaddleOneAnalog: + case Event::PaddleTwoAnalog: + case Event::PaddleThreeAnalog: return true; default: return false; @@ -1926,7 +1861,6 @@ void EventHandler::startRecording() return; string eventfile = /*myOSystem->baseDir() + BSPF_PATH_SEPARATOR +*/ "test.inp"; - myEventStream.close(); if(!myEventStream.open(eventfile)) { myOSystem->frameBuffer().showMessage("Error opening eventstream"); @@ -2385,22 +2319,22 @@ ActionList EventHandler::ourActionList[kActionListSize] = { { Event::JoystickOneRight, "P2 Joystick Right", "" }, { Event::JoystickOneFire, "P2 Joystick Fire", "" }, -// { Event::PaddleZeroAnalog, "Paddle 1 Analog", "" }, + { Event::PaddleZeroAnalog, "Paddle 1 Analog", "" }, { Event::PaddleZeroDecrease, "Paddle 1 Decrease", "" }, { Event::PaddleZeroIncrease, "Paddle 1 Increase", "" }, { Event::PaddleZeroFire, "Paddle 1 Fire", "" }, -// { Event::PaddleOneAnalog, "Paddle 2 Analog", "" }, + { Event::PaddleOneAnalog, "Paddle 2 Analog", "" }, { Event::PaddleOneDecrease, "Paddle 2 Decrease", "" }, { Event::PaddleOneIncrease, "Paddle 2 Increase", "" }, { Event::PaddleOneFire, "Paddle 2 Fire", "" }, -// { Event::PaddleTwoAnalog, "Paddle 3 Analog", "" }, + { Event::PaddleTwoAnalog, "Paddle 3 Analog", "" }, { Event::PaddleTwoDecrease, "Paddle 3 Decrease", "" }, { Event::PaddleTwoIncrease, "Paddle 3 Increase", "" }, { Event::PaddleTwoFire, "Paddle 3 Fire", "" }, -// { Event::PaddleThreeAnalog, "Paddle 4 Analog", "" }, + { Event::PaddleThreeAnalog, "Paddle 4 Analog", "" }, { Event::PaddleThreeDecrease, "Paddle 4 Decrease", "" }, { Event::PaddleThreeIncrease, "Paddle 4 Increase", "" }, { Event::PaddleThreeFire, "Paddle 4 Fire", "" }, diff --git a/stella/src/emucore/EventHandler.hxx b/stella/src/emucore/EventHandler.hxx index 35a8eed78..141d238c3 100644 --- a/stella/src/emucore/EventHandler.hxx +++ b/stella/src/emucore/EventHandler.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: EventHandler.hxx,v 1.66 2005-12-16 14:41:14 stephena Exp $ +// $Id: EventHandler.hxx,v 1.67 2005-12-17 22:48:24 stephena Exp $ //============================================================================ #ifndef EVENTHANDLER_HXX @@ -50,7 +50,7 @@ struct ActionList { }; enum { - kActionListSize = 75 + kActionListSize = 79 }; // Joystick related items @@ -92,7 +92,7 @@ struct Stella_Joystick { mapping can take place. @author Stephen Anthony - @version $Id: EventHandler.hxx,v 1.66 2005-12-16 14:41:14 stephena Exp $ + @version $Id: EventHandler.hxx,v 1.67 2005-12-17 22:48:24 stephena Exp $ */ class EventHandler { diff --git a/stella/src/emucore/Serializer.cxx b/stella/src/emucore/Serializer.cxx index eefd6fd2a..a4d182a2c 100644 --- a/stella/src/emucore/Serializer.cxx +++ b/stella/src/emucore/Serializer.cxx @@ -13,14 +13,13 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Serializer.cxx,v 1.7 2005-12-17 01:23:07 stephena Exp $ +// $Id: Serializer.cxx,v 1.8 2005-12-17 22:48:24 stephena Exp $ //============================================================================ #include "Serializer.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Serializer::Serializer(void) - : myStream(0) { } @@ -34,7 +33,7 @@ Serializer::~Serializer(void) bool Serializer::open(const string& fileName) { close(); - myStream = new ofstream(fileName.c_str(), ios::out | ios::binary); + myStream.open(fileName.c_str(), ios::out | ios::binary); return isOpen(); } @@ -42,20 +41,13 @@ bool Serializer::open(const string& fileName) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Serializer::close(void) { - if(myStream) - { - if(myStream->is_open()) - myStream->close(); - - delete myStream; - myStream = (ofstream*) 0; - } + myStream.close(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Serializer::isOpen(void) { - return myStream && myStream->is_open(); + return myStream.is_open(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -65,8 +57,8 @@ void Serializer::putInt(int value) for(int i = 0; i < 4; ++i) buf[i] = (value >> (i<<3)) & 0xff; - myStream->write((char*)buf, 4); - if(myStream->bad()) + myStream.write((char*)buf, 4); + if(myStream.bad()) throw "Serializer: file write failed"; } @@ -75,18 +67,14 @@ void Serializer::putString(const string& str) { int len = str.length(); putInt(len); - myStream->write(str.data(), (streamsize)len); + myStream.write(str.data(), (streamsize)len); - if(myStream->bad()) + if(myStream.bad()) throw "Serializer: file write failed"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Serializer::putBool(bool b) { - int l = b ? TruePattern: FalsePattern; - putInt(l); - - if(myStream->bad ()) - throw "Serializer: file write failed"; + putInt(b ? TruePattern: FalsePattern); } diff --git a/stella/src/emucore/Serializer.hxx b/stella/src/emucore/Serializer.hxx index 68e6a8bc6..1b0848863 100644 --- a/stella/src/emucore/Serializer.hxx +++ b/stella/src/emucore/Serializer.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: Serializer.hxx,v 1.9 2005-12-17 01:23:07 stephena Exp $ +// $Id: Serializer.hxx,v 1.10 2005-12-17 22:48:24 stephena Exp $ //============================================================================ #ifndef SERIALIZER_HXX @@ -32,7 +32,7 @@ Boolean values are written using a special pattern. @author Stephen Anthony - @version $Id: Serializer.hxx,v 1.9 2005-12-17 01:23:07 stephena Exp $ + @version $Id: Serializer.hxx,v 1.10 2005-12-17 22:48:24 stephena Exp $ */ class Serializer { @@ -93,7 +93,7 @@ class Serializer private: // The stream to send the serialized data to. - ofstream* myStream; + fstream myStream; enum { TruePattern = 0xfab1fab2,