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,
|
pub config: ConfigUnion,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u16)]
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum EventType {
|
pub enum EventType {
|
||||||
Syn = 0x00,
|
Syn = 0x00,
|
||||||
@ -236,10 +236,10 @@ pub fn setup_input_device(ptr: *mut u32) -> bool {
|
|||||||
repopulate_event(&mut dev, i);
|
repopulate_event(&mut dev, i);
|
||||||
}
|
}
|
||||||
INPUT_DEVICES[idx] = Some(dev);
|
INPUT_DEVICES[idx] = Some(dev);
|
||||||
ABS_EVENTS = Some(VecDeque::with_capacity(10000));
|
ABS_EVENTS = Some(VecDeque::with_capacity(100000));
|
||||||
ABS_OBSERVERS = Some(VecDeque::new());
|
// ABS_OBSERVERS = Some(VecDeque::new());
|
||||||
KEY_EVENTS = Some(VecDeque::with_capacity(1000));
|
KEY_EVENTS = Some(VecDeque::with_capacity(1000));
|
||||||
KEY_OBSERVERS = Some(VecDeque::new());
|
// KEY_OBSERVERS = Some(VecDeque::new());
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ use crate::{block::block_op,
|
|||||||
fs,
|
fs,
|
||||||
elf,
|
elf,
|
||||||
gpu,
|
gpu,
|
||||||
|
input,
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
page::{virt_to_phys, Table, map, EntryBits, PAGE_SIZE},
|
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}};
|
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 => {
|
1004 => {
|
||||||
// wait for abs events
|
// wait for abs events
|
||||||
let ret_pc;
|
|
||||||
let mut ev = ABS_EVENTS.take().unwrap();
|
let mut ev = ABS_EVENTS.take().unwrap();
|
||||||
if ev.is_empty() {
|
let max_events = (*frame).regs[Registers::A1 as usize];
|
||||||
(*frame).regs[Registers::A0 as usize] = -1isize as usize;
|
let vaddr = (*frame).regs[Registers::A0 as usize] as *const Event;
|
||||||
ret_pc = 0;
|
if (*frame).satp >> 60 != 0 {
|
||||||
}
|
let process = get_by_pid((*frame).pid as u16);
|
||||||
else {
|
let table = ((*process).get_table_address()
|
||||||
let event = ev.pop_front().unwrap();
|
as *mut Table)
|
||||||
let mut ret = event.code as u64;
|
.as_mut()
|
||||||
ret <<= 32;
|
.unwrap();
|
||||||
ret |= event.value as u64;
|
(*frame).regs[Registers::A0 as usize] = 0;
|
||||||
// println!("ABS: Code: {}, Value: {}", event.code, event.value);
|
for i in 0..ev.len() {
|
||||||
(*frame).regs[Registers::A0 as usize] = ret as usize;
|
let paddr = virt_to_phys(table, vaddr.add(i) as usize);
|
||||||
ret_pc = 0;
|
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);
|
ABS_EVENTS.replace(ev);
|
||||||
ret_pc
|
0
|
||||||
},
|
},
|
||||||
1062 => {
|
1062 => {
|
||||||
// gettime
|
// gettime
|
||||||
|
@ -2,13 +2,8 @@
|
|||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <input-event-codes.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) table_cos(x)
|
||||||
// #define cos(x) taylor_cos(x)
|
// #define cos(x) taylor_cos(x)
|
||||||
#define min(x, y) ((x < y) ? x : y)
|
#define min(x, y) ((x < y) ? x : y)
|
||||||
@ -25,6 +20,19 @@ using i64 = signed long;
|
|||||||
using f64 = double;
|
using f64 = double;
|
||||||
using f32 = float;
|
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 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 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);
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
bool mouse_down = false;
|
bool mouse_down = true;
|
||||||
int VERSION = -1;
|
int VERSION = -1;
|
||||||
printf("(%d): TESTING FRAMEBUFFER FROM USERSPACE\n", VERSION);
|
printf("(%d): TESTING FRAMEBUFFER FROM USERSPACE\n", VERSION);
|
||||||
Pixel *fb = (Pixel *)syscall_get_fb(6);
|
Pixel *fb = (Pixel *)syscall_get_fb(6);
|
||||||
@ -61,6 +69,7 @@ int main()
|
|||||||
u32 y = 0;
|
u32 y = 0;
|
||||||
u32 width = 40;
|
u32 width = 40;
|
||||||
u32 height = 50;
|
u32 height = 50;
|
||||||
|
unsigned long i = 0;
|
||||||
|
|
||||||
fill_rect(fb, 0, 0, 640, 480, white_color);
|
fill_rect(fb, 0, 0, 640, 480, white_color);
|
||||||
stroke_rect(fb, 10, 10, 20, 20, blue_color, 5);
|
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);
|
stroke_rect(fb, 150, 150, 140, 140, red_color, 15);
|
||||||
draw_cosine(fb, 0, 400, 500, 50, red_color);
|
draw_cosine(fb, 0, 400, 500, 50, red_color);
|
||||||
syscall_inv_rect(6, x, y, 640, 480);
|
syscall_inv_rect(6, x, y, 640, 480);
|
||||||
|
i64 abs;
|
||||||
do {
|
do {
|
||||||
i64 key = syscall_get_key();
|
|
||||||
i64 abs = syscall_get_abs();
|
if ((abs = syscall_get_abs(events, MAX_EVENTS)) < 1) {
|
||||||
if (key == -1 && abs == -1) {
|
|
||||||
syscall_sleep(noevt_slptm);
|
syscall_sleep(noevt_slptm);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (key != -1) {
|
for (i64 z = 0;z < abs;z++) {
|
||||||
short code = key >> 16;
|
Event &ev = events[z];
|
||||||
bool pressed = (key & 1) ? true : false;
|
if (ev.code == ABS_X) {
|
||||||
// printf("%s key %d\n", pressed ? "pressed" : "released", code);
|
x = lerp(ev.value & 0xffff, 32767, 640);
|
||||||
if (code == BTN_LEFT) { // left mouse button
|
fill_rect(fb, x, y, 5, 5, orange_color);
|
||||||
mouse_down = pressed;
|
}
|
||||||
}
|
else if (ev.code == ABS_Y) {
|
||||||
}
|
y = lerp(ev.value & 0xffff, 32767, 480);
|
||||||
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) {
|
|
||||||
fill_rect(fb, x, y, 5, 5, orange_color);
|
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);
|
} while (true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,6 @@ extern "C"
|
|||||||
#define syscall_get_fb(x) make_syscall(1000, (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_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) 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)
|
#define syscall_get_time() make_syscall(1062)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user