- [NEW] Ja funciona el joystick tipus Kempston
This commit is contained in:
43
gamepad.cpp
43
gamepad.cpp
@@ -1,5 +1,6 @@
|
|||||||
#include "gamepad.h"
|
#include "gamepad.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include "z80.h"
|
||||||
#include "zx_ula.h"
|
#include "zx_ula.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -20,6 +21,30 @@ namespace gamepad
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::vector<gamepad_t> gamepads;
|
std::vector<gamepad_t> gamepads;
|
||||||
|
bool kempston_active = false;
|
||||||
|
|
||||||
|
int kempston_port_in(int port)
|
||||||
|
{
|
||||||
|
for (auto gamepad: gamepads)
|
||||||
|
{
|
||||||
|
if (gamepad.type == GAMEPAD_TYPE_KEMPSTON)
|
||||||
|
{
|
||||||
|
uint8_t result = 0;
|
||||||
|
if (gamepad.buttons[GAMEPAD_BUTTON_FIRE]) result |= 0x10;
|
||||||
|
if (gamepad.buttons[GAMEPAD_BUTTON_UP]) result |= 0x08;
|
||||||
|
if (gamepad.buttons[GAMEPAD_BUTTON_DOWN]) result |= 0x04;
|
||||||
|
if (gamepad.buttons[GAMEPAD_BUTTON_LEFT]) result |= 0x02;
|
||||||
|
if (gamepad.buttons[GAMEPAD_BUTTON_RIGHT]) result |= 0x01;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
z80::connect_port(0x1f, 0x001f, kempston_port_in, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t getNextType()
|
uint8_t getNextType()
|
||||||
{
|
{
|
||||||
@@ -55,25 +80,17 @@ namespace gamepad
|
|||||||
return gamepads.size()-1;
|
return gamepads.size()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void modify(int32_t index, uint8_t type)
|
|
||||||
{
|
|
||||||
for (auto& gamepad : gamepads)
|
|
||||||
{
|
|
||||||
if (gamepad.index == index)
|
|
||||||
{
|
|
||||||
gamepad.type = type;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void remove(int32_t index)
|
void remove(int32_t index)
|
||||||
{
|
{
|
||||||
SDL_GameController *game_controller = SDL_GameControllerFromInstanceID(index);
|
SDL_GameController *game_controller = SDL_GameControllerFromInstanceID(index);
|
||||||
for (int i=0; i<gamepads.size(); ++i)
|
for (int i=0; i<gamepads.size(); ++i)
|
||||||
{
|
{
|
||||||
if (gamepads[i].gamepad == game_controller) gamepads.erase(gamepads.begin()+i);
|
if (gamepads[i].gamepad == game_controller) {
|
||||||
|
gamepads.erase(gamepads.begin()+i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GameControllerClose(game_controller);
|
SDL_GameControllerClose(game_controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
namespace gamepad
|
namespace gamepad
|
||||||
{
|
{
|
||||||
|
void init();
|
||||||
uint8_t add(int32_t index, uint8_t type);
|
uint8_t add(int32_t index, uint8_t type);
|
||||||
void modify(int32_t index, uint8_t type);
|
|
||||||
void remove(int32_t index);
|
void remove(int32_t index);
|
||||||
void buttonDown(int32_t index, uint8_t button);
|
void buttonDown(int32_t index, uint8_t button);
|
||||||
void buttonUp(int32_t index, uint8_t button);
|
void buttonUp(int32_t index, uint8_t button);
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -169,7 +169,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
//uint32_t update_freq =
|
//uint32_t update_freq =
|
||||||
zx_system::init(ZX_48K);
|
zx_system::init(ZX_48K);
|
||||||
|
gamepad::init();
|
||||||
zx_tape::load("ROBOCOP1.TAP");
|
zx_tape::load("ROBOCOP1.TAP");
|
||||||
|
|
||||||
//if (argc==3) { z80debug::loadngo(argv[1], argv[2]); }
|
//if (argc==3) { z80debug::loadngo(argv[1], argv[2]); }
|
||||||
|
|||||||
Reference in New Issue
Block a user