Merge remote-tracking branch 'origin/main'

# Conflicts:
#	rickroll.txt
This commit is contained in:
2025-02-18 01:49:18 +00:00
25 changed files with 203 additions and 91 deletions
+19
View File
@@ -12,6 +12,25 @@ while I'm waiting for the third edition to release, I guess I'm gonna just have
- for more details on this project read the wiki ^^^
# Building
- this project unfortunately does not build on the latest rust versions and requires an older nightly build.
the version below (rust v1.68.0-nightly) works:
> rustup override set nightly-2023-01-01
(you may need to install this first)
> rustup install nightly-2023-01-01
- you will need the bare metal x86 target installed:
> rustup target add x86_64-unknown-none
- you will also need several extra rustup components to build the project
> rustup component add llvm-tools-preview
> rustup component add rust-src
(ensure that you are installing the components for the correct nightly build)
- you will also need the bootimage crate which can be installed with the below command:
> cargo install bootimage
- the final requirement is having QEMU desktop installed for your system. on linux this comes in the default repositories of most major distributions.
- finally:
> cargo run
# Features as of Nov 2023
### barebones standard library with the following general features
+4
View File
@@ -0,0 +1,4 @@
never gonna give you up
// "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
-2
View File
@@ -1,2 +0,0 @@
never gonna give you up
never gonna give you up
+3 -1
View File
@@ -1,11 +1,13 @@
use async_trait::async_trait;
use alloc::{string::String, vec::Vec, boxed::Box};
use super::render::Window;
#[async_trait]
pub trait Application {
fn new() -> Self;
async fn run(&mut self, _: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, _window: Option<Window>, _args: Vec<String>) -> Result<(), Error> {
Ok(())
}
}
+5 -37
View File
@@ -48,46 +48,10 @@ impl Serial {
}
}
/// enum with a terminal and application mode
pub enum Screen {
Terminal,
Application,
}
/// DEPRECATED - STOP USING THIS SOON
impl Screen {
/// mode can be set for the kernel using this method
// pub fn set_mode(&self) -> Result<(), RenderError> {
// Ok(match self {
// Screen::Terminal => RENDERER.lock().terminal_mode(),
// Screen::Application => RENDERER.lock().application_mode(),
// })
// }
/// returns the current display mode
pub fn get_mode() -> Screen {
match RENDERER.lock().mode_is_app() {
true => Screen::Application,
false => Screen::Terminal,
}
}
/// switches between modes
pub fn switch(&self) {
if RENDERER.lock().mode_is_app() == true {
RENDERER.lock().terminal_mode();
} else {
RENDERER.lock().application_mode();
}
}
pub fn clear() {
RENDERER.lock().clear();
}
}
/// An interface that tells the kernel what rendering mode to use
/// Creating an instance of this struct will enable application rendering mode
/// Dropping the instance will return the display to focus on the terminal.
/// this will be deprecated in the near future !!
pub struct Display;
impl Display {
@@ -99,6 +63,10 @@ impl Display {
pub fn mv_cursor(&self, x: u8, y: u8) -> Result<(), RenderError> {
RENDERER.lock().cursor_position(x, y)
}
pub fn clear() {
RENDERER.lock().clear();
}
}
impl Drop for Display {
+57
View File
@@ -21,6 +21,53 @@ pub use crate::system::kernel::render::{
BUFFER_HEIGHT
};
pub struct Window {
width: u32,
height: u32,
x: u32,
y: u32,
bordered: bool,
open: bool,
}
impl Window {
pub fn new() -> Window {
Window {
width: BUFFER_WIDTH as u32,
height: BUFFER_HEIGHT as u32,
x: 0,
y: 0,
bordered: true,
open: true
}
}
pub fn open(&mut self) -> Result<(), RenderError> {
if self.open {
return Err(RenderError::InvalidRenderMode);
}
self.open = true;
let mut frame: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT] = [[ScreenChar::null(); BUFFER_WIDTH]; BUFFER_HEIGHT];
Ok(())
}
// pub fn render(&self, f: &Frame) -> Result<(), RenderError> {
// let mut frame: &[[ScreenChar; self.width]; self.height] = &[[ScreenChar::null(); self.width]; self.height];
// for (i, row) in f.frame.iter().enumerate() {
// for (j, col) in row.iter().enumerate() {
// frame[i + f.position.y][j + f.position.x] = col.as_screen_char();
// };
// }
// RENDERER.lock().render_frame(frame);
// Ok(())
// }
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ColouredChar {
@@ -117,6 +164,14 @@ impl Frame {
})
}
pub fn from_window(window: &Window) -> Frame {
Frame {
dimensions: Dimensions::new(window.width as usize, window.height as usize),
position: Position::new(window.x as usize, window.y as usize),
frame: vec![vec![ColouredChar::null(); window.width as usize]; window.height as usize],
}
}
pub fn from_str(elemstr: String) -> Self {
let mut element = Frame { frame: Vec::<Vec<ColouredChar>>::new(), dimensions: Dimensions::new(0, 0), position: Position::new(0, 0) };
@@ -141,6 +196,7 @@ impl Frame {
self.frame.clone()
}
/// DEPRECATED. Use Window::render(&Frame) instead !!
pub fn write_to_screen(&self) -> Result<(), RenderError> {
let mut frame: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT] = [[ScreenChar::null(); BUFFER_WIDTH]; BUFFER_HEIGHT];
for (i, row) in self.frame.iter().enumerate() {
@@ -151,6 +207,7 @@ impl Frame {
RENDERER.lock().render_frame(frame);
Ok(())
}
pub fn get_position(&self) -> Position<usize> {
self.position
}
+2 -1
View File
@@ -2,6 +2,7 @@ use core::fmt;
use alloc::{boxed::Box, format, string::String, vec::Vec};
use alloc::string::ToString;
use alloc::borrow::ToOwned;
use crate::std::render::Window;
use crate::{println, print, mknode, std, serial_println};
use async_trait::async_trait;
@@ -361,7 +362,7 @@ impl Application for Calculator {
Self {}
}
async fn run(&mut self, args: Vec<String>) -> Result<(), ShellError> {
async fn run(&mut self, window: Option<Window>, args: Vec<String>) -> Result<(), ShellError> {
if args.len() == 0 {
loop {
print!("enter equation > ");
+2 -2
View File
@@ -1,7 +1,7 @@
use crate::{serial_println, std};
use crate::std::application::{self, Application};
use crate::std::io::{Color, ColorCode, Display, KeyStroke};
use crate::std::render::{ColouredChar, Frame, Position, RenderError};
use crate::std::render::{ColouredChar, Frame, Position, RenderError, Window};
use crate::user::lib::libgui::cg_core::CgComponent;
@@ -169,7 +169,7 @@ impl Application for Editor {
}
}
async fn run(&mut self, _args: Vec<String>) -> Result<(), application::Error> {
async fn run(&mut self, window: Option<Window>, _args: Vec<String>) -> Result<(), application::Error> {
// if let Some(s) = args.get(0) {
// self.buffer = s.lines().map(|l| l.chars().collect()).collect::<Vec<Vec<char>>>()
+2 -2
View File
@@ -5,7 +5,7 @@ use alloc::boxed::Box;
use core::any::Any;
use async_trait::async_trait;
use crate::std::application::{Application, Error};
use crate::std::render::{Frame, Position, Dimensions, ColouredChar, RenderError};
use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError, Window};
use crate::std::io::{Display, KeyStroke, Stdin};
use crate::user::lib::libgui::{
@@ -49,7 +49,7 @@ impl Application for Grapher {
frame: Frame::new(Position::new(1, 1), Dimensions::new(78, 22)).unwrap()
}
}
async fn run(&mut self, args: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, args: Vec<String>) -> Result<(), Error> {
let _d = Display::borrow();
self.frame.frame = vec![vec![ColouredChar::new(' '); self.frame.dimensions.x]; self.frame.dimensions.y];
+1
View File
@@ -2,3 +2,4 @@ pub mod calc;
pub mod editor;
pub mod grapher;
pub mod tasks;
pub mod zxqsh;
+2 -1
View File
@@ -4,6 +4,7 @@ use crate::std::application::{
Error
};
use crate::println;
use crate::std::render::Window;
use lazy_static::lazy_static;
use spin::Mutex;
use async_trait::async_trait;
@@ -27,7 +28,7 @@ pub struct Tasks;
impl Application for Tasks {
fn new() -> Self { Self {} }
async fn run(&mut self, args: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, args: Vec<String>) -> Result<(), Error> {
if args[0].clone() == String::from("add") {
+50
View File
@@ -0,0 +1,50 @@
use alloc::{string::String, vec::Vec, boxed::Box};
use crate::std::{application::{Application, Error}, render::Window};
use async_trait::async_trait;
pub struct ZxqSH {
history: Vec<String>,
idx: u32,
window: Window,
}
#[async_trait]
impl Application for ZxqSH {
fn new() -> Self {
todo!()
}
async fn run(&mut self, window: Option<Window>, _args: Vec<String>) -> Result<(), Error> {
loop {
if let Ok(exit) = self.next().await {
if exit { return Ok(()) }
}
}
}
}
impl ZxqSH {
async fn next(&mut self) -> Result<bool, Error> {
// update cycle for the shell
// TOOD: prompt
// TODO: exit if necessar
// TODO: execute command
// return
Ok(false)
}
async fn execute(&self, command: String) -> Result<(), Error> {
Ok(())
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
use crate::std::application::Error;
use crate::std::application::Error::ApplicationError;
use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError};
use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError, Window};
use crate::std::io::{Color, ColorCode, Display, KeyStroke, Stdin};
use crate::std::random::Random;
use crate::system::std::application::Application;
@@ -52,7 +52,7 @@ impl Application for Game {
timer: GameTimer::new(),
}
}
async fn run(&mut self, _args: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, _args: Vec<String>) -> Result<(), Error> {
let _d = Display::borrow();
let mut container_data =
+2 -2
View File
@@ -1,7 +1,7 @@
use alloc::{string::String, vec::Vec, boxed::Box};
use async_trait::async_trait;
use crate::{std::{application::{Application, Error}, io::{Color, Display, KeyStroke, Stdin}, random::Random, render::{ColorCode, ColouredChar, Dimensions, Frame, Position, RenderError}, time}, user::lib::libgui::cg_core::CgComponent};
use crate::{std::{application::{Application, Error}, io::{Color, Display, KeyStroke, Stdin}, random::Random, render::{ColorCode, ColouredChar, Dimensions, Frame, Position, RenderError, Window}, time}, user::lib::libgui::cg_core::CgComponent};
pub struct Game {
pub board: [[Cell; 7]; 6],
@@ -31,7 +31,7 @@ impl Application for Game {
}
}
async fn run(&mut self, _: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, _: Vec<String>) -> Result<(), Error> {
let _display = Display::borrow();
self.get_next_mode().await;
+2 -2
View File
@@ -4,7 +4,7 @@ use alloc::vec::Vec;
use alloc::boxed::Box;
use crate::std::application::{Application, Error};
use async_trait::async_trait;
use crate::std::render::{ColouredChar, Frame, Position, Dimensions, RenderError};
use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError, Window};
use crate::std::io::{KeyStroke, Stdin, Color, ColorCode, Display};
use crate::std::time::wait;
@@ -21,7 +21,7 @@ impl Application for GameOfLife {
frame: Frame::new(Position::new(0, 0), Dimensions::new(80, 25)).unwrap()
}
}
async fn run(&mut self, _args: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, _args: Vec<String>) -> Result<(), Error> {
// setup:
let _d = Display::borrow();
+2 -2
View File
@@ -8,7 +8,7 @@ use crate::{
self,
application::{Application, Error},
io::{Color, ColorCode, Display, KeyStroke, Stdin},
render::{ColouredChar, Dimensions, Frame, Position, RenderError},
render::{ColouredChar, Dimensions, Frame, Position, RenderError, Window},
time
},
user::lib::libgui::cg_core::CgComponent
@@ -49,7 +49,7 @@ impl Application for GameBoard {
}
}
async fn run(&mut self, _args: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, _args: Vec<String>) -> Result<(), Error> {
let _display = Display::borrow();
'outer: loop {
+2 -2
View File
@@ -4,7 +4,7 @@ use alloc::vec::Vec;
use core::any::Any;
use async_trait::async_trait;
use crate::std::application::{Application, Error};
use crate::std::render::{BUFFER_HEIGHT, BUFFER_WIDTH, ColorCode, ColouredChar, Dimensions, Frame, Position, RenderError};
use crate::std::render::{ColorCode, ColouredChar, Dimensions, Frame, Position, RenderError, Window, BUFFER_HEIGHT, BUFFER_WIDTH};
use crate::std::io::{Color, Display, KeyStroke, Stdin};
use crate::std::time::Timer;
use crate::user::lib::libgui::cg_core::CgComponent;
@@ -25,7 +25,7 @@ impl Application for Game {
}
}
async fn run(&mut self, _: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, _: Vec<String>) -> Result<(), Error> {
let _d = Display::borrow();
let mut update_time = Timer::new(0.1);
+2 -2
View File
@@ -4,7 +4,7 @@ use async_trait::async_trait;
use crate::std::io::{Color, Display, KeyStroke, Stdin};
use crate::std::time;
use crate::std::application::{Application, Error};
use crate::std::render::{ColouredChar, Dimensions, Frame, RenderError, ColorCode};
use crate::std::render::{ColorCode, ColouredChar, Dimensions, Frame, RenderError, Window};
use crate::std::random::Random;
use crate::system::std::render;
use super::super::super::lib::geometry::{Position, Direction};
@@ -45,7 +45,7 @@ impl Application for Game {
}
}
async fn run(&mut self, args: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, args: Vec<String>) -> Result<(), Error> {
let _settings = [0, 0, 0]; // ai_count, snake_len, poi_count
+24 -23
View File
@@ -18,15 +18,9 @@ use crate::{
printerr,
println,
std::{
application::{Application, Error, Exit},
time::{timer},
io::{Color, write, Screen, Stdin, Serial, KeyStroke, Display},
application::{Application, Error, Exit}, io::{write, Color, Display, KeyStroke, Serial, Stdin}, render::Window, time::timer
},
user::{
lib::libgui::{
cg_core::{CgComponent, CgKeyboardCapture},
cg_widgets::CgDialog,
},
bin::{
apps::{
calc::Calculator,
@@ -48,7 +42,10 @@ use crate::{
gigachad_detector::GigachadDetector,
rickroll::Rickroll,
},
},
}, lib::libgui::{
cg_core::{CgComponent, CgKeyboardCapture},
cg_widgets::CgDialog,
}
},
};
@@ -67,11 +64,13 @@ pub async fn command_handler() {
pub async fn eventloop() {
println!("running!");
let window = Window::new();
let mut fetch = CrystalFetch::new();
let string = String::from(" ");
let mut vec: Vec<String> = Vec::new();
vec.push(string);
fetch.run(vec).await.unwrap();
fetch.run(Some(window), vec).await.unwrap();
CMD.lock().prompt();
@@ -122,29 +121,31 @@ async fn exec() -> Result<(), Error> {
}
};
let window = Window::new();
match cmd.as_str() {
"calculate" | "calc" | "solve" => {
let mut cmd = Calculator::new();
cmd.run(args).await?;
cmd.run(Some(window), args).await?;
}
"games/connect4" => {
let mut cmd = Connect4Game::new();
cmd.run(args).await?;
cmd.run(Some(window), args).await?;
}
"rickroll" => {
let mut cmd = Rickroll::new();
cmd.run(args).await?;
cmd.run(Some(window), args).await?;
}
"crystalfetch" => {
let mut cmd = CrystalFetch::new();
cmd.run(args).await?;
cmd.run(Some(window), args).await?;
}
"tasks" => {
let mut cmd = Tasks::new();
cmd.run(args).await?;
cmd.run(Some(window), args).await?;
}
"VGA" => {
use vga::colors::Color16;
@@ -156,21 +157,21 @@ async fn exec() -> Result<(), Error> {
mode.draw_line((80, 60), (120, 420), Color16::Cyan);
}
"graph" => {
Grapher::new().run(args).await?;
Grapher::new().run(Some(window), args).await?;
}
"games/snake" => {
SnakeGame::new().run(args).await?;
SnakeGame::new().run(Some(window), args).await?;
}
"games/asteroids" => {
let mut asteroid_game = AsteroidsGame::new();
asteroid_game.run(args).await?;
asteroid_game.run(Some(window), args).await?;
}
"games/pong" => {
PongGame::new().run(args).await?;
PongGame::new().run(Some(window), args).await?;
}
"games/paper.rs" => {
let mut game = GameBoard::new();
game.run(args).await?;
game.run(Some(window), args).await?;
}
"serial" => {
let c = Serial::reply_char('e');
@@ -178,7 +179,7 @@ async fn exec() -> Result<(), Error> {
}
"games/gameoflife" => {
let mut game = GameOfLife::new();
game.run(Vec::new()).await?;
game.run(Some(window), Vec::new()).await?;
}
"games/tetris" => {
// let mut game = TetrisEngine::new();
@@ -187,12 +188,12 @@ async fn exec() -> Result<(), Error> {
"gigachad?" => {
let mut detector = GigachadDetector::new();
detector.run(args).await?;
detector.run(Some(window), args).await?;
}
"editor" => {
let mut editor = Editor::new();
editor.run(args).await?;
editor.run(Some(window), args).await?;
}
// direct OS functions (not applications)
@@ -208,7 +209,7 @@ async fn exec() -> Result<(), Error> {
)
}
"clear" => {
Screen::clear();
Display::clear();
// not sure why this code was here but leaving it in case weird bugs happen so i remember to add it back if so
//interrupts::without_interrupts(|| {});
}
+6 -5
View File
@@ -2,9 +2,7 @@ use async_trait::async_trait;
use alloc::{boxed::Box, format, string::String, vec::Vec};
use crate::std::{
os::OS,
io::{Color, write, Screen},
application::{Application, Error},
application::{Application, Error}, io::{write, Color, Display}, os::OS, render::Window
};
use crate::println;
@@ -55,12 +53,15 @@ impl Application for CrystalFetch {
Self {}
}
async fn run(&mut self, _args: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, _args: Vec<String>) -> Result<(), Error> {
let ds = Display::borrow();
let os = OS.lock().os.clone();
let version = OS.lock().version.clone();
Screen::clear();
// clear screen
Display::clear();
let logo_string = ZXQ5_LOGO;
let info_string = format!(
+3 -3
View File
@@ -3,10 +3,10 @@ use alloc::{boxed::Box, string::String, vec::Vec};
use crate::{
println,
std::application::{
std::{application::{
Application,
Error,
},
}, render::Window},
};
const GIGACHAD: [&'static str; 3] = ["fantasypvp", "zxq5", "ZXQ5"];
@@ -19,7 +19,7 @@ impl Application for GigachadDetector {
Self {}
}
async fn run(&mut self, args: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, args: Vec<String>) -> Result<(), Error> {
for arg in args {
self.detect_gigachad_by_username(&arg)
}
+2 -1
View File
@@ -44,6 +44,7 @@ const RICKROLL2: &str = "
`--'";
use crate::println;
use crate::std::render::Window;
use alloc::{string::String, boxed::Box, vec::Vec};
@@ -55,7 +56,7 @@ impl Application for Rickroll {
Self {}
}
async fn run(&mut self, _args: Vec<String>) -> Result<(), Error> {
async fn run(&mut self, window: Option<Window>, _args: Vec<String>) -> Result<(), Error> {
println!("{}", RICKROLL2);
Ok(())
}
+1
View File
@@ -1,3 +1,4 @@
// pub mod libgui_old_archive;
pub mod geometry;
pub mod libgui;
pub mod termui;
+6
View File
@@ -0,0 +1,6 @@
pub async fn idk() {}
+1
View File
@@ -0,0 +1 @@
pub mod components;