Extend Periphery code

This commit is contained in:
Jaby
2024-01-02 19:47:23 -06:00
parent f15061fe67
commit fc646f1b1b
4 changed files with 81 additions and 3 deletions

View File

@@ -0,0 +1,31 @@
#pragma once
#include <PSX/System/IOPorts/periphery_io.hpp>
#include <PSX/System/IOPorts/interrupt_io.hpp>
namespace JabyEngine {
namespace Periphery {
using namespace Periphery_IO;
static void busy_cycle(uint32_t cycles) {
while(cycles--) {
asm("");
}
}
static void connect_to(uint16_t port) {
JOY_CTRL.write(JOY_CTRL::create_for(port));
busy_cycle(500);
}
static void close_connection() {
JOY_CTRL.write(JOY_CTRL::close());
}
static void acknowledge() {
while(JOY_STAT.read().is_set(JOY_STAT::ACKIrqLow));
JOY_CTRL.write(JOY_CTRL.read().set(JOY_CTRL::ACK));
Interrupt::ack_irq(Interrupt::Periphery);
}
}
}

View File

@@ -1,4 +1,5 @@
#include <PSX/System/IOPorts/periphery_io.hpp>
#include "../../internal-include/periphery_internal.hpp"
#include <PSX/System/syscalls.hpp>
namespace JabyEngine {
namespace boot {
@@ -6,6 +7,11 @@ namespace JabyEngine {
void setup() {
Periphery_IO::JOY_MODE.write(Periphery_IO::JOY_MODE::create());
Periphery_IO::JOY_BAUD.write(Periphery_IO::JOY_BAUD::create());
SysCall::EnterCriticalSection();
Interrupt::enable_irq(Interrupt::Periphery);
Interrupt::ack_irq(Interrupt::Periphery);
SysCall::ExitCriticalSection();
}
}
}