#pragma once #include #include #include 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 code = {}; u32 len = 0; u32 cycles = 0; } __attribute__((__packed__)); template struct CachedBlock { CachedBlock() { lines.resize(lineAmount); } std::vector lines = {}; }; template struct CachedState { static constexpr u32 MAX_LINES = 1 << blockBits; std::vector *> blocks = {}; bool exception = false; void EvictCachedBlock(u64 addr) { blocks[addr / MAX_LINES] = {}; } 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