@@ -52,7 +52,7 @@ impl VgaConsole {
5252 false ,
5353 ) ;
5454
55- pub fn new ( addr : * mut u8 , width : isize , height : isize ) -> VgaConsole {
55+ pub fn new ( addr : * mut u32 , width : isize , height : isize ) -> VgaConsole {
5656 VgaConsole {
5757 inner : ConsoleInner {
5858 addr,
@@ -112,16 +112,31 @@ impl VgaConsole {
112112///
113113/// Separate from the parser, so it can be passed to the `advance` method.
114114struct ConsoleInner {
115- addr : * mut u8 ,
115+ /// The start of our text buffer.
116+ ///
117+ /// Always 32-bit aligned.
118+ addr : * mut u32 ,
119+ /// The width of the screen in characters
116120 width : isize ,
121+ /// The height of the screen in characters
117122 height : isize ,
123+ /// The current row position in characters
118124 row : isize ,
125+ /// The current column position in characters
119126 col : isize ,
127+ /// The attribute to apply to the next character we draw
120128 attr : Attr ,
129+ /// Have we seen the ANSI 'bold' command?
121130 bright : bool ,
131+ /// Have we seen the ANSI 'reverse' command?
122132 reverse : bool ,
133+ /// Should we draw a cursor?
123134 cursor_wanted : bool ,
135+ /// How many times has the cursor been turned off?
136+ ///
137+ /// The cursor is only enabled when at `0`.
124138 cursor_depth : u8 ,
139+ /// What character should be where the cursor currently is?
125140 cursor_holder : Option < u8 > ,
126141}
127142
@@ -237,7 +252,8 @@ impl ConsoleInner {
237252 }
238253
239254 let offset = ( ( row * self . width ) + col) * 2 ;
240- unsafe { core:: ptr:: write_volatile ( self . addr . offset ( offset) , glyph) } ;
255+ let byte_addr = self . addr as * mut u8 ;
256+ unsafe { core:: ptr:: write_volatile ( byte_addr. offset ( offset) , glyph) } ;
241257 let attr = if self . reverse {
242258 let new_fg = self . attr . bg ( ) . make_foreground ( ) ;
243259 let new_bg = self . attr . fg ( ) . make_background ( ) ;
@@ -246,7 +262,7 @@ impl ConsoleInner {
246262 self . attr
247263 } ;
248264
249- unsafe { core:: ptr:: write_volatile ( self . addr . offset ( offset + 1 ) , attr. as_u8 ( ) ) } ;
265+ unsafe { core:: ptr:: write_volatile ( byte_addr . offset ( offset + 1 ) , attr. as_u8 ( ) ) } ;
250266 }
251267
252268 /// Read a glyph at the current position
@@ -266,20 +282,21 @@ impl ConsoleInner {
266282 assert ! ( self . cursor_holder. is_none( ) ) ;
267283 }
268284 let offset = ( ( row * self . width ) + col) * 2 ;
269- unsafe { core:: ptr:: read_volatile ( self . addr . offset ( offset) ) }
285+ let byte_addr = self . addr as * const u8 ;
286+ unsafe { core:: ptr:: read_volatile ( byte_addr. offset ( offset) ) }
270287 }
271288
272289 /// Move everyone on screen up one line, losing the top line.
273290 ///
274291 /// The bottom line will be all space characters.
275292 fn scroll_page ( & mut self ) {
276- let row_len_bytes = self . width * 2 ;
293+ let row_len_words = self . width / 2 ;
277294 unsafe {
278295 // Scroll rows[1..=height-1] to become rows[0..=height-2].
279296 core:: ptr:: copy (
280- self . addr . offset ( row_len_bytes ) ,
297+ self . addr . offset ( row_len_words ) ,
281298 self . addr ,
282- ( row_len_bytes * ( self . height - 1 ) ) as usize ,
299+ ( row_len_words * ( self . height - 1 ) ) as usize ,
283300 ) ;
284301 }
285302 // Blank the bottom line of the screen (rows[height-1]).
0 commit comments