2016-11-24 10:31:49 -07:00
|
|
|
#include <stdio.h>
|
2016-11-02 18:38:58 -06:00
|
|
|
#include "NDS.h"
|
2016-11-24 10:31:49 -07:00
|
|
|
#include "ARM.h"
|
|
|
|
#include "ARMInterpreter.h"
|
2016-11-02 18:38:58 -06:00
|
|
|
|
|
|
|
|
|
|
|
ARM::ARM(u32 num)
|
|
|
|
{
|
|
|
|
// well uh
|
|
|
|
Num = num;
|
2016-11-24 10:31:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ARM::~ARM()
|
|
|
|
{
|
|
|
|
// dorp
|
|
|
|
}
|
2016-11-02 18:38:58 -06:00
|
|
|
|
2016-11-24 10:31:49 -07:00
|
|
|
void ARM::Reset()
|
|
|
|
{
|
2016-11-02 18:38:58 -06:00
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
R[i] = 0;
|
|
|
|
|
2016-11-24 10:31:49 -07:00
|
|
|
ExceptionBase = Num ? 0x00000000 : 0xFFFF0000;
|
2016-11-02 18:38:58 -06:00
|
|
|
|
|
|
|
// zorp
|
|
|
|
JumpTo(ExceptionBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM::JumpTo(u32 addr)
|
|
|
|
{
|
|
|
|
// pipeline shit
|
|
|
|
|
|
|
|
// TODO: THUMB!!
|
2016-11-24 10:31:49 -07:00
|
|
|
if (addr&1) printf("!!! THUMB JUMP\n");
|
2016-11-02 18:38:58 -06:00
|
|
|
|
|
|
|
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
|
2016-11-24 10:31:49 -07:00
|
|
|
if ((CurInstr & 0xF0000000) != 0xE0000000) printf("well shit\n");
|
|
|
|
u32 icode = ((CurInstr >> 4) & 0xF) | ((CurInstr >> 16) & 0xFF0);
|
|
|
|
cycles -= ARMInterpreter::ARMInstrTable[icode](this);
|
2016-11-02 18:38:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return cycles;
|
|
|
|
}
|