well, adding shit. laying out the base for the interpreter. really dirty code.

This commit is contained in:
StapleButter 2016-11-24 18:31:49 +01:00
parent 3505ec993b
commit f74fb2dd27
11 changed files with 2143 additions and 17 deletions

28
ARM.cpp
View File

@ -1,19 +1,13 @@
#include "ARM.h" #include <stdio.h>
#include "NDS.h" #include "NDS.h"
#include "ARM.h"
#include "ARMInterpreter.h"
ARM::ARM(u32 num) ARM::ARM(u32 num)
{ {
// well uh // well uh
Num = num; Num = num;
for (int i = 0; i < 16; i++)
R[i] = 0;
ExceptionBase = num ? 0x00000000 : 0xFFFF0000;
// zorp
JumpTo(ExceptionBase);
} }
ARM::~ARM() ARM::~ARM()
@ -21,11 +15,23 @@ ARM::~ARM()
// dorp // dorp
} }
void ARM::Reset()
{
for (int i = 0; i < 16; i++)
R[i] = 0;
ExceptionBase = Num ? 0x00000000 : 0xFFFF0000;
// zorp
JumpTo(ExceptionBase);
}
void ARM::JumpTo(u32 addr) void ARM::JumpTo(u32 addr)
{ {
// pipeline shit // pipeline shit
// TODO: THUMB!! // TODO: THUMB!!
if (addr&1) printf("!!! THUMB JUMP\n");
NextInstr = Read32(addr); NextInstr = Read32(addr);
R[15] = addr+4; R[15] = addr+4;
@ -43,7 +49,9 @@ s32 ARM::Execute(s32 cycles)
R[15] += 4; R[15] += 4;
// actually execute // actually execute
// er... if ((CurInstr & 0xF0000000) != 0xE0000000) printf("well shit\n");
u32 icode = ((CurInstr >> 4) & 0xF) | ((CurInstr >> 16) & 0xFF0);
cycles -= ARMInterpreter::ARMInstrTable[icode](this);
} }
return cycles; return cycles;

6
ARM.h
View File

@ -6,12 +6,18 @@
#include "types.h" #include "types.h"
#include "NDS.h" #include "NDS.h"
// lame
#define C_S(x) x
#define C_N(x) x
class ARM class ARM
{ {
public: public:
ARM(u32 num); ARM(u32 num);
~ARM(); // destroy shit ~ARM(); // destroy shit
void Reset();
void JumpTo(u32 addr); void JumpTo(u32 addr);
s32 Execute(s32 cycles); s32 Execute(s32 cycles);

31
ARMInterpreter.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <stdio.h>
#include "NDS.h"
#include "ARMInterpreter.h"
#include "ARMInterpreter_Branch.h"
namespace ARMInterpreter
{
s32 A_UNK(ARM* cpu)
{
printf("undefined ARM instruction %08X @ %08X\n", cpu->CurInstr, cpu->R[15]-8);
NDS::Halt();
return 0x7FFFFFFF;
}
s32 T_UNK(ARM* cpu)
{
printf("undefined THUMB instruction %04X @ %08X\n", cpu->CurInstr, cpu->R[15]-4);
NDS::Halt();
return 0x7FFFFFFF;
}
#define INSTRFUNC_PROTO(x) s32 (*x)(ARM* cpu)
#include "ARM_InstrTable.h"
#undef INSTRFUNC_PROTO
}

16
ARMInterpreter.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef ARMINTERPRETER_H
#define ARMINTERPRETER_H
#include "types.h"
#include "ARM.h"
namespace ARMInterpreter
{
extern s32 (*ARMInstrTable[4096])(ARM* cpu);
extern s32 (*THUMBInstrTable[1024])(ARM* cpu);
}
#endif // ARMINTERPRETER_H

27
ARMInterpreter_Branch.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "ARM.h"
namespace ARMInterpreter
{
s32 A_B(ARM* cpu)
{
s32 offset = (s32)(cpu->CurInstr << 8) >> 6;
cpu->JumpTo(cpu->R[15] + offset);
return C_S(2) + C_N(1);
}
s32 A_BL(ARM* cpu)
{
s32 offset = (s32)(cpu->CurInstr << 8) >> 6;
cpu->R[14] = cpu->R[15] - 4;
cpu->JumpTo(cpu->R[15] + offset);
return C_S(2) + C_N(1);
}
}

13
ARMInterpreter_Branch.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef ARMINTERPRETER_BRANCH_H
#define ARMINTERPRETER_BRANCH_H
namespace ARMInterpreter
{
s32 A_B(ARM* cpu);
s32 A_BL(ARM* cpu);
}
#endif

1962
ARM_InstrTable.h Normal file

File diff suppressed because it is too large Load Diff

34
NDS.cpp
View File

@ -9,9 +9,13 @@ namespace NDS
ARM* ARM9; ARM* ARM9;
ARM* ARM7; ARM* ARM7;
s32 ARM9Cycles, ARM7Cycles;
u8 ARM9BIOS[0x1000]; u8 ARM9BIOS[0x1000];
u8 ARM7BIOS[0x4000]; u8 ARM7BIOS[0x4000];
bool Running;
void Init() void Init()
{ {
@ -48,6 +52,36 @@ void Reset()
printf("ARM7 BIOS loaded: %08X\n", ARM7Read32(0x00000000)); printf("ARM7 BIOS loaded: %08X\n", ARM7Read32(0x00000000));
fclose(f); fclose(f);
} }
ARM9->Reset();
ARM7->Reset();
ARM9Cycles = 0;
ARM7Cycles = 0;
Running = true; // hax
}
void RunFrame()
{
s32 framecycles = 560190<<1;
// very gross and temp. loop
while (Running && framecycles>0)
{
ARM9Cycles = ARM9->Execute(32 + ARM9Cycles);
ARM7Cycles = ARM7->Execute(16 + ARM7Cycles);
framecycles -= 32;
}
}
void Halt()
{
Running = false;
} }

4
NDS.h
View File

@ -10,6 +10,10 @@ namespace NDS
void Init(); void Init();
void Reset(); void Reset();
void RunFrame();
void Halt();
u32 ARM9Read32(u32 addr); u32 ARM9Read32(u32 addr);
u32 ARM7Read32(u32 addr); u32 ARM7Read32(u32 addr);

View File

@ -9,5 +9,10 @@ int main()
NDS::Init(); NDS::Init();
for (;;)
{
NDS::RunFrame();
}
return 0; return 0;
} }

View File

@ -1,20 +1,40 @@
# depslib dependency file v1.0 # depslib dependency file v1.0
1478130209 source:c:\documents\sources\melonds\main.cpp 1480007651 source:c:\documents\sources\melonds\main.cpp
<stdio.h> <stdio.h>
"NDS.h" "NDS.h"
1478129148 c:\documents\sources\melonds\nds.h 1480006838 c:\documents\sources\melonds\nds.h
"types.h" "types.h"
1463409689 c:\documents\sources\melonds\types.h 1463409689 c:\documents\sources\melonds\types.h
1463410049 source:c:\documents\sources\melonds\nds.cpp 1480007757 source:c:\documents\sources\melonds\nds.cpp
<stdio.h> <stdio.h>
"NDS.h" "NDS.h"
1478128612 source:c:\documents\sources\melonds\arm.cpp
"ARM.h" "ARM.h"
1478130006 c:\documents\sources\melonds\arm.h 1480007764 source:c:\documents\sources\melonds\arm.cpp
"types.h" <stdio.h>
"NDS.h"
"ARM.h"
"ARMInterpreter.h"
1480008165 c:\documents\sources\melonds\arm.h
"types.h"
"NDS.h"
1480008597 c:\documents\sources\melonds\arm_instrtable.h
1480005496 c:\documents\sources\melonds\arminterpreter.h
"types.h"
"ARM.h"
1480008388 source:c:\documents\sources\melonds\arminterpreter.cpp
<stdio.h>
"NDS.h"
"ARMInterpreter.h"
"ARMInterpreter_Branch.h"
"ARM_InstrTable.h"
1480008608 c:\documents\sources\melonds\arminterpreter_branch.h