diff options
author | StapleButter <thetotalworm@gmail.com> | 2016-11-03 01:38:58 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2016-11-03 01:38:58 +0100 |
commit | 3505ec993b0d700800f77c667078e2c552a38b34 (patch) | |
tree | 35ffbbe7657e6c1b70197d4450e57f1cafa8ba4e | |
parent | 5b7ae6dab3fa260903d9348bdac7add6a81b7336 (diff) |
hey look, more crap
no MrRean this doesn't run NSMB yet
-rw-r--r-- | ARM.cpp | 50 | ||||
-rw-r--r-- | ARM.h | 40 | ||||
-rw-r--r-- | NDS.cpp | 50 | ||||
-rw-r--r-- | NDS.h | 3 | ||||
-rw-r--r-- | main.cpp | 1 | ||||
-rw-r--r-- | melonDS.cbp | 3 | ||||
-rw-r--r-- | melonDS.depend | 20 | ||||
-rw-r--r-- | melonDS.layout | 15 |
8 files changed, 180 insertions, 2 deletions
@@ -0,0 +1,50 @@ +#include "ARM.h" +#include "NDS.h" + + +ARM::ARM(u32 num) +{ + // well uh + Num = num; + + for (int i = 0; i < 16; i++) + R[i] = 0; + + ExceptionBase = num ? 0x00000000 : 0xFFFF0000; + + // zorp + JumpTo(ExceptionBase); +} + +ARM::~ARM() +{ + // dorp +} + +void ARM::JumpTo(u32 addr) +{ + // pipeline shit + + // TODO: THUMB!! + + NextInstr = Read32(addr); + R[15] = addr+4; +} + +s32 ARM::Execute(s32 cycles) +{ + while (cycles > 0) + { + // TODO THUM SHIT ASGAFDGSUHAJISGFYAUISAGY + + // prefetch + CurInstr = NextInstr; + NextInstr = Read32(R[15]); + R[15] += 4; + + // actually execute + // er... + } + + return cycles; +} @@ -0,0 +1,40 @@ +// ARM shit + +#ifndef ARM_H +#define ARM_H + +#include "types.h" +#include "NDS.h" + +class ARM +{ +public: + ARM(u32 num); + ~ARM(); // destroy shit + + void JumpTo(u32 addr); + s32 Execute(s32 cycles); + + u32 Read32(u32 addr) + { + if (Num) return NDS::ARM7Read32(addr); + else return NDS::ARM9Read32(addr); + } + + + u32 Num; + + u32 R[16]; // heh + u32 CPSR; + u32 R_FIQ[8]; // holding SPSR too + u32 R_SVC[3]; + u32 R_ABT[3]; + u32 R_IRQ[3]; + u32 R_UND[3]; + u32 CurInstr; + u32 NextInstr; + + u32 ExceptionBase; +}; + +#endif // ARM_H @@ -1,15 +1,23 @@ #include <stdio.h> #include "NDS.h" +#include "ARM.h" namespace NDS { -// +ARM* ARM9; +ARM* ARM7; + +u8 ARM9BIOS[0x1000]; +u8 ARM7BIOS[0x4000]; void Init() { + ARM9 = new ARM(0); + ARM7 = new ARM(1); + Reset(); } @@ -22,12 +30,50 @@ void Reset() printf("ARM9 BIOS not found\n"); else { - // load BIOS here + fseek(f, 0, SEEK_SET); + fread(ARM9BIOS, 0x1000, 1, f); + printf("ARM9 BIOS loaded: %08X\n", ARM9Read32(0xFFFF0000)); fclose(f); } + + f = fopen("bios7.bin", "rb"); + if (!f) + printf("ARM7 BIOS not found\n"); + else + { + fseek(f, 0, SEEK_SET); + fread(ARM7BIOS, 0x4000, 1, f); + + printf("ARM7 BIOS loaded: %08X\n", ARM7Read32(0x00000000)); + fclose(f); + } +} + + +u32 ARM9Read32(u32 addr) +{ + // implement ARM9y shit here, like memory protection + + if ((addr & 0xFFFFF000) == 0xFFFF0000) + { + return *(u32*)&ARM9BIOS[addr & 0xFFF]; + } + + printf("unknown arm9 read32 %08X\n", addr); + return 0; } +u32 ARM7Read32(u32 addr) +{ + if (addr < 0x00004000) + { + return *(u32*)&ARM7BIOS[addr]; + } + + printf("unknown arm7 read32 %08X\n", addr); + return 0; +} template<typename T> T Read(u32 addr) { @@ -10,6 +10,9 @@ namespace NDS void Init(); void Reset(); +u32 ARM9Read32(u32 addr); +u32 ARM7Read32(u32 addr); + template<typename T> T Read(u32 addr); template<typename T> void Write(u32 addr, T val); @@ -5,6 +5,7 @@ int main() { printf("melonDS version uh... 0.1??\n"); + printf("it's a DS emulator!!!\n"); NDS::Init(); diff --git a/melonDS.cbp b/melonDS.cbp index d8465a9..76310dc 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -32,7 +32,10 @@ <Add option="-Wall" /> <Add option="-fexceptions" /> </Compiler> + <Unit filename="NDS.cpp" /> + <Unit filename="NDS.h" /> <Unit filename="main.cpp" /> + <Unit filename="types.h" /> <Extensions> <code_completion /> <envvars /> diff --git a/melonDS.depend b/melonDS.depend new file mode 100644 index 0000000..c60dba6 --- /dev/null +++ b/melonDS.depend @@ -0,0 +1,20 @@ +# depslib dependency file v1.0 +1478130209 source:c:\documents\sources\melonds\main.cpp + <stdio.h> + "NDS.h" + +1478129148 c:\documents\sources\melonds\nds.h + "types.h" + +1463409689 c:\documents\sources\melonds\types.h + +1463410049 source:c:\documents\sources\melonds\nds.cpp + <stdio.h> + "NDS.h" + +1478128612 source:c:\documents\sources\melonds\arm.cpp + "ARM.h" + +1478130006 c:\documents\sources\melonds\arm.h + "types.h" + diff --git a/melonDS.layout b/melonDS.layout index 593c06e..1b5b6bf 100644 --- a/melonDS.layout +++ b/melonDS.layout @@ -2,4 +2,19 @@ <CodeBlocks_layout_file> <FileVersion major="1" minor="0" /> <ActiveTarget name="Debug" /> + <File name="NDS.cpp" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="253" topLine="14" /> + </Cursor> + </File> + <File name="NDS.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> + <File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> </CodeBlocks_layout_file> |