Cached interpreter plays Mario 64. Start looking into RSP as well
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <Instruction.hpp>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
namespace n64 {
|
||||
static constexpr u32 MAX_INSTR_PER_BLOCK = 128;
|
||||
|
||||
#define CACHE_GET_BLOCK(addr) (addr / (cachedState.MAX_LINES))
|
||||
#define CACHE_GET_LINE(addr) ((addr & ((cachedState.MAX_LINES) - 1)) >> 2)
|
||||
|
||||
struct CachedLine {
|
||||
std::array<Instruction, MAX_INSTR_PER_BLOCK> code = {};
|
||||
u32 len = 0;
|
||||
u32 cycles = 0;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
template <u32 lineAmount>
|
||||
struct CachedBlock {
|
||||
CachedBlock() { lines.resize(lineAmount); }
|
||||
std::vector<CachedLine *> lines = {};
|
||||
};
|
||||
|
||||
template <u32 blockBits, u64 addressSpace>
|
||||
struct CachedState {
|
||||
static constexpr u32 MAX_LINES = 1 << blockBits;
|
||||
std::vector<CachedBlock<MAX_LINES / 4> *> blocks = {};
|
||||
bool exception = false;
|
||||
|
||||
void Reset() {
|
||||
for (auto block : blocks) {
|
||||
if (block)
|
||||
for (auto line : block->lines)
|
||||
delete line;
|
||||
|
||||
delete block;
|
||||
}
|
||||
blocks = {};
|
||||
blocks.resize((addressSpace + 1) / MAX_LINES);
|
||||
}
|
||||
};
|
||||
} // namespace n64
|
||||
Reference in New Issue
Block a user