From c9ec8f7a07d6e456bc1493dd90374c05cfd80eed Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 1 Feb 2022 19:50:15 -0700 Subject: [PATCH] WIP: VGA --- src/lib.rs | 56 ++++++++++++++++++++++++++++++++++++++++++ x86/startup-common.asm | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 001513e716..5a2f6c7eee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,9 +2,65 @@ #![feature(lang_items)] #![feature(llvm_asm)] +use core::slice; + mod panic; +#[repr(packed)] +pub struct VgaTextBlock { + char: u8, + color: u8, +} + +#[repr(u8)] +pub enum VgaTextColor { + Black = 0, + Blue = 1, + Green = 2, + Cyan = 3, + Red = 4, + Purple = 5, + Brown = 6, + Gray = 7, + DarkGray = 8, + LightBlue = 9, + LightGreen = 10, + LightCyan = 11, + LightRed = 12, + LightPurple = 13, + Yellow = 14, + White = 15, +} + #[no_mangle] pub unsafe extern "C" fn kstart() -> ! { + let vga = slice::from_raw_parts_mut( + 0xb8000 as *mut VgaTextBlock, + 80 * 25 + ); + + for i in 0..vga.len() { + vga[i].char = 0; + vga[i].color = + ((VgaTextColor::DarkGray as u8) << 4) | + (VgaTextColor::White as u8); + } + + let draw_text = |vga: &mut [VgaTextBlock], x: usize, y: usize, text: &str| { + let mut i = y * 80 + x; + for c in text.chars() { + if let Some(block) = vga.get_mut(i) { + block.char = c as u8; + } + i += 1; + } + }; + + draw_text( + vga, + 10, 1, + "Arrow keys and space select mode, enter to continue" + ); + loop {} } diff --git a/x86/startup-common.asm b/x86/startup-common.asm index 34c8189c44..81def6a5f7 100644 --- a/x86/startup-common.asm +++ b/x86/startup-common.asm @@ -46,7 +46,7 @@ startup: call memory_map - call vesa + ;TODO call vesa mov si, init_fpu_msg call print