all repos — mgba @ 0207048679df30de14212500e8ce42a24aeaef2b

mGBA Game Boy Advance Emulator

GB Video: Implement MLT_REQ controller iterating
Vicki Pfau vi@endrift.com
Sat, 21 Apr 2018 17:57:49 -0700
commit

0207048679df30de14212500e8ce42a24aeaef2b

parent

2cd339d3f6075e8e68a5ea5dd81d06ea3e10aac8

M include/mgba/internal/gb/gb.hinclude/mgba/internal/gb/gb.h

@@ -62,7 +62,7 @@ SGB_TEST_EN,

SGB_PICON_EN, SGB_DATA_SND, SGB_DATA_TRN, - SGB_MLT_REG, + SGB_MLT_REQ, SGB_JUMP, SGB_CHR_TRN, SGB_PCT_TRN,

@@ -107,6 +107,8 @@

int sgbBit; int currentSgbBits; uint8_t sgbPacket[16]; + uint8_t sgbControllers; + uint8_t sgbCurrentController; struct mCoreCallbacksList coreCallbacks; struct mAVStream* stream;
M include/mgba/internal/gb/serialize.hinclude/mgba/internal/gb/serialize.h

@@ -258,7 +258,9 @@

DECL_BITFIELD(GBSerializedSGBFlags, uint32_t); DECL_BITS(GBSerializedSGBFlags, P1Bits, 0, 2); DECL_BITS(GBSerializedSGBFlags, RenderMode, 2, 2); -DECL_BITS(GBSerializedSGBFlags, BufferIndex, 4, 3) +DECL_BITS(GBSerializedSGBFlags, BufferIndex, 4, 3); +DECL_BITS(GBSerializedSGBFlags, CurrentController, 7, 2); +DECL_BITS(GBSerializedSGBFlags, ReqControllers, 9, 2); #pragma pack(push, 1) struct GBSerializedState {
M src/gb/gb.csrc/gb/gb.c

@@ -446,6 +446,8 @@ gb->yankedRomSize = 0;

} gb->sgbBit = -1; + gb->sgbControllers = 0; + gb->sgbCurrentController = 0; gb->currentSgbBits = 0; memset(gb->sgbPacket, 0, sizeof(gb->sgbPacket));
M src/gb/io.csrc/gb/io.c

@@ -113,6 +113,9 @@ if (bits == gb->currentSgbBits) {

return; } gb->currentSgbBits = bits; + if (bits == 3) { + gb->sgbCurrentController = (gb->sgbCurrentController + 1) & gb->sgbControllers; + } if (gb->sgbBit == 128 && bits == 2) { GBVideoWriteSGBPacket(&gb->video, gb->sgbPacket); ++gb->sgbBit;

@@ -503,10 +506,13 @@ }

static uint8_t _readKeys(struct GB* gb) { uint8_t keys = *gb->keySource; + if (gb->sgbCurrentController != 0) { + keys = 0; + } switch (gb->memory.io[REG_JOYP] & 0x30) { case 0x30: // TODO: Increment - keys = (gb->video.sgbCommandHeader >> 3) == SGB_MLT_REG ? 0xF : 0; + keys = (gb->video.sgbCommandHeader >> 3) == SGB_MLT_REQ ? 0xF - gb->sgbCurrentController : 0; break; case 0x20: keys >>= 4;
M src/gb/serialize.csrc/gb/serialize.c

@@ -213,6 +213,8 @@ GBSerializedSGBFlags flags = 0;

flags = GBSerializedSGBFlagsSetP1Bits(flags, gb->currentSgbBits); flags = GBSerializedSGBFlagsSetRenderMode(flags, gb->video.renderer->sgbRenderMode); flags = GBSerializedSGBFlagsSetBufferIndex(flags, gb->video.sgbBufferIndex); + flags = GBSerializedSGBFlagsSetReqControllers(flags, gb->sgbControllers); + flags = GBSerializedSGBFlagsSetCurrentController(flags, gb->sgbCurrentController); STORE_32LE(flags, 0, &state->sgb.flags); memcpy(state->sgb.packet, gb->video.sgbPacketBuffer, sizeof(state->sgb.packet));

@@ -244,6 +246,8 @@ LOAD_32LE(flags, 0, &state->sgb.flags);

gb->currentSgbBits = GBSerializedSGBFlagsGetP1Bits(flags); gb->video.renderer->sgbRenderMode = GBSerializedSGBFlagsGetRenderMode(flags); gb->video.sgbBufferIndex = GBSerializedSGBFlagsGetBufferIndex(flags); + gb->sgbControllers = GBSerializedSGBFlagsGetReqControllers(flags); + gb->sgbCurrentController = GBSerializedSGBFlagsGetCurrentController(flags); memcpy(gb->video.sgbPacketBuffer, state->sgb.packet, sizeof(state->sgb.packet)); memcpy(gb->sgbPacket, state->sgb.inProgressPacket, sizeof(state->sgb.inProgressPacket));
M src/gb/video.csrc/gb/video.c

@@ -701,7 +701,8 @@ case SGB_PCT_TRN:

case SGB_ATTR_TRN: case SGB_ATTR_SET: break; - case SGB_MLT_REG: + case SGB_MLT_REQ: + video->p->sgbControllers = video->sgbPacketBuffer[1] & 0x3; return; case SGB_MASK_EN: video->renderer->sgbRenderMode = video->sgbPacketBuffer[1] & 0x3;