interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / crates / aienos-kernel / src / display / font.rs

365 lines · 8282 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Built-in 5x7 bitmap font for the early boot screen.
17//!
18//! Glyphs are drawn as text so a reviewer can check them by eye. Lowercase
19//! letters render as uppercase; anything without a glyph renders as `?`.
20
21pub const GLYPH_WIDTH: usize = 5;
22pub const GLYPH_HEIGHT: usize = 7;
23
24type Art = [&'static str; GLYPH_HEIGHT];
25
26const GLYPHS: &[(char, Art)] = &[
27 (
28 ' ',
29 [
30 " ", " ", " ", " ", " ", " ", " ",
31 ],
32 ),
33 (
34 '0',
35 [
36 " ### ", "# #", "# ##", "# # #", "## #", "# #", " ### ",
37 ],
38 ),
39 (
40 '1',
41 [
42 " # ", " ## ", " # ", " # ", " # ", " # ", " ### ",
43 ],
44 ),
45 (
46 '2',
47 [
48 " ### ", "# #", " #", " # ", " # ", " # ", "#####",
49 ],
50 ),
51 (
52 '3',
53 [
54 "#####", " # ", " # ", " # ", " #", "# #", " ### ",
55 ],
56 ),
57 (
58 '4',
59 [
60 " # ", " ## ", " # # ", "# # ", "#####", " # ", " # ",
61 ],
62 ),
63 (
64 '5',
65 [
66 "#####", "# ", "#### ", " #", " #", "# #", " ### ",
67 ],
68 ),
69 (
70 '6',
71 [
72 " ## ", " # ", "# ", "#### ", "# #", "# #", " ### ",
73 ],
74 ),
75 (
76 '7',
77 [
78 "#####", " #", " # ", " # ", " # ", " # ", " # ",
79 ],
80 ),
81 (
82 '8',
83 [
84 " ### ", "# #", "# #", " ### ", "# #", "# #", " ### ",
85 ],
86 ),
87 (
88 '9',
89 [
90 " ### ", "# #", "# #", " ####", " #", " # ", " ## ",
91 ],
92 ),
93 (
94 'A',
95 [
96 " ### ", "# #", "# #", "#####", "# #", "# #", "# #",
97 ],
98 ),
99 (
100 'B',
101 [
102 "#### ", "# #", "# #", "#### ", "# #", "# #", "#### ",
103 ],
104 ),
105 (
106 'C',
107 [
108 " ### ", "# #", "# ", "# ", "# ", "# #", " ### ",
109 ],
110 ),
111 (
112 'D',
113 [
114 "#### ", "# #", "# #", "# #", "# #", "# #", "#### ",
115 ],
116 ),
117 (
118 'E',
119 [
120 "#####", "# ", "# ", "#### ", "# ", "# ", "#####",
121 ],
122 ),
123 (
124 'F',
125 [
126 "#####", "# ", "# ", "#### ", "# ", "# ", "# ",
127 ],
128 ),
129 (
130 'G',
131 [
132 " ### ", "# #", "# ", "# ###", "# #", "# #", " ####",
133 ],
134 ),
135 (
136 'H',
137 [
138 "# #", "# #", "# #", "#####", "# #", "# #", "# #",
139 ],
140 ),
141 (
142 'I',
143 [
144 " ### ", " # ", " # ", " # ", " # ", " # ", " ### ",
145 ],
146 ),
147 (
148 'J',
149 [
150 " ###", " # ", " # ", " # ", " # ", "# # ", " ## ",
151 ],
152 ),
153 (
154 'K',
155 [
156 "# #", "# # ", "# # ", "## ", "# # ", "# # ", "# #",
157 ],
158 ),
159 (
160 'L',
161 [
162 "# ", "# ", "# ", "# ", "# ", "# ", "#####",
163 ],
164 ),
165 (
166 'M',
167 [
168 "# #", "## ##", "# # #", "# # #", "# #", "# #", "# #",
169 ],
170 ),
171 (
172 'N',
173 [
174 "# #", "# #", "## #", "# # #", "# ##", "# #", "# #",
175 ],
176 ),
177 (
178 'O',
179 [
180 " ### ", "# #", "# #", "# #", "# #", "# #", " ### ",
181 ],
182 ),
183 (
184 'P',
185 [
186 "#### ", "# #", "# #", "#### ", "# ", "# ", "# ",
187 ],
188 ),
189 (
190 'Q',
191 [
192 " ### ", "# #", "# #", "# #", "# # #", "# # ", " ## #",
193 ],
194 ),
195 (
196 'R',
197 [
198 "#### ", "# #", "# #", "#### ", "# # ", "# # ", "# #",
199 ],
200 ),
201 (
202 'S',
203 [
204 " ####", "# ", "# ", " ### ", " #", " #", "#### ",
205 ],
206 ),
207 (
208 'T',
209 [
210 "#####", " # ", " # ", " # ", " # ", " # ", " # ",
211 ],
212 ),
213 (
214 'U',
215 [
216 "# #", "# #", "# #", "# #", "# #", "# #", " ### ",
217 ],
218 ),
219 (
220 'V',
221 [
222 "# #", "# #", "# #", "# #", "# #", " # # ", " # ",
223 ],
224 ),
225 (
226 'W',
227 [
228 "# #", "# #", "# #", "# # #", "# # #", "# # #", " # # ",
229 ],
230 ),
231 (
232 'X',
233 [
234 "# #", "# #", " # # ", " # ", " # # ", "# #", "# #",
235 ],
236 ),
237 (
238 'Y',
239 [
240 "# #", "# #", " # # ", " # ", " # ", " # ", " # ",
241 ],
242 ),
243 (
244 'Z',
245 [
246 "#####", " #", " # ", " # ", " # ", "# ", "#####",
247 ],
248 ),
249 (
250 ':',
251 [
252 " ", " # ", " # ", " ", " # ", " # ", " ",
253 ],
254 ),
255 (
256 '_',
257 [
258 " ", " ", " ", " ", " ", " ", "#####",
259 ],
260 ),
261 (
262 '.',
263 [
264 " ", " ", " ", " ", " ", " ## ", " ## ",
265 ],
266 ),
267 (
268 ',',
269 [
270 " ", " ", " ", " ", " ## ", " # ", " # ",
271 ],
272 ),
273 (
274 '-',
275 [
276 " ", " ", " ", "#####", " ", " ", " ",
277 ],
278 ),
279 (
280 '/',
281 [
282 " #", " #", " # ", " # ", " # ", "# ", "# ",
283 ],
284 ),
285 (
286 '=',
287 [
288 " ", " ", "#####", " ", "#####", " ", " ",
289 ],
290 ),
291 (
292 '(',
293 [
294 " # ", " # ", " # ", " # ", " # ", " # ", " # ",
295 ],
296 ),
297 (
298 ')',
299 [
300 " # ", " # ", " # ", " # ", " # ", " # ", " # ",
301 ],
302 ),
303 (
304 '#',
305 [
306 " # # ", "#####", " # # ", " # # ", " # # ", "#####", " # # ",
307 ],
308 ),
309 (
310 '?',
311 [
312 " ### ", "# #", " #", " # ", " # ", " ", " # ",
313 ],
314 ),
315];
316
317fn art(c: char) -> &'static Art {
318 let c = c.to_ascii_uppercase();
319 GLYPHS
320 .iter()
321 .find(|(g, _)| *g == c)
322 .or_else(|| GLYPHS.iter().find(|(g, _)| *g == '?'))
323 .map(|(_, a)| a)
324 .expect("font contains '?'")
325}
326
327/// Whether the pixel at column `x`, row `y` of `c`'s glyph is lit.
328pub fn lit(c: char, x: usize, y: usize) -> bool {
329 art(c)
330 .get(y)
331 .and_then(|row| row.as_bytes().get(x))
332 .is_some_and(|b| *b == b'#')
333}
334
335#[cfg(test)]
336mod tests {
337 use super::*;
338
339 #[test]
340 fn every_glyph_is_five_by_seven_hashes_and_spaces() {
341 for (c, rows) in GLYPHS {
342 for row in rows {
343 assert_eq!(row.len(), GLYPH_WIDTH, "glyph {c:?}");
344 assert!(row.bytes().all(|b| b == b' ' || b == b'#'), "glyph {c:?}");
345 }
346 }
347 }
348
349 #[test]
350 fn digits_and_letters_are_distinct() {
351 let chars: std::vec::Vec<char> = ('0'..='9').chain('A'..='Z').collect();
352 for (i, a) in chars.iter().enumerate() {
353 for b in &chars[i + 1..] {
354 assert_ne!(art(*a), art(*b), "{a} and {b} share a glyph");
355 }
356 }
357 }
358
359 #[test]
360 fn lowercase_maps_to_uppercase_and_unknown_to_question_mark() {
361 assert_eq!(art('k'), art('K'));
362 assert_eq!(art('~'), art('?'));
363 assert!(lit('L', 0, 6) && lit('L', 4, 6) && !lit('L', 4, 0));
364 }
365}