mirror of
https://github.com/sgmarz/osblog.git
synced 2024-11-23 09:56:21 +04:00
Added keyboard event gather. Fixed bug where we didn't replace the event queues.
This commit is contained in:
parent
f9f93ada71
commit
8132b63f9c
@ -209,21 +209,28 @@ pub unsafe fn do_syscall(mepc: usize, frame: *mut TrapFrame) -> usize {
|
||||
},
|
||||
1002 => {
|
||||
// wait for keyboard events
|
||||
let ret_pc;
|
||||
let mut ev = KEY_EVENTS.take().unwrap();
|
||||
if ev.is_empty() {
|
||||
(*frame).regs[Registers::A0 as usize] = -1isize as usize;
|
||||
ret_pc = 0;
|
||||
}
|
||||
else {
|
||||
let event = ev.pop_front().unwrap();
|
||||
let ret = ((event.code as usize) << 16) | event.value as usize;
|
||||
// println!("Code: {}, Value: {}, ret: 0x{:016x}", event.code, event.value, ret);
|
||||
(*frame).regs[Registers::A0 as usize] = ret;
|
||||
ret_pc = 0;
|
||||
let max_events = (*frame).regs[Registers::A1 as usize];
|
||||
let vaddr = (*frame).regs[Registers::A0 as usize] as *const Event;
|
||||
if (*frame).satp >> 60 != 0 {
|
||||
let process = get_by_pid((*frame).pid as u16);
|
||||
let table = ((*process).get_table_address()
|
||||
as *mut Table)
|
||||
.as_mut()
|
||||
.unwrap();
|
||||
(*frame).regs[Registers::A0 as usize] = 0;
|
||||
for i in 0..ev.len() {
|
||||
let paddr = virt_to_phys(table, vaddr.add(i) as usize);
|
||||
if paddr.is_none() {
|
||||
break;
|
||||
}
|
||||
let paddr = paddr.unwrap() as *mut Event;
|
||||
*paddr = ev.pop_front().unwrap();
|
||||
(*frame).regs[Registers::A0 as usize] += 1;
|
||||
}
|
||||
}
|
||||
KEY_EVENTS.replace(ev);
|
||||
ret_pc
|
||||
0
|
||||
},
|
||||
1004 => {
|
||||
// wait for abs events
|
||||
@ -240,7 +247,7 @@ pub unsafe fn do_syscall(mepc: usize, frame: *mut TrapFrame) -> usize {
|
||||
for i in 0..ev.len() {
|
||||
let paddr = virt_to_phys(table, vaddr.add(i) as usize);
|
||||
if paddr.is_none() {
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
let paddr = paddr.unwrap() as *mut Event;
|
||||
*paddr = ev.pop_front().unwrap();
|
||||
|
@ -49,53 +49,48 @@ struct Rect {
|
||||
u32 height;
|
||||
};
|
||||
|
||||
u32 lerp(u32 val, u32 mx1, u32 mx2) {
|
||||
constexpr u32 lerp(u32 val, u32 mx1, u32 mx2) {
|
||||
f64 r = val / static_cast<f64>(mx1);
|
||||
return r * mx2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
bool mouse_down = true;
|
||||
int VERSION = -1;
|
||||
printf("(%d): TESTING FRAMEBUFFER FROM USERSPACE\n", VERSION);
|
||||
bool pressed = false;
|
||||
Pixel *fb = (Pixel *)syscall_get_fb(6);
|
||||
Pixel blue_color = {0, 0, 255, 255};
|
||||
Pixel red_color = {255, 0, 0, 255};
|
||||
Pixel green_color = {0, 255, 0, 255};
|
||||
Pixel white_color = {255, 255, 255, 255};
|
||||
Pixel orange_color = {255, 150, 0, 255};
|
||||
u32 x = 0;
|
||||
u32 y = 0;
|
||||
u32 width = 40;
|
||||
u32 height = 50;
|
||||
unsigned long i = 0;
|
||||
u32 num_events;
|
||||
|
||||
fill_rect(fb, 0, 0, 640, 480, white_color);
|
||||
stroke_rect(fb, 10, 10, 20, 20, blue_color, 5);
|
||||
stroke_rect(fb, 50, 50, 40, 40, green_color, 10);
|
||||
stroke_rect(fb, 150, 150, 140, 140, red_color, 15);
|
||||
draw_cosine(fb, 0, 400, 500, 50, red_color);
|
||||
syscall_inv_rect(6, x, y, 640, 480);
|
||||
i64 abs;
|
||||
do {
|
||||
|
||||
if ((abs = syscall_get_abs(events, MAX_EVENTS)) < 1) {
|
||||
if ((num_events = syscall_get_key(0, MAX_EVENTS)) > 0) {
|
||||
for (u32 z = 0;z < num_events;z++) {
|
||||
Event &ev = events[z];
|
||||
if (ev.code == BTN_MOUSE) {
|
||||
pressed = (ev.value & 1) == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((num_events = syscall_get_abs(events, MAX_EVENTS)) < 1) {
|
||||
syscall_sleep(noevt_slptm);
|
||||
continue;
|
||||
}
|
||||
for (i64 z = 0;z < abs;z++) {
|
||||
for (u32 z = 0;z < num_events;z++) {
|
||||
Event &ev = events[z];
|
||||
if (ev.code == ABS_X) {
|
||||
x = lerp(ev.value & 0x7fff, 32767, 640);
|
||||
fill_rect(fb, x, y, 5, 5, orange_color);
|
||||
}
|
||||
else if (ev.code == ABS_Y) {
|
||||
y = lerp(ev.value & 0x7fff, 32767, 480);
|
||||
}
|
||||
if (pressed) {
|
||||
fill_rect(fb, x, y, 5, 5, orange_color);
|
||||
}
|
||||
}
|
||||
syscall_inv_rect(6, 0, 0, 640, 480);
|
||||
if (pressed) {
|
||||
syscall_inv_rect(6, 0, 0, 640, 480);
|
||||
}
|
||||
} while (true);
|
||||
return 0;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ extern "C"
|
||||
#define syscall_sleep(x) make_syscall(10, (unsigned long)x)
|
||||
#define syscall_get_fb(x) make_syscall(1000, (unsigned long)x)
|
||||
#define syscall_inv_rect(d, x, y, w, h) make_syscall(1001, (unsigned long) d, (unsigned long)x, (unsigned long)y, (unsigned long)w, (unsigned long)h)
|
||||
#define syscall_get_key(x) make_syscall(1002)
|
||||
#define syscall_get_key(x, y) make_syscall(1002, (unsigned long)x, (unsigned long)y)
|
||||
#define syscall_get_abs(x, y) make_syscall(1004, (unsigned long)x, (unsigned long)y)
|
||||
#define syscall_get_time() make_syscall(1062)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user