GBA DMA: Minor optimization of warm function

This commit is contained in:
Vicki Pfau 2022-11-30 17:44:53 -08:00
parent 2ba42761b8
commit 3385f02b51
1 changed files with 9 additions and 14 deletions

View File

@ -244,7 +244,6 @@ void GBADMAService(struct GBA* gba, int number, struct GBADMA* info) {
struct GBAMemory* memory = &gba->memory; struct GBAMemory* memory = &gba->memory;
struct ARMCore* cpu = gba->cpu; struct ARMCore* cpu = gba->cpu;
uint32_t width = 2 << GBADMARegisterGetWidth(info->reg); uint32_t width = 2 << GBADMARegisterGetWidth(info->reg);
int32_t wordsRemaining = info->nextCount;
uint32_t source = info->nextSource; uint32_t source = info->nextSource;
uint32_t dest = info->nextDest; uint32_t dest = info->nextDest;
uint32_t sourceRegion = source >> BASE_OFFSET; uint32_t sourceRegion = source >> BASE_OFFSET;
@ -252,6 +251,8 @@ void GBADMAService(struct GBA* gba, int number, struct GBADMA* info) {
int32_t cycles = 2; int32_t cycles = 2;
gba->cpuBlocked = true; gba->cpuBlocked = true;
gba->performingDMA = 1 | (number << 1);
if (info->count == info->nextCount) { if (info->count == info->nextCount) {
if (width == 4) { if (width == 4) {
cycles += memory->waitstatesNonseq32[sourceRegion] + memory->waitstatesNonseq32[destRegion]; cycles += memory->waitstatesNonseq32[sourceRegion] + memory->waitstatesNonseq32[destRegion];
@ -267,12 +268,10 @@ void GBADMAService(struct GBA* gba, int number, struct GBADMA* info) {
} }
info->when += cycles; info->when += cycles;
gba->performingDMA = 1 | (number << 1);
if (width == 4) { if (width == 4) {
if (source) { if (source) {
memory->dmaTransferRegister = cpu->memory.load32(cpu, source, 0); memory->dmaTransferRegister = cpu->memory.load32(cpu, source, 0);
} }
gba->bus = memory->dmaTransferRegister;
cpu->memory.store32(cpu, dest, memory->dmaTransferRegister, 0); cpu->memory.store32(cpu, dest, memory->dmaTransferRegister, 0);
} else { } else {
if (sourceRegion == REGION_CART2_EX && (memory->savedata.type == SAVEDATA_EEPROM || memory->savedata.type == SAVEDATA_EEPROM512)) { if (sourceRegion == REGION_CART2_EX && (memory->savedata.type == SAVEDATA_EEPROM || memory->savedata.type == SAVEDATA_EEPROM512)) {
@ -288,14 +287,13 @@ void GBADMAService(struct GBA* gba, int number, struct GBADMA* info) {
GBASavedataInitEEPROM(&memory->savedata); GBASavedataInitEEPROM(&memory->savedata);
} }
if (memory->savedata.type == SAVEDATA_EEPROM512 || memory->savedata.type == SAVEDATA_EEPROM) { if (memory->savedata.type == SAVEDATA_EEPROM512 || memory->savedata.type == SAVEDATA_EEPROM) {
GBASavedataWriteEEPROM(&memory->savedata, memory->dmaTransferRegister, wordsRemaining); GBASavedataWriteEEPROM(&memory->savedata, memory->dmaTransferRegister, info->nextCount);
} }
} else { } else {
cpu->memory.store16(cpu, dest, memory->dmaTransferRegister, 0); cpu->memory.store16(cpu, dest, memory->dmaTransferRegister, 0);
}
} }
gba->bus = memory->dmaTransferRegister; gba->bus = memory->dmaTransferRegister;
}
int sourceOffset; int sourceOffset;
if (info->nextSource >= BASE_CART0 && info->nextSource < BASE_CART_SRAM && GBADMARegisterGetSrcControl(info->reg) < 3) { if (info->nextSource >= BASE_CART0 && info->nextSource < BASE_CART_SRAM && GBADMARegisterGetSrcControl(info->reg) < 3) {
@ -305,15 +303,12 @@ void GBADMAService(struct GBA* gba, int number, struct GBADMA* info) {
} }
int destOffset = DMA_OFFSET[GBADMARegisterGetDestControl(info->reg)] * width; int destOffset = DMA_OFFSET[GBADMARegisterGetDestControl(info->reg)] * width;
if (source) { if (source) {
source += sourceOffset; info->nextSource += sourceOffset;
} }
dest += destOffset; info->nextDest += destOffset;
--wordsRemaining; --info->nextCount;
gba->performingDMA = 0;
info->nextCount = wordsRemaining; gba->performingDMA = 0;
info->nextSource = source;
info->nextDest = dest;
int i; int i;
for (i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
@ -324,7 +319,7 @@ void GBADMAService(struct GBA* gba, int number, struct GBADMA* info) {
} }
} }
if (!wordsRemaining) { if (!info->nextCount) {
info->nextCount |= 0x80000000; info->nextCount |= 0x80000000;
if (sourceRegion < REGION_CART0 || destRegion < REGION_CART0) { if (sourceRegion < REGION_CART0 || destRegion < REGION_CART0) {
info->when += 2; info->when += 2;