font_bitmap: use 4bpp palette

This commit is contained in:
Zack Buhman 2023-12-20 22:28:42 +08:00
parent 7330ccc8e0
commit 7e03eee3ed
3 changed files with 53 additions and 6 deletions

View File

@ -33,8 +33,8 @@ MACAW_TWIDDLE_OBJ = \
example/macaw_twiddle.elf: LDSCRIPT = $(LIB)/alt.lds example/macaw_twiddle.elf: LDSCRIPT = $(LIB)/alt.lds
example/macaw_twiddle.elf: $(START_OBJ) $(MACAW_TWIDDLE_OBJ) example/macaw_twiddle.elf: $(START_OBJ) $(MACAW_TWIDDLE_OBJ)
FONT_OBJ = \ FONT_BITMAP_OBJ = \
example/font.o \ example/font_bitmap.o \
vga.o \ vga.o \
holly/core.o \ holly/core.o \
holly/region_array.o \ holly/region_array.o \
@ -43,8 +43,8 @@ FONT_OBJ = \
serial.o \ serial.o \
sperrypc.data.o sperrypc.data.o
example/font.elf: LDSCRIPT = $(LIB)/alt.lds example/font_bitmap.elf: LDSCRIPT = $(LIB)/alt.lds
example/font.elf: $(START_OBJ) $(FONT_OBJ) example/font_bitmap.elf: $(START_OBJ) $(FONT_BITMAP_OBJ)
MACAW_MULTIPASS_OBJ = \ MACAW_MULTIPASS_OBJ = \
example/macaw_multipass.o \ example/macaw_multipass.o \

View File

@ -107,7 +107,7 @@ uint32_t transform(uint32_t * ta_parameter_buf, const char * s, const uint32_t l
| tsp_instruction_word::texture_u_size::_8 // 8px | tsp_instruction_word::texture_u_size::_8 // 8px
| tsp_instruction_word::texture_v_size::_8; // 8px | tsp_instruction_word::texture_v_size::_8; // 8px
polygon.texture_control_word = texture_control_word::pixel_format::_8bpp_palette polygon.texture_control_word = texture_control_word::pixel_format::_4bpp_palette
| texture_control_word::scan_order::twiddled | texture_control_word::scan_order::twiddled
| texture_control_word::texture_address((texture_address + 8 * 8 * (s[string_ix] - ' ')) / 8); | texture_control_word::texture_address((texture_address + 8 * 8 * (s[string_ix] - ' ')) / 8);
parameter.append<global_polygon_type_0>() = polygon; parameter.append<global_polygon_type_0>() = polygon;
@ -182,7 +182,7 @@ inline void inflate_character(const uint8_t * src, const uint8_t c)
} temp2; } temp2;
//twiddle::texture(&texture[offset], temp, 8, 8); //twiddle::texture(&texture[offset], temp, 8, 8);
twiddle::texture(temp2.u8, temp, 8, 8); twiddle::texture_4bpp(temp2.u8, temp, 8, 8);
for (uint32_t i = 0; i < 8 * 8 / 4; i++) { for (uint32_t i = 0; i < 8 * 8 / 4; i++) {
texture[(offset / 4) + i] = temp2.u32[i]; texture[(offset / 4) + i] = temp2.u32[i];
} }

View File

@ -1,4 +1,5 @@
#include <cstdint> #include <cstdint>
#include <array>
namespace twiddle { namespace twiddle {
@ -57,6 +58,38 @@ static_assert(from_xy(0b000, 0b101) == 17);
static_assert(from_xy(0b000, 0b110) == 20); static_assert(from_xy(0b000, 0b110) == 20);
static_assert(from_xy(0b000, 0b111) == 21); static_assert(from_xy(0b000, 0b111) == 21);
constexpr inline std::array<uint32_t, 2>
from_ix(uint32_t curve_ix)
{
std::array<uint32_t, 2> x_y = {0, 0};
uint32_t curve_bit = 0;
while (curve_ix != 0) {
x_y[(curve_bit + 1) % 2] |= (curve_ix & 1) << (curve_bit / 2);
curve_ix >>= 1;
curve_bit += 1;
}
return x_y;
}
static_assert(from_ix(0) == std::array<uint32_t, 2>{{0b000, 0b000}});
static_assert(from_ix(2) == std::array<uint32_t, 2>{{0b001, 0b000}});
static_assert(from_ix(8) == std::array<uint32_t, 2>{{0b010, 0b000}});
static_assert(from_ix(10) == std::array<uint32_t, 2>{{0b011, 0b000}});
static_assert(from_ix(32) == std::array<uint32_t, 2>{{0b100, 0b000}});
static_assert(from_ix(34) == std::array<uint32_t, 2>{{0b101, 0b000}});
static_assert(from_ix(40) == std::array<uint32_t, 2>{{0b110, 0b000}});
static_assert(from_ix(42) == std::array<uint32_t, 2>{{0b111, 0b000}});
static_assert(from_ix(1) == std::array<uint32_t, 2>{{0b000, 0b001}});
static_assert(from_ix(4) == std::array<uint32_t, 2>{{0b000, 0b010}});
static_assert(from_ix(5) == std::array<uint32_t, 2>{{0b000, 0b011}});
static_assert(from_ix(16) == std::array<uint32_t, 2>{{0b000, 0b100}});
static_assert(from_ix(17) == std::array<uint32_t, 2>{{0b000, 0b101}});
static_assert(from_ix(20) == std::array<uint32_t, 2>{{0b000, 0b110}});
static_assert(from_ix(21) == std::array<uint32_t, 2>{{0b000, 0b111}});
template <typename T> template <typename T>
void texture(volatile T * dst, const T * src, const uint32_t width, const uint32_t height) void texture(volatile T * dst, const T * src, const uint32_t width, const uint32_t height)
{ {
@ -69,4 +102,18 @@ void texture(volatile T * dst, const T * src, const uint32_t width, const uint32
} }
} }
template <typename T>
void texture_4bpp(volatile T * dst, const T * src, const uint32_t width, const uint32_t height)
{
for (uint32_t y = 0; y < height; y++) {
for (uint32_t x = 0; x < width; x++) {
uint32_t twiddle_ix = from_xy(x, y);
T value = src[y * width + x];
uint32_t shift = (4 * (twiddle_ix & 1));
dst[twiddle_ix / 2] &= ~(0b1111 << shift);
dst[twiddle_ix / 2] |= value << shift;
}
}
}
} }