Format code
This commit is contained in:
parent
ec3200625e
commit
6144d2ef19
56
src/main.rs
56
src/main.rs
@ -21,10 +21,17 @@
|
||||
|
||||
use core::str;
|
||||
use std::{
|
||||
borrow::Cow, collections::HashMap, fmt::{self, Write}, os::mikros::{address_space::ACTIVE_SPACE, ipc, syscalls}, usize
|
||||
borrow::Cow,
|
||||
collections::HashMap,
|
||||
fmt::{self, Write},
|
||||
os::mikros::{address_space::ACTIVE_SPACE, ipc, syscalls},
|
||||
usize,
|
||||
};
|
||||
|
||||
use fontdue::{layout::{CoordinateSystem, GlyphRasterConfig, Layout, LayoutSettings, TextStyle, WrapStyle}, Font, FontSettings};
|
||||
use fontdue::{
|
||||
layout::{CoordinateSystem, GlyphRasterConfig, Layout, LayoutSettings, TextStyle, WrapStyle},
|
||||
Font, FontSettings,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use parking_lot::Mutex;
|
||||
use x86_64::structures::paging::PageTableFlags;
|
||||
@ -61,13 +68,19 @@ pub struct Bga {
|
||||
yres: usize,
|
||||
}
|
||||
|
||||
|
||||
unsafe impl Send for Bga {}
|
||||
unsafe impl Sync for Bga {}
|
||||
|
||||
impl Bga {
|
||||
pub unsafe fn new(mmio_base: *mut u8, framebuffer_base: *mut u8) -> Self {
|
||||
Self { mmio_base, framebuffer_base, draw_buffer: Vec::new(), scroll_offset: 0, xres: 0, yres: 0}
|
||||
Self {
|
||||
mmio_base,
|
||||
framebuffer_base,
|
||||
draw_buffer: Vec::new(),
|
||||
scroll_offset: 0,
|
||||
xres: 0,
|
||||
yres: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// Changes the screenn resolution. Also clears the screen.
|
||||
@ -80,7 +93,8 @@ impl Bga {
|
||||
vbe_base.wrapping_add(VBE_BPP_NUM).write_volatile(0x20);
|
||||
vbe_base.wrapping_add(VBE_ENABLE_NUM).write_volatile(0x41);
|
||||
}
|
||||
self.draw_buffer.resize(xres as usize * yres as usize * 4 * 2, 0);
|
||||
self.draw_buffer
|
||||
.resize(xres as usize * yres as usize * 4 * 2, 0);
|
||||
self.draw_buffer.fill(0);
|
||||
self.scroll_offset = 0;
|
||||
self.xres = xres as usize;
|
||||
@ -104,11 +118,16 @@ impl Bga {
|
||||
let scroll_top_byte_offset = self.row_byte_offset(self.scroll_offset);
|
||||
let scroll_bot_byte_offset = self.row_byte_offset(self.scroll_offset + self.yres);
|
||||
let visible_buf = &self.draw_buffer[scroll_top_byte_offset..scroll_bot_byte_offset];
|
||||
unsafe { self.framebuffer_base.copy_from_nonoverlapping(&visible_buf[0], visible_buf.len()) };
|
||||
unsafe {
|
||||
self.framebuffer_base
|
||||
.copy_from_nonoverlapping(&visible_buf[0], visible_buf.len())
|
||||
};
|
||||
}
|
||||
|
||||
fn vbe_base(&self) -> *mut u16 {
|
||||
self.mmio_base.wrapping_add(BGA_MMIO_VBE_OFFSET).cast::<u16>()
|
||||
self.mmio_base
|
||||
.wrapping_add(BGA_MMIO_VBE_OFFSET)
|
||||
.cast::<u16>()
|
||||
}
|
||||
|
||||
fn row_byte_offset(&self, row: usize) -> usize {
|
||||
@ -188,17 +207,18 @@ impl FramebufferWriter {
|
||||
|
||||
fn update_screen(&mut self, fbuf: &mut Bga) {
|
||||
self.layout.clear();
|
||||
self.layout.append(&[&self.font], &TextStyle::new(&self.out_string, 12.0, 0));
|
||||
self.layout
|
||||
.append(&[&self.font], &TextStyle::new(&self.out_string, 12.0, 0));
|
||||
let text_height = self.layout.height();
|
||||
self.layout.append(&[&self.font], &TextStyle::new("\u{2588}", 12.0, 0));
|
||||
self.layout
|
||||
.append(&[&self.font], &TextStyle::new("\u{2588}", 12.0, 0));
|
||||
|
||||
for row in self.cursor_top..self.cursor_bot {
|
||||
fbuf.clear_row(row);
|
||||
}
|
||||
|
||||
if (self.next_line_y + self.layout.height() as usize) > fbuf.yres {
|
||||
let excess_y =
|
||||
self.layout.height() as usize - (fbuf.yres - self.next_line_y);
|
||||
let excess_y = self.layout.height() as usize - (fbuf.yres - self.next_line_y);
|
||||
fbuf.scroll_by(excess_y);
|
||||
self.next_line_y -= excess_y;
|
||||
}
|
||||
@ -238,7 +258,9 @@ impl FramebufferWriter {
|
||||
let cursor_glyph = glyphs.last().unwrap();
|
||||
|
||||
self.cursor_top = cursor_glyph.y as usize - first_line_top_offset + self.next_line_y;
|
||||
self.cursor_bot = cursor_glyph.y as usize - first_line_top_offset + self.next_line_y + cursor_glyph.height;
|
||||
self.cursor_bot = cursor_glyph.y as usize - first_line_top_offset
|
||||
+ self.next_line_y
|
||||
+ cursor_glyph.height;
|
||||
|
||||
let last_line = self.layout.lines().unwrap().last().unwrap();
|
||||
let log_line_slice = if last_line.glyph_start == last_line.glyph_end {
|
||||
@ -247,7 +269,9 @@ impl FramebufferWriter {
|
||||
let first_char_offset = glyphs[last_line.glyph_start].byte_offset;
|
||||
let last_char_offset = glyphs[last_line.glyph_end - 1].byte_offset;
|
||||
let mut last_char_end = last_char_offset + 1;
|
||||
while last_char_end < self.out_string.len() && !self.out_string.is_char_boundary(last_char_end) {
|
||||
while last_char_end < self.out_string.len()
|
||||
&& !self.out_string.is_char_boundary(last_char_end)
|
||||
{
|
||||
last_char_end += 1;
|
||||
}
|
||||
&self.out_string[first_char_offset..last_char_end]
|
||||
@ -405,7 +429,11 @@ fn main() {
|
||||
.unwrap();
|
||||
bga.set_resolution(1920, 1050);
|
||||
|
||||
let font = Font::from_bytes(include_bytes!("../FiraCode-Regular.ttf").as_slice(), FontSettings::default()).unwrap();
|
||||
let font = Font::from_bytes(
|
||||
include_bytes!("../FiraCode-Regular.ttf").as_slice(),
|
||||
FontSettings::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let writer = FramebufferWriter::new(font, &bga);
|
||||
|
||||
dev_driver_rpc::register_server(Box::new(DevServ));
|
||||
|
Loading…
Reference in New Issue
Block a user