diff --git a/examples/PoolBox/application/src/FontWriter/font_writer.cpp b/examples/PoolBox/application/src/FontWriter/font_writer.cpp index e13fab6e..1e3fdfd6 100644 --- a/examples/PoolBox/application/src/FontWriter/font_writer.cpp +++ b/examples/PoolBox/application/src/FontWriter/font_writer.cpp @@ -4,7 +4,7 @@ #include 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 { diff --git a/examples/PoolBox/application/src/Overlay/TimerTests/timer_tests.cpp b/examples/PoolBox/application/src/Overlay/TimerTests/timer_tests.cpp index e62774eb..45de067f 100644 --- a/examples/PoolBox/application/src/Overlay/TimerTests/timer_tests.cpp +++ b/examples/PoolBox/application/src/Overlay/TimerTests/timer_tests.cpp @@ -1,6 +1,7 @@ #include #include +#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() { diff --git a/include/PSX/File/cd_file_types.hpp b/include/PSX/File/cd_file_types.hpp index 67634209..582d4145 100644 --- a/include/PSX/File/cd_file_types.hpp +++ b/include/PSX/File/cd_file_types.hpp @@ -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) { diff --git a/include/PSX/File/file_types.hpp b/include/PSX/File/file_types.hpp index c2df1d56..b06c5a95 100644 --- a/include/PSX/File/file_types.hpp +++ b/include/PSX/File/file_types.hpp @@ -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; } diff --git a/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp b/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp index 48547ca7..700ef19f 100644 --- a/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp @@ -12,7 +12,7 @@ namespace JabyEngine { namespace internal { struct RectCode : public CodeBase { - enum struct Size : uint8_t { + enum struct SizeType : uint8_t { Variable = 0, Pixel1x1 = 1, Sprite8x8 = 2, @@ -37,9 +37,9 @@ namespace JabyEngine { } }; - template + template struct RECT_BASE_F : public RectCodeInterface> { - typedef RECT_BASE_F::Code Code; + typedef RectCodeInterface>::Code Code; static constexpr auto IdentityCode = Code::create().set(Code::Size.with(static_cast(Size))).set(Code::Untextured).set(Code::NonTransparent); Color24 color; @@ -51,9 +51,9 @@ namespace JabyEngine { } }; - template + template struct RECT_BASE_T : public RectCodeInterface> { - typedef RECT_BASE_T::Code Code; + typedef RectCodeInterface>::Code Code; static constexpr auto IdentityCode = Code(RECT_BASE_F::IdentityCode).set(Code::Textured); Color24 color; @@ -67,21 +67,21 @@ namespace JabyEngine { } }; - template + template struct RECT_F : public RECT_BASE_F, public internal::RenderPrimitive>, public internal::LinkedElementCreator> { using RECT_BASE_F::RECT_BASE_F; }; - template + template struct RECT_T : public RECT_BASE_T, public internal::RenderPrimitive>, public internal::LinkedElementCreator> { using RECT_BASE_T::RECT_BASE_T; }; } - typedef internal::RECT_F TILE_1; - typedef internal::RECT_F TILE_8; - typedef internal::RECT_F TILE_16; - struct TILE : public internal::RECT_BASE_F, public internal::RenderPrimitive, public internal::LinkedElementCreator { + typedef internal::RECT_F TILE_1; + typedef internal::RECT_F TILE_8; + typedef internal::RECT_F TILE_16; + struct TILE : public internal::RECT_BASE_F, public internal::RenderPrimitive, public internal::LinkedElementCreator { SizeI16 size; constexpr TILE() = default; @@ -89,10 +89,10 @@ namespace JabyEngine { } }; - typedef internal::RECT_T SPRT_1; - typedef internal::RECT_T SPRT_8; - typedef internal::RECT_T SPRT_16; - struct SPRT : public internal::RECT_BASE_T, public internal::RenderPrimitive, public internal::LinkedElementCreator { + typedef internal::RECT_T SPRT_1; + typedef internal::RECT_T SPRT_8; + typedef internal::RECT_T SPRT_16; + struct SPRT : public internal::RECT_BASE_T, public internal::RenderPrimitive, public internal::LinkedElementCreator { SizeI16 size; constexpr SPRT() = default; diff --git a/include/PSX/System/IOPorts/dma_io.hpp b/include/PSX/System/IOPorts/dma_io.hpp index 9092e8a3..2e747ede 100644 --- a/include/PSX/System/IOPorts/dma_io.hpp +++ b/include/PSX/System/IOPorts/dma_io.hpp @@ -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; diff --git a/include/PSX/System/IOPorts/ioport.hpp b/include/PSX/System/IOPorts/ioport.hpp index 7120225f..56b397e9 100644 --- a/include/PSX/System/IOPorts/ioport.hpp +++ b/include/PSX/System/IOPorts/ioport.hpp @@ -113,7 +113,8 @@ namespace JabyEngine { typedef name##_io_base name##_v; \ typedef name##_io_base 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__ \ No newline at end of file diff --git a/include/PSX/System/IOPorts/spu_io.hpp b/include/PSX/System/IOPorts/spu_io.hpp index a5edfea0..c703f5b2 100644 --- a/include/PSX/System/IOPorts/spu_io.hpp +++ b/include/PSX/System/IOPorts/spu_io.hpp @@ -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 { diff --git a/include/PSX/System/IOPorts/timer_io.hpp b/include/PSX/System/IOPorts/timer_io.hpp index eadd5d44..fda85c18 100644 --- a/include/PSX/System/IOPorts/timer_io.hpp +++ b/include/PSX/System/IOPorts/timer_io.hpp @@ -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)); diff --git a/include/PSX/System/syscalls.h b/include/PSX/System/syscalls.h index ad327d65..38b3bac2 100644 --- a/include/PSX/System/syscalls.h +++ b/include/PSX/System/syscalls.h @@ -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) diff --git a/lib/Makefile b/lib/Makefile index 01616051..483d4078 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -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) diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index 9ef12677..d5ff40c5 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -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(); }