From 8d6b9ef626bfbaf89f9ee5f379ed84953fea7b43 Mon Sep 17 00:00:00 2001 From: Jaby Date: Tue, 19 Dec 2023 16:26:04 -0500 Subject: [PATCH] Clean up code slightly --- include/PSX/GPU/gpu_auto_load_font.hpp | 23 +++ include/PSX/GPU/gpu_types.hpp | 2 + .../BootLoader/BIOSFont/ascii_bios_font.hpp | 73 +++++++++ .../BootLoader/BIOSFont/bios_font_types.hpp | 98 +++++++++++ src/Library/src/BootLoader/gpu_boot.cpp | 155 +----------------- 5 files changed, 200 insertions(+), 151 deletions(-) create mode 100644 include/PSX/GPU/gpu_auto_load_font.hpp create mode 100644 src/Library/src/BootLoader/BIOSFont/ascii_bios_font.hpp create mode 100644 src/Library/src/BootLoader/BIOSFont/bios_font_types.hpp diff --git a/include/PSX/GPU/gpu_auto_load_font.hpp b/include/PSX/GPU/gpu_auto_load_font.hpp new file mode 100644 index 00000000..32ff3a73 --- /dev/null +++ b/include/PSX/GPU/gpu_auto_load_font.hpp @@ -0,0 +1,23 @@ +#pragma once +#include "gpu_primitives.hpp" + +namespace JabyEngine { + namespace GPU { + struct BIOS_Font { + // This size is by Hardware limitation + static constexpr auto Size = SizeU16::create(16, 16); + + // The following two values can be easily changed + static constexpr auto TextureLoadPos = PositionU16::create(0, 0); + static constexpr auto CLUTLoadPos = PositionU16::create(0, 0); + + static constexpr TexPage get_tex_page() { + return TexPage::create(BIOS_Font::TextureLoadPos, GPU::TexturePageColor::$4bit); + } + + static constexpr OffsetPageWithClut get_offset_page_with_clut() { + return OffsetPageWithClut::create(PageOffset::create(BIOS_Font::CLUTLoadPos.x & 0x3F, BIOS_Font::CLUTLoadPos.y & 0xFF), PageClut::create(BIOS_Font::CLUTLoadPos)); + } + }; + } +} \ No newline at end of file diff --git a/include/PSX/GPU/gpu_types.hpp b/include/PSX/GPU/gpu_types.hpp index b366235b..02c6381d 100644 --- a/include/PSX/GPU/gpu_types.hpp +++ b/include/PSX/GPU/gpu_types.hpp @@ -170,6 +170,8 @@ namespace JabyEngine { static constexpr Size create(T w, T h) { return Size{w, h}; } + + auto operator<=>(const Size&) const = default; }; typedef Size SizeI16; typedef Size SizeU16; diff --git a/src/Library/src/BootLoader/BIOSFont/ascii_bios_font.hpp b/src/Library/src/BootLoader/BIOSFont/ascii_bios_font.hpp new file mode 100644 index 00000000..0448d40f --- /dev/null +++ b/src/Library/src/BootLoader/BIOSFont/ascii_bios_font.hpp @@ -0,0 +1,73 @@ +#pragma once +#include "../../../internal-include/GPU/gpu_internal.hpp" +#include "bios_font_types.hpp" +#include + +// | ! | " | # | $ | % | & | ' | ( | ) | * | + | , | - | . | / | 0 | +// | 8149 | 8168 | 8194 | 8190 | 8193 | 8195 | 8166 | 8169 | 816A | 8196 | 817B | 8143 | 817C | 8144 | 815E | 8240 | +// | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | < | = | > | ? | @ | +// | 8251 | 8252 | 8253 | 8254 | 8255 | 8256 | 8257 | 8258 | 8259 | 8146 | 8147 | 8183 | 8181 | 8184 | 8148 | 8197 | +// | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | +// | 8260 | 8261 | 8262 | 8263 | 8264 | 8265 | 8266 | 8267 | 8268 | 8269 | 826A | 826B | 826C | 826D | 826E | 826F | +// | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _ | ` | +// | 8270 | 8271 | 8272 | 8273 | 8274 | 8275 | 8276 | 8277 | 8278 | 8279 | 816D | 815F | 816E | 814F | 8151 | 814D | +// | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | +// | 8281 | 8282 | 8283 | 8284 | 8285 | 8286 | 8287 | 8288 | 8289 | 828A | 828B | 828C | 828D | 828E | 828F | 8290 | +// | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ | | | +// | 8291 | 8292 | 8293 | 8294 | 8295 | 8296 | 8297 | 8298 | 8299 | 829A | 816F | 8162 | 8170 | 8160 | | | + +namespace JabyEngine { + namespace GPU { + namespace SJIS { + // base: 0x8100 + static const SpecialChar Specials[] = { // ToDo: Can we split this into 4 arrays? Would that help somehow? + // { ! } { " } { # } { $ } { % } { & } { ' } { ( } { ) } { * } { + } { , } { - } { . } { / } + {0x49, 0}, {0x68, 1}, {0x94, 2}, {0x90, 3}, {0x93, 4}, {0x95, 5}, {0x66, 6}, {0x69, 7}, {0x6A, 8}, {0x96, 9}, {0x7B, 10}, {0x43, 11}, {0x7C, 12}, {0x44, 13}, {0x5E, 14}, + // { : } { ; } { < } { = } { > } { ? } { @ } + {0x46, 25}, {0x47, 26}, {0x83, 27}, {0x81, 28}, {0x84, 29}, {0x48, 30}, {0x97, 31}, + // { [ } { \ } { ] } { ^ } { _ } { ` } + {0x6D, 58}, {0x5F, 59}, {0x6E, 60}, {0x4F, 61}, {0x51, 62}, {0x4D, 63}, + // { { } { | } { } } { ~ } + {0x6F, 90}, {0x62, 91}, {0x70, 92}, {0x60, 93} + }; + + // base: 0x8200 + static const RangeChar AlphaNumeric[] = { + // { 0 } + {{0x4F, 15}, 1}, + // { 1 - 9 } + {{0x50, 16}, 9}, + // { A - Z } + {{0x60, 32}, 26}, + // { a - z } + {{0x81, 64}, 26} + }; + + static void load(const PositionU16& start_pos) { + FontBuffer font_buffer; + const auto load_special_chars = [&font_buffer](const PositionU16& pos, const SpecialChar(&special_chars)[Size]) { + for(const auto& special_char : special_chars) { + font_buffer.load_to(pos.add(FontBuffer::vram_offset(special_char.tile_id)), SysCall::Krom2RawAdd(0x8100 | special_char.base_offset)); + } + }; + const auto load_alpha_num = [&font_buffer](const PositionU16& pos, const RangeChar(&range_char)[Size]) { + for(const auto& range : range_char) { + const auto end_tile = range.start_char.tile_id + range.length; + auto sjis_code = 0x8200 | range.start_char.base_offset; + + for(uint16_t tile_id = range.start_char.tile_id; tile_id < end_tile; tile_id++,sjis_code++) { + font_buffer.load_to(pos.add(FontBuffer::vram_offset(tile_id)), SysCall::Krom2RawAdd(sjis_code)); + } + } + }; + + font_buffer.setup(); + + GPU::internal::DMA::Receive::prepare(); + load_special_chars(start_pos, Specials); + load_alpha_num(start_pos, AlphaNumeric); + font_buffer.flush(); + } + } + } +} \ No newline at end of file diff --git a/src/Library/src/BootLoader/BIOSFont/bios_font_types.hpp b/src/Library/src/BootLoader/BIOSFont/bios_font_types.hpp new file mode 100644 index 00000000..443f27f7 --- /dev/null +++ b/src/Library/src/BootLoader/BIOSFont/bios_font_types.hpp @@ -0,0 +1,98 @@ +#pragma once +#include + +namespace JabyEngine { + namespace GPU { + namespace SJIS { + struct FontBuffer { + // A line of 16 Pixel + struct Line { + Color pixel[BIOS_Font::Size.width]; + + void load(uint16_t bit_pattern) { + size_t px_idx = 0; + for(uint16_t shift = 1 << 15; shift; shift = shift >> 1) { + this->pixel[px_idx++] = bit_pattern & shift ? Color::from_rgb(0xFF, 0xFF, 0xFF) : Color::from_rgb(0x0, 0x0, 0x0); + } + } + + static PositionU16 vram_offset(uint16_t tile_id) { + return tile_id_for16(tile_id); + } + }; + + // Letters are actually only 16x15 but should be treated 16x16 + struct Letter : public GPU::internal::LinkedElementCreator { + CPU2VRAM cmd; + Line lines[BIOS_Font::Size.height - 1]; + Line empty_line; + + void setup(const SizeU16& size) { + this->cmd.cmd = GPU_IO::Command::CPU2VRAM_Blitting(); + this->cmd.size = GPU_IO::Command::WidthHeight(size); + this->empty_line.load(0); + } + + void load_to(const PositionU16& pos, const uint16_t* bit_map) { + this->cmd.pos = GPU_IO::Command::TopLeftPosition(pos); + for(auto& cur_line : this->lines) { + cur_line.load(__builtin_bswap16(*bit_map++)); + } + } + }; + + // v double buffer do not change size without adjusting + Letter::Linked letter_buffer[2*4]; + uint8_t free_idx; + + void setup() { + for(auto& letter : this->letter_buffer) { + letter->setup(SizeU16::create(16, 16)); + letter.set_link_identitiy(); + } + this->free_idx = 0; + } + + void load_to(const PositionU16& pos, const uint16_t* bit_map) { + auto& cur_letter = this->letter_buffer[this->free_idx++]; + + cur_letter->load_to(pos, bit_map); + if((this->free_idx&0x3) == 0) { + cur_letter.terminate(); + GPU::render(this->letter_buffer[this->free_idx - 4]); + this->free_idx &= ~0x7; + } + + else { + cur_letter.concat(this->letter_buffer[this->free_idx]); + } + } + + void flush() { + if((this->free_idx&0x3) != 0) { + this->letter_buffer[this->free_idx - 1].terminate(); + + const auto idx = this->free_idx > 3 ? 4 : 0; + GPU::render(this->letter_buffer[idx]); + } + } + + static PositionU16 vram_offset(uint16_t tile_id) { + return Line::vram_offset(tile_id); + } + }; + + struct SpecialChar { + uint8_t base_offset; + uint8_t tile_id; + }; + + struct RangeChar { + SpecialChar start_char; + uint8_t length; + }; + + static_assert(BIOS_Font::Size == SizeU16::create(16, 16)); + } + } +} \ No newline at end of file diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index b6407353..a704fd4b 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -12,18 +12,8 @@ #include "splash_image_ntsc_boot.hpp" #endif //JABYENGINE_PAL -// | ! | " | # | $ | % | & | ' | ( | ) | * | + | , | - | . | / | 0 | -// | 8149 | 8168 | 8194 | 8190 | 8193 | 8195 | 8166 | 8169 | 816A | 8196 | 817B | 8143 | 817C | 8144 | 815E | 8240 | -// | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | < | = | > | ? | @ | -// | 8251 | 8252 | 8253 | 8254 | 8255 | 8256 | 8257 | 8258 | 8259 | 8146 | 8147 | 8183 | 8181 | 8184 | 8148 | 8197 | -// | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | -// | 8260 | 8261 | 8262 | 8263 | 8264 | 8265 | 8266 | 8267 | 8268 | 8269 | 826A | 826B | 826C | 826D | 826E | 826F | -// | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _ | ` | -// | 8270 | 8271 | 8272 | 8273 | 8274 | 8275 | 8276 | 8277 | 8278 | 8279 | 816D | 815F | 816E | 814F | 8151 | 814D | -// | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | -// | 8281 | 8282 | 8283 | 8284 | 8285 | 8286 | 8287 | 8288 | 8289 | 828A | 828B | 828C | 828D | 828E | 828F | 8290 | -// | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ | | | -// | 8291 | 8292 | 8293 | 8294 | 8295 | 8296 | 8297 | 8298 | 8299 | 829A | 816F | 8162 | 8170 | 8160 | | | +// Concept for switchting BIOS Fonts...? +#include "BIOSFont/ascii_bios_font.hpp" extern "C" uint32_t __boot_loader_end; @@ -38,144 +28,6 @@ namespace JabyEngine { namespace GPU { using namespace JabyEngine::GPU; - namespace SJIS { - struct FontBuffer { - static constexpr auto FontSize = SizeU16::create(16, 16); - static constexpr auto AmountOfChars = 4; - - struct Line { - Color pixel[FontSize.width]; - - void load(uint16_t bit_pattern) { - size_t px_idx = 0; - for(uint16_t shift = 1 << 15; shift; shift = shift >> 1) { - this->pixel[px_idx++] = bit_pattern & shift ? Color::from_rgb(0xFF, 0xFF, 0xFF) : Color::from_rgb(0x0, 0x0, 0x0); - } - } - }; - - // Letters are actually only 16x15 but should be treated 16x16 - struct Letter : public GPU::internal::LinkedElementCreator { - CPU2VRAM cmd; - Line lines[FontSize.height - 1]; - Line empty_line; - - void setup(const SizeU16& size) { - this->cmd.cmd = GPU_IO::Command::CPU2VRAM_Blitting(); - this->cmd.size = GPU_IO::Command::WidthHeight(size); - this->empty_line.load(0); - } - - void load_to(const PositionU16& pos, const uint16_t* bit_map) { - this->cmd.pos = GPU_IO::Command::TopLeftPosition(pos); - for(auto& cur_line : this->lines) { - cur_line.load(__builtin_bswap16(*bit_map++)); - } - } - }; - - // v double buffer do not change size without adjusting - Letter::Linked letter_buffer[2*4]; - uint8_t free_idx; - - void setup() { - for(auto& letter : this->letter_buffer) { - letter->setup(SizeU16::create(16, 16)); - letter.set_link_identitiy(); - } - this->free_idx = 0; - } - - void load_to(const PositionU16& pos, const uint16_t* bit_map) { - auto& cur_letter = this->letter_buffer[this->free_idx++]; - - cur_letter->load_to(pos, bit_map); - if((this->free_idx&0x3) == 0) { - cur_letter.terminate(); - GPU::render(this->letter_buffer[this->free_idx - 4]); - this->free_idx &= ~0x7; - } - - else { - cur_letter.concat(this->letter_buffer[this->free_idx]); - } - } - - void flush() { - if((this->free_idx&0x3) != 0) { - this->letter_buffer[this->free_idx - 1].terminate(); - - const auto idx = this->free_idx > 3 ? 4 : 0; - GPU::render(this->letter_buffer[idx]); - } - } - }; - - struct SpecialChar { - uint8_t base_offset; - uint8_t tile_id; - }; - - struct RangeChar { - SpecialChar start_char; - uint8_t length; - }; - - // base: 0x8100 - static const SpecialChar Specials[] = { // ToDo: Can we split this into 4 arrays? Would that help somehow? - // { ! } { " } { # } { $ } { % } { & } { ' } { ( } { ) } { * } { + } { , } { - } { . } { / } - {0x49, 0}, {0x68, 1}, {0x94, 2}, {0x90, 3}, {0x93, 4}, {0x95, 5}, {0x66, 6}, {0x69, 7}, {0x6A, 8}, {0x96, 9}, {0x7B, 10}, {0x43, 11}, {0x7C, 12}, {0x44, 13}, {0x5E, 14}, - // { : } { ; } { < } { = } { > } { ? } { @ } - {0x46, 25}, {0x47, 26}, {0x83, 27}, {0x81, 28}, {0x84, 29}, {0x48, 30}, {0x97, 31}, - // { [ } { \ } { ] } { ^ } { _ } { ` } - {0x6D, 58}, {0x5F, 59}, {0x6E, 60}, {0x4F, 61}, {0x51, 62}, {0x4D, 63}, - // { { } { | } { } } { ~ } - {0x6F, 90}, {0x62, 91}, {0x70, 92}, {0x60, 93} - }; - - // base: 0x8200 - static const RangeChar AlphaNumeric[] = { - // { 0 } - {{0x4F, 15}, 1}, - // { 1 - 9 } - {{0x50, 16}, 9}, - // { A - Z } - {{0x60, 32}, 26}, - // { a - z } - {{0x81, 64}, 26} - }; - - void load(const PositionU16& start_pos) { - static const auto get_dst_pos = [](const PositionU16& pos, uint16_t tile_id) { - return pos.add(tile_id_for16(tile_id)); - }; - - FontBuffer font_buffer; - const auto load_special_chars = [&font_buffer](const PositionU16& pos, const SpecialChar(&special_chars)[Size]) { - for(const auto& special_char : special_chars) { - font_buffer.load_to(get_dst_pos(pos, special_char.tile_id), SysCall::Krom2RawAdd(0x8100 | special_char.base_offset)); - } - }; - const auto load_alpha_num = [&font_buffer](const PositionU16& pos, const RangeChar(&range_char)[Size]) { - for(const auto& range : range_char) { - const auto end_tile = range.start_char.tile_id + range.length; - auto sjis_code = 0x8200 | range.start_char.base_offset; - - for(uint16_t tile_id = range.start_char.tile_id; tile_id < end_tile; tile_id++,sjis_code++) { - font_buffer.load_to(get_dst_pos(pos, tile_id), SysCall::Krom2RawAdd(sjis_code)); - } - } - }; - - font_buffer.setup(); - - GPU::internal::DMA::Receive::prepare(); - load_special_chars(start_pos, Specials); - load_alpha_num(start_pos, AlphaNumeric); - font_buffer.flush(); - } - } - static void configurate_display() { // Ideal I hope that an offset of 0,0 will produce a well enough centered picture for every TV for now GPU_IO::GP1.write(GPU_IO::Command::DisplayMode(::JabyEngine::GPU::internal::Display::DisplayMode)); @@ -210,7 +62,8 @@ namespace JabyEngine { auto state = FileProcessor::create(&__boot_loader_end, SimpleTIM(32, 0, 0, 0)); state.process(bytes_ready); - SJIS::load(PositionU16::create(0, 0)); + // Now load the BIOS font to the specified location + SJIS::load(BIOS_Font::TextureLoadPos); // Duplicate DisplayBuffer content ::JabyEngine::GPU::internal::copy_vram_to_vram({PositionU16::create(0, Display::Height), SizeU16::create(Display::Width, Display::Height)}, PositionU16::create(0, 0));