Skip to content

Commit

Permalink
Add snake gui app and update os/usr parts. Now snake can run!
Browse files Browse the repository at this point in the history
  • Loading branch information
chyyuu committed Jan 8, 2023
1 parent af05b65 commit fbb5923
Show file tree
Hide file tree
Showing 14 changed files with 457 additions and 15 deletions.
3 changes: 1 addition & 2 deletions os/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion os/src/boards/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion os/src/drivers/chardev/ns16550a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand All @@ -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> {
Expand Down
5 changes: 2 additions & 3 deletions os/src/drivers/input/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion os/src/syscall/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
12 changes: 12 additions & 0 deletions os/src/syscall/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 2 additions & 0 deletions os/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
}
}
9 changes: 2 additions & 7 deletions user/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ buddy_system_allocator = "0.6"
bitflags = "1.2.1"
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
embedded-graphics = "0.7.1"
# lazy_static = { version = "1.4.0", features = ["spin_no_std"] }

oorandom ="11"
[profile.release]
debug = true

# [features]
# board_qemu = []
# board_k210 = []
debug = true
File renamed without changes.
Loading

0 comments on commit fbb5923

Please sign in to comment.