From 7a817120056abc36edc0c00921ee04ce6713e838 Mon Sep 17 00:00:00 2001 From: bQUARKz Date: Mon, 9 Mar 2026 07:35:45 +0000 Subject: [PATCH] fixed some issues into `draw_char` --- crates/console/prometeu-drivers/src/gfx.rs | 141 +++++++++++++-------- 1 file changed, 85 insertions(+), 56 deletions(-) diff --git a/crates/console/prometeu-drivers/src/gfx.rs b/crates/console/prometeu-drivers/src/gfx.rs index 99d92e09..2af12a06 100644 --- a/crates/console/prometeu-drivers/src/gfx.rs +++ b/crates/console/prometeu-drivers/src/gfx.rs @@ -78,6 +78,63 @@ pub struct Gfx { priority_buckets: [Vec; 5], } +const GLYPH_UNKNOWN: [u8; 5] = [0x7, 0x7, 0x7, 0x7, 0x7]; + +#[inline] +fn glyph_for_char(c: char) -> &'static [u8; 5] { + match c.to_ascii_uppercase() { + '0' => &[0x7, 0x5, 0x5, 0x5, 0x7], + '1' => &[0x2, 0x6, 0x2, 0x2, 0x7], + '2' => &[0x7, 0x1, 0x7, 0x4, 0x7], + '3' => &[0x7, 0x1, 0x7, 0x1, 0x7], + '4' => &[0x5, 0x5, 0x7, 0x1, 0x1], + '5' => &[0x7, 0x4, 0x7, 0x1, 0x7], + '6' => &[0x7, 0x4, 0x7, 0x5, 0x7], + '7' => &[0x7, 0x1, 0x1, 0x1, 0x1], + '8' => &[0x7, 0x5, 0x7, 0x5, 0x7], + '9' => &[0x7, 0x5, 0x7, 0x1, 0x7], + 'A' => &[0x7, 0x5, 0x7, 0x5, 0x5], + 'B' => &[0x6, 0x5, 0x6, 0x5, 0x6], + 'C' => &[0x7, 0x4, 0x4, 0x4, 0x7], + 'D' => &[0x6, 0x5, 0x5, 0x5, 0x6], + 'E' => &[0x7, 0x4, 0x6, 0x4, 0x7], + 'F' => &[0x7, 0x4, 0x6, 0x4, 0x4], + 'G' => &[0x7, 0x4, 0x5, 0x5, 0x7], + 'H' => &[0x5, 0x5, 0x7, 0x5, 0x5], + 'I' => &[0x7, 0x2, 0x2, 0x2, 0x7], + 'J' => &[0x1, 0x1, 0x1, 0x5, 0x2], + 'K' => &[0x5, 0x5, 0x6, 0x5, 0x5], + 'L' => &[0x4, 0x4, 0x4, 0x4, 0x7], + 'M' => &[0x5, 0x7, 0x5, 0x5, 0x5], + 'N' => &[0x5, 0x5, 0x5, 0x5, 0x5], + 'O' => &[0x7, 0x5, 0x5, 0x5, 0x7], + 'P' => &[0x7, 0x5, 0x7, 0x4, 0x4], + 'Q' => &[0x7, 0x5, 0x5, 0x7, 0x1], + 'R' => &[0x7, 0x5, 0x6, 0x5, 0x5], + 'S' => &[0x7, 0x4, 0x7, 0x1, 0x7], + 'T' => &[0x7, 0x2, 0x2, 0x2, 0x2], + 'U' => &[0x5, 0x5, 0x5, 0x5, 0x7], + 'V' => &[0x5, 0x5, 0x5, 0x5, 0x2], + 'W' => &[0x5, 0x5, 0x5, 0x7, 0x5], + 'X' => &[0x5, 0x5, 0x2, 0x5, 0x5], + 'Y' => &[0x5, 0x5, 0x2, 0x2, 0x2], + 'Z' => &[0x7, 0x1, 0x2, 0x4, 0x7], + ':' => &[0x0, 0x2, 0x0, 0x2, 0x0], + '.' => &[0x0, 0x0, 0x0, 0x0, 0x2], + ',' => &[0x0, 0x0, 0x0, 0x2, 0x4], + '!' => &[0x2, 0x2, 0x2, 0x0, 0x2], + '?' => &[0x7, 0x1, 0x2, 0x0, 0x2], + ' ' => &[0x0, 0x0, 0x0, 0x0, 0x0], + '|' => &[0x2, 0x2, 0x2, 0x2, 0x2], + '/' => &[0x1, 0x1, 0x2, 0x4, 0x4], + '(' => &[0x2, 0x4, 0x4, 0x4, 0x2], + ')' => &[0x2, 0x1, 0x1, 0x1, 0x2], + '>' => &[0x4, 0x2, 0x1, 0x2, 0x4], + '<' => &[0x1, 0x2, 0x4, 0x2, 0x1], + _ => &GLYPH_UNKNOWN, + } +} + impl GfxBridge for Gfx { fn size(&self) -> (usize, usize) { self.size() @@ -802,64 +859,36 @@ impl Gfx { } fn draw_char(&mut self, x: i32, y: i32, c: char, color: Color) { - let glyph: [u8; 5] = match c.to_ascii_uppercase() { - '0' => [0x7, 0x5, 0x5, 0x5, 0x7], - '1' => [0x2, 0x6, 0x2, 0x2, 0x7], - '2' => [0x7, 0x1, 0x7, 0x4, 0x7], - '3' => [0x7, 0x1, 0x7, 0x1, 0x7], - '4' => [0x5, 0x5, 0x7, 0x1, 0x1], - '5' => [0x7, 0x4, 0x7, 0x1, 0x7], - '6' => [0x7, 0x4, 0x7, 0x5, 0x7], - '7' => [0x7, 0x1, 0x1, 0x1, 0x1], - '8' => [0x7, 0x5, 0x7, 0x5, 0x7], - '9' => [0x7, 0x5, 0x7, 0x1, 0x7], - 'A' => [0x7, 0x5, 0x7, 0x5, 0x5], - 'B' => [0x6, 0x5, 0x6, 0x5, 0x6], - 'C' => [0x7, 0x4, 0x4, 0x4, 0x7], - 'D' => [0x6, 0x5, 0x5, 0x5, 0x6], - 'E' => [0x7, 0x4, 0x6, 0x4, 0x7], - 'F' => [0x7, 0x4, 0x6, 0x4, 0x4], - 'G' => [0x7, 0x4, 0x5, 0x5, 0x7], - 'H' => [0x5, 0x5, 0x7, 0x5, 0x5], - 'I' => [0x7, 0x2, 0x2, 0x2, 0x7], - 'J' => [0x1, 0x1, 0x1, 0x5, 0x2], - 'K' => [0x5, 0x5, 0x6, 0x5, 0x5], - 'L' => [0x4, 0x4, 0x4, 0x4, 0x7], - 'M' => [0x5, 0x7, 0x5, 0x5, 0x5], - 'N' => [0x5, 0x5, 0x5, 0x5, 0x5], - 'O' => [0x7, 0x5, 0x5, 0x5, 0x7], - 'P' => [0x7, 0x5, 0x7, 0x4, 0x4], - 'Q' => [0x7, 0x5, 0x5, 0x7, 0x1], - 'R' => [0x7, 0x5, 0x6, 0x5, 0x5], - 'S' => [0x7, 0x4, 0x7, 0x1, 0x7], - 'T' => [0x7, 0x2, 0x2, 0x2, 0x2], - 'U' => [0x5, 0x5, 0x5, 0x5, 0x7], - 'V' => [0x5, 0x5, 0x5, 0x5, 0x2], - 'W' => [0x5, 0x5, 0x5, 0x7, 0x5], - 'X' => [0x5, 0x5, 0x2, 0x5, 0x5], - 'Y' => [0x5, 0x5, 0x2, 0x2, 0x2], - 'Z' => [0x7, 0x1, 0x2, 0x4, 0x7], - ':' => [0x0, 0x2, 0x0, 0x2, 0x0], - '.' => [0x0, 0x0, 0x0, 0x0, 0x2], - ',' => [0x0, 0x0, 0x0, 0x2, 0x4], - '!' => [0x2, 0x2, 0x2, 0x0, 0x2], - '?' => [0x7, 0x1, 0x2, 0x0, 0x2], - ' ' => [0x0, 0x0, 0x0, 0x0, 0x0], - '|' => [0x2, 0x2, 0x2, 0x2, 0x2], - '/' => [0x1, 0x1, 0x2, 0x4, 0x4], - '(' => [0x2, 0x4, 0x4, 0x4, 0x2], - ')' => [0x2, 0x1, 0x1, 0x1, 0x2], - '>' => [0x4, 0x2, 0x1, 0x2, 0x4], - '<' => [0x1, 0x2, 0x4, 0x2, 0x1], - _ => [0x7, 0x7, 0x7, 0x7, 0x7], - }; + if color == Color::COLOR_KEY { + return; + } - for (row_idx, row) in glyph.iter().enumerate() { - for col_idx in 0..3 { + let screen_w = self.w as i32; + let screen_h = self.h as i32; + if x >= screen_w || y >= screen_h || x + 3 <= 0 || y + 5 <= 0 { + return; + } + + let glyph = glyph_for_char(c); + let raw = color.0; + + let row_start = (-y).max(0).min(5) as usize; + let row_end = (screen_h - y).max(0).min(5) as usize; + let col_start = (-x).max(0).min(3) as usize; + let col_end = (screen_w - x).max(0).min(3) as usize; + + for (row_idx, row) in glyph + .iter() + .enumerate() + .skip(row_start) + .take(row_end.saturating_sub(row_start)) + { + let py = (y + row_idx as i32) as usize; + let base = py * self.w; + for col_idx in col_start..col_end { if (row >> (2 - col_idx)) & 1 == 1 { - let px = x + col_idx; - let py = y + row_idx as i32; - self.draw_pixel(px, py, color); + let px = (x + col_idx as i32) as usize; + self.back[base + px] = raw; } } }