Skip to content

Commit

Permalink
- Add option to force field rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Oct 9, 2022
1 parent 07cb377 commit e38f7d6
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 14 deletions.
1 change: 1 addition & 0 deletions cube/swiss/include/swiss.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ typedef struct {
int forceHScale;
short forceVOffset;
int forceVFilter;
int forceVJitter;
int disableDithering;
int forceAnisotropy;
int forceWidescreen;
Expand Down
30 changes: 30 additions & 0 deletions cube/swiss/source/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ int config_update_global(bool checkConfigDevice) {
fprintf(fp, "Force Horizontal Scale=%s\r\n", forceHScaleStr[swissSettings.forceHScale]);
fprintf(fp, "Force Vertical Offset=%+hi\r\n", swissSettings.forceVOffset);
fprintf(fp, "Force Vertical Filter=%s\r\n", forceVFilterStr[swissSettings.forceVFilter]);
fprintf(fp, "Force Field Rendering=%s\r\n", forceVJitterStr[swissSettings.forceVJitter]);
fprintf(fp, "Disable Alpha Dithering=%s\r\n", swissSettings.disableDithering ? "Yes":"No");
fprintf(fp, "Force Anisotropic Filter=%s\r\n", swissSettings.forceAnisotropy ? "Yes":"No");
fprintf(fp, "Force Widescreen=%s\r\n", forceWidescreenStr[swissSettings.forceWidescreen]);
Expand Down Expand Up @@ -250,6 +251,7 @@ int config_update_game(ConfigEntry* entry, bool checkConfigDevice) {
fprintf(fp, "Force Horizontal Scale=%s\r\n", forceHScaleStr[entry->forceHScale]);
fprintf(fp, "Force Vertical Offset=%+hi\r\n", entry->forceVOffset);
fprintf(fp, "Force Vertical Filter=%s\r\n", forceVFilterStr[entry->forceVFilter]);
fprintf(fp, "Force Field Rendering=%s\r\n", forceVJitterStr[entry->forceVJitter]);
fprintf(fp, "Disable Alpha Dithering=%s\r\n", entry->disableDithering ? "Yes":"No");
fprintf(fp, "Force Anisotropic Filter=%s\r\n", entry->forceAnisotropy ? "Yes":"No");
fprintf(fp, "Force Widescreen=%s\r\n", forceWidescreenStr[entry->forceWidescreen]);
Expand Down Expand Up @@ -281,6 +283,7 @@ void config_defaults(ConfigEntry *entry) {
entry->forceVOffset = swissSettings.forceVOffset;
entry->forceVOffset = swissSettings.aveCompat == 1 ? -3:0;
entry->forceVFilter = swissSettings.forceVFilter;
entry->forceVJitter = swissSettings.forceVJitter;
entry->disableDithering = swissSettings.disableDithering;
entry->forceAnisotropy = swissSettings.forceAnisotropy;
entry->forceWidescreen = swissSettings.forceWidescreen;
Expand Down Expand Up @@ -370,6 +373,15 @@ void config_parse_legacy(char *configData, void (*progress_indicator)(char*, int
}
}
}
else if(!strcmp("Force Field Rendering", name)) {
int *ptr = !defaultPassed ? &swissSettings.forceVJitter : &configEntries[configEntriesCount].forceVJitter;
for(int i = 0; i < 3; i++) {
if(!strcmp(forceVJitterStr[i], value)) {
*ptr = i;
break;
}
}
}
else if(!strcmp("Disable Alpha Dithering", name)) {
if(defaultPassed)
configEntries[configEntriesCount].disableDithering = !strcmp("Yes", value);
Expand Down Expand Up @@ -622,6 +634,14 @@ void config_parse_global(char *configData) {
}
}
}
else if(!strcmp("Force Field Rendering", name)) {
for(int i = 0; i < 3; i++) {
if(!strcmp(forceVJitterStr[i], value)) {
swissSettings.forceVJitter = i;
break;
}
}
}
else if(!strcmp("Disable Alpha Dithering", name)) {
swissSettings.disableDithering = !strcmp("Yes", value);
}
Expand Down Expand Up @@ -894,6 +914,14 @@ void config_parse_game(char *configData, ConfigEntry *entry) {
}
}
}
else if(!strcmp("Force Field Rendering", name)) {
for(int i = 0; i < 3; i++) {
if(!strcmp(forceVJitterStr[i], value)) {
entry->forceVJitter = i;
break;
}
}
}
else if(!strcmp("Disable Alpha Dithering", name)) {
entry->disableDithering = !strcmp("Yes", value);
}
Expand Down Expand Up @@ -1011,6 +1039,7 @@ void config_load_current(ConfigEntry *config) {
swissSettings.forceHScale = config->forceHScale;
swissSettings.forceVOffset = config->forceVOffset;
swissSettings.forceVFilter = config->forceVFilter;
swissSettings.forceVJitter = config->forceVJitter;
swissSettings.disableDithering = config->disableDithering;
swissSettings.forceAnisotropy = config->forceAnisotropy;
swissSettings.forceWidescreen = config->forceWidescreen;
Expand All @@ -1024,6 +1053,7 @@ void config_unload_current() {
swissSettings.forceHScale = backup.forceHScale;
swissSettings.forceVOffset = backup.forceVOffset;
swissSettings.forceVFilter = backup.forceVFilter;
swissSettings.forceVJitter = backup.forceVJitter;
swissSettings.disableDithering = backup.disableDithering;
swissSettings.forceAnisotropy = backup.forceAnisotropy;
swissSettings.forceWidescreen = backup.forceWidescreen;
Expand Down
1 change: 1 addition & 0 deletions cube/swiss/source/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ typedef struct {
int forceHScale;
short forceVOffset;
int forceVFilter;
int forceVJitter;
int disableDithering;
int forceAnisotropy;
int forceWidescreen;
Expand Down
23 changes: 23 additions & 0 deletions cube/swiss/source/gui/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ char *uiVModeStr[] = {"Auto", "480i", "480p", "576i", "576p"};
char *gameVModeStr[] = {"Auto", "480i", "480sf", "240p", "960i", "480p", "1080i60", "540p60", "576i", "576sf", "288p", "1152i", "576p", "1080i50", "540p50"};
char *forceHScaleStr[] = {"Auto", "1:1", "11:10", "9:8", "640px", "656px", "672px", "704px", "720px"};
char *forceVFilterStr[] = {"Auto", "0", "1", "2"};
char *forceVJitterStr[] = {"Auto", "On", "Off"};
char *forceWidescreenStr[] = {"No", "3D", "2D+3D"};
char *invertCStickStr[] = {"No", "X", "Y", "X&Y"};
char *disableVideoPatchesStr[] = {"None", "Game", "All"};
Expand Down Expand Up @@ -80,6 +81,7 @@ static char *tooltips_game[PAGE_GAME_MAX+1] = {
NULL,
NULL,
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 @@ -305,6 +307,7 @@ uiDrawObj_t* settings_draw_page(int page_num, int option, ConfigEntry *gameConfi
sprintf(forceVOffsetStr, "%+hi", swissSettings.forceVOffset);
drawSettingEntryString(page, &page_y_ofs, "Force Vertical Offset:", forceVOffsetStr, option == SET_DEFAULT_VERT_OFFSET, enabledVideoPatches);
drawSettingEntryString(page, &page_y_ofs, "Force Vertical Filter:", forceVFilterStr[swissSettings.forceVFilter], option == SET_DEFAULT_VERT_FILTER, enabledVideoPatches);
drawSettingEntryString(page, &page_y_ofs, "Force Field Rendering:", forceVJitterStr[swissSettings.forceVJitter], option == SET_FIELD_RENDER, enabledVideoPatches);
drawSettingEntryBoolean(page, &page_y_ofs, "Disable Alpha Dithering:", swissSettings.disableDithering, option == SET_DEFAULT_ALPHA_DITHER, enabledVideoPatches);
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);
Expand All @@ -324,6 +327,7 @@ uiDrawObj_t* settings_draw_page(int page_num, int option, ConfigEntry *gameConfi
sprintf(forceVOffsetStr, "%+hi", gameConfig->forceVOffset);
drawSettingEntryString(page, &page_y_ofs, "Force Vertical Offset:", forceVOffsetStr, option == SET_VERT_OFFSET, enabledVideoPatches);
drawSettingEntryString(page, &page_y_ofs, "Force Vertical Filter:", forceVFilterStr[gameConfig->forceVFilter], option == SET_VERT_FILTER, enabledVideoPatches);
drawSettingEntryString(page, &page_y_ofs, "Force Field Rendering:", forceVJitterStr[gameConfig->forceVJitter], option == SET_FIELD_RENDER, enabledVideoPatches);
drawSettingEntryBoolean(page, &page_y_ofs, "Disable Alpha Dithering:", gameConfig->disableDithering, option == SET_ALPHA_DITHER, enabledVideoPatches);
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);
Expand All @@ -339,6 +343,7 @@ uiDrawObj_t* settings_draw_page(int page_num, int option, ConfigEntry *gameConfi
sprintf(forceVOffsetStr, "%+hi", swissSettings.forceVOffset);
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);
drawSettingEntryString(page, &page_y_ofs, "Force Field Rendering:", forceVJitterStr[swissSettings.forceVJitter], option == SET_FIELD_RENDER, 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);
Expand Down Expand Up @@ -602,6 +607,15 @@ void settings_toggle(int page, int option, int direction, ConfigEntry *gameConfi
swissSettings.forceVFilter = 3;
}
break;
case SET_DEFAULT_FIELD_RENDER:
if(swissSettings.disableVideoPatches < 2) {
swissSettings.forceVJitter += direction;
if(swissSettings.forceVJitter > 2)
swissSettings.forceVJitter = 0;
if(swissSettings.forceVJitter < 0)
swissSettings.forceVJitter = 2;
}
break;
case SET_DEFAULT_ALPHA_DITHER:
if(swissSettings.disableVideoPatches < 2)
swissSettings.disableDithering ^= 1;
Expand Down Expand Up @@ -690,6 +704,15 @@ void settings_toggle(int page, int option, int direction, ConfigEntry *gameConfi
gameConfig->forceVFilter = 3;
}
break;
case SET_FIELD_RENDER:
if(swissSettings.disableVideoPatches < 2) {
gameConfig->forceVJitter += direction;
if(gameConfig->forceVJitter > 2)
gameConfig->forceVJitter = 0;
if(gameConfig->forceVJitter < 0)
gameConfig->forceVJitter = 2;
}
break;
case SET_ALPHA_DITHER:
if(swissSettings.disableVideoPatches < 2)
gameConfig->disableDithering ^= 1;
Expand Down
3 changes: 3 additions & 0 deletions cube/swiss/source/gui/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ enum SETTINGS_GAME_DEFAULTS {
SET_DEFAULT_HORIZ_SCALE,
SET_DEFAULT_VERT_OFFSET,
SET_DEFAULT_VERT_FILTER,
SET_DEFAULT_FIELD_RENDER,
SET_DEFAULT_ALPHA_DITHER,
SET_DEFAULT_ANISO_FILTER,
SET_DEFAULT_WIDESCREEN,
Expand All @@ -102,6 +103,7 @@ enum SETTINGS_GAME {
SET_HORIZ_SCALE,
SET_VERT_OFFSET,
SET_VERT_FILTER,
SET_FIELD_RENDER,
SET_ALPHA_DITHER,
SET_ANISO_FILTER,
SET_WIDESCREEN,
Expand All @@ -118,6 +120,7 @@ extern char *uiVModeStr[];
extern char *gameVModeStr[];
extern char *forceHScaleStr[];
extern char *forceVFilterStr[];
extern char *forceVJitterStr[];
extern char *forceWidescreenStr[];
extern char *invertCStickStr[];
extern char *disableVideoPatchesStr[];
Expand Down
51 changes: 37 additions & 14 deletions cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -6675,14 +6675,40 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
_SDA2_BASE_ = _SDA_BASE_ = 0;

switch (swissSettings.gameVMode) {
case 6: case 13: case 7: case 14:
case 2: case 9: case 5: case 12: case -1: case -2:
if (!swissSettings.forceVFilter)
swissSettings.forceVFilter = 1;
break;
case 3: case 10:
swissSettings.forceVOffset &= ~1;
if (!swissSettings.forceVFilter)
swissSettings.forceVFilter = 1;
if (!swissSettings.forceVJitter)
swissSettings.forceVJitter = 2;
break;
case 4: case 11:
swissSettings.forceVOffset &= ~1;
if (!swissSettings.forceVFilter)
swissSettings.forceVFilter = 1;
if (!swissSettings.forceVJitter)
swissSettings.forceVJitter = 1;
break;
case 6: case 13:
if (!swissSettings.forceHScale)
swissSettings.forceHScale = 1;
case 3: case 10: case 4: case 11:
swissSettings.forceVOffset &= ~1;
case 2: case 9: case 5: case 12: case -1: case -2:
if (!swissSettings.forceVFilter)
swissSettings.forceVFilter = 1;
if (!swissSettings.forceVJitter)
swissSettings.forceVJitter = 1;
break;
case 7: case 14:
if (!swissSettings.forceHScale)
swissSettings.forceHScale = 1;
swissSettings.forceVOffset &= ~1;
if (!swissSettings.forceVFilter)
swissSettings.forceVFilter = 1;
break;
}

if (swissSettings.gameVMode == 3 || swissSettings.gameVMode == 10)
Expand Down Expand Up @@ -7397,8 +7423,7 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
break;
}
}
if (swissSettings.gameVMode == 4 || swissSettings.gameVMode == 11 ||
swissSettings.gameVMode == 6 || swissSettings.gameVMode == 13) {
if (swissSettings.forceVJitter == 1) {
__VIRetraceHandlerHook = getPatchAddr(VI_RETRACEHANDLERHOOK);

switch (j) {
Expand Down Expand Up @@ -8396,15 +8421,15 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
if (j == 0)
data[i + 7] = 0x547F0FFE; // srwi r31, r3, 31

if (swissSettings.gameVMode == 3 || swissSettings.gameVMode == 8) {
if (swissSettings.gameVMode == -2 || (swissSettings.gameVMode >= 8 && swissSettings.gameVMode <= 14))
if (j == 1)
data[i + 12] = 0x38600006; // li r3, 6

if (swissSettings.forceVJitter == 2) {
memset(data + i, 0, VIGetNextFieldSigs[j].Length * sizeof(u32));
data[i + 0] = 0x38600001; // li r3, 1
data[i + 1] = 0x4E800020; // blr
}
else if (swissSettings.gameVMode == -2 || (swissSettings.gameVMode >= 8 && swissSettings.gameVMode <= 14)) {
if (j == 1)
data[i + 12] = 0x38600006; // li r3, 6
}
print_gecko("Found:[%s$%i] @ %08X\n", VIGetNextFieldSigs[j].Name, j, VIGetNextField);
}
}
Expand Down Expand Up @@ -8433,8 +8458,7 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
u32 *__GXInitGX = Calc_ProperAddress(data, dataType, i * sizeof(u32));

if (__GXInitGX) {
if (swissSettings.gameVMode == 4 || swissSettings.gameVMode == 11 ||
swissSettings.gameVMode == 6 || swissSettings.gameVMode == 13) {
if (swissSettings.forceVJitter == 1) {
switch (j) {
case 0: data[i + 1055] = 0x38600001; break;
case 1: data[i + 466] = 0x38600001; break;
Expand Down Expand Up @@ -8526,8 +8550,7 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
}
}

if (swissSettings.gameVMode == 4 || swissSettings.gameVMode == 11 ||
swissSettings.gameVMode == 6 || swissSettings.gameVMode == 13) {
if (swissSettings.forceVJitter == 1) {
for (j = 0; j < sizeof(GXCopyDispSigs) / sizeof(FuncPattern); j++)
if (GXCopyDispSigs[j].offsetFoundAt) break;

Expand Down

0 comments on commit e38f7d6

Please sign in to comment.