From 380b7adfbb5971fa498069158aad477bca822838 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 11 Jul 2019 02:38:49 -0700 Subject: [PATCH] Fix vga printing newlines --- src/main.rs | 3 ++- src/vga_buffer.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1f8ffc7..9a1280f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,9 +22,10 @@ pub fn init() { pub extern "C" fn _start() -> ! { init(); - x86_64::instructions::interrupts::int3(); + //x86_64::instructions::interrupts::int3(); println!("Gamarjoba, munde: {}", 1); + println!("Gamarjoba, munde: {}", 2); //panic!("A bad thing happened"); loop {} } diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 8c13f4a..a9224e1 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -103,7 +103,24 @@ impl Writer { } fn new_line(&mut self) { + for row in 1..BUFFER_HEIGHT { + for col in 0..BUFFER_WIDTH { + let character = self.buffer.chars[row][col].read(); + self.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_char: b' ', + color_code: self.color_code, + }; + for col in 0..BUFFER_WIDTH { + self.buffer.chars[row][col].write(blank); + } } }