Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b5642cc4e |
No files matched your search
+1
-83
@@ -6,23 +6,10 @@ pub struct Console {
|
||||
con_init: extern "stdcall" fn(u32, u32, u32, u32, *const u8),
|
||||
con_write_string: extern "stdcall" fn(*const u8, u32),
|
||||
con_exit: extern "stdcall" fn(bool),
|
||||
con_set_title: extern "stdcall" fn(*const u8),
|
||||
con_get_flags: extern "stdcall" fn() -> u32,
|
||||
con_set_flags: extern "stdcall" fn(u32) -> u32,
|
||||
con_get_font_height: extern "stdcall" fn() -> u32,
|
||||
con_get_cursor_height: extern "stdcall" fn() -> u32,
|
||||
con_set_cursor_height: extern "stdcall" fn(u32) -> u32,
|
||||
con_getch: extern "stdcall" fn() -> u32,
|
||||
con_getch2: extern "stdcall" fn() -> u16,
|
||||
con_kbhit: extern "stdcall" fn() -> u32,
|
||||
con_gets: extern "stdcall" fn(*mut u8, u32) -> *mut u8,
|
||||
con_cls: extern "stdcall" fn(),
|
||||
con_get_cursor_pos: extern "stdcall" fn(*mut u32, *mut u32),
|
||||
con_set_cursor_pos: extern "stdcall" fn(u32, u32),
|
||||
}
|
||||
|
||||
impl Console {
|
||||
pub fn import(path: Option<&CStr>) -> Result<Self, &'static str> {
|
||||
pub fn import(path: Option<&CStr>) -> Result<Self, &str> {
|
||||
let lib = DLL::load_dll(path.unwrap_or(c"/sys/lib/console.obj"));
|
||||
match lib {
|
||||
Err(e) => return Err(e),
|
||||
@@ -31,19 +18,6 @@ impl Console {
|
||||
con_init: transmute(dll.get_func(c"con_init").ok().unwrap()),
|
||||
con_write_string: transmute(dll.get_func(c"con_write_string").ok().unwrap()),
|
||||
con_exit: transmute(dll.get_func(c"con_exit").ok().unwrap()),
|
||||
con_set_title: transmute(dll.get_func(c"con_set_title").ok().unwrap()),
|
||||
con_get_flags: transmute(dll.get_func(c"con_get_flags").ok().unwrap()),
|
||||
con_set_flags: transmute(dll.get_func(c"con_set_flags").ok().unwrap()),
|
||||
con_get_font_height: transmute(dll.get_func(c"con_get_font_height").ok().unwrap()),
|
||||
con_get_cursor_height: transmute(dll.get_func(c"con_get_cursor_height").ok().unwrap()),
|
||||
con_set_cursor_height: transmute(dll.get_func(c"con_set_cursor_height").ok().unwrap()),
|
||||
con_getch: transmute(dll.get_func(c"con_getch").ok().unwrap()),
|
||||
con_getch2: transmute(dll.get_func(c"con_getch2").ok().unwrap()),
|
||||
con_kbhit: transmute(dll.get_func(c"con_kbhit").ok().unwrap()),
|
||||
con_gets: transmute(dll.get_func(c"con_gets").ok().unwrap()),
|
||||
con_cls: transmute(dll.get_func(c"con_cls").ok().unwrap()),
|
||||
con_get_cursor_pos: transmute(dll.get_func(c"con_get_cursor_pos").ok().unwrap()),
|
||||
con_set_cursor_pos: transmute(dll.get_func(c"con_set_cursor_pos").ok().unwrap()),
|
||||
})
|
||||
},
|
||||
}
|
||||
@@ -60,60 +34,4 @@ impl Console {
|
||||
pub fn exit(self, close_window: bool) {
|
||||
(self.con_exit)(close_window);
|
||||
}
|
||||
|
||||
pub fn set_title(&self, title: &CStr) {
|
||||
(self.con_set_title)(title.as_ptr() as *const u8);
|
||||
}
|
||||
|
||||
pub fn get_flags(&self) -> u32 {
|
||||
(self.con_get_flags)()
|
||||
}
|
||||
|
||||
pub fn set_flags(&self, flags: u32) -> u32 {
|
||||
(self.con_set_flags)(flags)
|
||||
}
|
||||
|
||||
pub fn get_font_height(&self) -> u32 {
|
||||
(self.con_get_font_height)()
|
||||
}
|
||||
|
||||
pub fn get_cursor_height(&self) -> u32 {
|
||||
(self.con_get_cursor_height)()
|
||||
}
|
||||
|
||||
pub fn set_cursor_height(&self, height: u32) -> u32 {
|
||||
(self.con_set_cursor_height)(height)
|
||||
}
|
||||
|
||||
pub fn getch(&self) -> u32 {
|
||||
(self.con_getch)()
|
||||
}
|
||||
|
||||
pub fn getch2(&self) -> u16 {
|
||||
(self.con_getch2)()
|
||||
}
|
||||
|
||||
pub fn kbhit(&self) -> u32 {
|
||||
(self.con_kbhit)()
|
||||
}
|
||||
|
||||
pub fn gets<'a>(&self, buf: &'a mut [u8]) -> Option<&'a [u8]> {
|
||||
let ptr = (self.con_gets)(buf.as_mut_ptr(), buf.len() as u32);
|
||||
if ptr.is_null() { None } else { Some(buf) }
|
||||
}
|
||||
|
||||
pub fn cls(&self) {
|
||||
(self.con_cls)();
|
||||
}
|
||||
|
||||
pub fn get_cursor_pos(&self) -> (u32, u32) {
|
||||
let mut x = 0u32;
|
||||
let mut y = 0u32;
|
||||
(self.con_get_cursor_pos)(&mut x, &mut y);
|
||||
(x, y)
|
||||
}
|
||||
|
||||
pub fn set_cursor_pos(&self, x: u32, y: u32) {
|
||||
(self.con_set_cursor_pos)(x, y);
|
||||
}
|
||||
}
|
||||
@@ -31,3 +31,12 @@ pub unsafe extern "C" fn memcmp(s1: *mut u8, s2: *const u8, n: usize) -> i32 {
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn strlen(str: *mut u8) -> usize {
|
||||
let mut len = 0usize;
|
||||
loop {
|
||||
if *str.add(len) == 0 { return len; }
|
||||
len += 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user