Integrate all the progress into master #6

Merged
jaby merged 595 commits from ToolBox into main 2025-01-01 13:17:44 +00:00
7 changed files with 94 additions and 52 deletions
Showing only changes of commit 3ab9d8b1f8 - Show all commits

View File

@ -7,8 +7,6 @@
namespace JabyEngine {
namespace CD {
extern volatile uint8_t zero;
namespace internal {
enum struct State {
Ready = 0,
@ -21,9 +19,36 @@ namespace JabyEngine {
Error,
};
extern State current_state;
extern State current_state;
extern uint8_t irq_bit_pending;
extern uint8_t last_cmd;
struct NewCommand {
struct Command {
static void wait_completed() {
while(const_cast<volatile uint8_t&>(irq_bit_pending));
}
template<typename...ARGS>
static void send(CD_IO::Command::Desc cmd, ARGS...args) {
Command::wait_completed();
while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy));
irq_bit_pending = bit::set(irq_bit_pending, cmd.complete_irq);
last_cmd = cmd.id;
CD_IO::PortIndex0::change_to();
((CD_IO::PortIndex0::ParameterFifo.write(CD_IO::ParameterFifo{args})),...);
CD_IO::PortIndex0::CommandFifo.write(CD_IO::CommandFifo{cmd.id});
}
template<typename...ARGS>
static void send_wait_response(CD_IO::Command::Desc cmd, ARGS...args) {
Command::send(cmd, args...);
Command::wait_completed();
}
};
/*struct NewCommand {
struct Internal {
static void wait_completed(CD_IO::Interrupt::Type irq) {
static const auto get_next_irq = []() -> CD_IO::Interrupt::Type {
@ -69,7 +94,7 @@ namespace JabyEngine {
Internal::wait_completed(cmd.complete_irq);
Interrupt::enable_irq(Interrupt::CDROM);
}
};
};*/
namespace IRQ {
void process(uint32_t irq);
@ -93,8 +118,7 @@ namespace JabyEngine {
void enable_CDXA(bool double_speed);
static void pause() {
CD_IO::PortIndex0::change_to();
NewCommand::send(CD_IO::Command::Pause);
Command::send(CD_IO::Command::Pause);
}
}
}

View File

@ -1,14 +1,20 @@
#pragma once
#include "threads.hpp"
#include <stdio.hpp>
namespace JabyEngine {
namespace Callback {
namespace internal {
static void execute_callback(Thread::Handle thread_handle, uint32_t parm) {
static void execute_callback(Thread::Handle thread_handle, uint32_t parm, uint8_t irq_bit_pending, uint8_t irq, uint8_t last_cmd) {
if(CurrentThread::is_me(MainThread::Handle)) {
CurrentThread::replace_with(thread_handle);
CurrentThread::force_a0(parm);
}
else {
//printf("%i +> %i +> %i\n", irq_bit_pending, irq, last_cmd);
}
//printf("C\n");
SysCall::ReturnFromException();
}
@ -26,7 +32,7 @@ namespace JabyEngine {
void routine();
static void [[deprecated("Currently not in use")]] execute() {
execute_callback(VSync::thread_handle, 0);
execute_callback(VSync::thread_handle, 0, 0, 0, 0);
}
}
@ -37,8 +43,8 @@ namespace JabyEngine {
extern uint32_t stack[StackSize];
void routine(uint32_t irq);
static void execute(uint32_t irq) {
execute_callback(CD::thread_handle, irq);
static void execute(uint32_t irq, uint8_t irq_bit_pending, uint8_t irq2, uint8_t last_cmd) {
execute_callback(CD::thread_handle, irq, irq_bit_pending, irq2, last_cmd);
}
static uint32_t resume() {

View File

@ -9,7 +9,7 @@ namespace JabyEngine {
static CD::BCDTimeStamp last_track;
TrackList get_tracks() {
CD::NewCommand::send_wait_response(CD_IO::Command::GetTN);
CD::Command::send_wait_response(CD_IO::Command::GetTN);
const auto stat = CD_IO::PortIndex0::ResponseFifo.read();
const auto first = CD_IO::PortIndex0::ResponseFifo.read().raw;
@ -25,12 +25,12 @@ namespace JabyEngine {
void play(uint8_t track) {
CD::enable_CDDA();
CD::NewCommand::send_wait_response(CD_IO::Command::GetTD, track);
CD::Command::send_wait_response(CD_IO::Command::GetTD, track);
const auto stats = CD_IO::PortIndex0::ResponseFifo.read().raw;
playing_track.min = CD_IO::PortIndex0::ResponseFifo.read().raw;
playing_track.sec = CD_IO::PortIndex0::ResponseFifo.read().raw;
CD::NewCommand::send(CD_IO::Command::Play, track);
CD::Command::send(CD_IO::Command::Play, track);
}
void stop() {
@ -44,8 +44,8 @@ namespace JabyEngine {
void pop_play() {
CD::enable_CDDA();
CD::NewCommand::send(CD_IO::Command::SetLoc, last_track.min, last_track.sec, last_track.sector);
CD::NewCommand::send(CD_IO::Command::Play);
CD::Command::send(CD_IO::Command::SetLoc, last_track.min, last_track.sec, last_track.sector);
CD::Command::send(CD_IO::Command::Play);
}
}
}

View File

@ -24,7 +24,7 @@ namespace JabyEngine {
CD::IRQ::read_sector_to0(reinterpret_cast<uint32_t*>(&xa_file), sizeof(CD::RawXADataSector));
if(setting.channel == xa_file.sub_header.channel_number) {
CD::IRQ::resume_at0(setting.start_loc);
CD::NewCommand::send(CD_IO::Command::ReadS);
CD::Command::send(CD_IO::Command::ReadS);
}
else {
@ -49,8 +49,8 @@ namespace JabyEngine {
CD::enable_CDXA(double_speed); //< Activates PortIndex0
set_channel(channel);printf("!!0-%X %X %X\n", setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector);
CD::NewCommand::send(CD_IO::Command::SetLoc, setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector);
CD::NewCommand::send(CD_IO::Command::ReadS);
CD::Command::send(CD_IO::Command::SetLoc, setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector);
CD::Command::send(CD_IO::Command::ReadS);
}
void stop() {
@ -60,7 +60,7 @@ namespace JabyEngine {
void set_channel(uint8_t channel) {
static constexpr uint8_t File = 1;
CD::NewCommand::send(CD_IO::Command::Filter, File, channel);
CD::Command::send(CD_IO::Command::Filter, File, channel);
setting.channel = channel;
}
@ -76,8 +76,8 @@ namespace JabyEngine {
CD::enable_CDXA(setting.double_speed); //< Activates PortIndex0
set_channel(setting.channel);printf("!!1-%X %X %X\n", setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector);
CD::NewCommand::send_wait_response(CD_IO::Command::SetLoc, setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector);
CD::NewCommand::send(CD_IO::Command::ReadS);
CD::Command::send_wait_response(CD_IO::Command::SetLoc, setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector);
CD::Command::send(CD_IO::Command::ReadS);
}
}
}

View File

@ -13,7 +13,7 @@ namespace JabyEngine {
namespace boot {
namespace CD {
using JabyEngine::CD::internal::NewCommand;
using JabyEngine::CD::internal::Command;
void setup() {
static constexpr auto DebugX = 1;
@ -41,13 +41,13 @@ namespace JabyEngine {
CD_IO::PortIndex0::change_to();
__debug_boot_color_at(::JabyEngine::GPU::Color24::Green(), DebugX, DebugY, DebugScale);
NewCommand::send(CD_IO::Command::GetStat);
Command::send(CD_IO::Command::GetStat);
__debug_boot_color_at(::JabyEngine::GPU::Color24::Blue(), DebugX, DebugY, DebugScale);
NewCommand::send(CD_IO::Command::GetStat);
Command::send(CD_IO::Command::GetStat);
__debug_boot_color_at(::JabyEngine::GPU::Color24::Yellow(), DebugX, DebugY, DebugScale);
NewCommand::send(CD_IO::Command::Init);
Command::send(CD_IO::Command::Init);
NewCommand::send(CD_IO::Command::Demute);
Command::send(CD_IO::Command::Demute);
}
}
}

View File

@ -11,6 +11,8 @@ namespace JabyEngine {
}
namespace CD {
extern volatile uint32_t zero;
namespace internal {
struct File {
uint32_t cur_lba;
@ -39,7 +41,9 @@ namespace JabyEngine {
static SectorBufferAllocator sector_allocator;
static File cur_file;
State current_state = State::Ready;
State current_state = State::Ready;
uint8_t irq_bit_pending = CD_IO::Interrupt::None;
uint8_t last_cmd = 0;
auto irq_callback = SysCall::InterruptCallback::from(IRQ::verifier, IRQ::handler);
@ -47,8 +51,8 @@ namespace JabyEngine {
const auto loc = BCDTimeStamp::from(lba);
printf("!!2-%X %X %X\n", loc.min, loc.sec, loc.sector);
NewCommand::send(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector);
NewCommand::send(cmd);
Command::send(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector);
Command::send(cmd);
return loc;
}
@ -88,14 +92,16 @@ namespace JabyEngine {
void resume_at0(const BCDTimeStamp& cd_time) {
printf("!!3-%X %X %X\n", cd_time.min, cd_time.sec, cd_time.sector);
NewCommand::send(CD_IO::Command::SetLoc, cd_time.min, cd_time.sec, cd_time.sector);
Command::send(CD_IO::Command::SetLoc, cd_time.min, cd_time.sec, cd_time.sector);
}
//######################################################################################################################
static SysCall::InterruptVerifierResult verifier() {
if(Interrupt::is_irq(Interrupt::CDROM)) {
//printf("A\n");
Interrupt::ack_irq(Interrupt::CDROM);
//printf("B\n");
return SysCall::InterruptVerifierResult::ExecuteHandler;
}
@ -104,17 +110,11 @@ namespace JabyEngine {
}
}
static void handler(uint32_t) {
static void handler(uint32_t x) {
const auto old_status = CD_IO::IndexStatus.read();
CD_IO::PortIndex1::change_to();
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
const auto is_data_rdy = cur_irq == CD_IO::Interrupt::DataReady;
if(is_data_rdy) {
CD_IO::PortIndex0::change_to();
CD_IO::PortIndex0::Request.write(CD_IO::Request::want_data());
}
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
CD_IO::PortIndex1::change_to();
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
CD_IO::Interrupt::reset_parameter_fifo(CD_IO::PortIndex1::InterruptFlag);
@ -123,12 +123,24 @@ namespace JabyEngine {
zero = 2;
zero = 3;
irq_bit_pending = bit::clear(irq_bit_pending, cur_irq);
CD_IO::PortIndex0::change_to();
if(cur_irq == CD_IO::Interrupt::DataReady) {
CD_IO::PortIndex0::Request.write(CD_IO::Request::want_data());
}
if(cur_irq == CD_IO::Interrupt::Acknowledge) {
CD_IO::PortIndex0::ResponseFifo.read();
}
// No masking required because we can only write bit 0 - 2
CD_IO::IndexStatus.write(old_status);
Callback::internal::CD::execute(cur_irq);
Callback::internal::CD::execute(cur_irq, irq_bit_pending, cur_irq, last_cmd);
}
void process(uint32_t irq) {
printf("%i -> %i -> %i\n", irq_bit_pending, irq, last_cmd);
if(current_state != State::XAMode) {
switch(irq) {
case CD_IO::Interrupt::DataReady: {
@ -143,25 +155,25 @@ namespace JabyEngine {
if(cur_file.done_processing()) {
current_state = State::Done;
NewCommand::send(CD_IO::Command::Pause);
Command::send(CD_IO::Command::Pause);
}
}
else {
current_state = State::BufferFull;
NewCommand::send(CD_IO::Command::Pause);
Command::send(CD_IO::Command::Pause);
}
} break;
case CD_IO::Interrupt::DataEnd: {
// TODO: Fix this!! This is a freaking static time
resume_at0(BCDTimeStamp{.min = 0x0, .sec = 0x09, .sector = 0x0});
NewCommand::send(CD_IO::Command::Play);
Command::send(CD_IO::Command::Play);
} break;
case CD_IO::Interrupt::DiskError: {
current_state = State::Error;
} break;
} break;
}
}
@ -175,7 +187,7 @@ namespace JabyEngine {
cur_file.set_from(file_info);
sector_allocator = buffer_allocator;
NewCommand::send(CD_IO::Command::SetMode, DataSectorMode);
Command::send(CD_IO::Command::SetMode, DataSectorMode);
send_read_n0(cur_file.cur_lba);
}
@ -191,7 +203,7 @@ namespace JabyEngine {
}
BCDTimeStamp get_loc() {
NewCommand::send_wait_response(CD_IO::Command::GetLocP);
Command::send_wait_response(CD_IO::Command::GetLocP);
const auto track = CD_IO::PortIndex0::ResponseFifo.read().raw; // track number (AAh=Lead-out area) (FFh=unknown, toc, none?)
const auto index = CD_IO::PortIndex0::ResponseFifo.read().raw; // index number (Usually 01h)
@ -207,7 +219,7 @@ namespace JabyEngine {
}
BCDTimeStamp get_locL() {
NewCommand::send_wait_response(CD_IO::Command::GetLocL);
Command::send_wait_response(CD_IO::Command::GetLocL);
const auto min = CD_IO::PortIndex0::ResponseFifo.read().raw;
const auto sec = CD_IO::PortIndex0::ResponseFifo.read().raw;
@ -217,11 +229,11 @@ namespace JabyEngine {
}
void enable_CD() {
NewCommand::send(CD_IO::Command::SetMode, DataSectorMode);
Command::send(CD_IO::Command::SetMode, DataSectorMode);
}
void enable_CDDA() {
NewCommand::send(CD_IO::Command::SetMode, AudioSectorMode);
Command::send(CD_IO::Command::SetMode, AudioSectorMode);
}
void enable_CDXA(bool double_speed) {
@ -230,7 +242,7 @@ namespace JabyEngine {
const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit);
NewCommand::send(CD_IO::Command::SetMode, mode);
Command::send(CD_IO::Command::SetMode, mode);
current_state = State::XAMode;
}
}

View File

@ -88,7 +88,7 @@ namespace JabyEngine {
void query_controller() {
static constexpr auto TypeIDX = 1;
SysCall::EnterCriticalSection();
//SysCall::EnterCriticalSection();
Periphery::connect_to(cur_controller_port);
for(uint32_t id = 0; id < Periphery::DeviceCount; id++) {
auto &cur_controller = controller[cur_controller_port][id];
@ -130,7 +130,7 @@ namespace JabyEngine {
if(Configuration::Periphery::include_portB()) {
cur_controller_port ^= 0x1;
}
SysCall::ExitCriticalSection();
//SysCall::ExitCriticalSection();
}
}
}