Drawing text

This commit is contained in:
Ryan Kennedy 2020-03-24 15:44:30 -05:00
parent 5a072f5382
commit 42d2f4836e
3 changed files with 29 additions and 0 deletions

View file

@ -21,6 +21,7 @@ repository = "https://github.com/rust-osdev/vga"
[dependencies] [dependencies]
bitflags = "1.2.1" bitflags = "1.2.1"
conquer-once = { version = "0.2.0", default-features = false } conquer-once = { version = "0.2.0", default-features = false }
font8x8 = { version = "0.2.5", default-features = false, features = ["unicode"] }
spinning_top = { version = "0.1.0", features = ["nightly"] } spinning_top = { version = "0.1.0", features = ["nightly"] }
x86_64 = "0.9.6" x86_64 = "0.9.6"

View file

@ -5,6 +5,7 @@ use crate::{
registers::{PlaneMask, WriteMode}, registers::{PlaneMask, WriteMode},
vga::{Vga, VideoMode, VGA}, vga::{Vga, VideoMode, VGA},
}; };
use font8x8::UnicodeFonts;
use spinning_top::SpinlockGuard; use spinning_top::SpinlockGuard;
const WIDTH: usize = 640; const WIDTH: usize = 640;
@ -62,6 +63,31 @@ impl GraphicsWriter<Color16Bit> for Graphics640x480x16 {
} }
} }
fn draw_character(&self, x: usize, y: usize, character: char, color: Color16Bit) {
let character = match font8x8::BASIC_FONTS.get(character) {
Some(character) => character,
None => font8x8::unicode::BLOCK_UNICODE[8].byte_array(),
};
{
let (mut vga, _frame_buffer) = self.get_frame_buffer();
vga.graphics_controller_registers
.set_write_mode(WriteMode::Mode2);
vga.graphics_controller_registers.set_bit_mask(0xFF);
vga.sequencer_registers
.set_plane_mask(PlaneMask::ALL_PLANES);
}
for (y1, byte) in character.iter().enumerate() {
for bit in 0..8 {
match *byte & 1 << bit {
0 => {}
_ => self._set_pixel(x + bit, y + y1, color),
}
}
}
}
/// Sets the given pixel at `(x, y)` to the given `color`. /// Sets the given pixel at `(x, y)` to the given `color`.
/// ///
/// **Note:** This method is provided for convenience, but has terrible /// **Note:** This method is provided for convenience, but has terrible

View file

@ -185,6 +185,8 @@ pub trait GraphicsWriter<Color> {
fn clear_screen(&self, color: Color); fn clear_screen(&self, color: Color);
/// /// Draws a line from `start` to `end` with the specified `color`. /// /// Draws a line from `start` to `end` with the specified `color`.
fn draw_line(&self, start: Point<isize>, end: Point<isize>, color: Color); fn draw_line(&self, start: Point<isize>, end: Point<isize>, color: Color);
/// Draws a character at the given `(x, y)` coordinant to the specified `color`.
fn draw_character(&self, x: usize, y: usize, character: char, color: Color);
/// Sets the given pixel at `(x, y)` to the given `color`. /// Sets the given pixel at `(x, y)` to the given `color`.
/// ///
/// **Note:** This method is provided for convenience, but has terrible /// **Note:** This method is provided for convenience, but has terrible