From 3505ec993b0d700800f77c667078e2c552a38b34 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Thu, 3 Nov 2016 01:38:58 +0100 Subject: [PATCH] hey look, more crap no MrRean this doesn't run NSMB yet --- ARM.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ ARM.h | 40 ++++++++++++++++++++++++++++++++++++++++ NDS.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- NDS.h | 3 +++ main.cpp | 1 + melonDS.cbp | 3 +++ melonDS.depend | 20 ++++++++++++++++++++ melonDS.layout | 15 +++++++++++++++ 8 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 ARM.cpp create mode 100644 ARM.h create mode 100644 melonDS.depend diff --git a/ARM.cpp b/ARM.cpp new file mode 100644 index 00000000..47d5ec97 --- /dev/null +++ b/ARM.cpp @@ -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; +} diff --git a/ARM.h b/ARM.h new file mode 100644 index 00000000..024ecb95 --- /dev/null +++ b/ARM.h @@ -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 diff --git a/NDS.cpp b/NDS.cpp index f9922975..71de789c 100644 --- a/NDS.cpp +++ b/NDS.cpp @@ -1,15 +1,23 @@ #include #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,13 +30,51 @@ 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 T Read(u32 addr) { return (T)0; diff --git a/NDS.h b/NDS.h index 3e051b88..dff26935 100644 --- a/NDS.h +++ b/NDS.h @@ -10,6 +10,9 @@ namespace NDS void Init(); void Reset(); +u32 ARM9Read32(u32 addr); +u32 ARM7Read32(u32 addr); + template T Read(u32 addr); template void Write(u32 addr, T val); diff --git a/main.cpp b/main.cpp index fee895c3..7ac564b2 100644 --- a/main.cpp +++ b/main.cpp @@ -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 d8465a92..76310dcc 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -32,7 +32,10 @@ + + + diff --git a/melonDS.depend b/melonDS.depend new file mode 100644 index 00000000..c60dba64 --- /dev/null +++ b/melonDS.depend @@ -0,0 +1,20 @@ +# depslib dependency file v1.0 +1478130209 source:c:\documents\sources\melonds\main.cpp + + "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 + + "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 593c06ed..1b5b6bfc 100644 --- a/melonDS.layout +++ b/melonDS.layout @@ -2,4 +2,19 @@ + + + + + + + + + + + + + + +