mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-24 14:49:53 -06:00
botching Teakra some... not a big success
This commit is contained in:
@ -19,6 +19,7 @@ add_library(teakra
|
|||||||
timer.cpp
|
timer.cpp
|
||||||
timer.h
|
timer.h
|
||||||
icu.h
|
icu.h
|
||||||
|
InstrDecode.h
|
||||||
interpreter.h
|
interpreter.h
|
||||||
matcher.h
|
matcher.h
|
||||||
memory_interface.cpp
|
memory_interface.cpp
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
namespace Teakra {
|
namespace Teakra {
|
||||||
|
|
||||||
|
class Interpreter;
|
||||||
|
extern void (*InstrTable[65536])(Interpreter& cpu, u16 instr);
|
||||||
|
|
||||||
class UnimplementedException : public std::runtime_error {
|
class UnimplementedException : public std::runtime_error {
|
||||||
public:
|
public:
|
||||||
UnimplementedException() : std::runtime_error("unimplemented") {}
|
UnimplementedException() : std::runtime_error("unimplemented") {}
|
||||||
@ -60,6 +63,34 @@ public:
|
|||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u16 OpcodeFetch()
|
||||||
|
{
|
||||||
|
u16 opcode = mem.ProgramRead((regs.pc++) | (regs.prpage << 18));
|
||||||
|
return opcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleLoops()
|
||||||
|
{
|
||||||
|
if (regs.rep) {
|
||||||
|
if (regs.repc == 0) {
|
||||||
|
regs.rep = false;
|
||||||
|
} else {
|
||||||
|
--regs.repc;
|
||||||
|
--regs.pc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regs.lp && regs.bkrep_stack[regs.bcn - 1].end + 1 == regs.pc) {
|
||||||
|
if (regs.bkrep_stack[regs.bcn - 1].lc == 0) {
|
||||||
|
--regs.bcn;
|
||||||
|
regs.lp = regs.bcn != 0;
|
||||||
|
} else {
|
||||||
|
--regs.bkrep_stack[regs.bcn - 1].lc;
|
||||||
|
regs.pc = regs.bkrep_stack[regs.bcn - 1].start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Run(u64 cycles) {
|
void Run(u64 cycles) {
|
||||||
idle = false;
|
idle = false;
|
||||||
for (u64 i = 0; i < cycles; ++i) {
|
for (u64 i = 0; i < cycles; ++i) {
|
||||||
@ -84,8 +115,8 @@ public:
|
|||||||
regs.ipv = 1;
|
regs.ipv = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 opcode = mem.ProgramRead((regs.pc++) | (regs.prpage << 18));
|
u16 opcode = OpcodeFetch();
|
||||||
auto& decoder = decoders[opcode];
|
/*auto& decoder = decoders[opcode];
|
||||||
u16 expand_value = 0;
|
u16 expand_value = 0;
|
||||||
if (decoder.NeedExpansion()) {
|
if (decoder.NeedExpansion()) {
|
||||||
expand_value = mem.ProgramRead((regs.pc++) | (regs.prpage << 18));
|
expand_value = mem.ProgramRead((regs.pc++) | (regs.prpage << 18));
|
||||||
@ -110,7 +141,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder.call(*this, opcode, expand_value);
|
decoder.call(*this, opcode, expand_value);*/
|
||||||
|
InstrTable[opcode](*this, opcode);
|
||||||
|
|
||||||
// I am not sure if a single-instruction loop is interruptable and how it is handled,
|
// I am not sure if a single-instruction loop is interruptable and how it is handled,
|
||||||
// so just disable interrupt for it for now.
|
// so just disable interrupt for it for now.
|
||||||
@ -1185,14 +1217,16 @@ public:
|
|||||||
// retd is supposed to kick in after 2 cycles
|
// retd is supposed to kick in after 2 cycles
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
u16 opcode = mem.ProgramRead((regs.pc++) | (regs.prpage << 18));
|
/*u16 opcode = mem.ProgramRead((regs.pc++) | (regs.prpage << 18));
|
||||||
auto& decoder = decoders[opcode];
|
auto& decoder = decoders[opcode];
|
||||||
u16 expand_value = 0;
|
u16 expand_value = 0;
|
||||||
if (decoder.NeedExpansion()) {
|
if (decoder.NeedExpansion()) {
|
||||||
expand_value = mem.ProgramRead((regs.pc++) | (regs.prpage << 18));
|
expand_value = mem.ProgramRead((regs.pc++) | (regs.prpage << 18));
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder.call(*this, opcode, expand_value);
|
decoder.call(*this, opcode, expand_value);*/
|
||||||
|
u16 opcode = OpcodeFetch();
|
||||||
|
InstrTable[opcode](*this, opcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
PopPC();
|
PopPC();
|
||||||
@ -3642,7 +3676,9 @@ private:
|
|||||||
return map.at(in);
|
return map.at(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Matcher<Interpreter>> decoders = GetDecoderTable<Interpreter>();
|
//const std::vector<Matcher<Interpreter>> decoders = GetDecoderTable<Interpreter>();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Teakra
|
} // namespace Teakra
|
||||||
|
|
||||||
|
#include "InstrDecode.h"
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#include "mmio.h"
|
#include "mmio.h"
|
||||||
#include "shared_memory.h"
|
#include "shared_memory.h"
|
||||||
|
|
||||||
|
#include "../../DSi.h"
|
||||||
|
|
||||||
namespace Teakra {
|
namespace Teakra {
|
||||||
MemoryInterface::MemoryInterface(SharedMemory& shared_memory,
|
MemoryInterface::MemoryInterface(SharedMemory& shared_memory,
|
||||||
MemoryInterfaceUnit& memory_interface_unit)
|
MemoryInterfaceUnit& memory_interface_unit)
|
||||||
@ -11,11 +13,17 @@ void MemoryInterface::SetMMIO(MMIORegion& mmio) {
|
|||||||
this->mmio = &mmio;
|
this->mmio = &mmio;
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 MemoryInterface::ProgramRead(u32 address) const {
|
u16 MemoryInterface::ProgramRead(u32 address) const
|
||||||
return shared_memory.ReadWord(address);
|
{
|
||||||
|
//return shared_memory.ReadWord(address);
|
||||||
|
u8* ptr = DSi::NWRAMMap_B[2][(address >> 14) & 0x7];
|
||||||
|
return ptr ? *(u16*)&ptr[(address << 1) & 0x7FFF] : 0;
|
||||||
}
|
}
|
||||||
void MemoryInterface::ProgramWrite(u32 address, u16 value) {
|
void MemoryInterface::ProgramWrite(u32 address, u16 value)
|
||||||
shared_memory.WriteWord(address, value);
|
{
|
||||||
|
//shared_memory.WriteWord(address, value);
|
||||||
|
u8* ptr = DSi::NWRAMMap_B[2][(address >> 14) & 0x7];
|
||||||
|
if (ptr) *(u16*)&ptr[(address << 1) & 0x7FFF] = value;
|
||||||
}
|
}
|
||||||
u16 MemoryInterface::DataRead(u16 address, bool bypass_mmio) {
|
u16 MemoryInterface::DataRead(u16 address, bool bypass_mmio) {
|
||||||
if (memory_interface_unit.InMMIO(address) && !bypass_mmio) {
|
if (memory_interface_unit.InMMIO(address) && !bypass_mmio) {
|
||||||
|
@ -9,7 +9,7 @@ struct Operand {
|
|||||||
static_assert(bits > 0 && bits <= 16);
|
static_assert(bits > 0 && bits <= 16);
|
||||||
static constexpr unsigned Bits = bits;
|
static constexpr unsigned Bits = bits;
|
||||||
|
|
||||||
protected:
|
public:
|
||||||
u16 storage{};
|
u16 storage{};
|
||||||
|
|
||||||
template <typename OperandT, unsigned pos>
|
template <typename OperandT, unsigned pos>
|
||||||
|
Reference in New Issue
Block a user