Add busy loop code and make HighResTimer work on demand rather automatically or ifdefed
This commit is contained in:
@@ -10,8 +10,7 @@ CCFLAGS += -Iinclude -I../../include
|
||||
CCFLAGS += -save-temps=obj
|
||||
|
||||
include ../../lib/Wildcard.mk
|
||||
SRCS = $(call rwildcard, src, c cpp)
|
||||
SRCS += src/syscall_printf.asm
|
||||
SRCS = $(call rwildcard, src, c cpp s)
|
||||
|
||||
include ../../lib/Makefile
|
||||
LIB_DIR = ../../lib/$(CONFIG_NAME)
|
||||
|
@@ -21,15 +21,10 @@ namespace JabyEngine {
|
||||
CD::setup();
|
||||
Timer::setup();
|
||||
|
||||
const auto start = HighResTime::get_time_stamp();
|
||||
printf("Start...\n");
|
||||
GPU::setup();
|
||||
GPU::display_logo();
|
||||
const auto end = HighResTime::get_time_stamp();
|
||||
printf("GPU setup took %ims %ius\n", start.milliseconds_to(end), start.microseconds_to(end));
|
||||
|
||||
//Pause??
|
||||
|
||||
SPU::setup();
|
||||
}
|
||||
}
|
||||
|
@@ -1,46 +1,34 @@
|
||||
#include <PSX/jabyengine_config.hpp>
|
||||
#ifdef JABYENGINE_USE_HIGH_PERCISION_TIMER
|
||||
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
||||
#include <PSX/System/syscalls.h>
|
||||
#define private public
|
||||
#include <PSX/Timer/high_res_timer.hpp>
|
||||
#undef private
|
||||
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
||||
#include <PSX/System/syscalls.h>
|
||||
#define private public
|
||||
#include <PSX/Timer/high_res_timer.hpp>
|
||||
#undef private
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace JabyEngine {
|
||||
namespace Timer {
|
||||
extern InterrupCallback IRQCallback;
|
||||
}
|
||||
|
||||
namespace boot {
|
||||
namespace Timer {
|
||||
extern InterrupCallback IRQCallback;
|
||||
}
|
||||
using namespace JabyEngine::Timer;
|
||||
|
||||
void setup() {
|
||||
using namespace Timer_IO;
|
||||
|
||||
namespace boot {
|
||||
namespace Timer {
|
||||
using namespace JabyEngine::Timer;
|
||||
|
||||
void setup() {
|
||||
using namespace Timer_IO;
|
||||
static constexpr auto Mode = CounterMode_t::from(CounterMode_t::FreeRun, Counter2_v::SyncMode::FreeRun, CounterMode_t::ResetAfterTarget, CounterMode_t::IRQAtTarget, CounterMode_t::IRQEveryTime, CounterMode_t::IRQPulse, Counter2_v::Source::System_Clock_Div_8);
|
||||
|
||||
static constexpr auto Mode = CounterMode_t::from(CounterMode_t::FreeRun, Counter2_v::SyncMode::FreeRun, CounterMode_t::ResetAfterTarget, CounterMode_t::IRQAtTarget, CounterMode_t::IRQEveryTime, CounterMode_t::IRQPulse, Counter2_v::Source::System_Clock_Div_8);
|
||||
// We disable the IRQ here so it can be enabled by user demand later
|
||||
// Having the interrupt fire every 10ms will slow us down slightly so we only do it on demand
|
||||
Interrupt::disable_irq(Interrupt::Timer2);
|
||||
|
||||
Interrupt::disable_irq(Interrupt::Timer2);
|
||||
__syscall_EnterCriticalSection();
|
||||
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
|
||||
__syscall_ExitCriticalSection();
|
||||
|
||||
__syscall_EnterCriticalSection();
|
||||
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
|
||||
__syscall_ExitCriticalSection();
|
||||
|
||||
Counter2.set_target_value(HighResTime::TicksFor10ms);
|
||||
Counter2.set_mode(Mode);
|
||||
|
||||
Interrupt::enable_irq(Interrupt::Timer2);
|
||||
}
|
||||
Counter2.set_target_value(HighResTime::TicksFor10ms);
|
||||
Counter2.set_mode(Mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
namespace JabyEngine {
|
||||
namespace boot {
|
||||
namespace Timer {
|
||||
void setup() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //JABYENGINE_USE_HIGH_PERCISION_TIMER
|
||||
}
|
@@ -1,38 +1,34 @@
|
||||
#include <PSX/jabyengine_config.hpp>
|
||||
#ifdef JABYENGINE_USE_HIGH_PERCISION_TIMER
|
||||
#define private public
|
||||
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
||||
#include <PSX/System/IOPorts/timer_io.hpp>
|
||||
#include <PSX/System/syscalls.h>
|
||||
#include <PSX/Timer/high_res_timer.hpp>
|
||||
#undef private
|
||||
#define private public
|
||||
#include <PSX/System/IOPorts/timer_io.hpp>
|
||||
#include <PSX/System/syscalls.h>
|
||||
#include <PSX/Timer/high_res_timer.hpp>
|
||||
#undef private
|
||||
|
||||
namespace JabyEngine {
|
||||
volatile uint16_t HighResTime :: global_counter_10ms = 0;
|
||||
namespace JabyEngine {
|
||||
volatile uint16_t HighResTime :: global_counter_10ms = 0;
|
||||
|
||||
namespace Timer {
|
||||
static InterruptVerifierResult interrupt_verifier() {
|
||||
if(Interrupt::is_irq(Interrupt::Timer2)) {
|
||||
return InterruptVerifierResult::ExecuteHandler;
|
||||
}
|
||||
|
||||
else {
|
||||
return InterruptVerifierResult::SkipHandler;
|
||||
}
|
||||
namespace Timer {
|
||||
static InterruptVerifierResult interrupt_verifier() {
|
||||
if(Interrupt::is_irq(Interrupt::Timer2)) {
|
||||
return InterruptVerifierResult::ExecuteHandler;
|
||||
}
|
||||
|
||||
static void interrupt_handler(uint32_t) {
|
||||
HighResTime::global_counter_10ms = HighResTime::global_counter_10ms + 1;
|
||||
|
||||
Interrupt::ack_irq(Interrupt::Timer2);
|
||||
__syscall_ReturnFromException();
|
||||
|
||||
else {
|
||||
return InterruptVerifierResult::SkipHandler;
|
||||
}
|
||||
|
||||
InterrupCallback IRQCallback = {
|
||||
.next = nullptr,
|
||||
.handler_function = reinterpret_cast<InterruptHandler>(interrupt_handler),
|
||||
.verifier_function = interrupt_verifier
|
||||
};
|
||||
}
|
||||
|
||||
static void interrupt_handler(uint32_t) {
|
||||
HighResTime::global_counter_10ms = HighResTime::global_counter_10ms + 1;
|
||||
|
||||
Interrupt::ack_irq(Interrupt::Timer2);
|
||||
__syscall_ReturnFromException();
|
||||
}
|
||||
|
||||
InterrupCallback IRQCallback = {
|
||||
.next = nullptr,
|
||||
.handler_function = reinterpret_cast<InterruptHandler>(interrupt_handler),
|
||||
.verifier_function = interrupt_verifier
|
||||
};
|
||||
}
|
||||
#endif //JABYENGINE_USE_HIGH_PERCISION_TIMER
|
||||
}
|
26
src/Library/src/busyloop.s
Normal file
26
src/Library/src/busyloop.s
Normal file
@@ -0,0 +1,26 @@
|
||||
.set noreorder
|
||||
.section .text, "ax", @progbits
|
||||
.align 2
|
||||
.global busy_loop
|
||||
.type busy_loop, @function
|
||||
|
||||
busy_loop:
|
||||
sw $a0, 0($sp)
|
||||
lw $v0, 0($sp)
|
||||
lw $v1, 0($sp)
|
||||
nop
|
||||
addiu $v1, -1
|
||||
beqz $v0, early_exit
|
||||
sw $v1, 0($sp)
|
||||
|
||||
busy_loop_loop:
|
||||
lw $v0, 0($sp)
|
||||
lw $v1, 0($sp)
|
||||
nop
|
||||
addiu $v1, -1
|
||||
bnez $v0, busy_loop_loop
|
||||
sw $v1, 0($sp)
|
||||
|
||||
early_exit:
|
||||
jr $ra
|
||||
nop
|
@@ -1,6 +1,6 @@
|
||||
.set push
|
||||
.set noreorder
|
||||
#.section .ramtext, "ax", @progbits
|
||||
.section .text, "ax", @progbits
|
||||
.align 2
|
||||
.global __syscall_printf
|
||||
.type __syscall_printf, @function
|
||||
|
Reference in New Issue
Block a user