mirror of https://github.com/mgba-emu/mgba.git
GB Video: Implement MLT_REQ controller iterating
This commit is contained in:
parent
2cd339d3f6
commit
0207048679
|
@ -62,7 +62,7 @@ enum GBSGBCommand {
|
||||||
SGB_PICON_EN,
|
SGB_PICON_EN,
|
||||||
SGB_DATA_SND,
|
SGB_DATA_SND,
|
||||||
SGB_DATA_TRN,
|
SGB_DATA_TRN,
|
||||||
SGB_MLT_REG,
|
SGB_MLT_REQ,
|
||||||
SGB_JUMP,
|
SGB_JUMP,
|
||||||
SGB_CHR_TRN,
|
SGB_CHR_TRN,
|
||||||
SGB_PCT_TRN,
|
SGB_PCT_TRN,
|
||||||
|
@ -107,6 +107,8 @@ struct GB {
|
||||||
int sgbBit;
|
int sgbBit;
|
||||||
int currentSgbBits;
|
int currentSgbBits;
|
||||||
uint8_t sgbPacket[16];
|
uint8_t sgbPacket[16];
|
||||||
|
uint8_t sgbControllers;
|
||||||
|
uint8_t sgbCurrentController;
|
||||||
|
|
||||||
struct mCoreCallbacksList coreCallbacks;
|
struct mCoreCallbacksList coreCallbacks;
|
||||||
struct mAVStream* stream;
|
struct mAVStream* stream;
|
||||||
|
|
|
@ -258,7 +258,9 @@ DECL_BITS(GBSerializedMemoryFlags, ActiveRtcReg, 5, 3);
|
||||||
DECL_BITFIELD(GBSerializedSGBFlags, uint32_t);
|
DECL_BITFIELD(GBSerializedSGBFlags, uint32_t);
|
||||||
DECL_BITS(GBSerializedSGBFlags, P1Bits, 0, 2);
|
DECL_BITS(GBSerializedSGBFlags, P1Bits, 0, 2);
|
||||||
DECL_BITS(GBSerializedSGBFlags, RenderMode, 2, 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)
|
#pragma pack(push, 1)
|
||||||
struct GBSerializedState {
|
struct GBSerializedState {
|
||||||
|
|
|
@ -446,6 +446,8 @@ void GBReset(struct LR35902Core* cpu) {
|
||||||
}
|
}
|
||||||
|
|
||||||
gb->sgbBit = -1;
|
gb->sgbBit = -1;
|
||||||
|
gb->sgbControllers = 0;
|
||||||
|
gb->sgbCurrentController = 0;
|
||||||
gb->currentSgbBits = 0;
|
gb->currentSgbBits = 0;
|
||||||
memset(gb->sgbPacket, 0, sizeof(gb->sgbPacket));
|
memset(gb->sgbPacket, 0, sizeof(gb->sgbPacket));
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,9 @@ static void _writeSGBBits(struct GB* gb, int bits) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gb->currentSgbBits = bits;
|
gb->currentSgbBits = bits;
|
||||||
|
if (bits == 3) {
|
||||||
|
gb->sgbCurrentController = (gb->sgbCurrentController + 1) & gb->sgbControllers;
|
||||||
|
}
|
||||||
if (gb->sgbBit == 128 && bits == 2) {
|
if (gb->sgbBit == 128 && bits == 2) {
|
||||||
GBVideoWriteSGBPacket(&gb->video, gb->sgbPacket);
|
GBVideoWriteSGBPacket(&gb->video, gb->sgbPacket);
|
||||||
++gb->sgbBit;
|
++gb->sgbBit;
|
||||||
|
@ -503,10 +506,13 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
|
||||||
|
|
||||||
static uint8_t _readKeys(struct GB* gb) {
|
static uint8_t _readKeys(struct GB* gb) {
|
||||||
uint8_t keys = *gb->keySource;
|
uint8_t keys = *gb->keySource;
|
||||||
|
if (gb->sgbCurrentController != 0) {
|
||||||
|
keys = 0;
|
||||||
|
}
|
||||||
switch (gb->memory.io[REG_JOYP] & 0x30) {
|
switch (gb->memory.io[REG_JOYP] & 0x30) {
|
||||||
case 0x30:
|
case 0x30:
|
||||||
// TODO: Increment
|
// 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;
|
break;
|
||||||
case 0x20:
|
case 0x20:
|
||||||
keys >>= 4;
|
keys >>= 4;
|
||||||
|
|
|
@ -213,6 +213,8 @@ void GBSGBSerialize(struct GB* gb, struct GBSerializedState* state) {
|
||||||
flags = GBSerializedSGBFlagsSetP1Bits(flags, gb->currentSgbBits);
|
flags = GBSerializedSGBFlagsSetP1Bits(flags, gb->currentSgbBits);
|
||||||
flags = GBSerializedSGBFlagsSetRenderMode(flags, gb->video.renderer->sgbRenderMode);
|
flags = GBSerializedSGBFlagsSetRenderMode(flags, gb->video.renderer->sgbRenderMode);
|
||||||
flags = GBSerializedSGBFlagsSetBufferIndex(flags, gb->video.sgbBufferIndex);
|
flags = GBSerializedSGBFlagsSetBufferIndex(flags, gb->video.sgbBufferIndex);
|
||||||
|
flags = GBSerializedSGBFlagsSetReqControllers(flags, gb->sgbControllers);
|
||||||
|
flags = GBSerializedSGBFlagsSetCurrentController(flags, gb->sgbCurrentController);
|
||||||
STORE_32LE(flags, 0, &state->sgb.flags);
|
STORE_32LE(flags, 0, &state->sgb.flags);
|
||||||
|
|
||||||
memcpy(state->sgb.packet, gb->video.sgbPacketBuffer, sizeof(state->sgb.packet));
|
memcpy(state->sgb.packet, gb->video.sgbPacketBuffer, sizeof(state->sgb.packet));
|
||||||
|
@ -244,6 +246,8 @@ void GBSGBDeserialize(struct GB* gb, const struct GBSerializedState* state) {
|
||||||
gb->currentSgbBits = GBSerializedSGBFlagsGetP1Bits(flags);
|
gb->currentSgbBits = GBSerializedSGBFlagsGetP1Bits(flags);
|
||||||
gb->video.renderer->sgbRenderMode = GBSerializedSGBFlagsGetRenderMode(flags);
|
gb->video.renderer->sgbRenderMode = GBSerializedSGBFlagsGetRenderMode(flags);
|
||||||
gb->video.sgbBufferIndex = GBSerializedSGBFlagsGetBufferIndex(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->video.sgbPacketBuffer, state->sgb.packet, sizeof(state->sgb.packet));
|
||||||
memcpy(gb->sgbPacket, state->sgb.inProgressPacket, sizeof(state->sgb.inProgressPacket));
|
memcpy(gb->sgbPacket, state->sgb.inProgressPacket, sizeof(state->sgb.inProgressPacket));
|
||||||
|
|
|
@ -701,7 +701,8 @@ void GBVideoWriteSGBPacket(struct GBVideo* video, uint8_t* data) {
|
||||||
case SGB_ATTR_TRN:
|
case SGB_ATTR_TRN:
|
||||||
case SGB_ATTR_SET:
|
case SGB_ATTR_SET:
|
||||||
break;
|
break;
|
||||||
case SGB_MLT_REG:
|
case SGB_MLT_REQ:
|
||||||
|
video->p->sgbControllers = video->sgbPacketBuffer[1] & 0x3;
|
||||||
return;
|
return;
|
||||||
case SGB_MASK_EN:
|
case SGB_MASK_EN:
|
||||||
video->renderer->sgbRenderMode = video->sgbPacketBuffer[1] & 0x3;
|
video->renderer->sgbRenderMode = video->sgbPacketBuffer[1] & 0x3;
|
||||||
|
|
Loading…
Reference in New Issue