From c5fcd734993a124d5ccc72b7b14aab8d6da2c66d Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 22 Oct 2015 23:40:18 -0700 Subject: [PATCH] write_to_coord() in rust now has sensible coordinates --- lightshow.rs | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/lightshow.rs b/lightshow.rs index e4330e3..f660b95 100644 --- a/lightshow.rs +++ b/lightshow.rs @@ -9,29 +9,57 @@ extern fn eh_personality() {} #[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} } +#[lang = "panic"] +pub fn panic(expr_file_line: &(&'static str, &'static str, u32)) -> ! { panic_fmt() } + #[lang = "sized"] trait Sized {} #[lang = "copy"] trait Copy {} +#[lang = "add"] +pub trait Add { + type Output; + fn add(self, rhs: RHS) -> Self::Output; +} + +/* this can be bogus, apparently? */ +impl Add for usize { + type Output = usize; + fn add(self, _rhs: usize) -> usize { 1 } +} + +#[lang = "mul"] +pub trait Mul { + type Output; + fn mul(self, rhs: RHS) -> Self::Output; +} + +impl Mul for usize { + type Output = usize; + fn mul(self, rhs: usize) -> usize { 1 } +} + + #[no_mangle] pub extern fn rust_entry() { //white A on black let spec: u16 = 0x0f_41; - write_to_coord(0, 0, spec); - loop { - - } + write_to_coord(1, 2, spec); + loop { } } -//const VRAM_OFFSET = 0xb8000; +const X86_COLS: usize = 80; +const X86_ROWS: usize = 25; +const VRAM_OFFSET: usize = 0xb8000; fn write_to_coord(x: u8, y: u8, x86_specifier: u16) { unsafe { - *(0xb8000 as *mut u16) = x86_specifier; + let offset = VRAM_OFFSET + (X86_COLS*2*(y as usize)) + (x as usize)*2; + *(offset as *mut u16) = x86_specifier; } }