Skip to content

Commit 1ebe58b

Browse files
committed
fix possible freeze during cart transfer (Dragon Ball 2)
1 parent ce3dc37 commit 1ebe58b

6 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/DMA.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ void DMA::WriteCnt(u32 val)
145145

146146
if ((StartMode & 0x7) == 0)
147147
Start();
148+
else if (StartMode == 0x05 || StartMode == 0x12)
149+
NDS.NDSCartSlots[0]->CheckDMA(CPU);
148150
else if (StartMode == 0x07)
149151
NDS.GPU.GPU3D.CheckFIFODMA();
150152

@@ -621,6 +623,9 @@ void DMA::Run9()
621623
Running = 0;
622624
InProgress = false;
623625
NDS.ResumeCPU(0, 1<<Num);
626+
627+
if (StartMode == 0x05)
628+
NDS.NDSCartSlots[0]->CheckDMA(0);
624629
}
625630

626631
void DMA::Run7()
@@ -691,6 +696,9 @@ void DMA::Run7()
691696
Running = 0;
692697
InProgress = false;
693698
NDS.ResumeCPU(1, 1<<Num);
699+
700+
if (StartMode == 0x12)
701+
NDS.NDSCartSlots[0]->CheckDMA(1);
694702
}
695703

696704
void DMA::Run()

src/DSi_NDMA.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ void DSi_NDMA::WriteCnt(u32 val)
127127

128128
if ((StartMode & 0x1F) == 0x10)
129129
Start();
130+
else if (StartMode == 0x04 || StartMode == 0x24)
131+
DSi.NDSCartSlots[0]->CheckDMA(CPU);
132+
else if (StartMode == 0x05 || StartMode == 0x25)
133+
DSi.NDSCartSlots[1]->CheckDMA(CPU);
130134
else if (StartMode == 0x0A)
131135
DSi.GPU.GPU3D.CheckFIFODMA();
132136

@@ -290,6 +294,11 @@ void DSi_NDMA::Run9()
290294
Running = 0;
291295
InProgress = false;
292296
DSi.ResumeCPU(0, 1<<(Num+4));
297+
298+
if (StartMode == 0x04)
299+
DSi.NDSCartSlots[0]->CheckDMA(0);
300+
else if (StartMode == 0x05)
301+
DSi.NDSCartSlots[1]->CheckDMA(0);
293302
}
294303

295304
void DSi_NDMA::Run7()
@@ -389,6 +398,11 @@ void DSi_NDMA::Run7()
389398

390399
DSi.AES.CheckInputDMA();
391400
DSi.AES.CheckOutputDMA();
401+
402+
if (StartMode == 0x24)
403+
DSi.NDSCartSlots[0]->CheckDMA(1);
404+
else if (StartMode == 0x25)
405+
DSi.NDSCartSlots[1]->CheckDMA(1);
392406
}
393407

394408
}

src/NDS.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,8 +1933,8 @@ void NDS::debug(u32 param)
19331933

19341934
//for (int i = 0; i < 9; i++)
19351935
// printf("VRAM %c: %02X\n", 'A'+i, GPU->VRAMCNT[i]);
1936-
1937-
/*Platform::FileHandle* shit = Platform::OpenFile("debug/pokeplat.bin", FileMode::Write);
1936+
return;
1937+
Platform::FileHandle* shit = Platform::OpenFile("debug/dragonball.bin", FileMode::Write);
19381938
Platform::FileWrite(ARM9.ITCM, 0x8000, 1, shit);
19391939
for (u32 i = 0x02000000; i < 0x02400000; i+=4)
19401940
{
@@ -1951,9 +1951,9 @@ void NDS::debug(u32 param)
19511951
u32 val = NDS::ARM7Read32(i);
19521952
Platform::FileWrite(&val, 4, 1, shit);
19531953
}
1954-
Platform::CloseFile(shit);*/
1954+
Platform::CloseFile(shit);
19551955

1956-
FILE*
1956+
/*FILE*
19571957
shit = fopen("debug/bowser9.bin", "wb");
19581958
fwrite(ARM9.ITCM, 0x8000, 1, shit);
19591959
for (u32 i = 0x02000000; i < 0x04000000; i+=4)
@@ -1968,7 +1968,7 @@ void NDS::debug(u32 param)
19681968
u32 val = ARM7Read32(i);
19691969
fwrite(&val, 4, 1, shit);
19701970
}
1971-
fclose(shit);
1971+
fclose(shit);*/
19721972
}
19731973

19741974

src/NDSCart.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,17 @@ void NDSCartSlot::Interface::RaiseDRQ()
959959
// TODO: the DMA trigger is level-sensitive
960960
// thus, if a cart DMA gets set up while DRQ is already active, it will start immediately
961961
// emulating this would require keeping track of the DMA trigger line states somewhere
962+
// the current handling for this is a hack
963+
// (DMA triggering needs a cleanup anyway)
962964

963965
ROMCnt |= (1<<23);
966+
CheckDMA();
967+
}
968+
969+
void NDSCartSlot::Interface::CheckDMA()
970+
{
971+
if (!(ROMCnt & (1<<23)))
972+
return;
964973

965974
// TODO: make this code suck less!!
966975
// maybe have a general "DMA trigger function" that covers both DMA types for DSi

src/NDSCart.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class NDSCartSlot
138138
u32 ReadROMData(u32 cpu) noexcept { return Interfaces[cpu].ReadROMData(); }
139139
void WriteROMData(u32 cpu, u32 val, u32 mask) noexcept { Interfaces[cpu].WriteROMData(val, mask); }
140140

141+
void CheckDMA(u32 cpu) { return Interfaces[cpu].CheckDMA(); }
142+
141143
void RaiseCardIRQ();
142144

143145
private:
@@ -177,6 +179,7 @@ class NDSCartSlot
177179
void ROMAdvanceSend();
178180
void ROMEndTransfer(u32 param);
179181
void RaiseDRQ();
182+
void CheckDMA();
180183

181184
void SPITransferDone(u32 param);
182185

src/frontend/qt_sdl/Window.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ void MainWindow::keyPressEvent(QKeyEvent* event)
964964
if (event->isAutoRepeat()) return;
965965

966966
// TODO!! REMOVE ME IN RELEASE BUILDS!!
967-
//if (event->key() == Qt::Key_F11) emuInstance->getNDS()->debug(0);
967+
if (event->key() == Qt::Key_F11) emuInstance->getNDS()->debug(0);
968968

969969
emuInstance->onKeyPress(event);
970970
}

0 commit comments

Comments
 (0)