Introduce the JabyEngine namespace to all files

This commit is contained in:
Jaby 2022-12-23 21:18:25 +01:00 committed by Jaby
parent 291641e599
commit 014baa2cbf
27 changed files with 1320 additions and 1282 deletions

View File

@ -2,7 +2,8 @@
#define __JABYENGINE_BITS_HPP__
#include "../jabyengine_defines.h"
namespace bit {
namespace JabyEngine {
namespace bit {
template<typename T>
static constexpr T set(T raw_value, size_t bit) {
return (raw_value | (1 << bit));
@ -49,6 +50,7 @@ namespace bit {
static constexpr S cast(T value) {
return *reinterpret_cast<S*>(&value);
}
}
}
#define __start_end_bit2_start_length(start_bit, end_bit) start_bit, (end_bit - start_bit + 1)

View File

@ -2,15 +2,16 @@
#define __JABYENGINE_COMPLEX_BITMAP_HPP__
#include "bits.hpp"
struct ClearBitValue {
namespace JabyEngine {
struct ClearBitValue {
size_t bit;
constexpr ClearBitValue(size_t bit) : bit(bit) {
}
};
};
template<typename T>
struct Bit {
template<typename T>
struct Bit {
typedef T ValueType;
size_t value;
@ -25,17 +26,17 @@ struct Bit {
constexpr ClearBitValue operator!() const {
return ClearBitValue(this->value);
}
};
};
template<typename T>
struct BitRangeValue {
template<typename T>
struct BitRangeValue {
T value;
size_t begin;
size_t length;
};
};
template<typename T>
struct BitRange {
template<typename T>
struct BitRange {
typedef T ValueType;
size_t begin;
@ -48,19 +49,19 @@ struct BitRange {
constexpr BitRangeValue<T> with(T value) const {
return {value, this->begin, this->length};
}
};
};
template<typename T>
static constexpr __always_inline BitRangeValue<T> operator<<(const BitRange<T>& range, T value) {
template<typename T>
static constexpr __always_inline BitRangeValue<T> operator<<(const BitRange<T>& range, T value) {
return BitRangeValue{value, range.begin, range.length};
}
}
template<typename T>
class ComplexBitMap {
public:
template<typename T>
class ComplexBitMap {
public:
T raw;
private:
private:
template<typename S>
constexpr __always_inline ComplexBitMap<T>& set_va(const S& value) {
return this->set(value);
@ -71,7 +72,7 @@ private:
return this->set_va(value).set_va(args...);
}
public:
public:
template<typename...ARGS>
static constexpr __always_inline ComplexBitMap<T> with(ARGS...args) {
return ComplexBitMap().set_va(args...);
@ -190,6 +191,7 @@ public:
this->clear_bit(value.bit);
return *this;
}
};
};
}
#endif //!__JABYENGINE_COMPLEX_BITMAP_HPP__

View File

@ -3,7 +3,8 @@
#include "../cd_file_types.hpp"
#include "file_processor.hpp"
namespace CDFileProcessor {
namespace JabyEngine {
namespace CDFileProcessor {
class State {
private:
FileProcessor::State file_processor_state;
@ -27,6 +28,7 @@ namespace CDFileProcessor {
//while(state.process());???
}
}
}
}
// This will be used as the file processor but will work on cd types

View File

@ -2,7 +2,8 @@
#define __JABYENGINE_FILE_PROCESSOR_HPP__
#include "../file_types.hpp"
namespace FileProcessor {
namespace JabyEngine {
namespace FileProcessor {
class State {
private:
struct Reserved {
@ -46,6 +47,6 @@ namespace FileProcessor {
};
State create(const uint32_t* data_adr, const SimpleTIM& file);
}
}
#endif // !__JABYENGINE_FILE_PROCESSOR_HPP__

View File

@ -3,12 +3,13 @@
#include "../Overlay/overlay.hpp"
#include "file_types.hpp"
enum struct CDFileType : uint8_t {
namespace JabyEngine {
enum struct CDFileType : uint8_t {
SimpleTIM = 0,
Custom
};
};
struct __no_align CDFile {
struct __no_align CDFile {
union __no_align Payload {
uint32_t empty;
SimpleTIM simple_tim;
@ -17,11 +18,12 @@ struct __no_align CDFile {
uint8_t rel_lba_idx;
CDFileType type;
Payload payload;
};
};
namespace CDFileBuilder {
namespace CDFileBuilder {
static constexpr CDFile simple_tim(uint8_t rel_lba_idx, SimpleTIM simple_tim) {
return CDFile{.rel_lba_idx = rel_lba_idx, .type = CDFileType::SimpleTIM, .payload = {.simple_tim = simple_tim}};
}
}
}
#endif //!__JABYENGINE_CD_FILE_TYPES_HPP__

View File

@ -3,7 +3,8 @@
#include "../Auxiliary/complex_bitmap.hpp"
#include "../jabyengine_defines.h"
struct __no_align SimpleTIM : private ComplexBitMap<uint32_t> {
namespace JabyEngine {
struct __no_align SimpleTIM : private ComplexBitMap<uint32_t> {
static constexpr auto TextureX = BitRange<uint32_t>(0, 8);
static constexpr auto TextureY = BitRange<uint32_t>(9, 16);
static constexpr auto ClutX = BitRange<uint32_t>(17, 22);
@ -31,7 +32,6 @@ struct __no_align SimpleTIM : private ComplexBitMap<uint32_t> {
constexpr uint16_t getClutY() const {
return ComplexBitMap<uint32_t>::get_value(SimpleTIM::ClutY);
}
};
};
}
#endif // !__JABYENGINE_FILE_TYPES_HPP__

View File

@ -10,7 +10,8 @@
#endif
#endif
namespace GPU {
namespace JabyEngine {
namespace GPU {
namespace Display {
#ifdef JABYENGINE_PAL
static constexpr size_t Width = 320;
@ -36,6 +37,6 @@ namespace GPU {
void set_offset(uint16_t x, uint16_t y);
}
}
}
}
#endif //!__JABYENGINE_GPU_HPP__

View File

@ -3,7 +3,8 @@
#include "../jabyengine_defines.h"
#include "../Auxiliary/complex_bitmap.hpp"
namespace GPU {
namespace JabyEngine {
namespace GPU {
struct Color24 {
uint8_t red = 0;
uint8_t green = 0;
@ -97,6 +98,6 @@ namespace GPU {
typedef Size<int16_t> SizeI16;
typedef Size<uint16_t> SizeU16;
}
}
#endif //!__JABYENGINE_GPU_TYPES_HPP__

View File

@ -2,14 +2,16 @@
#define __JABYENGINE_OVERLAY__HPP__
#include "../../stdint.h"
struct __attribute__((packed)) OverlayHeader {
namespace JabyEngine {
struct __attribute__((packed)) OverlayHeader {
void (*execute)();
uint16_t lba_size;
};
};
// Maybe encode attributes like "isLZ4" into size parameter
struct __attribute__((packed)) OverlayLBA {
// Maybe encode attributes like "isLZ4" into size parameter
struct __attribute__((packed)) OverlayLBA {
uint16_t lba;
uint16_t size;
};
};
}
#endif //!__JABYENGINE_OVERLAY__HPP__

View File

@ -3,12 +3,12 @@
// No include here because this header should be included in a namespace and we don't want multiple namespace definitions of OverlayHeader and OverlayLBA
extern const OverlayHeader overlay_header;
extern const OverlayLBA overlay_lba[];
extern const JabyEngine::OverlayHeader overlay_header;
extern const JabyEngine::OverlayLBA overlay_lba[];
#define __declare_overlay_header(function, enum_struct) \
[[gnu::used]] \
const OverlayHeader __section(".header") overlay_header = {.execute = &function, .lba_size = static_cast<uint16_t>(enum_struct::EndOfRequest)}; \
const JabyEngine::OverlayHeader __section(".header") overlay_header = {.execute = &function, .lba_size = static_cast<uint16_t>(enum_struct::EndOfRequest)}; \
[[gnu::used]] \
const OverlayLBA __section(".header.lbas") overlay_lba[static_cast<int>(enum_struct::EndOfRequest)] = {0}
const JabyEngine::OverlayLBA __section(".header.lbas") overlay_lba[static_cast<int>(enum_struct::EndOfRequest)] = {0}
#endif //!__JABYENGINE_OVERLAY_DECLARATION__HPP__

View File

@ -2,7 +2,8 @@
#define __JABYENGINE_DMA_IO_HPP__
#include "ioport.hpp"
namespace DMA {
namespace JabyEngine {
namespace DMA {
struct __no_align MADR : public ComplexBitMap<uint32_t> {
__io_port_inherit_complex_bit_map(MADR);
@ -139,6 +140,6 @@ namespace DMA {
__declare_io_port_global(DMAControlRegister, DPCR, 0x1F8010F0);
__declare_io_port_global(DMAInterruptRegister, DICR, 0x1F8010F4);
}
}
#endif //!__JABYENGINE_DMA_IO_HPP__

View File

@ -3,7 +3,8 @@
#include "ioport.hpp"
#include "../../GPU/gpu_types.hpp"
namespace GPU {
namespace JabyEngine {
namespace GPU {
enum struct SemiTransparency {
B_Half_add_F_Half = 0,
B_add_F = 1,
@ -167,6 +168,6 @@ namespace GPU {
__declare_io_port_global_const(uint32_t, GPUREAD, 0x1F801810);
__declare_io_port_global_const(GPUStatusRegister, GPUSTAT, 0x1F801814);
}
}
#endif //!__JABYENGINE_GPU_IO_HPP__

View File

@ -2,12 +2,13 @@
#define __JABYENGINE_IOPORT_HPP__
#include "../../Auxiliary/complex_bitmap.hpp"
template<typename T>
class __no_align IOPort {
private:
namespace JabyEngine {
template<typename T>
class __no_align IOPort {
private:
T value;
public:
public:
//For easy access
constexpr T read() const {
return const_cast<volatile IOPort<T>*>(this)->value;
@ -24,9 +25,9 @@ public:
constexpr const volatile T& ref() const {
return const_cast<volatile IOPort<T>*>(this)->value;
}
};
};
struct __no_align ubus32_t {
struct __no_align ubus32_t {
ComplexBitMap<uint16_t> low;
ComplexBitMap<uint16_t> high;
@ -53,19 +54,19 @@ struct __no_align ubus32_t {
this->low.raw = (value & 0xFFFF);
this->high.raw = (value >> 16);
}
};
static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
static constexpr uintptr_t IO_Base_Adr = 0x10000000;
};
static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
static constexpr uintptr_t IO_Base_Adr = 0x10000000;
#define __io_port_adr(adr) (IO_Base_Adr + (adr & ~IO_Base_Mask))
#define __declare_io_port_global_raw(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast<IOPort<type>*>(__io_port_adr(adr))
#define __io_port_adr(adr) (IO_Base_Adr + (adr & ~IO_Base_Mask))
#define __declare_io_port_global_raw(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast<IOPort<type>*>(__io_port_adr(adr))
#define __declare_io_port_global(type, name, adr) __declare_io_port_global_raw(, type, name, adr)
#define __declare_io_port_global_const(type, name, adr) __declare_io_port_global_raw(const, type, name, adr)
#define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>((IO_Base_Adr + (adr & ~IO_Base_Mask))))
#define __declare_io_port_global_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast<type*>(__io_port_adr(adr))
#define __declare_io_port_global(type, name, adr) __declare_io_port_global_raw(, type, name, adr)
#define __declare_io_port_global_const(type, name, adr) __declare_io_port_global_raw(const, type, name, adr)
#define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>((IO_Base_Adr + (adr & ~IO_Base_Mask))))
#define __declare_io_port_global_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast<type*>(__io_port_adr(adr))
#define __io_port_inherit_complex_bit_map(name) \
#define __io_port_inherit_complex_bit_map(name) \
constexpr __always_inline name() = default; \
constexpr __always_inline name(ComplexBitMap value) : ComplexBitMap(value) { \
} \
@ -77,5 +78,5 @@ static constexpr uintptr_t IO_Base_Adr = 0x10000000;
constexpr void __always_inline operator=(ComplexBitMap<T> value) volatile { \
this->raw = value.raw; \
}
}
#endif //!__JABYENGINE_IOPORT_HPP__

View File

@ -2,7 +2,8 @@
#define __JABYENGINE_SPU_IO_HPP__
#include "ioport.hpp"
namespace SPU {
namespace JabyEngine {
namespace SPU {
enum struct Mode {
Linear = 0,
Exponential = 1,
@ -164,6 +165,6 @@ namespace SPU {
__declare_io_port_global(EchoOn, EON, 0x1F801D98);
__declare_io_port_global_array(Voice, Voices, 0x1F801C00, VoiceCount);
}
}
#endif //!__JABYENGINE_SPU_IO_HPP__

View File

@ -2,6 +2,7 @@
#define __JABYENGINE_SCRATCHPAD_HPP__
#include "../jabyengine_defines.h"
static __always_inline auto& ScratchPad = reinterpret_cast<uint8_t(&)[1024]>(*reinterpret_cast<uint8_t*>(0x1F800000));
namespace JabyEngine {
static __always_inline auto& ScratchPad = reinterpret_cast<uint8_t(&)[1024]>(*reinterpret_cast<uint8_t*>(0x1F800000));
}
#endif //!__JABYENGINE_SCRATCHPAD_HPP__

View File

@ -1,5 +1,5 @@
#ifndef __JABYENGINE__H__
#define __JABYENGINE__H__
#ifndef __JABYENGINE__HPP__
#define __JABYENGINE__HPP__
#include "../stdint.h"
namespace JabyEngine {
@ -33,4 +33,4 @@ namespace JabyEngine {
typedef NextRoutine::MainRoutine MainRoutine;
}
#endif //!__JABYENGINE__H__
#endif //!__JABYENGINE__HPP__

View File

@ -1,23 +1,24 @@
#ifndef BOOT_LOADER_HPP
#define BOOT_LOADER_HPP
#include <PSX/jabyengine.h>
#include <PSX/jabyengine.hpp>
namespace GPU {
namespace JabyEngine {
namespace GPU {
void display_logo();
void setup();
}
}
namespace SPU {
namespace SPU {
void stop_voices();
void setup();
}
}
namespace Setup {
namespace Setup {
JabyEngine::NextRoutine start();
}
}
namespace BootFile {
namespace BootFile {
JabyEngine::NextRoutine setup();
}
}
#endif //!BOOT_LOADER_HPP

View File

@ -2,7 +2,8 @@
#define __JABYENGINE_CD_HPP__
#include <stdint.h>
namespace CD {
namespace JabyEngine {
namespace CD {
namespace CircularBuffer {
extern uint8_t* write_ptr;
extern uint8_t* read_ptr;
@ -13,6 +14,6 @@ namespace CD {
};
extern State state;
}
}
#endif //!__JABYENGINE_CD_HPP__

View File

@ -4,7 +4,8 @@
#include <PSX/System/IOPorts/dma_io.hpp>
#include <PSX/System/IOPorts/gpu_io.hpp>
namespace GPU {
namespace JabyEngine {
namespace GPU {
namespace Screen {
struct Mode {
enum struct TVEncoding {
@ -78,7 +79,7 @@ namespace GPU {
namespace DMA {
static void wait() {
while(::DMA::GPU.channel_ctrl.ref().is(::DMA::CHCHR::Busy));
while(::JabyEngine::DMA::GPU.channel_ctrl.ref().is(::JabyEngine::DMA::CHCHR::Busy));
}
static void end() {
@ -93,7 +94,7 @@ namespace GPU {
}
static void set_src(uintptr_t adr) {
::DMA::GPU.adr.ref().set_value(static_cast<uint32_t>(adr), ::DMA::MADR::MemoryAdr);
::JabyEngine::DMA::GPU.adr.ref().set_value(static_cast<uint32_t>(adr), ::JabyEngine::DMA::MADR::MemoryAdr);
}
static void set_dst(const PositionU16& position, const SizeU16& size) {
@ -105,10 +106,11 @@ namespace GPU {
}
static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) {
typedef ::DMA::BCR::SyncMode1 SyncMode1;
typedef ::JabyEngine::DMA::BCR::SyncMode1 SyncMode1;
::DMA::GPU.block_ctrl.write(SyncMode1::with(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount)));
::DMA::GPU.channel_ctrl.write(::DMA::CHCHR::StartGPUReceive());
::JabyEngine::DMA::GPU.block_ctrl.write(SyncMode1::with(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount)));
::JabyEngine::DMA::GPU.channel_ctrl.write(::JabyEngine::DMA::CHCHR::StartGPUReceive());
}
}
}
}

View File

@ -3,9 +3,11 @@
extern JabyEngine::NextRoutine main();
namespace BootFile {
namespace JabyEngine {
namespace BootFile {
JabyEngine::NextRoutine setup() {
printf("Running main!\n");
return JabyEngine::NextRoutine::from(main);
}
}
}

View File

@ -1,9 +1,11 @@
#include "../../../include/BootLoader/boot_loader.hpp"
#include <stdio.h>
namespace BootFile {
namespace JabyEngine {
namespace BootFile {
JabyEngine::NextRoutine setup() {
printf("Overlay boot not implemented!\n");
return JabyEngine::NextRoutine::null();
}
}
}

View File

@ -8,7 +8,8 @@
#include "splash_image_ntsc_boot.hpp"
#endif //JABYENGINE_PAL
namespace GPU {
namespace JabyEngine {
namespace GPU {
void display_logo() {
// Upload SplashScreen picture
auto state = FileProcessor::create(reinterpret_cast<const uint32_t*>(SplashScreen), SimpleTIM(32, 0, 0, 0));
@ -25,4 +26,5 @@ namespace GPU {
GPU::wait_ready_for_CMD();
quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height));
}
}
}

View File

@ -2,7 +2,10 @@
#include <stdio.h>
#include <limits.h>
namespace SPU {
namespace JabyEngine {
namespace SPU {
using namespace JabyEngine;
static void clear_main_volume() {
static constexpr auto StartVol = SweepVolume::with(SweepVolume::VolumeEnable, SweepVolume::Volume.with(I16_MAX >> 2));
@ -92,4 +95,5 @@ namespace SPU {
setup_data_transfer_control();
setup_control_register();
}
}
}

View File

@ -2,7 +2,8 @@
#include <PSX/System/IOPorts/dMa_io.hpp>
#include <stdio.h>
namespace Setup {
namespace JabyEngine {
namespace Setup {
static void enable_DMA() {
DMA::DPCR.write(DMA::DPCR.read() | DMA::DMAControlRegister::SPUEnable | DMA::DMAControlRegister::GPUEnable);
}
@ -19,4 +20,5 @@ namespace Setup {
SPU::setup();
return BootFile::setup();
}
}
}

View File

@ -3,7 +3,8 @@
#define private public
#include <PSX/File/Processor/file_processor.hpp>
namespace FileProcessor {
namespace JabyEngine {
namespace FileProcessor {
namespace Helper {
template<typename T>
static void simple_read(T& dst, State::Configuration& config) {
@ -21,6 +22,6 @@ namespace FileProcessor {
return process_routine(config, state);
}
}
}
}
#endif // !__JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__

View File

@ -3,7 +3,8 @@
#include <limits.h>
#include <stdio.h>
namespace FileProcessor {
namespace JabyEngine {
namespace FileProcessor {
using GPU::PositionU16;
using GPU::SizeU16;
@ -126,6 +127,6 @@ namespace FileProcessor {
State create(const uint32_t* data_adr, const SimpleTIM& file) {
return State::from(SimpleTIMState(file), data_adr, parse_header);
}
}
}
#undef private

View File

@ -1,6 +1,7 @@
#include "../include/GPU/gpu.hpp"
namespace GPU {
namespace JabyEngine {
namespace GPU {
namespace Screen {
uint8_t CurrentDisplayAreaID = 1; //< Setup will call exchange and set it to 0
@ -33,4 +34,5 @@ namespace GPU {
GP1.write(Command::GP1::DisplayArea(0, (Display::Height*CurrentDisplayAreaID)));
}
}
}
}