From 6568bfcd7d1b21472fc6f94ea8a9cc73b3db5f56 Mon Sep 17 00:00:00 2001 From: jaby Date: Mon, 18 Dec 2023 16:12:13 -0500 Subject: [PATCH] Load BIOS font --- include/PSX/GPU/gpu_types.hpp | 39 +++++++++++++++++++--- src/Library/src/BootLoader/gpu_boot.cpp | 43 ++++++++++++++++++------- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/include/PSX/GPU/gpu_types.hpp b/include/PSX/GPU/gpu_types.hpp index 639f2819..b366235b 100644 --- a/include/PSX/GPU/gpu_types.hpp +++ b/include/PSX/GPU/gpu_types.hpp @@ -15,7 +15,15 @@ namespace JabyEngine { } constexpr T add(S dx, S dy) const { - return T(static_cast(this)->x, static_cast(this)->y).add(dx, dy); + return T::create(static_cast(this)->x, static_cast(this)->y).add(dx, dy); + } + + constexpr T& add(const T& offset) { + return add(offset.x, offset.y); + } + + constexpr T add(const T& offset) const { + return add(offset.x, offset.y); } constexpr T& sub(S dx, S dy) { @@ -29,6 +37,14 @@ namespace JabyEngine { return T::create(static_cast(this)->x, static_cast(this)->y).sub(dx, dy); } + constexpr T& sub(const T& offset) { + return sub(offset.x, offset.y); + } + + constexpr T sub(const T& offset) const { + return sub(offset.x, offset.y); + } + constexpr T& move(S dx, S dy) { return this->add(dx, dy); } @@ -160,6 +176,22 @@ namespace JabyEngine { // Type used for primitives typedef PositionI16 Vertex; + template + static constexpr T tile_id_for(S id, S row_count, Size size) { + const auto x = id%row_count; + const auto y = id/row_count; + + return T::create(static_cast(size.width*x), static_cast(size.height*y)); + } + + template + static constexpr T tile_id_for16(S id) { + const auto x = id&0xF; + const auto y = id >> 4; + + return T::create(static_cast(x << 4), static_cast(y << 4)); + } + template struct Area { Position position; @@ -201,10 +233,7 @@ namespace JabyEngine { } static constexpr PageOffset from_tile_id(int16_t id, int16_t row_count, SizeI16 size) { - const auto x = id%row_count; - const auto y = id/row_count; - - return PageOffset::create(static_cast(size.width*x), static_cast(size.height*y)); + return tile_id_for(id, row_count, size); } }; diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index fa05f2a6..bbc968be 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -131,23 +131,42 @@ namespace JabyEngine { }; // base: 0x8200 - // { 0 - 9 } - static const auto Numbers = RangeChar{{0x50, 15}, 10}; - // { A - Z } - static const auto UpperCaseLetter = RangeChar{{0x60, 32}, 26}; - // { a - z } - static const auto LowerCaseLetter = RangeChar{{0x81, 64}, 26}; + static const RangeChar AlphaNumeric[] = { + // { 0 - 9 } + {{0x50, 15}, 10}, + // { 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)); + }; - void load() { - // Linkd create here 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(); - for(size_t n = 0; n < 5; n++) { - font_buffer.load_to(PositionU16::create(16*n, 0), SysCall::Krom2RawAdd(0x8200 | (UpperCaseLetter.start_char.base_offset + n))); - } + load_special_chars(start_pos, Specials); + load_alpha_num(start_pos, AlphaNumeric); font_buffer.flush(); } } @@ -186,7 +205,7 @@ namespace JabyEngine { auto state = FileProcessor::create(&__boot_loader_end, SimpleTIM(32, 0, 0, 0)); state.process(bytes_ready); - SJIS::load(); + SJIS::load(PositionU16::create(0, 0)); // 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));