33//! Code for dealing with a VGA-style console, where there's a buffer of 16-bit
44//! values, each corresponding to a glyph and some attributes.
55
6+ use neotron_common_bios:: video:: { Attr , TextBackgroundColour , TextForegroundColour } ;
7+
68#[ derive( Debug ) ]
79pub struct VgaConsole {
810 addr : * mut u8 ,
@@ -14,7 +16,11 @@ pub struct VgaConsole {
1416
1517impl VgaConsole {
1618 /// White on Black
17- const DEFAULT_ATTR : u8 = 15 << 3 ;
19+ const DEFAULT_ATTR : Attr = Attr :: new (
20+ TextForegroundColour :: WHITE ,
21+ TextBackgroundColour :: BLACK ,
22+ false ,
23+ ) ;
1824
1925 pub fn new ( addr : * mut u8 , width : isize , height : isize ) -> VgaConsole {
2026 VgaConsole {
@@ -60,17 +66,17 @@ impl VgaConsole {
6066 self . reset_cursor ( ) ;
6167 }
6268
63- fn write ( & mut self , glyph : u8 , attr : Option < u8 > ) {
69+ fn write ( & mut self , glyph : u8 , attr : Option < Attr > ) {
6470 self . write_at ( self . row , self . col , glyph, attr) ;
6571 }
6672
67- fn write_at ( & mut self , row : isize , col : isize , glyph : u8 , attr : Option < u8 > ) {
73+ fn write_at ( & mut self , row : isize , col : isize , glyph : u8 , attr : Option < Attr > ) {
6874 assert ! ( row < self . height, "{} >= {}?" , row, self . height) ;
6975 assert ! ( col < self . width, "{} => {}?" , col, self . width) ;
7076 let offset = ( ( row * self . width ) + col) * 2 ;
7177 unsafe { core:: ptr:: write_volatile ( self . addr . offset ( offset) , glyph) } ;
7278 if let Some ( a) = attr {
73- unsafe { core:: ptr:: write_volatile ( self . addr . offset ( offset + 1 ) , a) } ;
79+ unsafe { core:: ptr:: write_volatile ( self . addr . offset ( offset + 1 ) , a. 0 ) } ;
7480 }
7581 }
7682
0 commit comments