Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ ifeq ($(PLATFORM),rgb30)
CFLAGS += -DBR2 -DRGB30
else ifeq ($(PLATFORM),h700)
CFLAGS += -DBR2 -DH700
else ifeq ($(PLATFORM),rg35xxsp)
CFLAGS += -DBR2 -DRG35XXSP
else ifeq ($(PLATFORM),r36s)
CFLAGS += -DBR2 -DR36S
else ifeq ($(PLATFORM),pi)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Currently supported platforms include:
- `rgb30`
- `h700`
- `r36s`
- `rg35xxsp`
- `pi` (Raspberry Pi / generic controller)

If no platform is specified, SimpleTerminal builds with a generic Linux keyboard mapping.
Expand Down
51 changes: 41 additions & 10 deletions src/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
// R36S / dArkOS (GO-Super Gamepad) confirmed via jstest/evtest:
// D-pad: 8=Up, 9=Down, 10=Left, 11=Right
// Select=12, Start=13, L3=14, R3=15, FN(MENU)=16
#define JOYBUTTON_A -1
#define JOYBUTTON_B -0
#define JOYBUTTON_X -2
#define JOYBUTTON_Y -3
#define JOYBUTTON_L1 -4
#define JOYBUTTON_R1 -5
#define JOYBUTTON_L2 -6
#define JOYBUTTON_R2 -7
#define JOYBUTTON_UP -8
#define JOYBUTTON_DOWN -9
#define JOYBUTTON_LEFT -10
Expand All @@ -23,8 +31,41 @@
#define JOYBUTTON_R3 -15
#define JOYBUTTON_MENU -16

#elif defined(RG35XXSP)
#define JOYBUTTON_A -3
#define JOYBUTTON_B -4
#define JOYBUTTON_X -6
#define JOYBUTTON_Y -5
#define JOYBUTTON_L1 -7
#define JOYBUTTON_R1 -8
#define JOYBUTTON_L2 -12
#define JOYBUTTON_R2 -13

// D-pad keys are treated as joystick hats on the 35xxSP, so here we map to
// synthetic keys that are emitted from the hat event handling code.
#define JOYBUTTON_UP -100
#define JOYBUTTON_DOWN -101
#define JOYBUTTON_LEFT -102
#define JOYBUTTON_RIGHT -103

#define JOYBUTTON_SELECT -9
#define JOYBUTTON_START -10
// Volume up.
#define JOYBUTTON_L3 -2
// Volume down.
#define JOYBUTTON_R3 -1
#define JOYBUTTON_MENU -11

#else
// Default BR2 handheld layout (rgb30, h700, etc.)
#define JOYBUTTON_A -1
#define JOYBUTTON_B -0
#define JOYBUTTON_X -2
#define JOYBUTTON_Y -3
#define JOYBUTTON_L1 -4
#define JOYBUTTON_R1 -5
#define JOYBUTTON_L2 -6
#define JOYBUTTON_R2 -7
#define JOYBUTTON_UP -13
#define JOYBUTTON_DOWN -14
#define JOYBUTTON_LEFT -15
Expand All @@ -36,16 +77,6 @@
#define JOYBUTTON_MENU -10
#endif

// Shared buttons
#define JOYBUTTON_A -1
#define JOYBUTTON_B -0
#define JOYBUTTON_X -2
#define JOYBUTTON_Y -3
#define JOYBUTTON_L1 -4
#define JOYBUTTON_R1 -5
#define JOYBUTTON_L2 -6
#define JOYBUTTON_R2 -7

// Logical key bindings

#define KEY_UP JOYBUTTON_UP
Expand Down
39 changes: 39 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,9 @@ void main_loop(void) {
int running = 1;
int button_up_held = 0, button_down_held = 0, button_left_held = 0, button_right_held = 0;
Uint32 last_button_held_time = 0;
#if defined(RG35XXSP)
Uint8 joy0_hat0_last_state = 0;
#endif
while (running) {
while (SDL_PollEvent(&ev))
// while (SDL_WaitEvent(&ev))
Expand Down Expand Up @@ -1022,6 +1025,42 @@ void main_loop(void) {
}}};

SDL_PushEvent(&sdl_event);
#if defined(RG35XXSP)
} else if (ev.type == SDL_JOYHATMOTION && ev.jhat.which == 0 &&
ev.jhat.hat == 0) {
// The RG35XXSP does not treat the d-pad directions as individual buttons; instead it treats it as a joystick hat.
// Here we translate hat events into key events to handle those directions.
static const Uint8 HAT_MASKS[] = {
SDL_HAT_LEFT, SDL_HAT_RIGHT, SDL_HAT_UP, SDL_HAT_DOWN,
};
static const int HAT_BUTTONS[] = {
JOYBUTTON_LEFT, JOYBUTTON_RIGHT, JOYBUTTON_UP, JOYBUTTON_DOWN,
};
for (int i = 0; i < 4; i++) {
if ((joy0_hat0_last_state & HAT_MASKS[i]) && !(ev.jhat.value & HAT_MASKS[i])) {
SDL_Event sdl_event = {.key = {.type = SDL_KEYUP,
.state = SDL_RELEASED,
.keysym = {
.scancode = HAT_BUTTONS[i],
.sym = HAT_BUTTONS[i],
.mod = 0,
}}};

SDL_PushEvent(&sdl_event);
} else if (!(joy0_hat0_last_state & HAT_MASKS[i]) && (ev.jhat.value & HAT_MASKS[i])) {
SDL_Event sdl_event = {.key = {.type = SDL_KEYDOWN,
.state = SDL_PRESSED,
.keysym = {
.scancode = HAT_BUTTONS[i],
.sym = HAT_BUTTONS[i],
.mod = 0,
}}};

SDL_PushEvent(&sdl_event);
}
}
joy0_hat0_last_state = ev.jhat.value;
#endif
} else {
if (event_handler[ev.type]) (event_handler[ev.type])(&ev);
}
Expand Down
Loading