Skip to content

Commit

Permalink
GBA DMA: Linger last DMA on bus (fixes mgba.io/i/301, fixes mgba.io/i…
Browse files Browse the repository at this point in the history
…/1320)
  • Loading branch information
endrift committed Jan 25, 2020
1 parent 38613e1 commit 93633ea
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Emulation fixes:
- ARM: Fix ALU reading PC after shifting
- ARM: Fix STR storing PC after address calculation
- GBA DMA: Linger last DMA on bus (fixes mgba.io/i/301 and mgba.io/i/1320)
- GBA Memory: Misaligned SRAM writes are ignored
- GBA Serialize: Fix serializing DMA transfer register
Other fixes:
Expand Down
1 change: 1 addition & 0 deletions include/mgba/internal/gba/gba.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct GBA {
bool haltPending;
bool cpuBlocked;
bool earlyExit;
uint32_t dmaPC;
int idleDetectionStep;
int idleDetectionFailures;
int32_t cachedRegisters[16];
Expand Down
3 changes: 2 additions & 1 deletion include/mgba/internal/gba/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,9 @@ struct GBASerializedState {
} hw;

uint32_t dmaTransferRegister;
uint32_t dmaBlockPC;

uint32_t reservedHardware[5];
uint32_t reservedHardware[4];

struct {
uint8_t type;
Expand Down
1 change: 1 addition & 0 deletions src/gba/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ void GBADMAUpdate(struct GBA* gba) {
}

if (memory->activeDMA >= 0) {
gba->dmaPC = gba->cpu->gprs[ARM_PC];
mTimingDeschedule(&gba->timing, &memory->dmaEvent);
mTimingSchedule(&gba->timing, &memory->dmaEvent, memory->dma[memory->activeDMA].when - currentTime);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/gba/gba.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ void GBAReset(struct ARMCore* cpu) {

gba->cpuBlocked = false;
gba->earlyExit = false;
gba->dmaPC = 0;
if (gba->yankedRomSize) {
gba->memory.romSize = gba->yankedRomSize;
gba->memory.romMask = toPow2(gba->memory.romSize) - 1;
Expand Down
2 changes: 2 additions & 0 deletions src/gba/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ void GBAIOSerialize(struct GBA* gba, struct GBASerializedState* state) {
}

STORE_32(gba->memory.dmaTransferRegister, 0, &state->dmaTransferRegister);
STORE_32(gba->dmaPC, 0, &state->dmaBlockPC);

GBAHardwareSerialize(&gba->memory.hw, state);
}
Expand Down Expand Up @@ -995,6 +996,7 @@ void GBAIODeserialize(struct GBA* gba, const struct GBASerializedState* state) {
GBAAudioWriteSOUNDCNT_X(&gba->audio, gba->memory.io[REG_SOUNDCNT_X >> 1]);

LOAD_32(gba->memory.dmaTransferRegister, 0, &state->dmaTransferRegister);
LOAD_32(gba->dmaPC, 0, &state->dmaBlockPC);

GBADMAUpdate(gba);
GBAHardwareDeserialize(&gba->memory.hw, state);
Expand Down
2 changes: 1 addition & 1 deletion src/gba/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) {
}

#define LOAD_BAD \
if (gba->performingDMA) { \
if (gba->performingDMA || cpu->gprs[ARM_PC] - gba->dmaPC == (gba->cpu->executionMode == MODE_THUMB ? WORD_SIZE_THUMB : WORD_SIZE_ARM)) { \
value = gba->bus; \
} else { \
value = cpu->prefetch[1]; \
Expand Down

0 comments on commit 93633ea

Please sign in to comment.