From ef009315c713630fac41061d95e7d26b1b8d670d Mon Sep 17 00:00:00 2001 From: Jaby Date: Thu, 21 Dec 2023 12:50:42 -0500 Subject: [PATCH] Introduce LookUpColor4 --- include/PSX/GPU/gpu_types.hpp | 18 ++++++++++++++++++ src/Library/src/BootLoader/gpu_boot.cpp | 19 +++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/include/PSX/GPU/gpu_types.hpp b/include/PSX/GPU/gpu_types.hpp index 0a04b36d..e0bd009f 100644 --- a/include/PSX/GPU/gpu_types.hpp +++ b/include/PSX/GPU/gpu_types.hpp @@ -167,7 +167,25 @@ namespace JabyEngine { constexpr void set_lu_id(uint8_t new_lu_id, size_t at) { this->lu_id[at] = new_lu_id; } + }; + struct LookUpColor4 { + uint8_t lu_id[2]; + + static constexpr LookUpColor4 from_id(uint8_t px0, uint8_t px1, uint8_t px2, uint8_t px3) { + return {{static_cast((px0 << 4) | px1), static_cast((px2 << 4) | px3)}}; + } + + constexpr uint8_t get_lu_id(size_t at) const { + const auto value = this->lu_id[at >> 1]; + + return (value & 0x1) ? value & 0xF : value >> 4; + } + + constexpr void set_lu_id(uint8_t new_lu_id, size_t at) { + this->lu_id[at >> 1] = bit::value::set_normalized(this->lu_id[at >> 1], BitRange(4*(at&0x1), 4).with(new_lu_id)); + } + uint16_t force_read() const { return *const_cast(reinterpret_cast(this->lu_id)); } diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index 8ff9dd8d..35ede6c3 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -93,21 +93,12 @@ namespace JabyEngine { void setup() { asm("# Planschi1"); - auto test = LookUpColor8::from_ids(0xAA, 0xBB); - test.force_read(); + auto value = LookUpColor4::from_id(0xA, 0xB, 0xC, 0xF); + + for(size_t n = 0; n < 4; n++) { + printf(">>> %i\n", value.get_lu_id(n)); + } asm("# Planschi2"); - test.set_lu_id(0xCC, 0); - test.set_lu_id(0xDD, 1); - test.force_read(); - asm("# Planschi3"); - test.set_lu_id(*reinterpret_cast(0xAA), 0); - test.set_lu_id(*reinterpret_cast(0xDD), 1); - test.force_read(); - asm("# Planschi4"); - test.set_lu_id(*reinterpret_cast(0xAA), *reinterpret_cast(0xAE)); - test.set_lu_id(*reinterpret_cast(0xDD), *reinterpret_cast(0xDE)); - test.force_read(); - asm("# Planschi5"); GPU_IO::GP1.write(GPU_IO::Command::Reset()); configurate_display();