- [NEW] Ja funciona el joystick tipus Kempston

This commit is contained in:
2025-08-16 16:59:26 +02:00
parent 1fdfeedacc
commit 6837392c53
3 changed files with 32 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
#include "gamepad.h"
#include <SDL2/SDL.h>
#include "z80.h"
#include "zx_ula.h"
#include <vector>
@@ -20,6 +21,30 @@ namespace gamepad
};
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()
{
@@ -55,25 +80,17 @@ namespace gamepad
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)
{
SDL_GameController *game_controller = SDL_GameControllerFromInstanceID(index);
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);
}