@@ -51,15 +51,13 @@ static FONT: &[u8] = include_bytes!("../../font.bin");
51
51
// -----------------------------------------------------|
52
52
// ```
53
53
54
- const DEFAULT_FONT_WIDTH : usize = 8 ;
55
- const DEFAULT_FONT_HEIGHT : usize = 16 ;
54
+ const FONT_WIDTH : usize = 8 ;
55
+ const FONT_HEIGHT : usize = 16 ;
56
56
57
57
const DEFAULT_MARGIN : usize = 64 / 2 ;
58
-
59
58
const TAB_SIZE : usize = 4 ;
60
59
61
60
/// The amount of VGA font glyphs.
62
- const VGA_FONT_GLYPHS : usize = 256 ;
63
61
64
62
const MARGIN_GRADIENT : usize = 4 ;
65
63
const DWORD_SIZE : usize = core:: mem:: size_of :: < u32 > ( ) ;
@@ -216,13 +214,8 @@ pub struct DebugRendy<'this> {
216
214
map : Box < [ Option < * mut QueueCharacter > ] > ,
217
215
bg_canvas : Box < [ u32 ] > ,
218
216
219
- vga_font_bool : Box < [ bool ] > ,
220
-
221
217
queue_cursor : usize ,
222
218
223
- glyph_width : usize ,
224
- glyph_height : usize ,
225
-
226
219
offset_x : usize ,
227
220
offset_y : usize ,
228
221
@@ -237,17 +230,11 @@ impl<'this> DebugRendy<'this> {
237
230
let width = info. horizontal_resolution ;
238
231
let height = info. vertical_resolution ;
239
232
240
- let glyph_width = DEFAULT_FONT_WIDTH ;
241
- let glyph_height = DEFAULT_FONT_HEIGHT ;
233
+ let offset_x = DEFAULT_MARGIN + ( ( width - DEFAULT_MARGIN * 2 ) % FONT_WIDTH ) / 2 ;
234
+ let offset_y = DEFAULT_MARGIN + ( ( height - DEFAULT_MARGIN * 2 ) % FONT_HEIGHT ) / 2 ;
242
235
243
- let offset_x =
244
- DEFAULT_MARGIN + ( ( info. horizontal_resolution - DEFAULT_MARGIN * 2 ) % glyph_width) / 2 ;
245
-
246
- let offset_y =
247
- DEFAULT_MARGIN + ( ( info. horizontal_resolution - DEFAULT_MARGIN * 2 ) % glyph_height) / 2 ;
248
-
249
- let cols = ( info. horizontal_resolution - DEFAULT_MARGIN * 2 ) / glyph_width;
250
- let rows = ( info. vertical_resolution - DEFAULT_MARGIN * 2 ) / glyph_height;
236
+ let cols = ( width - DEFAULT_MARGIN * 2 ) / FONT_WIDTH ;
237
+ let rows = ( height - DEFAULT_MARGIN * 2 ) / FONT_HEIGHT ;
251
238
252
239
let grid_size = rows * cols * core:: mem:: size_of :: < Character > ( ) ;
253
240
let grid = mem:: alloc_boxed_buffer :: < Character > ( grid_size) ;
@@ -261,50 +248,6 @@ impl<'this> DebugRendy<'this> {
261
248
let bg_canvas_size = width * height * core:: mem:: size_of :: < u32 > ( ) ;
262
249
let bg_canvas = mem:: alloc_boxed_buffer :: < u32 > ( bg_canvas_size) ;
263
250
264
- let vga_font_bool_size = VGA_FONT_GLYPHS
265
- * DEFAULT_FONT_HEIGHT
266
- * DEFAULT_FONT_WIDTH
267
- * core:: mem:: size_of :: < bool > ( ) ;
268
-
269
- let mut vga_font_bool = mem:: alloc_boxed_buffer :: < bool > ( vga_font_bool_size) ;
270
-
271
- for i in 0 ..VGA_FONT_GLYPHS {
272
- // Each glyph is a bitmap:
273
- let glyph = & FONT [ i * DEFAULT_FONT_HEIGHT ] as * const u8 ;
274
-
275
- for y in 0 ..DEFAULT_FONT_HEIGHT {
276
- // NOTE: the characters in VGA fonts are always one byte wide.
277
- // 9 dot wide fonts have 8 dots and one empty column, except
278
- // characters 0xC0-0xDF replicate column 9.
279
- for x in 0 ..8 {
280
- let offset =
281
- i * DEFAULT_FONT_HEIGHT * DEFAULT_FONT_WIDTH + y * DEFAULT_FONT_WIDTH + x;
282
-
283
- unsafe {
284
- if ( * glyph. offset ( y as isize ) & ( 0x80 >> x) ) != 0 {
285
- vga_font_bool[ offset] = true ;
286
- } else {
287
- vga_font_bool[ offset] = false ;
288
- }
289
- }
290
- }
291
-
292
- // Fill columns above 8 like VGA Line Graphics Mode does:
293
- for x in 8 ..DEFAULT_FONT_WIDTH {
294
- let offset =
295
- i * DEFAULT_FONT_HEIGHT * DEFAULT_FONT_WIDTH + y * DEFAULT_FONT_WIDTH + x;
296
-
297
- if i >= 0xC0 && i <= 0xDF {
298
- unsafe {
299
- vga_font_bool[ offset] = ( * glyph. offset ( y as isize ) & 1 ) != 0 ;
300
- }
301
- } else {
302
- vga_font_bool[ offset] = false ;
303
- }
304
- }
305
- }
306
- }
307
-
308
251
let mut this = Self {
309
252
buffer,
310
253
info,
@@ -326,23 +269,18 @@ impl<'this> DebugRendy<'this> {
326
269
map,
327
270
bg_canvas,
328
271
329
- glyph_height,
330
- glyph_width,
272
+ queue_cursor : 0 ,
331
273
332
274
offset_x,
333
275
offset_y,
334
276
335
- vga_font_bool,
336
-
337
- queue_cursor : 0 ,
338
-
339
277
cursor_visibility : true ,
340
278
auto_flush : true ,
341
279
} ;
342
280
343
281
let image = cmdline. term_background . map ( |a| parse_bmp_image ( a) ) ;
344
- this. generate_canvas ( image) ;
345
282
283
+ this. generate_canvas ( image) ;
346
284
this. clear ( true ) ;
347
285
this. double_buffer_flush ( ) ;
348
286
@@ -366,8 +304,7 @@ impl<'this> DebugRendy<'this> {
366
304
367
305
let width = self . info . horizontal_resolution ;
368
306
let height = self . info . vertical_resolution ;
369
-
370
- let colsize = image. bpp / 8 ;
307
+ let col_size = image. bpp / 8 ;
371
308
372
309
// Tiled Image:
373
310
// for y in ystart..yend {
@@ -412,7 +349,7 @@ impl<'this> DebugRendy<'this> {
412
349
413
350
for x in xstart..xend {
414
351
let img_pixel = unsafe {
415
- ( image. image . as_ptr ( ) ) . add ( fixedp6_to_int ( img_x) * colsize + off) as * const u32
352
+ ( image. image . as_ptr ( ) ) . add ( fixedp6_to_int ( img_x) * col_size + off) as * const u32
416
353
} ;
417
354
418
355
let i = blender ( x, y, unsafe { * img_pixel } ) ;
@@ -474,22 +411,22 @@ impl<'this> DebugRendy<'this> {
474
411
let height = self . info . vertical_resolution ;
475
412
476
413
if let Some ( image) = image {
477
- let frame_height = height / 2 - ( self . glyph_height * self . rows ) / 2 ;
478
- let frame_width = width / 2 - ( self . glyph_width * self . cols ) / 2 ;
414
+ let frame_width = width / 2 - ( FONT_WIDTH * self . cols ) / 2 ;
415
+ let frame_height = height / 2 - ( FONT_HEIGHT * self . rows ) / 2 ;
479
416
480
- let frame_height_end = frame_height + self . glyph_height * self . rows ;
481
- let frame_width_end = frame_width + self . glyph_width * self . cols ;
417
+ let frame_width_end = frame_width + FONT_WIDTH * self . cols ;
418
+ let frame_height_end = frame_height + FONT_HEIGHT * self . rows ;
482
419
483
420
let fheight = frame_height - MARGIN_GRADIENT ;
484
421
let fheight_end = frame_height_end + MARGIN_GRADIENT ;
422
+
485
423
let fwidth = frame_width - MARGIN_GRADIENT ;
486
424
let fwidth_end = frame_width_end + MARGIN_GRADIENT ;
487
425
488
426
self . loop_external ( & image, 0 , width, 0 , fheight) ;
489
427
self . loop_external ( & image, 0 , width, fheight_end, height) ;
490
428
self . loop_external ( & image, 0 , fwidth, fheight, fheight_end) ;
491
429
self . loop_external ( & image, fwidth_end, width, fheight, fheight_end) ;
492
-
493
430
self . loop_internal (
494
431
& image,
495
432
frame_width,
@@ -614,17 +551,17 @@ impl<'this> DebugRendy<'this> {
614
551
return ;
615
552
}
616
553
617
- let x = self . offset_x + x * self . glyph_width ;
618
- let y = self . offset_y + y * self . glyph_height ;
619
-
554
+ let x = self . offset_x + x * FONT_WIDTH ;
555
+ let y = self . offset_y + y * FONT_HEIGHT ;
620
556
let glyph = unsafe {
621
- self . vga_font_bool
622
- . as_ptr ( )
623
- . add ( ch as usize * DEFAULT_FONT_HEIGHT * DEFAULT_FONT_WIDTH )
557
+ core:: slice:: from_raw_parts (
558
+ FONT . as_ptr ( ) . offset ( ch as isize * FONT_HEIGHT as isize ) as * const u8 ,
559
+ FONT_HEIGHT ,
560
+ )
624
561
} ;
625
562
626
563
// naming: fx, fy for font coordinates and gx, gy for glyph coordinates
627
- for gy in 0 ..self . glyph_height {
564
+ for gy in 0 ..FONT_HEIGHT {
628
565
let fb_line = unsafe {
629
566
self . buffer
630
567
. as_mut_ptr ( )
@@ -637,23 +574,18 @@ impl<'this> DebugRendy<'this> {
637
574
. add ( x + ( y + gy) * self . info . horizontal_resolution )
638
575
} ;
639
576
640
- for fx in 0 ..DEFAULT_FONT_WIDTH {
641
- let draw = unsafe { * glyph. add ( gy * DEFAULT_FONT_WIDTH + fx) } ;
642
-
643
- let bg = if char. bg == u32:: MAX {
644
- unsafe { * canvas_line. add ( fx) }
577
+ for gx in 0 ..FONT_WIDTH {
578
+ let draw = glyph[ gy] & ( 1 << ( FONT_WIDTH - gx) ) != 0 ;
579
+ let color = if draw {
580
+ char. fg
581
+ } else if char. bg == u32:: MAX {
582
+ unsafe { * canvas_line. add ( gx) }
645
583
} else {
646
584
char. bg
647
585
} ;
648
586
649
- let fg = char. fg ;
650
-
651
587
unsafe {
652
- if draw {
653
- * fb_line. add ( fx) = fg;
654
- } else {
655
- * fb_line. add ( fx) = bg;
656
- }
588
+ * fb_line. add ( gx) = color;
657
589
}
658
590
}
659
591
}
0 commit comments