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 52be17a891
commit 9d97cf746d
27 changed files with 1320 additions and 1282 deletions

View File

@ -2,53 +2,55 @@
#define __JABYENGINE_BITS_HPP__ #define __JABYENGINE_BITS_HPP__
#include "../jabyengine_defines.h" #include "../jabyengine_defines.h"
namespace bit { namespace JabyEngine {
template<typename T> namespace bit {
static constexpr T set(T raw_value, size_t bit) {
return (raw_value | (1 << bit));
}
template<typename T>
static constexpr T clear(T raw_value, size_t bit) {
return (raw_value & ~(1 << bit));
}
template<typename T>
static constexpr bool is_set(T raw_value, size_t bit) {
return static_cast<bool>(raw_value & (1 << bit));
}
namespace value {
template<typename T> template<typename T>
static constexpr T crop_value(T raw_value, size_t length) { static constexpr T set(T raw_value, size_t bit) {
return (raw_value & ((1 << length) - 1)); return (raw_value | (1 << bit));
} }
template<typename T> template<typename T>
static constexpr T range_mask(size_t start_bit, size_t length) { static constexpr T clear(T raw_value, size_t bit) {
return (((1 << length) - 1) << start_bit); return (raw_value & ~(1 << bit));
} }
template<typename T> template<typename T>
static constexpr T clear_normalized(T raw_value, size_t start_bit, size_t length) { static constexpr bool is_set(T raw_value, size_t bit) {
return (raw_value & ~range_mask<T>(start_bit, length)); return static_cast<bool>(raw_value & (1 << bit));
} }
template<typename T> namespace value {
static constexpr T set_normalized(T raw_value, T value, size_t start_bit, size_t length) { template<typename T>
return (clear_normalized(raw_value, start_bit, length) | (value << start_bit)); static constexpr T crop_value(T raw_value, size_t length) {
return (raw_value & ((1 << length) - 1));
}
template<typename T>
static constexpr T range_mask(size_t start_bit, size_t length) {
return (((1 << length) - 1) << start_bit);
}
template<typename T>
static constexpr T clear_normalized(T raw_value, size_t start_bit, size_t length) {
return (raw_value & ~range_mask<T>(start_bit, length));
}
template<typename T>
static constexpr T set_normalized(T raw_value, T value, size_t start_bit, size_t length) {
return (clear_normalized(raw_value, start_bit, length) | (value << start_bit));
}
template<typename T>
static constexpr T get_normalized(T raw_value, size_t start_bit, size_t length) {
return (raw_value & range_mask<T>(start_bit, length)) >> start_bit;
}
} }
template<typename T> template<typename S, typename T>
static constexpr T get_normalized(T raw_value, size_t start_bit, size_t length) { static constexpr S cast(T value) {
return (raw_value & range_mask<T>(start_bit, length)) >> start_bit; return *reinterpret_cast<S*>(&value);
} }
} }
template<typename S, typename T>
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) #define __start_end_bit2_start_length(start_bit, end_bit) start_bit, (end_bit - start_bit + 1)

View File

@ -2,194 +2,196 @@
#define __JABYENGINE_COMPLEX_BITMAP_HPP__ #define __JABYENGINE_COMPLEX_BITMAP_HPP__
#include "bits.hpp" #include "bits.hpp"
struct ClearBitValue { namespace JabyEngine {
size_t bit; struct ClearBitValue {
size_t bit;
constexpr ClearBitValue(size_t bit) : bit(bit) { constexpr ClearBitValue(size_t bit) : bit(bit) {
} }
}; };
template<typename T> template<typename T>
struct Bit { struct Bit {
typedef T ValueType; typedef T ValueType;
size_t value; size_t value;
constexpr Bit(size_t value) : value(value) { constexpr Bit(size_t value) : value(value) {
}
constexpr operator size_t() const {
return this->value;
}
constexpr ClearBitValue operator!() const {
return ClearBitValue(this->value);
}
};
template<typename T>
struct BitRangeValue {
T value;
size_t begin;
size_t length;
};
template<typename T>
struct BitRange {
typedef T ValueType;
size_t begin;
size_t length;
static constexpr BitRange<T> from_to(size_t start, size_t end) {
return {start, (end - start + 1)};
}
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) {
return BitRangeValue{value, range.begin, range.length};
} }
constexpr operator size_t() const { template<typename T>
return this->value; class ComplexBitMap {
} public:
T raw;
constexpr ClearBitValue operator!() const { private:
return ClearBitValue(this->value); template<typename S>
} constexpr __always_inline ComplexBitMap<T>& set_va(const S& value) {
}; return this->set(value);
}
template<typename T> template<typename S, typename...ARGS>
struct BitRangeValue { constexpr __always_inline ComplexBitMap<T>& set_va(const S& value, const ARGS&...args) {
T value; return this->set_va(value).set_va(args...);
size_t begin; }
size_t length;
};
template<typename T> public:
struct BitRange { template<typename...ARGS>
typedef T ValueType; static constexpr __always_inline ComplexBitMap<T> with(ARGS...args) {
return ComplexBitMap().set_va(args...);
}
size_t begin; //Accesssing bits
size_t length; template<typename S>
constexpr ComplexBitMap<T>& set_bit(S bit) {
this->raw = bit::set(this->raw, static_cast<size_t>(bit));
return *this;
}
static constexpr BitRange<T> from_to(size_t start, size_t end) { template<typename S>
return {start, (end - start + 1)}; constexpr void set_bit(S bit) volatile {
} this->raw = bit::set(this->raw, static_cast<size_t>(bit));
}
constexpr BitRangeValue<T> with(T value) const { template<typename S>
return {value, this->begin, this->length}; constexpr ComplexBitMap<T>& clear_bit(S bit) {
} this->raw = bit::clear(this->raw, static_cast<size_t>(bit));
}; return *this;
}
template<typename T> template<typename S>
static constexpr __always_inline BitRangeValue<T> operator<<(const BitRange<T>& range, T value) { constexpr void clear_bit(S bit) volatile {
return BitRangeValue{value, range.begin, range.length}; this->raw = bit::clear(this->raw, static_cast<size_t>(bit));
}
template<typename S>
constexpr bool is_bit_set(S bit) {
return bit::is_set(this->raw, static_cast<size_t>(bit));
}
template<typename S>
constexpr bool is_bit_set(S bit) const volatile {
return bit::is_set(this->raw, static_cast<size_t>(bit));
}
//Accessing values
template<typename S>
constexpr ComplexBitMap<T>& set_value(S value, const BitRange<S>& range) {
this->raw = bit::value::set_normalized(this->raw, static_cast<T>(value), range.begin, range.length);
return *this;
}
template<typename S>
constexpr void set_value(S value, const BitRange<S>& range) volatile {
this->raw = bit::value::set_normalized(this->raw, static_cast<T>(value), range.begin, range.length);
}
template<typename S>
constexpr ComplexBitMap<T>& clear_value(const BitRange<S>& range) {
this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length);
return *this;
}
template<typename S>
constexpr void clear_value(const BitRange<S>& range) volatile {
this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length);
}
template<typename S>
constexpr S get_value(const BitRange<S>& range) const {
return static_cast<S>(bit::value::get_normalized(this->raw, range.begin, range.length));
}
template<typename S>
constexpr S get_value(const BitRange<S>& range) const volatile {
return static_cast<S>(bit::value::get_normalized(this->raw, range.begin, range.length));
}
//For easier checking
constexpr bool is(Bit<T> bit) const {
return ComplexBitMap::is_bit_set(bit);
}
constexpr bool is(Bit<T> bit) const volatile {
return ComplexBitMap::is_bit_set(bit);
}
// For easier constructing
template<typename S>
constexpr __always_inline ComplexBitMap<T>& set(const BitRange<S>& range, T value) {
this->set_value(value, range);
return *this;
}
template<typename S>
constexpr __always_inline ComplexBitMap<T>& set(const BitRangeValue<S>& value) {
this->set_value(value.value, {value.begin, value.length});
return *this;
}
template<typename S>
constexpr __always_inline ComplexBitMap<T>& set(const Bit<S>& bit) {
this->set_bit(bit.value);
return *this;
}
constexpr __always_inline ComplexBitMap<T>& set(const ClearBitValue& value) {
this->clear_bit(value.bit);
return *this;
}
constexpr __always_inline ComplexBitMap<T>& operator|(const BitRangeValue<T>& value) {
this->set_value(value.value, value.range);
return *this;
}
constexpr __always_inline ComplexBitMap<T>& operator|(const Bit<T>& bit) {
this->set_bit(bit.value);
return *this;
}
constexpr __always_inline ComplexBitMap<T>& operator|(const ClearBitValue& value) {
this->clear_bit(value.bit);
return *this;
}
};
} }
template<typename T>
class ComplexBitMap {
public:
T raw;
private:
template<typename S>
constexpr __always_inline ComplexBitMap<T>& set_va(const S& value) {
return this->set(value);
}
template<typename S, typename...ARGS>
constexpr __always_inline ComplexBitMap<T>& set_va(const S& value, const ARGS&...args) {
return this->set_va(value).set_va(args...);
}
public:
template<typename...ARGS>
static constexpr __always_inline ComplexBitMap<T> with(ARGS...args) {
return ComplexBitMap().set_va(args...);
}
//Accesssing bits
template<typename S>
constexpr ComplexBitMap<T>& set_bit(S bit) {
this->raw = bit::set(this->raw, static_cast<size_t>(bit));
return *this;
}
template<typename S>
constexpr void set_bit(S bit) volatile {
this->raw = bit::set(this->raw, static_cast<size_t>(bit));
}
template<typename S>
constexpr ComplexBitMap<T>& clear_bit(S bit) {
this->raw = bit::clear(this->raw, static_cast<size_t>(bit));
return *this;
}
template<typename S>
constexpr void clear_bit(S bit) volatile {
this->raw = bit::clear(this->raw, static_cast<size_t>(bit));
}
template<typename S>
constexpr bool is_bit_set(S bit) {
return bit::is_set(this->raw, static_cast<size_t>(bit));
}
template<typename S>
constexpr bool is_bit_set(S bit) const volatile {
return bit::is_set(this->raw, static_cast<size_t>(bit));
}
//Accessing values
template<typename S>
constexpr ComplexBitMap<T>& set_value(S value, const BitRange<S>& range) {
this->raw = bit::value::set_normalized(this->raw, static_cast<T>(value), range.begin, range.length);
return *this;
}
template<typename S>
constexpr void set_value(S value, const BitRange<S>& range) volatile {
this->raw = bit::value::set_normalized(this->raw, static_cast<T>(value), range.begin, range.length);
}
template<typename S>
constexpr ComplexBitMap<T>& clear_value(const BitRange<S>& range) {
this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length);
return *this;
}
template<typename S>
constexpr void clear_value(const BitRange<S>& range) volatile {
this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length);
}
template<typename S>
constexpr S get_value(const BitRange<S>& range) const {
return static_cast<S>(bit::value::get_normalized(this->raw, range.begin, range.length));
}
template<typename S>
constexpr S get_value(const BitRange<S>& range) const volatile {
return static_cast<S>(bit::value::get_normalized(this->raw, range.begin, range.length));
}
//For easier checking
constexpr bool is(Bit<T> bit) const {
return ComplexBitMap::is_bit_set(bit);
}
constexpr bool is(Bit<T> bit) const volatile {
return ComplexBitMap::is_bit_set(bit);
}
// For easier constructing
template<typename S>
constexpr __always_inline ComplexBitMap<T>& set(const BitRange<S>& range, T value) {
this->set_value(value, range);
return *this;
}
template<typename S>
constexpr __always_inline ComplexBitMap<T>& set(const BitRangeValue<S>& value) {
this->set_value(value.value, {value.begin, value.length});
return *this;
}
template<typename S>
constexpr __always_inline ComplexBitMap<T>& set(const Bit<S>& bit) {
this->set_bit(bit.value);
return *this;
}
constexpr __always_inline ComplexBitMap<T>& set(const ClearBitValue& value) {
this->clear_bit(value.bit);
return *this;
}
constexpr __always_inline ComplexBitMap<T>& operator|(const BitRangeValue<T>& value) {
this->set_value(value.value, value.range);
return *this;
}
constexpr __always_inline ComplexBitMap<T>& operator|(const Bit<T>& bit) {
this->set_bit(bit.value);
return *this;
}
constexpr __always_inline ComplexBitMap<T>& operator|(const ClearBitValue& value) {
this->clear_bit(value.bit);
return *this;
}
};
#endif //!__JABYENGINE_COMPLEX_BITMAP_HPP__ #endif //!__JABYENGINE_COMPLEX_BITMAP_HPP__

View File

@ -3,28 +3,30 @@
#include "../cd_file_types.hpp" #include "../cd_file_types.hpp"
#include "file_processor.hpp" #include "file_processor.hpp"
namespace CDFileProcessor { namespace JabyEngine {
class State { namespace CDFileProcessor {
private: class State {
FileProcessor::State file_processor_state; private:
const uint32_t* data_adr; FileProcessor::State file_processor_state;
const uint32_t* data_adr;
public: public:
State() = default; State() = default;
void setup(uint16_t lba, uint16_t size, const CDFile::Payload& payload); void setup(uint16_t lba, uint16_t size, const CDFile::Payload& payload);
bool process(); bool process();
}; };
template<size_t Size> template<size_t Size>
static void load_from_cd(const OverlayLBA* overlay_lbas, const CDFile (&cd_files)[Size]) { static void load_from_cd(const OverlayLBA* overlay_lbas, const CDFile (&cd_files)[Size]) {
State state; State state;
for(const auto& file : cd_files) { for(const auto& file : cd_files) {
const auto& lba_info = overlay_lbas[file.rel_lba_idx]; const auto& lba_info = overlay_lbas[file.rel_lba_idx];
state.setup(lba_info.lba, lba_info.size, file.payload); state.setup(lba_info.lba, lba_info.size, file.payload);
//while(state.process());??? //while(state.process());???
}
} }
} }
} }

View File

@ -2,50 +2,51 @@
#define __JABYENGINE_FILE_PROCESSOR_HPP__ #define __JABYENGINE_FILE_PROCESSOR_HPP__
#include "../file_types.hpp" #include "../file_types.hpp"
namespace FileProcessor { namespace JabyEngine {
class State { namespace FileProcessor {
private: class State {
struct Reserved { private:
uint32_t reserved[4]; struct Reserved {
}; uint32_t reserved[4];
};
struct Configuration; struct Configuration;
typedef bool (*ProcessRoutine)(Configuration&, Reserved&); typedef bool (*ProcessRoutine)(Configuration&, Reserved&);
struct Configuration { struct Configuration {
ProcessRoutine process_routine = nullptr; ProcessRoutine process_routine = nullptr;
const uint32_t* data_adr = nullptr; const uint32_t* data_adr = nullptr;
size_t data_word_size = 0ull; size_t data_word_size = 0ull;
template<typename T>
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&), const uint32_t* data_adr) {
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
}
constexpr void processed(size_t words) {
this->data_adr += words;
this->data_word_size -= words;
}
};
private:
Configuration config;
Reserved reserved;
template<typename T> template<typename T>
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&), const uint32_t* data_adr) { static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&)) {
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr}; return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&reserved)};
static_assert(sizeof(T) <= sizeof(Reserved));
} }
constexpr void processed(size_t words) { public:
this->data_adr += words; bool process(size_t word_size) {
this->data_word_size -= words; this->config.data_word_size += word_size;
return (*this->config.process_routine)(this->config, this->reserved);
} }
}; };
private: State create(const uint32_t* data_adr, const SimpleTIM& file);
Configuration config; }
Reserved reserved;
template<typename T>
static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&)) {
return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&reserved)};
static_assert(sizeof(T) <= sizeof(Reserved));
}
public:
bool process(size_t word_size) {
this->config.data_word_size += word_size;
return (*this->config.process_routine)(this->config, this->reserved);
}
};
State create(const uint32_t* data_adr, const SimpleTIM& file);
} }
#endif // !__JABYENGINE_FILE_PROCESSOR_HPP__ #endif // !__JABYENGINE_FILE_PROCESSOR_HPP__

View File

@ -3,25 +3,27 @@
#include "../Overlay/overlay.hpp" #include "../Overlay/overlay.hpp"
#include "file_types.hpp" #include "file_types.hpp"
enum struct CDFileType : uint8_t { namespace JabyEngine {
SimpleTIM = 0, enum struct CDFileType : uint8_t {
Custom SimpleTIM = 0,
}; Custom
struct __no_align CDFile {
union __no_align Payload {
uint32_t empty;
SimpleTIM simple_tim;
}; };
uint8_t rel_lba_idx; struct __no_align CDFile {
CDFileType type; union __no_align Payload {
Payload payload; uint32_t empty;
}; SimpleTIM simple_tim;
};
namespace CDFileBuilder { uint8_t rel_lba_idx;
static constexpr CDFile simple_tim(uint8_t rel_lba_idx, SimpleTIM simple_tim) { CDFileType type;
return CDFile{.rel_lba_idx = rel_lba_idx, .type = CDFileType::SimpleTIM, .payload = {.simple_tim = simple_tim}}; Payload payload;
};
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__ #endif //!__JABYENGINE_CD_FILE_TYPES_HPP__

View File

@ -3,35 +3,35 @@
#include "../Auxiliary/complex_bitmap.hpp" #include "../Auxiliary/complex_bitmap.hpp"
#include "../jabyengine_defines.h" #include "../jabyengine_defines.h"
struct __no_align SimpleTIM : private ComplexBitMap<uint32_t> { namespace JabyEngine {
static constexpr auto TextureX = BitRange<uint32_t>(0, 8); struct __no_align SimpleTIM : private ComplexBitMap<uint32_t> {
static constexpr auto TextureY = BitRange<uint32_t>(9, 16); static constexpr auto TextureX = BitRange<uint32_t>(0, 8);
static constexpr auto ClutX = BitRange<uint32_t>(17, 22); static constexpr auto TextureY = BitRange<uint32_t>(9, 16);
static constexpr auto ClutY = BitRange<uint32_t>(23, 31); static constexpr auto ClutX = BitRange<uint32_t>(17, 22);
static constexpr auto ClutY = BitRange<uint32_t>(23, 31);
constexpr SimpleTIM() { constexpr SimpleTIM() {
this->raw = 0; this->raw = 0;
} }
constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : ComplexBitMap(ComplexBitMap::with(TextureX.with(texX >> 1), TextureY.with(texY >> 1), ClutX.with(clutX >> 4), ClutY.with(clutY))) { constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : ComplexBitMap(ComplexBitMap::with(TextureX.with(texX >> 1), TextureY.with(texY >> 1), ClutX.with(clutX >> 4), ClutY.with(clutY))) {
} }
constexpr uint16_t getTextureX() const { constexpr uint16_t getTextureX() const {
return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::TextureX) << 1); return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::TextureX) << 1);
} }
constexpr uint16_t getTextureY() const { constexpr uint16_t getTextureY() const {
return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::TextureY) << 1); return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::TextureY) << 1);
} }
constexpr uint16_t getClutX() const {
return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::ClutX) << 4);
}
constexpr uint16_t getClutY() const {
return ComplexBitMap<uint32_t>::get_value(SimpleTIM::ClutY);
}
};
constexpr uint16_t getClutX() const {
return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::ClutX) << 4);
}
constexpr uint16_t getClutY() const {
return ComplexBitMap<uint32_t>::get_value(SimpleTIM::ClutY);
}
};
}
#endif // !__JABYENGINE_FILE_TYPES_HPP__ #endif // !__JABYENGINE_FILE_TYPES_HPP__

View File

@ -10,32 +10,33 @@
#endif #endif
#endif #endif
namespace GPU { namespace JabyEngine {
namespace Display { namespace GPU {
#ifdef JABYENGINE_PAL namespace Display {
static constexpr size_t Width = 320; #ifdef JABYENGINE_PAL
static constexpr size_t Height = 256; static constexpr size_t Width = 320;
#else static constexpr size_t Height = 256;
static constexpr size_t Width = 320; #else
static constexpr size_t Height = 240; static constexpr size_t Width = 320;
#endif static constexpr size_t Height = 240;
#endif
static void enable() { static void enable() {
GP1.write(Command::GP1::SetDisplayState(DisplayState::On)); GP1.write(Command::GP1::SetDisplayState(DisplayState::On));
}
static void disable() {
GP1.write(Command::GP1::SetDisplayState(DisplayState::Off));
}
} }
static void disable() { namespace Screen {
GP1.write(Command::GP1::SetDisplayState(DisplayState::Off)); extern uint8_t CurrentDisplayAreaID;
}
}
namespace Screen { namespace Range {
extern uint8_t CurrentDisplayAreaID; void set_offset(uint16_t x, uint16_t y);
}
namespace Range {
void set_offset(uint16_t x, uint16_t y);
} }
} }
} }
#endif //!__JABYENGINE_GPU_HPP__ #endif //!__JABYENGINE_GPU_HPP__

View File

@ -3,100 +3,101 @@
#include "../jabyengine_defines.h" #include "../jabyengine_defines.h"
#include "../Auxiliary/complex_bitmap.hpp" #include "../Auxiliary/complex_bitmap.hpp"
namespace GPU { namespace JabyEngine {
struct Color24 { namespace GPU {
uint8_t red = 0; struct Color24 {
uint8_t green = 0; uint8_t red = 0;
uint8_t blue = 0; uint8_t green = 0;
uint8_t blue = 0;
constexpr Color24() = default; constexpr Color24() = default;
constexpr Color24(uint8_t r, uint8_t g, uint8_t b) : blue(b), green(g), red(r) { constexpr Color24(uint8_t r, uint8_t g, uint8_t b) : blue(b), green(g), red(r) {
} }
constexpr uint32_t raw() const { constexpr uint32_t raw() const {
return ((this->blue << 16) | (this->green << 8) | this->red); return ((this->blue << 16) | (this->green << 8) | this->red);
} }
static constexpr Color24 Black() { static constexpr Color24 Black() {
return Color24(0, 0, 0); return Color24(0, 0, 0);
} }
static constexpr Color24 White() { static constexpr Color24 White() {
return Color24(0xFF, 0xFF, 0xFF); return Color24(0xFF, 0xFF, 0xFF);
} }
static constexpr Color24 Red() { static constexpr Color24 Red() {
return Color24(0xFF, 0x0, 0x0); return Color24(0xFF, 0x0, 0x0);
} }
static constexpr Color24 Green() { static constexpr Color24 Green() {
return Color24(0x0, 0xFF, 0x0); return Color24(0x0, 0xFF, 0x0);
} }
static constexpr Color24 Blue() { static constexpr Color24 Blue() {
return Color24(0x0, 0x0, 0xFF); return Color24(0x0, 0x0, 0xFF);
} }
}; };
class Color { class Color {
private: private:
static constexpr auto RedRange = BitRange<uint16_t>::from_to(0, 4); static constexpr auto RedRange = BitRange<uint16_t>::from_to(0, 4);
static constexpr auto GreenRange = BitRange<uint16_t>::from_to(5, 9); static constexpr auto GreenRange = BitRange<uint16_t>::from_to(5, 9);
static constexpr auto BlueRange = BitRange<uint16_t>::from_to(10, 14); static constexpr auto BlueRange = BitRange<uint16_t>::from_to(10, 14);
static constexpr auto SemiTransperancyBit = Bit<uint16_t>(15); static constexpr auto SemiTransperancyBit = Bit<uint16_t>(15);
ComplexBitMap<uint16_t> value = {0}; ComplexBitMap<uint16_t> value = {0};
public: public:
static constexpr Color from_rgb(uint8_t r, uint8_t g, uint8_t b) { static constexpr Color from_rgb(uint8_t r, uint8_t g, uint8_t b) {
return Color().set_red(r).set_green(g).set_blue(b); return Color().set_red(r).set_green(g).set_blue(b);
} }
static constexpr Color from(const Color24& color) { static constexpr Color from(const Color24& color) {
return Color::from_rgb(color.red, color.green, color.blue); return Color::from_rgb(color.red, color.green, color.blue);
} }
constexpr Color& set_red(uint8_t red) { constexpr Color& set_red(uint8_t red) {
this->value.set_value(static_cast<uint16_t>(red), RedRange); this->value.set_value(static_cast<uint16_t>(red), RedRange);
return *this; return *this;
} }
constexpr Color& set_green(uint8_t green) { constexpr Color& set_green(uint8_t green) {
this->value.set_value(static_cast<uint16_t>(green), GreenRange); this->value.set_value(static_cast<uint16_t>(green), GreenRange);
return *this; return *this;
} }
constexpr Color& set_blue(uint8_t blue) { constexpr Color& set_blue(uint8_t blue) {
this->value.set_value(static_cast<uint16_t>(blue), BlueRange); this->value.set_value(static_cast<uint16_t>(blue), BlueRange);
return *this; return *this;
} }
}; };
template<typename T> template<typename T>
struct Position { struct Position {
T x = 0; T x = 0;
T y = 0; T y = 0;
constexpr Position() = default; constexpr Position() = default;
constexpr Position(T x, T y) : x(x), y(y) { constexpr Position(T x, T y) : x(x), y(y) {
} }
}; };
template<typename T> template<typename T>
struct Size { struct Size {
T width = 0; T width = 0;
T height = 0; T height = 0;
constexpr Size() = default; constexpr Size() = default;
constexpr Size(T w, T h) : width(w), height(h) { constexpr Size(T w, T h) : width(w), height(h) {
} }
}; };
typedef Position<int16_t> PositionI16; typedef Position<int16_t> PositionI16;
typedef Position<uint16_t> PositionU16; typedef Position<uint16_t> PositionU16;
typedef Size<int16_t> SizeI16; typedef Size<int16_t> SizeI16;
typedef Size<uint16_t> SizeU16; typedef Size<uint16_t> SizeU16;
}
} }
#endif //!__JABYENGINE_GPU_TYPES_HPP__ #endif //!__JABYENGINE_GPU_TYPES_HPP__

View File

@ -2,14 +2,16 @@
#define __JABYENGINE_OVERLAY__HPP__ #define __JABYENGINE_OVERLAY__HPP__
#include "../../stdint.h" #include "../../stdint.h"
struct __attribute__((packed)) OverlayHeader { namespace JabyEngine {
void (*execute)(); struct __attribute__((packed)) OverlayHeader {
uint16_t lba_size; void (*execute)();
}; uint16_t lba_size;
};
// Maybe encode attributes like "isLZ4" into size parameter // Maybe encode attributes like "isLZ4" into size parameter
struct __attribute__((packed)) OverlayLBA { struct __attribute__((packed)) OverlayLBA {
uint16_t lba; uint16_t lba;
uint16_t size; uint16_t size;
}; };
}
#endif //!__JABYENGINE_OVERLAY__HPP__ #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 // 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 JabyEngine::OverlayHeader overlay_header;
extern const OverlayLBA overlay_lba[]; extern const JabyEngine::OverlayLBA overlay_lba[];
#define __declare_overlay_header(function, enum_struct) \ #define __declare_overlay_header(function, enum_struct) \
[[gnu::used]] \ [[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]] \ [[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__ #endif //!__JABYENGINE_OVERLAY_DECLARATION__HPP__

View File

@ -2,143 +2,144 @@
#define __JABYENGINE_DMA_IO_HPP__ #define __JABYENGINE_DMA_IO_HPP__
#include "ioport.hpp" #include "ioport.hpp"
namespace DMA { namespace JabyEngine {
struct __no_align MADR : public ComplexBitMap<uint32_t> { namespace DMA {
__io_port_inherit_complex_bit_map(MADR); struct __no_align MADR : public ComplexBitMap<uint32_t> {
__io_port_inherit_complex_bit_map(MADR);
static constexpr auto MemoryAdr = BitRange<uint32_t>::from_to(0, 23); static constexpr auto MemoryAdr = BitRange<uint32_t>::from_to(0, 23);
};
struct __no_align BCR : public ComplexBitMap<uint32_t> {
__io_port_inherit_complex_bit_map(BCR);
struct __no_align SyncMode0 {
static constexpr auto NumberOfWords = BitRange<uint16_t>::from_to(0, 15);
static constexpr auto CD_OneBlock = Bit<uint16_t>(16);
}; };
struct __no_align SyncMode1 : public ComplexBitMap<uint32_t> { struct __no_align BCR : public ComplexBitMap<uint32_t> {
__io_port_inherit_complex_bit_map(SyncMode1); __io_port_inherit_complex_bit_map(BCR);
static constexpr auto BlockSize = BitRange<uint32_t>::from_to(0, 15); struct __no_align SyncMode0 {
static constexpr auto BlockAmount = BitRange<uint32_t>::from_to(16, 31); static constexpr auto NumberOfWords = BitRange<uint16_t>::from_to(0, 15);
static constexpr auto CD_OneBlock = Bit<uint16_t>(16);
};
struct __no_align SyncMode1 : public ComplexBitMap<uint32_t> {
__io_port_inherit_complex_bit_map(SyncMode1);
static constexpr auto BlockSize = BitRange<uint32_t>::from_to(0, 15);
static constexpr auto BlockAmount = BitRange<uint32_t>::from_to(16, 31);
};
struct __no_align SyncMode2 {
};
}; };
struct __no_align SyncMode2 { struct __no_align CHCHR : public ComplexBitMap<uint32_t> {
}; __io_port_inherit_complex_bit_map(CHCHR);
};
struct __no_align CHCHR : public ComplexBitMap<uint32_t> { enum _SyncMode {
__io_port_inherit_complex_bit_map(CHCHR); Sync0 = 0, //Start immediately,
Sync1 = 1, //Sync blocks to DMA requests
Sync2 = 2, //Linked List
};
enum _SyncMode { static constexpr auto ManualStart = Bit<uint32_t>(28);
Sync0 = 0, //Start immediately,
Sync1 = 1, //Sync blocks to DMA requests static constexpr auto Start = Bit<uint32_t>(24);
Sync2 = 2, //Linked List static constexpr auto Busy = Start;
static constexpr auto ChoppingCPUWindowSize = BitRange<uint32_t>::from_to(20, 22);
static constexpr auto ChoppingDMAWindowSize = BitRange<uint32_t>::from_to(16, 18);
static constexpr auto SyncMode = BitRange<_SyncMode>::from_to(9, 10);
static constexpr auto UseSyncMode0 = SyncMode.with(Sync0);
static constexpr auto UseSyncMode1 = SyncMode.with(Sync1);
static constexpr auto UseSyncMode2 = SyncMode.with(Sync2);
static constexpr auto UseChopping = Bit<uint32_t>(8);
static constexpr auto MemoryAdrDecreaseBy4 = Bit<uint32_t>(1);
static constexpr auto MemoryAdrIncreaseBy4 = !MemoryAdrDecreaseBy4;
static constexpr auto FromMainRAM = Bit<uint32_t>(0);
static constexpr auto ToMainRAM = !FromMainRAM;
static constexpr CHCHR StartMDECin() {
return ComplexBitMap{0x01000201};
}
static constexpr CHCHR StartMDECout() {
return ComplexBitMap{0x01000200};
}
static constexpr CHCHR StartGPUReceive() {
return ComplexBitMap{0x01000201};
}
static constexpr CHCHR StartCDROM() {
return ComplexBitMap{0x11000000};
}
static constexpr CHCHR StartSPUReceive() {
return ComplexBitMap{0x01000201};
}
static constexpr CHCHR StartOTC() {
return ComplexBitMap{0x11000002};
}
}; };
static constexpr auto ManualStart = Bit<uint32_t>(28); struct __no_align Registers {
IOPort<MADR> adr;
IOPort<BCR> block_ctrl;
IOPort<CHCHR> channel_ctrl;
};
static constexpr auto Start = Bit<uint32_t>(24); //0: Highest, 7: Lowest
static constexpr auto Busy = Start; typedef uint32_t Priority;
static constexpr Priority HighestPriority = 0;
static constexpr Priority LowestPriority = 7;
static constexpr auto ChoppingCPUWindowSize = BitRange<uint32_t>::from_to(20, 22); struct __no_align DMAControlRegister : public ComplexBitMap<uint32_t> {
static constexpr auto ChoppingDMAWindowSize = BitRange<uint32_t>::from_to(16, 18); __io_port_inherit_complex_bit_map(DMAControlRegister);
static constexpr auto SyncMode = BitRange<_SyncMode>::from_to(9, 10); static constexpr auto OTCEnable = Bit<uint32_t>(27);
static constexpr auto UseSyncMode0 = SyncMode.with(Sync0); static constexpr auto OTCPriority = BitRange<Priority>::from_to(24, 26);
static constexpr auto UseSyncMode1 = SyncMode.with(Sync1);
static constexpr auto UseSyncMode2 = SyncMode.with(Sync2);
static constexpr auto UseChopping = Bit<uint32_t>(8); static constexpr auto PIOEnable = Bit<uint32_t>(23);
static constexpr auto PIOPriority = BitRange<Priority>::from_to(20, 22);
static constexpr auto MemoryAdrDecreaseBy4 = Bit<uint32_t>(1); static constexpr auto SPUEnable = Bit<uint32_t>(19);
static constexpr auto MemoryAdrIncreaseBy4 = !MemoryAdrDecreaseBy4; static constexpr auto SPUPriority = BitRange<Priority>::from_to(16, 18);
static constexpr auto FromMainRAM = Bit<uint32_t>(0); static constexpr auto CDROMEnable = Bit<uint32_t>(15);
static constexpr auto ToMainRAM = !FromMainRAM; static constexpr auto CDROMPriority = BitRange<Priority>::from_to(12, 14);
static constexpr CHCHR StartMDECin() { static constexpr auto GPUEnable = Bit<uint32_t>(11);
return ComplexBitMap{0x01000201}; static constexpr auto GPUPriority = BitRange<Priority>::from_to(8, 10);
}
static constexpr CHCHR StartMDECout() { static constexpr auto MDECoutEnable = Bit<uint32_t>(7);
return ComplexBitMap{0x01000200}; static constexpr auto MDECoutPriority = BitRange<Priority>::from_to(4, 6);
}
static constexpr CHCHR StartGPUReceive() { static constexpr auto MDECinEnable = Bit<uint32_t>(3);
return ComplexBitMap{0x01000201}; static constexpr auto MDECinPriority = BitRange<Priority>::from_to(0, 2);
} };
static constexpr CHCHR StartCDROM() { struct __no_align DMAInterruptRegister : public ComplexBitMap<uint32_t> {
return ComplexBitMap{0x11000000}; __io_port_inherit_complex_bit_map(DMAInterruptRegister);
}
static constexpr CHCHR StartSPUReceive() { static constexpr auto MasterEnable = Bit<uint32_t>(31);
return ComplexBitMap{0x01000201}; static constexpr auto Flags = BitRange<uint32_t>::from_to(24, 30);
} static constexpr auto MasterEnableDPCR = Bit<uint32_t>(23);
static constexpr auto EnableDPCR = BitRange<uint32_t>::from_to(16, 22);
static constexpr auto ForceIRQ = Bit<uint32_t>(15);
};
static constexpr CHCHR StartOTC() { __declare_io_port_global(Registers, MDECin, 0x1F801080);
return ComplexBitMap{0x11000002}; __declare_io_port_global(Registers, MDECout, 0x1F801090);
} __declare_io_port_global_struct(Registers, GPU, 0x1F8010A0);
}; __declare_io_port_global(Registers, CDROM, 0x1F8010B0);
__declare_io_port_global(Registers, SPU, 0x1F8010C0);
__declare_io_port_global(Registers, PIO, 0x1F8010D0);
__declare_io_port_global(Registers, OTC, 0x1F8010E0);
struct __no_align Registers { __declare_io_port_global(DMAControlRegister, DPCR, 0x1F8010F0);
IOPort<MADR> adr; __declare_io_port_global(DMAInterruptRegister, DICR, 0x1F8010F4);
IOPort<BCR> block_ctrl; }
IOPort<CHCHR> channel_ctrl;
};
//0: Highest, 7: Lowest
typedef uint32_t Priority;
static constexpr Priority HighestPriority = 0;
static constexpr Priority LowestPriority = 7;
struct __no_align DMAControlRegister : public ComplexBitMap<uint32_t> {
__io_port_inherit_complex_bit_map(DMAControlRegister);
static constexpr auto OTCEnable = Bit<uint32_t>(27);
static constexpr auto OTCPriority = BitRange<Priority>::from_to(24, 26);
static constexpr auto PIOEnable = Bit<uint32_t>(23);
static constexpr auto PIOPriority = BitRange<Priority>::from_to(20, 22);
static constexpr auto SPUEnable = Bit<uint32_t>(19);
static constexpr auto SPUPriority = BitRange<Priority>::from_to(16, 18);
static constexpr auto CDROMEnable = Bit<uint32_t>(15);
static constexpr auto CDROMPriority = BitRange<Priority>::from_to(12, 14);
static constexpr auto GPUEnable = Bit<uint32_t>(11);
static constexpr auto GPUPriority = BitRange<Priority>::from_to(8, 10);
static constexpr auto MDECoutEnable = Bit<uint32_t>(7);
static constexpr auto MDECoutPriority = BitRange<Priority>::from_to(4, 6);
static constexpr auto MDECinEnable = Bit<uint32_t>(3);
static constexpr auto MDECinPriority = BitRange<Priority>::from_to(0, 2);
};
struct __no_align DMAInterruptRegister : public ComplexBitMap<uint32_t> {
__io_port_inherit_complex_bit_map(DMAInterruptRegister);
static constexpr auto MasterEnable = Bit<uint32_t>(31);
static constexpr auto Flags = BitRange<uint32_t>::from_to(24, 30);
static constexpr auto MasterEnableDPCR = Bit<uint32_t>(23);
static constexpr auto EnableDPCR = BitRange<uint32_t>::from_to(16, 22);
static constexpr auto ForceIRQ = Bit<uint32_t>(15);
};
__declare_io_port_global(Registers, MDECin, 0x1F801080);
__declare_io_port_global(Registers, MDECout, 0x1F801090);
__declare_io_port_global_struct(Registers, GPU, 0x1F8010A0);
__declare_io_port_global(Registers, CDROM, 0x1F8010B0);
__declare_io_port_global(Registers, SPU, 0x1F8010C0);
__declare_io_port_global(Registers, PIO, 0x1F8010D0);
__declare_io_port_global(Registers, OTC, 0x1F8010E0);
__declare_io_port_global(DMAControlRegister, DPCR, 0x1F8010F0);
__declare_io_port_global(DMAInterruptRegister, DICR, 0x1F8010F4);
} }
#endif //!__JABYENGINE_DMA_IO_HPP__ #endif //!__JABYENGINE_DMA_IO_HPP__

View File

@ -3,170 +3,171 @@
#include "ioport.hpp" #include "ioport.hpp"
#include "../../GPU/gpu_types.hpp" #include "../../GPU/gpu_types.hpp"
namespace GPU { namespace JabyEngine {
enum struct SemiTransparency { namespace GPU {
B_Half_add_F_Half = 0, enum struct SemiTransparency {
B_add_F = 1, B_Half_add_F_Half = 0,
B_sub_F = 2, B_add_F = 1,
B_add_F_Quarter = 3, B_sub_F = 2,
}; B_add_F_Quarter = 3,
enum struct DisplayAreaColorDepth {
$15bit = 0,
$24bit = 1,
};
enum struct TexturePageColor {
$4bit = 0,
$8bit = 1,
$15bit = 2,
};
enum struct HorizontalResolution {
$256 = 0,
$320 = 1,
$512 = 2,
$640 = 3,
};
enum struct VerticalResolution {
$240 = 0,
$480 = 1
};
enum struct DMADirection {
Off = 0,
Fifo = 1,
CPU2GPU = 2,
GPU2CPU = 3,
};
enum struct DisplayState {
On = 0,
Off = 1
};
namespace Command {
struct __no_align GP0 : public ComplexBitMap<uint32_t> {
__io_port_inherit_complex_bit_map(GP0);
static constexpr GP0 QuickFill(Color24 color) {
return ComplexBitMap{(0x02 << 24) | color.raw()};
}
static constexpr GP0 CPU2VRAM_Blitting() {
return ComplexBitMap{(0b101u << 29)};
}
static constexpr GP0 DrawAreaTemplate(uint8_t code, uint16_t x, uint16_t y) {
constexpr auto Command = BitRange<uint32_t>::from_to(24, 31);
constexpr auto Y = BitRange<uint32_t>::from_to(10, 18);
constexpr auto X = BitRange<uint32_t>::from_to(0, 9);
return ComplexBitMap<uint32_t>::with(Command.with(code), Y.with(y), X.with(x));
}
static constexpr GP0 DrawAreaTopLeft(uint16_t x, uint16_t y) {
return DrawAreaTemplate(0xE3, x, y);
}
static constexpr GP0 DrawAreaBottomRight(uint16_t x, uint16_t y) {
return DrawAreaTemplate(0xE4, x, y);
}
static constexpr GP0 TopLeftPosition(uint16_t x, uint16_t y) {
return ComplexBitMap{static_cast<uint32_t>((y << 16u) | x)};
}
static constexpr GP0 WidthHeight(uint16_t w, uint16_t h) {
return ComplexBitMap{static_cast<uint32_t>((h << 16u) | w)};
}
}; };
struct __no_align GP1 : public ComplexBitMap<uint32_t> { enum struct DisplayAreaColorDepth {
__io_port_inherit_complex_bit_map(GP1); $15bit = 0,
$24bit = 1,
static constexpr uint32_t construct_cmd(uint8_t cmd, uint32_t value) {
return ((cmd << 24) | value);
}
static constexpr GP1 Reset() {
return ComplexBitMap{0};
}
static constexpr GP1 ResetCMDBufer() {
return ComplexBitMap{construct_cmd(0x01, 0)};
}
static constexpr GP1 SetDisplayState(DisplayState state) {
return ComplexBitMap{construct_cmd(0x03, static_cast<uint32_t>(state))};
}
static constexpr GP1 DMADirection(DMADirection dir) {
return ComplexBitMap{construct_cmd(0x04, static_cast<uint32_t>(dir))};
}
static constexpr GP1 DisplayArea(uint16_t x, uint16_t y) {
constexpr auto X = BitRange<uint32_t>::from_to(0, 9);
constexpr auto Y = BitRange<uint32_t>::from_to(10, 18);
return ComplexBitMap{construct_cmd(0x05, ComplexBitMap<uint32_t>::with(X.with(x), Y.with(y)).raw)};
}
static constexpr GP1 HorizontalDisplayRange(uint32_t x1, uint32_t x2) {
constexpr auto X1 = BitRange<uint32_t>::from_to(0, 11);
constexpr auto X2 = BitRange<uint32_t>::from_to(12, 23);
return ComplexBitMap{construct_cmd(0x06, ComplexBitMap<uint32_t>::with(X1.with(x1), X2.with(x2)).raw)};
}
static constexpr GP1 VerticalDisplayRange(uint32_t y1, uint32_t y2) {
constexpr auto Y1 = BitRange<uint32_t>::from_to(0, 9);
constexpr auto Y2 = BitRange<uint32_t>::from_to(10, 19);
return ComplexBitMap{construct_cmd(0x07, ComplexBitMap<uint32_t>::with(Y1.with(y1), Y2.with(y2)).raw)};
}
static constexpr GP1 DisplayMode(uint32_t mode) {
return ComplexBitMap{construct_cmd(0x08, mode)};
}
}; };
enum struct TexturePageColor {
$4bit = 0,
$8bit = 1,
$15bit = 2,
};
enum struct HorizontalResolution {
$256 = 0,
$320 = 1,
$512 = 2,
$640 = 3,
};
enum struct VerticalResolution {
$240 = 0,
$480 = 1
};
enum struct DMADirection {
Off = 0,
Fifo = 1,
CPU2GPU = 2,
GPU2CPU = 3,
};
enum struct DisplayState {
On = 0,
Off = 1
};
namespace Command {
struct __no_align GP0 : public ComplexBitMap<uint32_t> {
__io_port_inherit_complex_bit_map(GP0);
static constexpr GP0 QuickFill(Color24 color) {
return ComplexBitMap{(0x02 << 24) | color.raw()};
}
static constexpr GP0 CPU2VRAM_Blitting() {
return ComplexBitMap{(0b101u << 29)};
}
static constexpr GP0 DrawAreaTemplate(uint8_t code, uint16_t x, uint16_t y) {
constexpr auto Command = BitRange<uint32_t>::from_to(24, 31);
constexpr auto Y = BitRange<uint32_t>::from_to(10, 18);
constexpr auto X = BitRange<uint32_t>::from_to(0, 9);
return ComplexBitMap<uint32_t>::with(Command.with(code), Y.with(y), X.with(x));
}
static constexpr GP0 DrawAreaTopLeft(uint16_t x, uint16_t y) {
return DrawAreaTemplate(0xE3, x, y);
}
static constexpr GP0 DrawAreaBottomRight(uint16_t x, uint16_t y) {
return DrawAreaTemplate(0xE4, x, y);
}
static constexpr GP0 TopLeftPosition(uint16_t x, uint16_t y) {
return ComplexBitMap{static_cast<uint32_t>((y << 16u) | x)};
}
static constexpr GP0 WidthHeight(uint16_t w, uint16_t h) {
return ComplexBitMap{static_cast<uint32_t>((h << 16u) | w)};
}
};
struct __no_align GP1 : public ComplexBitMap<uint32_t> {
__io_port_inherit_complex_bit_map(GP1);
static constexpr uint32_t construct_cmd(uint8_t cmd, uint32_t value) {
return ((cmd << 24) | value);
}
static constexpr GP1 Reset() {
return ComplexBitMap{0};
}
static constexpr GP1 ResetCMDBufer() {
return ComplexBitMap{construct_cmd(0x01, 0)};
}
static constexpr GP1 SetDisplayState(DisplayState state) {
return ComplexBitMap{construct_cmd(0x03, static_cast<uint32_t>(state))};
}
static constexpr GP1 DMADirection(DMADirection dir) {
return ComplexBitMap{construct_cmd(0x04, static_cast<uint32_t>(dir))};
}
static constexpr GP1 DisplayArea(uint16_t x, uint16_t y) {
constexpr auto X = BitRange<uint32_t>::from_to(0, 9);
constexpr auto Y = BitRange<uint32_t>::from_to(10, 18);
return ComplexBitMap{construct_cmd(0x05, ComplexBitMap<uint32_t>::with(X.with(x), Y.with(y)).raw)};
}
static constexpr GP1 HorizontalDisplayRange(uint32_t x1, uint32_t x2) {
constexpr auto X1 = BitRange<uint32_t>::from_to(0, 11);
constexpr auto X2 = BitRange<uint32_t>::from_to(12, 23);
return ComplexBitMap{construct_cmd(0x06, ComplexBitMap<uint32_t>::with(X1.with(x1), X2.with(x2)).raw)};
}
static constexpr GP1 VerticalDisplayRange(uint32_t y1, uint32_t y2) {
constexpr auto Y1 = BitRange<uint32_t>::from_to(0, 9);
constexpr auto Y2 = BitRange<uint32_t>::from_to(10, 19);
return ComplexBitMap{construct_cmd(0x07, ComplexBitMap<uint32_t>::with(Y1.with(y1), Y2.with(y2)).raw)};
}
static constexpr GP1 DisplayMode(uint32_t mode) {
return ComplexBitMap{construct_cmd(0x08, mode)};
}
};
}
struct __no_align GPUStatusRegister : public ComplexBitMap<uint32_t> {
static constexpr auto DrawingOddLinesInterlaced = Bit<uint32_t>(31);
static constexpr auto DMADirectionValue = BitRange<DMADirection>::from_to(29, 30);
static constexpr auto DMAReady = Bit<uint32_t>(28);
static constexpr auto VRAMtoCPUtransferReay = Bit<uint32_t>(27);
static constexpr auto GP0ReadyForCMD = Bit<uint32_t>(26);
static constexpr auto FifoNotFull = Bit<uint32_t>(25); // Only for Fifo
static constexpr auto InterruptRequest = Bit<uint32_t>(24);
static constexpr auto DisplayDisabled = Bit<uint32_t>(23);
static constexpr auto VerticalInterlaceOn = Bit<uint32_t>(22);
static constexpr auto DisplayAreaColorDepth = BitRange<GPU::DisplayAreaColorDepth>::from_to(21, 21);
static constexpr auto VideoModePal = Bit<uint32_t>(20);
static constexpr auto VerticalResolutionValue = BitRange<VerticalResolution>::from_to(19, 19);
static constexpr auto HorizontalResolutionValue = BitRange<HorizontalResolution>::from_to(17, 18);
static constexpr auto HorizontalResolution368 = Bit<uint32_t>(16);
static constexpr auto TexturesDisabled = Bit<uint32_t>(15);
static constexpr auto NotDrawingMaskedPixels = Bit<uint32_t>(12);
static constexpr auto MaskBitSetDuringDrawEnabled = Bit<uint32_t>(11);
static constexpr auto DrawingToDisplayAreadAllowed = Bit<uint32_t>(10);
static constexpr auto DitherEnabled = Bit<uint32_t>(9);
static constexpr auto TexturePageColorValue = BitRange<TexturePageColor>::from_to(7, 8);
static constexpr auto SemiTransparencyValue = BitRange<SemiTransparency>::from_to(5, 6);
static constexpr auto TexturePageY = BitRange<uint32_t>::from_to(4, 4); // N*256
static constexpr auto TexturePageX = BitRange<uint32_t>::from_to(0, 3); // N*64
static constexpr auto VerticalResolution480 = Bit<uint32_t>(19);
static constexpr auto TexturePageY256 = Bit<uint32_t>(4);
};
__declare_io_port_global(Command::GP0, GP0, 0x1F801810);
__declare_io_port_global(Command::GP1, GP1, 0x1F801814);
__declare_io_port_global_const(uint32_t, GPUREAD, 0x1F801810);
__declare_io_port_global_const(GPUStatusRegister, GPUSTAT, 0x1F801814);
} }
struct __no_align GPUStatusRegister : public ComplexBitMap<uint32_t> {
static constexpr auto DrawingOddLinesInterlaced = Bit<uint32_t>(31);
static constexpr auto DMADirectionValue = BitRange<DMADirection>::from_to(29, 30);
static constexpr auto DMAReady = Bit<uint32_t>(28);
static constexpr auto VRAMtoCPUtransferReay = Bit<uint32_t>(27);
static constexpr auto GP0ReadyForCMD = Bit<uint32_t>(26);
static constexpr auto FifoNotFull = Bit<uint32_t>(25); // Only for Fifo
static constexpr auto InterruptRequest = Bit<uint32_t>(24);
static constexpr auto DisplayDisabled = Bit<uint32_t>(23);
static constexpr auto VerticalInterlaceOn = Bit<uint32_t>(22);
static constexpr auto DisplayAreaColorDepth = BitRange<GPU::DisplayAreaColorDepth>::from_to(21, 21);
static constexpr auto VideoModePal = Bit<uint32_t>(20);
static constexpr auto VerticalResolutionValue = BitRange<VerticalResolution>::from_to(19, 19);
static constexpr auto HorizontalResolutionValue = BitRange<HorizontalResolution>::from_to(17, 18);
static constexpr auto HorizontalResolution368 = Bit<uint32_t>(16);
static constexpr auto TexturesDisabled = Bit<uint32_t>(15);
static constexpr auto NotDrawingMaskedPixels = Bit<uint32_t>(12);
static constexpr auto MaskBitSetDuringDrawEnabled = Bit<uint32_t>(11);
static constexpr auto DrawingToDisplayAreadAllowed = Bit<uint32_t>(10);
static constexpr auto DitherEnabled = Bit<uint32_t>(9);
static constexpr auto TexturePageColorValue = BitRange<TexturePageColor>::from_to(7, 8);
static constexpr auto SemiTransparencyValue = BitRange<SemiTransparency>::from_to(5, 6);
static constexpr auto TexturePageY = BitRange<uint32_t>::from_to(4, 4); // N*256
static constexpr auto TexturePageX = BitRange<uint32_t>::from_to(0, 3); // N*64
static constexpr auto VerticalResolution480 = Bit<uint32_t>(19);
static constexpr auto TexturePageY256 = Bit<uint32_t>(4);
};
__declare_io_port_global(Command::GP0, GP0, 0x1F801810);
__declare_io_port_global(Command::GP1, GP1, 0x1F801814);
__declare_io_port_global_const(uint32_t, GPUREAD, 0x1F801810);
__declare_io_port_global_const(GPUStatusRegister, GPUSTAT, 0x1F801814);
} }
#endif //!__JABYENGINE_GPU_IO_HPP__ #endif //!__JABYENGINE_GPU_IO_HPP__

View File

@ -2,80 +2,81 @@
#define __JABYENGINE_IOPORT_HPP__ #define __JABYENGINE_IOPORT_HPP__
#include "../../Auxiliary/complex_bitmap.hpp" #include "../../Auxiliary/complex_bitmap.hpp"
template<typename T> namespace JabyEngine {
class __no_align IOPort { template<typename T>
private: class __no_align IOPort {
T value; private:
T value;
public: public:
//For easy access //For easy access
constexpr T read() const { constexpr T read() const {
return const_cast<volatile IOPort<T>*>(this)->value; return const_cast<volatile IOPort<T>*>(this)->value;
} }
constexpr void write(T value) { constexpr void write(T value) {
const_cast<volatile IOPort<T>*>(this)->value = value; const_cast<volatile IOPort<T>*>(this)->value = value;
} }
constexpr volatile T& ref() { constexpr volatile T& ref() {
return const_cast<volatile IOPort<T>*>(this)->value; return const_cast<volatile IOPort<T>*>(this)->value;
} }
constexpr const volatile T& ref() const { constexpr const volatile T& ref() const {
return const_cast<volatile IOPort<T>*>(this)->value; 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> low;
ComplexBitMap<uint16_t> high; ComplexBitMap<uint16_t> high;
constexpr ubus32_t(uint32_t value) { constexpr ubus32_t(uint32_t value) {
*this = value; *this = value;
} }
constexpr operator uint32_t() const { constexpr operator uint32_t() const {
return ((this->high.raw << 16) | this->low.raw); return ((this->high.raw << 16) | this->low.raw);
} }
operator uint32_t() const volatile { operator uint32_t() const volatile {
return ((this->high.raw << 16) | this->low.raw); return ((this->high.raw << 16) | this->low.raw);
} }
constexpr ubus32_t& operator=(uint32_t value) { constexpr ubus32_t& operator=(uint32_t value) {
this->low.raw = (value & 0xFFFF); this->low.raw = (value & 0xFFFF);
this->high.raw = (value >> 16); this->high.raw = (value >> 16);
return *this; return *this;
} }
constexpr void operator=(uint32_t value) volatile { constexpr void operator=(uint32_t value) volatile {
this->low.raw = (value & 0xFFFF); this->low.raw = (value & 0xFFFF);
this->high.raw = (value >> 16); this->high.raw = (value >> 16);
} }
}; };
static constexpr uintptr_t IO_Base_Mask = 0xF0000000; static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
static constexpr uintptr_t IO_Base_Adr = 0x10000000; static constexpr uintptr_t IO_Base_Adr = 0x10000000;
#define __io_port_adr(adr) (IO_Base_Adr + (adr & ~IO_Base_Mask)) #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_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(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_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_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_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast<type*>(__io_port_adr(adr))
#define __io_port_inherit_complex_bit_map(name) \
constexpr __always_inline name() = default; \
constexpr __always_inline name(ComplexBitMap value) : ComplexBitMap(value) { \
} \
template<typename...ARGS> \
static constexpr __always_inline name with(ARGS...args) { \
return {ComplexBitMap::with(args...)}; \
}\
template<typename T> \
constexpr void __always_inline operator=(ComplexBitMap<T> value) volatile { \
this->raw = value.raw; \
}
#define __io_port_inherit_complex_bit_map(name) \
constexpr __always_inline name() = default; \
constexpr __always_inline name(ComplexBitMap value) : ComplexBitMap(value) { \
} \
template<typename...ARGS> \
static constexpr __always_inline name with(ARGS...args) { \
return {ComplexBitMap::with(args...)}; \
}\
template<typename T> \
constexpr void __always_inline operator=(ComplexBitMap<T> value) volatile { \
this->raw = value.raw; \
}
}
#endif //!__JABYENGINE_IOPORT_HPP__ #endif //!__JABYENGINE_IOPORT_HPP__

View File

@ -2,168 +2,169 @@
#define __JABYENGINE_SPU_IO_HPP__ #define __JABYENGINE_SPU_IO_HPP__
#include "ioport.hpp" #include "ioport.hpp"
namespace SPU { namespace JabyEngine {
enum struct Mode { namespace SPU {
Linear = 0, enum struct Mode {
Exponential = 1, Linear = 0,
}; Exponential = 1,
enum struct Direction {
Increase = 0,
Decrease = 1,
};
enum struct Phase {
Posititve = 0,
Negative = 1,
};
//0..0x1F = Fast..Slow
typedef uint8_t Shift;
//0..3 = +7, +6, +5, +4 or -6, -7, -6, -5
typedef uint8_t Step;
typedef int16_t SimpleVolume;
struct __no_align SampleRate : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(SampleRate);
static constexpr SampleRate from_HZ(double freq) {
//4096 == 44100Hz
constexpr double Base = (4096.0 / 44100.0);
return ComplexBitMap<uint16_t>{static_cast<uint16_t>((freq*Base))};
}
};
struct __no_align SweepVolume : public ComplexBitMap<int16_t> {
__io_port_inherit_complex_bit_map(SweepVolume);
// For Volume Mode
static constexpr auto SweepEnable = Bit<int16_t>(15);
static constexpr auto VolumeEnable = !SweepEnable;
static constexpr auto Volume = BitRange<int16_t>::from_to(0, 14);
// For Sweep Mode
static constexpr auto SweepMode = Bit<Mode>(14);
static constexpr auto SweepDirection = Bit<Direction>(13);
static constexpr auto SweepPhase = Bit<Phase>(12);
static constexpr auto SweepShift = BitRange<Shift>::from_to(2, 6);
static constexpr auto SweepStep = BitRange<Step>::from_to(0, 1);
};
struct __no_align SR : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(SR);
static constexpr auto SustainMode = Bit<Mode>(31 - 16);
static constexpr auto SustainDirection = Bit<Direction>(30 - 16);
static constexpr auto SustainShift = BitRange<Shift>::from_to((24 - 16), (28 - 16));
static constexpr auto SustainStep = BitRange<Step>::from_to((22 - 16), (23 - 16));
static constexpr auto ReleaseMode = Bit<Mode>(21 - 16);
static constexpr auto ReleaseShift = BitRange<Shift>::from_to((16 - 16), (20 - 16));
};
struct __no_align AD : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(AD);
static constexpr auto AttackMode = Bit<Mode>(15);
static constexpr auto AttackShift = BitRange<Shift>::from_to(10, 14);
static constexpr auto AttackStep = BitRange<Step>::from_to(8, 9);
static constexpr auto DecayShift = BitRange<Shift>::from_to(4, 7);
static constexpr auto SustainLevel = BitRange<uint16_t>::from_to(0, 3);
};
struct __no_align Voice {
IOPort<SweepVolume> volumeLeft; //Offset: 0x0
IOPort<SweepVolume> volumeRight; //Offset: 0x2
IOPort<SampleRate> sampleRate; //Offset: 0x4;
IOPort<uint16_t> adr; //Offset: 0x6
IOPort<AD> ad; //Offset: 0x8
IOPort<SR> sr; //Offset: 0xA
IOPort<SimpleVolume> currentVolume; //Offset: 0xC
IOPort<uint16_t> repeatAdr; //Offset: 0xE
};
struct __no_align ControlRegister : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(ControlRegister);
enum RAMTransferMode {
Stop = 0,
ManualWrite = 1,
DMAWrite = 2,
DMARead = 3
}; };
static constexpr auto Enable = Bit<uint16_t>(15); enum struct Direction {
static constexpr auto Unmute = Bit<uint16_t>(14); Increase = 0,
static constexpr auto NoiseFrequcenyShift = BitRange<Shift>::from_to(10, 13); Decrease = 1,
static constexpr auto NoiseFrequcenyStep = BitRange<Step>::from_to(8, 9); };
static constexpr auto ReverbMasterEnable = Bit<uint16_t>(7);
static constexpr auto IRQ9Enable = Bit<uint16_t>(6);
static constexpr auto TransferMode = BitRange<RAMTransferMode>::from_to(4, 5);
static constexpr auto ExternalAudioReverb = Bit<uint16_t>(3);
static constexpr auto CDAudioReverb = Bit<uint16_t>(2);
static constexpr auto ExternalAudioEnable = Bit<uint16_t>(1);
static constexpr auto CDAudioEnable = Bit<uint16_t>(0);
};
struct __no_align PitchModFlags : public ComplexBitMap<uint16_t> { enum struct Phase {
__io_port_inherit_complex_bit_map(PitchModFlags); Posititve = 0,
Negative = 1,
};
static constexpr BitRange<uint16_t> EnableBits = BitRange<uint16_t>::from_to(1, 23); //0..0x1F = Fast..Slow
}; typedef uint8_t Shift;
struct __no_align NoiseGenerator : public ComplexBitMap<uint16_t> { //0..3 = +7, +6, +5, +4 or -6, -7, -6, -5
__io_port_inherit_complex_bit_map(NoiseGenerator); typedef uint8_t Step;
static constexpr BitRange<uint16_t> NoiseBits = BitRange<uint16_t>::from_to(0, 23); typedef int16_t SimpleVolume;
};
struct __no_align EchoOn : public ComplexBitMap<uint16_t> { struct __no_align SampleRate : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(EchoOn); __io_port_inherit_complex_bit_map(SampleRate);
static constexpr BitRange<uint16_t> EchoBits = BitRange<uint16_t>::from_to(0, 23); static constexpr SampleRate from_HZ(double freq) {
}; //4096 == 44100Hz
constexpr double Base = (4096.0 / 44100.0);
static constexpr size_t VoiceCount = 24; return ComplexBitMap<uint16_t>{static_cast<uint16_t>((freq*Base))};
}
};
namespace Key { struct __no_align SweepVolume : public ComplexBitMap<int16_t> {
__declare_io_port_global(ubus32_t, on, 0x1F801D88); __io_port_inherit_complex_bit_map(SweepVolume);
__declare_io_port_global(ubus32_t, off, 0x1F801D8C);
__declare_io_port_global(ubus32_t, status, 0x1F801D9C);
}
namespace MainVolume { // For Volume Mode
__declare_io_port_global(SweepVolume, left, 0x1F801D80); static constexpr auto SweepEnable = Bit<int16_t>(15);
__declare_io_port_global(SweepVolume, right, 0x1F801D82); static constexpr auto VolumeEnable = !SweepEnable;
} static constexpr auto Volume = BitRange<int16_t>::from_to(0, 14);
namespace CDVolume { // For Sweep Mode
__declare_io_port_global(SimpleVolume, left, 0x1F801DB0); static constexpr auto SweepMode = Bit<Mode>(14);
__declare_io_port_global(SimpleVolume, right, 0x1F801DB2); static constexpr auto SweepDirection = Bit<Direction>(13);
} static constexpr auto SweepPhase = Bit<Phase>(12);
static constexpr auto SweepShift = BitRange<Shift>::from_to(2, 6);
static constexpr auto SweepStep = BitRange<Step>::from_to(0, 1);
};
namespace ExternalAudioInputVolume { struct __no_align SR : public ComplexBitMap<uint16_t> {
__declare_io_port_global(SimpleVolume, left, 0x1F801DB4); __io_port_inherit_complex_bit_map(SR);
__declare_io_port_global(SimpleVolume, right, 0x1F801DB6);
}
namespace Reverb { static constexpr auto SustainMode = Bit<Mode>(31 - 16);
namespace Volume { static constexpr auto SustainDirection = Bit<Direction>(30 - 16);
__declare_io_port_global(SimpleVolume, left, 0x1F801D84); static constexpr auto SustainShift = BitRange<Shift>::from_to((24 - 16), (28 - 16));
__declare_io_port_global(SimpleVolume, right, 0x1F801D86); static constexpr auto SustainStep = BitRange<Step>::from_to((22 - 16), (23 - 16));
static constexpr auto ReleaseMode = Bit<Mode>(21 - 16);
static constexpr auto ReleaseShift = BitRange<Shift>::from_to((16 - 16), (20 - 16));
};
struct __no_align AD : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(AD);
static constexpr auto AttackMode = Bit<Mode>(15);
static constexpr auto AttackShift = BitRange<Shift>::from_to(10, 14);
static constexpr auto AttackStep = BitRange<Step>::from_to(8, 9);
static constexpr auto DecayShift = BitRange<Shift>::from_to(4, 7);
static constexpr auto SustainLevel = BitRange<uint16_t>::from_to(0, 3);
};
struct __no_align Voice {
IOPort<SweepVolume> volumeLeft; //Offset: 0x0
IOPort<SweepVolume> volumeRight; //Offset: 0x2
IOPort<SampleRate> sampleRate; //Offset: 0x4;
IOPort<uint16_t> adr; //Offset: 0x6
IOPort<AD> ad; //Offset: 0x8
IOPort<SR> sr; //Offset: 0xA
IOPort<SimpleVolume> currentVolume; //Offset: 0xC
IOPort<uint16_t> repeatAdr; //Offset: 0xE
};
struct __no_align ControlRegister : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(ControlRegister);
enum RAMTransferMode {
Stop = 0,
ManualWrite = 1,
DMAWrite = 2,
DMARead = 3
};
static constexpr auto Enable = Bit<uint16_t>(15);
static constexpr auto Unmute = Bit<uint16_t>(14);
static constexpr auto NoiseFrequcenyShift = BitRange<Shift>::from_to(10, 13);
static constexpr auto NoiseFrequcenyStep = BitRange<Step>::from_to(8, 9);
static constexpr auto ReverbMasterEnable = Bit<uint16_t>(7);
static constexpr auto IRQ9Enable = Bit<uint16_t>(6);
static constexpr auto TransferMode = BitRange<RAMTransferMode>::from_to(4, 5);
static constexpr auto ExternalAudioReverb = Bit<uint16_t>(3);
static constexpr auto CDAudioReverb = Bit<uint16_t>(2);
static constexpr auto ExternalAudioEnable = Bit<uint16_t>(1);
static constexpr auto CDAudioEnable = Bit<uint16_t>(0);
};
struct __no_align PitchModFlags : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(PitchModFlags);
static constexpr BitRange<uint16_t> EnableBits = BitRange<uint16_t>::from_to(1, 23);
};
struct __no_align NoiseGenerator : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(NoiseGenerator);
static constexpr BitRange<uint16_t> NoiseBits = BitRange<uint16_t>::from_to(0, 23);
};
struct __no_align EchoOn : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(EchoOn);
static constexpr BitRange<uint16_t> EchoBits = BitRange<uint16_t>::from_to(0, 23);
};
static constexpr size_t VoiceCount = 24;
namespace Key {
__declare_io_port_global(ubus32_t, on, 0x1F801D88);
__declare_io_port_global(ubus32_t, off, 0x1F801D8C);
__declare_io_port_global(ubus32_t, status, 0x1F801D9C);
} }
__declare_io_port_global(uint16_t, work_area_adr, 0x1F801DA2);
namespace MainVolume {
__declare_io_port_global(SweepVolume, left, 0x1F801D80);
__declare_io_port_global(SweepVolume, right, 0x1F801D82);
}
namespace CDVolume {
__declare_io_port_global(SimpleVolume, left, 0x1F801DB0);
__declare_io_port_global(SimpleVolume, right, 0x1F801DB2);
}
namespace ExternalAudioInputVolume {
__declare_io_port_global(SimpleVolume, left, 0x1F801DB4);
__declare_io_port_global(SimpleVolume, right, 0x1F801DB6);
}
namespace Reverb {
namespace Volume {
__declare_io_port_global(SimpleVolume, left, 0x1F801D84);
__declare_io_port_global(SimpleVolume, right, 0x1F801D86);
}
__declare_io_port_global(uint16_t, work_area_adr, 0x1F801DA2);
}
__declare_io_port_global(ControlRegister, Control, 0x1F801DAA);
__declare_io_port_global(uint16_t, DataTransferControl, 0x1F801DAC);
__declare_io_port_global(PitchModFlags, PMON, 0x1F801D90);
__declare_io_port_global(NoiseGenerator, NON, 0x1F801D94);
__declare_io_port_global(EchoOn, EON, 0x1F801D98);
__declare_io_port_global_array(Voice, Voices, 0x1F801C00, VoiceCount);
} }
__declare_io_port_global(ControlRegister, Control, 0x1F801DAA);
__declare_io_port_global(uint16_t, DataTransferControl, 0x1F801DAC);
__declare_io_port_global(PitchModFlags, PMON, 0x1F801D90);
__declare_io_port_global(NoiseGenerator, NON, 0x1F801D94);
__declare_io_port_global(EchoOn, EON, 0x1F801D98);
__declare_io_port_global_array(Voice, Voices, 0x1F801C00, VoiceCount);
} }
#endif //!__JABYENGINE_SPU_IO_HPP__ #endif //!__JABYENGINE_SPU_IO_HPP__

View File

@ -2,6 +2,7 @@
#define __JABYENGINE_SCRATCHPAD_HPP__ #define __JABYENGINE_SCRATCHPAD_HPP__
#include "../jabyengine_defines.h" #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__ #endif //!__JABYENGINE_SCRATCHPAD_HPP__

View File

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

View File

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

View File

@ -2,17 +2,18 @@
#define __JABYENGINE_CD_HPP__ #define __JABYENGINE_CD_HPP__
#include <stdint.h> #include <stdint.h>
namespace CD { namespace JabyEngine {
namespace CircularBuffer { namespace CD {
extern uint8_t* write_ptr; namespace CircularBuffer {
extern uint8_t* read_ptr; extern uint8_t* write_ptr;
extern uint8_t* end_ptr; extern uint8_t* read_ptr;
extern uint8_t* end_ptr;
}
enum struct State {
};
extern State state;
} }
enum struct State {
};
extern State state;
} }
#endif //!__JABYENGINE_CD_HPP__ #endif //!__JABYENGINE_CD_HPP__

View File

@ -4,111 +4,113 @@
#include <PSX/System/IOPorts/dma_io.hpp> #include <PSX/System/IOPorts/dma_io.hpp>
#include <PSX/System/IOPorts/gpu_io.hpp> #include <PSX/System/IOPorts/gpu_io.hpp>
namespace GPU { namespace JabyEngine {
namespace Screen { namespace GPU {
struct Mode { namespace Screen {
enum struct TVEncoding { struct Mode {
NTSC = 0, enum struct TVEncoding {
PAL = 1, NTSC = 0,
PAL = 1,
};
static constexpr auto HorizontalResolution368 = Bit<uint32_t>(6);
static constexpr auto VerticalInterlace = Bit<uint32_t>(5);
static constexpr auto DisplayAreaColorDepth = BitRange<GPU::DisplayAreaColorDepth>::from_to(4, 4);
static constexpr auto VideoMode = BitRange<TVEncoding>::from_to(3, 3);
static constexpr auto VerticalResolution = BitRange<GPU::VerticalResolution>::from_to(2, 2);
static constexpr auto HorizontalResolution = BitRange<GPU::HorizontalResolution>::from_to(0, 1);
static constexpr uint32_t PAL() {
return ComplexBitMap<uint32_t>::with(
Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320),
Mode::VerticalResolution.with(GPU::VerticalResolution::$240),
Mode::VideoMode.with(TVEncoding::PAL),
Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit)
).raw;
}
static constexpr uint32_t NTSC() {
return ComplexBitMap<uint32_t>::with(
Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320),
Mode::VerticalResolution.with(GPU::VerticalResolution::$240),
Mode::VideoMode.with(TVEncoding::NTSC),
Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit)
).raw;
}
}; };
static constexpr auto HorizontalResolution368 = Bit<uint32_t>(6); static void configurate() {
static constexpr auto VerticalInterlace = Bit<uint32_t>(5); static constexpr uint16_t FirstVisiblePixelH = 0x260;
static constexpr auto DisplayAreaColorDepth = BitRange<GPU::DisplayAreaColorDepth>::from_to(4, 4);
static constexpr auto VideoMode = BitRange<TVEncoding>::from_to(3, 3);
static constexpr auto VerticalResolution = BitRange<GPU::VerticalResolution>::from_to(2, 2);
static constexpr auto HorizontalResolution = BitRange<GPU::HorizontalResolution>::from_to(0, 1);
static constexpr uint32_t PAL() { #ifdef JABYENGINE_PAL
return ComplexBitMap<uint32_t>::with( static constexpr uint16_t FirstVisiblePixelV = 0xA3;
Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320),
Mode::VerticalResolution.with(GPU::VerticalResolution::$240), GP1.write(Command::GP1::DisplayMode(Mode::PAL()));
Mode::VideoMode.with(TVEncoding::PAL), GPU::Screen::Range::set_offset(0, 0);
Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit) #else
).raw; static constexpr uint16_t FirstVisiblePixelV = 0x88;
GP1.write(Command::GP1::DisplayMode(Mode::NTSC()));
GPU::Screen::set_offset(0, 5); //< Random values
#endif
} }
static constexpr uint32_t NTSC() { void exchange_buffer_and_display();
return ComplexBitMap<uint32_t>::with( }
Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320),
Mode::VerticalResolution.with(GPU::VerticalResolution::$240), static void set_draw_area(uint16_t x, uint16_t y) {
Mode::VideoMode.with(TVEncoding::NTSC), GP0.write(Command::GP0::DrawAreaTopLeft(x, y));
Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit) GP0.write(Command::GP0::DrawAreaBottomRight((x + Display::Width), (y + Display::Height)));
).raw; }
static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) {
GP0.write(Command::GP0::QuickFill(color));
GP0.write(Command::GP0::TopLeftPosition(pos.x, pos.y));
GP0.write(Command::GP0::WidthHeight(size.width, size.height));
}
static void reset_cmd_buffer() {
GP1.write(Command::GP1::ResetCMDBufer());
}
static void wait_ready_for_CMD() {
while(!GPUSTAT.ref().is(GPUStatusRegister::GP0ReadyForCMD));
}
namespace DMA {
static void wait() {
while(::JabyEngine::DMA::GPU.channel_ctrl.ref().is(::JabyEngine::DMA::CHCHR::Busy));
} }
};
static void configurate() { static void end() {
static constexpr uint16_t FirstVisiblePixelH = 0x260;
#ifdef JABYENGINE_PAL
static constexpr uint16_t FirstVisiblePixelV = 0xA3;
GP1.write(Command::GP1::DisplayMode(Mode::PAL()));
GPU::Screen::Range::set_offset(0, 0);
#else
static constexpr uint16_t FirstVisiblePixelV = 0x88;
GP1.write(Command::GP1::DisplayMode(Mode::NTSC()));
GPU::Screen::set_offset(0, 5); //< Random values
#endif
}
void exchange_buffer_and_display();
}
static void set_draw_area(uint16_t x, uint16_t y) {
GP0.write(Command::GP0::DrawAreaTopLeft(x, y));
GP0.write(Command::GP0::DrawAreaBottomRight((x + Display::Width), (y + Display::Height)));
}
static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) {
GP0.write(Command::GP0::QuickFill(color));
GP0.write(Command::GP0::TopLeftPosition(pos.x, pos.y));
GP0.write(Command::GP0::WidthHeight(size.width, size.height));
}
static void reset_cmd_buffer() {
GP1.write(Command::GP1::ResetCMDBufer());
}
static void wait_ready_for_CMD() {
while(!GPUSTAT.ref().is(GPUStatusRegister::GP0ReadyForCMD));
}
namespace DMA {
static void wait() {
while(::DMA::GPU.channel_ctrl.ref().is(::DMA::CHCHR::Busy));
}
static void end() {
reset_cmd_buffer();
}
namespace Receive {
static void prepare()
{
GP1.write(Command::GP1::DMADirection(DMADirection::CPU2GPU));
reset_cmd_buffer(); reset_cmd_buffer();
} }
static void set_src(uintptr_t adr) { namespace Receive {
::DMA::GPU.adr.ref().set_value(static_cast<uint32_t>(adr), ::DMA::MADR::MemoryAdr); static void prepare()
} {
GP1.write(Command::GP1::DMADirection(DMADirection::CPU2GPU));
reset_cmd_buffer();
}
static void set_dst(const PositionU16& position, const SizeU16& size) { static void set_src(uintptr_t adr) {
::JabyEngine::DMA::GPU.adr.ref().set_value(static_cast<uint32_t>(adr), ::JabyEngine::DMA::MADR::MemoryAdr);
}
wait_ready_for_CMD(); static void set_dst(const PositionU16& position, const SizeU16& size) {
GP0.write(Command::GP0::CPU2VRAM_Blitting());
GP0.write(Command::GP0::TopLeftPosition(position.x, position.y));
GP0.write(Command::GP0::WidthHeight(size.width, size.height));
}
static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) { wait_ready_for_CMD();
typedef ::DMA::BCR::SyncMode1 SyncMode1; GP0.write(Command::GP0::CPU2VRAM_Blitting());
GP0.write(Command::GP0::TopLeftPosition(position.x, position.y));
GP0.write(Command::GP0::WidthHeight(size.width, size.height));
}
::DMA::GPU.block_ctrl.write(SyncMode1::with(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount))); static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) {
::DMA::GPU.channel_ctrl.write(::DMA::CHCHR::StartGPUReceive()); typedef ::JabyEngine::DMA::BCR::SyncMode1 SyncMode1;
::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(); extern JabyEngine::NextRoutine main();
namespace BootFile { namespace JabyEngine {
JabyEngine::NextRoutine setup() { namespace BootFile {
printf("Running main!\n"); JabyEngine::NextRoutine setup() {
return JabyEngine::NextRoutine::from(main); printf("Running main!\n");
return JabyEngine::NextRoutine::from(main);
}
} }
} }

View File

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

View File

@ -8,21 +8,23 @@
#include "splash_image_ntsc_boot.hpp" #include "splash_image_ntsc_boot.hpp"
#endif //JABYENGINE_PAL #endif //JABYENGINE_PAL
namespace GPU { namespace JabyEngine {
void display_logo() { namespace GPU {
// Upload SplashScreen picture void display_logo() {
auto state = FileProcessor::create(reinterpret_cast<const uint32_t*>(SplashScreen), SimpleTIM(32, 0, 0, 0)); // Upload SplashScreen picture
while(state.process((sizeof(SplashScreen)/sizeof(uint32_t)))); auto state = FileProcessor::create(reinterpret_cast<const uint32_t*>(SplashScreen), SimpleTIM(32, 0, 0, 0));
while(state.process((sizeof(SplashScreen)/sizeof(uint32_t))));
Display::enable(); Display::enable();
} }
void setup() { void setup() {
GP1.write(Command::GP1::Reset()); GP1.write(Command::GP1::Reset());
Screen::configurate(); Screen::configurate();
Screen::exchange_buffer_and_display(); Screen::exchange_buffer_and_display();
GPU::wait_ready_for_CMD(); GPU::wait_ready_for_CMD();
quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height)); quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height));
}
} }
} }

View File

@ -2,94 +2,98 @@
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
namespace SPU { namespace JabyEngine {
static void clear_main_volume() { namespace SPU {
static constexpr auto StartVol = SweepVolume::with(SweepVolume::VolumeEnable, SweepVolume::Volume.with(I16_MAX >> 2)); using namespace JabyEngine;
MainVolume::left.write(StartVol); static void clear_main_volume() {
MainVolume::right.write(StartVol); static constexpr auto StartVol = SweepVolume::with(SweepVolume::VolumeEnable, SweepVolume::Volume.with(I16_MAX >> 2));
}
static void clear_cd_and_ext_audio_volume() { MainVolume::left.write(StartVol);
CDVolume::left.write(0); MainVolume::right.write(StartVol);
CDVolume::right.write(0);
ExternalAudioInputVolume::left.write(0);
ExternalAudioInputVolume::right.write(0);
}
static void clear_control_register() {
Control.write(ControlRegister());
}
static void clear_voice() {
for(auto& voice : Voices) {
voice.volumeLeft.write(SweepVolume());
voice.volumeRight.write(SweepVolume());
voice.sampleRate.write(SampleRate());
voice.ad.write(AD());
voice.sr.write(SR());
voice.currentVolume.write(SimpleVolume(0));
voice.adr.write(0x200);
voice.repeatAdr.write(0x200);
} }
}
static void clear_pmon() { static void clear_cd_and_ext_audio_volume() {
PMON.write(PitchModFlags()); CDVolume::left.write(0);
} CDVolume::right.write(0);
static void clear_noise_and_echo() { ExternalAudioInputVolume::left.write(0);
NON.write(NoiseGenerator()); ExternalAudioInputVolume::right.write(0);
EON.write(EchoOn()); }
}
static void clear_reverb() { static void clear_control_register() {
Reverb::Volume::left.write(0); Control.write(ControlRegister());
Reverb::Volume::right.write(0); }
Reverb::work_area_adr.write(0);
}
static void setup_control_register() { static void clear_voice() {
static constexpr auto SetupValue = ControlRegister::with(ControlRegister::Enable, ControlRegister::Unmute, ControlRegister::CDAudioEnable); for(auto& voice : Voices) {
voice.volumeLeft.write(SweepVolume());
voice.volumeRight.write(SweepVolume());
voice.sampleRate.write(SampleRate());
voice.ad.write(AD());
voice.sr.write(SR());
voice.currentVolume.write(SimpleVolume(0));
Control.write(SetupValue); voice.adr.write(0x200);
} voice.repeatAdr.write(0x200);
static void setup_data_transfer_control() {
static constexpr uint16_t RequiredValue = (2 << 1);
DataTransferControl.write(RequiredValue);
}
static void wait_voices() {
static constexpr int16_t Treshhold = (I16_MAX*0.03);
try_again:
for(const auto& voice : Voices) {
if(voice.currentVolume.read() > Treshhold) {
goto try_again;
} }
} }
}
void stop_voices() { static void clear_pmon() {
Key::off.write(UI32_MAX); PMON.write(PitchModFlags());
} }
void setup() { static void clear_noise_and_echo() {
wait_voices(); NON.write(NoiseGenerator());
EON.write(EchoOn());
}
clear_main_volume(); static void clear_reverb() {
clear_cd_and_ext_audio_volume(); Reverb::Volume::left.write(0);
clear_control_register(); Reverb::Volume::right.write(0);
clear_voice(); Reverb::work_area_adr.write(0);
clear_pmon(); }
clear_noise_and_echo();
clear_reverb();
setup_data_transfer_control(); static void setup_control_register() {
setup_control_register(); static constexpr auto SetupValue = ControlRegister::with(ControlRegister::Enable, ControlRegister::Unmute, ControlRegister::CDAudioEnable);
Control.write(SetupValue);
}
static void setup_data_transfer_control() {
static constexpr uint16_t RequiredValue = (2 << 1);
DataTransferControl.write(RequiredValue);
}
static void wait_voices() {
static constexpr int16_t Treshhold = (I16_MAX*0.03);
try_again:
for(const auto& voice : Voices) {
if(voice.currentVolume.read() > Treshhold) {
goto try_again;
}
}
}
void stop_voices() {
Key::off.write(UI32_MAX);
}
void setup() {
wait_voices();
clear_main_volume();
clear_cd_and_ext_audio_volume();
clear_control_register();
clear_voice();
clear_pmon();
clear_noise_and_echo();
clear_reverb();
setup_data_transfer_control();
setup_control_register();
}
} }
} }

View File

@ -2,21 +2,23 @@
#include <PSX/System/IOPorts/dMa_io.hpp> #include <PSX/System/IOPorts/dMa_io.hpp>
#include <stdio.h> #include <stdio.h>
namespace Setup { namespace JabyEngine {
static void enable_DMA() { namespace Setup {
DMA::DPCR.write(DMA::DPCR.read() | DMA::DMAControlRegister::SPUEnable | DMA::DMAControlRegister::GPUEnable); static void enable_DMA() {
} DMA::DPCR.write(DMA::DPCR.read() | DMA::DMAControlRegister::SPUEnable | DMA::DMAControlRegister::GPUEnable);
}
JabyEngine::NextRoutine start() { JabyEngine::NextRoutine start() {
enable_DMA(); enable_DMA();
SPU::stop_voices(); SPU::stop_voices();
GPU::setup(); GPU::setup();
GPU::display_logo(); GPU::display_logo();
//Pause?? //Pause??
SPU::setup(); SPU::setup();
return BootFile::setup(); return BootFile::setup();
}
} }
} }

View File

@ -3,24 +3,25 @@
#define private public #define private public
#include <PSX/File/Processor/file_processor.hpp> #include <PSX/File/Processor/file_processor.hpp>
namespace FileProcessor { namespace JabyEngine {
namespace Helper { namespace FileProcessor {
template<typename T> namespace Helper {
static void simple_read(T& dst, State::Configuration& config) { template<typename T>
static constexpr size_t UINT32_SIZE = (sizeof(T)/sizeof(uint32_t)); static void simple_read(T& dst, State::Configuration& config) {
static constexpr size_t UINT32_SIZE = (sizeof(T)/sizeof(uint32_t));
dst = *reinterpret_cast<const T*>(config.data_adr); dst = *reinterpret_cast<const T*>(config.data_adr);
config.processed(UINT32_SIZE); config.processed(UINT32_SIZE);
static_assert((UINT32_SIZE*sizeof(uint32_t)) == sizeof(T)); static_assert((UINT32_SIZE*sizeof(uint32_t)) == sizeof(T));
} }
template<typename T> template<typename T>
static bool exchange_and_execute_process_function(bool (*process_routine)(State::Configuration&, T&), State::Configuration& config, T& state) { static bool exchange_and_execute_process_function(bool (*process_routine)(State::Configuration&, T&), State::Configuration& config, T& state) {
config.process_routine = reinterpret_cast<State::ProcessRoutine>(process_routine); config.process_routine = reinterpret_cast<State::ProcessRoutine>(process_routine);
return process_routine(config, state); return process_routine(config, state);
}
} }
} }
} }
#endif // !__JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__ #endif // !__JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__

View File

@ -3,129 +3,130 @@
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
namespace FileProcessor { namespace JabyEngine {
using GPU::PositionU16; namespace FileProcessor {
using GPU::SizeU16; using GPU::PositionU16;
using GPU::SizeU16;
struct SimpleTIMSize : private SimpleTIM { struct SimpleTIMSize : private SimpleTIM {
constexpr SimpleTIMSize() { constexpr SimpleTIMSize() {
}
constexpr uint16_t getTextureWidth() const {
return SimpleTIM::getTextureX();
}
constexpr uint16_t getTextureHeight() const {
return SimpleTIM::getTextureY();
}
constexpr uint16_t getClutWidth() const {
return SimpleTIM::getClutX();
}
constexpr uint16_t getClutHeight() const {
return SimpleTIM::getClutY();
}
};
struct SimpleTIMState {
SimpleTIM dst_info;
SimpleTIMSize size_info;
size_t words_left; //32bit values
constexpr SimpleTIMState(const SimpleTIM& dst_info) : dst_info(dst_info) {
}
};
static void set_gpu_receive(const uint32_t* src, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
GPU::DMA::Receive::prepare();
GPU::DMA::Receive::set_dst(PositionU16(x, y), SizeU16(w, h));
GPU::DMA::Receive::set_src(reinterpret_cast<const uintptr_t>(src));
} }
constexpr uint16_t getTextureWidth() const { static void set_gpu_receive_data(const uint32_t* src, SimpleTIMState& state, uint16_t width, uint16_t height) {
return SimpleTIM::getTextureX(); state.words_left = (width*height)/2;
set_gpu_receive(src, state.dst_info.getTextureX(), state.dst_info.getTextureY(), width, height);
} }
constexpr uint16_t getTextureHeight() const { static bool parse_data(State::Configuration& config, SimpleTIMState& state) {
return SimpleTIM::getTextureY(); const auto words_to_use = (config.data_word_size > state.words_left) ? state.words_left : config.data_word_size;
} bool is_last = (words_to_use == state.words_left);
auto block_count = (words_to_use >> 4);
constexpr uint16_t getClutWidth() const { while(block_count > 0) {
return SimpleTIM::getClutX(); const auto block_send = (block_count > UI16_MAX) ? UI16_MAX : block_count;
}
constexpr uint16_t getClutHeight() const { // Send data!
return SimpleTIM::getClutY();
}
};
struct SimpleTIMState {
SimpleTIM dst_info;
SimpleTIMSize size_info;
size_t words_left; //32bit values
constexpr SimpleTIMState(const SimpleTIM& dst_info) : dst_info(dst_info) {
}
};
static void set_gpu_receive(const uint32_t* src, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
GPU::DMA::Receive::prepare();
GPU::DMA::Receive::set_dst(PositionU16(x, y), SizeU16(w, h));
GPU::DMA::Receive::set_src(reinterpret_cast<const uintptr_t>(src));
}
static void set_gpu_receive_data(const uint32_t* src, SimpleTIMState& state, uint16_t width, uint16_t height) {
state.words_left = (width*height)/2;
set_gpu_receive(src, state.dst_info.getTextureX(), state.dst_info.getTextureY(), width, height);
}
static bool parse_data(State::Configuration& config, SimpleTIMState& state) {
const auto words_to_use = (config.data_word_size > state.words_left) ? state.words_left : config.data_word_size;
bool is_last = (words_to_use == state.words_left);
auto block_count = (words_to_use >> 4);
while(block_count > 0) {
const auto block_send = (block_count > UI16_MAX) ? UI16_MAX : block_count;
// Send data!
GPU::DMA::wait();
GPU::DMA::Receive::start(block_send);
block_count -= block_send;
}
if(is_last) {
// Send words
const auto last_words = (words_to_use & 0b1111);
if(last_words > 0) {
GPU::DMA::wait(); GPU::DMA::wait();
GPU::DMA::Receive::start(1, last_words); GPU::DMA::Receive::start(block_send);
block_count -= block_send;
} }
GPU::DMA::wait(); if(is_last) {
GPU::DMA::end(); // Send words
const auto last_words = (words_to_use & 0b1111);
if(last_words > 0) {
GPU::DMA::wait();
GPU::DMA::Receive::start(1, last_words);
}
state.words_left = 0; GPU::DMA::wait();
config.processed(words_to_use); GPU::DMA::end();
return false; state.words_left = 0;
} config.processed(words_to_use);
else { return false;
const auto words_used = (words_to_use & ~0b1111); }
state.words_left -= words_used; else {
config.processed(words_used); const auto words_used = (words_to_use & ~0b1111);
return true;
} state.words_left -= words_used;
} config.processed(words_used);
return true;
static bool switch_state_parse_data(State::Configuration& config, SimpleTIMState& state) { }
set_gpu_receive_data(config.data_adr, state, state.size_info.getTextureWidth(), state.size_info.getTextureHeight()); }
return Helper::exchange_and_execute_process_function(parse_data, config, state);
} static bool switch_state_parse_data(State::Configuration& config, SimpleTIMState& state) {
set_gpu_receive_data(config.data_adr, state, state.size_info.getTextureWidth(), state.size_info.getTextureHeight());
static bool parse_clut(State::Configuration& config, SimpleTIMState& state) { return Helper::exchange_and_execute_process_function(parse_data, config, state);
if(parse_data(config, state)) { }
return true;
} static bool parse_clut(State::Configuration& config, SimpleTIMState& state) {
if(parse_data(config, state)) {
else { return true;
return switch_state_parse_data(config, state);
}
}
static bool parse_header(State::Configuration& config, SimpleTIMState& state) {
if(config.data_word_size >= (sizeof(SimpleTIMSize)/sizeof(uint32_t))) {
Helper::simple_read(state.size_info, config);
//Check if we have a clut to care about
if(state.size_info.getClutWidth() > 0) {
//CLUTs are 16bit full color anyway
set_gpu_receive_data(config.data_adr, state, state.size_info.getClutWidth(), state.size_info.getClutHeight());
return Helper::exchange_and_execute_process_function(parse_clut, config, state);
} }
//We have direct data
else { else {
return switch_state_parse_data(config, state); return switch_state_parse_data(config, state);
} }
} }
return true; static bool parse_header(State::Configuration& config, SimpleTIMState& state) {
} if(config.data_word_size >= (sizeof(SimpleTIMSize)/sizeof(uint32_t))) {
Helper::simple_read(state.size_info, config);
State create(const uint32_t* data_adr, const SimpleTIM& file) { //Check if we have a clut to care about
return State::from(SimpleTIMState(file), data_adr, parse_header); if(state.size_info.getClutWidth() > 0) {
//CLUTs are 16bit full color anyway
set_gpu_receive_data(config.data_adr, state, state.size_info.getClutWidth(), state.size_info.getClutHeight());
return Helper::exchange_and_execute_process_function(parse_clut, config, state);
}
//We have direct data
else {
return switch_state_parse_data(config, state);
}
}
return true;
}
State create(const uint32_t* data_adr, const SimpleTIM& file) {
return State::from(SimpleTIMState(file), data_adr, parse_header);
}
} }
} }
#undef private #undef private

View File

@ -1,36 +1,38 @@
#include "../include/GPU/gpu.hpp" #include "../include/GPU/gpu.hpp"
namespace GPU { namespace JabyEngine {
namespace Screen { namespace GPU {
uint8_t CurrentDisplayAreaID = 1; //< Setup will call exchange and set it to 0 namespace Screen {
uint8_t CurrentDisplayAreaID = 1; //< Setup will call exchange and set it to 0
namespace Range { namespace Range {
#ifdef JABYENGINE_PAL #ifdef JABYENGINE_PAL
static constexpr uint16_t ScanlinesV = 288; static constexpr uint16_t ScanlinesV = 288;
#else #else
static constexpr uint16_t ScanlinesV = 240; static constexpr uint16_t ScanlinesV = 240;
#endif //JABYENGINE_PAL #endif //JABYENGINE_PAL
#ifndef USE_NO$PSX #ifndef USE_NO$PSX
void set_offset(uint16_t x, uint16_t y) { void set_offset(uint16_t x, uint16_t y) {
x += 78; x += 78;
y += 43; y += 43;
GP1.write(Command::GP1::HorizontalDisplayRange((x << 3), (x + Display::Width) << 3)); GP1.write(Command::GP1::HorizontalDisplayRange((x << 3), (x + Display::Width) << 3));
GP1.write(Command::GP1::VerticalDisplayRange(y, y + Display::Height)); GP1.write(Command::GP1::VerticalDisplayRange(y, y + Display::Height));
} }
#else #else
void set_offset(uint16_t x, uint16_t y) { void set_offset(uint16_t x, uint16_t y) {
GP1.write(Command::GP1::HorizontalDisplayRange(x, (x + Display::Width*8))); GP1.write(Command::GP1::HorizontalDisplayRange(x, (x + Display::Width*8)));
GP1.write(Command::GP1::VerticalDisplayRange(y - (ScanlinesV/2), y + (ScanlinesV/2))); GP1.write(Command::GP1::VerticalDisplayRange(y - (ScanlinesV/2), y + (ScanlinesV/2)));
} }
#endif //USE_NO$PSX #endif //USE_NO$PSX
} }
void exchange_buffer_and_display() { void exchange_buffer_and_display() {
GPU::set_draw_area(0, (Display::Height*CurrentDisplayAreaID)); GPU::set_draw_area(0, (Display::Height*CurrentDisplayAreaID));
CurrentDisplayAreaID ^= 1; CurrentDisplayAreaID ^= 1;
GP1.write(Command::GP1::DisplayArea(0, (Display::Height*CurrentDisplayAreaID))); GP1.write(Command::GP1::DisplayArea(0, (Display::Height*CurrentDisplayAreaID)));
}
} }
} }
} }