Added keyboard controller to the debugger I/O tab.

Cleaned up the Event object in the EventHander, turning
it into a reference instead of a pointer (pointers are evil).

Minor speed optimization to Keyboard class; the update method
isn't required, since all work is done on the initial write().


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2350 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2012-01-09 17:23:44 +00:00
parent 13c797c428
commit 30bfa0e639
8 changed files with 115 additions and 113 deletions

View File

@ -35,6 +35,22 @@ KeyboardWidget::KeyboardWidget(GuiObject* boss, const GUI::Font& font,
t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth,
fontHeight, label, kTextAlignLeft);
xpos += 30; ypos += t->getHeight() + 10;
for(int i = 0; i < 12; ++i)
{
myBox[i] = new CheckboxWidget(boss, font, xpos, ypos, "", kCheckActionCmd);
myBox[i]->setID(i);
myBox[i]->setTarget(this);
xpos += myBox[i]->getWidth() + 5;
if((i+1) % 3 == 0)
{
xpos = x + 30;
ypos += myBox[i]->getHeight() + 5;
}
}
myEvent = leftport ? ourLeftEvents : ourRightEvents;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -45,10 +61,31 @@ KeyboardWidget::~KeyboardWidget()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void KeyboardWidget::loadConfig()
{
const Event& event = instance().eventHandler().event();
for(int i = 0; i < 12; ++i)
myBox[i]->setState(event.get(myEvent[i]));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void KeyboardWidget::handleCommand(
CommandSender* sender, int cmd, int data, int id)
{
if(cmd == kCheckActionCmd)
instance().eventHandler().handleEvent(myEvent[id], myBox[id]->getState());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type KeyboardWidget::ourLeftEvents[12] = {
Event::KeyboardZero1, Event::KeyboardZero2, Event::KeyboardZero3,
Event::KeyboardZero4, Event::KeyboardZero5, Event::KeyboardZero6,
Event::KeyboardZero7, Event::KeyboardZero8, Event::KeyboardZero9,
Event::KeyboardZeroStar, Event::KeyboardZero0, Event::KeyboardZeroPound
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type KeyboardWidget::ourRightEvents[12] = {
Event::KeyboardOne1, Event::KeyboardOne2, Event::KeyboardOne3,
Event::KeyboardOne4, Event::KeyboardOne5, Event::KeyboardOne6,
Event::KeyboardOne7, Event::KeyboardOne8, Event::KeyboardOne9,
Event::KeyboardOneStar, Event::KeyboardOne0, Event::KeyboardOnePound
};

View File

@ -35,6 +35,10 @@ class KeyboardWidget : public ControllerWidget
void handleCommand(CommandSender* sender, int cmd, int data, int id);
private:
CheckboxWidget* myBox[12];
Event::Type* myEvent;
static Event::Type ourLeftEvents[12], ourRightEvents[12];
};
#endif

View File

@ -68,26 +68,21 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props)
: myOSystem(osystem),
myEvent(osystem->eventHandler().event()),
myProperties(props),
myTIA(0),
mySwitches(0),
mySystem(0),
myCart(cart),
myDisplayFormat("NTSC"),
myFramerate(60.0),
myUserPaletteDefined(false)
{
myControllers[0] = 0;
myControllers[1] = 0;
myTIA = 0;
mySwitches = 0;
mySystem = 0;
myEvent = 0;
// Attach the event subsystem to the current console
myEvent = myOSystem->eventHandler().event();
// Load user-defined palette for this ROM
loadUserPalette();
// Create switches for the console
mySwitches = new Switches(*myEvent, myProperties);
mySwitches = new Switches(myEvent, myProperties);
// Construct the system and components
mySystem = new System(13, 6);
@ -109,7 +104,6 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props)
m6502->attach(myOSystem->debugger());
#endif
myCart = cart;
myRiot = new M6532(*this, myOSystem->settings());
myTIA = new TIA(*this, myOSystem->sound(), myOSystem->settings());
@ -592,8 +586,7 @@ void Console::changeHeight(int direction)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Console::setControllers(const string& rommd5)
{
delete myControllers[0];
delete myControllers[1];
myControllers[0] = myControllers[1] = 0;
// Setup the controllers based on properties
const string& left = myProperties.get(Controller_Left);
@ -616,15 +609,15 @@ void Console::setControllers(const string& rommd5)
// Construct left controller
if(left == "BOOSTERGRIP")
{
myControllers[leftPort] = new BoosterGrip(Controller::Left, *myEvent, *mySystem);
myControllers[leftPort] = new BoosterGrip(Controller::Left, myEvent, *mySystem);
}
else if(left == "DRIVING")
{
myControllers[leftPort] = new Driving(Controller::Left, *myEvent, *mySystem);
myControllers[leftPort] = new Driving(Controller::Left, myEvent, *mySystem);
}
else if((left == "KEYBOARD") || (left == "KEYPAD"))
{
myControllers[leftPort] = new Keyboard(Controller::Left, *myEvent, *mySystem);
myControllers[leftPort] = new Keyboard(Controller::Left, myEvent, *mySystem);
}
else if(BSPF_startsWithIgnoreCase(left, "PADDLES"))
{
@ -636,53 +629,53 @@ void Console::setControllers(const string& rommd5)
else if(left == "PADDLES_IAXDR")
swapAxis = swapDir = true;
myControllers[leftPort] =
new Paddles(Controller::Left, *myEvent, *mySystem,
new Paddles(Controller::Left, myEvent, *mySystem,
swapPaddles, swapAxis, swapDir);
}
else if(left == "TRACKBALL22")
{
myControllers[leftPort] = new TrackBall(Controller::Left, *myEvent, *mySystem,
myControllers[leftPort] = new TrackBall(Controller::Left, myEvent, *mySystem,
Controller::TrackBall22);
}
else if(left == "TRACKBALL80")
{
myControllers[leftPort] = new TrackBall(Controller::Left, *myEvent, *mySystem,
myControllers[leftPort] = new TrackBall(Controller::Left, myEvent, *mySystem,
Controller::TrackBall80);
}
else if(left == "AMIGAMOUSE")
{
myControllers[leftPort] = new TrackBall(Controller::Left, *myEvent, *mySystem,
myControllers[leftPort] = new TrackBall(Controller::Left, myEvent, *mySystem,
Controller::AmigaMouse);
}
else if(left == "GENESIS")
{
myControllers[leftPort] = new Genesis(Controller::Left, *myEvent, *mySystem);
myControllers[leftPort] = new Genesis(Controller::Left, myEvent, *mySystem);
}
else if(left == "COMPUMATE")
{
myControllers[leftPort] = new CompuMate(Controller::Left, *myEvent, *mySystem);
myControllers[leftPort] = new CompuMate(Controller::Left, myEvent, *mySystem);
}
else if(left == "MINDLINK")
{
myControllers[leftPort] = new MindLink(Controller::Left, *myEvent, *mySystem);
myControllers[leftPort] = new MindLink(Controller::Left, myEvent, *mySystem);
}
else
{
myControllers[leftPort] = new Joystick(Controller::Left, *myEvent, *mySystem);
myControllers[leftPort] = new Joystick(Controller::Left, myEvent, *mySystem);
}
// Construct right controller
if(right == "BOOSTERGRIP")
{
myControllers[rightPort] = new BoosterGrip(Controller::Right, *myEvent, *mySystem);
myControllers[rightPort] = new BoosterGrip(Controller::Right, myEvent, *mySystem);
}
else if(right == "DRIVING")
{
myControllers[rightPort] = new Driving(Controller::Right, *myEvent, *mySystem);
myControllers[rightPort] = new Driving(Controller::Right, myEvent, *mySystem);
}
else if((right == "KEYBOARD") || (right == "KEYPAD"))
{
myControllers[rightPort] = new Keyboard(Controller::Right, *myEvent, *mySystem);
myControllers[rightPort] = new Keyboard(Controller::Right, myEvent, *mySystem);
}
else if(BSPF_startsWithIgnoreCase(right, "PADDLES"))
{
@ -694,56 +687,56 @@ void Console::setControllers(const string& rommd5)
else if(right == "PADDLES_IAXDR")
swapAxis = swapDir = true;
myControllers[rightPort] =
new Paddles(Controller::Right, *myEvent, *mySystem,
new Paddles(Controller::Right, myEvent, *mySystem,
swapPaddles, swapAxis, swapDir);
}
else if(right == "TRACKBALL22")
{
myControllers[rightPort] = new TrackBall(Controller::Left, *myEvent, *mySystem,
myControllers[rightPort] = new TrackBall(Controller::Left, myEvent, *mySystem,
Controller::TrackBall22);
}
else if(right == "TRACKBALL80")
{
myControllers[rightPort] = new TrackBall(Controller::Left, *myEvent, *mySystem,
myControllers[rightPort] = new TrackBall(Controller::Left, myEvent, *mySystem,
Controller::TrackBall80);
}
else if(right == "AMIGAMOUSE")
{
myControllers[rightPort] = new TrackBall(Controller::Left, *myEvent, *mySystem,
myControllers[rightPort] = new TrackBall(Controller::Left, myEvent, *mySystem,
Controller::AmigaMouse);
}
else if(right == "ATARIVOX")
{
const string& eepromfile = myOSystem->eepromDir() + "atarivox_eeprom.dat";
myControllers[rightPort] = new AtariVox(Controller::Right, *myEvent,
myControllers[rightPort] = new AtariVox(Controller::Right, myEvent,
*mySystem, myOSystem->serialPort(),
myOSystem->settings().getString("avoxport"), eepromfile);
}
else if(right == "SAVEKEY")
{
const string& eepromfile = myOSystem->eepromDir() + "savekey_eeprom.dat";
myControllers[rightPort] = new SaveKey(Controller::Right, *myEvent, *mySystem,
myControllers[rightPort] = new SaveKey(Controller::Right, myEvent, *mySystem,
eepromfile);
}
else if(right == "GENESIS")
{
myControllers[rightPort] = new Genesis(Controller::Right, *myEvent, *mySystem);
myControllers[rightPort] = new Genesis(Controller::Right, myEvent, *mySystem);
}
else if(right == "COMPUMATE")
{
myControllers[rightPort] = new CompuMate(Controller::Right, *myEvent, *mySystem);
myControllers[rightPort] = new CompuMate(Controller::Right, myEvent, *mySystem);
}
else if(right == "KIDVID")
{
myControllers[rightPort] = new KidVid(Controller::Right, *myEvent, *mySystem, rommd5);
myControllers[rightPort] = new KidVid(Controller::Right, myEvent, *mySystem, rommd5);
}
else if(right == "MINDLINK")
{
myControllers[rightPort] = new MindLink(Controller::Right, *myEvent, *mySystem);
myControllers[rightPort] = new MindLink(Controller::Right, myEvent, *mySystem);
}
else
{
myControllers[rightPort] = new Joystick(Controller::Right, *myEvent, *mySystem);
myControllers[rightPort] = new Joystick(Controller::Right, myEvent, *mySystem);
}
myControllers[leftPort]->enable(false);
@ -1130,7 +1123,8 @@ uInt32 Console::ourUserSECAMPalette[256] = { 0 }; // filled from external file
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Console::Console(const Console& console)
: myOSystem(console.myOSystem)
: myOSystem(console.myOSystem),
myEvent(console.myEvent)
{
assert(false);
}

View File

@ -313,18 +313,18 @@ class Console : public Serializable
// Pointer to the osystem object
OSystem* myOSystem;
// Pointers to the left and right controllers
Controller* myControllers[2];
// Pointer to the event object to use
Event* myEvent;
// Pointer to the TIA object
TIA* myTIA;
// Reference to the event object to use
Event& myEvent;
// Properties for the game
Properties myProperties;
// Pointers to the left and right controllers
Controller* myControllers[2];
// Pointer to the TIA object
TIA* myTIA;
// Pointer to the switches on the front of the console
Switches* mySwitches;

View File

@ -57,7 +57,6 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandler::EventHandler(OSystem* osystem)
: myOSystem(osystem),
myEvent(NULL),
myOverlay(NULL),
myState(S_NONE),
myAllowAllDirectionsFlag(false),
@ -66,9 +65,6 @@ EventHandler::EventHandler(OSystem* osystem)
myJoysticks(NULL),
myNumJoysticks(0)
{
// Create the event object which will be used for this handler
myEvent = new Event();
// Erase the key mapping array
for(int i = 0; i < SDLK_LAST; ++i)
{
@ -107,7 +103,6 @@ EventHandler::~EventHandler()
free(ourMenuActionList[i].key);
delete[] myJoysticks;
delete myEvent;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -609,8 +604,8 @@ void EventHandler::poll(uInt64 time)
{
if(!mySkipMouseMotion)
{
myEvent->set(Event::MouseAxisXValue, event.motion.xrel);
myEvent->set(Event::MouseAxisYValue, event.motion.yrel);
myEvent.set(Event::MouseAxisXValue, event.motion.xrel);
myEvent.set(Event::MouseAxisYValue, event.motion.yrel);
}
mySkipMouseMotion = false;
}
@ -627,7 +622,7 @@ void EventHandler::poll(uInt64 time)
// Determine which mode we're in, then send the event to the appropriate place
if(myState == S_EMULATE)
{
myEvent->set(Event::MouseButtonValue, state);
myEvent.set(Event::MouseButtonValue, state);
}
else if(myOverlay)
{
@ -705,14 +700,14 @@ void EventHandler::poll(uInt64 time)
// The 'type-2' here refers to the fact that 'StellaJoystick::JT_STELLADAPTOR_LEFT'
// and 'StellaJoystick::JT_STELLADAPTOR_RIGHT' are at index 2 and 3 in the JoyType
// enum; subtracting two gives us Controller 0 and 1
if(button < 2) myEvent->set(SA_Button[joy.type-2][button], state);
if(button < 2) myEvent.set(SA_Button[joy.type-2][button], state);
break; // Stelladaptor button
case StellaJoystick::JT_2600DAPTOR_LEFT:
case StellaJoystick::JT_2600DAPTOR_RIGHT:
// The 'type-4' here refers to the fact that 'StellaJoystick::JT_2600DAPTOR_LEFT'
// and 'StellaJoystick::JT_2600DAPTOR_RIGHT' are at index 4 and 5 in the JoyType
// enum; subtracting four gives us Controller 0 and 1
if(button < 2) myEvent->set(SA_Button[joy.type-4][button], state);
if(button < 2) myEvent.set(SA_Button[joy.type-4][button], state);
break; // 2600DAPTOR button
default:
break;
@ -746,16 +741,16 @@ void EventHandler::poll(uInt64 time)
switch((int)eventAxisNeg)
{
case Event::PaddleZeroAnalog:
myEvent->set(Event::SALeftAxis0Value, value);
myEvent.set(Event::SALeftAxis0Value, value);
break;
case Event::PaddleOneAnalog:
myEvent->set(Event::SALeftAxis1Value, value);
myEvent.set(Event::SALeftAxis1Value, value);
break;
case Event::PaddleTwoAnalog:
myEvent->set(Event::SARightAxis0Value, value);
myEvent.set(Event::SARightAxis0Value, value);
break;
case Event::PaddleThreeAnalog:
myEvent->set(Event::SARightAxis1Value, value);
myEvent.set(Event::SARightAxis1Value, value);
break;
default:
{
@ -816,7 +811,7 @@ void EventHandler::poll(uInt64 time)
// and 'StellaJoystick::JT_STELLADAPTOR_RIGHT' are at index 2 and 3 in the JoyType
// enum; subtracting two gives us Controller 0 and 1
if(axis < 2)
myEvent->set(SA_Axis[type-2][axis], value);
myEvent.set(SA_Axis[type-2][axis], value);
break; // Stelladaptor axis
case StellaJoystick::JT_2600DAPTOR_LEFT:
case StellaJoystick::JT_2600DAPTOR_RIGHT:
@ -824,7 +819,7 @@ void EventHandler::poll(uInt64 time)
// and 'StellaJoystick::JT_2600DAPTOR_RIGHT' are at index 4 and 5 in the JoyType
// enum; subtracting four gives us Controller 0 and 1
if(axis < 2)
myEvent->set(SA_Axis[type-4][axis], value);
myEvent.set(SA_Axis[type-4][axis], value);
break; // 26000daptor axis
}
break; // SDL_JOYAXISMOTION
@ -916,8 +911,8 @@ void EventHandler::poll(uInt64 time)
// Turn off all mouse-related items; if they haven't been taken care of
// in the previous ::update() methods, they're now invalid
myEvent->set(Event::MouseAxisXValue, 0);
myEvent->set(Event::MouseAxisYValue, 0);
myEvent.set(Event::MouseAxisXValue, 0);
myEvent.set(Event::MouseAxisYValue, 0);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -931,42 +926,42 @@ void EventHandler::handleEvent(Event::Type event, int state)
// If enabled, make sure 'impossible' joystick directions aren't allowed
case Event::JoystickZeroUp:
if(!myAllowAllDirectionsFlag && state)
myEvent->set(Event::JoystickZeroDown, 0);
myEvent.set(Event::JoystickZeroDown, 0);
break;
case Event::JoystickZeroDown:
if(!myAllowAllDirectionsFlag && state)
myEvent->set(Event::JoystickZeroUp, 0);
myEvent.set(Event::JoystickZeroUp, 0);
break;
case Event::JoystickZeroLeft:
if(!myAllowAllDirectionsFlag && state)
myEvent->set(Event::JoystickZeroRight, 0);
myEvent.set(Event::JoystickZeroRight, 0);
break;
case Event::JoystickZeroRight:
if(!myAllowAllDirectionsFlag && state)
myEvent->set(Event::JoystickZeroLeft, 0);
myEvent.set(Event::JoystickZeroLeft, 0);
break;
case Event::JoystickOneUp:
if(!myAllowAllDirectionsFlag && state)
myEvent->set(Event::JoystickOneDown, 0);
myEvent.set(Event::JoystickOneDown, 0);
break;
case Event::JoystickOneDown:
if(!myAllowAllDirectionsFlag && state)
myEvent->set(Event::JoystickOneUp, 0);
myEvent.set(Event::JoystickOneUp, 0);
break;
case Event::JoystickOneLeft:
if(!myAllowAllDirectionsFlag && state)
myEvent->set(Event::JoystickOneRight, 0);
myEvent.set(Event::JoystickOneRight, 0);
break;
case Event::JoystickOneRight:
if(!myAllowAllDirectionsFlag && state)
myEvent->set(Event::JoystickOneLeft, 0);
myEvent.set(Event::JoystickOneLeft, 0);
break;
////////////////////////////////////////////////////////////////////////
@ -1061,7 +1056,7 @@ void EventHandler::handleEvent(Event::Type event, int state)
myOSystem->frameBuffer().showMessage(ourMessageTable[event]);
// Otherwise, pass it to the emulation core
myEvent->set(event, state);
myEvent.set(event, state);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -2089,7 +2084,7 @@ void EventHandler::setEventState(State state)
}
// Always clear any pending events when changing states
myEvent->clear();
myEvent.clear();
// Sometimes an extraneous mouse motion event is generated
// after a state change, which should be supressed

View File

@ -101,7 +101,7 @@ class EventHandler
@return The event object
*/
Event* event() { return myEvent; }
Event& event() { return myEvent; }
/**
Initialize state of this eventhandler.
@ -369,7 +369,7 @@ class EventHandler
OSystem* myOSystem;
// Global Event object
Event* myEvent;
Event myEvent;
// Indicates current overlay object
DialogContainer* myOverlay;

View File

@ -22,8 +22,7 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Keyboard::Keyboard(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::Keyboard),
myPinState(0)
: Controller(jack, event, system, Controller::Keyboard)
{
if(myJack == Left)
{
@ -65,66 +64,42 @@ Keyboard::~Keyboard()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Keyboard::write(DigitalPin pin, bool value)
{
// Change the pin state based on value
switch(pin)
{
case One:
myPinState = (myPinState & 0x0E) | (value ? 0x01 : 0x00);
break;
case Two:
myPinState = (myPinState & 0x0D) | (value ? 0x02 : 0x00);
break;
case Three:
myPinState = (myPinState & 0x0B) | (value ? 0x04 : 0x00);
break;
case Four:
myPinState = (myPinState & 0x07) | (value ? 0x08 : 0x00);
break;
myDigitalPinState[pin] = value;
default:
break;
}
// State has probably changed, so recalculate it
update();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Keyboard::update()
{
myDigitalPinState[One] = (myPinState & 0x01);
myDigitalPinState[Two] = (myPinState & 0x02);
myDigitalPinState[Three] = (myPinState & 0x04);
myDigitalPinState[Four] = (myPinState & 0x08);
// Set defaults
myDigitalPinState[Six] = true;
myAnalogPinValue[Five] = minimumResistance;
myAnalogPinValue[Nine] = minimumResistance;
// Now scan the rows and columns
if(!(myPinState & 0x08))
if(!myDigitalPinState[Four])
{
myDigitalPinState[Six] = (myEvent.get(myPoundEvent) == 0);
if(myEvent.get(myZeroEvent) != 0) myAnalogPinValue[Five] = maximumResistance;
if(myEvent.get(myStarEvent) != 0) myAnalogPinValue[Nine] = maximumResistance;
}
if(!(myPinState & 0x04))
if(!myDigitalPinState[Three])
{
myDigitalPinState[Six] = (myEvent.get(myNineEvent) == 0);
if(myEvent.get(myEightEvent) != 0) myAnalogPinValue[Five] = maximumResistance;
if(myEvent.get(mySevenEvent) != 0) myAnalogPinValue[Nine] = maximumResistance;
}
if(!(myPinState & 0x02))
if(!myDigitalPinState[Two])
{
myDigitalPinState[Six] = (myEvent.get(mySixEvent) == 0);
if(myEvent.get(myFiveEvent) != 0) myAnalogPinValue[Five] = maximumResistance;
if(myEvent.get(myFourEvent) != 0) myAnalogPinValue[Nine] = maximumResistance;
}
if(!(myPinState & 0x01))
if(!myDigitalPinState[One])
{
myDigitalPinState[Six] = (myEvent.get(myThreeEvent) == 0);
if(myEvent.get(myTwoEvent) != 0) myAnalogPinValue[Five] = maximumResistance;

View File

@ -62,12 +62,9 @@ class Keyboard : public Controller
Update the entire digital and analog pin state according to the
events currently set.
*/
void update();
void update() { }
private:
// State of the output pins
uInt8 myPinState;
// Pre-compute the events we care about based on given port
// This will eliminate test for left or right port in update()
Event::Type myOneEvent, myTwoEvent, myThreeEvent,