GB Video: Implement MLT_REQ controller iterating

This commit is contained in:
Vicki Pfau 2018-04-21 17:57:49 -07:00
parent 2cd339d3f6
commit 0207048679
6 changed files with 21 additions and 4 deletions

View File

@ -62,7 +62,7 @@ enum GBSGBCommand {
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 @@ struct GB {
int sgbBit;
int currentSgbBits;
uint8_t sgbPacket[16];
uint8_t sgbControllers;
uint8_t sgbCurrentController;
struct mCoreCallbacksList coreCallbacks;
struct mAVStream* stream;

View File

@ -258,7 +258,9 @@ DECL_BITS(GBSerializedMemoryFlags, ActiveRtcReg, 5, 3);
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 {

View File

@ -446,6 +446,8 @@ void GBReset(struct LR35902Core* cpu) {
}
gb->sgbBit = -1;
gb->sgbControllers = 0;
gb->sgbCurrentController = 0;
gb->currentSgbBits = 0;
memset(gb->sgbPacket, 0, sizeof(gb->sgbPacket));

View File

@ -113,6 +113,9 @@ static void _writeSGBBits(struct GB* gb, int bits) {
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 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
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;

View File

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

View File

@ -701,7 +701,8 @@ void GBVideoWriteSGBPacket(struct GBVideo* video, uint8_t* data) {
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;