GB, GBA: Fix broken opposing button filter (fixes #1191)
Vicki Pfau vi@endrift.com
Sat, 29 Sep 2018 12:55:31 -0700
5 files changed,
31 insertions(+),
2 deletions(-)
M
CHANGES
→
CHANGES
@@ -109,6 +109,7 @@ - 3DS: Fix unused screens not clearing (fixes mgba.io/i/1184)
- GBA Video: Fix caching with background toggling (fixes mgba.io/i/1118) - Wii: Fix drawing caching regression (fixes mgba.io/i/1185) - Switch: Fix incorrect mapping for fast forward cap + - GB, GBA: Fix broken opposing button filter (fixes mgba.io/i/1191) Misc: - mGUI: Add SGB border configuration option - mGUI: Add support for different settings types
M
include/mgba/internal/gb/gb.h
→
include/mgba/internal/gb/gb.h
@@ -117,6 +117,8 @@ bool cpuBlocked;
bool earlyExit; struct mTimingEvent eiPending; unsigned doubleSpeed; + + bool allowOpposingDirections; }; struct GBCartridge {
M
src/gb/core.c
→
src/gb/core.c
@@ -210,8 +210,12 @@ mCoreConfigCopyValue(&core->config, config, "gbc.bios");
mCoreConfigCopyValue(&core->config, config, "gb.model"); mCoreConfigCopyValue(&core->config, config, "sgb.model"); mCoreConfigCopyValue(&core->config, config, "cgb.model"); + mCoreConfigCopyValue(&core->config, config, "allowOpposingDirections"); - int fakeBool; + int fakeBool = 0; + mCoreConfigGetIntValue(config, "allowOpposingDirections", &fakeBool); + gb->allowOpposingDirections = fakeBool; + if (mCoreConfigGetIntValue(config, "sgb.borders", &fakeBool)) { gb->video.sgbBorders = fakeBool; gb->video.renderer->enableSGBBorder(gb->video.renderer, fakeBool);
M
src/gb/io.c
→
src/gb/io.c
@@ -105,6 +105,7 @@ [REG_IE] = 0xE0,
}; static uint8_t _readKeys(struct GB* gb); +static uint8_t _readKeysFiltered(struct GB* gb); static void _writeSGBBits(struct GB* gb, int bits) { if (!bits) {@@ -557,10 +558,26 @@ }
return gb->memory.io[REG_JOYP]; } +static uint8_t _readKeysFiltered(struct GB* gb) { + uint8_t keys = _readKeys(gb); + if (!gb->allowOpposingDirections && (keys & 0x30) == 0x20) { + unsigned rl = keys & 0x03; + unsigned ud = keys & 0x0C; + keys &= 0xF0; + if (rl != 0x03) { + keys |= rl; + } + if (ud != 0x0C) { + keys |= ud; + } + } + return keys; +} + uint8_t GBIORead(struct GB* gb, unsigned address) { switch (address) { case REG_JOYP: - return _readKeys(gb); + return _readKeysFiltered(gb); case REG_IE: return gb->memory.ie; case REG_WAVE_0:
M
src/gba/core.c
→
src/gba/core.c
@@ -239,6 +239,11 @@ }
} } + int fakeBool = 0; + mCoreConfigGetIntValue(config, "allowOpposingDirections", &fakeBool); + gba->allowOpposingDirections = fakeBool; + + mCoreConfigCopyValue(&core->config, config, "allowOpposingDirections"); mCoreConfigCopyValue(&core->config, config, "gba.bios"); #ifndef DISABLE_THREADING