Support BIOS Font
This commit is contained in:
parent
f96b55a548
commit
a67a634fd8
|
@ -1,24 +1,30 @@
|
|||
#include "../include/font_writer.hpp"
|
||||
#include <PSX/File/Processor/cd_file_processor.hpp>
|
||||
#include <PSX/GPU/gpu_auto_load_font.hpp>
|
||||
#include <PSX/GPU/make_gpu_primitives.hpp>
|
||||
#include <PSX/Timer/frame_timer.hpp>
|
||||
#include <FontWriter/default_font.hpp>
|
||||
|
||||
using JabyEngine::Make::PositionI8;
|
||||
|
||||
static constexpr auto FontWriterTIM = JabyEngine::SimpleTIM(320, 0, 320, JabyEngine::DefaultFont::Info.texture_size.height);
|
||||
static constexpr auto LibraryFontTIM = JabyEngine::SimpleTIM(320, 0, 320, JabyEngine::DefaultFont::Info.texture_size.height);
|
||||
|
||||
static JabyEngine::FontPrimitive font_buffer[2*256];
|
||||
static JabyEngine::Wiggle wiggle = {PositionI8(0, 0), PositionI8(1, -2), PositionI8(0, -4), PositionI8(-1, -2), PositionI8(0, 0), PositionI8(1, 2), PositionI8(0, 4), PositionI8(-1, 2)};
|
||||
static JabyEngine::FontWriter new_font_writer = JabyEngine::FontWriter::empty();
|
||||
static JabyEngine::Wiggle wiggle = {PositionI8(0, 0), PositionI8(1, -2), PositionI8(0, -4), PositionI8(-1, -2), PositionI8(0, 0), PositionI8(1, 2), PositionI8(0, 4), PositionI8(-1, 2)};
|
||||
static JabyEngine::FontWriter new_font_writer = JabyEngine::FontWriter::empty();
|
||||
static JabyEngine::FontWriter bios_font_writer = JabyEngine::FontWriter::empty();
|
||||
static JabyEngine::SimpleTimer<uint8_t> timer;
|
||||
static uint8_t wiggle_count = 0;
|
||||
static uint8_t wiggle_count = 0;
|
||||
|
||||
void font_writer_setup() {
|
||||
JabyEngine::DefaultFont::load(&__heap_start, FontWriterTIM);
|
||||
JabyEngine::DefaultFont::load(&__heap_start, LibraryFontTIM);
|
||||
JabyEngine::GlobalFontPrimitivePool::setup(font_buffer);
|
||||
|
||||
new_font_writer.setup(FontWriterTIM, JabyEngine::DefaultFont::Info);
|
||||
new_font_writer.setup(LibraryFontTIM, JabyEngine::DefaultFont::Info);
|
||||
bios_font_writer.setup(JabyEngine::GPU::BIOS_Font::as_simple_tim(), {
|
||||
.texture_size = {64, 80},
|
||||
.font_size = {16, 16}
|
||||
});
|
||||
timer.reset();
|
||||
}
|
||||
|
||||
|
@ -27,7 +33,8 @@ void font_writer_update() {
|
|||
|
||||
auto state = JabyEngine::State::create(JabyEngine::Make::PositionI16(8, 8), wiggle_count);
|
||||
new_font_writer.write(state, "012345 ABCDEFGHIJKL\nabcedfghijkl\n", JabyEngine::GPU::Color24::Blue(), &wiggle);
|
||||
new_font_writer.write(state, "%i (0x%p)\nWiggle (%s)", JabyEngine::GPU::Color24::Green(), &wiggle, wiggle_count, 0xAABBCCDD, Text[wiggle_count&0x1]);
|
||||
new_font_writer.write(state, "%i (0x%p)\nWiggle (%s)\n", JabyEngine::GPU::Color24::Green(), &wiggle, wiggle_count, 0xAABBCCDD, Text[wiggle_count&0x1]);
|
||||
bios_font_writer.write(state, "!!PLANSCHBECKEN!!");
|
||||
|
||||
if(timer.is_expired_for(50_ms)) {
|
||||
timer.reset();
|
||||
|
@ -37,4 +44,5 @@ void font_writer_update() {
|
|||
|
||||
void font_writer_render() {
|
||||
new_font_writer.render();
|
||||
bios_font_writer.render();
|
||||
}
|
|
@ -219,7 +219,7 @@ namespace JabyEngine {
|
|||
PageOffset tex_offset3; // i
|
||||
uint16_t pad3; // i
|
||||
|
||||
static constexpr POLY_FT4 create(const Vertex (&verticies)[4], const PageOffset (&tex_offsets)[4], TPage tpage, PageClut clut, Color24 color) {
|
||||
static constexpr POLY_FT4 create(const Vertex (&verticies)[4], const PageOffset (&tex_offsets)[4], TPage tpage, PageClut clut, Color24 color = Color24::Grey()) {
|
||||
return POLY_FT4::create({
|
||||
{verticies[0], tex_offsets[0]},
|
||||
{verticies[1], tex_offsets[1]},
|
||||
|
@ -238,7 +238,7 @@ namespace JabyEngine {
|
|||
};
|
||||
}
|
||||
|
||||
static constexpr POLY_FT4 create(const AreaI16& area, const PageOffset& tex_offset, TPage tpage, PageClut clut, Color24 color) {
|
||||
static constexpr POLY_FT4 create(const AreaI16& area, const PageOffset& tex_offset, TPage tpage, PageClut clut, Color24 color = Color24::Grey()) {
|
||||
return POLY_FT4::create({
|
||||
{area.position, tex_offset},
|
||||
{area.position.move(area.size.width, 0), tex_offset.move(area.size.width, 0)},
|
||||
|
|
|
@ -8,15 +8,31 @@ namespace JabyEngine {
|
|||
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, 96);
|
||||
static constexpr auto TextureLoadPos = PositionU16::create(320, 256);
|
||||
static constexpr auto CLUTLoadPos = PositionU16::create(320, 511);
|
||||
|
||||
static constexpr TexPage get_tex_page() {
|
||||
return TexPage::create(BIOS_Font::TextureLoadPos, GPU::TexturePageColor::$4bit);
|
||||
}
|
||||
|
||||
static constexpr TPage get_tpage() {
|
||||
return TPage::create(TextureLoadPos.x, TextureLoadPos.y, SemiTransparency::B_add_F, TexturePageColor::$4bit);
|
||||
}
|
||||
|
||||
static constexpr PageOffset get_offset_page() {
|
||||
return PageOffset::create(BIOS_Font::CLUTLoadPos.x & 0x3F, BIOS_Font::CLUTLoadPos.y & 0xFF);
|
||||
}
|
||||
|
||||
static constexpr PageClut get_page_clut() {
|
||||
return PageClut::create(BIOS_Font::CLUTLoadPos);
|
||||
}
|
||||
|
||||
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));
|
||||
return OffsetPageWithClut::create(BIOS_Font::get_offset_page(), BIOS_Font::get_page_clut());
|
||||
}
|
||||
|
||||
static constexpr SimpleTIM as_simple_tim() {
|
||||
return SimpleTIM(BIOS_Font::TextureLoadPos.x, BIOS_Font::TextureLoadPos.y, BIOS_Font::CLUTLoadPos.x, BIOS_Font::CLUTLoadPos.y);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ namespace JabyEngine {
|
|||
uint16_t raw;
|
||||
|
||||
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);
|
||||
return Color().set_red(r >> 3).set_green(g >> 3).set_blue(b >> 3);
|
||||
}
|
||||
|
||||
static constexpr Color from(const Color24& color) {
|
||||
|
@ -156,8 +156,12 @@ namespace JabyEngine {
|
|||
struct LookUpColor8 {
|
||||
uint8_t lu_id[2];
|
||||
|
||||
static constexpr LookUpColor8 from_ids(uint8_t px0, uint8_t px1) {
|
||||
return {{px0, px1}};
|
||||
static constexpr LookUpColor8 create(const uint8_t (&data)[2]) {
|
||||
return LookUpColor8::create(data[0], data[1]);
|
||||
}
|
||||
|
||||
static constexpr LookUpColor8 create(uint8_t px0, uint8_t px1) {
|
||||
return LookUpColor8{{px0, px1}};
|
||||
}
|
||||
|
||||
constexpr uint8_t get_lu_id(size_t at) const {
|
||||
|
@ -172,22 +176,12 @@ namespace JabyEngine {
|
|||
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<uint8_t>((px0 << 4) | px1), static_cast<uint8_t>((px2 << 4) | px3)}};
|
||||
static constexpr LookUpColor4 create(const uint8_t (&data)[4]) {
|
||||
return LookUpColor4::create(data[0], data[1], data[2], data[3]);
|
||||
}
|
||||
|
||||
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<const volatile uint16_t*>(reinterpret_cast<const uint16_t*>(this->lu_id));
|
||||
static constexpr LookUpColor4 create(uint8_t px0, uint8_t px1, uint8_t px2, uint8_t px3) {
|
||||
return LookUpColor4{{static_cast<uint8_t>((px1 << 4) | px0), static_cast<uint8_t>((px3 << 4) | px2)}};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -230,11 +224,11 @@ namespace JabyEngine {
|
|||
}
|
||||
|
||||
template<typename T, typename S>
|
||||
static constexpr T tile_id_for16(S id) {
|
||||
static constexpr T tile_id_for16(S id, Size<S> size) {
|
||||
const auto x = id&0xF;
|
||||
const auto y = id >> 4;
|
||||
|
||||
return T::create(static_cast<S>(x << 4), static_cast<S>(y << 4));
|
||||
return T::create(static_cast<S>(x*size.width), static_cast<S>(y*size.height));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -280,6 +274,10 @@ namespace JabyEngine {
|
|||
static constexpr PageOffset from_tile_id(int16_t id, int16_t row_count, SizeI16 size) {
|
||||
return tile_id_for<PageOffset>(id, row_count, size);
|
||||
}
|
||||
|
||||
static constexpr PageOffset from_tile_id16(int16_t id, SizeI16 size) {
|
||||
return tile_id_for16<PageOffset>(id, size);
|
||||
}
|
||||
};
|
||||
|
||||
struct VertexColor {
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace JabyEngine {
|
|||
constexpr auto DrawOnDisplayAreaBit = BitRange::from_to(10, 10);
|
||||
|
||||
return Helper::construct_cmd<struct GP0>(0xE1,
|
||||
TexXRange.as_value(page_pos.x >> 6) | TexYRange.as_value(page_pos.y >> 7) |
|
||||
TexXRange.as_value(page_pos.x >> 6) | TexYRange.as_value(page_pos.y >> 8) |
|
||||
TransparencyRange.as_value(static_cast<uint32_t>(transparency)) | TextureColorRange.as_value(static_cast<uint32_t>(tex_color)) |
|
||||
DitherBit.as_value(static_cast<uint32_t>(dither)) | DrawOnDisplayAreaBit.as_value(static_cast<uint32_t>(draw_on_display_area))
|
||||
);
|
||||
|
|
|
@ -7,17 +7,25 @@ namespace JabyEngine {
|
|||
struct FontBuffer {
|
||||
// A line of 16 Pixel
|
||||
struct Line {
|
||||
Color pixel[BIOS_Font::Size.width];
|
||||
LookUpColor4 pixel[BIOS_Font::Size.width/4];
|
||||
|
||||
void load(uint16_t bit_pattern) {
|
||||
static constexpr auto BitsPerRound = 4;
|
||||
|
||||
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);
|
||||
for(uint16_t shift = 1 << 15; shift; shift = shift >> BitsPerRound) {
|
||||
uint8_t lu_ids[BitsPerRound];
|
||||
|
||||
for(size_t n = 0; n < BitsPerRound; n++) {
|
||||
lu_ids[n] = (bit_pattern & (shift >> n)) ? 1 : 0;
|
||||
}
|
||||
|
||||
this->pixel[px_idx++] = LookUpColor4::create(lu_ids);
|
||||
}
|
||||
}
|
||||
|
||||
static PositionU16 vram_offset(uint16_t tile_id) {
|
||||
return tile_id_for16<PositionU16>(tile_id);
|
||||
return tile_id_for16<PositionU16>(tile_id, SizeU16::create(4, 16));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -47,7 +55,7 @@ namespace JabyEngine {
|
|||
|
||||
void setup() {
|
||||
for(auto& letter : this->letter_buffer) {
|
||||
letter->setup(SizeU16::create(16, 16));
|
||||
letter->setup(SizeU16::create(16/4, 16));
|
||||
letter.set_link_identitiy();
|
||||
}
|
||||
this->free_idx = 0;
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace JabyEngine {
|
|||
const CLUT clut {
|
||||
.cmd = CPU2VRAM::create(AreaU16::create(dst_cord, GPU::SizeU16::create(16, 1))),
|
||||
.data = {
|
||||
Color::Grey(), Color::White(),
|
||||
Color::Black(), Color::Grey(),
|
||||
Color::Black(), Color::Black(), Color::Black(), Color::Black(), Color::Black(), Color::Black(), Color::Black(),
|
||||
Color::Black(), Color::Black(), Color::Black(), Color::Black(), Color::Black(), Color::Black(), Color::Black(),
|
||||
}
|
||||
|
@ -92,14 +92,6 @@ namespace JabyEngine {
|
|||
}
|
||||
|
||||
void setup() {
|
||||
asm("# Planschi1");
|
||||
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");
|
||||
|
||||
GPU_IO::GP1.write(GPU_IO::Command::Reset());
|
||||
configurate_display();
|
||||
::JabyEngine::GPU::internal::Display::exchange_buffer_and_display();
|
||||
|
|
Loading…
Reference in New Issue