GB: More SGB controller incrementing fixes
Vicki Pfau vi@endrift.com
Tue, 03 Sep 2019 19:38:51 -0700
5 files changed,
19 insertions(+),
11 deletions(-)
M
include/mgba/internal/gb/gb.h
→
include/mgba/internal/gb/gb.h
@@ -109,6 +109,7 @@ int currentSgbBits;
uint8_t sgbPacket[16]; uint8_t sgbControllers; uint8_t sgbCurrentController; + bool sgbIncrement; struct mCoreCallbacksList coreCallbacks; struct mAVStream* stream;
M
include/mgba/internal/gb/serialize.h
→
include/mgba/internal/gb/serialize.h
@@ -263,6 +263,7 @@ DECL_BITS(GBSerializedSGBFlags, RenderMode, 2, 2);
DECL_BITS(GBSerializedSGBFlags, BufferIndex, 4, 3); DECL_BITS(GBSerializedSGBFlags, CurrentController, 7, 2); DECL_BITS(GBSerializedSGBFlags, ReqControllers, 9, 2); +DECL_BIT(GBSerializedSGBFlags, Increment, 11); #pragma pack(push, 1) struct GBSerializedState {
M
src/gb/gb.c
→
src/gb/gb.c
@@ -437,6 +437,7 @@ gb->sgbBit = -1;
gb->sgbControllers = 0; gb->sgbCurrentController = 0; gb->currentSgbBits = 0; + gb->sgbIncrement = false; memset(gb->sgbPacket, 0, sizeof(gb->sgbPacket)); mTimingClear(&gb->timing);
M
src/gb/io.c
→
src/gb/io.c
@@ -116,18 +116,16 @@ if (bits == gb->currentSgbBits) {
return; } gb->currentSgbBits = bits; - if (gb->sgbBit > 128) { - switch (bits) { - case 1: - gb->sgbBit ^= 2; - break; - case 3: - if (gb->sgbBit == 131) { - gb->sgbBit &= ~2; - gb->sgbCurrentController = (gb->sgbCurrentController + 1) & gb->sgbControllers; - } - break; + switch (bits) { + case 1: + gb->sgbIncrement = !gb->sgbIncrement; + break; + case 3: + if (gb->sgbIncrement) { + gb->sgbIncrement = false; + gb->sgbCurrentController = (gb->sgbCurrentController + 1) & gb->sgbControllers; } + break; } if (gb->sgbBit == 128 && bits == 2) { GBVideoWriteSGBPacket(&gb->video, gb->sgbPacket);
M
src/gb/serialize.c
→
src/gb/serialize.c
@@ -225,6 +225,7 @@ flags = GBSerializedSGBFlagsSetP1Bits(flags, gb->currentSgbBits);
flags = GBSerializedSGBFlagsSetRenderMode(flags, gb->video.renderer->sgbRenderMode); flags = GBSerializedSGBFlagsSetBufferIndex(flags, gb->video.sgbBufferIndex); flags = GBSerializedSGBFlagsSetReqControllers(flags, gb->sgbControllers); + flags = GBSerializedSGBFlagsSetIncrement(flags, gb->sgbIncrement); flags = GBSerializedSGBFlagsSetCurrentController(flags, gb->sgbCurrentController); STORE_32LE(flags, 0, &state->sgb.flags);@@ -260,6 +261,12 @@ gb->video.renderer->sgbRenderMode = GBSerializedSGBFlagsGetRenderMode(flags);
gb->video.sgbBufferIndex = GBSerializedSGBFlagsGetBufferIndex(flags); gb->sgbControllers = GBSerializedSGBFlagsGetReqControllers(flags); gb->sgbCurrentController = GBSerializedSGBFlagsGetCurrentController(flags); + gb->sgbIncrement = GBSerializedSGBFlagsGetIncrement(flags); + + // Old versions of mGBA stored the increment bits here + if (gb->sgbBit > 129 && gb->sgbBit & 2) { + gb->sgbIncrement = true; + } memcpy(gb->video.sgbPacketBuffer, state->sgb.packet, sizeof(state->sgb.packet)); memcpy(gb->sgbPacket, state->sgb.inProgressPacket, sizeof(state->sgb.inProgressPacket));