Files
kaizen/src/backend/core/registers/Registers.hpp
2025-08-01 21:05:11 +02:00

80 lines
1.6 KiB
C++

#pragma once
#include <array>
#include <xbyak.h>
#include <backend/core/registers/Cop1.hpp>
namespace n64 {
struct Registers {
Registers();
void Reset();
void SetPC64(s64);
void SetPC32(s32);
void SetJIT(JIT* jit) { this->jit = jit; }
[[nodiscard]] bool IsRegConstant(const u32 index) const {
if (index == 0)
return true;
return regIsConstant & (1 << index);
}
[[nodiscard]] bool IsRegConstant(const u32 first, const u32 second) const {
return IsRegConstant(first) && IsRegConstant(second);
}
bool GetLOConstant() {
return regIsConstant & (1ull << 32);
}
bool GetHIConstant() {
return regIsConstant & (1ull << 33);
}
void SetLOConstant() {
regIsConstant |= (1ull << 32);
}
void SetHIConstant() {
regIsConstant |= (1ull << 33);
}
void UnsetLOConstant() {
regIsConstant &= ~(1ull << 32);
}
void UnsetHIConstant() {
regIsConstant &= ~(1ull << 33);
}
JIT *jit = nullptr;
uint64_t regIsConstant = 0;
Cop0 cop0;
Cop1 cop1;
s64 oldPC{}, pc{}, nextPC{};
s64 hi{}, lo{};
bool prevDelaySlot{}, delaySlot{};
u32 steps = 0;
u32 extraCycles = 0;
void CpuStall(u32 cycles) { extraCycles += cycles; }
u32 PopStalledCycles() {
u32 ret = extraCycles;
extraCycles = 0;
return ret;
}
template <typename T>
__attribute__((always_inline)) T Read(size_t);
template <typename T>
__attribute__((always_inline)) void Read(size_t, Xbyak::Reg);
template <typename T>
__attribute__((always_inline)) void Write(size_t, T);
template <typename T>
__attribute__((always_inline)) void Write(size_t, Xbyak::Reg);
std::array<s64, 32> gpr{};
};
} // namespace n64