Add snake gui app and update os/usr parts. Now snake can run!

This commit is contained in:
Yu Chen 2023-01-08 22:41:41 +08:00
parent b40120f8ff
commit 2cbd237260
14 changed files with 457 additions and 15 deletions

View file

@ -15,9 +15,8 @@ xmas-elf = "0.7.0"
volatile = "0.3"
#virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "4ee80e5" }
virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "70b5850" }
easy-fs = { path = "../easy-fs" }
virtio-input-decoder = "0.1.4"
#virtio-input-decoder = "0.1.4"
embedded-graphics = "0.7.1"
tinybmp = "0.3.1"

View file

@ -12,7 +12,7 @@ pub type CharDeviceImpl = crate::drivers::chardev::NS16550a<VIRT_UART>;
pub const VIRT_PLIC: usize = 0xC00_0000;
pub const VIRT_UART: usize = 0x1000_0000;
#[allow(unused)]
pub const VIRTGPU_XRES: u32 = 1280;
#[allow(unused)]
pub const VIRTGPU_YRES: u32 = 800;

View file

@ -131,7 +131,7 @@ pub struct NS16550a<const BASE_ADDR: usize> {
impl<const BASE_ADDR: usize> NS16550a<BASE_ADDR> {
pub fn new() -> Self {
let mut inner = NS16550aInner {
let inner = NS16550aInner {
ns16550a: NS16550aRaw::new(BASE_ADDR),
read_buffer: VecDeque::new(),
};
@ -141,6 +141,10 @@ impl<const BASE_ADDR: usize> NS16550a<BASE_ADDR> {
condvar: Condvar::new(),
}
}
pub fn read_buffer_is_empty(&self) -> bool {
self.inner.exclusive_session(|inner| inner.read_buffer.is_empty())
}
}
impl<const BASE_ADDR: usize> CharDevice for NS16550a<BASE_ADDR> {

View file

@ -1,12 +1,10 @@
use crate::drivers::bus::virtio::VirtioHal;
use crate::sync::{Condvar, UPIntrFreeCell};
use crate::task::schedule;
use alloc::collections::BTreeMap;
use alloc::collections::VecDeque;
use alloc::sync::Arc;
use core::any::Any;
use virtio_drivers::{VirtIOHeader, VirtIOInput};
use virtio_input_decoder::{Decoder, Key, KeyType};
const VIRTIO5: usize = 0x10005000;
const VIRTIO6: usize = 0x10006000;
@ -112,7 +110,8 @@ impl InputDevice for VirtIOInputWrapper {
| (event.code as u64) << 32
| (event.value) as u64;
inner.events.push_back(result);
println!("[KERN] inputdev_handle_irq: event: {:x}", result);
// for test
//println!("[KERN] inputdev_handle_irq: event: {:x}", result);
}
});
if count > 0 {

View file

@ -96,4 +96,4 @@ pub fn sys_dup(fd: usize) -> isize {
let new_fd = inner.alloc_fd();
inner.fd_table[new_fd] = Some(Arc::clone(inner.fd_table[fd].as_ref().unwrap()));
new_fd as isize
}
}

View file

@ -14,4 +14,16 @@ pub fn sys_event_get() ->isize {
0
}
}
use crate::drivers::chardev::UART;
/// check UART's read-buffer is empty or not
pub fn sys_key_pressed() -> isize {
let res =!UART.read_buffer_is_empty();
if res {
1
} else {
0
}
}

View file

@ -28,6 +28,7 @@ const SYSCALL_CONDVAR_WAIT: usize = 1032;
const SYSCALL_FRAMEBUFFER: usize = 2000;
const SYSCALL_FRAMEBUFFER_FLUSH: usize = 2001;
const SYSCALL_EVENT_GET: usize = 3000;
const SYSCALL_KEY_PRESSED: usize = 3001;
mod fs;
mod process;
@ -75,6 +76,7 @@ pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
SYSCALL_FRAMEBUFFER => sys_framebuffer(),
SYSCALL_FRAMEBUFFER_FLUSH => sys_framebuffer_flush(),
SYSCALL_EVENT_GET => sys_event_get(),
SYSCALL_KEY_PRESSED => sys_key_pressed(),
_ => panic!("Unsupported syscall_id: {}", syscall_id),
}
}