Skip to content

Commit 2f6debe

Browse files
committed
Reformatting of print + added further files
1 parent 7a913b8 commit 2f6debe

File tree

4 files changed

+41
-23
lines changed

4 files changed

+41
-23
lines changed

src/exceptions.rs

Whitespace-only changes.

src/interrupt.rs

Whitespace-only changes.

src/main.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,35 @@ use spin::Mutex;
88

99
mod vga;
1010

11-
lazy_static! {
12-
pub static ref SCREEN : Mutex<vga::Screen> = Mutex::new(vga::Screen{
13-
col_pos : 0,
14-
row_pos : 0,
15-
color : vga::ColorCode::new(vga::Color::Yellow, vga::Color::Black),
16-
buffer : unsafe { &mut *(0xb8000 as *mut vga::BUFFER) },
17-
});
18-
}
19-
2011
/// This function is called on panic.
2112
#[panic_handler]
2213
fn panic(_info: &PanicInfo) -> ! {
23-
writeln!(SCREEN.lock(), "{}", _info).unwrap();
14+
println!("{}", _info);
2415
loop {}
2516
}
2617

2718
/// This is the starting function. Its name must not be changeed by the compiler, hence the `#![no_mangle]`
2819
#[no_mangle]
2920
pub extern "C" fn _start() -> ! {
21+
/*
3022
SCREEN.lock().clear().unwrap();
3123
3224
SCREEN.lock().write_byte(b'H');
3325
SCREEN.lock().write_string("ello \n");
3426
SCREEN.lock().write_string("Wörld! \n");
3527
write!(SCREEN.lock(), "Test : {}", 42).unwrap();
28+
*/
3629

3730
for i in 0..10 {
38-
writeln!(SCREEN.lock(), "{}", i).unwrap();
31+
println!("{}", i);
3932
}
4033
for i in 0..30 {
41-
writeln!(SCREEN.lock(), "{},", i).unwrap();
34+
println!("{},", i);
4235
}
4336

4437
for i in 0..1000000 {
45-
write!(SCREEN.lock(), "{}/1000000", i).unwrap();
46-
SCREEN.lock().write_byte(b'\r');
38+
print!("{}/1000000", i);
39+
vga::write_back();
4740
}
4841

4942
loop{}

src/vga.rs

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
11
use core::fmt;
2+
use core::fmt::Write;
3+
use lazy_static::lazy_static;
4+
use spin::Mutex;
25

36
const BUFFER_HEIGHT: usize = 25;
47
const BUFFER_WIDTH: usize = 80;
58

69

10+
lazy_static! {
11+
pub static ref SCREEN : Mutex<Screen> = Mutex::new(Screen{
12+
col_pos : 0,
13+
row_pos : 0,
14+
color : ColorCode::new(Color::LightGreen, Color::Black),
15+
buffer : unsafe { &mut *(0xb8000 as *mut BUFFER) },
16+
});
17+
}
18+
19+
#[macro_export]
20+
macro_rules! println {
21+
() => (print!("\n"));
22+
($($arg:tt)*) => (print!("{}\n", format_args!($($arg)*)));
23+
}
24+
25+
#[macro_export]
26+
macro_rules! print {
27+
($($arg:tt)*) => ($crate::vga::_print(format_args!($($arg)*)));
28+
}
29+
30+
pub fn write_back() {
31+
SCREEN.lock().write_byte(b'\r');
32+
}
33+
34+
pub fn _print(args: fmt::Arguments) {
35+
SCREEN.lock().write_fmt(args).unwrap();
36+
}
37+
38+
39+
740
/// The 16 colors available in VGA mode
841
#[allow(dead_code)]
942
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -136,7 +169,7 @@ impl Screen {
136169
self.write_string(s);
137170
self.set_color(old_color);
138171
}
139-
fn new(color : ColorCode, buffer : &'static mut BUFFER) -> Self {
172+
fn _new(color : ColorCode, buffer : &'static mut BUFFER) -> Self {
140173
Screen {col_pos : 0, row_pos : 0, color : color, buffer : buffer}
141174
}
142175
pub fn set_color(&mut self, color : ColorCode) -> () {
@@ -163,12 +196,4 @@ impl fmt::Write for Screen {
163196
self.write_string(s);
164197
Ok(())
165198
}
166-
}
167-
168-
pub fn new_screen<'a>() -> Result<Screen, VgaError<'a>> {
169-
let res = Screen::new(
170-
ColorCode::new(Color::Yellow, Color::Black),
171-
unsafe { &mut *(0xb8000 as *mut BUFFER) },
172-
);
173-
Ok(res)
174199
}

0 commit comments

Comments
 (0)