Starts adding fontplate for VGA
This commit is contained in:
48
bench/programs_rust/fpga-lib/src/vga.rs
Normal file
48
bench/programs_rust/fpga-lib/src/vga.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use fpga_lib_macros::include_font_plate;
|
||||
|
||||
pub const VGA_ADDRESS: *mut Color = 0x80000000 as *mut Color;
|
||||
pub const WIDTH: usize = 320;
|
||||
pub const HEIGHT: usize = 240;
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct Color(pub(crate) u8);
|
||||
|
||||
impl Color {
|
||||
pub const fn from_rgb(r: u8, g: u8, b: u8) -> Self {
|
||||
Self(((r >> 6) << 6) | ((g >> 5) << 3) | (b >> 5))
|
||||
}
|
||||
}
|
||||
|
||||
pub const WHITE: Color = Color::from_rgb(255, 255, 255);
|
||||
pub const GRAY: Color = Color::from_rgb(128, 128, 128);
|
||||
pub const LIGHT_GRAY: Color = Color::from_rgb(128, 64, 64);
|
||||
pub const BLACK: Color = Color::from_rgb(0, 0, 0);
|
||||
pub const RED: Color = Color::from_rgb(255, 0, 0);
|
||||
pub const GREEN: Color = Color::from_rgb(0, 255, 0);
|
||||
pub const BLUE: Color = Color::from_rgb(0, 0, 255);
|
||||
|
||||
pub struct VGA {}
|
||||
|
||||
impl VGA {
|
||||
/// # Safety
|
||||
/// `x` must be less than `WIDTH` and `y` must be less than `HEIGHT`
|
||||
pub unsafe fn write_pixel_unsafe(x: u16, y: u16, color: Color) {
|
||||
unsafe { *VGA_ADDRESS.add(x as usize + y as usize * WIDTH) = color }
|
||||
}
|
||||
|
||||
pub unsafe fn draw_char(x: u16, y: u16, c: char) {
|
||||
let c = c as u8 - b' ';
|
||||
for i in 0..FONT_HEIGHT {
|
||||
for j in 0..FONT_WIDTH {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const FONT_WIDTH: usize = 6;
|
||||
pub const FONT_HEIGHT: usize = 13;
|
||||
pub const FONTPLATE_WIDTH: usize = 32 * FONT_WIDTH;
|
||||
pub const FONTPLATE_HEIGHT: usize = 3 * FONT_HEIGHT;
|
||||
pub const FONTPLATE_SIZE: usize = FONTPLATE_WIDTH * FONTPLATE_HEIGHT / 8;
|
||||
pub const FONTPLATE: [u8; FONTPLATE_SIZE] = include_font_plate! {"fontplate.png"};
|
||||
Reference in New Issue
Block a user