1
0
Fork 0
forked from koniifer/ableos

prelim work on VGA

This commit is contained in:
able 2022-08-05 01:14:13 -05:00
parent 8c511e6550
commit 2200b5bbda
6 changed files with 78 additions and 25 deletions

5
Cargo.lock generated
View file

@ -726,12 +726,15 @@ dependencies = [
[[package]] [[package]]
name = "vga" name = "vga"
version = "0.2.7" version = "0.2.7"
source = "git+https://git.ablecorp.us/able/vga.git#9e72fa603927983e359c8a7c56cb110a81eb161e" source = "git+https://git.ablecorp.us/able/vga.git#fd41943bb05ca90414e84cff3def1ffe72a62efe"
dependencies = [ dependencies = [
"ab_glyph",
"bitflags", "bitflags",
"conquer-once", "conquer-once",
"font8x8", "font8x8",
"log",
"num-traits", "num-traits",
"spin 0.9.4",
"spinning_top", "spinning_top",
"x86_64", "x86_64",
] ]

View file

@ -144,3 +144,4 @@ x86_64 = "0.14.8"
pc-beeper = { git = "https://github.com/AbleOS/pc-beeper" } pc-beeper = { git = "https://github.com/AbleOS/pc-beeper" }
acpi = "4.1.0" acpi = "4.1.0"
vga = { git = "https://git.ablecorp.us:443/able/vga.git" } vga = { git = "https://git.ablecorp.us:443/able/vga.git" }
# vga = { path = "../../vga" }

View file

@ -6,7 +6,7 @@ user_processes = ["shell"]
enabled = true enabled = true
level = "Trace" level = "Trace"
log_to_serial = true log_to_serial = true
filter = [] filter = ["ableos::ps2_mouse"]
# "ableos::vterm"] # "ableos::vterm"]

View file

@ -52,7 +52,7 @@ impl log::Log for SimpleLogger {
if KERNEL_CONF.logging.log_to_serial { if KERNEL_CONF.logging.log_to_serial {
serial_println!( serial_println!(
"[{}{}{}][{}{}{}][{}{}@{}{}] {}", "[{}{:05}{}][{}{}{}][{}{}@{}{}] {}",
color.0, color.0,
record.level(), record.level(),
Fg::Reset, Fg::Reset,

View file

@ -4,7 +4,7 @@ use crate::image::mono_bitmap::bruh;
use crate::systeminfo::{KERNEL_VERSION, RELEASE_TYPE}; use crate::systeminfo::{KERNEL_VERSION, RELEASE_TYPE};
use crate::time::fetch_time; use crate::time::fetch_time;
use crate::{ use crate::{
arch::shutdown, filesystem::FILE_SYSTEM, rhai_shell::KEYBUFF, vterm::Term, arch::shutdown, filesystem::FILE_SYSTEM, rhai_shell::KEYBUFF, vterm::VTerm,
wasm_jumploader::run_program, wasm_jumploader::run_program,
}; };
@ -38,7 +38,7 @@ impl acpi::AcpiHandler for AcpiStruct {
} }
} }
pub static TERM: Lazy<spin::Mutex<Term>> = Lazy::new(|| spin::Mutex::new(Term::new())); pub static TERM: Lazy<spin::Mutex<VTerm>> = Lazy::new(|| spin::Mutex::new(VTerm::new()));
#[derive(Debug)] #[derive(Debug)]
pub struct Path { pub struct Path {
@ -66,6 +66,10 @@ pub fn scratchpad() {
println!("\0RED\0OHNO\0RESET\0"); println!("\0RED\0OHNO\0RESET\0");
// for c in 0..144_697 {
// trace!("{:?}", char::from_u32(c));
// }
// bruh(); // bruh();
disable(); disable();
@ -82,7 +86,7 @@ pub fn scratchpad() {
,-------. OS: \0BLUE\0AbleOS\0RESET\0 ,-------. OS: \0BLUE\0AbleOS\0RESET\0
,'\\ _ _`. Host: None ,'\\ _ _`. Host: None
/ \\)_)-)_)-\\ Kernel: \0RED\0AKern-{}-v{}\0RESET\0 / \\)_)-)_)-\\ Kernel: \0RED\0AKern-{}-v{}\0RESET\0
: : Uptime: {} : : Uptime: \0GREEN\0{}\0RESET\0
\\ / Packages: None \\ / Packages: None
\\ / Shell: BuiltinShell \\ / Shell: BuiltinShell
`. ,' Resolution: 640x480 `. ,' Resolution: 640x480
@ -156,7 +160,7 @@ pub fn real_shell() {
} }
Some('\u{8}') => { Some('\u{8}') => {
print!("\u{8}"); print!("\u{8}");
trace!("");
buf.pop(); buf.pop();
} }

View file

@ -1,19 +1,31 @@
/*
* Copyright (c) 2022, Able <able@ablecorp.us>
*
* SPDX-License-Identifier: MPL-2.0
*/
#![deny(missing_docs)]
//! The VTerm is a terminal with nice
use crate::{hardware::MOUSE, vga_e::VGAE}; use crate::{hardware::MOUSE, vga_e::VGAE};
use ab_glyph::{Font, FontRef, Glyph};
use logos::{Lexer, Logos}; use logos::{Lexer, Logos};
use spin::Lazy;
use vga::{colors::Color16, writers::GraphicsWriter}; use vga::{colors::Color16, writers::GraphicsWriter};
const TERM_MINUS_ONE_LINE: usize = 4720; const TERM_MINUS_ONE_LINE: usize = 4720;
const CURSOR_COLOR: Color16 = Color16::Cyan; const CURSOR_COLOR: Color16 = Color16::Cyan;
#[derive(Debug)] #[derive(Debug)]
pub struct Term { /// A VTerm
pub struct VTerm {
dirty: bool, dirty: bool,
color: Color16, color: Color16,
term: [(char, Color16); 80 * 60], term: [(char, Color16); 80 * 60],
back_buffer: [u8; 640 * 480], back_buffer: [u8; 640 * 480],
x: u8, x: u8,
} }
impl Term { impl VTerm {
/// Construct a new VTerm
pub fn new() -> Self { pub fn new() -> Self {
let mode = VGAE.lock(); let mode = VGAE.lock();
mode.set_mode(); mode.set_mode();
@ -24,18 +36,21 @@ impl Term {
dirty: false, dirty: false,
x: 0, x: 0,
back_buffer: [0; 640 * 480], back_buffer: [0; 640 * 480],
term: [('\0', Color16::LightGrey); 80 * 60], term: [('\0', Color16::DarkGrey); 80 * 60],
color: Color16::White, color: Color16::White,
} }
} }
/// Check the dirty state of the VTerm
pub fn is_dirty(&self) -> bool { pub fn is_dirty(&self) -> bool {
self.dirty self.dirty
} }
/// Set the dirty state of the VTerm
pub fn set_dirty(&mut self, dirty: bool) { pub fn set_dirty(&mut self, dirty: bool) {
self.dirty = dirty self.dirty = dirty
} }
/// Append a &str to the VTerm
pub fn print(&mut self, data: &str) { pub fn print(&mut self, data: &str) {
let mut lex = Token::lexer(data); let mut lex = Token::lexer(data);
@ -61,23 +76,29 @@ impl Term {
Token::TPink => self.color = Color16::Pink, Token::TPink => self.color = Color16::Pink,
Token::TYellow => self.color = Color16::Yellow, Token::TYellow => self.color = Color16::Yellow,
Token::TWhite => self.color = Color16::White, Token::TWhite => self.color = Color16::White,
Token::Space => { // Token::Space => {
self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] = (' ', self.color); // self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] = (' ', self.color);
self.x += 1; // self.x += 1;
} // }
Token::Text(st) => { Token::Text(st) => {
for c in st.chars() { for c in st.chars() {
if self.x == 80 { if self.x == 80 {
// trace!("X too big moving up");
self.move_up(); self.move_up();
} }
// trace!("C"); // trace!("C");
match c { match c {
'\0' => {
self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] =
(c, self.color);
self.x += 1;
}
'\u{08}' => { '\u{08}' => {
if self.x == 0 { if self.x == 0 {
trace!("IMPOSSIBLE BACKSPACE"); trace!("IMPOSSIBLE BACKSPACE");
return; return;
} }
trace!("BACKSPACE");
self.x -= 1; self.x -= 1;
self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] = self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] =
('\0', Color16::LightGrey); ('\0', Color16::LightGrey);
@ -99,19 +120,16 @@ impl Term {
} }
} }
/// Move the VTerm up by one line
pub fn move_up(&mut self) { pub fn move_up(&mut self) {
self.term.rotate_left(80); self.term.rotate_left(80);
for x in 0..80 { for x in 0..80 {
self.term[TERM_MINUS_ONE_LINE + x] = ('\0', Color16::LightGrey); self.term[TERM_MINUS_ONE_LINE + x] = ('\0', Color16::DarkGrey);
} }
self.x = 0; self.x = 0;
} }
// pub fn initialize(&self) {
// let mode = VGAE.lock();
// mode.set_mode();
// drop(mode);
// }
/// Redraw the VTerm to the VGA buffer
pub fn draw_term(&mut self) { pub fn draw_term(&mut self) {
if self.is_dirty() { if self.is_dirty() {
// trace!("Redrawing"); // trace!("Redrawing");
@ -123,8 +141,10 @@ impl Term {
for c in self.term { for c in self.term {
mode.draw_character(x * 8, y * 8, c.0, c.1); mode.draw_character(x * 8, y * 8, c.0, c.1);
// mode.draw_unicode_char(x, y, c.0, c.1);
if x == 79 { if x == 79 {
y += 1; y += 1;
x = 0; x = 0;
} else { } else {
x += 1 x += 1
@ -155,6 +175,30 @@ impl Term {
); );
} }
drop(mode);
/*
let mut x = 0;
let mut y = 0;
for c in ['b'; 80 * 60]
// "abcdefghijklmnopqrstuvwxyzabcdefghijk\nabcd jkjhgkjhgkjhgefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz12"
// .chars()
{
if c == '\n' {
y += 1;
x = 0;
continue;
}
self.draw_char(x, y, c, Color16::Red);
if x == 80 {
y += 1;
x = 1;
} else {
x += 1;
}
}
*/
self.set_dirty(false); self.set_dirty(false);
// trace!("Finished drawing"); // trace!("Finished drawing");
} }
@ -162,7 +206,7 @@ impl Term {
} }
#[derive(Logos, Debug, Clone, PartialEq)] #[derive(Logos, Debug, Clone, PartialEq)]
pub enum Token { enum Token {
#[regex(r"", logos::skip)] #[regex(r"", logos::skip)]
#[error] #[error]
Error, Error,
@ -203,10 +247,11 @@ pub enum Token {
#[token("\0WHITE\0", priority = 10)] #[token("\0WHITE\0", priority = 10)]
TWhite, TWhite,
#[token(" ")] // #[token(" ")]
Space,
#[regex("[\t\n\u{8}█!-~]+", text_lex, priority = 0)] // Space,
#[regex("[\t\n\u{8}█!-\u{10FFFF} ]+", text_lex, priority = 0)]
/// A printable string
Text(String), Text(String),
} }