broken cbfa to fix for a while
This commit is contained in:
@@ -1,126 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use rand::prelude::*;
|
||||
|
||||
use super::{
|
||||
engine::{eventcheck, Choice, Event},
|
||||
entity::{Entity, Enemy, EntityObject},
|
||||
player::Player,
|
||||
};
|
||||
|
||||
use alloc::{boxed::Box, string::{String, ToString}, vec::Vec, format, borrow::ToOwned};
|
||||
|
||||
use crate::{
|
||||
std::application::{
|
||||
Application,
|
||||
Error,
|
||||
},
|
||||
std::{
|
||||
io::{self, println, serial_println, FRAMEGEN, Element},
|
||||
random,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
pub struct GameLoop;
|
||||
|
||||
|
||||
#[async_trait]
|
||||
impl Application for GameLoop {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
async fn run(&mut self, _args: Vec<String>) -> Result<(), Error> {
|
||||
|
||||
let mut username: String = io::stdin().await;
|
||||
username = username.trim().to_string();
|
||||
|
||||
let mut player = Player::new(username);
|
||||
|
||||
let mut enemy = Enemy::new();
|
||||
|
||||
for _ in 0..30 {
|
||||
match (eventcheck(player.attack_entity(&mut EntityObject::Enemy(&mut enemy)))) {
|
||||
Choice::A(result) => {
|
||||
println!("{}", result);
|
||||
},
|
||||
Choice::B(event) => {
|
||||
println!("{}", event);
|
||||
match event {
|
||||
Event::PlayerKilled => {
|
||||
println!(" [!] {} was slain by Enemy\n\n[ You lost! ]", player.username);
|
||||
break;
|
||||
}
|
||||
Event::EntityKilled(entity) => {
|
||||
println!("\n [!] Enemy was slain by {}\n\n [ You won! ]", player.username);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("{}", eventcheck(enemy.attack_entity(&mut EntityObject::Player(&mut player))));
|
||||
println!("[{}\n[{}", player, enemy);
|
||||
}
|
||||
|
||||
FRAMEGEN.lock().render_frame();
|
||||
|
||||
|
||||
let string = String::from(format!(
|
||||
"┌────────────────────────────┐
|
||||
│ {}
|
||||
│ {} / {}
|
||||
└────────────────────────────┘"
|
||||
, player.username, player.health_points, player.max_health_points));
|
||||
let mut healthbar = Element::from_str(string);
|
||||
healthbar.render((1, 1));
|
||||
|
||||
let new2 = String::from("slushy stfu");
|
||||
let mut new = Element::from_str(new2);
|
||||
|
||||
new.render((10, 20));
|
||||
|
||||
|
||||
|
||||
FRAMEGEN.lock().render_frame();
|
||||
|
||||
let fr = FRAMEGEN.lock().get_frame().to_owned();
|
||||
serial_println!("{}", {
|
||||
let mut string = String::new();
|
||||
for row in fr {
|
||||
let mut r = String::new();
|
||||
for col in row {
|
||||
r.push(col);
|
||||
}
|
||||
string.push_str(&r);
|
||||
string.push('\n')
|
||||
};
|
||||
string
|
||||
});
|
||||
|
||||
|
||||
loop {
|
||||
println!("{}", io::stdchar().await)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn random() -> u64 {
|
||||
let mut r = random::Random::int(0, 125) as u64;
|
||||
r
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use alloc::{boxed::Box, string::String, vec::Vec};
|
||||
|
||||
use crate::{
|
||||
kernel::{
|
||||
os::OS,
|
||||
render::{Color, write}
|
||||
},
|
||||
println,
|
||||
std::application::{
|
||||
Application,
|
||||
Error,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
pub struct CrystalFetch {}
|
||||
|
||||
#[async_trait]
|
||||
impl Application for CrystalFetch {
|
||||
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
async fn run(&mut self, _args: Vec<String>) -> Result<(), Error> {
|
||||
|
||||
let os = OS.lock().os.clone();
|
||||
let version = OS.lock().version.clone();
|
||||
|
||||
|
||||
write(format_args!("
|
||||
────────────────────────────────────────────────────────
|
||||
_____ _ _ ____ _____
|
||||
/ ____| | | | |/ __ \\ / ____|
|
||||
| | _ __ _ _ ___| |_ __ _| | | | | (___
|
||||
| | | '__| | | / __| __/ _` | | | | |\\___ \\
|
||||
| |____| | | |_| \\__ \\ || (_| | | |__| |____) |
|
||||
\\_____|_| \\__, |___/\\__\\__,_|_|\\____/|_____/
|
||||
__/ |
|
||||
|___/
|
||||
"), (Color::Magenta, Color::Black));
|
||||
|
||||
println!("
|
||||
╔═══════════════════════════════
|
||||
║
|
||||
║ OS » {}
|
||||
║ BUILD » {}
|
||||
║ RAM » idk
|
||||
║ Shell » CrystalSH
|
||||
║ API » CrystalAPI
|
||||
║ Pkgs » 4
|
||||
║ Fetch » CrystalFetch
|
||||
║
|
||||
╚═══════════════════════════════
|
||||
|
||||
────────────────────────────────────────────────────────
|
||||
", os, version);
|
||||
Ok(())
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
|
||||
/*
|
||||
|
||||
[ Cry-SH ]
|
||||
|
||||
CrystalOS shell rewrite to replace the original shell implementation
|
||||
this shell should support:
|
||||
- running basic commands
|
||||
- a prompt that displays the status of the last command
|
||||
- customised error messages returned from applications
|
||||
- invoking any application with arguments
|
||||
- cycling through previous commands with arrow keys
|
||||
- parsing of basic mathematical expressions using the calc module
|
||||
- chained commands using the '|' or pipe operator which sends the output
|
||||
of one command to the next
|
||||
*/
|
||||
|
||||
// import necessary modules
|
||||
|
||||
use async_trait::async_trait;
|
||||
use lazy_static::lazy_static;
|
||||
use spin::Mutex;
|
||||
use x86_64::instructions::interrupts;
|
||||
|
||||
use alloc::{string::{String, ToString}, vec::Vec, boxed::Box};
|
||||
|
||||
use crate::{
|
||||
kernel::tasks::keyboard::KEYBOARD,
|
||||
std::application::{Error, Application}
|
||||
std::io::{println, print};
|
||||
};
|
||||
|
||||
use super::*
|
||||
+3
-7
@@ -17,14 +17,12 @@ use core::panic::PanicInfo;
|
||||
pub mod system;
|
||||
pub mod user;
|
||||
|
||||
pub use system::kernel as kernel;
|
||||
pub use system::std as std;
|
||||
pub use user::bin::*;
|
||||
|
||||
extern crate alloc;
|
||||
//extern crate fatfs;
|
||||
|
||||
#[cfg(test)]
|
||||
use bootloader::{entry_point, BootInfo};
|
||||
|
||||
|
||||
@@ -36,10 +34,8 @@ fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
|
||||
panic!("error while allocating: {:?}", layout)
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn init() {
|
||||
system::init();
|
||||
pub fn start(boot_info: &'static BootInfo) {
|
||||
system::init(boot_info);
|
||||
}
|
||||
|
||||
pub fn hlt() -> ! {
|
||||
@@ -77,7 +73,7 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
|
||||
|
||||
#[cfg(test)]
|
||||
fn test_kernel_main(_boot_info: &'static BootInfo) -> ! {
|
||||
init();
|
||||
start();
|
||||
test_main();
|
||||
hlt();
|
||||
}
|
||||
|
||||
+4
-17
@@ -6,15 +6,15 @@
|
||||
|
||||
use bootloader::{entry_point, BootInfo};
|
||||
use core::panic::PanicInfo;
|
||||
use CrystalOS::kernel::tasks::{executor::Executor, Task};
|
||||
use CrystalOS::{kernel, print, print_log, printerr, println, println_log};
|
||||
use CrystalOS::std::tasks::{Executor, Task};
|
||||
use CrystalOS::{print, print_log, printerr, println, println_log, std::syscall};
|
||||
extern crate alloc;
|
||||
use CrystalOS::user::bin::shell;
|
||||
|
||||
#[cfg(not(test))]
|
||||
#[panic_handler]
|
||||
fn panic(_info: &PanicInfo) -> ! {
|
||||
kernel::render::RENDERER.lock().terminal_mode_force();
|
||||
syscall::terminal_mode_force();
|
||||
printerr!("{}", _info);
|
||||
CrystalOS::hlt();
|
||||
}
|
||||
@@ -28,23 +28,10 @@ fn panic(info: &PanicInfo) -> ! {
|
||||
entry_point!(main);
|
||||
|
||||
fn main(boot_info: &'static BootInfo) -> ! {
|
||||
use x86_64::VirtAddr;
|
||||
use CrystalOS::kernel::allocator;
|
||||
use CrystalOS::kernel::memory;
|
||||
use CrystalOS::kernel::memory::BootInfoFrameAllocator;
|
||||
|
||||
CrystalOS::init();
|
||||
|
||||
let physical_memory_offset = VirtAddr::new(boot_info.physical_memory_offset);
|
||||
let mut mapper = unsafe { memory::init(physical_memory_offset) };
|
||||
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) };
|
||||
|
||||
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialisation failed");
|
||||
CrystalOS::start(boot_info);
|
||||
|
||||
let mut executor = Executor::new();
|
||||
|
||||
executor.spawn(Task::new(shell::command_handler()));
|
||||
|
||||
loop {
|
||||
executor.try_run();
|
||||
}
|
||||
|
||||
@@ -1,290 +0,0 @@
|
||||
use core::fmt;
|
||||
use lazy_static::lazy_static;
|
||||
use spin::Mutex;
|
||||
use volatile::Volatile;
|
||||
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub enum Color {
|
||||
Black = 0,
|
||||
Blue = 1,
|
||||
Green = 2,
|
||||
Cyan = 3,
|
||||
Red = 4,
|
||||
Magenta = 5,
|
||||
Brown = 6,
|
||||
LightGray = 7,
|
||||
DarkGray = 8,
|
||||
LightBlue = 9,
|
||||
LightGreen = 10,
|
||||
LightCyan = 11,
|
||||
LightRed = 12,
|
||||
Pink = 13,
|
||||
Yellow = 14,
|
||||
White = 15,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(transparent)]
|
||||
pub struct ColorCode(u8);
|
||||
|
||||
impl ColorCode {
|
||||
pub fn new(foreground: Color, background: Color) -> ColorCode {
|
||||
ColorCode((background as u8) << 5 | (foreground as u8))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(C)]
|
||||
struct ScreenChar {
|
||||
character: u8,
|
||||
colour: ColorCode,
|
||||
}
|
||||
|
||||
pub const BUFFER_HEIGHT: usize = 25;
|
||||
pub const BUFFER_WIDTH: usize = 80;
|
||||
|
||||
#[repr(transparent)]
|
||||
struct Buffer {
|
||||
chars: [[Volatile<ScreenChar>; BUFFER_WIDTH]; BUFFER_HEIGHT],
|
||||
}
|
||||
|
||||
struct BufferSwap {
|
||||
chars: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT],
|
||||
}
|
||||
struct CharGrid {
|
||||
chars: Vec<[ScreenChar; BUFFER_WIDTH]>,
|
||||
}
|
||||
|
||||
pub struct Renderer {
|
||||
col_pos: usize,
|
||||
pub col_code: ColorCode,
|
||||
buffer: &'static mut Buffer,
|
||||
userspace: BufferSwap,
|
||||
upwards: CharGrid,
|
||||
downwards: CharGrid,
|
||||
pub sandbox: bool,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
lazy_static! {
|
||||
pub static ref RENDERER: Mutex<Renderer> = Mutex::new(Renderer {
|
||||
col_pos: 0,
|
||||
col_code: ColorCode::new(Color::White, Color::Black),
|
||||
buffer: unsafe { &mut *(0xb8000 as *mut Buffer) },
|
||||
userspace: BufferSwap {
|
||||
chars: [[ScreenChar {
|
||||
character: 178u8,
|
||||
colour: ColorCode::new(Color::White, Color::Black),
|
||||
}; BUFFER_WIDTH]; BUFFER_HEIGHT]
|
||||
},
|
||||
upwards: CharGrid {
|
||||
chars: vec![
|
||||
[ScreenChar {
|
||||
character: 32u8,
|
||||
colour: ColorCode::new(Color::White, Color::Black),
|
||||
}; 80]
|
||||
]
|
||||
},
|
||||
downwards: CharGrid {
|
||||
chars: vec![
|
||||
[ScreenChar {
|
||||
character: 32u8,
|
||||
colour: ColorCode::new(Color::White, Color::Black),
|
||||
}; 80]
|
||||
]
|
||||
},
|
||||
sandbox: false,
|
||||
});
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn text_mode(&mut self) -> Result<(), ()> {
|
||||
if !self.sandbox {
|
||||
return Err(());
|
||||
};
|
||||
self.buffer_swap().unwrap();
|
||||
self.sandbox = false;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn sandbox_mode(&mut self) -> Result<(), ()> {
|
||||
if self.sandbox {
|
||||
return Err(());
|
||||
};
|
||||
self.buffer_swap().unwrap();
|
||||
self.sandbox = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn buffer_swap(&mut self) -> Result<(), ()> {
|
||||
for (i, _) in self.userspace.chars.clone().iter().enumerate() {
|
||||
let tmp = self.buffer.chars[i].clone();
|
||||
|
||||
for (j, col) in self.userspace.chars[i].clone().iter().enumerate() {
|
||||
self.buffer.chars[i][j].write(col.to_owned())
|
||||
}
|
||||
|
||||
for (j, _) in tmp.iter().enumerate() {
|
||||
self.userspace.chars[i][j] = tmp[j].read().to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn render_frame(&mut self, frame: [[char; BUFFER_WIDTH]; BUFFER_HEIGHT]) {
|
||||
for (i, row) in frame.iter().enumerate() {
|
||||
for (j, col) in row.iter().enumerate() {
|
||||
if let Some(c) = self.fancy_char(*col) {
|
||||
self.buffer.chars[i][j].write(ScreenChar {
|
||||
character: c,
|
||||
colour: self.col_code,
|
||||
});
|
||||
} else {
|
||||
self.buffer.chars[i][j].write(ScreenChar {
|
||||
character: *col as u8,
|
||||
colour: self.col_code,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_string(&mut self, string: &str) {
|
||||
for ch in string.chars() {
|
||||
if let Some(x) = self.fancy_char(ch) {
|
||||
self.write_byte(x)
|
||||
} else {
|
||||
match ch as u8 {
|
||||
0x20..=0xff | b'\n' => self.write_byte(ch as u8),
|
||||
_ => self.write_byte(0xfe),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fancy_char(&self, ch: char) -> Option<u8> {
|
||||
let res: u8 = match ch {
|
||||
'│' => 179,
|
||||
'─' => 196,
|
||||
'┴' => 193,
|
||||
'┤' => 180,
|
||||
'═' => 205,
|
||||
'║' => 186,
|
||||
'╗' => 187,
|
||||
'╝' => 188,
|
||||
'╚' => 200,
|
||||
'╔' => 201,
|
||||
'»' => 175,
|
||||
'┐' => 191,
|
||||
'└' => 192,
|
||||
'┘' => 217,
|
||||
'┌' => 218,
|
||||
'┼' => 197,
|
||||
'░' => 176,
|
||||
'▓' => 178,
|
||||
'«' => 174,
|
||||
'»' => 175,
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
|
||||
pub fn backspace(&mut self) -> Result<(), ()> {
|
||||
if self.col_pos == 0 {
|
||||
self.undonewline();
|
||||
}
|
||||
self.col_pos -= 1;
|
||||
let row = BUFFER_HEIGHT - 1;
|
||||
let col = self.col_pos;
|
||||
|
||||
let blank = ScreenChar {
|
||||
character: b' ',
|
||||
colour: self.col_code,
|
||||
};
|
||||
self.buffer.chars[row][col].write(blank);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_byte(&mut self, byte: u8) {
|
||||
match byte {
|
||||
b'\n' => self.newline(),
|
||||
byte => {
|
||||
if self.col_pos >= BUFFER_WIDTH {
|
||||
self.newline();
|
||||
}
|
||||
let row = BUFFER_HEIGHT - 1;
|
||||
let col = self.col_pos;
|
||||
let col_code = self.col_code;
|
||||
self.buffer.chars[row][col].write(ScreenChar {
|
||||
character: byte,
|
||||
colour: col_code,
|
||||
});
|
||||
self.col_pos += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
fn newline(&mut self) {
|
||||
for row in 1..BUFFER_HEIGHT {
|
||||
for col in 0..BUFFER_WIDTH {
|
||||
let character = self.buffer.chars[row][col].read();
|
||||
self.buffer.chars[row - 1][col].write(character);
|
||||
}
|
||||
}
|
||||
self.clear_row(BUFFER_HEIGHT - 1);
|
||||
self.col_pos = 0;
|
||||
}
|
||||
|
||||
pub fn undonewline(&mut self) {
|
||||
for row in (0..BUFFER_HEIGHT - 1).rev() {
|
||||
for col in 0..BUFFER_WIDTH {
|
||||
let character = self.buffer.chars[row][col].read();
|
||||
self.buffer.chars[row + 1][col].write(character);
|
||||
}
|
||||
}
|
||||
self.clear_row(0);
|
||||
self.col_pos = BUFFER_WIDTH;
|
||||
}
|
||||
pub fn clear(&mut self) {
|
||||
for row in (0..BUFFER_HEIGHT - 1).rev() {
|
||||
self.clear_row(row);
|
||||
}
|
||||
}
|
||||
|
||||
fn clear_row(&mut self, row: usize) {
|
||||
let blank = ScreenChar {
|
||||
character: b' ',
|
||||
colour: self.col_code,
|
||||
};
|
||||
for col in 0..BUFFER_WIDTH {
|
||||
self.buffer.chars[row][col].write(blank);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Write for Renderer {
|
||||
fn write_str(&mut self, string: &str) -> fmt::Result {
|
||||
self.write_string(string);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(args: fmt::Arguments, cols: (Color, Color)) {
|
||||
use core::fmt::Write;
|
||||
use x86_64::instructions::interrupts;
|
||||
interrupts::without_interrupts(|| {
|
||||
let mut writer = RENDERER.lock();
|
||||
writer.col_code = ColorCode::new(cols.0, cols.1);
|
||||
writer.write_fmt(args).unwrap()
|
||||
})
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||
use crate::{print, println};
|
||||
use crate::kernel::gdt;
|
||||
use super::gdt;
|
||||
use lazy_static::lazy_static;
|
||||
use spin;
|
||||
use pic8259::ChainedPics;
|
||||
@@ -42,7 +42,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
|
||||
let mut port = Port::new(0x60);
|
||||
let scancode: u8 = unsafe { port.read() };
|
||||
|
||||
crate::kernel::tasks::keyboard::add_scancode(scancode);
|
||||
super::tasks::keyboard::add_scancode(scancode);
|
||||
|
||||
unsafe {
|
||||
PICS.lock().notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
|
||||
|
||||
@@ -6,7 +6,7 @@ use volatile::Volatile;
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
use crate::kernel::render::RenderError::InvalidRenderMode;
|
||||
use crate::system::kernel::render::RenderError::InvalidRenderMode;
|
||||
use crate::serial_println;
|
||||
use crate::std::io::Screen;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ lazy_static! {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn _print(args: core::fmt::Arguments) {
|
||||
pub fn _serial_print(args: core::fmt::Arguments) {
|
||||
use core::fmt::Write;
|
||||
use x86_64::instructions::interrupts;
|
||||
|
||||
@@ -38,22 +38,3 @@ pub fn serial_reply(chr: char) -> char {
|
||||
chr_return
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! serial_print {
|
||||
($($arg:tt)*) => {
|
||||
$crate::kernel::serial::_print(format_args!($($arg)*));
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! serial_println {
|
||||
() => (serial_print!("\n"));
|
||||
($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n")));
|
||||
($fmt:expr, $($arg:tt)*) => (
|
||||
$crate::serial_print!(
|
||||
concat!($fmt, "\n"), $($arg)*
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use futures_util::task::AtomicWaker;
|
||||
use futures_util::stream::StreamExt;
|
||||
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1, KeyCode};
|
||||
use crate::print;
|
||||
use crate::kernel::render::RENDERER;
|
||||
use crate::system::kernel::render::RENDERER;
|
||||
use alloc::{string::String};
|
||||
|
||||
static WAKER: AtomicWaker = AtomicWaker::new();
|
||||
|
||||
+15
-3
@@ -1,10 +1,22 @@
|
||||
pub mod std;
|
||||
pub mod kernel;
|
||||
use bootloader::BootInfo;
|
||||
use x86_64::VirtAddr;
|
||||
use crate::system::kernel::{allocator, memory};
|
||||
use crate::system::kernel::memory::BootInfoFrameAllocator;
|
||||
|
||||
pub fn init() {
|
||||
pub mod std;
|
||||
mod kernel;
|
||||
|
||||
pub fn init(boot_info : &'static BootInfo) {
|
||||
kernel::gdt::init();
|
||||
kernel::interrupts::init_idt();
|
||||
unsafe { kernel::interrupts::PICS.lock().initialize() };
|
||||
x86_64::instructions::interrupts::enable();
|
||||
|
||||
kernel::sysinit::init().unwrap();
|
||||
|
||||
let physical_memory_offset = VirtAddr::new(boot_info.physical_memory_offset);
|
||||
let mut mapper = unsafe { memory::init(physical_memory_offset) };
|
||||
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) };
|
||||
|
||||
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialisation failed");
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
use alloc::string::String;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
use lazy_static::lazy_static;
|
||||
use crate::kernel::render::{BUFFER_HEIGHT, BUFFER_WIDTH, ColorCode, RENDERER, ScreenChar};
|
||||
use crate::{println, serial_println};
|
||||
use spin::Mutex;
|
||||
use crate::system::kernel::render::{BUFFER_HEIGHT, BUFFER_WIDTH, RENDERER, ScreenChar};
|
||||
use crate::std::io::{Color, Screen};
|
||||
|
||||
/// TODO: get a working implementation for CLI apps
|
||||
@@ -13,11 +10,9 @@ use crate::std::io::{Color, Screen};
|
||||
/// the position of the element by passing a tuple (x,y) to render()
|
||||
///
|
||||
/// nothing will appear on the screen until the frame is actually rendered by
|
||||
/// the render_frame method on the renderer
|
||||
|
||||
pub use crate::system::kernel::render::{special_char, RenderError};
|
||||
|
||||
/// the write_to_screen() method on the renderer
|
||||
|
||||
pub use crate::system::kernel::render::{special_char, RenderError, ColorCode};
|
||||
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
|
||||
+29
-13
@@ -1,20 +1,17 @@
|
||||
use crate::{
|
||||
kernel::render::{RENDERER, self},
|
||||
kernel::tasks::keyboard::{KEYBOARD},
|
||||
use crate::system::kernel::{
|
||||
render::{RENDERER, self, RenderError},
|
||||
tasks::keyboard::{KEYBOARD},
|
||||
serial::{serial_reply},
|
||||
};
|
||||
|
||||
pub use crate::system::kernel::{
|
||||
tasks::keyboard::KeyStroke,
|
||||
serial::{_serial_print},
|
||||
render::{Color, ColorCode},
|
||||
};
|
||||
pub use crate::kernel::tasks::keyboard::KeyStroke;
|
||||
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
pub use crate::{print, println, serial_print, serial_println};
|
||||
pub use crate::kernel::render::Color;
|
||||
use crate::kernel::serial::serial_reply;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use spin::Mutex;
|
||||
use crate::kernel::render::Renderer;
|
||||
use crate::std::frame::RenderError;
|
||||
|
||||
pub struct Stdin {}
|
||||
impl Stdin {
|
||||
@@ -109,6 +106,25 @@ macro_rules! printerr {
|
||||
($($arg:tt)*) => ($crate::std::io::_printerr(format_args!($($arg)*)));
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! serial_print {
|
||||
($($arg:tt)*) => {
|
||||
$crate::std::io::_serial_print(format_args!($($arg)*));
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! serial_println {
|
||||
() => (serial_print!("\n"));
|
||||
($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n")));
|
||||
($fmt:expr, $($arg:tt)*) => (
|
||||
$crate::serial_print!(
|
||||
concat!($fmt, "\n"), $($arg)*
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn _print(args: core::fmt::Arguments) {
|
||||
render::write(args, (Color::White, Color::Black));
|
||||
|
||||
@@ -5,6 +5,7 @@ pub mod tasks;
|
||||
pub mod os;
|
||||
pub mod frame;
|
||||
pub mod time;
|
||||
pub mod syscall;
|
||||
|
||||
|
||||
// this is where the standard library for the operating system will be defined
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
/// THIS FILE IS ONLY FOR SPECIFIC CASES WHERE THE MAIN FUNCTION NEEDS DIRECT KERNEL INTERACTION
|
||||
|
||||
use crate::system::kernel::render::RENDERER;
|
||||
|
||||
pub fn terminal_mode_force() {
|
||||
RENDERER.lock().terminal_mode_force();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
pub use crate::kernel::tasks::{Task, executor::Executor};
|
||||
pub use crate::system::kernel::tasks::{Task, executor::Executor};
|
||||
|
||||
pub fn stop() -> ! {
|
||||
loop {
|
||||
|
||||
@@ -5,10 +5,8 @@ use alloc::vec::Vec;
|
||||
use alloc::boxed::Box;
|
||||
use crate::std::application::{Application, Error};
|
||||
use async_trait::async_trait;
|
||||
use crate::kernel::render::{Color, ColorCode};
|
||||
use crate::{println, serial_println};
|
||||
use crate::std::frame::{ColouredChar, Frame, Position, Dimensions, RenderError};
|
||||
use crate::std::io::{KeyStroke, Screen, Stdin};
|
||||
use crate::std::io::{KeyStroke, Screen, Stdin, Color, ColorCode};
|
||||
use crate::std::time::wait;
|
||||
use crate::user::bin::snake::Game;
|
||||
|
||||
|
||||
+12
-6
@@ -2,16 +2,22 @@ use alloc::string::{String, ToString};
|
||||
use alloc::{format, vec};
|
||||
use alloc::vec::Vec;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::sync::Arc;
|
||||
use async_trait::async_trait;
|
||||
use spin::Mutex;
|
||||
use crate::{println, serial_println};
|
||||
use crate::kernel::render::{ColorCode, RenderError};
|
||||
use crate::std::io::{ColorCode};
|
||||
use crate::shell::command_handler;
|
||||
use crate::std::application::{Application, Error};
|
||||
use crate::std::frame::{self, Frame, Position, Dimensions, ColouredChar};
|
||||
use crate::std::frame::{self, Frame, Position, Dimensions, ColouredChar, RenderError};
|
||||
use crate::std::io::{Color, KeyStroke, Screen, Stdin};
|
||||
use crate::user::lib::libgui::cg_core::{CgComponent, CgTextEdit};
|
||||
use crate::user::lib::libgui::cg_inputs::CgLineEdit;
|
||||
use crate::user::lib::libgui::cg_widgets::CgContainer;
|
||||
|
||||
use crate::user::lib::libgui::{
|
||||
cg_core::{CgComponent, CgTextInput, CgInputHandler, CgContainer},
|
||||
cg_widgets::CgContainerWidget,
|
||||
cg_inputs::CgLineEdit,
|
||||
};
|
||||
|
||||
use super::calc;
|
||||
|
||||
const OFFSET_X: i64 = 39;
|
||||
@@ -73,7 +79,7 @@ impl Application for Grapher {
|
||||
let mut commandresult = String::new();
|
||||
|
||||
while let c = Stdin::keystroke().await {
|
||||
let mut container = CgContainer::new(
|
||||
let mut container = CgContainerWidget::new(
|
||||
Position::new(0, 0),
|
||||
Dimensions::new(80, 25),
|
||||
true,
|
||||
|
||||
@@ -6,13 +6,11 @@ use core::cell::RefCell;
|
||||
use async_trait::async_trait;
|
||||
use crate::std::io::{Color, KeyStroke, Screen, Stdin};
|
||||
use crate::std::time;
|
||||
use crate::kernel::tasks::keyboard::KEYBOARD;
|
||||
use crossbeam_queue::SegQueue;
|
||||
use lazy_static::lazy_static;
|
||||
use crate::kernel::render::{ColorCode, ScreenChar};
|
||||
use crate::{println, serial_println};
|
||||
use crate::std::application::{Application, Error};
|
||||
use crate::std::frame::{ColouredChar, Dimensions, Frame, RenderError};
|
||||
use crate::std::frame::{ColouredChar, Dimensions, Frame, RenderError, ColorCode};
|
||||
use crate::std::random::Random;
|
||||
use crate::system::std::frame;
|
||||
use super::super::lib::coords::{Line, Position, Direction};
|
||||
|
||||
@@ -3,7 +3,7 @@ use alloc::boxed::Box;
|
||||
use alloc::string::String;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
use crate::kernel::render::ScreenChar;
|
||||
use crate::std::frame::{ColouredChar};
|
||||
use crate::{serial_print, serial_println};
|
||||
use crate::std::application::{Application, Error};
|
||||
use crate::std::io::Screen;
|
||||
@@ -13,7 +13,7 @@ use crate::user::lib::coords::{Direction, Position, PositionReal};
|
||||
pub(crate) struct TetrisEngine {
|
||||
score: u32,
|
||||
next: TetrisPiece,
|
||||
completed_frame: [[ScreenChar; 80]; 25], // this frame does not contain falling blocks, only static ones
|
||||
completed_frame: [[ColouredChar; 80]; 25], // this frame does not contain falling blocks, only static ones
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ impl Application for TetrisEngine {
|
||||
Self {
|
||||
score: 0,
|
||||
next: TetrisPiece::new(PieceType::OPiece),
|
||||
completed_frame: [[ScreenChar::null(); 80]; 25],
|
||||
completed_frame: [[ColouredChar::null(); 80]; 25],
|
||||
}
|
||||
}
|
||||
async fn run(&mut self, args: Vec<String>) -> Result<(), Error> {
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ fn main(boot_info: &'static BootInfo) -> ! {
|
||||
use CrystalOS::kernel::memory::{self, BootInfoFrameAllocator};
|
||||
use x86_64::VirtAddr;
|
||||
|
||||
CrystalOS::init();
|
||||
CrystalOS::start();
|
||||
|
||||
let physical_memory_offset = VirtAddr::new(boot_info.physical_memory_offset);
|
||||
let mut mapper = unsafe { memory::init(physical_memory_offset)};
|
||||
|
||||
Reference in New Issue
Block a user