ke m i n g ''
This commit is contained in:
parent
139f5243f3
commit
bbe2a0183a
7
ableos/Cargo.lock
generated
7
ableos/Cargo.lock
generated
|
@ -39,6 +39,7 @@ dependencies = [
|
||||||
"shadeable",
|
"shadeable",
|
||||||
"spin",
|
"spin",
|
||||||
"uart_16550",
|
"uart_16550",
|
||||||
|
"unicode-width",
|
||||||
"vga",
|
"vga",
|
||||||
"volatile 0.2.7",
|
"volatile 0.2.7",
|
||||||
"wasmi",
|
"wasmi",
|
||||||
|
@ -456,6 +457,12 @@ dependencies = [
|
||||||
"x86_64",
|
"x86_64",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
|
|
@ -37,7 +37,7 @@ vga = "*"
|
||||||
log= "*"
|
log= "*"
|
||||||
pretty-hex = "0.2.1"
|
pretty-hex = "0.2.1"
|
||||||
|
|
||||||
|
unicode-width = "0.1.7"
|
||||||
|
|
||||||
|
|
||||||
[dependencies.shadeable]
|
[dependencies.shadeable]
|
||||||
|
|
BIN
ableos/assets/fonts/OpenSansEmoji.ttf
Normal file
BIN
ableos/assets/fonts/OpenSansEmoji.ttf
Normal file
Binary file not shown.
|
@ -37,7 +37,7 @@ impl ScreenBuffer {
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_pixel(&mut self, x: usize, y: usize, color: Rgba64) {
|
pub fn set_pixel(&mut self, x: usize, y: usize, color: Rgba64) {
|
||||||
self.buff[y * self.size.y + x] = color;
|
self.buff[y * self.size.x + x] = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
|
@ -52,18 +52,11 @@ pub trait VgaBuffer {
|
||||||
impl VgaBuffer for ScreenBuffer {
|
impl VgaBuffer for ScreenBuffer {
|
||||||
fn copy_to_buffer(&self) -> GraphicsReturn {
|
fn copy_to_buffer(&self) -> GraphicsReturn {
|
||||||
let mode = VGAE.lock();
|
let mode = VGAE.lock();
|
||||||
|
|
||||||
/*
|
|
||||||
if self.size.y * 640 + self.size.x > 640 * 480 {
|
|
||||||
return GraphicsReturn::ImproperScreenSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
for y in 0..self.size.y {
|
for y in 0..self.size.y {
|
||||||
for x in 0..self.size.x {
|
for x in 0..self.size.x {
|
||||||
use shadeable::pixel_format::into_vga_16;
|
use shadeable::pixel_format::{get_color16, into_vga_16};
|
||||||
let vga_color = into_vga_16(self.buff[y * self.size.y + x]);
|
let vga_color = get_color16(self.buff[y * self.size.x + x]);
|
||||||
|
// let vga_color = into_vga_16(self.buff[y * self.size.x + x]);
|
||||||
mode.set_pixel(x, y, vga_color);
|
mode.set_pixel(x, y, vga_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
use alloc::format;
|
use alloc::format;
|
||||||
|
|
||||||
use shadeable::pixel_format::{into_vga_16, new_rgba64};
|
use shadeable::pixel_format::{from_vga_16, into_vga_16, new_rgba64};
|
||||||
use vga::{colors::Color16, writers::GraphicsWriter};
|
use vga::{colors::Color16, writers::GraphicsWriter};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
graphics::VgaBuffer,
|
graphics::VgaBuffer,
|
||||||
relib::network::socket::{SimpleSock, SocketReturns},
|
relib::network::socket::{SimpleSock, SocketReturns},
|
||||||
vga_e::{self, VGAE},
|
vga_e::{self, num_to_vga16, VGAE},
|
||||||
};
|
};
|
||||||
|
|
||||||
use log::*;
|
use log::*;
|
||||||
|
@ -58,22 +58,26 @@ pub fn kernel_main() -> ! {
|
||||||
log::set_max_level(LevelFilter::Trace);
|
log::set_max_level(LevelFilter::Trace);
|
||||||
// crate::wasm::evaluate();
|
// crate::wasm::evaluate();
|
||||||
|
|
||||||
let mut abcde = ScreenBuffer::new(480, 640);
|
let mut abcde = ScreenBuffer::new(640, 480);
|
||||||
// abcde.clear();
|
// abcde.clear();
|
||||||
// abcde.copy_to_buffer();
|
// abcde.copy_to_buffer();
|
||||||
|
|
||||||
VGAE.lock().clear_screen(Color16::Black);
|
VGAE.lock().clear_screen(Color16::Black);
|
||||||
|
|
||||||
trace!("length of screen buffer {}", abcde.buff.len());
|
trace!("length of screen buffer {}", abcde.buff.len());
|
||||||
trace!("Screen size {:?}", abcde.size);
|
trace!("Screen size {:?}", abcde.size);
|
||||||
|
|
||||||
abcde.set_pixel(10, 10, new_rgba64(255, 0, 0, 255));
|
for y in 0..480 {
|
||||||
for y in 30..60 {
|
for x in 0..640 {
|
||||||
for x in 1..=639 {
|
let segment_x = x * 4 / 640;
|
||||||
abcde.set_pixel(x, y, new_rgba64(255, 255, 8, 255));
|
let segment_y = y * 4 / 480;
|
||||||
|
let segment = segment_x + segment_y * 4;
|
||||||
|
|
||||||
|
abcde.set_pixel(x, y, from_vga_16(num_to_vga16(segment as u8)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// info!("{:?}", abcde.buff);
|
|
||||||
abcde.copy_to_buffer();
|
// abcde.copy_to_buffer();
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut xyz = SimpleSock::new();
|
let mut xyz = SimpleSock::new();
|
||||||
|
@ -101,19 +105,18 @@ pub fn kernel_main() -> ! {
|
||||||
let mut sock_print_id = SimpleSock::new();
|
let mut sock_print_id = SimpleSock::new();
|
||||||
|
|
||||||
{
|
{
|
||||||
// sock_print_id.write(format!("原 画 フ ァ イ ル 集").into());
|
sock_print_id.write(format!("a原b画cフdァeイfル 集").into());
|
||||||
sock_print_id.write(format!("simple sockets are based").into());
|
// sock_print_id.write(format!("simple sockets are based").into());
|
||||||
sock_print_id.write(format!("🤯 🍆 💦").into());
|
|
||||||
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
|
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
|
||||||
}
|
}
|
||||||
// crate::relib::image::mono_bitmap::bruh();
|
// crate::relib::image::mono_bitmap::bruh();
|
||||||
|
|
||||||
if false {
|
if true {
|
||||||
for x in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap()))
|
let mut prev = None;
|
||||||
.chars()
|
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() {
|
||||||
.enumerate()
|
vga_e::draw_char(prev, current, 0);
|
||||||
{
|
|
||||||
vga_e::draw_char(x.1, x.0);
|
prev = Some(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
use alloc::string::ToString;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
ab_glyph::{Font, FontRef, Glyph},
|
ab_glyph::{Font, FontRef, Glyph},
|
||||||
vga::{
|
vga::{
|
||||||
|
@ -16,39 +19,11 @@ lazy_static::lazy_static! {
|
||||||
pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
|
pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_it_fucko() {
|
|
||||||
let mode = Graphics640x480x16::new();
|
|
||||||
mode.set_mode();
|
|
||||||
mode.clear_screen(Color16::Black);
|
|
||||||
|
|
||||||
mode.draw_line((80, 60), (80, 420), Color16::White);
|
|
||||||
mode.draw_line((80, 60), (540, 60), Color16::White);
|
|
||||||
|
|
||||||
{
|
|
||||||
let offset = 110;
|
|
||||||
mode.draw_character(offset - 15 - 4, 60 + 15 - 4, 'x', Color16::Red);
|
|
||||||
|
|
||||||
mode.draw_line(
|
|
||||||
(offset.try_into().unwrap(), 60),
|
|
||||||
(offset.try_into().unwrap(), 90),
|
|
||||||
Color16::White,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
mode.draw_line((80, 420), (540, 420), Color16::White);
|
|
||||||
mode.draw_line((540, 420), (540, 60), Color16::White);
|
|
||||||
mode.draw_line((80, 90), (540, 90), Color16::White);
|
|
||||||
|
|
||||||
for (offset, character) in "ableOS".chars().enumerate() {
|
|
||||||
mode.draw_character(270 + offset * 8, 72, character, Color16::White)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait GraphicsAPI {
|
pub trait GraphicsAPI {
|
||||||
fn add_shader() {}
|
fn add_shader() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_char(character: char, _offset: usize) {
|
pub fn draw_char(previous_character: Option<char>, character: char, _offset: usize) {
|
||||||
let mode = *VGAE.lock();
|
let mode = *VGAE.lock();
|
||||||
let mut offset_x = VGAE_BUFF_OFFSET_X.lock();
|
let mut offset_x = VGAE_BUFF_OFFSET_X.lock();
|
||||||
let mut offset_y = VGAE_BUFF_OFFSET_Y.lock();
|
let mut offset_y = VGAE_BUFF_OFFSET_Y.lock();
|
||||||
|
@ -64,7 +39,7 @@ pub fn draw_char(character: char, _offset: usize) {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let font2 = FontRef::try_from_slice(include_bytes!(
|
let font2 = FontRef::try_from_slice(include_bytes!(
|
||||||
"../../ableos/assets/fonts/unifont_upper-14.0.01.ttf"
|
"../../ableos/assets/fonts/unifont_upper-14.0.01.ttf" // "../../ableos/assets/fonts/OpenSansEmoji.ttf"
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -87,13 +62,30 @@ pub fn draw_char(character: char, _offset: usize) {
|
||||||
match character {
|
match character {
|
||||||
'\n' => {}
|
'\n' => {}
|
||||||
_ => {
|
_ => {
|
||||||
let q_glyph: Glyph = used_font.glyph_id(character).with_scale_and_position(
|
let previous_glyph: Glyph = used_font
|
||||||
|
.glyph_id(previous_character.unwrap_or(' '))
|
||||||
|
.with_scale_and_position(
|
||||||
20.0 * font_scale,
|
20.0 * font_scale,
|
||||||
ab_glyph::point(
|
ab_glyph::point(
|
||||||
*offset_x as f32 * (10.0 * font_scale),
|
*offset_x as f32 * (10.0 * font_scale),
|
||||||
*offset_y as f32 + (18.0 * font_scale),
|
*offset_y as f32 + (18.0 * font_scale),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut q_glyph: Glyph = used_font.glyph_id(character).with_scale_and_position(
|
||||||
|
20.0 * font_scale,
|
||||||
|
ab_glyph::point(
|
||||||
|
*offset_x as f32 * (10.0 * font_scale),
|
||||||
|
*offset_y as f32 + (18.0 * font_scale),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
{
|
||||||
|
// figure it our latter bruh
|
||||||
|
let spacing = used_font.kern_unscaled(previous_glyph.id, q_glyph.id);
|
||||||
|
info!("{spacing} {:?} {:?}", previous_glyph.id, q_glyph.id);
|
||||||
|
q_glyph.position.x += spacing * font_scale;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(q) = used_font.outline_glyph(q_glyph) {
|
if let Some(q) = used_font.outline_glyph(q_glyph) {
|
||||||
q.draw(|x, y, c| {
|
q.draw(|x, y, c| {
|
||||||
if c > 0.015 {
|
if c > 0.015 {
|
||||||
|
@ -111,3 +103,26 @@ pub fn draw_char(character: char, _offset: usize) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn num_to_vga16(num: u8) -> Color16 {
|
||||||
|
use Color16::*;
|
||||||
|
match num {
|
||||||
|
0 => Black,
|
||||||
|
1 => Blue,
|
||||||
|
2 => Green,
|
||||||
|
3 => Cyan,
|
||||||
|
4 => Red,
|
||||||
|
5 => Magenta,
|
||||||
|
6 => Brown,
|
||||||
|
7 => LightGrey,
|
||||||
|
8 => DarkGrey,
|
||||||
|
9 => LightBlue,
|
||||||
|
10 => LightGreen,
|
||||||
|
11 => LightCyan,
|
||||||
|
12 => LightRed,
|
||||||
|
13 => Pink,
|
||||||
|
14 => Yellow,
|
||||||
|
15 => White,
|
||||||
|
// NOTE: Leasve the in
|
||||||
|
_ => Color16::Pink,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -164,24 +164,28 @@ pub fn into_vga_16(rgba_64: Rgba64) -> Color16 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_vga_16(color: Color16) -> Rgba64 {
|
pub fn from_vga_16(color: Color16) -> Rgba64 {
|
||||||
|
use Color16::*;
|
||||||
match color {
|
match color {
|
||||||
Color16::Black => new_rgba64(0, 0, 0, 0),
|
Black => new_rgba64(0, 0, 0, 0),
|
||||||
Color16::Blue => new_rgba64(0, 0, 255, 0),
|
DarkGrey => new_rgba64(105, 105, 105, 0),
|
||||||
Color16::Green => new_rgba64(0, 255, 0, 0),
|
LightGrey => new_rgba64(211, 211, 211, 0),
|
||||||
Color16::Cyan => new_rgba64(0, 255, 255, 0),
|
//
|
||||||
Color16::Red => new_rgba64(255, 0, 0, 0),
|
Blue => new_rgba64(0, 0, 255, 0),
|
||||||
Color16::Magenta => new_rgba64(255, 0, 255, 0),
|
Green => new_rgba64(0, 255, 0, 0),
|
||||||
Color16::Brown => new_rgba64(165, 42, 42, 0),
|
Red => new_rgba64(255, 0, 0, 0),
|
||||||
Color16::Pink => new_rgba64(255, 105, 180, 0),
|
//
|
||||||
Color16::LightGrey => new_rgba64(211, 211, 211, 0),
|
Yellow => new_rgba64(255, 255, 0, 0),
|
||||||
Color16::DarkGrey => new_rgba64(105, 105, 105, 0),
|
Cyan => new_rgba64(0, 255, 255, 0),
|
||||||
Color16::Yellow => new_rgba64(255, 255, 0, 0),
|
Magenta => new_rgba64(255, 0, 255, 0),
|
||||||
Color16::White => new_rgba64(255, 255, 255, 0),
|
|
||||||
// To be colored
|
Brown => new_rgba64(165, 42, 42, 0),
|
||||||
Color16::LightBlue => new_rgba64(0, 255, 255, 0),
|
Pink => new_rgba64(255, 105, 180, 0),
|
||||||
Color16::LightGreen => new_rgba64(0, 255, 255, 0),
|
White => new_rgba64(255, 255, 255, 0),
|
||||||
Color16::LightCyan => new_rgba64(0, 255, 255, 0),
|
|
||||||
Color16::LightRed => new_rgba64(0, 255, 255, 0),
|
LightBlue => new_rgba64(173, 216, 230, 0),
|
||||||
|
LightGreen => new_rgba64(144, 238, 144, 0),
|
||||||
|
LightCyan => new_rgba64(88, 100, 100, 0),
|
||||||
|
LightRed => new_rgba64(255, 204, 203, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,25 +197,29 @@ fn euclideand(c1: (u8, u8, u8), c2: (u8, u8, u8)) -> u8 {
|
||||||
let (rd, gd, bd) = (r2 - r1, g2 - g1, b2 - b1);
|
let (rd, gd, bd) = (r2 - r1, g2 - g1, b2 - b1);
|
||||||
sqrt((rd * rd + gd * gd + bd * bd) as f64) as u8
|
sqrt((rd * rd + gd * gd + bd * bd) as f64) as u8
|
||||||
}
|
}
|
||||||
|
pub fn get_color16(c: Rgba64) -> Color16 {
|
||||||
|
let r = get_r(c);
|
||||||
|
let g = get_g(c);
|
||||||
|
let b = get_b(c);
|
||||||
|
|
||||||
fn get_color16(c: (u8, u8, u8)) -> Color16 {
|
let c = (r, g, b);
|
||||||
let palette: [(u8, u8, u8); 16] = [
|
let palette: [(u8, u8, u8); 16] = [
|
||||||
(0, 0, 0),
|
(0, 0, 0),
|
||||||
|
(105, 105, 105),
|
||||||
|
(211, 211, 211),
|
||||||
(0, 0, 255),
|
(0, 0, 255),
|
||||||
(128, 128, 128),
|
(0, 255, 0),
|
||||||
(128, 128, 128),
|
(255, 0, 0),
|
||||||
(128, 128, 128),
|
(255, 255, 0),
|
||||||
(128, 128, 128),
|
(0, 255, 255),
|
||||||
(128, 128, 128),
|
(255, 0, 255),
|
||||||
(128, 128, 128),
|
(165, 42, 42),
|
||||||
(128, 128, 128),
|
(255, 105, 180),
|
||||||
(128, 128, 128),
|
(255, 255, 255),
|
||||||
(128, 128, 128),
|
(173, 216, 230),
|
||||||
(128, 128, 128),
|
(144, 238, 144),
|
||||||
(128, 128, 128),
|
(88, 100, 100),
|
||||||
(128, 128, 128),
|
(255, 204, 203),
|
||||||
(128, 128, 128),
|
|
||||||
(128, 128, 128),
|
|
||||||
];
|
];
|
||||||
let mut minc = euclideand(c, palette[0]);
|
let mut minc = euclideand(c, palette[0]);
|
||||||
let mut retval = 0;
|
let mut retval = 0;
|
||||||
|
@ -222,23 +230,24 @@ fn get_color16(c: (u8, u8, u8)) -> Color16 {
|
||||||
minc = eucd
|
minc = eucd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
use Color16::*;
|
||||||
match retval {
|
match retval {
|
||||||
0 => Color16::Black,
|
0 => Black,
|
||||||
1 => Color16::Red,
|
1 => Blue,
|
||||||
2 => Color16::Red,
|
2 => Green,
|
||||||
3 => Color16::Red,
|
3 => Cyan,
|
||||||
4 => Color16::Red,
|
4 => Red,
|
||||||
5 => Color16::Red,
|
5 => Magenta,
|
||||||
6 => Color16::Red,
|
6 => Brown,
|
||||||
7 => Color16::Red,
|
7 => LightGrey,
|
||||||
8 => Color16::Red,
|
8 => DarkGrey,
|
||||||
9 => Color16::Red,
|
9 => LightBlue,
|
||||||
10 => Color16::Blue,
|
10 => LightGreen,
|
||||||
11 => Color16::Blue,
|
11 => LightCyan,
|
||||||
12 => Color16::Blue,
|
12 => LightRed,
|
||||||
13 => Color16::Blue,
|
13 => Pink,
|
||||||
14 => Color16::Blue,
|
14 => Yellow,
|
||||||
15 => Color16::Blue,
|
15 => White,
|
||||||
_ => Color16::Pink,
|
_ => Green,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue