Skip to content

Commit fbb5923

Browse files
committed
Add snake gui app and update os/usr parts. Now snake can run!
1 parent af05b65 commit fbb5923

File tree

14 files changed

+457
-15
lines changed

14 files changed

+457
-15
lines changed

os/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ xmas-elf = "0.7.0"
1515
volatile = "0.3"
1616
#virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "4ee80e5" }
1717
virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "70b5850" }
18-
1918
easy-fs = { path = "../easy-fs" }
20-
virtio-input-decoder = "0.1.4"
19+
#virtio-input-decoder = "0.1.4"
2120
embedded-graphics = "0.7.1"
2221
tinybmp = "0.3.1"
2322

os/src/boards/qemu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub type CharDeviceImpl = crate::drivers::chardev::NS16550a<VIRT_UART>;
1212

1313
pub const VIRT_PLIC: usize = 0xC00_0000;
1414
pub const VIRT_UART: usize = 0x1000_0000;
15-
15+
#[allow(unused)]
1616
pub const VIRTGPU_XRES: u32 = 1280;
1717
#[allow(unused)]
1818
pub const VIRTGPU_YRES: u32 = 800;

os/src/drivers/chardev/ns16550a.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub struct NS16550a<const BASE_ADDR: usize> {
131131

132132
impl<const BASE_ADDR: usize> NS16550a<BASE_ADDR> {
133133
pub fn new() -> Self {
134-
let mut inner = NS16550aInner {
134+
let inner = NS16550aInner {
135135
ns16550a: NS16550aRaw::new(BASE_ADDR),
136136
read_buffer: VecDeque::new(),
137137
};
@@ -141,6 +141,10 @@ impl<const BASE_ADDR: usize> NS16550a<BASE_ADDR> {
141141
condvar: Condvar::new(),
142142
}
143143
}
144+
145+
pub fn read_buffer_is_empty(&self) -> bool {
146+
self.inner.exclusive_session(|inner| inner.read_buffer.is_empty())
147+
}
144148
}
145149

146150
impl<const BASE_ADDR: usize> CharDevice for NS16550a<BASE_ADDR> {

os/src/drivers/input/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use crate::drivers::bus::virtio::VirtioHal;
22
use crate::sync::{Condvar, UPIntrFreeCell};
33
use crate::task::schedule;
4-
use alloc::collections::BTreeMap;
54
use alloc::collections::VecDeque;
65
use alloc::sync::Arc;
76
use core::any::Any;
87
use virtio_drivers::{VirtIOHeader, VirtIOInput};
9-
use virtio_input_decoder::{Decoder, Key, KeyType};
108

119
const VIRTIO5: usize = 0x10005000;
1210
const VIRTIO6: usize = 0x10006000;
@@ -112,7 +110,8 @@ impl InputDevice for VirtIOInputWrapper {
112110
| (event.code as u64) << 32
113111
| (event.value) as u64;
114112
inner.events.push_back(result);
115-
println!("[KERN] inputdev_handle_irq: event: {:x}", result);
113+
// for test
114+
//println!("[KERN] inputdev_handle_irq: event: {:x}", result);
116115
}
117116
});
118117
if count > 0 {

os/src/syscall/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ pub fn sys_dup(fd: usize) -> isize {
9696
let new_fd = inner.alloc_fd();
9797
inner.fd_table[new_fd] = Some(Arc::clone(inner.fd_table[fd].as_ref().unwrap()));
9898
new_fd as isize
99-
}
99+
}

os/src/syscall/input.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@ pub fn sys_event_get() ->isize {
1414
0
1515
}
1616

17+
}
18+
19+
use crate::drivers::chardev::UART;
20+
21+
/// check UART's read-buffer is empty or not
22+
pub fn sys_key_pressed() -> isize {
23+
let res =!UART.read_buffer_is_empty();
24+
if res {
25+
1
26+
} else {
27+
0
28+
}
1729
}

os/src/syscall/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const SYSCALL_CONDVAR_WAIT: usize = 1032;
2828
const SYSCALL_FRAMEBUFFER: usize = 2000;
2929
const SYSCALL_FRAMEBUFFER_FLUSH: usize = 2001;
3030
const SYSCALL_EVENT_GET: usize = 3000;
31+
const SYSCALL_KEY_PRESSED: usize = 3001;
3132

3233
mod fs;
3334
mod process;
@@ -75,6 +76,7 @@ pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
7576
SYSCALL_FRAMEBUFFER => sys_framebuffer(),
7677
SYSCALL_FRAMEBUFFER_FLUSH => sys_framebuffer_flush(),
7778
SYSCALL_EVENT_GET => sys_event_get(),
79+
SYSCALL_KEY_PRESSED => sys_key_pressed(),
7880
_ => panic!("Unsupported syscall_id: {}", syscall_id),
7981
}
8082
}

user/Cargo.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ buddy_system_allocator = "0.6"
1111
bitflags = "1.2.1"
1212
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
1313
embedded-graphics = "0.7.1"
14-
# lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
15-
14+
oorandom ="11"
1615
[profile.release]
17-
debug = true
18-
19-
# [features]
20-
# board_qemu = []
21-
# board_k210 = []
16+
debug = true
File renamed without changes.

0 commit comments

Comments
 (0)