From 2625fd044547c7e8b8de287963ba9422aff1f051 Mon Sep 17 00:00:00 2001 From: Tianhao Wang Date: Sat, 11 Mar 2023 00:39:38 +0100 Subject: fix linking --- src/lib.rs | 23 +++++++++-------------- src/machine/cgascr.rs | 41 ++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 767e547..c10460c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,23 +1,18 @@ #![no_std] #![no_main] mod arch; -// use core::panic::PanicInfo; +mod machine; +use core::panic::PanicInfo; +use machine::cgascr::CGAScreen; -static HELLO: &[u8] = b"Hello World!"; - -// #[panic_handler] -// fn panic(_info: &PanicInfo) -> ! { -// -// loop {} -// } +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop {} +} #[no_mangle] pub extern "C" fn _entry() -> ! { - let vga_buffer = 0xb8000 as *mut u8; - - unsafe { - *vga_buffer.offset(10 as isize * 2) = 'X' as u8; - *vga_buffer.offset(10 as isize * 2 + 1) = 0xb; - } + let scr = CGAScreen::new(80,25); + scr.test(); loop {} } diff --git a/src/machine/cgascr.rs b/src/machine/cgascr.rs index a43e073..f67501c 100644 --- a/src/machine/cgascr.rs +++ b/src/machine/cgascr.rs @@ -1,9 +1,9 @@ -const CGA_START:u32 = 0xb8000; +const vga_buffer:*mut u8 = 0xb8000 as *mut u8; #[allow(dead_code)] pub struct CGAScreen{ - max_cows:u32, - max_rows:u32, + pub max_cows:u32, + pub max_rows:u32, } #[allow(dead_code)] @@ -12,24 +12,31 @@ impl CGAScreen{ Self {max_cows: cows, max_rows:rows,} } - pub fn set_pos(x:u32, y:u32){ - - } - - pub fn get_pos(x:&mut u32, y:&mut u32){ - // TODO - *x = 1; - *y = 1; - } - - pub fn putchar(c:char, attr:u8){ - - } // this function should be the only one that "directly touches" // the memory by address. // and since it's unsafe, it shouldn't be public - fn show(&self, x:u32, y:u32, c:char, attr:u8){ + // + // fn show(&self, x:u32, y:u32, c:char, attr:u8){ + // + // } + pub fn test(&self){ + let mut r = 0; + let mut c = 0; + + while r