Skip to content
Permalink
Browse files

Add write_with_bg! macro

  • Loading branch information...
yoshitsugu committed Jun 28, 2019
1 parent 7c8281f commit 11bd1b2ccda8b7028aab6fc03e23f582870ea131
Showing with 57 additions and 56 deletions.
  1. +40 −56 src/lib.rs
  2. +17 −0 src/vga.rs
@@ -110,85 +110,71 @@ pub extern "C" fn haribote_os() {
sheet_manager.updown(shi_win, Some(1)); sheet_manager.updown(shi_win, Some(1));
sheet_manager.updown(shi_mouse, Some(2)); sheet_manager.updown(shi_mouse, Some(2));


boxfill( write_with_bg!(
sheet_manager,
shi_bg,
buf_bg_addr, buf_bg_addr,
*SCREEN_WIDTH as isize, *SCREEN_WIDTH as isize,
Color::DarkCyan, *SCREEN_HEIGHT as isize,
0,
32,
100,
48,
);
let mut writer = ScreenWriter::new(
Some(buf_bg_addr),
vga::Color::White,
0, 0,
32, 32,
*SCREEN_WIDTH as usize, Color::White,
*SCREEN_HEIGHT as usize, Color::DarkCyan,
); 27,
write!( "total: {:>2}MB free: {:>6}KB",
writer,
"total: {}MB free: {}KB",
memtotal / (1024 * 1024), memtotal / (1024 * 1024),
memman.total() / 1024 memman.total() / 1024
) );
.unwrap();
sheet_manager.refresh(shi_bg, 0, 0, scrnx, 48);
loop { loop {
cli(); cli();
if let Some(t) = TIMER_MANAGER.try_lock() { if let Some(t) = TIMER_MANAGER.try_lock() {
boxfill(buf_win_addr, 160, Color::LightGray, 40, 28, 119, 43); write_with_bg!(
let mut writer = sheet_manager,
ScreenWriter::new(Some(buf_win_addr), vga::Color::Black, 40, 28, 160, 52); shi_win,
write!(writer, "{:>010}", t.count).unwrap(); buf_win_addr,
sheet_manager.refresh(shi_win, 40, 28, 120, 44); 160,
52,
40,
28,
Color::Black,
Color::LightGray,
10,
"{:>010}",
t.count
);
} }
if KEYBUF.lock().status() != 0 { if KEYBUF.lock().status() != 0 {
let key = KEYBUF.lock().get().unwrap(); let key = KEYBUF.lock().get().unwrap();
sti(); sti();
boxfill( write_with_bg!(
sheet_manager,
shi_bg,
buf_bg_addr, buf_bg_addr,
*SCREEN_WIDTH as isize, *SCREEN_WIDTH as isize,
Color::DarkCyan, *SCREEN_HEIGHT as isize,
0, 0,
0, 0,
16, Color::White,
16, Color::DarkCyan,
); 2,
let mut writer = ScreenWriter::new( "{:x}",
Some(buf_bg_addr), key
vga::Color::White,
0,
0,
*SCREEN_WIDTH as usize,
*SCREEN_HEIGHT as usize,
); );
write!(writer, "{:x}", key).unwrap();
sheet_manager.refresh(shi_bg, 0, 0, 16, 16);
} else if MOUSEBUF.lock().status() != 0 { } else if MOUSEBUF.lock().status() != 0 {
let i = MOUSEBUF.lock().get().unwrap(); let i = MOUSEBUF.lock().get().unwrap();
sti(); sti();
if mouse_dec.decode(i).is_some() { if mouse_dec.decode(i).is_some() {
boxfill( write_with_bg!(
sheet_manager,
shi_bg,
buf_bg_addr, buf_bg_addr,
*SCREEN_WIDTH as isize, *SCREEN_WIDTH as isize,
Color::DarkCyan, *SCREEN_HEIGHT as isize,
32, 32,
0, 0,
32 + 15 * 8, Color::White,
16, Color::DarkCyan,
); 15,
let mut writer = ScreenWriter::new(
Some(buf_bg_addr),
vga::Color::White,
32,
0,
*SCREEN_WIDTH as usize,
*SCREEN_HEIGHT as usize,
);
write!(
writer,
"[{}{}{} {:>4},{:>4}]", "[{}{}{} {:>4},{:>4}]",
if (mouse_dec.btn.get() & 0x01) != 0 { if (mouse_dec.btn.get() & 0x01) != 0 {
'L' 'L'
@@ -207,9 +193,7 @@ pub extern "C" fn haribote_os() {
}, },
mouse_dec.x.get(), mouse_dec.x.get(),
mouse_dec.y.get(), mouse_dec.y.get(),
) );
.unwrap();
sheet_manager.refresh(shi_bg, 32, 0, 32 + 15 * 8, 16);
sheet_manager.slide_by_diff(shi_mouse, mouse_dec.x.get(), mouse_dec.y.get()); sheet_manager.slide_by_diff(shi_mouse, mouse_dec.x.get(), mouse_dec.y.get());
} }
} else if timer_buf1.status() != 0 { } else if timer_buf1.status() != 0 {
@@ -251,6 +251,23 @@ impl fmt::Write for ScreenWriter {
} }
} }


#[macro_export]
macro_rules! write_with_bg {
($sheet_manager: expr, $sheet_addr: expr, $dst: expr, $width: expr, $height: expr, $x: expr, $y: expr, $fg: expr, $bg: expr, $length: expr, $($arg: tt)* ) => {{
boxfill($dst, $width, $bg, $x, $y, $x + 8 * $length - 1, $y + 15);
let mut writer = ScreenWriter::new(
Some($dst),
$fg,
$x,
$y,
$width as usize,
$height as usize);
use core::fmt::Write;
write!(writer, $($arg)*).unwrap();
$sheet_manager.refresh($sheet_addr, $x, $y, $x + $length * 8, $y + 16);
}}
}

pub fn make_window(buf: usize, xsize: i32, ysize: i32, title: &str) { pub fn make_window(buf: usize, xsize: i32, ysize: i32, title: &str) {
let xsize = xsize as isize; let xsize = xsize as isize;
let ysize = ysize as isize; let ysize = ysize as isize;

0 comments on commit 11bd1b2

Please sign in to comment.
You can’t perform that action at this time.