move TCM shit to CP15.cpp. closer to the real thing (for example now DMA can't access TCM, etc).
the code is shit. I would use templates if only it fucking worked without requiring the function body to be included in a .h.
This commit is contained in:
parent
6f3b0498db
commit
348bbd8cb8
33
ARM.h
33
ARM.h
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "types.h"
|
||||
#include "NDS.h"
|
||||
#include "CP15.h"
|
||||
|
||||
// lame
|
||||
#define C_S(x) x
|
||||
|
@ -87,8 +88,8 @@ public:
|
|||
// TODO eventually: on ARM9, THUMB opcodes are prefetched with 32bit reads
|
||||
if (!Num)
|
||||
{
|
||||
// TODO: PU shit
|
||||
val = NDS::ARM9Read16(addr);
|
||||
if (!CP15::HandleCodeRead16(addr, &val))
|
||||
val = NDS::ARM9Read16(addr);
|
||||
}
|
||||
else
|
||||
val = NDS::ARM7Read16(addr);
|
||||
|
@ -102,8 +103,8 @@ public:
|
|||
u32 val;
|
||||
if (!Num)
|
||||
{
|
||||
// TODO: PU shit
|
||||
val = NDS::ARM9Read32(addr);
|
||||
if (!CP15::HandleCodeRead32(addr, &val))
|
||||
val = NDS::ARM9Read32(addr);
|
||||
}
|
||||
else
|
||||
val = NDS::ARM7Read32(addr);
|
||||
|
@ -118,8 +119,8 @@ public:
|
|||
u8 val;
|
||||
if (!Num)
|
||||
{
|
||||
// TODO: PU shit
|
||||
val = NDS::ARM9Read8(addr);
|
||||
if (!CP15::HandleDataRead8(addr, &val, forceuser))
|
||||
val = NDS::ARM9Read8(addr);
|
||||
}
|
||||
else
|
||||
val = NDS::ARM7Read8(addr);
|
||||
|
@ -134,8 +135,8 @@ public:
|
|||
addr &= ~1;
|
||||
if (!Num)
|
||||
{
|
||||
// TODO: PU shit
|
||||
val = NDS::ARM9Read16(addr);
|
||||
if (!CP15::HandleDataRead16(addr, &val, forceuser))
|
||||
val = NDS::ARM9Read16(addr);
|
||||
}
|
||||
else
|
||||
val = NDS::ARM7Read16(addr);
|
||||
|
@ -150,8 +151,8 @@ public:
|
|||
addr &= ~3;
|
||||
if (!Num)
|
||||
{
|
||||
// TODO: PU shit
|
||||
val = NDS::ARM9Read32(addr);
|
||||
if (!CP15::HandleDataRead32(addr, &val, forceuser))
|
||||
val = NDS::ARM9Read32(addr);
|
||||
}
|
||||
else
|
||||
val = NDS::ARM7Read32(addr);
|
||||
|
@ -164,8 +165,8 @@ public:
|
|||
{
|
||||
if (!Num)
|
||||
{
|
||||
// TODO: PU shit
|
||||
NDS::ARM9Write8(addr, val);
|
||||
if (!CP15::HandleDataWrite8(addr, val, forceuser))
|
||||
NDS::ARM9Write8(addr, val);
|
||||
}
|
||||
else
|
||||
NDS::ARM7Write8(addr, val);
|
||||
|
@ -178,8 +179,8 @@ public:
|
|||
addr &= ~1;
|
||||
if (!Num)
|
||||
{
|
||||
// TODO: PU shit
|
||||
NDS::ARM9Write16(addr, val);
|
||||
if (!CP15::HandleDataWrite16(addr, val, forceuser))
|
||||
NDS::ARM9Write16(addr, val);
|
||||
}
|
||||
else
|
||||
NDS::ARM7Write16(addr, val);
|
||||
|
@ -192,8 +193,8 @@ public:
|
|||
addr &= ~3;
|
||||
if (!Num)
|
||||
{
|
||||
// TODO: PU shit
|
||||
NDS::ARM9Write32(addr, val);
|
||||
if (!CP15::HandleDataWrite32(addr, val, forceuser))
|
||||
NDS::ARM9Write32(addr, val);
|
||||
}
|
||||
else
|
||||
NDS::ARM7Write32(addr, val);
|
||||
|
|
152
CP15.cpp
152
CP15.cpp
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "NDS.h"
|
||||
#include "ARM.h"
|
||||
#include "CP15.h"
|
||||
|
@ -35,6 +36,11 @@ u32 Control;
|
|||
|
||||
u32 DTCMSetting, ITCMSetting;
|
||||
|
||||
u8 ITCM[0x8000];
|
||||
u32 ITCMSize;
|
||||
u8 DTCM[0x4000];
|
||||
u32 DTCMBase, DTCMSize;
|
||||
|
||||
|
||||
void Reset()
|
||||
{
|
||||
|
@ -42,6 +48,13 @@ void Reset()
|
|||
|
||||
DTCMSetting = 0;
|
||||
ITCMSetting = 0;
|
||||
|
||||
memset(ITCM, 0, 0x8000);
|
||||
memset(DTCM, 0, 0x4000);
|
||||
|
||||
ITCMSize = 0;
|
||||
DTCMBase = 0xFFFFFFFF;
|
||||
DTCMSize = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -49,14 +62,14 @@ void UpdateDTCMSetting()
|
|||
{
|
||||
if (Control & (1<<16))
|
||||
{
|
||||
NDS::ARM9DTCMBase = DTCMSetting & 0xFFFFF000;
|
||||
NDS::ARM9DTCMSize = 0x200 << ((DTCMSetting >> 1) & 0x1F);
|
||||
printf("DTCM [%08X] enabled at %08X, size %X\n", DTCMSetting, NDS::ARM9DTCMBase, NDS::ARM9DTCMSize);
|
||||
DTCMBase = DTCMSetting & 0xFFFFF000;
|
||||
DTCMSize = 0x200 << ((DTCMSetting >> 1) & 0x1F);
|
||||
printf("DTCM [%08X] enabled at %08X, size %X\n", DTCMSetting, DTCMBase, DTCMSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
NDS::ARM9DTCMBase = 0xFFFFFFFF;
|
||||
NDS::ARM9DTCMSize = 0;
|
||||
DTCMBase = 0xFFFFFFFF;
|
||||
DTCMSize = 0;
|
||||
printf("DTCM disabled\n");
|
||||
}
|
||||
}
|
||||
|
@ -65,12 +78,12 @@ void UpdateITCMSetting()
|
|||
{
|
||||
if (Control & (1<<18))
|
||||
{
|
||||
NDS::ARM9ITCMSize = 0x200 << ((ITCMSetting >> 1) & 0x1F);
|
||||
printf("ITCM [%08X] enabled at %08X, size %X\n", ITCMSetting, 0, NDS::ARM9ITCMSize);
|
||||
ITCMSize = 0x200 << ((ITCMSetting >> 1) & 0x1F);
|
||||
printf("ITCM [%08X] enabled at %08X, size %X\n", ITCMSetting, 0, ITCMSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
NDS::ARM9ITCMSize = 0;
|
||||
ITCMSize = 0;
|
||||
printf("ITCM disabled\n");
|
||||
}
|
||||
}
|
||||
|
@ -159,4 +172,127 @@ u32 Read(u32 id)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// TCM are handled here.
|
||||
// TODO: later on, handle PU, and maybe caches
|
||||
|
||||
bool HandleCodeRead16(u32 addr, u16* val)
|
||||
{
|
||||
if (addr < ITCMSize)
|
||||
{
|
||||
*val = *(u16*)&ITCM[addr & 0x7FFF];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandleCodeRead32(u32 addr, u32* val)
|
||||
{
|
||||
if (addr < ITCMSize)
|
||||
{
|
||||
*val = *(u32*)&ITCM[addr & 0x7FFF];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool HandleDataRead8(u32 addr, u8* val, u32 forceuser)
|
||||
{
|
||||
if (addr < ITCMSize)
|
||||
{
|
||||
*val = *(u8*)&ITCM[addr & 0x7FFF];
|
||||
return true;
|
||||
}
|
||||
if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize))
|
||||
{
|
||||
*val = *(u8*)&DTCM[(addr - DTCMBase) & 0x3FFF];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandleDataRead16(u32 addr, u16* val, u32 forceuser)
|
||||
{
|
||||
if (addr < ITCMSize)
|
||||
{
|
||||
*val = *(u16*)&ITCM[addr & 0x7FFF];
|
||||
return true;
|
||||
}
|
||||
if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize))
|
||||
{
|
||||
*val = *(u16*)&DTCM[(addr - DTCMBase) & 0x3FFF];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandleDataRead32(u32 addr, u32* val, u32 forceuser)
|
||||
{
|
||||
if (addr < ITCMSize)
|
||||
{
|
||||
*val = *(u32*)&ITCM[addr & 0x7FFF];
|
||||
return true;
|
||||
}
|
||||
if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize))
|
||||
{
|
||||
*val = *(u32*)&DTCM[(addr - DTCMBase) & 0x3FFF];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandleDataWrite8(u32 addr, u8 val, u32 forceuser)
|
||||
{
|
||||
if (addr < ITCMSize)
|
||||
{
|
||||
*(u8*)&ITCM[addr & 0x7FFF] = val;
|
||||
return true;
|
||||
}
|
||||
if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize))
|
||||
{
|
||||
*(u8*)&DTCM[(addr - DTCMBase) & 0x3FFF] = val;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandleDataWrite16(u32 addr, u16 val, u32 forceuser)
|
||||
{
|
||||
if (addr < ITCMSize)
|
||||
{
|
||||
*(u16*)&ITCM[addr & 0x7FFF] = val;
|
||||
return true;
|
||||
}
|
||||
if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize))
|
||||
{
|
||||
*(u16*)&DTCM[(addr - DTCMBase) & 0x3FFF] = val;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandleDataWrite32(u32 addr, u32 val, u32 forceuser)
|
||||
{
|
||||
if (addr < ITCMSize)
|
||||
{
|
||||
*(u32*)&ITCM[addr & 0x7FFF] = val;
|
||||
return true;
|
||||
}
|
||||
if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize))
|
||||
{
|
||||
*(u32*)&DTCM[(addr - DTCMBase) & 0x3FFF] = val;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
9
CP15.h
9
CP15.h
|
@ -30,6 +30,15 @@ void UpdateITCMSetting();
|
|||
void Write(u32 id, u32 val);
|
||||
u32 Read(u32 id);
|
||||
|
||||
bool HandleCodeRead16(u32 addr, u16* val);
|
||||
bool HandleCodeRead32(u32 addr, u32* val);
|
||||
bool HandleDataRead8(u32 addr, u8* val, u32 forceuser=0);
|
||||
bool HandleDataRead16(u32 addr, u16* val, u32 forceuser=0);
|
||||
bool HandleDataRead32(u32 addr, u32* val, u32 forceuser=0);
|
||||
bool HandleDataWrite8(u32 addr, u8 val, u32 forceuser=0);
|
||||
bool HandleDataWrite16(u32 addr, u16 val, u32 forceuser=0);
|
||||
bool HandleDataWrite32(u32 addr, u32 val, u32 forceuser=0);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
87
NDS.cpp
87
NDS.cpp
|
@ -64,11 +64,6 @@ u32 SWRAM_ARM7Mask;
|
|||
|
||||
u8 ARM7WRAM[0x10000];
|
||||
|
||||
u8 ARM9ITCM[0x8000];
|
||||
u32 ARM9ITCMSize;
|
||||
u8 ARM9DTCM[0x4000];
|
||||
u32 ARM9DTCMBase, ARM9DTCMSize;
|
||||
|
||||
u16 ExMemCnt[2];
|
||||
|
||||
u8 ROMSeed0[2*8];
|
||||
|
@ -206,15 +201,9 @@ void Reset()
|
|||
memset(MainRAM, 0, 0x400000);
|
||||
memset(SharedWRAM, 0, 0x8000);
|
||||
memset(ARM7WRAM, 0, 0x10000);
|
||||
memset(ARM9ITCM, 0, 0x8000);
|
||||
memset(ARM9DTCM, 0, 0x4000);
|
||||
|
||||
MapSharedWRAM(0);
|
||||
|
||||
ARM9ITCMSize = 0;
|
||||
ARM9DTCMBase = 0xFFFFFFFF;
|
||||
ARM9DTCMSize = 0;
|
||||
|
||||
ExMemCnt[0] = 0;
|
||||
ExMemCnt[1] = 0;
|
||||
memset(ROMSeed0, 0, 2*8);
|
||||
|
@ -682,14 +671,6 @@ u8 ARM9Read8(u32 addr)
|
|||
{
|
||||
return *(u8*)&ARM9BIOS[addr & 0xFFF];
|
||||
}
|
||||
if (addr < ARM9ITCMSize)
|
||||
{
|
||||
return *(u8*)&ARM9ITCM[addr & 0x7FFF];
|
||||
}
|
||||
if (addr >= ARM9DTCMBase && addr < (ARM9DTCMBase + ARM9DTCMSize))
|
||||
{
|
||||
return *(u8*)&ARM9DTCM[(addr - ARM9DTCMBase) & 0x3FFF];
|
||||
}
|
||||
|
||||
switch (addr & 0xFF000000)
|
||||
{
|
||||
|
@ -741,14 +722,6 @@ u16 ARM9Read16(u32 addr)
|
|||
{
|
||||
return *(u16*)&ARM9BIOS[addr & 0xFFF];
|
||||
}
|
||||
if (addr < ARM9ITCMSize)
|
||||
{
|
||||
return *(u16*)&ARM9ITCM[addr & 0x7FFF];
|
||||
}
|
||||
if (addr >= ARM9DTCMBase && addr < (ARM9DTCMBase + ARM9DTCMSize))
|
||||
{
|
||||
return *(u16*)&ARM9DTCM[(addr - ARM9DTCMBase) & 0x3FFF];
|
||||
}
|
||||
|
||||
switch (addr & 0xFF000000)
|
||||
{
|
||||
|
@ -800,29 +773,6 @@ u32 ARM9Read32(u32 addr)
|
|||
{
|
||||
return *(u32*)&ARM9BIOS[addr & 0xFFF];
|
||||
}
|
||||
if (addr < ARM9ITCMSize)
|
||||
{
|
||||
return *(u32*)&ARM9ITCM[addr & 0x7FFF];
|
||||
}
|
||||
if (addr >= ARM9DTCMBase && addr < (ARM9DTCMBase + ARM9DTCMSize))
|
||||
{
|
||||
return *(u32*)&ARM9DTCM[(addr - ARM9DTCMBase) & 0x3FFF];
|
||||
}
|
||||
|
||||
if (addr >= 0xFFFF1000)
|
||||
{
|
||||
printf("!!!!!!!!!!!!!\n");
|
||||
Halt();
|
||||
/*FILE* f = fopen("ram.bin", "wb");
|
||||
fwrite(MainRAM, 0x400000, 1, f);
|
||||
fclose(f);
|
||||
fopen("wram.bin", "wb");
|
||||
fwrite(ARM7WRAM, 0x10000, 1, f);
|
||||
fclose(f);
|
||||
fopen("swram.bin", "wb");
|
||||
fwrite(ARM7WRAM, 0x8000, 1, f);
|
||||
fclose(f);*/
|
||||
}
|
||||
|
||||
switch (addr & 0xFF000000)
|
||||
{
|
||||
|
@ -870,17 +820,6 @@ u32 ARM9Read32(u32 addr)
|
|||
|
||||
void ARM9Write8(u32 addr, u8 val)
|
||||
{
|
||||
if (addr < ARM9ITCMSize)
|
||||
{
|
||||
*(u8*)&ARM9ITCM[addr & 0x7FFF] = val;
|
||||
return;
|
||||
}
|
||||
if (addr >= ARM9DTCMBase && addr < (ARM9DTCMBase + ARM9DTCMSize))
|
||||
{
|
||||
*(u8*)&ARM9DTCM[(addr - ARM9DTCMBase) & 0x3FFF] = val;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (addr & 0xFF000000)
|
||||
{
|
||||
case 0x02000000:
|
||||
|
@ -906,19 +845,6 @@ void ARM9Write8(u32 addr, u8 val)
|
|||
|
||||
void ARM9Write16(u32 addr, u16 val)
|
||||
{
|
||||
if (addr == ARM9->R[15]) printf("!!!!!!!!!!!!9999 %08X %04X\n", addr, val);
|
||||
|
||||
if (addr < ARM9ITCMSize)
|
||||
{
|
||||
*(u16*)&ARM9ITCM[addr & 0x7FFF] = val;
|
||||
return;
|
||||
}
|
||||
if (addr >= ARM9DTCMBase && addr < (ARM9DTCMBase + ARM9DTCMSize))
|
||||
{
|
||||
*(u16*)&ARM9DTCM[(addr - ARM9DTCMBase) & 0x3FFF] = val;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (addr & 0xFF000000)
|
||||
{
|
||||
case 0x02000000:
|
||||
|
@ -964,19 +890,6 @@ void ARM9Write16(u32 addr, u16 val)
|
|||
|
||||
void ARM9Write32(u32 addr, u32 val)
|
||||
{
|
||||
if (addr == ARM9->R[15]) printf("!!!!!!!!!!!!9999 %08X %08X\n", addr, val);
|
||||
|
||||
if (addr < ARM9ITCMSize)
|
||||
{
|
||||
*(u32*)&ARM9ITCM[addr & 0x7FFF] = val;
|
||||
return;
|
||||
}
|
||||
if (addr >= ARM9DTCMBase && addr < (ARM9DTCMBase + ARM9DTCMSize))
|
||||
{
|
||||
*(u32*)&ARM9DTCM[(addr - ARM9DTCMBase) & 0x3FFF] = val;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (addr & 0xFF000000)
|
||||
{
|
||||
case 0x02000000:
|
||||
|
|
3
NDS.h
3
NDS.h
|
@ -103,9 +103,6 @@ extern u8 ROMSeed1[2*8];
|
|||
extern u8 ARM9BIOS[0x1000];
|
||||
extern u8 ARM7BIOS[0x4000];
|
||||
|
||||
extern u32 ARM9ITCMSize;
|
||||
extern u32 ARM9DTCMBase, ARM9DTCMSize;
|
||||
|
||||
void Init();
|
||||
void Reset();
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
"NDS.h"
|
||||
"GPU.h"
|
||||
|
||||
1485792939 c:\documents\sources\melonds\nds.h
|
||||
1485798225 c:\documents\sources\melonds\nds.h
|
||||
"types.h"
|
||||
|
||||
1481161027 c:\documents\sources\melonds\types.h
|
||||
|
||||
1485374133 source:c:\documents\sources\melonds\nds.cpp
|
||||
1485798397 source:c:\documents\sources\melonds\nds.cpp
|
||||
<stdio.h>
|
||||
<string.h>
|
||||
"NDS.h"
|
||||
|
@ -30,9 +30,10 @@
|
|||
"ARM.h"
|
||||
"ARMInterpreter.h"
|
||||
|
||||
1485797447 c:\documents\sources\melonds\arm.h
|
||||
1485799759 c:\documents\sources\melonds\arm.h
|
||||
"types.h"
|
||||
"NDS.h"
|
||||
"CP15.h"
|
||||
|
||||
1484530962 c:\documents\sources\melonds\arm_instrtable.h
|
||||
|
||||
|
@ -68,17 +69,18 @@
|
|||
<stdio.h>
|
||||
"ARM.h"
|
||||
|
||||
1481037554 c:\documents\sources\melonds\cp15.h
|
||||
1485799621 c:\documents\sources\melonds\cp15.h
|
||||
|
||||
1485136658 source:c:\documents\sources\melonds\cp15.cpp
|
||||
1485799278 source:c:\documents\sources\melonds\cp15.cpp
|
||||
<stdio.h>
|
||||
<string.h>
|
||||
"NDS.h"
|
||||
"ARM.h"
|
||||
"CP15.h"
|
||||
|
||||
1480957111 c:\documents\sources\melonds\spi.h
|
||||
|
||||
1485137440 source:c:\documents\sources\melonds\spi.cpp
|
||||
1485797744 source:c:\documents\sources\melonds\spi.cpp
|
||||
<stdio.h>
|
||||
<string.h>
|
||||
"NDS.h"
|
||||
|
|
Loading…
Reference in New Issue