Make screen width and height constant

pull/12/head
Daniel Beckwith 2020-03-31 18:29:32 -04:00
parent 6fa4d119ad
commit 9cf310e462
6 changed files with 29 additions and 69 deletions

View File

@ -37,20 +37,9 @@ const SIZE: usize = WIDTH * HEIGHT;
pub struct Graphics320x200x256;
impl Screen for Graphics320x200x256 {
#[inline]
fn get_width(&self) -> usize {
WIDTH
}
#[inline]
fn get_height(&self) -> usize {
HEIGHT
}
#[inline]
fn get_size(&self) -> usize {
SIZE
}
const WIDTH: usize = WIDTH;
const HEIGHT: usize = HEIGHT;
const SIZE: usize = SIZE;
}
impl GraphicsWriter<u8> for Graphics320x200x256 {

View File

@ -40,15 +40,9 @@ const WIDTH_IN_BYTES: usize = WIDTH / 8;
pub struct Graphics640x480x16;
impl Screen for Graphics640x480x16 {
fn get_width(&self) -> usize {
WIDTH
}
fn get_height(&self) -> usize {
HEIGHT
}
fn get_size(&self) -> usize {
SIZE
}
const WIDTH: usize = WIDTH;
const HEIGHT: usize = HEIGHT;
const SIZE: usize = SIZE;
}
impl GraphicsWriter<Color16> for Graphics640x480x16 {

View File

@ -51,12 +51,12 @@ static BLANK_CHARACTER: ScreenCharacter = ScreenCharacter {
/// A helper trait used to interact with various vga screens.
pub trait Screen {
/// Returns the width of the `Screen`.
fn get_width(&self) -> usize;
/// Returns the height of the `Screen`.
fn get_height(&self) -> usize;
/// Returns the size of the `Screen`.
fn get_size(&self) -> usize;
/// The width of the `Screen`.
const WIDTH: usize;
/// The height of the `Screen`.
const HEIGHT: usize;
/// The size (total area) of the `Screen`.
const SIZE: usize;
}
/// A helper trait used to interact with various vga text modes.
@ -79,8 +79,7 @@ pub trait TextWriter: Screen {
/// color of `Color16::Yellow`.
fn clear_screen(&self) {
let (_vga, frame_buffer) = self.get_frame_buffer();
let screen_size = self.get_width() * self.get_height();
for i in 0..screen_size {
for i in 0..Self::SIZE {
unsafe {
frame_buffer.add(i).write_volatile(BLANK_CHARACTER);
}
@ -94,8 +93,7 @@ pub trait TextWriter: Screen {
character: b' ',
color,
};
let screen_size = self.get_width() * self.get_height();
for i in 0..screen_size {
for i in 0..Self::SIZE {
unsafe {
frame_buffer.add(i).write_volatile(character);
}
@ -133,7 +131,7 @@ pub trait TextWriter: Screen {
/// Returns the `ScreenCharacter` at the given `(x, y)` position.
fn read_character(&self, x: usize, y: usize) -> ScreenCharacter {
let (_vga, frame_buffer) = self.get_frame_buffer();
let offset = self.get_width() * y + x;
let offset = Self::WIDTH * y + x;
unsafe { frame_buffer.add(offset).read_volatile() }
}
@ -169,7 +167,7 @@ pub trait TextWriter: Screen {
/// Sets the current text cursor to the position specified by
/// `x` and `y`.
fn set_cursor_position(&self, x: usize, y: usize) {
let offset = self.get_width() * y + x;
let offset = Self::WIDTH * y + x;
let (mut vga, _frame_buffer) = self.get_frame_buffer();
let emulation_mode = vga.get_emulation_mode();
let cursor_start = offset & 0xFF;
@ -189,7 +187,7 @@ pub trait TextWriter: Screen {
/// Prints the given `character` and `color` at `(x, y)`.
fn write_character(&self, x: usize, y: usize, screen_character: ScreenCharacter) {
let (_vga, frame_buffer) = self.get_frame_buffer();
let offset = self.get_width() * y + x;
let offset = Self::WIDTH * y + x;
unsafe {
frame_buffer.add(offset).write_volatile(screen_character);
}

View File

@ -7,6 +7,7 @@ use crate::{
const WIDTH: usize = 40;
const HEIGHT: usize = 25;
const SIZE: usize = WIDTH * HEIGHT;
/// A basic interface for interacting with vga text mode 40x25
///
@ -30,17 +31,9 @@ const HEIGHT: usize = 25;
pub struct Text40x25;
impl Screen for Text40x25 {
fn get_width(&self) -> usize {
WIDTH
}
fn get_height(&self) -> usize {
HEIGHT
}
fn get_size(&self) -> usize {
WIDTH * HEIGHT
}
const WIDTH: usize = WIDTH;
const HEIGHT: usize = HEIGHT;
const SIZE: usize = SIZE;
}
impl TextWriter for Text40x25 {

View File

@ -7,6 +7,7 @@ use crate::{
const WIDTH: usize = 40;
const HEIGHT: usize = 50;
const SIZE: usize = WIDTH * HEIGHT;
/// A basic interface for interacting with vga text mode 40x50
///
@ -30,17 +31,9 @@ const HEIGHT: usize = 50;
pub struct Text40x50;
impl Screen for Text40x50 {
fn get_width(&self) -> usize {
WIDTH
}
fn get_height(&self) -> usize {
HEIGHT
}
fn get_size(&self) -> usize {
WIDTH * HEIGHT
}
const WIDTH: usize = WIDTH;
const HEIGHT: usize = HEIGHT;
const SIZE: usize = SIZE;
}
impl TextWriter for Text40x50 {

View File

@ -7,6 +7,7 @@ use crate::{
const WIDTH: usize = 80;
const HEIGHT: usize = 25;
const SIZE: usize = WIDTH * HEIGHT;
/// A basic interface for interacting with vga text mode 80x25
///
@ -30,17 +31,9 @@ const HEIGHT: usize = 25;
pub struct Text80x25;
impl Screen for Text80x25 {
fn get_width(&self) -> usize {
WIDTH
}
fn get_height(&self) -> usize {
HEIGHT
}
fn get_size(&self) -> usize {
WIDTH * HEIGHT
}
const WIDTH: usize = WIDTH;
const HEIGHT: usize = HEIGHT;
const SIZE: usize = SIZE;
}
impl TextWriter for Text80x25 {