From a039b60d5280431d05987ff74aa1162af7f2e865 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Sun, 24 Jan 2016 17:45:12 -0800 Subject: [PATCH] get tests back running --- CMakeLists.txt | 10 +++++----- src/hw/dreamcast.h | 16 ++-------------- src/hw/holly/holly.cc | 6 ++++++ src/hw/holly/pvr2.cc | 6 ++++++ src/hw/sh4/sh4.cc | 3 ++- test/test_sh4.cc | 16 +++++++++++++--- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cbf8c49..9544885d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -324,8 +324,8 @@ list(REMOVE_ITEM DREAVM_TEST_SOURCES src/main.cc) # assign source groups for visual studio projects source_group_by_dir(DREAVM_TEST_SOURCES) -#add_executable(dreavm_test ${DREAVM_TEST_SOURCES}) -#target_include_directories(dreavm_test PUBLIC deps/gtest-1.7.0/include src/ test/ ${DREAVM_INCLUDE_DIRS}) -#target_link_libraries(dreavm_test gtest gtest_main ${DREAVM_LIBS}) -#target_compile_definitions(dreavm_test PRIVATE ${DREAVM_DEFS}) -#target_compile_options(dreavm_test PRIVATE ${DREAVM_COMPILE_FLAGS}) +add_executable(dreavm_test ${DREAVM_TEST_SOURCES}) +target_include_directories(dreavm_test PUBLIC deps/gtest-1.7.0/include src/ test/ ${DREAVM_INCLUDE_DIRS}) +target_link_libraries(dreavm_test gtest gtest_main ${DREAVM_LIBS}) +target_compile_definitions(dreavm_test PRIVATE DREAVM_TEST=1 ${DREAVM_DEFS}) +target_compile_options(dreavm_test PRIVATE ${DREAVM_COMPILE_FLAGS}) diff --git a/src/hw/dreamcast.h b/src/hw/dreamcast.h index 94af1b0f..ac5df727 100644 --- a/src/hw/dreamcast.h +++ b/src/hw/dreamcast.h @@ -137,29 +137,17 @@ enum { }; struct Dreamcast { - Dreamcast() { -#define HOLLY_REG(addr, name, flags, default, type) \ - holly_regs[name##_OFFSET] = {flags, default}; -#include "hw/holly/holly_regs.inc" -#undef HOLLY_REG - -#define PVR_REG(addr, name, flags, default, type) \ - pvr_regs[name##_OFFSET] = {flags, default}; -#include "hw/holly/pvr2_regs.inc" -#undef PVR_REG - } - // uint8_t *aica_regs; Register holly_regs[HOLLY_REG_SIZE >> 2]; Register pvr_regs[PVR_REG_SIZE >> 2]; #define HOLLY_REG(offset, name, flags, default, type) \ - type &name{reinterpret_cast(holly_regs[name##_OFFSET].value)}; + type &name = reinterpret_cast(holly_regs[name##_OFFSET].value); #include "hw/holly/holly_regs.inc" #undef HOLLY_REG #define PVR_REG(offset, name, flags, default, type) \ - type &name{reinterpret_cast(pvr_regs[name##_OFFSET].value)}; + type &name = reinterpret_cast(pvr_regs[name##_OFFSET].value); #include "hw/holly/pvr2_regs.inc" #undef PVR_REG diff --git a/src/hw/holly/holly.cc b/src/hw/holly/holly.cc index de3d7f71..f6825699 100644 --- a/src/hw/holly/holly.cc +++ b/src/hw/holly/holly.cc @@ -21,6 +21,12 @@ bool Holly::Init() { maple_ = dc_->maple; sh4_ = dc_->sh4; + // initialize registers +#define HOLLY_REG(addr, name, flags, default, type) \ + holly_regs_[name##_OFFSET] = {flags, default}; +#include "hw/holly/holly_regs.inc" +#undef HOLLY_REG + return true; } diff --git a/src/hw/holly/pvr2.cc b/src/hw/holly/pvr2.cc index 44599dcd..1998e762 100644 --- a/src/hw/holly/pvr2.cc +++ b/src/hw/holly/pvr2.cc @@ -20,6 +20,12 @@ bool PVR2::Init() { palette_ram_ = dc_->palette_ram; video_ram_ = dc_->video_ram; + // initialize registers +#define PVR_REG(addr, name, flags, default, type) \ + pvr_regs_[name##_OFFSET] = {flags, default}; +#include "hw/holly/pvr2_regs.inc" +#undef PVR_REG + ReconfigureSPG(); return true; diff --git a/src/hw/sh4/sh4.cc b/src/hw/sh4/sh4.cc index 502ddf01..6ffd3316 100644 --- a/src/hw/sh4/sh4.cc +++ b/src/hw/sh4/sh4.cc @@ -80,7 +80,8 @@ void SH4::SetPC(uint32_t pc) { ctx_.pc = pc; } void SH4::Run(const std::chrono::nanoseconds &period) { PROFILER_RUNTIME("SH4::Execute"); - int64_t cycles = NANO_TO_CYCLES(period, SH4_CLOCK_FREQ); + // execute at least 1 cycle. the tests rely on this to step block by block + int64_t cycles = std::max(NANO_TO_CYCLES(period, SH4_CLOCK_FREQ), 1ll); // set current sh4 instance for CompilePC s_current_cpu = this; diff --git a/test/test_sh4.cc b/test/test_sh4.cc index 34b45e8c..0c99fc65 100644 --- a/test/test_sh4.cc +++ b/test/test_sh4.cc @@ -4,7 +4,9 @@ #include "gtest/gtest.h" #include "core/core.h" #include "hw/sh4/sh4.h" +#include "hw/dreamcast.h" #include "hw/memory.h" +#include "hw/scheduler.h" using namespace dvm; using namespace dvm::hw; @@ -97,7 +99,7 @@ int sh4_num_test_regs = xf12, xf13, xf14, xf15) \ SH4Context { \ nullptr, nullptr, nullptr, nullptr, \ - 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, 0, \ {r0, r1, r2, r3, r4, r5, r6, r7, \ r8, r9, r10, r11, r12, r13, r14, r15}, \ {0, 0, 0, 0, 0, 0, 0, 0}, 0, \ @@ -164,8 +166,16 @@ void RunSH4Test(const SH4Test &test) { memmap.Mount(code_handle, code_size, code_address); CHECK(memory.Map(memmap)); + // fake scheduler + Scheduler scheduler; + + // initialize fake dreamcast device + std::unique_ptr dc(new Dreamcast()); + dc->memory = &memory; + dc->scheduler = &scheduler; + // initialize cpu - SH4 sh4(memory); + SH4 sh4(dc.get()); CHECK(sh4.Init()); // setup in registers @@ -193,7 +203,7 @@ void RunSH4Test(const SH4Test &test) { // run until the function returns while (sh4.ctx_.pc) { - sh4.Run(1); + sh4.Run(std::chrono::nanoseconds(1)); } // validate out registers