Skip to content

Commit

Permalink
DMA timing renovation (melonDS-emu#1207)
Browse files Browse the repository at this point in the history
* make timers usable for measurement shito without being assfuckingly unreliable

* bürp

* Arisotura can you ever clean up your goddamn code

also regroup the timer code instead of having it split weirdly

* make the set-timing functions a tad less hacky

* congrats Arisotura you made an ass-enum

* add timing region tables, and separate timings for ARM9 DMA (exempt of 3c penalty)

* temp work on DMA timings, not finished

also, did you know? 'increment/reload' is also a thing for the source address

* begin work

* add some of the GBA slot/wifi timings

* complete it, I guess

* make some progress

* getting somewhere

* sdsdfs

* see, Arisotura, was it that hard? blarg.
  • Loading branch information
Arisotura authored Aug 31, 2021
1 parent e1f3fc7 commit d20543c
Show file tree
Hide file tree
Showing 8 changed files with 785 additions and 216 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_library(core STATIC
CP15.cpp
CRC32.cpp
DMA.cpp
DMA_Timings.h
DSi.cpp
DSi_AES.cpp
DSi_Camera.cpp
Expand Down
30 changes: 19 additions & 11 deletions src/CP15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,16 @@ void ARMv5::UpdatePURegion(u32 n)
usermask |= 0x40;
}

//printf("PU region %d: %08X-%08X, user=%02X priv=%02X\n", n, start<<12, end<<12, usermask, privmask);
printf("PU region %d: %08X-%08X, user=%02X priv=%02X\n", n, start<<12, end<<12, usermask, privmask);
printf("%08X/%08X\n", PU_DataRW, PU_CodeRW);

for (u32 i = start; i < end; i++)
{
PU_UserMap[i] = usermask;
PU_PrivMap[i] = privmask;
}

UpdateRegionTimings(start<<12, end<<12);
UpdateRegionTimings(start, end);
}

void ARMv5::UpdatePURegions(bool update_all)
Expand All @@ -249,7 +250,7 @@ void ARMv5::UpdatePURegions(bool update_all)
memset(PU_UserMap, mask, 0x100000);
memset(PU_PrivMap, mask, 0x100000);

UpdateRegionTimings(0x00000000, 0xFFFFFFFF);
UpdateRegionTimings(0x00000, 0x100000);
return;
}

Expand All @@ -266,16 +267,11 @@ void ARMv5::UpdatePURegions(bool update_all)

// TODO: this is way unoptimized
// should be okay unless the game keeps changing shit, tho
if (update_all) UpdateRegionTimings(0x00000000, 0xFFFFFFFF);
if (update_all) UpdateRegionTimings(0x00000, 0x100000);
}

void ARMv5::UpdateRegionTimings(u32 addrstart, u32 addrend)
{
addrstart >>= 12;
addrend >>= 12;

if (addrend == 0xFFFFF) addrend++;

for (u32 i = addrstart; i < addrend; i++)
{
u8 pu = PU_Map[i];
Expand Down Expand Up @@ -420,7 +416,7 @@ void ARMv5::ICacheInvalidateAll()

void ARMv5::CP15Write(u32 id, u32 val)
{
//printf("CP15 write op %03X %08X %08X\n", id, val, R[15]);
//if(id!=0x704)printf("CP15 write op %03X %08X %08X\n", id, val, R[15]);

switch (id)
{
Expand Down Expand Up @@ -520,7 +516,7 @@ void ARMv5::CP15Write(u32 id, u32 val)
return;

case 0x502: // data permissions
{
{printf("SET DATAPERM %08X (%08X %08X)\n", val,PU_DataRW,PU_DataRW ^ val);
u32 diff = PU_DataRW ^ val;
PU_DataRW = val;
for (u32 i = 0; i < 8; i++)
Expand Down Expand Up @@ -814,6 +810,12 @@ void ARMv5::DataRead16(u32 addr, u32* val)

void ARMv5::DataRead32(u32 addr, u32* val)
{
/*if (!(PU_Map[addr>>12] & 0x01))
{printf("addr %08X very bad\n", addr);
DataAbort();
return;
}*/

DataRegion = addr;

addr &= ~3;
Expand Down Expand Up @@ -908,6 +910,12 @@ void ARMv5::DataWrite16(u32 addr, u16 val)

void ARMv5::DataWrite32(u32 addr, u32 val)
{
/*if (!(PU_Map[addr>>12] & 0x02))
{printf("addr %08X wr very bad\n", addr);
DataAbort();
return;
}*/

DataRegion = addr;

addr &= ~3;
Expand Down
Loading

0 comments on commit d20543c

Please sign in to comment.