Support BIOS Font

This commit is contained in:
2024-01-02 15:42:57 -06:00
parent f96b55a548
commit a67a634fd8
7 changed files with 68 additions and 46 deletions

View File

@@ -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)},

View File

@@ -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);
}
};
}

View File

@@ -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 {

View File

@@ -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))
);