Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Change select / start button to be turbos for B / A respectively #180

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ venv

**/*.pyc

*.sw[mnop]
15 changes: 15 additions & 0 deletions Core/Src/gw_buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

#include "stm32h7xx_hal.h"
#include "main.h"
#include "odroid_system.h"

#include <stdbool.h>

#if ENABLE_TURBO_BUTTONS == 1
#define TURBO_FREQUENCY_HZ 30

bool is_turbo_high() {
int turbo_period_ms = 1000 / TURBO_FREQUENCY_HZ;
return (get_elapsed_time() % turbo_period_ms) < (turbo_period_ms / 2);
}
#endif

uint32_t buttons_get() {
bool left = HAL_GPIO_ReadPin(BTN_Left_GPIO_Port, BTN_Left_Pin) == GPIO_PIN_RESET;
bool right = HAL_GPIO_ReadPin(BTN_Right_GPIO_Port, BTN_Right_Pin) == GPIO_PIN_RESET;
Expand All @@ -17,8 +27,13 @@ uint32_t buttons_get() {
bool pause = HAL_GPIO_ReadPin(BTN_PAUSE_GPIO_Port, BTN_PAUSE_Pin) == GPIO_PIN_RESET;
bool power = HAL_GPIO_ReadPin(BTN_PWR_GPIO_Port, BTN_PWR_Pin) == GPIO_PIN_RESET;

#if ENABLE_TURBO_BUTTONS == 1
a |= HAL_GPIO_ReadPin(BTN_START_GPIO_Port, BTN_START_Pin) == GPIO_PIN_RESET && is_turbo_high();
b |= HAL_GPIO_ReadPin(BTN_SELECT_GPIO_Port, BTN_SELECT_Pin) == GPIO_PIN_RESET && is_turbo_high();
#else
game |= HAL_GPIO_ReadPin(BTN_START_GPIO_Port, BTN_START_Pin) == GPIO_PIN_RESET;
time |= HAL_GPIO_ReadPin(BTN_SELECT_GPIO_Port, BTN_SELECT_Pin) == GPIO_PIN_RESET;
#endif

return (
left | (up << 1) | (right << 2) | (down << 3) | (a << 4) | (b << 5) |
Expand Down
5 changes: 5 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ else
ENABLE_SCREENSHOT ?= 1
endif

ENABLE_TURBO_BUTTONS ?= 0

# Compress supported ROMs by default. Set to 0 to disable.
COMPRESS ?= lzma
ifeq ($(COMPRESS),0)
Expand Down Expand Up @@ -277,6 +279,7 @@ C_DEFS += \
-DDEBUG_RG_ALLOC \
-DSTATE_SAVING=$(STATE_SAVING) \
-DENABLE_SCREENSHOT=$(ENABLE_SCREENSHOT) \
-DENABLE_TURBO_BUTTONS=$(ENABLE_TURBO_BUTTONS) \
-DGNW_TARGET_MARIO=$(GNW_TARGET_MARIO) \
-DGNW_TARGET_ZELDA=$(GNW_TARGET_ZELDA)

Expand Down Expand Up @@ -645,6 +648,7 @@ help:
@echo " RESET_DBGMCU - Configures if DBGMCU should be reset after flashing."
@echo " Set to 0 to disable power saving (default=1)"
@echo " ENABLE_SCREENSHOT - Set to 1 to enable screenshot support (default disabled if extflash is 1MB)"
@echo " ENABLE_TURBO_BUTTONS- Set to 1 to swap start/select buttons for turbo A and B buttons (Zelda only) (default=0)"
@echo " GNW_TARGET - Game & Watch target, Valid values {mario,zelda} (default=mario)"
@echo ""
@echo "Current configuration:"
Expand All @@ -658,6 +662,7 @@ help:
@echo " STATE_SAVING=$(STATE_SAVING)"
@echo " RESET_DBGMCU=$(RESET_DBGMCU)"
@echo " ENABLE_SCREENSHOT=$(ENABLE_SCREENSHOT)"
@echo " ENABLE_TURBO_BUTTONS=$(ENABLE_TURBO_BUTTONS)"
@echo " GNW_TARGET=$(GNW_TARGET)"
@echo " GCC_PATH=$(GCC_PATH)"
@echo " PREFIX=$(PREFIX)"
Expand Down