use super::{GraphicsWriter, Screen};
use crate::writers::PrimitiveDrawing;
use crate::{
colors::DEFAULT_PALETTE,
vga::{VideoMode, VGA},
};
use font8x8::UnicodeFonts;
const WIDTH: usize = 320;
const HEIGHT: usize = 200;
const SIZE: usize = WIDTH * HEIGHT;
#[derive(Debug, Clone, Copy, Default)]
pub struct Graphics320x200x256;
impl Screen for Graphics320x200x256 {
const WIDTH: usize = WIDTH;
const HEIGHT: usize = HEIGHT;
const SIZE: usize = SIZE;
}
impl GraphicsWriter<u8> for Graphics320x200x256 {
fn clear_screen(&self, color: u8) {
unsafe {
self.get_frame_buffer().write_bytes(color, Self::SIZE);
}
}
fn set_pixel(&self, x: usize, y: usize, color: u8) {
let offset = (y * WIDTH) + x;
unsafe {
self.get_frame_buffer().add(offset).write_volatile(color);
}
}
fn draw_character(&self, x: usize, y: usize, character: char, color: u8) {
let character = match font8x8::BASIC_FONTS.get(character) {
Some(character) => character,
None => font8x8::unicode::BLOCK_UNICODE[8].byte_array(),
};
for (row, byte) in character.iter().enumerate() {
for bit in 0..8 {
match *byte & 1 << bit {
0 => (),
_ => self.set_pixel(x + bit, y + row, color),
}
}
}
}
fn set_mode(&self) {
let mut vga = VGA.lock();
vga.set_video_mode(VideoMode::Mode320x200x256);
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
}
}
impl PrimitiveDrawing<u8> for Graphics320x200x256 {}
impl Graphics320x200x256 {
pub const fn new() -> Graphics320x200x256 {
Graphics320x200x256
}
}