diff --git a/src/Platform_Dreamcast.c b/src/Platform_Dreamcast.c index f1af4ea..62bc23e 100644 --- a/src/Platform_Dreamcast.c +++ b/src/Platform_Dreamcast.c @@ -38,14 +38,26 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { } // Borrowed from kos/kernel/arch/dreamcast/kernel/timer.c so it compiles // with older toolchain versions -#define NS_PER_CYCLE 5 +#define _PMCR_CTRL_0 ( *((volatile uint16*)(0xff000084)) ) +#define _PMCTR_HIGH_0 ( *((volatile uint32*)(0xff100004)) ) +#define _PMCTR_LOW_0 ( *((volatile uint32*)(0xff100008)) ) +#define _PMCR_CLR 0x2000 +#define _PMCR_PMENABLE 0x8000 +#define _PMCR_RUN 0xc000 +#define _PMCR_PMM_MASK 0x003f +#define _PMCR_CLOCK_TYPE_SHIFT 8 +#define _NS_PER_CYCLE 5 +#define _PMCR_COUNT_CPU_CYCLES 0 +#define _PMCR_ELAPSED_TIME_MODE 0x23 cc_uint64 Stopwatch_Measure(void) { - uint64 cycles = perf_cntr_count(PRFC0); - return cycles * NS_PER_CYCLE; + uint64 cycles = (uint64)(_PMCTR_HIGH_0 & 0xFFFF) << 32 | _PMCTR_LOW_0; + return cycles * _NS_PER_CYCLE; } static void Stopwatch_Init(void) { - perf_cntr_start(PRFC0, PMCR_ELAPSED_TIME_MODE, PMCR_COUNT_CPU_CYCLES); + _PMCR_CTRL_0 &= ~(_PMCR_PMM_MASK | _PMCR_PMENABLE); + _PMCR_CTRL_0 |= _PMCR_CLR; + _PMCR_CTRL_0 = _PMCR_RUN | _PMCR_ELAPSED_TIME_MODE | (_PMCR_COUNT_CPU_CYCLES << _PMCR_CLOCK_TYPE_SHIFT); } // NOTE: If using newer toolchain versions, only need this: // cc_uint64 Stopwatch_Measure(void) { return timer_ns_gettime64(); } diff --git a/third_party/gldc/Makefile b/third_party/gldc/Makefile index bdde857..09f3181 100644 --- a/third_party/gldc/Makefile +++ b/third_party/gldc/Makefile @@ -3,7 +3,7 @@ SOURCE_DIRS := src src/yalloc C_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c)) OBJS := $(notdir $(C_FILES:%.c=%.o)) -C_FLAGS = -O3 -DNDEBUG -mfsrra -mfsca -fno-math-errno -ffp-contract=fast -ffast-math -O3 -mpretend-cmove -fexpensive-optimizations -fomit-frame-pointer -finline-functions -flto -fno-fat-lto-objects -ml -m4-single-only -ffunction-sections -fdata-sections -std=gnu99 +C_FLAGS = -O3 -DNDEBUG -mfsrra -mfsca -fno-math-errno -ffp-contract=fast -ffast-math -O3 -mpretend-cmove -fexpensive-optimizations -fomit-frame-pointer -finline-functions -ml -m4-single-only -ffunction-sections -fdata-sections -std=gnu99 C_DEFINES = -DDREAMCAST -DNDEBUG -D__DREAMCAST__ -D__arch_dreamcast -D_arch_dreamcast -D_arch_sub_pristine