mirror of
https://github.com/sgmarz/osblog.git
synced 2024-11-23 18:06:20 +04:00
Change the way events are handled. Now, get a full list of events, not just one per system call.
This commit is contained in:
parent
98de4555ed
commit
74e44fab5d
@ -76,7 +76,7 @@ pub struct Config {
|
||||
pub config: ConfigUnion,
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[repr(u16)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum EventType {
|
||||
Syn = 0x00,
|
||||
@ -236,10 +236,10 @@ pub fn setup_input_device(ptr: *mut u32) -> bool {
|
||||
repopulate_event(&mut dev, i);
|
||||
}
|
||||
INPUT_DEVICES[idx] = Some(dev);
|
||||
ABS_EVENTS = Some(VecDeque::with_capacity(10000));
|
||||
ABS_OBSERVERS = Some(VecDeque::new());
|
||||
ABS_EVENTS = Some(VecDeque::with_capacity(100000));
|
||||
// ABS_OBSERVERS = Some(VecDeque::new());
|
||||
KEY_EVENTS = Some(VecDeque::with_capacity(1000));
|
||||
KEY_OBSERVERS = Some(VecDeque::new());
|
||||
// KEY_OBSERVERS = Some(VecDeque::new());
|
||||
|
||||
true
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use crate::{block::block_op,
|
||||
fs,
|
||||
elf,
|
||||
gpu,
|
||||
input,
|
||||
buffer::Buffer,
|
||||
page::{virt_to_phys, Table, map, EntryBits, PAGE_SIZE},
|
||||
process::{PROCESS_LIST, PROCESS_LIST_MUTEX, delete_process, get_by_pid, set_sleeping, set_waiting, add_kernel_process_args}};
|
||||
@ -226,23 +227,28 @@ pub unsafe fn do_syscall(mepc: usize, frame: *mut TrapFrame) -> usize {
|
||||
},
|
||||
1004 => {
|
||||
// wait for abs events
|
||||
let ret_pc;
|
||||
let mut ev = ABS_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 mut ret = event.code as u64;
|
||||
ret <<= 32;
|
||||
ret |= event.value as u64;
|
||||
// println!("ABS: Code: {}, Value: {}", event.code, event.value);
|
||||
(*frame).regs[Registers::A0 as usize] = ret as usize;
|
||||
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() {
|
||||
return 0;
|
||||
}
|
||||
let paddr = paddr.unwrap() as *mut Event;
|
||||
*paddr = ev.pop_front().unwrap();
|
||||
(*frame).regs[Registers::A0 as usize] += 1;
|
||||
}
|
||||
}
|
||||
ABS_EVENTS.replace(ev);
|
||||
ret_pc
|
||||
0
|
||||
},
|
||||
1062 => {
|
||||
// gettime
|
||||
|
@ -2,13 +2,8 @@
|
||||
#include <syscall.h>
|
||||
#include <input-event-codes.h>
|
||||
|
||||
struct Pixel {
|
||||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
unsigned char a;
|
||||
};
|
||||
|
||||
#define MAX_EVENTS 100000
|
||||
#define cos(x) table_cos(x)
|
||||
// #define cos(x) taylor_cos(x)
|
||||
#define min(x, y) ((x < y) ? x : y)
|
||||
@ -25,6 +20,19 @@ using i64 = signed long;
|
||||
using f64 = double;
|
||||
using f32 = float;
|
||||
|
||||
struct Pixel {
|
||||
u8 r;
|
||||
u8 g;
|
||||
u8 b;
|
||||
u8 a;
|
||||
};
|
||||
|
||||
struct Event {
|
||||
u16 event_type;
|
||||
u16 code;
|
||||
u32 value;
|
||||
} events[MAX_EVENTS];
|
||||
|
||||
void fill_rect(Pixel *fb, u32 x, u32 y, u32 width, u32 height, Pixel &color);
|
||||
void stroke_rect(Pixel *fb, u32 x, u32 y, u32 width, u32 height, Pixel &color, u32 size);
|
||||
void set_pixel(Pixel *fb, u32 x, u32 y, Pixel &color);
|
||||
@ -48,7 +56,7 @@ u32 lerp(u32 val, u32 mx1, u32 mx2) {
|
||||
|
||||
int main()
|
||||
{
|
||||
bool mouse_down = false;
|
||||
bool mouse_down = true;
|
||||
int VERSION = -1;
|
||||
printf("(%d): TESTING FRAMEBUFFER FROM USERSPACE\n", VERSION);
|
||||
Pixel *fb = (Pixel *)syscall_get_fb(6);
|
||||
@ -61,6 +69,7 @@ int main()
|
||||
u32 y = 0;
|
||||
u32 width = 40;
|
||||
u32 height = 50;
|
||||
unsigned long i = 0;
|
||||
|
||||
fill_rect(fb, 0, 0, 640, 480, white_color);
|
||||
stroke_rect(fb, 10, 10, 20, 20, blue_color, 5);
|
||||
@ -68,34 +77,28 @@ int main()
|
||||
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 {
|
||||
i64 key = syscall_get_key();
|
||||
i64 abs = syscall_get_abs();
|
||||
if (key == -1 && abs == -1) {
|
||||
|
||||
if ((abs = syscall_get_abs(events, MAX_EVENTS)) < 1) {
|
||||
syscall_sleep(noevt_slptm);
|
||||
continue;
|
||||
}
|
||||
if (key != -1) {
|
||||
short code = key >> 16;
|
||||
bool pressed = (key & 1) ? true : false;
|
||||
// printf("%s key %d\n", pressed ? "pressed" : "released", code);
|
||||
if (code == BTN_LEFT) { // left mouse button
|
||||
mouse_down = pressed;
|
||||
}
|
||||
}
|
||||
if (abs != -1) {
|
||||
u16 code = abs >> 32;
|
||||
if (code == ABS_X) {
|
||||
x = lerp(abs & 0xffff, 32767, 640);
|
||||
}
|
||||
else if (code == ABS_Y) {
|
||||
y = lerp(abs & 0xffff, 32767, 480);
|
||||
}
|
||||
if (mouse_down) {
|
||||
for (i64 z = 0;z < abs;z++) {
|
||||
Event &ev = events[z];
|
||||
if (ev.code == ABS_X) {
|
||||
x = lerp(ev.value & 0xffff, 32767, 640);
|
||||
fill_rect(fb, x, y, 5, 5, orange_color);
|
||||
}
|
||||
else if (ev.code == ABS_Y) {
|
||||
y = lerp(ev.value & 0xffff, 32767, 480);
|
||||
fill_rect(fb, x, y, 5, 5, orange_color);
|
||||
syscall_inv_rect(6, 0, 0, 640, 480);
|
||||
}
|
||||
}
|
||||
syscall_inv_rect(6, 0, 0, 640, 480);
|
||||
// if (i++ >= 100) {
|
||||
// i = 0;
|
||||
// syscall_inv_rect(6, 0, 0, 640, 480);
|
||||
// }
|
||||
} while (true);
|
||||
return 0;
|
||||
}
|
||||
|
@ -18,6 +18,6 @@ extern "C"
|
||||
#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_abs(x) make_syscall(1004)
|
||||
#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