Current buggy state

This commit is contained in:
Jaby 2024-07-04 06:47:47 +02:00 committed by Jaby
parent ad14970640
commit 6913ca749d
7 changed files with 94 additions and 52 deletions

View File

@ -7,8 +7,6 @@
namespace JabyEngine { namespace JabyEngine {
namespace CD { namespace CD {
extern volatile uint8_t zero;
namespace internal { namespace internal {
enum struct State { enum struct State {
Ready = 0, Ready = 0,
@ -21,9 +19,36 @@ namespace JabyEngine {
Error, 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 { struct Internal {
static void wait_completed(CD_IO::Interrupt::Type irq) { static void wait_completed(CD_IO::Interrupt::Type irq) {
static const auto get_next_irq = []() -> CD_IO::Interrupt::Type { static const auto get_next_irq = []() -> CD_IO::Interrupt::Type {
@ -69,7 +94,7 @@ namespace JabyEngine {
Internal::wait_completed(cmd.complete_irq); Internal::wait_completed(cmd.complete_irq);
Interrupt::enable_irq(Interrupt::CDROM); Interrupt::enable_irq(Interrupt::CDROM);
} }
}; };*/
namespace IRQ { namespace IRQ {
void process(uint32_t irq); void process(uint32_t irq);
@ -93,8 +118,7 @@ namespace JabyEngine {
void enable_CDXA(bool double_speed); void enable_CDXA(bool double_speed);
static void pause() { static void pause() {
CD_IO::PortIndex0::change_to(); Command::send(CD_IO::Command::Pause);
NewCommand::send(CD_IO::Command::Pause);
} }
} }
} }

View File

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

View File

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

View File

@ -24,7 +24,7 @@ namespace JabyEngine {
CD::IRQ::read_sector_to0(reinterpret_cast<uint32_t*>(&xa_file), sizeof(CD::RawXADataSector)); CD::IRQ::read_sector_to0(reinterpret_cast<uint32_t*>(&xa_file), sizeof(CD::RawXADataSector));
if(setting.channel == xa_file.sub_header.channel_number) { if(setting.channel == xa_file.sub_header.channel_number) {
CD::IRQ::resume_at0(setting.start_loc); CD::IRQ::resume_at0(setting.start_loc);
CD::NewCommand::send(CD_IO::Command::ReadS); CD::Command::send(CD_IO::Command::ReadS);
} }
else { else {
@ -49,8 +49,8 @@ namespace JabyEngine {
CD::enable_CDXA(double_speed); //< Activates PortIndex0 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); 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::Command::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::ReadS);
} }
void stop() { void stop() {
@ -60,7 +60,7 @@ namespace JabyEngine {
void set_channel(uint8_t channel) { void set_channel(uint8_t channel) {
static constexpr uint8_t File = 1; 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; setting.channel = channel;
} }
@ -76,8 +76,8 @@ namespace JabyEngine {
CD::enable_CDXA(setting.double_speed); //< Activates PortIndex0 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); 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::Command::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(CD_IO::Command::ReadS);
} }
} }
} }

View File

@ -13,7 +13,7 @@ namespace JabyEngine {
namespace boot { namespace boot {
namespace CD { namespace CD {
using JabyEngine::CD::internal::NewCommand; using JabyEngine::CD::internal::Command;
void setup() { void setup() {
static constexpr auto DebugX = 1; static constexpr auto DebugX = 1;
@ -41,13 +41,13 @@ namespace JabyEngine {
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
__debug_boot_color_at(::JabyEngine::GPU::Color24::Green(), DebugX, DebugY, DebugScale); __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); __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); __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 { namespace CD {
extern volatile uint32_t zero;
namespace internal { namespace internal {
struct File { struct File {
uint32_t cur_lba; uint32_t cur_lba;
@ -39,7 +41,9 @@ namespace JabyEngine {
static SectorBufferAllocator sector_allocator; static SectorBufferAllocator sector_allocator;
static File cur_file; 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); auto irq_callback = SysCall::InterruptCallback::from(IRQ::verifier, IRQ::handler);
@ -47,8 +51,8 @@ namespace JabyEngine {
const auto loc = BCDTimeStamp::from(lba); const auto loc = BCDTimeStamp::from(lba);
printf("!!2-%X %X %X\n", loc.min, loc.sec, loc.sector); printf("!!2-%X %X %X\n", loc.min, loc.sec, loc.sector);
NewCommand::send(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector); Command::send(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector);
NewCommand::send(cmd); Command::send(cmd);
return loc; return loc;
} }
@ -88,14 +92,16 @@ namespace JabyEngine {
void resume_at0(const BCDTimeStamp& cd_time) { void resume_at0(const BCDTimeStamp& cd_time) {
printf("!!3-%X %X %X\n", cd_time.min, cd_time.sec, cd_time.sector); 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() { static SysCall::InterruptVerifierResult verifier() {
if(Interrupt::is_irq(Interrupt::CDROM)) { if(Interrupt::is_irq(Interrupt::CDROM)) {
//printf("A\n");
Interrupt::ack_irq(Interrupt::CDROM); Interrupt::ack_irq(Interrupt::CDROM);
//printf("B\n");
return SysCall::InterruptVerifierResult::ExecuteHandler; 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(); const auto old_status = CD_IO::IndexStatus.read();
CD_IO::PortIndex1::change_to(); CD_IO::PortIndex1::change_to();
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); 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());
}
CD_IO::PortIndex1::change_to(); CD_IO::PortIndex1::change_to();
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag); CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
CD_IO::Interrupt::reset_parameter_fifo(CD_IO::PortIndex1::InterruptFlag); CD_IO::Interrupt::reset_parameter_fifo(CD_IO::PortIndex1::InterruptFlag);
@ -123,12 +123,24 @@ namespace JabyEngine {
zero = 2; zero = 2;
zero = 3; 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 // No masking required because we can only write bit 0 - 2
CD_IO::IndexStatus.write(old_status); 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) { void process(uint32_t irq) {
printf("%i -> %i -> %i\n", irq_bit_pending, irq, last_cmd);
if(current_state != State::XAMode) { if(current_state != State::XAMode) {
switch(irq) { switch(irq) {
case CD_IO::Interrupt::DataReady: { case CD_IO::Interrupt::DataReady: {
@ -143,20 +155,20 @@ namespace JabyEngine {
if(cur_file.done_processing()) { if(cur_file.done_processing()) {
current_state = State::Done; current_state = State::Done;
NewCommand::send(CD_IO::Command::Pause); Command::send(CD_IO::Command::Pause);
} }
} }
else { else {
current_state = State::BufferFull; current_state = State::BufferFull;
NewCommand::send(CD_IO::Command::Pause); Command::send(CD_IO::Command::Pause);
} }
} break; } break;
case CD_IO::Interrupt::DataEnd: { case CD_IO::Interrupt::DataEnd: {
// TODO: Fix this!! This is a freaking static time // TODO: Fix this!! This is a freaking static time
resume_at0(BCDTimeStamp{.min = 0x0, .sec = 0x09, .sector = 0x0}); resume_at0(BCDTimeStamp{.min = 0x0, .sec = 0x09, .sector = 0x0});
NewCommand::send(CD_IO::Command::Play); Command::send(CD_IO::Command::Play);
} break; } break;
case CD_IO::Interrupt::DiskError: { case CD_IO::Interrupt::DiskError: {
@ -175,7 +187,7 @@ namespace JabyEngine {
cur_file.set_from(file_info); cur_file.set_from(file_info);
sector_allocator = buffer_allocator; 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); send_read_n0(cur_file.cur_lba);
} }
@ -191,7 +203,7 @@ namespace JabyEngine {
} }
BCDTimeStamp get_loc() { 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 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) const auto index = CD_IO::PortIndex0::ResponseFifo.read().raw; // index number (Usually 01h)
@ -207,7 +219,7 @@ namespace JabyEngine {
} }
BCDTimeStamp get_locL() { 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 min = CD_IO::PortIndex0::ResponseFifo.read().raw;
const auto sec = CD_IO::PortIndex0::ResponseFifo.read().raw; const auto sec = CD_IO::PortIndex0::ResponseFifo.read().raw;
@ -217,11 +229,11 @@ namespace JabyEngine {
} }
void enable_CD() { void enable_CD() {
NewCommand::send(CD_IO::Command::SetMode, DataSectorMode); Command::send(CD_IO::Command::SetMode, DataSectorMode);
} }
void enable_CDDA() { void enable_CDDA() {
NewCommand::send(CD_IO::Command::SetMode, AudioSectorMode); Command::send(CD_IO::Command::SetMode, AudioSectorMode);
} }
void enable_CDXA(bool double_speed) { void enable_CDXA(bool double_speed) {
@ -230,7 +242,7 @@ namespace JabyEngine {
const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit); 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; current_state = State::XAMode;
} }
} }

View File

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