diff --git a/src/hw/aica/aica.cc b/src/hw/aica/aica.cc index 347fabb7..e7e56ff5 100644 --- a/src/hw/aica/aica.cc +++ b/src/hw/aica/aica.cc @@ -14,7 +14,7 @@ bool AICA::Init() { return true; } -uint32_t AICA::Execute(uint32_t cycles) { +int AICA::Execute(int cycles) { // uint16_t MCIEB = *reinterpret_cast(&aica_regs_[MCIEB_OFFSET]); // uint16_t MCIPD = *reinterpret_cast(&aica_regs_[MCIPD_OFFSET]); diff --git a/src/hw/aica/aica.h b/src/hw/aica/aica.h index d4af5212..0a05972c 100644 --- a/src/hw/aica/aica.h +++ b/src/hw/aica/aica.h @@ -14,10 +14,10 @@ class AICA : public hw::Device { public: AICA(hw::Dreamcast *dc); - uint32_t GetClockFrequency() { return 22579200; } + int GetClockFrequency() { return 22579200; } bool Init(); - uint32_t Execute(uint32_t cycles); + int Execute(int cycles); static uint32_t ReadRegister(void *ctx, uint32_t addr); static void WriteRegister(void *ctx, uint32_t addr, uint32_t value); diff --git a/src/hw/device.h b/src/hw/device.h index 3e6a9aae..72f912ac 100644 --- a/src/hw/device.h +++ b/src/hw/device.h @@ -10,8 +10,8 @@ class Device { public: virtual ~Device(){}; - virtual uint32_t GetClockFrequency() = 0; - virtual uint32_t Execute(uint32_t cycles) = 0; + virtual int GetClockFrequency() = 0; + virtual int Execute(int cycles) = 0; }; } } diff --git a/src/hw/scheduler.cc b/src/hw/scheduler.cc index 84498b95..163d0f46 100644 --- a/src/hw/scheduler.cc +++ b/src/hw/scheduler.cc @@ -76,14 +76,14 @@ void Scheduler::Tick(const std::chrono::nanoseconds &delta) { for (auto &info : devices_) { auto delta = std::chrono::duration_cast( target_time - info.current_time); - uint32_t cycles_per_second = info.device->GetClockFrequency(); - uint32_t cycles_to_run = static_cast( - (delta.count() * static_cast(cycles_per_second)) / + int cycles_per_second = info.device->GetClockFrequency(); + int cycles_to_run = static_cast( + (delta.count() * static_cast(cycles_per_second)) / NS_PER_SEC); - uint32_t ran = info.device->Execute(cycles_to_run); + int ran = info.device->Execute(cycles_to_run); info.current_time += std::chrono::nanoseconds( - (ran * static_cast(NS_PER_SEC)) / cycles_per_second); + (ran * static_cast(NS_PER_SEC)) / cycles_per_second); } base_time_ = target_time; diff --git a/src/hw/sh4/sh4.cc b/src/hw/sh4/sh4.cc index 1e9d9568..b0c07b60 100644 --- a/src/hw/sh4/sh4.cc +++ b/src/hw/sh4/sh4.cc @@ -53,10 +53,10 @@ bool SH4::Init() { void SH4::SetPC(uint32_t pc) { ctx_.pc = pc; } -uint32_t SH4::Execute(uint32_t cycles) { +int SH4::Execute(int cycles) { PROFILER_RUNTIME("SH4::Execute"); - uint32_t remaining = cycles; + int remaining = cycles; // update timers for (int i = 0; i < 3; i++) { @@ -64,18 +64,11 @@ uint32_t SH4::Execute(uint32_t cycles) { RunTimer(i, cycles >> 2); } - while (ctx_.pc) { + while (ctx_.pc && remaining > 0) { RuntimeBlock *block = runtime_.GetBlock(ctx_.pc, &ctx_); - // be careful not to wrap around - uint32_t next_remaining = remaining - block->guest_cycles(); - if (next_remaining > remaining) { - break; - } - - // run the block ctx_.pc = block->call()(&memory_, &ctx_, block); - remaining = next_remaining; + remaining -= block->guest_cycles(); CheckPendingCacheReset(); CheckPendingInterrupts(); @@ -459,7 +452,7 @@ bool SH4::TimerEnabled(int n) { // return TSTR & (1 << n); } -void SH4::RunTimer(int n, uint32_t cycles) { +void SH4::RunTimer(int n, int cycles) { static const int tcr_shift[] = {2, 4, 6, 8, 10, 0, 0, 0}; if (!TimerEnabled(n)) { diff --git a/src/hw/sh4/sh4.h b/src/hw/sh4/sh4.h index abcae6c7..7f267dc2 100644 --- a/src/hw/sh4/sh4.h +++ b/src/hw/sh4/sh4.h @@ -118,11 +118,11 @@ class SH4 : public hw::Device { public: SH4(hw::Memory &memory, jit::Runtime &runtime); - uint32_t GetClockFrequency() { return 200000000; } + int GetClockFrequency() { return 200000000; } bool Init(); void SetPC(uint32_t pc); - uint32_t Execute(uint32_t cycles); + int Execute(int cycles); // DMAC void DDT(int channel, DDTRW rw, uint32_t addr); @@ -165,7 +165,7 @@ class SH4 : public hw::Device { // TMU bool TimerEnabled(int n); - void RunTimer(int n, uint32_t cycles); + void RunTimer(int n, int cycles); hw::Memory &memory_; jit::Runtime &runtime_; diff --git a/src/jit/backend/interpreter/interpreter_block.cc b/src/jit/backend/interpreter/interpreter_block.cc index 63b65572..6b571113 100644 --- a/src/jit/backend/interpreter/interpreter_block.cc +++ b/src/jit/backend/interpreter/interpreter_block.cc @@ -14,7 +14,8 @@ InterpreterBlock::InterpreterBlock(int guest_cycles, IntInstr *instrs, void InterpreterBlock::Dump() { LOG_INFO("Unimplemented"); } -uint32_t InterpreterBlock::Call(Memory *memory, void *guest_ctx, RuntimeBlock *block) { +uint32_t InterpreterBlock::Call(Memory *memory, void *guest_ctx, + RuntimeBlock *block) { InterpreterBlock *self = reinterpret_cast(block); IntValue *registers = reinterpret_cast( alloca(int_num_registers * sizeof(IntValue))); diff --git a/src/jit/backend/interpreter/interpreter_block.h b/src/jit/backend/interpreter/interpreter_block.h index b8c3e674..063b4cee 100644 --- a/src/jit/backend/interpreter/interpreter_block.h +++ b/src/jit/backend/interpreter/interpreter_block.h @@ -18,7 +18,8 @@ class InterpreterBlock : public RuntimeBlock { void Dump(); private: - static uint32_t Call(hw::Memory *memory, void *guest_ctx, RuntimeBlock *block); + static uint32_t Call(hw::Memory *memory, void *guest_ctx, + RuntimeBlock *block); IntInstr *instrs_; int num_instrs_; diff --git a/src/jit/runtime.cc b/src/jit/runtime.cc index 258c947c..8234a8f6 100644 --- a/src/jit/runtime.cc +++ b/src/jit/runtime.cc @@ -23,8 +23,7 @@ enum { MAX_BLOCKS = 0x1000000 >> BLOCK_ADDR_SHIFT, }; -#define BLOCK_OFFSET(addr) \ - ((addr & BLOCK_ADDR_MASK) >> BLOCK_ADDR_SHIFT) +#define BLOCK_OFFSET(addr) ((addr & BLOCK_ADDR_MASK) >> BLOCK_ADDR_SHIFT) Runtime::Runtime(Memory &memory, frontend::Frontend &frontend, backend::Backend &backend) diff --git a/src/jit/runtime.h b/src/jit/runtime.h index a29ae425..237bc302 100644 --- a/src/jit/runtime.h +++ b/src/jit/runtime.h @@ -16,11 +16,12 @@ class Frontend; } class RuntimeBlock; -typedef uint32_t(*RuntimeCall)(hw::Memory *, void *, RuntimeBlock *); +typedef uint32_t (*RuntimeCall)(hw::Memory *, void *, RuntimeBlock *); class RuntimeBlock { public: - RuntimeBlock(int guest_cycles, RuntimeCall call) : guest_cycles_(guest_cycles), call_(call) {} + RuntimeBlock(int guest_cycles, RuntimeCall call) + : guest_cycles_(guest_cycles), call_(call) {} virtual ~RuntimeBlock() {} int guest_cycles() { return guest_cycles_; }