1
1
use core:: fmt;
2
+ use core:: fmt:: Write ;
3
+ use lazy_static:: lazy_static;
4
+ use spin:: Mutex ;
2
5
3
6
const BUFFER_HEIGHT : usize = 25 ;
4
7
const BUFFER_WIDTH : usize = 80 ;
5
8
6
9
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
+
7
40
/// The 16 colors available in VGA mode
8
41
#[ allow( dead_code) ]
9
42
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
@@ -136,7 +169,7 @@ impl Screen {
136
169
self . write_string ( s) ;
137
170
self . set_color ( old_color) ;
138
171
}
139
- fn new ( color : ColorCode , buffer : & ' static mut BUFFER ) -> Self {
172
+ fn _new ( color : ColorCode , buffer : & ' static mut BUFFER ) -> Self {
140
173
Screen { col_pos : 0 , row_pos : 0 , color : color, buffer : buffer}
141
174
}
142
175
pub fn set_color ( & mut self , color : ColorCode ) -> ( ) {
@@ -163,12 +196,4 @@ impl fmt::Write for Screen {
163
196
self . write_string ( s) ;
164
197
Ok ( ( ) )
165
198
}
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)
174
199
}
0 commit comments