Compare commits

..

15 commits

Author SHA1 Message Date
able 773709c035 Begin work on draw_unicode_char 2022-08-04 03:36:46 -05:00
able 53317e6935 Implement bounds checks 2022-08-02 01:16:47 -05:00
RKennedy9064 2059f09675 Merge pull request #26 from clavierpaul/master
Set color palette to standard 256 VGA palette
2022-02-15 16:06:11 -06:00
Paul Clavier c2ad9a0155 Set color palette to standard 256 VGA palette
This fixes issue 18.
2022-02-15 20:01:44 +00:00
Ryan Kennedy 86fc89f060 Merge branch 'master' of https://github.com/rust-osdev/vga 2021-06-02 18:53:27 -05:00
Ryan Kennedy bd91dae004 Update version 2021-06-02 18:53:17 -05:00
RKennedy9064 a0d5ccfd2c Merge pull request #24 from rust-osdev/update-testing
Update testing
2021-05-24 20:32:52 -05:00
Ryan Kennedy f88a4cfc07 Update testing 2021-05-24 20:22:55 -05:00
RKennedy9064 1c0b29dba2 Update interrupts.rs 2021-05-24 19:27:14 -05:00
RKennedy9064 4c782615c5 Update Cargo.toml 2021-05-24 19:25:17 -05:00
RKennedy9064 46f5302cd1 Merge pull request #23 from ethindp/master
Update dependencies to latest versions to fix E0557
2021-05-19 10:09:00 -05:00
RKennedy9064 9a7efbd3ef Update Cargo.toml 2021-05-19 10:03:30 -05:00
RKennedy9064 d2f3b66381 Update Cargo.toml 2021-05-19 09:55:37 -05:00
Ethin Probst 40e62a9536 Update dependencies to latest versions to fix E0557
Signed-off-by: Ethin Probst <ethindp@protonmail.com>
2021-05-16 12:19:02 -05:00
RKennedy9064 d80449dc8e Merge pull request #22 from rust-osdev/develop
Update config/testing
2021-02-14 21:38:51 -06:00
8 changed files with 111 additions and 31 deletions

View file

@ -1,17 +1,12 @@
[package] [package]
name = "vga" name = "vga"
version = "0.2.6" version = "0.2.7"
authors = ["Ryan Kennedy <rkennedy9064@gmail.com>"] authors = ["Ryan Kennedy <rkennedy9064@gmail.com>"]
edition = "2018" edition = "2018"
description = "Support for vga specific functions, data structures, and registers." description = "Support for vga specific functions, data structures, and registers."
documentation = "https://docs.rs/vga" documentation = "https://docs.rs/vga"
keywords = [ keywords = ["vga", "no_std"]
"vga", categories = ["no-std"]
"no_std",
]
categories = [
"no-std",
]
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
readme = "README.md" readme = "README.md"
repository = "https://github.com/rust-osdev/vga" repository = "https://github.com/rust-osdev/vga"
@ -20,11 +15,20 @@ repository = "https://github.com/rust-osdev/vga"
[dependencies] [dependencies]
bitflags = "1.2.1" bitflags = "1.2.1"
conquer-once = { version = "0.2.1", default-features = false } spin = "0.9"
font8x8 = { version = "0.2.5", default-features = false, features = ["unicode"] } log = "*"
spinning_top = { version = "0.2.2", features = ["nightly"] }
x86_64 = "0.13.2"
conquer-once = { version = "0.3.2", default-features = false }
font8x8 = { version = "0.3.1", default-features = false, features = [
"unicode",
] }
spinning_top = { version = "0.2.4", features = ["nightly"] }
x86_64 = "0.14.2"
[dependencies.num-traits] [dependencies.num-traits]
version = "0.2.14" version = "0.2.14"
default-features = false default-features = false
[dependencies.ab_glyph]
version = "0.2.15"
default-features = false
features = ["libm"]

Binary file not shown.

Binary file not shown.

View file

@ -69,7 +69,6 @@ impl TextModeColor {
self.0 = foreground as u8; self.0 = foreground as u8;
} }
} }
/// Represents the default vga 256 color palette. /// Represents the default vga 256 color palette.
pub const DEFAULT_PALETTE: [u8; PALETTE_SIZE] = [ pub const DEFAULT_PALETTE: [u8; PALETTE_SIZE] = [
0x0, 0x0, 0x0, 0x0, 0x0, 0x2A, 0x0, 0x2A, 0x0, 0x0, 0x2A, 0x2A, 0x2A, 0x0, 0x0, 0x2A, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2A, 0x0, 0x2A, 0x0, 0x0, 0x2A, 0x2A, 0x2A, 0x0, 0x0, 0x2A, 0x0,

View file

@ -7,6 +7,8 @@
#![no_std] #![no_std]
#![warn(missing_docs)] #![warn(missing_docs)]
extern crate alloc;
pub mod colors; pub mod colors;
pub mod configurations; pub mod configurations;
pub mod drawing; pub mod drawing;

View file

@ -5,6 +5,7 @@ use crate::{
registers::{PlaneMask, WriteMode}, registers::{PlaneMask, WriteMode},
vga::{VideoMode, VGA}, vga::{VideoMode, VGA},
}; };
use core::convert::From;
use font8x8::UnicodeFonts; use font8x8::UnicodeFonts;
const WIDTH: usize = 640; const WIDTH: usize = 640;
@ -122,15 +123,89 @@ impl Graphics640x480x16 {
#[inline] #[inline]
fn _set_pixel(self, x: usize, y: usize, color: Color16) { fn _set_pixel(self, x: usize, y: usize, color: Color16) {
let frame_buffer = self.get_frame_buffer(); if x < 640 && y < 480 {
let offset = x / 8 + y * WIDTH_IN_BYTES; let frame_buffer = self.get_frame_buffer();
let pixel_mask = 0x80 >> (x & 0x07); let offset = x / 8 + y * WIDTH_IN_BYTES;
VGA.lock() let pixel_mask = 0x80 >> (x & 0x07);
.graphics_controller_registers VGA.lock()
.set_bit_mask(pixel_mask); .graphics_controller_registers
unsafe { .set_bit_mask(pixel_mask);
frame_buffer.add(offset).read_volatile(); unsafe {
frame_buffer.add(offset).write_volatile(u8::from(color)); frame_buffer.add(offset).read_volatile();
frame_buffer.add(offset).write_volatile(u8::from(color));
}
}
}
}
use ab_glyph::{Font, FontRef, Glyph};
use log::trace;
use spin::Lazy;
const FONT_BASIC: Lazy<FontRef> = Lazy::new({
|| FontRef::try_from_slice(include_bytes!("../../assets/fonts/unifont-14.0.01.ttf")).unwrap()
});
const FONT_SUPPLEMENTARY: Lazy<FontRef> = Lazy::new(|| {
FontRef::try_from_slice(include_bytes!(
"../../assets/fonts/unifont_upper-14.0.01.ttf"
))
.unwrap()
});
const FONT_SCALE: f32 = 14.0;
const GLYPH_HEIGHT: f32 = 10.0;
const GLYPH_WIDTH: f32 = 8.0;
impl Graphics640x480x16 {
/// Draw a glyph on the screen at the given position
///
/// # Arguments
/// * `x` - the x position of the glyph
/// * `y` - the y position of the glyph
/// * `glyph` - the glyph to draw
/// * `color` - the color of the glyph
pub fn draw_unicode_char(&self, mut x: usize, mut y: usize, character: char, color: Color16) {
self.set_write_mode_2();
// trace!("Char {}", character);
// if character == '\n' {
// return;
// }
if x == 80 {
x = 0;
y += 1;
}
if character != '\0' {
let real_x = x as f32 * GLYPH_WIDTH;
let real_y = (y as f32 + 1.0) * GLYPH_HEIGHT;
// trace!("REALX{}\nREALY{}", real_x, real_y);
let in_supp_plane = character as u32 > 0xffff;
let plane = match in_supp_plane {
false => FONT_BASIC,
true => FONT_SUPPLEMENTARY,
};
let q_glyph: Glyph = plane
.glyph_id(character)
.with_scale_and_position(FONT_SCALE, ab_glyph::point(real_x, real_y));
if let Some(q) = plane.outline_glyph(q_glyph) {
q.draw(|gx, gy, c| {
if c > 0.1 {
let corner = q.px_bounds().min;
self._set_pixel(
gx as usize + corner.x as usize,
gy as usize + corner.y as usize,
color,
);
}
});
}
} }
} }
} }

View file

@ -6,12 +6,12 @@ edition = "2018"
[dependencies] [dependencies]
bootloader = { version = "0.9.11", features = ["map_physical_memory"] } bootloader = { version = "0.9.11", features = ["map_physical_memory"] }
conquer-once = { version = "0.2.1", default-features = false } conquer-once = { version = "0.3.2", default-features = false }
spinning_top = { version = "0.2.2", features = ["nightly"] } spinning_top = { version = "0.2.4", features = ["nightly"] }
pic8259_simple = "0.2.0" pic8259 = "0.10.1"
vga = { path = "../" } vga = { path = "../" }
uart_16550 = "0.2.10" uart_16550 = "0.2.14"
x86_64 = "0.13.2" x86_64 = "0.14.2"
[package.metadata.bootimage] [package.metadata.bootimage]
test-args = [ test-args = [

View file

@ -2,7 +2,7 @@ use crate::gdt;
use crate::{hlt_loop, serial_print, serial_println}; use crate::{hlt_loop, serial_print, serial_println};
use conquer_once::spin::Lazy; use conquer_once::spin::Lazy;
use core::convert::Into; use core::convert::Into;
use pic8259_simple::ChainedPics; use pic8259::ChainedPics;
use spinning_top::Spinlock; use spinning_top::Spinlock;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode}; use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
@ -49,14 +49,14 @@ pub fn init_idt() {
} }
extern "x86-interrupt" fn double_fault_handler( extern "x86-interrupt" fn double_fault_handler(
stack_frame: &mut InterruptStackFrame, stack_frame: InterruptStackFrame,
_error_code: u64, _error_code: u64,
) -> ! { ) -> ! {
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame); panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
} }
extern "x86-interrupt" fn page_fault_handler( extern "x86-interrupt" fn page_fault_handler(
stack_frame: &mut InterruptStackFrame, stack_frame: InterruptStackFrame,
error_code: PageFaultErrorCode, error_code: PageFaultErrorCode,
) { ) {
use x86_64::registers::control::Cr2; use x86_64::registers::control::Cr2;
@ -69,7 +69,7 @@ extern "x86-interrupt" fn page_fault_handler(
} }
extern "x86-interrupt" fn segment_not_present( extern "x86-interrupt" fn segment_not_present(
_stack_frame: &mut InterruptStackFrame, _stack_frame: InterruptStackFrame,
_error_code: u64, _error_code: u64,
) { ) {
// For some reason this sometimes gets thrown when running tests in qemu, // For some reason this sometimes gets thrown when running tests in qemu,