Introduce the JabyEngine namespace to all files
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user