GB: More SGB controller incrementing fixes

This commit is contained in:
Vicki Pfau 2019-09-03 19:38:51 -07:00
parent d6e9315ff5
commit 34529398bb
5 changed files with 19 additions and 11 deletions

View File

@ -109,6 +109,7 @@ struct GB {
uint8_t sgbPacket[16];
uint8_t sgbControllers;
uint8_t sgbCurrentController;
bool sgbIncrement;
struct mCoreCallbacksList coreCallbacks;
struct mAVStream* stream;

View File

@ -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 {

View File

@ -437,6 +437,7 @@ void GBReset(struct LR35902Core* cpu) {
gb->sgbControllers = 0;
gb->sgbCurrentController = 0;
gb->currentSgbBits = 0;
gb->sgbIncrement = false;
memset(gb->sgbPacket, 0, sizeof(gb->sgbPacket));
mTimingClear(&gb->timing);

View File

@ -116,18 +116,16 @@ static void _writeSGBBits(struct GB* gb, int bits) {
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);

View File

@ -225,6 +225,7 @@ void GBSGBSerialize(struct GB* gb, struct GBSerializedState* state) {
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 @@ void GBSGBDeserialize(struct GB* gb, const struct GBSerializedState* state) {
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));