mirror of https://github.com/stella-emu/stella.git
Added mapping of analog joystick axes to paddle events.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@913 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
0f90b07e1a
commit
37bf0dc029
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 <algorithm>
|
||||
|
@ -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", "" },
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue