From 274b3dc243c846a8f452ff8a9a9560f18acb102e Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 8 Jan 2023 16:39:26 +0100 Subject: [PATCH] Cleanup code --- include/PSX/System/IOPorts/timer_io.hpp | 15 +++++++++++---- include/PSX/System/syscalls.h | 2 +- src/Library/src/BootLoader/timer_boot.cpp | 6 ++---- src/Library/src/Timer/timer.cpp | 4 +++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/PSX/System/IOPorts/timer_io.hpp b/include/PSX/System/IOPorts/timer_io.hpp index 5c6695ad..010e4c04 100644 --- a/include/PSX/System/IOPorts/timer_io.hpp +++ b/include/PSX/System/IOPorts/timer_io.hpp @@ -31,7 +31,7 @@ namespace JabyEngine { static constexpr auto CounterTargetValue = BitRange::from_to(0, 15); }; - struct __no_align Timer { + struct __no_align TimerInfo { IOPort value; IOPort mode; IOPort target; @@ -39,6 +39,10 @@ namespace JabyEngine { uint32_t _unused[1]; }; + static constexpr uintptr_t counter_base_adr(size_t ID) { + return (0x1F801100 + (ID*0x10)); + } + namespace Counter0 { struct SyncMode { static constexpr auto Pause_During_Hblank = CounterMode::SyncMode.with(0); @@ -53,6 +57,8 @@ namespace JabyEngine { static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(2); static constexpr auto Dot_Clock_Too = CounterMode::ClockSource.with(3); }; + + __declare_io_port_global_struct(TimerInfo, Timer, counter_base_adr(0)); } namespace Counter1 { @@ -69,6 +75,8 @@ namespace JabyEngine { static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(2); static constexpr auto Hblank_Too = CounterMode::ClockSource.with(3); }; + + __declare_io_port_global_struct(TimerInfo, Timer, counter_base_adr(1)); } namespace Counter2 { @@ -85,10 +93,9 @@ namespace JabyEngine { static constexpr auto System_Clock_Div_8 = CounterMode::ClockSource.with(2); static constexpr auto System_Clock_Div_8_Too = CounterMode::ClockSource.with(3); }; - } - __declare_io_port_global_array(Timer, Counter, 0x1F801100, 3); - static_assert(sizeof(Timer) == 0x10); + __declare_io_port_global_struct(TimerInfo, Timer, counter_base_adr(2)); + } } } diff --git a/include/PSX/System/syscalls.h b/include/PSX/System/syscalls.h index f3d50605..05e13f32 100644 --- a/include/PSX/System/syscalls.h +++ b/include/PSX/System/syscalls.h @@ -94,7 +94,7 @@ static __always_inline void __syscall_ChangeClearPad(int32_t _reserved) { __syscall_function_cast(__syscall_Table_B, void(*)(int32_t))(_reserved); } -static __always_inline void __syscall_ReturnFromException() { +static __always_inline void [[noreturn]] __syscall_ReturnFromException() { register uint32_t FuncID asm("t1") = 0x17; __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); diff --git a/src/Library/src/BootLoader/timer_boot.cpp b/src/Library/src/BootLoader/timer_boot.cpp index 2f5757d3..a9a7e943 100644 --- a/src/Library/src/BootLoader/timer_boot.cpp +++ b/src/Library/src/BootLoader/timer_boot.cpp @@ -31,16 +31,14 @@ namespace JabyEngine { static constexpr auto Mode = CounterMode::with(CounterMode::FreeRun, Counter2::SyncMode::Freerun, CounterMode::ResetAfterTarget, CounterMode::IRQAtTarget, CounterMode::IRQEveryTime, CounterMode::IRQPulse, Counter2::Source::System_Clock_Div_8); static constexpr uint16_t Target = MS_Per_Tick(CPU_Frequncey_Hz_Div8)*10; - printf("Timer2 Target: %i\n", Target); - Interrupt::disable_irq(Interrupt::Timer2); __syscall_EnterCriticalSection(); __syscall_SysEnqIntRP(Timer2Irq, &IRQCallback); __syscall_ExitCriticalSection(); - Counter[2].target.write(CounterTarget::CounterTargetValue.with(Target)); - Counter[2].mode.write(Mode); + Counter2::Timer.target.write(CounterTarget::CounterTargetValue.with(Target)); + Counter2::Timer.mode.write(Mode); Interrupt::enable_irq(Interrupt::Timer2); } diff --git a/src/Library/src/Timer/timer.cpp b/src/Library/src/Timer/timer.cpp index 1e45d9ba..91670c37 100644 --- a/src/Library/src/Timer/timer.cpp +++ b/src/Library/src/Timer/timer.cpp @@ -20,10 +20,12 @@ namespace JabyEngine { } uint32_t interrupt_handler(uint32_t) { - GlobalTime::global_counter++; + GlobalTime::global_counter = GlobalTime::global_counter + 1; Interrupt::ack_irg(Interrupt::Timer2); __syscall_ReturnFromException(); + // v to make GCC happy + return 0; } InterrupCallback IRQCallback = {