Skip to content

Commit

Permalink
- Add digital trigger level option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Jan 28, 2022
1 parent a3a27e3 commit e3997f4
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 10 deletions.
9 changes: 8 additions & 1 deletion cube/patches/base/igr.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021, Extrems <extrems@extremscorner.org>
* Copyright (c) 2019-2022, Extrems <extrems@extremscorner.org>
*
* This file is part of Swiss.
*
Expand All @@ -25,6 +25,13 @@

void check_pad(int32_t chan, PADStatus *status)
{
if (*VAR_TRIGGER_LEVEL > 0) {
if (status->triggerL >= *VAR_TRIGGER_LEVEL)
status->button |= PAD_BUTTON_L;
if (status->triggerR >= *VAR_TRIGGER_LEVEL)
status->button |= PAD_BUTTON_R;
}

if ((status->button & PAD_COMBO_EXIT) == PAD_COMBO_EXIT) {
switch (*VAR_IGR_TYPE) {
case IGR_HARDRESET:
Expand Down
2 changes: 2 additions & 0 deletions cube/reservedarea.h
Expand Up @@ -47,6 +47,7 @@
.set VAR_SAR_HEIGHT, 0x09FA # sample aspect ratio height
.set VAR_NEXT_FIELD, 0x09FB # next video field
.set VAR_CURRENT_FIELD, 0x09FC # current video field
.set VAR_TRIGGER_LEVEL, 0x09FD # digital trigger level
.set VAR_CARD_IDS, 0x09FE # emulated memory cards
.set VAR_CARD_A_ID, 0x09FE # emulated memory card a
.set VAR_CARD_B_ID, 0x09FF # emulated memory card b
Expand Down Expand Up @@ -111,6 +112,7 @@ extern char VAR_SAR_WIDTH[2]; // sample aspect ratio width
extern char VAR_SAR_HEIGHT[1]; // sample aspect ratio height
extern char VAR_NEXT_FIELD[1]; // next video field
extern char VAR_CURRENT_FIELD[1]; // current video field
extern char VAR_TRIGGER_LEVEL[1]; // digital trigger level
extern char VAR_CARD_IDS[2]; // emulated memory cards
extern char VAR_CARD_A_ID[1]; // emulated memory card a
extern char VAR_CARD_B_ID[1]; // emulated memory card b
Expand Down
1 change: 1 addition & 0 deletions cube/reservedarea.ld
Expand Up @@ -35,6 +35,7 @@ VAR_SAR_WIDTH = VAR_AREA | 0x09F8; /* sample aspect ratio width */
VAR_SAR_HEIGHT = VAR_AREA | 0x09FA; /* sample aspect ratio height */
VAR_NEXT_FIELD = VAR_AREA | 0x09FB; /* next video field */
VAR_CURRENT_FIELD = VAR_AREA | 0x09FC; /* current video field */
VAR_TRIGGER_LEVEL = VAR_AREA | 0x09FD; /* digital trigger level */
VAR_CARD_IDS = VAR_AREA | 0x09FE; /* emulated memory cards */
VAR_CARD_A_ID = VAR_AREA | 0x09FE; /* emulated memory card a */
VAR_CARD_B_ID = VAR_AREA | 0x09FF; /* emulated memory card b */
Expand Down
1 change: 1 addition & 0 deletions cube/swiss/include/swiss.h
Expand Up @@ -90,6 +90,7 @@ typedef struct {
int fontEncode;
int audioStreaming;
int invertCStick;
int triggerLevel;
int wiirdDebug; // Enable WiiRD debug
int hideUnknownFileTypes;
int sram60Hz;
Expand Down
15 changes: 15 additions & 0 deletions cube/swiss/source/config/config.c
Expand Up @@ -264,6 +264,9 @@ int config_update_global(bool checkConfigDevice) {
sprintf(txtbuffer, "Invert Camera Stick=%s\r\n",invertCStickStr[swissSettings.invertCStick]);
string_append(configString, txtbuffer);

sprintf(txtbuffer, "Digital Trigger Level=%hhu\r\n",swissSettings.triggerLevel);
string_append(configString, txtbuffer);

sprintf(txtbuffer, "Emulate Read Speed=%s\r\n",emulateReadSpeedStr[swissSettings.emulateReadSpeed]);
string_append(configString, txtbuffer);

Expand Down Expand Up @@ -349,6 +352,9 @@ int config_update_game(ConfigEntry* entry, bool checkConfigDevice) {
sprintf(txtbuffer, "Invert Camera Stick=%s\r\n",invertCStickStr[entry->invertCStick]);
string_append(configString, txtbuffer);

sprintf(txtbuffer, "Digital Trigger Level=%hhu\r\n",entry->triggerLevel);
string_append(configString, txtbuffer);

sprintf(txtbuffer, "Emulate Read Speed=%s\r\n",emulateReadSpeedStr[entry->emulateReadSpeed]);
string_append(configString, txtbuffer);

Expand Down Expand Up @@ -379,6 +385,7 @@ void config_defaults(ConfigEntry *entry) {
entry->forceAnisotropy = swissSettings.forceAnisotropy;
entry->forceWidescreen = swissSettings.forceWidescreen;
entry->invertCStick = swissSettings.invertCStick;
entry->triggerLevel = swissSettings.triggerLevel;
entry->emulateReadSpeed = swissSettings.emulateReadSpeed;

for(int i = 0; i < sizeof(emulateReadSpeedEntries) / sizeof(*emulateReadSpeedEntries); i++) {
Expand Down Expand Up @@ -740,6 +747,9 @@ void config_parse_global(char *configData) {
}
}
}
else if(!strcmp("Digital Trigger Level", name)) {
swissSettings.triggerLevel = atoi(value);
}
else if(!strcmp("Emulate Read Speed", name)) {
for(int i = 0; i < 3; i++) {
if(!strcmp(emulateReadSpeedStr[i], value)) {
Expand Down Expand Up @@ -1005,6 +1015,9 @@ void config_parse_game(char *configData, ConfigEntry *entry) {
}
}
}
else if(!strcmp("Digital Trigger Level", name)) {
entry->triggerLevel = atoi(value);
}
else if(!strcmp("Emulate Read Speed", name)) {
for(int i = 0; i < 3; i++) {
if(!strcmp(emulateReadSpeedStr[i], value)) {
Expand Down Expand Up @@ -1101,6 +1114,7 @@ void config_load_current(ConfigEntry *config) {
swissSettings.forceAnisotropy = config->forceAnisotropy;
swissSettings.forceWidescreen = config->forceWidescreen;
swissSettings.invertCStick = config->invertCStick;
swissSettings.triggerLevel = config->triggerLevel;
swissSettings.emulateReadSpeed = config->emulateReadSpeed;
}

Expand All @@ -1113,5 +1127,6 @@ void config_unload_current() {
swissSettings.forceAnisotropy = backup.forceAnisotropy;
swissSettings.forceWidescreen = backup.forceWidescreen;
swissSettings.invertCStick = backup.invertCStick;
swissSettings.triggerLevel = backup.triggerLevel;
swissSettings.emulateReadSpeed = backup.emulateReadSpeed;
}
1 change: 1 addition & 0 deletions cube/swiss/source/config/config.h
Expand Up @@ -19,6 +19,7 @@ typedef struct {
int forceAnisotropy;
int forceWidescreen;
int invertCStick;
int triggerLevel;
int emulateReadSpeed;
} ConfigEntry;

Expand Down
40 changes: 31 additions & 9 deletions cube/swiss/source/gui/settings.c
Expand Up @@ -78,6 +78,7 @@ static char *tooltips_game[PAGE_GAME_MAX+1] = {
NULL,
NULL,
"Invert Camera Stick:\n\nNo - Leave C Stick as-is (default)\nX - Invert X-axis of the C Stick\nY - Invert Y-axis of the C Stick\nX&Y - Invert both axes of the C Stick",
"Digital Trigger Level:\n\nSets the level where the L/R Button is fully pressed.",
"Emulate Read Speed:\n\nNo - Start transfer immediately (default)\nYes - Delay transfer to simulate the GameCube disc drive\nWii - Delay transfer to simulate the Wii disc drive\n\nThis is necessary to avoid programming mistakes obfuscated\nby the original medium, or for speedrunning."
};

Expand Down Expand Up @@ -176,6 +177,7 @@ uiDrawObj_t* settings_draw_page(int page_num, int option, file_handle *file, Con
uiDrawObj_t* page = DrawEmptyBox(20,60, getVideoMode()->fbWidth-20, 460);
char sramHOffsetStr[8];
char forceVOffsetStr[8];
char triggerLevelStr[8];

// Save Settings to current device (**Shown on all tabs**)
/** Global Settings (Page 1/) */
Expand Down Expand Up @@ -296,6 +298,8 @@ uiDrawObj_t* settings_draw_page(int page_num, int option, file_handle *file, Con
drawSettingEntryBoolean(page, &page_y_ofs, "Force Anisotropic Filter:", swissSettings.forceAnisotropy, option == SET_DEFAULT_ANISO_FILTER, true);
drawSettingEntryString(page, &page_y_ofs, "Force Widescreen:", forceWidescreenStr[swissSettings.forceWidescreen], option == SET_DEFAULT_WIDESCREEN, true);
drawSettingEntryString(page, &page_y_ofs, "Invert Camera Stick:", invertCStickStr[swissSettings.invertCStick], option == SET_DEFAULT_INVERT_CAMERA, true);
sprintf(triggerLevelStr, "%hhu", swissSettings.triggerLevel);
drawSettingEntryString(page, &page_y_ofs, "Digital Trigger Level:", triggerLevelStr, option == SET_DEFAULT_TRIGGER_LEVEL, true);
drawSettingEntryString(page, &page_y_ofs, "Emulate Read Speed:", emulateReadSpeedStr[swissSettings.emulateReadSpeed], option == SET_DEFAULT_READ_SPEED, emulatedReadSpeed);
}
else if(page_num == PAGE_GAME) {
Expand All @@ -313,20 +317,24 @@ uiDrawObj_t* settings_draw_page(int page_num, int option, file_handle *file, Con
drawSettingEntryBoolean(page, &page_y_ofs, "Force Anisotropic Filter:", gameConfig->forceAnisotropy, option == SET_ANISO_FILTER, true);
drawSettingEntryString(page, &page_y_ofs, "Force Widescreen:", forceWidescreenStr[gameConfig->forceWidescreen], option == SET_WIDESCREEN, true);
drawSettingEntryString(page, &page_y_ofs, "Invert Camera Stick:", invertCStickStr[gameConfig->invertCStick], option == SET_INVERT_CAMERA, true);
sprintf(triggerLevelStr, "%hhu", gameConfig->triggerLevel);
drawSettingEntryString(page, &page_y_ofs, "Digital Trigger Level:", triggerLevelStr, option == SET_TRIGGER_LEVEL, true);
drawSettingEntryString(page, &page_y_ofs, "Emulate Read Speed:", emulateReadSpeedStr[gameConfig->emulateReadSpeed], option == SET_READ_SPEED, emulatedReadSpeed);
}
else {
// Just draw the defaults again
drawSettingEntryString(page, &page_y_ofs, "Force Video Mode:", gameVModeStr[swissSettings.gameVMode], option == SET_DEFAULT_FORCE_VIDEOMODE, false);
drawSettingEntryString(page, &page_y_ofs, "Force Horizontal Scale:", forceHScaleStr[swissSettings.forceHScale], option == SET_DEFAULT_HORIZ_SCALE, false);
drawSettingEntryString(page, &page_y_ofs, "Force Video Mode:", gameVModeStr[swissSettings.gameVMode], option == SET_FORCE_VIDEOMODE, false);
drawSettingEntryString(page, &page_y_ofs, "Force Horizontal Scale:", forceHScaleStr[swissSettings.forceHScale], option == SET_HORIZ_SCALE, false);
sprintf(forceVOffsetStr, "%+hi", swissSettings.forceVOffset);
drawSettingEntryString(page, &page_y_ofs, "Force Vertical Offset:", forceVOffsetStr, option == SET_DEFAULT_VERT_OFFSET, false);
drawSettingEntryString(page, &page_y_ofs, "Force Vertical Filter:", forceVFilterStr[swissSettings.forceVFilter], option == SET_DEFAULT_VERT_FILTER, false);
drawSettingEntryBoolean(page, &page_y_ofs, "Disable Alpha Dithering:", swissSettings.disableDithering, option == SET_DEFAULT_ALPHA_DITHER, false);
drawSettingEntryBoolean(page, &page_y_ofs, "Force Anisotropic Filter:", swissSettings.forceAnisotropy, option == SET_DEFAULT_ANISO_FILTER, false);
drawSettingEntryString(page, &page_y_ofs, "Force Widescreen:", forceWidescreenStr[swissSettings.forceWidescreen], option == SET_DEFAULT_WIDESCREEN, false);
drawSettingEntryString(page, &page_y_ofs, "Invert Camera Stick:", invertCStickStr[swissSettings.invertCStick], option == SET_DEFAULT_INVERT_CAMERA, false);
drawSettingEntryString(page, &page_y_ofs, "Emulate Read Speed:", emulateReadSpeedStr[swissSettings.emulateReadSpeed], option == SET_DEFAULT_READ_SPEED, false);
drawSettingEntryString(page, &page_y_ofs, "Force Vertical Offset:", forceVOffsetStr, option == SET_VERT_OFFSET, false);
drawSettingEntryString(page, &page_y_ofs, "Force Vertical Filter:", forceVFilterStr[swissSettings.forceVFilter], option == SET_VERT_FILTER, false);
drawSettingEntryBoolean(page, &page_y_ofs, "Disable Alpha Dithering:", swissSettings.disableDithering, option == SET_ALPHA_DITHER, false);
drawSettingEntryBoolean(page, &page_y_ofs, "Force Anisotropic Filter:", swissSettings.forceAnisotropy, option == SET_ANISO_FILTER, false);
drawSettingEntryString(page, &page_y_ofs, "Force Widescreen:", forceWidescreenStr[swissSettings.forceWidescreen], option == SET_WIDESCREEN, false);
drawSettingEntryString(page, &page_y_ofs, "Invert Camera Stick:", invertCStickStr[swissSettings.invertCStick], option == SET_INVERT_CAMERA, false);
sprintf(triggerLevelStr, "%hhu", swissSettings.triggerLevel);
drawSettingEntryString(page, &page_y_ofs, "Digital Trigger Level:", triggerLevelStr, option == SET_TRIGGER_LEVEL, false);
drawSettingEntryString(page, &page_y_ofs, "Emulate Read Speed:", emulateReadSpeedStr[swissSettings.emulateReadSpeed], option == SET_READ_SPEED, false);
}
}
// If we have a tooltip for this page/option, add a fading label telling the user to press Y for help
Expand Down Expand Up @@ -602,6 +610,13 @@ void settings_toggle(int page, int option, int direction, file_handle *file, Con
if(swissSettings.invertCStick < 0)
swissSettings.invertCStick = 3;
break;
case SET_DEFAULT_TRIGGER_LEVEL:
swissSettings.triggerLevel += direction * 10;
if(swissSettings.triggerLevel > 200)
swissSettings.triggerLevel = 0;
if(swissSettings.triggerLevel < 0)
swissSettings.triggerLevel = 200;
break;
case SET_DEFAULT_READ_SPEED:
if(devices[DEVICE_CUR] == NULL || (devices[DEVICE_CUR]->emulable & EMU_READ_SPEED)) {
swissSettings.emulateReadSpeed += direction;
Expand Down Expand Up @@ -683,6 +698,13 @@ void settings_toggle(int page, int option, int direction, file_handle *file, Con
if(gameConfig->invertCStick < 0)
gameConfig->invertCStick = 3;
break;
case SET_TRIGGER_LEVEL:
gameConfig->triggerLevel += direction * 10;
if(gameConfig->triggerLevel > 200)
gameConfig->triggerLevel = 0;
if(gameConfig->triggerLevel < 0)
gameConfig->triggerLevel = 200;
break;
case SET_READ_SPEED:
if(devices[DEVICE_CUR] == NULL || (devices[DEVICE_CUR]->emulable & EMU_READ_SPEED)) {
gameConfig->emulateReadSpeed += direction;
Expand Down
2 changes: 2 additions & 0 deletions cube/swiss/source/gui/settings.h
Expand Up @@ -87,6 +87,7 @@ enum SETTINGS_GAME_DEFAULTS {
SET_DEFAULT_ANISO_FILTER,
SET_DEFAULT_WIDESCREEN,
SET_DEFAULT_INVERT_CAMERA,
SET_DEFAULT_TRIGGER_LEVEL,
SET_DEFAULT_READ_SPEED,
SET_PAGE_4_BACK,
SET_PAGE_4_NEXT,
Expand All @@ -104,6 +105,7 @@ enum SETTINGS_GAME {
SET_ANISO_FILTER,
SET_WIDESCREEN,
SET_INVERT_CAMERA,
SET_TRIGGER_LEVEL,
SET_READ_SPEED,
SET_PAGE_5_BACK,
SET_PAGE_5_SAVE,
Expand Down
1 change: 1 addition & 0 deletions cube/swiss/source/swiss.c
Expand Up @@ -1820,6 +1820,7 @@ void load_game() {
*(vu8*)VAR_SD_SHIFT = 0;
*(vu8*)VAR_IGR_TYPE = swissSettings.igrType;
*(vu32**)VAR_FRAG_LIST = NULL;
*(vu8*)VAR_TRIGGER_LEVEL = swissSettings.triggerLevel;
*(vu8*)VAR_CARD_A_ID = 0x00;
*(vu8*)VAR_CARD_B_ID = 0x00;

Expand Down

0 comments on commit e3997f4

Please sign in to comment.