mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-10-23 23:55:42 +00:00
59 lines
1.2 KiB
C
59 lines
1.2 KiB
C
|
#pragma once
|
||
|
#include "common/bitfield.h"
|
||
|
#include "cpu_types.h"
|
||
|
#include <array>
|
||
|
#include <memory>
|
||
|
#include <unordered_map>
|
||
|
#include <vector>
|
||
|
|
||
|
class JitCodeBuffer;
|
||
|
|
||
|
class Bus;
|
||
|
|
||
|
namespace CPU {
|
||
|
class Core;
|
||
|
|
||
|
namespace Recompiler {
|
||
|
class ASMFunctions;
|
||
|
}
|
||
|
|
||
|
class CodeCache
|
||
|
{
|
||
|
public:
|
||
|
CodeCache();
|
||
|
~CodeCache();
|
||
|
|
||
|
void Initialize(Core* core, Bus* bus);
|
||
|
void Reset();
|
||
|
void Execute();
|
||
|
|
||
|
/// Flushes all blocks which are in the range of the specified code page.
|
||
|
void FlushBlocksWithPageIndex(u32 page_index);
|
||
|
|
||
|
private:
|
||
|
using BlockMap = std::unordered_map<u32, CodeBlock*>;
|
||
|
|
||
|
const CodeBlock* GetNextBlock();
|
||
|
bool CompileBlock(CodeBlock* block);
|
||
|
void FlushBlock(CodeBlock* block);
|
||
|
void InterpretCachedBlock(const CodeBlock& block);
|
||
|
void InterpretUncachedBlock();
|
||
|
|
||
|
Core* m_core;
|
||
|
Bus* m_bus;
|
||
|
|
||
|
const CodeBlock* m_current_block = nullptr;
|
||
|
bool m_current_block_flushed = false;
|
||
|
|
||
|
std::unique_ptr<JitCodeBuffer> m_code_buffer;
|
||
|
std::unique_ptr<Recompiler::ASMFunctions> m_asm_functions;
|
||
|
|
||
|
BlockMap m_blocks;
|
||
|
|
||
|
std::array<std::vector<CodeBlock*>, CPU_CODE_CACHE_PAGE_COUNT> m_ram_block_map;
|
||
|
};
|
||
|
|
||
|
extern bool USE_CODE_CACHE;
|
||
|
extern bool USE_RECOMPILER;
|
||
|
|
||
|
} // namespace CPU
|