diff --git a/app b/app index 7676370..8a89bc8 100755 Binary files a/app and b/app differ diff --git a/fonts/7linedigital_font.h b/fonts/7linedigital_font.h index 055c045..cc4f4fc 100644 --- a/fonts/7linedigital_font.h +++ b/fonts/7linedigital_font.h @@ -1,4 +1,4 @@ -const unsigned char font_7linedigital[96][6] = { +const unsigned char font_7linedigital[96][4] = { {0x00,0x00,0x00,0x00}, // {0x36,0x00,0x00,0x00}, // ! {0x06,0x00,0x00,0x06}, // " diff --git a/fonts/BMSPA_font.h b/fonts/BMSPA_font.h index 845d34b..105cc6f 100644 --- a/fonts/BMSPA_font.h +++ b/fonts/BMSPA_font.h @@ -1,4 +1,4 @@ -const unsigned char font_BMSPA[96][6] = { +const unsigned char font_BMSPA[96][8] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // {0x00,0x5f,0x00,0x00,0x00,0x00,0x00,0x00}, // ! {0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00}, // " diff --git a/fonts/Commo-Monospaced_font.h b/fonts/Commo-Monospaced_font.h index 03622a3..7d39f1b 100644 --- a/fonts/Commo-Monospaced_font.h +++ b/fonts/Commo-Monospaced_font.h @@ -1,4 +1,4 @@ -const unsigned char font_Commo-Monospaced[96][6] = { +const unsigned char font_Commo_Monospaced[96][8] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // {0x5f,0x5c,0x00,0x00,0x00,0x00,0x00,0x00}, // ! {0x03,0x07,0x00,0x03,0x07,0x00,0x00,0x00}, // " diff --git a/fonts/HUNTER_font.h b/fonts/HUNTER_font.h index 66015cd..27ec66f 100644 --- a/fonts/HUNTER_font.h +++ b/fonts/HUNTER_font.h @@ -1,4 +1,4 @@ -const unsigned char font_HUNTER[96][6] = { +const unsigned char font_HUNTER[96][8] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // {0x5f,0x5f,0x00,0x00,0x00,0x00,0x00,0x00}, // ! {0x07,0x07,0x00,0x07,0x07,0x00,0x00,0x00}, // " diff --git a/fonts/Minimum+1_font.h b/fonts/Minimum_1_font.h similarity index 96% rename from fonts/Minimum+1_font.h rename to fonts/Minimum_1_font.h index 5a4a474..b06e970 100644 --- a/fonts/Minimum+1_font.h +++ b/fonts/Minimum_1_font.h @@ -1,4 +1,4 @@ -const unsigned char font_Minimum+1[96][6] = { +const unsigned char font_Minimum_1[96][7] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // {0x7f,0x51,0x7f,0x00,0x00,0x00,0x00}, // ! {0x0f,0x09,0x0f,0x09,0x0f,0x00,0x00}, // " diff --git a/fonts/Raumsond_font.h b/fonts/Raumsond_font.h index 681cc9b..1441033 100644 --- a/fonts/Raumsond_font.h +++ b/fonts/Raumsond_font.h @@ -1,4 +1,4 @@ -const unsigned char font_Raumsond[96][6] = { +const unsigned char font_Raumsond[96][5] = { {0x00,0x00,0x00,0x00,0x00}, // {0x5c,0x00,0x00,0x00,0x00}, // ! {0x0c,0x00,0x0c,0x00,0x00}, // " diff --git a/fonts/bubblesstandard_font.h b/fonts/bubblesstandard_font.h index b2215e4..6b7f406 100644 --- a/fonts/bubblesstandard_font.h +++ b/fonts/bubblesstandard_font.h @@ -1,4 +1,4 @@ -const unsigned char font_bubblesstandard[96][6] = { +const unsigned char font_bubblesstandard[96][7] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // {0xbf,0x00,0x00,0x00,0x00,0x00,0x00}, // ! {0x03,0x00,0x03,0x00,0x00,0x00,0x00}, // " diff --git a/fonts/formplex12_font.h b/fonts/formplex12_font.h index 26cf79b..257a333 100644 --- a/fonts/formplex12_font.h +++ b/fonts/formplex12_font.h @@ -1,4 +1,4 @@ -const unsigned char font_formplex12[96][6] = { +const unsigned char font_formplex12[96][8] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // {0x00,0x2f,0x2f,0x00,0x00,0x00,0x00,0x00}, // ! {0x03,0x03,0x00,0x03,0x03,0x00,0x00,0x00}, // " diff --git a/fonts/homespun_font.h b/fonts/homespun_font.h index 5f8727c..2d5a1ee 100644 --- a/fonts/homespun_font.h +++ b/fonts/homespun_font.h @@ -1,4 +1,4 @@ -const unsigned char font_homespun[96][6] = { +const unsigned char font_homespun[96][7] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // {0x5f,0x00,0x00,0x00,0x00,0x00,0x00}, // ! {0x03,0x00,0x03,0x00,0x00,0x00,0x00}, // " diff --git a/fonts/m38_font.h b/fonts/m38_font.h index 4d88789..34e3b1b 100644 --- a/fonts/m38_font.h +++ b/fonts/m38_font.h @@ -1,4 +1,4 @@ -const unsigned char font_m38[96][6] = { +const unsigned char font_m38[96][8] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // {0xdf,0xdf,0x00,0x00,0x00,0x00,0x00,0x00}, // ! {0x07,0x07,0x00,0x07,0x07,0x00,0x00,0x00}, // " diff --git a/fonts/pzim3x5_font.h b/fonts/pzim3x5_font.h index 9a4c205..9708799 100644 --- a/fonts/pzim3x5_font.h +++ b/fonts/pzim3x5_font.h @@ -1,4 +1,4 @@ -const unsigned char font_pzim3x5[96][6] = { +const unsigned char font_pzim3x5[96][3] = { {0x00,0x00,0x00}, // {0x00,0x2e,0x00}, // ! {0x06,0x00,0x06}, // " diff --git a/fonts/renew_font.h b/fonts/renew_font.h index 934819c..7c06f75 100644 --- a/fonts/renew_font.h +++ b/fonts/renew_font.h @@ -1,4 +1,4 @@ -const unsigned char font_renew[96][6] = { +const unsigned char font_renew[96][7] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // {0x5e,0x00,0x00,0x00,0x00,0x00,0x00}, // ! {0x0c,0x00,0x0c,0x00,0x00,0x00,0x00}, // " diff --git a/fonts/tama_mini02_font.h b/fonts/tama_mini02_font.h index e9b7c57..afb569f 100644 --- a/fonts/tama_mini02_font.h +++ b/fonts/tama_mini02_font.h @@ -1,4 +1,4 @@ -const unsigned char font_tama_mini02[96][6] = { +const unsigned char font_tama_mini02[96][5] = { {0x00,0x00,0x00,0x00,0x00}, // {0x2f,0x00,0x00,0x00,0x00}, // ! {0x03,0x00,0x03,0x00,0x00}, // " diff --git a/low_level_render.cpp b/low_level_render.cpp index af98b62..edc8a16 100644 --- a/low_level_render.cpp +++ b/low_level_render.cpp @@ -3,7 +3,6 @@ #include #include #include "./fonts/5x5_font.h" -#include "./fonts/7linedigital_font.h" #include "./fonts/BMplain_font.h" #include "./fonts/Blokus_font.h" #include "./fonts/HISKYF21_font.h" @@ -15,12 +14,52 @@ #include "./fonts/haiku_font.h" #include "./fonts/sloth_font.h" #include "./fonts/zxpix_font.h" +#include "./fonts/Commo-Monospaced_font.h" +#include "./fonts/7linedigital_font.h" +#include "./fonts/BMSPA_font.h" +#include "./fonts/HUNTER_font.h" +#include "./fonts/Raumsond_font.h" +#include "./fonts/bubblesstandard_font.h" +#include "./fonts/formplex12_font.h" +#include "./fonts/homespun_font.h" +#include "./fonts/Minimum_1_font.h" +#include "./fonts/m38_font.h" +#include "./fonts/pzim3x5_font.h" +#include "./fonts/renew_font.h" +#include "./fonts/tama_mini02_font.h" + +// Font object definitions +Font font_5x5_obj(reinterpret_cast(font_5x5), 96, 6, 8); +Font font_7linedigital_obj(reinterpret_cast(font_7linedigital), 96, 4, 8); +Font font_acme_5_outlines_obj(reinterpret_cast(font_acme_5_outlines), 96, 6, 8); +Font font_aztech_obj(reinterpret_cast(font_aztech), 96, 6, 8); +Font font_BMplain_obj(reinterpret_cast(font_BMplain), 96, 6, 8); +Font font_BMSPA_obj(reinterpret_cast(font_BMSPA), 96, 8, 8); +Font font_Blokus_obj(reinterpret_cast(font_Blokus), 96, 6, 8); +Font font_bubblesstandard_obj(reinterpret_cast(font_bubblesstandard), 96, 7, 8); +Font font_Commo_Monospaced_obj(reinterpret_cast(font_Commo_Monospaced), 96, 8, 8); +Font font_crackers_obj(reinterpret_cast(font_crackers), 96, 6, 8); +Font font_formplex12_obj(reinterpret_cast(font_formplex12), 96, 8, 8); +Font font_haiku_obj(reinterpret_cast(font_haiku), 96, 6, 8); +Font font_HISKYF21_obj(reinterpret_cast(font_HISKYF21), 96, 6, 8); +Font font_homespun_obj(reinterpret_cast(font_homespun), 96, 7, 8); +Font font_HUNTER_obj(reinterpret_cast(font_HUNTER), 96, 8, 8); +Font font_m38_obj(reinterpret_cast(font_m38), 96, 8, 8); +Font font_Minimum_obj(reinterpret_cast(font_Minimum), 96, 6, 8); +Font font_Minimum_1_obj(reinterpret_cast(font_Minimum_1), 96, 7, 8); +Font font_pzim3x5_obj(reinterpret_cast(font_pzim3x5), 96, 3, 8); +Font font_Raumsond_obj(reinterpret_cast(font_Raumsond), 96, 5, 8); +Font font_renew_obj(reinterpret_cast(font_renew), 96, 7, 8); +Font font_sloth_obj(reinterpret_cast(font_sloth), 96, 6, 8); +Font font_SUPERDIG_obj(reinterpret_cast(font_SUPERDIG), 96, 6, 8); +Font font_tama_mini02_obj(reinterpret_cast(font_tama_mini02), 96, 5, 8); +Font font_zxpix_obj(reinterpret_cast(font_zxpix), 96, 6, 8); LowLevelRenderer::LowLevelRenderer(uint8_t* buffer, int width, int height) - : bit_buffer(buffer), V_WIDTH(width), V_HEIGHT(height), current_font(&font_acme_5_outlines), + : bit_buffer(buffer), V_WIDTH(width), V_HEIGHT(height), current_font(nullptr), clipping_enabled(false), clip_x(0), clip_y(0), clip_width(width), clip_height(height), text_color(true) {} -void LowLevelRenderer::set_font(const unsigned char (*font)[96][6]) { +void LowLevelRenderer::set_font(const Font* font) { current_font = font; } @@ -488,19 +527,26 @@ void LowLevelRenderer::draw_filled_circle(int x, int y, int radius, bool on) void LowLevelRenderer::draw_char_vcol(int x, int y, char c) { + if (!current_font) return; + // The font table starts at space (ASCII 32) if (c < 32 || c > 127) return; int font_idx = c - 32; - for (int col = 0; col < 6; col++) - { - unsigned char column_byte = (*current_font)[font_idx][col]; + const unsigned char* char_data = current_font->get_char_data(font_idx); + if (!char_data) return; - for (int row = 0; row < 8; row++) + int bytes_per_char = current_font->get_bytes_per_char(); + int char_height = current_font->get_char_height(); + + for (int col = 0; col < bytes_per_char; col++) + { + unsigned char column_byte = char_data[col]; + + for (int row = 0; row < char_height; row++) { // Check if the bit for this row is set - // Most of these 1-bit fonts use bit 0 as the top pixel if (column_byte & (1 << row)) { set_pixel(x + col, y + row, text_color); @@ -511,26 +557,35 @@ void LowLevelRenderer::draw_char_vcol(int x, int y, char c) void LowLevelRenderer::draw_string(int x, int y, const std::string &text, int spacing) { + if (!current_font) return; + int char_width = current_font->get_bytes_per_char(); for (size_t i = 0; i < text.length(); i++) { - draw_char_vcol(x + (i * (6 + spacing)), y, text[i]); + draw_char_vcol(x + (i * (char_width + spacing)), y, text[i]); } } void LowLevelRenderer::draw_char_scaled(int x, int y, char c, int scale) { + if (!current_font) return; + if (c < 32 || c > 127) return; if (scale < 1) scale = 1; // Safety check int font_idx = c - 32; + const unsigned char* char_data = current_font->get_char_data(font_idx); + if (!char_data) return; - for (int col = 0; col < 6; col++) + int bytes_per_char = current_font->get_bytes_per_char(); + int char_height = current_font->get_char_height(); + + for (int col = 0; col < bytes_per_char; col++) { - unsigned char column_byte = (*current_font)[font_idx][col]; + unsigned char column_byte = char_data[col]; - for (int row = 0; row < 8; row++) + for (int row = 0; row < char_height; row++) { if (column_byte & (1 << row)) { @@ -551,11 +606,13 @@ void LowLevelRenderer::draw_char_scaled(int x, int y, char c, int scale) void LowLevelRenderer::draw_string_scaled(int x, int y, const char* text, int scale, int spacing) { + if (!current_font) return; + int char_width = current_font->get_bytes_per_char(); int i = 0; while(text[i] != '\0') { - // We multiply the character width (6) and spacing by the scale - int next_x = x + (i * (6 + spacing) * scale); + // We multiply the character width and spacing by the scale + int next_x = x + (i * (char_width + spacing) * scale); draw_char_scaled(next_x, y, text[i], scale); i++; } diff --git a/low_level_render.h b/low_level_render.h index 8edc0c6..fe725ec 100644 --- a/low_level_render.h +++ b/low_level_render.h @@ -12,27 +12,91 @@ #include #include +// Font class that holds font data and dimensions +class Font { +private: + const unsigned char* data; + int num_chars; + int bytes_per_char; + int char_height; + +public: + Font(const unsigned char* font_data, int num_chars, int bytes_per_char, int char_height) + : data(font_data), num_chars(num_chars), bytes_per_char(bytes_per_char), + char_height(char_height) {} + + const unsigned char* get_data() const { return data; } + int get_num_chars() const { return num_chars; } + int get_bytes_per_char() const { return bytes_per_char; } + int get_char_height() const { return char_height; } + + // Get a specific character's data + const unsigned char* get_char_data(int char_index) const { + if (char_index < 0 || char_index >= num_chars) return nullptr; + return data + (char_index * bytes_per_char); + } +}; + // Font extern declarations extern const unsigned char font_5x5[96][6]; -extern const unsigned char font_7linedigital[96][6]; -extern const unsigned char font_BMplain[96][6]; -extern const unsigned char font_Blokus[96][6]; -extern const unsigned char font_HISKYF21[96][6]; -extern const unsigned char font_Minimum[96][6]; -extern const unsigned char font_SUPERDIG[96][6]; +extern const unsigned char font_7linedigital[96][4]; extern const unsigned char font_acme_5_outlines[96][6]; extern const unsigned char font_aztech[96][6]; +extern const unsigned char font_BMplain[96][6]; +extern const unsigned char font_BMSPA[96][8]; +extern const unsigned char font_Blokus[96][6]; +extern const unsigned char font_bubblesstandard[96][7]; +extern const unsigned char font_Commo_Monospaced[96][8]; extern const unsigned char font_crackers[96][6]; +extern const unsigned char font_formplex12[96][8]; extern const unsigned char font_haiku[96][6]; +extern const unsigned char font_HISKYF21[96][6]; +extern const unsigned char font_homespun[96][7]; +extern const unsigned char font_HUNTER[96][8]; +extern const unsigned char font_m38[96][8]; +extern const unsigned char font_Minimum[96][6]; +extern const unsigned char font_Minimum_1[96][7]; +extern const unsigned char font_pzim3x5[96][3]; +extern const unsigned char font_Raumsond[96][5]; +extern const unsigned char font_renew[96][7]; extern const unsigned char font_sloth[96][6]; +extern const unsigned char font_SUPERDIG[96][6]; +extern const unsigned char font_tama_mini02[96][5]; extern const unsigned char font_zxpix[96][6]; +// Font object declarations +extern Font font_5x5_obj; +extern Font font_7linedigital_obj; +extern Font font_acme_5_outlines_obj; +extern Font font_aztech_obj; +extern Font font_BMplain_obj; +extern Font font_BMSPA_obj; +extern Font font_Blokus_obj; +extern Font font_bubblesstandard_obj; +extern Font font_Commo_Monospaced_obj; +extern Font font_crackers_obj; +extern Font font_formplex12_obj; +extern Font font_haiku_obj; +extern Font font_HISKYF21_obj; +extern Font font_homespun_obj; +extern Font font_HUNTER_obj; +extern Font font_m38_obj; +extern Font font_Minimum_obj; +extern Font font_Minimum_1_obj; +extern Font font_pzim3x5_obj; +extern Font font_Raumsond_obj; +extern Font font_renew_obj; +extern Font font_sloth_obj; +extern Font font_SUPERDIG_obj; +extern Font font_tama_mini02_obj; +extern Font font_zxpix_obj; + class LowLevelRenderer { private: uint8_t* bit_buffer; int V_WIDTH; int V_HEIGHT; - const unsigned char (*current_font)[96][6]; + const Font* current_font; bool clipping_enabled; int clip_x, clip_y, clip_width, clip_height; bool text_color; @@ -45,7 +109,7 @@ public: LowLevelRenderer(uint8_t* buffer, int width, int height); // Font management - void set_font(const unsigned char (*font)[96][6]); + void set_font(const Font* font); void set_text_color(bool color); // --- 1-BIT DRAWING PRIMITIVES --- diff --git a/low_level_render.o b/low_level_render.o new file mode 100644 index 0000000..9c4697c Binary files /dev/null and b/low_level_render.o differ diff --git a/main.cpp b/main.cpp index 858e1ba..b771d33 100644 --- a/main.cpp +++ b/main.cpp @@ -146,14 +146,15 @@ int main() renderer.set_clip_rect(300, 200, 80, 60); // Small rectangle in bottom-right renderer.draw_filled_circle(340, 230, 40, true); // Circle that extends outside clip rect renderer.reset_clip_rect(); // Reset to full screen - - // Text with different fonts - renderer.set_font(&font_acme_5_outlines); - renderer.draw_string_scaled(10, 10, "Drawing Demo", 2); - */ - renderer.set_font(&font_SUPERDIG); + // Text with different fonts + renderer.set_font(&font_HISKYF21_obj); + renderer.draw_string_scaled(10, 10, "Drawing Demo", 2); + + + + renderer.set_font(&font_SUPERDIG_obj); renderer.draw_string_scaled(10, 270, command_buffer, 1);