Integrate all the progress into master #6

Merged
jaby merged 595 commits from ToolBox into main 2025-01-01 13:17:44 +00:00
12 changed files with 83 additions and 67 deletions
Showing only changes of commit 30759b85c7 - Show all commits

View File

@ -4,7 +4,7 @@
#include <PSX/GPU/gpu_primitives.hpp>
extern "C" void memset() {
#pragma GCC warning "Declared to make code compile because of current GLOBAL_sub bug"
#pragma GCC warning "Declared to make code compile because of current GLOBAL_sub bug (Resolve this by not having any constructors)"
}
namespace FontWriter {

View File

@ -1,6 +1,7 @@
#include <PSX/Timer/high_res_timer.hpp>
#include <stdio.h>
#pragma GCC warning "Enable this code to verify that high percision counter is still functional"
extern "C" void busy_loop(int count);
namespace Overlay {
void mesaure_busy_loop() {

View File

@ -9,8 +9,9 @@ namespace JabyEngine {
CopyTo,
};
struct __no_align CDFile {
union __no_align Payload {
#pragma pack(push, 1)
struct CDFile {
union Payload {
uint32_t raw;
SimpleTIM simple_tim;
CopyTo copy_to;
@ -23,6 +24,7 @@ namespace JabyEngine {
static_assert(sizeof(Payload) == sizeof(uint32_t));
};
#pragma pack(pop)
struct CDFileBuilder {
static constexpr CDFile simple_tim(uint8_t rel_lba_idx, SimpleTIM simple_tim) {

View File

@ -5,10 +5,11 @@
#include "../jabyengine_defines.h"
namespace JabyEngine {
struct __no_align Nothing {
#pragma pack(push, 1)
struct Nothing {
};
struct __no_align SimpleTIM {
struct SimpleTIM {
static constexpr auto TextureX = BitRange::from_to(0, 8);
static constexpr auto TextureY = BitRange::from_to(9, 16);
static constexpr auto ClutX = BitRange::from_to(17, 22);
@ -46,9 +47,10 @@ namespace JabyEngine {
}
};
struct __no_align CopyTo {
struct CopyTo {
uint32_t* dst;
};
#pragma pack(pop)
typedef CopyTo Overlay;
}

View File

@ -12,7 +12,7 @@ namespace JabyEngine {
namespace internal {
struct RectCode : public CodeBase<RectCode> {
enum struct Size : uint8_t {
enum struct SizeType : uint8_t {
Variable = 0,
Pixel1x1 = 1,
Sprite8x8 = 2,
@ -37,9 +37,9 @@ namespace JabyEngine {
}
};
template<typename RectCode::Size Size>
template<typename RectCode::SizeType Size>
struct RECT_BASE_F : public RectCodeInterface<RECT_BASE_F<Size>> {
typedef RECT_BASE_F<Size>::Code Code;
typedef RectCodeInterface<RECT_BASE_F<Size>>::Code Code;
static constexpr auto IdentityCode = Code::create().set(Code::Size.with(static_cast<uint8_t>(Size))).set(Code::Untextured).set(Code::NonTransparent);
Color24 color;
@ -51,9 +51,9 @@ namespace JabyEngine {
}
};
template<typename RectCode::Size Size>
template<typename RectCode::SizeType Size>
struct RECT_BASE_T : public RectCodeInterface<RECT_BASE_T<Size>> {
typedef RECT_BASE_T<Size>::Code Code;
typedef RectCodeInterface<RECT_BASE_T<Size>>::Code Code;
static constexpr auto IdentityCode = Code(RECT_BASE_F<Size>::IdentityCode).set(Code::Textured);
Color24 color;
@ -67,21 +67,21 @@ namespace JabyEngine {
}
};
template<typename RectCode::Size Size>
template<typename RectCode::SizeType Size>
struct RECT_F : public RECT_BASE_F<Size>, public internal::RenderPrimitive<RECT_F<Size>>, public internal::LinkedElementCreator<RECT_F<Size>> {
using RECT_BASE_F<Size>::RECT_BASE_F;
};
template<typename RectCode::Size Size>
template<typename RectCode::SizeType Size>
struct RECT_T : public RECT_BASE_T<Size>, public internal::RenderPrimitive<RECT_T<Size>>, public internal::LinkedElementCreator<RECT_T<Size>> {
using RECT_BASE_T<Size>::RECT_BASE_T;
};
}
typedef internal::RECT_F<internal::RectCode::Size::Pixel1x1> TILE_1;
typedef internal::RECT_F<internal::RectCode::Size::Sprite8x8> TILE_8;
typedef internal::RECT_F<internal::RectCode::Size::Sprite16x16> TILE_16;
struct TILE : public internal::RECT_BASE_F<internal::RectCode::Size::Variable>, public internal::RenderPrimitive<TILE>, public internal::LinkedElementCreator<TILE> {
typedef internal::RECT_F<internal::RectCode::SizeType::Pixel1x1> TILE_1;
typedef internal::RECT_F<internal::RectCode::SizeType::Sprite8x8> TILE_8;
typedef internal::RECT_F<internal::RectCode::SizeType::Sprite16x16> TILE_16;
struct TILE : public internal::RECT_BASE_F<internal::RectCode::SizeType::Variable>, public internal::RenderPrimitive<TILE>, public internal::LinkedElementCreator<TILE> {
SizeI16 size;
constexpr TILE() = default;
@ -89,10 +89,10 @@ namespace JabyEngine {
}
};
typedef internal::RECT_T<internal::RectCode::Size::Pixel1x1> SPRT_1;
typedef internal::RECT_T<internal::RectCode::Size::Sprite8x8> SPRT_8;
typedef internal::RECT_T<internal::RectCode::Size::Sprite16x16> SPRT_16;
struct SPRT : public internal::RECT_BASE_T<internal::RectCode::Size::Variable>, public internal::RenderPrimitive<SPRT>, public internal::LinkedElementCreator<SPRT> {
typedef internal::RECT_T<internal::RectCode::SizeType::Pixel1x1> SPRT_1;
typedef internal::RECT_T<internal::RectCode::SizeType::Sprite8x8> SPRT_8;
typedef internal::RECT_T<internal::RectCode::SizeType::Sprite16x16> SPRT_16;
struct SPRT : public internal::RECT_BASE_T<internal::RectCode::SizeType::Variable>, public internal::RenderPrimitive<SPRT>, public internal::LinkedElementCreator<SPRT> {
SizeI16 size;
constexpr SPRT() = default;

View File

@ -85,7 +85,8 @@ namespace JabyEngine {
}
);
struct __no_align Registers {
#pragma pack(push, 1)
struct Registers {
MADR_v adr;
BCR_v block_ctrl;
CHCHR_v channel_ctrl;
@ -98,6 +99,7 @@ namespace JabyEngine {
while(this->channel_ctrl.is_set(CHCHR_t::Busy));
}
};
#pragma pack(pop)
// Those types do not need to be volatile because there members are
typedef Registers MDECin_v;

View File

@ -113,7 +113,8 @@ namespace JabyEngine {
typedef name##_io_base<IOPort::IOValueType::Volatile> name##_v; \
typedef name##_io_base<IOPort::IOValueType::Normal> name##_t
struct __no_align ubus32_t {
#pragma pack(push, 1)
struct ubus32_t {
__declare_io_type(uint16_t, uint16_t,);
uint16_t_v low;
uint16_t_v high;
@ -140,5 +141,6 @@ namespace JabyEngine {
return *this;
}
};
#pragma pack(pop)
}
#endif //!__JABYENGINE_IOPORT_HPP__

View File

@ -71,7 +71,8 @@ namespace JabyEngine {
static constexpr auto SustainLevel = BitRange::from_to(0, 3);
);
struct __no_align Voice_v {
#pragma pack(push, 1)
struct Voice_v {
SweepVolume_v volumeLeft; //Offset: 0x0
SweepVolume_v volumeRight; //Offset: 0x2
SampleRate_v sampleRate; //Offset: 0x4;
@ -81,6 +82,7 @@ namespace JabyEngine {
SimpleVolume_v currentVolume; //Offset: 0xC
Adr_v repeatAdr; //Offset: 0xE
};
#pragma pack(pop)
__declare_io_type(ControlRegister, uint16_t,
enum RAMTransferMode {

View File

@ -29,7 +29,8 @@ namespace JabyEngine {
static constexpr auto Value = BitRange::from_to(0, 15);
);
struct __no_align Counter {
#pragma pack(push, 1)
struct Counter {
CounterValue_v value;
CounterMode_v mode;
CounterTarget_v target;
@ -50,12 +51,14 @@ namespace JabyEngine {
this->mode = mode;
}
};
#pragma pack(pop)
static constexpr uintptr_t counter_base_adr(size_t ID) {
return (0x1F801100 + (ID*0x10));
}
struct __no_align Counter0_v : public Counter {
#pragma pack(push, 1)
struct Counter0_v : public Counter {
struct SyncMode {
static constexpr auto Pause_During_Hblank = CounterMode_v::SyncMode.with(0u);
static constexpr auto Zero_At_Hblank = CounterMode_v::SyncMode.with(1u);
@ -71,7 +74,7 @@ namespace JabyEngine {
};
};
struct __no_align Counter1_v : public Counter {
struct Counter1_v : public Counter {
struct SyncMode {
static constexpr auto Pause_During_Vblank = CounterMode_v::SyncMode.with(0u);
static constexpr auto Zero_At_Vblank = CounterMode_v::SyncMode.with(1u);
@ -87,7 +90,7 @@ namespace JabyEngine {
};
};
struct __no_align Counter2_v : public Counter {
struct Counter2_v : public Counter {
struct SyncMode {
static constexpr auto Stop_Counter = CounterMode_v::SyncMode.with(0u);
static constexpr auto FreeRun = CounterMode_v::SyncMode.with(1u);
@ -102,6 +105,7 @@ namespace JabyEngine {
static constexpr auto System_Clock_Div_8_Too = CounterMode_v::ClockSource.with(3u);
};
};
#pragma pack(pop)
__declare_new_io_port(Counter0, counter_base_adr(0));
__declare_new_io_port(Counter1, counter_base_adr(1));

View File

@ -45,12 +45,14 @@ enum InterruptVerifierResult {
typedef InterruptVerifierResult (*InterruptVerifier)();
typedef uint32_t (*InterruptHandler)(uint32_t);
struct __no_align InterrupCallback {
#pragma pack(push, 1)
struct InterrupCallback {
struct InterrupCallback* next;
InterruptHandler handler_function;
InterruptVerifier verifier_function;
uint32_t notUsed;
};
#pragma pack(pop)
#ifdef __cplusplus
#define __syscall_function_cast(table, ...) reinterpret_cast<__VA_ARGS__>(table)

View File

@ -31,8 +31,8 @@ endif
#LDSCRIPT := $(addprefix $(PSCX_REDUX_DIR)/default.ld , -T$(LDSCRIPT))
#endif
CC = $(PREFIX)-gcc-10
CXX = $(PREFIX)-g++-10
CC = $(PREFIX)-gcc
CXX = $(PREFIX)-g++
LD = $(CXX)
AR = ar
@ -49,9 +49,8 @@ CXXFLAGS += -fno-exceptions -fno-rtti
CCFLAGS += -mno-gpopt -fomit-frame-pointer -ffunction-sections -fdata-sections
CCFLAGS += -fno-builtin -fno-strict-aliasing -Wno-attributes
CCFLAGS += -std=c++20
CCFLAGS += $(ARCHFLAGS)
CCFLAGS += $(CCFLAGS_$(BUILD_PROFILE))
CCFLAGS += $(ARCHFLAGS)
CCFLAGS += $(INCLUDES)
CCFLAGS += -DJABYENGINE_$(TV_FORMAT)

View File

@ -70,40 +70,6 @@ namespace JabyEngine {
static InterruptVerifierResult interrupt_verifier() {
if(Interrupt::is_irq(Interrupt::CDROM)) {
const uint8_t old_status = CD_IO::IndexStatus;
CD_IO::PortIndex1::change_to();
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
last_interrupt = cur_irq;
CD_IO::Interrupt::ack(CD_IO::PortIndex1::InterruptFlag);
cmd_interrupt_bit = bit::clear(cmd_interrupt_bit, cur_irq);
if(cur_irq == CD_IO::Interrupt::DataReady) {
// Obtain sector content here
auto* sector = sector_allocator.allocate_sector();
if(sector) {
//Now obtain sector
read_sector_to(*sector);
cur_lba++;
if(cur_lba == dst_lba) {
current_state = State::Done;
pause_cd();
}
}
else {
current_state = State::BufferFull;
pause_cd();
}
}
else if(cur_irq == CD_IO::Interrupt::DiskError) {
current_state = State::Error;
}
// No masking required because we can only write bit 0 - 2
CD_IO::IndexStatus = old_status;
return InterruptVerifierResult::ExecuteHandler;
}
@ -113,6 +79,40 @@ namespace JabyEngine {
}
static void interrupt_handler(uint32_t) {
const uint8_t old_status = CD_IO::IndexStatus;
CD_IO::PortIndex1::change_to();
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
last_interrupt = cur_irq;
CD_IO::Interrupt::ack(CD_IO::PortIndex1::InterruptFlag);
cmd_interrupt_bit = bit::clear(cmd_interrupt_bit, cur_irq);
if(cur_irq == CD_IO::Interrupt::DataReady) {
// Obtain sector content here
auto* sector = sector_allocator.allocate_sector();
if(sector) {
//Now obtain sector
read_sector_to(*sector);
cur_lba++;
if(cur_lba == dst_lba) {
current_state = State::Done;
pause_cd();
}
}
else {
current_state = State::BufferFull;
pause_cd();
}
}
else if(cur_irq == CD_IO::Interrupt::DiskError) {
current_state = State::Error;
}
// No masking required because we can only write bit 0 - 2
CD_IO::IndexStatus = old_status;
Interrupt::ack_irq(Interrupt::CDROM);
__syscall_ReturnFromException();
}