Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Make it API compatible with the existing vga crate. #2

Merged
merged 1 commit into from
Sep 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ version = "0.1.0"
authors = ["Steve Klabnik <[email protected]>"]

[dependencies]
spin = "0.4.2"
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#![no_std]
#![feature(const_fn)]

extern crate spin;

use core::fmt;
use core::fmt::Write;

mod color;
use color::Color;

mod print;

use spin::Mutex;

const ROWS: usize = 25;
const COLS: usize = 80;
const COL_BYTES: usize = COLS * 2;
Expand All @@ -16,6 +23,8 @@ pub struct Vga {
position: usize,
}

unsafe impl Send for Vga {}

impl Vga {
pub unsafe fn new(location: *mut u8) -> Vga {
Vga {
Expand Down Expand Up @@ -80,6 +89,14 @@ impl Write for Vga {
}
}

pub static BUFFER: Mutex<Vga> = Mutex::new(
Vga {
location: 0xb8000 as *mut u8,
buffer: [0; ROWS * COL_BYTES],
position: 0,
}
);

#[cfg(test)]
mod tests {
use Vga;
Expand Down
29 changes: 29 additions & 0 deletions src/print.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// Prints something to the screen, with a trailing newline.
///
/// # Examples
///
/// ```ignore
/// kprintln!("Hello, world!");
/// ```
#[macro_export]
macro_rules! kprintln {
($fmt:expr) => (kprint!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (kprint!(concat!($fmt, "\n"), $($arg)*));
}

/// Prints something to the screen.
///
/// # Examples
///
/// ```ignore
/// kprint!("Hello, world!");
/// ```
#[macro_export]
macro_rules! kprint {
($($arg:tt)*) => ({
use core::fmt::Write;
let mut b = $crate::BUFFER.lock();
b.write_fmt(format_args!($($arg)*)).unwrap();
b.flush();
});
}