From f24c7bc32283e9aa592859e7230b3e4ee70d0439 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 12 Apr 2017 19:30:58 +0200 Subject: [PATCH] Implement the `new_line` method --- src/vga_buffer.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 20d620d..cdfe7ab 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -85,7 +85,27 @@ impl Writer { unsafe{ self.buffer.as_mut() } } - fn new_line(&mut self) {/* TODO */} + fn new_line(&mut self) { + for row in 1..BUFFER_HEIGHT { + for col in 0..BUFFER_WIDTH { + let buffer = self.buffer(); + let character = buffer.chars[row][col].read(); + buffer.chars[row - 1][col].write(character); + } + } + self.clear_row(BUFFER_HEIGHT-1); + self.column_position = 0; + } + + fn clear_row(&mut self, row: usize) { + let blank = ScreenChar { + ascii_character: b' ', + color_code: self.color_code, + }; + for col in 0..BUFFER_WIDTH { + self.buffer().chars[row][col].write(blank); + } + } } impl fmt::Write for Writer { @@ -107,7 +127,6 @@ pub fn print_something() { buffer: unsafe { Unique::new(0xb8000 as *mut _) }, }; - writer.write_byte(b'H'); - writer.write_str("ello! "); - write!(writer, "The numbers are {} and {}", 42, 1.0/3.0); + writeln!(writer, "Hello!"); + writeln!(writer, "The numbers are {} and {}", 42, 1.0/3.0); }