Introduce the JabyEngine namespace to all files
This commit is contained in:
parent
791fe85ab8
commit
def6c6d3b9
|
@ -2,53 +2,55 @@
|
|||
#define __JABYENGINE_BITS_HPP__
|
||||
#include "../jabyengine_defines.h"
|
||||
|
||||
namespace bit {
|
||||
template<typename T>
|
||||
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 {
|
||||
namespace JabyEngine {
|
||||
namespace bit {
|
||||
template<typename T>
|
||||
static constexpr T crop_value(T raw_value, size_t length) {
|
||||
return (raw_value & ((1 << length) - 1));
|
||||
static constexpr T set(T raw_value, size_t bit) {
|
||||
return (raw_value | (1 << bit));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T range_mask(size_t start_bit, size_t length) {
|
||||
return (((1 << length) - 1) << start_bit);
|
||||
static constexpr T clear(T raw_value, size_t bit) {
|
||||
return (raw_value & ~(1 << 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));
|
||||
static constexpr bool is_set(T raw_value, size_t bit) {
|
||||
return static_cast<bool>(raw_value & (1 << bit));
|
||||
}
|
||||
|
||||
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));
|
||||
namespace value {
|
||||
template<typename T>
|
||||
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>
|
||||
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 S, typename T>
|
||||
static constexpr S cast(T value) {
|
||||
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)
|
||||
|
|
|
@ -2,194 +2,196 @@
|
|||
#define __JABYENGINE_COMPLEX_BITMAP_HPP__
|
||||
#include "bits.hpp"
|
||||
|
||||
struct ClearBitValue {
|
||||
size_t bit;
|
||||
namespace JabyEngine {
|
||||
struct ClearBitValue {
|
||||
size_t bit;
|
||||
|
||||
constexpr ClearBitValue(size_t bit) : bit(bit) {
|
||||
}
|
||||
};
|
||||
constexpr ClearBitValue(size_t bit) : bit(bit) {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Bit {
|
||||
typedef T ValueType;
|
||||
template<typename T>
|
||||
struct Bit {
|
||||
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 {
|
||||
return this->value;
|
||||
}
|
||||
template<typename T>
|
||||
class ComplexBitMap {
|
||||
public:
|
||||
T raw;
|
||||
|
||||
constexpr ClearBitValue operator!() const {
|
||||
return ClearBitValue(this->value);
|
||||
}
|
||||
};
|
||||
private:
|
||||
template<typename S>
|
||||
constexpr __always_inline ComplexBitMap<T>& set_va(const S& value) {
|
||||
return this->set(value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct BitRangeValue {
|
||||
T value;
|
||||
size_t begin;
|
||||
size_t length;
|
||||
};
|
||||
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...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct BitRange {
|
||||
typedef T ValueType;
|
||||
public:
|
||||
template<typename...ARGS>
|
||||
static constexpr __always_inline ComplexBitMap<T> with(ARGS...args) {
|
||||
return ComplexBitMap().set_va(args...);
|
||||
}
|
||||
|
||||
size_t begin;
|
||||
size_t length;
|
||||
//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;
|
||||
}
|
||||
|
||||
static constexpr BitRange<T> from_to(size_t start, size_t end) {
|
||||
return {start, (end - start + 1)};
|
||||
}
|
||||
template<typename S>
|
||||
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 {
|
||||
return {value, this->begin, this->length};
|
||||
}
|
||||
};
|
||||
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 T>
|
||||
static constexpr __always_inline BitRangeValue<T> operator<<(const BitRange<T>& range, T value) {
|
||||
return BitRangeValue{value, range.begin, range.length};
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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__
|
|
@ -3,30 +3,32 @@
|
|||
#include "../cd_file_types.hpp"
|
||||
#include "file_processor.hpp"
|
||||
|
||||
namespace CDFileProcessor {
|
||||
class State {
|
||||
private:
|
||||
FileProcessor::State file_processor_state;
|
||||
const uint32_t* data_adr;
|
||||
namespace JabyEngine {
|
||||
namespace CDFileProcessor {
|
||||
class State {
|
||||
private:
|
||||
FileProcessor::State file_processor_state;
|
||||
const uint32_t* data_adr;
|
||||
|
||||
public:
|
||||
State() = default;
|
||||
public:
|
||||
State() = default;
|
||||
|
||||
void setup(uint16_t lba, uint16_t size, const CDFile::Payload& payload);
|
||||
bool process();
|
||||
};
|
||||
void setup(uint16_t lba, uint16_t size, const CDFile::Payload& payload);
|
||||
bool process();
|
||||
};
|
||||
|
||||
template<size_t Size>
|
||||
static void load_from_cd(const OverlayLBA* overlay_lbas, const CDFile (&cd_files)[Size]) {
|
||||
State state;
|
||||
template<size_t Size>
|
||||
static void load_from_cd(const OverlayLBA* overlay_lbas, const CDFile (&cd_files)[Size]) {
|
||||
State state;
|
||||
|
||||
for(const auto& file : cd_files) {
|
||||
const auto& lba_info = overlay_lbas[file.rel_lba_idx];
|
||||
for(const auto& file : cd_files) {
|
||||
const auto& lba_info = overlay_lbas[file.rel_lba_idx];
|
||||
|
||||
state.setup(lba_info.lba, lba_info.size, file.payload);
|
||||
//while(state.process());???
|
||||
}
|
||||
}
|
||||
state.setup(lba_info.lba, lba_info.size, file.payload);
|
||||
//while(state.process());???
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This will be used as the file processor but will work on cd types
|
||||
|
|
|
@ -2,50 +2,51 @@
|
|||
#define __JABYENGINE_FILE_PROCESSOR_HPP__
|
||||
#include "../file_types.hpp"
|
||||
|
||||
namespace FileProcessor {
|
||||
class State {
|
||||
private:
|
||||
struct Reserved {
|
||||
uint32_t reserved[4];
|
||||
};
|
||||
namespace JabyEngine {
|
||||
namespace FileProcessor {
|
||||
class State {
|
||||
private:
|
||||
struct Reserved {
|
||||
uint32_t reserved[4];
|
||||
};
|
||||
|
||||
struct Configuration;
|
||||
typedef bool (*ProcessRoutine)(Configuration&, Reserved&);
|
||||
struct Configuration;
|
||||
typedef bool (*ProcessRoutine)(Configuration&, Reserved&);
|
||||
|
||||
struct Configuration {
|
||||
ProcessRoutine process_routine = nullptr;
|
||||
const uint32_t* data_adr = nullptr;
|
||||
size_t data_word_size = 0ull;
|
||||
struct Configuration {
|
||||
ProcessRoutine process_routine = nullptr;
|
||||
const uint32_t* data_adr = nullptr;
|
||||
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>
|
||||
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&), const uint32_t* data_adr) {
|
||||
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
|
||||
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));
|
||||
}
|
||||
|
||||
constexpr void processed(size_t words) {
|
||||
this->data_adr += words;
|
||||
this->data_word_size -= words;
|
||||
|
||||
public:
|
||||
bool process(size_t word_size) {
|
||||
this->config.data_word_size += word_size;
|
||||
return (*this->config.process_routine)(this->config, this->reserved);
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
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);
|
||||
State create(const uint32_t* data_adr, const SimpleTIM& file);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !__JABYENGINE_FILE_PROCESSOR_HPP__
|
|
@ -3,25 +3,27 @@
|
|||
#include "../Overlay/overlay.hpp"
|
||||
#include "file_types.hpp"
|
||||
|
||||
enum struct CDFileType : uint8_t {
|
||||
SimpleTIM = 0,
|
||||
Custom
|
||||
};
|
||||
|
||||
struct __no_align CDFile {
|
||||
union __no_align Payload {
|
||||
uint32_t empty;
|
||||
SimpleTIM simple_tim;
|
||||
namespace JabyEngine {
|
||||
enum struct CDFileType : uint8_t {
|
||||
SimpleTIM = 0,
|
||||
Custom
|
||||
};
|
||||
|
||||
uint8_t rel_lba_idx;
|
||||
CDFileType type;
|
||||
Payload payload;
|
||||
};
|
||||
struct __no_align CDFile {
|
||||
union __no_align Payload {
|
||||
uint32_t empty;
|
||||
SimpleTIM simple_tim;
|
||||
};
|
||||
|
||||
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}};
|
||||
uint8_t rel_lba_idx;
|
||||
CDFileType type;
|
||||
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__
|
|
@ -3,35 +3,35 @@
|
|||
#include "../Auxiliary/complex_bitmap.hpp"
|
||||
#include "../jabyengine_defines.h"
|
||||
|
||||
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);
|
||||
static constexpr auto ClutY = BitRange<uint32_t>(23, 31);
|
||||
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);
|
||||
static constexpr auto ClutY = BitRange<uint32_t>(23, 31);
|
||||
|
||||
constexpr SimpleTIM() {
|
||||
this->raw = 0;
|
||||
}
|
||||
constexpr SimpleTIM() {
|
||||
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 {
|
||||
return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::TextureX) << 1);
|
||||
}
|
||||
constexpr uint16_t getTextureX() const {
|
||||
return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::TextureX) << 1);
|
||||
}
|
||||
|
||||
constexpr uint16_t getTextureY() const {
|
||||
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 getTextureY() const {
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // !__JABYENGINE_FILE_TYPES_HPP__
|
|
@ -10,32 +10,33 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
namespace GPU {
|
||||
namespace Display {
|
||||
#ifdef JABYENGINE_PAL
|
||||
static constexpr size_t Width = 320;
|
||||
static constexpr size_t Height = 256;
|
||||
#else
|
||||
static constexpr size_t Width = 320;
|
||||
static constexpr size_t Height = 240;
|
||||
#endif
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
namespace Display {
|
||||
#ifdef JABYENGINE_PAL
|
||||
static constexpr size_t Width = 320;
|
||||
static constexpr size_t Height = 256;
|
||||
#else
|
||||
static constexpr size_t Width = 320;
|
||||
static constexpr size_t Height = 240;
|
||||
#endif
|
||||
|
||||
static void enable() {
|
||||
GP1.write(Command::GP1::SetDisplayState(DisplayState::On));
|
||||
static void enable() {
|
||||
GP1.write(Command::GP1::SetDisplayState(DisplayState::On));
|
||||
}
|
||||
|
||||
static void disable() {
|
||||
GP1.write(Command::GP1::SetDisplayState(DisplayState::Off));
|
||||
}
|
||||
}
|
||||
|
||||
static void disable() {
|
||||
GP1.write(Command::GP1::SetDisplayState(DisplayState::Off));
|
||||
}
|
||||
}
|
||||
namespace Screen {
|
||||
extern uint8_t CurrentDisplayAreaID;
|
||||
|
||||
namespace Screen {
|
||||
extern uint8_t CurrentDisplayAreaID;
|
||||
|
||||
namespace Range {
|
||||
void set_offset(uint16_t x, uint16_t y);
|
||||
namespace Range {
|
||||
void set_offset(uint16_t x, uint16_t y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //!__JABYENGINE_GPU_HPP__
|
|
@ -3,100 +3,101 @@
|
|||
#include "../jabyengine_defines.h"
|
||||
#include "../Auxiliary/complex_bitmap.hpp"
|
||||
|
||||
namespace GPU {
|
||||
struct Color24 {
|
||||
uint8_t red = 0;
|
||||
uint8_t green = 0;
|
||||
uint8_t blue = 0;
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
struct Color24 {
|
||||
uint8_t red = 0;
|
||||
uint8_t green = 0;
|
||||
uint8_t blue = 0;
|
||||
|
||||
constexpr Color24() = default;
|
||||
constexpr Color24(uint8_t r, uint8_t g, uint8_t b) : blue(b), green(g), red(r) {
|
||||
}
|
||||
constexpr Color24() = default;
|
||||
constexpr Color24(uint8_t r, uint8_t g, uint8_t b) : blue(b), green(g), red(r) {
|
||||
}
|
||||
|
||||
constexpr uint32_t raw() const {
|
||||
return ((this->blue << 16) | (this->green << 8) | this->red);
|
||||
}
|
||||
constexpr uint32_t raw() const {
|
||||
return ((this->blue << 16) | (this->green << 8) | this->red);
|
||||
}
|
||||
|
||||
static constexpr Color24 Black() {
|
||||
return Color24(0, 0, 0);
|
||||
}
|
||||
static constexpr Color24 Black() {
|
||||
return Color24(0, 0, 0);
|
||||
}
|
||||
|
||||
static constexpr Color24 White() {
|
||||
return Color24(0xFF, 0xFF, 0xFF);
|
||||
}
|
||||
static constexpr Color24 White() {
|
||||
return Color24(0xFF, 0xFF, 0xFF);
|
||||
}
|
||||
|
||||
static constexpr Color24 Red() {
|
||||
return Color24(0xFF, 0x0, 0x0);
|
||||
}
|
||||
static constexpr Color24 Red() {
|
||||
return Color24(0xFF, 0x0, 0x0);
|
||||
}
|
||||
|
||||
static constexpr Color24 Green() {
|
||||
return Color24(0x0, 0xFF, 0x0);
|
||||
}
|
||||
static constexpr Color24 Green() {
|
||||
return Color24(0x0, 0xFF, 0x0);
|
||||
}
|
||||
|
||||
static constexpr Color24 Blue() {
|
||||
return Color24(0x0, 0x0, 0xFF);
|
||||
}
|
||||
};
|
||||
static constexpr Color24 Blue() {
|
||||
return Color24(0x0, 0x0, 0xFF);
|
||||
}
|
||||
};
|
||||
|
||||
class Color {
|
||||
private:
|
||||
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 BlueRange = BitRange<uint16_t>::from_to(10, 14);
|
||||
static constexpr auto SemiTransperancyBit = Bit<uint16_t>(15);
|
||||
class Color {
|
||||
private:
|
||||
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 BlueRange = BitRange<uint16_t>::from_to(10, 14);
|
||||
static constexpr auto SemiTransperancyBit = Bit<uint16_t>(15);
|
||||
|
||||
ComplexBitMap<uint16_t> value = {0};
|
||||
ComplexBitMap<uint16_t> value = {0};
|
||||
|
||||
public:
|
||||
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);
|
||||
}
|
||||
public:
|
||||
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);
|
||||
}
|
||||
|
||||
static constexpr Color from(const Color24& color) {
|
||||
return Color::from_rgb(color.red, color.green, color.blue);
|
||||
}
|
||||
static constexpr Color from(const Color24& color) {
|
||||
return Color::from_rgb(color.red, color.green, color.blue);
|
||||
}
|
||||
|
||||
constexpr Color& set_red(uint8_t red) {
|
||||
this->value.set_value(static_cast<uint16_t>(red), RedRange);
|
||||
return *this;
|
||||
}
|
||||
constexpr Color& set_red(uint8_t red) {
|
||||
this->value.set_value(static_cast<uint16_t>(red), RedRange);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Color& set_green(uint8_t green) {
|
||||
this->value.set_value(static_cast<uint16_t>(green), GreenRange);
|
||||
return *this;
|
||||
}
|
||||
constexpr Color& set_green(uint8_t green) {
|
||||
this->value.set_value(static_cast<uint16_t>(green), GreenRange);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Color& set_blue(uint8_t blue) {
|
||||
this->value.set_value(static_cast<uint16_t>(blue), BlueRange);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
constexpr Color& set_blue(uint8_t blue) {
|
||||
this->value.set_value(static_cast<uint16_t>(blue), BlueRange);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Position {
|
||||
T x = 0;
|
||||
T y = 0;
|
||||
template<typename T>
|
||||
struct Position {
|
||||
T x = 0;
|
||||
T y = 0;
|
||||
|
||||
constexpr Position() = default;
|
||||
constexpr Position(T x, T y) : x(x), y(y) {
|
||||
}
|
||||
};
|
||||
constexpr Position() = default;
|
||||
constexpr Position(T x, T y) : x(x), y(y) {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Size {
|
||||
T width = 0;
|
||||
T height = 0;
|
||||
template<typename T>
|
||||
struct Size {
|
||||
T width = 0;
|
||||
T height = 0;
|
||||
|
||||
constexpr Size() = default;
|
||||
constexpr Size(T w, T h) : width(w), height(h) {
|
||||
}
|
||||
};
|
||||
constexpr Size() = default;
|
||||
constexpr Size(T w, T h) : width(w), height(h) {
|
||||
}
|
||||
};
|
||||
|
||||
typedef Position<int16_t> PositionI16;
|
||||
typedef Position<uint16_t> PositionU16;
|
||||
typedef Position<int16_t> PositionI16;
|
||||
typedef Position<uint16_t> PositionU16;
|
||||
|
||||
typedef Size<int16_t> SizeI16;
|
||||
typedef Size<uint16_t> SizeU16;
|
||||
typedef Size<int16_t> SizeI16;
|
||||
typedef Size<uint16_t> SizeU16;
|
||||
}
|
||||
}
|
||||
|
||||
#endif //!__JABYENGINE_GPU_TYPES_HPP__
|
|
@ -2,14 +2,16 @@
|
|||
#define __JABYENGINE_OVERLAY__HPP__
|
||||
#include "../../stdint.h"
|
||||
|
||||
struct __attribute__((packed)) OverlayHeader {
|
||||
void (*execute)();
|
||||
uint16_t lba_size;
|
||||
};
|
||||
namespace JabyEngine {
|
||||
struct __attribute__((packed)) OverlayHeader {
|
||||
void (*execute)();
|
||||
uint16_t lba_size;
|
||||
};
|
||||
|
||||
// Maybe encode attributes like "isLZ4" into size parameter
|
||||
struct __attribute__((packed)) OverlayLBA {
|
||||
uint16_t lba;
|
||||
uint16_t size;
|
||||
};
|
||||
// Maybe encode attributes like "isLZ4" into size parameter
|
||||
struct __attribute__((packed)) OverlayLBA {
|
||||
uint16_t lba;
|
||||
uint16_t size;
|
||||
};
|
||||
}
|
||||
#endif //!__JABYENGINE_OVERLAY__HPP__
|
|
@ -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__
|
|
@ -2,143 +2,144 @@
|
|||
#define __JABYENGINE_DMA_IO_HPP__
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace DMA {
|
||||
struct __no_align MADR : public ComplexBitMap<uint32_t> {
|
||||
__io_port_inherit_complex_bit_map(MADR);
|
||||
namespace JabyEngine {
|
||||
namespace DMA {
|
||||
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);
|
||||
};
|
||||
|
||||
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);
|
||||
static constexpr auto MemoryAdr = BitRange<uint32_t>::from_to(0, 23);
|
||||
};
|
||||
|
||||
struct __no_align SyncMode1 : public ComplexBitMap<uint32_t> {
|
||||
__io_port_inherit_complex_bit_map(SyncMode1);
|
||||
struct __no_align BCR : public ComplexBitMap<uint32_t> {
|
||||
__io_port_inherit_complex_bit_map(BCR);
|
||||
|
||||
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 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> {
|
||||
__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> {
|
||||
__io_port_inherit_complex_bit_map(CHCHR);
|
||||
enum _SyncMode {
|
||||
Sync0 = 0, //Start immediately,
|
||||
Sync1 = 1, //Sync blocks to DMA requests
|
||||
Sync2 = 2, //Linked List
|
||||
};
|
||||
|
||||
enum _SyncMode {
|
||||
Sync0 = 0, //Start immediately,
|
||||
Sync1 = 1, //Sync blocks to DMA requests
|
||||
Sync2 = 2, //Linked List
|
||||
static constexpr auto ManualStart = Bit<uint32_t>(28);
|
||||
|
||||
static constexpr auto Start = Bit<uint32_t>(24);
|
||||
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);
|
||||
static constexpr auto Busy = Start;
|
||||
//0: Highest, 7: Lowest
|
||||
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);
|
||||
static constexpr auto ChoppingDMAWindowSize = BitRange<uint32_t>::from_to(16, 18);
|
||||
struct __no_align DMAControlRegister : public ComplexBitMap<uint32_t> {
|
||||
__io_port_inherit_complex_bit_map(DMAControlRegister);
|
||||
|
||||
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 OTCEnable = Bit<uint32_t>(27);
|
||||
static constexpr auto OTCPriority = BitRange<Priority>::from_to(24, 26);
|
||||
|
||||
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 MemoryAdrIncreaseBy4 = !MemoryAdrDecreaseBy4;
|
||||
static constexpr auto SPUEnable = Bit<uint32_t>(19);
|
||||
static constexpr auto SPUPriority = BitRange<Priority>::from_to(16, 18);
|
||||
|
||||
static constexpr auto FromMainRAM = Bit<uint32_t>(0);
|
||||
static constexpr auto ToMainRAM = !FromMainRAM;
|
||||
static constexpr auto CDROMEnable = Bit<uint32_t>(15);
|
||||
static constexpr auto CDROMPriority = BitRange<Priority>::from_to(12, 14);
|
||||
|
||||
static constexpr CHCHR StartMDECin() {
|
||||
return ComplexBitMap{0x01000201};
|
||||
}
|
||||
static constexpr auto GPUEnable = Bit<uint32_t>(11);
|
||||
static constexpr auto GPUPriority = BitRange<Priority>::from_to(8, 10);
|
||||
|
||||
static constexpr CHCHR StartMDECout() {
|
||||
return ComplexBitMap{0x01000200};
|
||||
}
|
||||
static constexpr auto MDECoutEnable = Bit<uint32_t>(7);
|
||||
static constexpr auto MDECoutPriority = BitRange<Priority>::from_to(4, 6);
|
||||
|
||||
static constexpr CHCHR StartGPUReceive() {
|
||||
return ComplexBitMap{0x01000201};
|
||||
}
|
||||
static constexpr auto MDECinEnable = Bit<uint32_t>(3);
|
||||
static constexpr auto MDECinPriority = BitRange<Priority>::from_to(0, 2);
|
||||
};
|
||||
|
||||
static constexpr CHCHR StartCDROM() {
|
||||
return ComplexBitMap{0x11000000};
|
||||
}
|
||||
struct __no_align DMAInterruptRegister : public ComplexBitMap<uint32_t> {
|
||||
__io_port_inherit_complex_bit_map(DMAInterruptRegister);
|
||||
|
||||
static constexpr CHCHR StartSPUReceive() {
|
||||
return ComplexBitMap{0x01000201};
|
||||
}
|
||||
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);
|
||||
};
|
||||
|
||||
static constexpr CHCHR StartOTC() {
|
||||
return ComplexBitMap{0x11000002};
|
||||
}
|
||||
};
|
||||
__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);
|
||||
|
||||
struct __no_align Registers {
|
||||
IOPort<MADR> adr;
|
||||
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);
|
||||
__declare_io_port_global(DMAControlRegister, DPCR, 0x1F8010F0);
|
||||
__declare_io_port_global(DMAInterruptRegister, DICR, 0x1F8010F4);
|
||||
}
|
||||
}
|
||||
|
||||
#endif //!__JABYENGINE_DMA_IO_HPP__
|
|
@ -3,170 +3,171 @@
|
|||
#include "ioport.hpp"
|
||||
#include "../../GPU/gpu_types.hpp"
|
||||
|
||||
namespace GPU {
|
||||
enum struct SemiTransparency {
|
||||
B_Half_add_F_Half = 0,
|
||||
B_add_F = 1,
|
||||
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)};
|
||||
}
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
enum struct SemiTransparency {
|
||||
B_Half_add_F_Half = 0,
|
||||
B_add_F = 1,
|
||||
B_sub_F = 2,
|
||||
B_add_F_Quarter = 3,
|
||||
};
|
||||
|
||||
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)};
|
||||
}
|
||||
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> {
|
||||
__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__
|
|
@ -2,80 +2,81 @@
|
|||
#define __JABYENGINE_IOPORT_HPP__
|
||||
#include "../../Auxiliary/complex_bitmap.hpp"
|
||||
|
||||
template<typename T>
|
||||
class __no_align IOPort {
|
||||
private:
|
||||
T value;
|
||||
namespace JabyEngine {
|
||||
template<typename T>
|
||||
class __no_align IOPort {
|
||||
private:
|
||||
T value;
|
||||
|
||||
public:
|
||||
//For easy access
|
||||
constexpr T read() const {
|
||||
return const_cast<volatile IOPort<T>*>(this)->value;
|
||||
}
|
||||
public:
|
||||
//For easy access
|
||||
constexpr T read() const {
|
||||
return const_cast<volatile IOPort<T>*>(this)->value;
|
||||
}
|
||||
|
||||
constexpr void write(T value) {
|
||||
const_cast<volatile IOPort<T>*>(this)->value = value;
|
||||
}
|
||||
constexpr void write(T value) {
|
||||
const_cast<volatile IOPort<T>*>(this)->value = value;
|
||||
}
|
||||
|
||||
constexpr volatile T& ref() {
|
||||
return const_cast<volatile IOPort<T>*>(this)->value;
|
||||
}
|
||||
constexpr volatile T& ref() {
|
||||
return const_cast<volatile IOPort<T>*>(this)->value;
|
||||
}
|
||||
|
||||
constexpr const volatile T& ref() const {
|
||||
return const_cast<volatile IOPort<T>*>(this)->value;
|
||||
}
|
||||
};
|
||||
constexpr const volatile T& ref() const {
|
||||
return const_cast<volatile IOPort<T>*>(this)->value;
|
||||
}
|
||||
};
|
||||
|
||||
struct __no_align ubus32_t {
|
||||
ComplexBitMap<uint16_t> low;
|
||||
ComplexBitMap<uint16_t> high;
|
||||
struct __no_align ubus32_t {
|
||||
ComplexBitMap<uint16_t> low;
|
||||
ComplexBitMap<uint16_t> high;
|
||||
|
||||
constexpr ubus32_t(uint32_t value) {
|
||||
*this = value;
|
||||
}
|
||||
constexpr ubus32_t(uint32_t value) {
|
||||
*this = value;
|
||||
}
|
||||
|
||||
constexpr operator uint32_t() const {
|
||||
return ((this->high.raw << 16) | this->low.raw);
|
||||
}
|
||||
constexpr operator uint32_t() const {
|
||||
return ((this->high.raw << 16) | this->low.raw);
|
||||
}
|
||||
|
||||
operator uint32_t() const volatile {
|
||||
return ((this->high.raw << 16) | this->low.raw);
|
||||
}
|
||||
operator uint32_t() const volatile {
|
||||
return ((this->high.raw << 16) | this->low.raw);
|
||||
}
|
||||
|
||||
constexpr ubus32_t& operator=(uint32_t value) {
|
||||
this->low.raw = (value & 0xFFFF);
|
||||
this->high.raw = (value >> 16);
|
||||
constexpr ubus32_t& operator=(uint32_t value) {
|
||||
this->low.raw = (value & 0xFFFF);
|
||||
this->high.raw = (value >> 16);
|
||||
|
||||
return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr void operator=(uint32_t value) volatile {
|
||||
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;
|
||||
constexpr void operator=(uint32_t value) volatile {
|
||||
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;
|
||||
|
||||
#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 __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 __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) \
|
||||
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__
|
|
@ -2,168 +2,169 @@
|
|||
#define __JABYENGINE_SPU_IO_HPP__
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace SPU {
|
||||
enum struct Mode {
|
||||
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
|
||||
namespace JabyEngine {
|
||||
namespace SPU {
|
||||
enum struct Mode {
|
||||
Linear = 0,
|
||||
Exponential = 1,
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
enum struct Direction {
|
||||
Increase = 0,
|
||||
Decrease = 1,
|
||||
};
|
||||
|
||||
struct __no_align PitchModFlags : public ComplexBitMap<uint16_t> {
|
||||
__io_port_inherit_complex_bit_map(PitchModFlags);
|
||||
enum struct Phase {
|
||||
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> {
|
||||
__io_port_inherit_complex_bit_map(NoiseGenerator);
|
||||
//0..3 = +7, +6, +5, +4 or -6, -7, -6, -5
|
||||
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> {
|
||||
__io_port_inherit_complex_bit_map(EchoOn);
|
||||
struct __no_align SampleRate : public ComplexBitMap<uint16_t> {
|
||||
__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 {
|
||||
__declare_io_port_global(ubus32_t, on, 0x1F801D88);
|
||||
__declare_io_port_global(ubus32_t, off, 0x1F801D8C);
|
||||
__declare_io_port_global(ubus32_t, status, 0x1F801D9C);
|
||||
}
|
||||
struct __no_align SweepVolume : public ComplexBitMap<int16_t> {
|
||||
__io_port_inherit_complex_bit_map(SweepVolume);
|
||||
|
||||
namespace MainVolume {
|
||||
__declare_io_port_global(SweepVolume, left, 0x1F801D80);
|
||||
__declare_io_port_global(SweepVolume, right, 0x1F801D82);
|
||||
}
|
||||
// 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);
|
||||
|
||||
namespace CDVolume {
|
||||
__declare_io_port_global(SimpleVolume, left, 0x1F801DB0);
|
||||
__declare_io_port_global(SimpleVolume, right, 0x1F801DB2);
|
||||
}
|
||||
// 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);
|
||||
};
|
||||
|
||||
namespace ExternalAudioInputVolume {
|
||||
__declare_io_port_global(SimpleVolume, left, 0x1F801DB4);
|
||||
__declare_io_port_global(SimpleVolume, right, 0x1F801DB6);
|
||||
}
|
||||
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));
|
||||
};
|
||||
|
||||
namespace Reverb {
|
||||
namespace Volume {
|
||||
__declare_io_port_global(SimpleVolume, left, 0x1F801D84);
|
||||
__declare_io_port_global(SimpleVolume, right, 0x1F801D86);
|
||||
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__
|
|
@ -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__
|
|
@ -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__
|
|
@ -1,23 +1,24 @@
|
|||
#ifndef BOOT_LOADER_HPP
|
||||
#define BOOT_LOADER_HPP
|
||||
#include <PSX/jabyengine.h>
|
||||
#include <PSX/jabyengine.hpp>
|
||||
|
||||
namespace GPU {
|
||||
void display_logo();
|
||||
void setup();
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
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
|
|
@ -2,17 +2,18 @@
|
|||
#define __JABYENGINE_CD_HPP__
|
||||
#include <stdint.h>
|
||||
|
||||
namespace CD {
|
||||
namespace CircularBuffer {
|
||||
extern uint8_t* write_ptr;
|
||||
extern uint8_t* read_ptr;
|
||||
extern uint8_t* end_ptr;
|
||||
namespace JabyEngine {
|
||||
namespace CD {
|
||||
namespace CircularBuffer {
|
||||
extern uint8_t* write_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__
|
|
@ -4,111 +4,113 @@
|
|||
#include <PSX/System/IOPorts/dma_io.hpp>
|
||||
#include <PSX/System/IOPorts/gpu_io.hpp>
|
||||
|
||||
namespace GPU {
|
||||
namespace Screen {
|
||||
struct Mode {
|
||||
enum struct TVEncoding {
|
||||
NTSC = 0,
|
||||
PAL = 1,
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
namespace Screen {
|
||||
struct Mode {
|
||||
enum struct TVEncoding {
|
||||
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 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 void configurate() {
|
||||
static constexpr uint16_t FirstVisiblePixelH = 0x260;
|
||||
|
||||
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;
|
||||
#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
|
||||
}
|
||||
|
||||
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;
|
||||
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(::JabyEngine::DMA::GPU.channel_ctrl.ref().is(::JabyEngine::DMA::CHCHR::Busy));
|
||||
}
|
||||
};
|
||||
|
||||
static void configurate() {
|
||||
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));
|
||||
static void end() {
|
||||
reset_cmd_buffer();
|
||||
}
|
||||
|
||||
static void set_src(uintptr_t adr) {
|
||||
::DMA::GPU.adr.ref().set_value(static_cast<uint32_t>(adr), ::DMA::MADR::MemoryAdr);
|
||||
}
|
||||
namespace Receive {
|
||||
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();
|
||||
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 set_dst(const PositionU16& position, const SizeU16& size) {
|
||||
|
||||
static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) {
|
||||
typedef ::DMA::BCR::SyncMode1 SyncMode1;
|
||||
wait_ready_for_CMD();
|
||||
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)));
|
||||
::DMA::GPU.channel_ctrl.write(::DMA::CHCHR::StartGPUReceive());
|
||||
static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
extern JabyEngine::NextRoutine main();
|
||||
|
||||
namespace BootFile {
|
||||
JabyEngine::NextRoutine setup() {
|
||||
printf("Running main!\n");
|
||||
return JabyEngine::NextRoutine::from(main);
|
||||
namespace JabyEngine {
|
||||
namespace BootFile {
|
||||
JabyEngine::NextRoutine setup() {
|
||||
printf("Running main!\n");
|
||||
return JabyEngine::NextRoutine::from(main);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
#include "../../../include/BootLoader/boot_loader.hpp"
|
||||
#include <stdio.h>
|
||||
|
||||
namespace BootFile {
|
||||
JabyEngine::NextRoutine setup() {
|
||||
printf("Overlay boot not implemented!\n");
|
||||
return JabyEngine::NextRoutine::null();
|
||||
namespace JabyEngine {
|
||||
namespace BootFile {
|
||||
JabyEngine::NextRoutine setup() {
|
||||
printf("Overlay boot not implemented!\n");
|
||||
return JabyEngine::NextRoutine::null();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,21 +8,23 @@
|
|||
#include "splash_image_ntsc_boot.hpp"
|
||||
#endif //JABYENGINE_PAL
|
||||
|
||||
namespace GPU {
|
||||
void display_logo() {
|
||||
// Upload SplashScreen picture
|
||||
auto state = FileProcessor::create(reinterpret_cast<const uint32_t*>(SplashScreen), SimpleTIM(32, 0, 0, 0));
|
||||
while(state.process((sizeof(SplashScreen)/sizeof(uint32_t))));
|
||||
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));
|
||||
while(state.process((sizeof(SplashScreen)/sizeof(uint32_t))));
|
||||
|
||||
Display::enable();
|
||||
}
|
||||
Display::enable();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
GP1.write(Command::GP1::Reset());
|
||||
Screen::configurate();
|
||||
Screen::exchange_buffer_and_display();
|
||||
|
||||
GPU::wait_ready_for_CMD();
|
||||
quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height));
|
||||
void setup() {
|
||||
GP1.write(Command::GP1::Reset());
|
||||
Screen::configurate();
|
||||
Screen::exchange_buffer_and_display();
|
||||
|
||||
GPU::wait_ready_for_CMD();
|
||||
quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,94 +2,98 @@
|
|||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
namespace SPU {
|
||||
static void clear_main_volume() {
|
||||
static constexpr auto StartVol = SweepVolume::with(SweepVolume::VolumeEnable, SweepVolume::Volume.with(I16_MAX >> 2));
|
||||
|
||||
MainVolume::left.write(StartVol);
|
||||
MainVolume::right.write(StartVol);
|
||||
}
|
||||
|
||||
static void clear_cd_and_ext_audio_volume() {
|
||||
CDVolume::left.write(0);
|
||||
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() {
|
||||
PMON.write(PitchModFlags());
|
||||
}
|
||||
|
||||
static void clear_noise_and_echo() {
|
||||
NON.write(NoiseGenerator());
|
||||
EON.write(EchoOn());
|
||||
}
|
||||
|
||||
static void clear_reverb() {
|
||||
Reverb::Volume::left.write(0);
|
||||
Reverb::Volume::right.write(0);
|
||||
Reverb::work_area_adr.write(0);
|
||||
}
|
||||
|
||||
static void 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);
|
||||
namespace JabyEngine {
|
||||
namespace SPU {
|
||||
using namespace JabyEngine;
|
||||
|
||||
DataTransferControl.write(RequiredValue);
|
||||
}
|
||||
static void clear_main_volume() {
|
||||
static constexpr auto StartVol = SweepVolume::with(SweepVolume::VolumeEnable, SweepVolume::Volume.with(I16_MAX >> 2));
|
||||
|
||||
static void wait_voices() {
|
||||
static constexpr int16_t Treshhold = (I16_MAX*0.03);
|
||||
MainVolume::left.write(StartVol);
|
||||
MainVolume::right.write(StartVol);
|
||||
}
|
||||
|
||||
try_again:
|
||||
for(const auto& voice : Voices) {
|
||||
if(voice.currentVolume.read() > Treshhold) {
|
||||
goto try_again;
|
||||
static void clear_cd_and_ext_audio_volume() {
|
||||
CDVolume::left.write(0);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void stop_voices() {
|
||||
Key::off.write(UI32_MAX);
|
||||
}
|
||||
static void clear_pmon() {
|
||||
PMON.write(PitchModFlags());
|
||||
}
|
||||
|
||||
void setup() {
|
||||
wait_voices();
|
||||
static void clear_noise_and_echo() {
|
||||
NON.write(NoiseGenerator());
|
||||
EON.write(EchoOn());
|
||||
}
|
||||
|
||||
clear_main_volume();
|
||||
clear_cd_and_ext_audio_volume();
|
||||
clear_control_register();
|
||||
clear_voice();
|
||||
clear_pmon();
|
||||
clear_noise_and_echo();
|
||||
clear_reverb();
|
||||
static void clear_reverb() {
|
||||
Reverb::Volume::left.write(0);
|
||||
Reverb::Volume::right.write(0);
|
||||
Reverb::work_area_adr.write(0);
|
||||
}
|
||||
|
||||
setup_data_transfer_control();
|
||||
setup_control_register();
|
||||
static void 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,21 +2,23 @@
|
|||
#include <PSX/System/IOPorts/dMa_io.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Setup {
|
||||
static void enable_DMA() {
|
||||
DMA::DPCR.write(DMA::DPCR.read() | DMA::DMAControlRegister::SPUEnable | DMA::DMAControlRegister::GPUEnable);
|
||||
}
|
||||
namespace JabyEngine {
|
||||
namespace Setup {
|
||||
static void enable_DMA() {
|
||||
DMA::DPCR.write(DMA::DPCR.read() | DMA::DMAControlRegister::SPUEnable | DMA::DMAControlRegister::GPUEnable);
|
||||
}
|
||||
|
||||
JabyEngine::NextRoutine start() {
|
||||
enable_DMA();
|
||||
JabyEngine::NextRoutine start() {
|
||||
enable_DMA();
|
||||
|
||||
SPU::stop_voices();
|
||||
SPU::stop_voices();
|
||||
|
||||
GPU::setup();
|
||||
GPU::display_logo();
|
||||
//Pause??
|
||||
GPU::setup();
|
||||
GPU::display_logo();
|
||||
//Pause??
|
||||
|
||||
SPU::setup();
|
||||
return BootFile::setup();
|
||||
SPU::setup();
|
||||
return BootFile::setup();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,24 +3,25 @@
|
|||
#define private public
|
||||
#include <PSX/File/Processor/file_processor.hpp>
|
||||
|
||||
namespace FileProcessor {
|
||||
namespace Helper {
|
||||
template<typename T>
|
||||
static void simple_read(T& dst, State::Configuration& config) {
|
||||
static constexpr size_t UINT32_SIZE = (sizeof(T)/sizeof(uint32_t));
|
||||
namespace JabyEngine {
|
||||
namespace FileProcessor {
|
||||
namespace Helper {
|
||||
template<typename 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);
|
||||
config.processed(UINT32_SIZE);
|
||||
dst = *reinterpret_cast<const T*>(config.data_adr);
|
||||
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>
|
||||
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);
|
||||
return process_routine(config, state);
|
||||
template<typename T>
|
||||
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);
|
||||
return process_routine(config, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !__JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__
|
|
@ -3,129 +3,130 @@
|
|||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace FileProcessor {
|
||||
using GPU::PositionU16;
|
||||
using GPU::SizeU16;
|
||||
namespace JabyEngine {
|
||||
namespace FileProcessor {
|
||||
using GPU::PositionU16;
|
||||
using GPU::SizeU16;
|
||||
|
||||
struct SimpleTIMSize : private SimpleTIM {
|
||||
constexpr SimpleTIMSize() {
|
||||
struct SimpleTIMSize : private SimpleTIM {
|
||||
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 {
|
||||
return SimpleTIM::getTextureX();
|
||||
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);
|
||||
}
|
||||
|
||||
constexpr uint16_t getTextureHeight() const {
|
||||
return SimpleTIM::getTextureY();
|
||||
}
|
||||
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);
|
||||
|
||||
constexpr uint16_t getClutWidth() const {
|
||||
return SimpleTIM::getClutX();
|
||||
}
|
||||
while(block_count > 0) {
|
||||
const auto block_send = (block_count > UI16_MAX) ? UI16_MAX : block_count;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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) {
|
||||
// Send data!
|
||||
GPU::DMA::wait();
|
||||
GPU::DMA::Receive::start(1, last_words);
|
||||
GPU::DMA::Receive::start(block_send);
|
||||
block_count -= block_send;
|
||||
}
|
||||
|
||||
GPU::DMA::wait();
|
||||
GPU::DMA::end();
|
||||
if(is_last) {
|
||||
// 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;
|
||||
config.processed(words_to_use);
|
||||
GPU::DMA::wait();
|
||||
GPU::DMA::end();
|
||||
|
||||
return false;
|
||||
}
|
||||
state.words_left = 0;
|
||||
config.processed(words_to_use);
|
||||
|
||||
else {
|
||||
const auto words_used = (words_to_use & ~0b1111);
|
||||
|
||||
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 parse_clut(State::Configuration& config, SimpleTIMState& state) {
|
||||
if(parse_data(config, state)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
else {
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
|
||||
else {
|
||||
const auto words_used = (words_to_use & ~0b1111);
|
||||
|
||||
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 parse_clut(State::Configuration& config, SimpleTIMState& state) {
|
||||
if(parse_data(config, state)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//We have direct data
|
||||
else {
|
||||
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);
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
State create(const uint32_t* data_adr, const SimpleTIM& file) {
|
||||
return State::from(SimpleTIMState(file), data_adr, parse_header);
|
||||
//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
|
|
@ -1,36 +1,38 @@
|
|||
#include "../include/GPU/gpu.hpp"
|
||||
|
||||
namespace GPU {
|
||||
namespace Screen {
|
||||
uint8_t CurrentDisplayAreaID = 1; //< Setup will call exchange and set it to 0
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
namespace Screen {
|
||||
uint8_t CurrentDisplayAreaID = 1; //< Setup will call exchange and set it to 0
|
||||
|
||||
namespace Range {
|
||||
#ifdef JABYENGINE_PAL
|
||||
static constexpr uint16_t ScanlinesV = 288;
|
||||
#else
|
||||
static constexpr uint16_t ScanlinesV = 240;
|
||||
#endif //JABYENGINE_PAL
|
||||
namespace Range {
|
||||
#ifdef JABYENGINE_PAL
|
||||
static constexpr uint16_t ScanlinesV = 288;
|
||||
#else
|
||||
static constexpr uint16_t ScanlinesV = 240;
|
||||
#endif //JABYENGINE_PAL
|
||||
|
||||
#ifndef USE_NO$PSX
|
||||
void set_offset(uint16_t x, uint16_t y) {
|
||||
x += 78;
|
||||
y += 43;
|
||||
#ifndef USE_NO$PSX
|
||||
void set_offset(uint16_t x, uint16_t y) {
|
||||
x += 78;
|
||||
y += 43;
|
||||
|
||||
GP1.write(Command::GP1::HorizontalDisplayRange((x << 3), (x + Display::Width) << 3));
|
||||
GP1.write(Command::GP1::VerticalDisplayRange(y, y + Display::Height));
|
||||
}
|
||||
#else
|
||||
void set_offset(uint16_t x, uint16_t y) {
|
||||
GP1.write(Command::GP1::HorizontalDisplayRange(x, (x + Display::Width*8)));
|
||||
GP1.write(Command::GP1::VerticalDisplayRange(y - (ScanlinesV/2), y + (ScanlinesV/2)));
|
||||
}
|
||||
#endif //USE_NO$PSX
|
||||
}
|
||||
GP1.write(Command::GP1::HorizontalDisplayRange((x << 3), (x + Display::Width) << 3));
|
||||
GP1.write(Command::GP1::VerticalDisplayRange(y, y + Display::Height));
|
||||
}
|
||||
#else
|
||||
void set_offset(uint16_t x, uint16_t y) {
|
||||
GP1.write(Command::GP1::HorizontalDisplayRange(x, (x + Display::Width*8)));
|
||||
GP1.write(Command::GP1::VerticalDisplayRange(y - (ScanlinesV/2), y + (ScanlinesV/2)));
|
||||
}
|
||||
#endif //USE_NO$PSX
|
||||
}
|
||||
|
||||
void exchange_buffer_and_display() {
|
||||
GPU::set_draw_area(0, (Display::Height*CurrentDisplayAreaID));
|
||||
CurrentDisplayAreaID ^= 1;
|
||||
GP1.write(Command::GP1::DisplayArea(0, (Display::Height*CurrentDisplayAreaID)));
|
||||
void exchange_buffer_and_display() {
|
||||
GPU::set_draw_area(0, (Display::Height*CurrentDisplayAreaID));
|
||||
CurrentDisplayAreaID ^= 1;
|
||||
GP1.write(Command::GP1::DisplayArea(0, (Display::Height*CurrentDisplayAreaID)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue