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); }