Skip to content
Snippets Groups Projects
Commit 8c51bd1a authored by Eemeli Lehtonen's avatar Eemeli Lehtonen
Browse files

unifont downloader

parent e4d16684
No related branches found
No related tags found
No related merge requests found
use std::{env::var, error::Error};
use std::{
env::var,
error::Error,
fs::{self, File, OpenOptions},
io::Read,
io::Write,
path::PathBuf,
process::Command,
};
//
......@@ -35,5 +43,30 @@ fn main() -> Result<(), Box<dyn Error>> {
panic!();
};
let unifont_path = "target/hyperion/unifont.bmp";
let read_unifont = || {
let mut file = OpenOptions::new()
.read(true)
.create(false)
.write(false)
.open(unifont_path)?;
let mut buf = Vec::new();
file.read_to_end(buf)?;
Ok::<_, Box<dyn Error>>(buf)
};
let unifont = if let Ok(file) = read_unifont() {
file
} else {
Command::new("wget")
.arg("http://unifoundry.com/pub/unifont/unifont-15.0.01/unifont-15.0.01.bmp")
.args(["-O", unifont_path])
.spawn()
.unwrap();
read_unifont().unwrap()
};
Ok(())
}
......@@ -2,9 +2,9 @@ use crate::{
println,
video::framebuffer::{Framebuffer, FBO},
};
use core::{ops::Deref, slice};
use limine::{LimineFramebuffer, LimineFramebufferRequest, LimineFramebufferResponse};
use spin::{Lazy, Mutex, MutexGuard};
use core::slice;
use limine::LimineFramebufferRequest;
use spin::Mutex;
//
......
......@@ -19,7 +19,7 @@ unsafe impl Send for Writer {}
impl Write for Writer {
fn write_str(&mut self, s: &str) -> fmt::Result {
let mut write = self.0.write().ok_or(fmt::Error)?;
let write = self.0.write().ok_or(fmt::Error)?;
for term in self.0.terminals() {
write(term, s);
......
......@@ -53,6 +53,8 @@ fn kernel_main() -> ! {
fbo.fill(40, 40, 40, 40, Color::RED);
fbo.fill(50, 50, 60, 40, Color::GREEN);
fbo.fill(5, 15, 80, 20, Color::BLUE);
fbo.put_bytes(100, 100, b"ABABABAB\0", Color::WHITE, Color::BLACK);
}
#[cfg(test)]
......@@ -61,6 +63,7 @@ fn kernel_main() -> ! {
arch::done();
}
#[allow(unused)]
fn stack_overflow(n: usize) {
if n == 0 {
return;
......
use core::{
fmt::{Arguments, Write},
sync::atomic::AtomicUsize,
};
use core::fmt::{Arguments, Write};
use spin::{Lazy, Mutex};
use uart_16550::SerialPort;
......@@ -16,6 +13,9 @@ pub fn _print(args: Arguments) {
}
/// Unlocks the COM1 writer IF it is locked by this exact thread
///
/// SAFETY: this is unsafe unless called from the same thread, this is intended for double fault
/// handling
pub unsafe fn unlock() {
// TODO: SMP
// if COM1_LOCKER.load(Ordering::SeqCst) != crate::THREAD {
......@@ -27,7 +27,7 @@ pub unsafe fn unlock() {
//
static COM1_LOCKER: AtomicUsize = AtomicUsize::new(0);
// static COM1_LOCKER: AtomicUsize = AtomicUsize::new(0);
static COM1: Lazy<Mutex<SerialPort>> = Lazy::new(|| {
let mut port = unsafe { SerialPort::new(0x3f8) };
port.init();
......
......@@ -3,14 +3,13 @@
// bitmap: [u8; 16],
// }
#[allow(clippy::unusual_byte_groupings)]
pub static FONT: [[u8; 16]; 256] = {
let mut font = [[0u8; 16]; 256];
font[b'a' as usize] = [
let default = [
0b_11111111,
0b_11111111,
0b_11000011,
0b_11000011,
0b_11000011, //
0b_11000011,
0b_11000011,
0b_11000011,
......@@ -25,5 +24,44 @@ pub static FONT: [[u8; 16]; 256] = {
0b_11111111,
];
let mut font = [default; 256];
font[b'A' as usize] = [
0b_00000000,
0b_00000000,
0b_00000000, //
0b_01111110,
0b_11111111,
0b_11100111,
0b_11000011,
0b_11111111,
0b_11111111,
0b_11000011,
0b_11000011,
0b_11000011,
0b_11000011,
0b_00000000, //
0b_00000000,
0b_00000000,
];
font[b'B' as usize] = [
0b_00000000,
0b_00000000,
0b_00000000, //
0b_11111110,
0b_11111111,
0b_11000111,
0b_11000111,
0b_11111110,
0b_11111110,
0b_11000111,
0b_11000111,
0b_11111111,
0b_11111110,
0b_00000000, //
0b_00000000,
0b_00000000,
];
font
};
use core::{
fmt,
ops::{Deref, DerefMut},
};
use super::font::FONT;
use core::fmt;
use spin::{Mutex, Once};
//
......@@ -40,10 +38,31 @@ impl Framebuffer {
}
}
}
pub fn put_byte(&mut self, x: usize, y: usize, ch: u8, fg: Color, bg: Color) {
let map = FONT[ch as usize];
for (yd, row) in map.into_iter().enumerate() {
for xd in 0..8 {
self.set(
x + xd,
y + yd,
if (row & 1 << (7 - xd)) != 0 { fg } else { bg },
);
}
}
}
pub fn put_bytes(&mut self, x: usize, y: usize, s: &[u8], fg: Color, bg: Color) {
for (offs, ch) in s.iter().enumerate() {
self.put_byte(x + 12 * offs, y, *ch, fg, bg)
}
}
}
impl Color {
pub const WHITE: Color = Color::new(0xff, 0xff, 0xff);
pub const BLACK: Color = Color::new(0x00, 0x00, 0x00);
pub const RED: Color = Color::new(0xff, 0x00, 0x00);
pub const GREEN: Color = Color::new(0x00, 0xff, 0x00);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment