/* NEStopia / Linux Port by R. Belmont input.cpp - input handling */ #include #include #include #include #include #include #include "core/api/NstApiEmulator.hpp" #include "core/api/NstApiVideo.hpp" #include "core/api/NstApiSound.hpp" #include "core/api/NstApiMachine.hpp" #include "core/api/NstApiUser.hpp" #include "core/api/NstApiNsf.hpp" #include "core/api/NstApiMovie.hpp" #include "core/api/NstApiFds.hpp" #include "core/api/NstApiRewinder.hpp" #include "oss.h" #include "settings.h" #include "auxio.h" #include "input.h" #include "kentry.h" static char linebuf[256]; static FILE *infile; // translate player control to Nes::Api code static int translate_code(const char *str) { int i = kentry_find_str(controlcodes, str); if (i == -1) std::cout << "Error understanding control type '" << str << "'\n"; return i; } // translate key descriptor into SDL keycode static bool translate_key(const char *substr, SDL_Event &evt) { evt.type = SDL_KEYDOWN; evt.key.keysym.sym = (SDLKey)0; evt.key.keysym.mod = (SDLMod)0; if (substr[0] != '_') // literal case { evt.key.keysym.sym = SDLKey(tolower(substr[0])); return true; } if (substr[1] == '_') // quoted _ { evt.key.keysym.sym = SDLKey('_'); return true; } int i = kentry_find_str(keycodes, substr + 1); if (i == -1) { std::cout << "unknown key " << substr << "\n"; return false; } evt.key.keysym.sym = SDLKey(i); return true; } // translate event type into InputEvtT value static int translate_meta(const char *str) { int i = kentry_find_str(metacodes, str); if (i == -1) { std::cout << "invalid event type '" << str << "'\n"; } return i; } // add a control to the list, fail if we're full bool add_control(const InputDefT &control, InputDefT *pcontrol, int &icontrol, int ccontrol) { if (icontrol >= ccontrol) { std::cout << "Too many controls (max " << ccontrol << ")\n"; return false; } memcpy(pcontrol + icontrol++, &control, sizeof(control)); return true; } // translate joystick/gamepad spec: // _ ( A | B