Make screen width and height constant
This commit is contained in:
parent
88ce4a55a1
commit
6547019382
|
@ -37,20 +37,9 @@ const SIZE: usize = WIDTH * HEIGHT;
|
||||||
pub struct Graphics320x200x256;
|
pub struct Graphics320x200x256;
|
||||||
|
|
||||||
impl Screen for Graphics320x200x256 {
|
impl Screen for Graphics320x200x256 {
|
||||||
#[inline]
|
const WIDTH: usize = WIDTH;
|
||||||
fn get_width(&self) -> usize {
|
const HEIGHT: usize = HEIGHT;
|
||||||
WIDTH
|
const SIZE: usize = SIZE;
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn get_height(&self) -> usize {
|
|
||||||
HEIGHT
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn get_size(&self) -> usize {
|
|
||||||
SIZE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphicsWriter<u8> for Graphics320x200x256 {
|
impl GraphicsWriter<u8> for Graphics320x200x256 {
|
||||||
|
|
|
@ -40,15 +40,9 @@ const WIDTH_IN_BYTES: usize = WIDTH / 8;
|
||||||
pub struct Graphics640x480x16;
|
pub struct Graphics640x480x16;
|
||||||
|
|
||||||
impl Screen for Graphics640x480x16 {
|
impl Screen for Graphics640x480x16 {
|
||||||
fn get_width(&self) -> usize {
|
const WIDTH: usize = WIDTH;
|
||||||
WIDTH
|
const HEIGHT: usize = HEIGHT;
|
||||||
}
|
const SIZE: usize = SIZE;
|
||||||
fn get_height(&self) -> usize {
|
|
||||||
HEIGHT
|
|
||||||
}
|
|
||||||
fn get_size(&self) -> usize {
|
|
||||||
SIZE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphicsWriter<Color16> for Graphics640x480x16 {
|
impl GraphicsWriter<Color16> for Graphics640x480x16 {
|
||||||
|
|
|
@ -51,12 +51,12 @@ static BLANK_CHARACTER: ScreenCharacter = ScreenCharacter {
|
||||||
|
|
||||||
/// A helper trait used to interact with various vga screens.
|
/// A helper trait used to interact with various vga screens.
|
||||||
pub trait Screen {
|
pub trait Screen {
|
||||||
/// Returns the width of the `Screen`.
|
/// The width of the `Screen`.
|
||||||
fn get_width(&self) -> usize;
|
const WIDTH: usize;
|
||||||
/// Returns the height of the `Screen`.
|
/// The height of the `Screen`.
|
||||||
fn get_height(&self) -> usize;
|
const HEIGHT: usize;
|
||||||
/// Returns the size of the `Screen`.
|
/// The size (total area) of the `Screen`.
|
||||||
fn get_size(&self) -> usize;
|
const SIZE: usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper trait used to interact with various vga text modes.
|
/// A helper trait used to interact with various vga text modes.
|
||||||
|
@ -79,8 +79,7 @@ pub trait TextWriter: Screen {
|
||||||
/// color of `Color16::Yellow`.
|
/// color of `Color16::Yellow`.
|
||||||
fn clear_screen(&self) {
|
fn clear_screen(&self) {
|
||||||
let (_vga, frame_buffer) = self.get_frame_buffer();
|
let (_vga, frame_buffer) = self.get_frame_buffer();
|
||||||
let screen_size = self.get_width() * self.get_height();
|
for i in 0..Self::SIZE {
|
||||||
for i in 0..screen_size {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
frame_buffer.add(i).write_volatile(BLANK_CHARACTER);
|
frame_buffer.add(i).write_volatile(BLANK_CHARACTER);
|
||||||
}
|
}
|
||||||
|
@ -94,8 +93,7 @@ pub trait TextWriter: Screen {
|
||||||
character: b' ',
|
character: b' ',
|
||||||
color,
|
color,
|
||||||
};
|
};
|
||||||
let screen_size = self.get_width() * self.get_height();
|
for i in 0..Self::SIZE {
|
||||||
for i in 0..screen_size {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
frame_buffer.add(i).write_volatile(character);
|
frame_buffer.add(i).write_volatile(character);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +131,7 @@ pub trait TextWriter: Screen {
|
||||||
/// Returns the `ScreenCharacter` at the given `(x, y)` position.
|
/// Returns the `ScreenCharacter` at the given `(x, y)` position.
|
||||||
fn read_character(&self, x: usize, y: usize) -> ScreenCharacter {
|
fn read_character(&self, x: usize, y: usize) -> ScreenCharacter {
|
||||||
let (_vga, frame_buffer) = self.get_frame_buffer();
|
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() }
|
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
|
/// Sets the current text cursor to the position specified by
|
||||||
/// `x` and `y`.
|
/// `x` and `y`.
|
||||||
fn set_cursor_position(&self, x: usize, y: usize) {
|
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 (mut vga, _frame_buffer) = self.get_frame_buffer();
|
||||||
let emulation_mode = vga.get_emulation_mode();
|
let emulation_mode = vga.get_emulation_mode();
|
||||||
let cursor_start = offset & 0xFF;
|
let cursor_start = offset & 0xFF;
|
||||||
|
@ -189,7 +187,7 @@ pub trait TextWriter: Screen {
|
||||||
/// Prints the given `character` and `color` at `(x, y)`.
|
/// Prints the given `character` and `color` at `(x, y)`.
|
||||||
fn write_character(&self, x: usize, y: usize, screen_character: ScreenCharacter) {
|
fn write_character(&self, x: usize, y: usize, screen_character: ScreenCharacter) {
|
||||||
let (_vga, frame_buffer) = self.get_frame_buffer();
|
let (_vga, frame_buffer) = self.get_frame_buffer();
|
||||||
let offset = self.get_width() * y + x;
|
let offset = Self::WIDTH * y + x;
|
||||||
unsafe {
|
unsafe {
|
||||||
frame_buffer.add(offset).write_volatile(screen_character);
|
frame_buffer.add(offset).write_volatile(screen_character);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
|
|
||||||
const WIDTH: usize = 40;
|
const WIDTH: usize = 40;
|
||||||
const HEIGHT: usize = 25;
|
const HEIGHT: usize = 25;
|
||||||
|
const SIZE: usize = WIDTH * HEIGHT;
|
||||||
|
|
||||||
/// A basic interface for interacting with vga text mode 40x25
|
/// A basic interface for interacting with vga text mode 40x25
|
||||||
///
|
///
|
||||||
|
@ -30,17 +31,9 @@ const HEIGHT: usize = 25;
|
||||||
pub struct Text40x25;
|
pub struct Text40x25;
|
||||||
|
|
||||||
impl Screen for Text40x25 {
|
impl Screen for Text40x25 {
|
||||||
fn get_width(&self) -> usize {
|
const WIDTH: usize = WIDTH;
|
||||||
WIDTH
|
const HEIGHT: usize = HEIGHT;
|
||||||
}
|
const SIZE: usize = SIZE;
|
||||||
|
|
||||||
fn get_height(&self) -> usize {
|
|
||||||
HEIGHT
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_size(&self) -> usize {
|
|
||||||
WIDTH * HEIGHT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextWriter for Text40x25 {
|
impl TextWriter for Text40x25 {
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
|
|
||||||
const WIDTH: usize = 40;
|
const WIDTH: usize = 40;
|
||||||
const HEIGHT: usize = 50;
|
const HEIGHT: usize = 50;
|
||||||
|
const SIZE: usize = WIDTH * HEIGHT;
|
||||||
|
|
||||||
/// A basic interface for interacting with vga text mode 40x50
|
/// A basic interface for interacting with vga text mode 40x50
|
||||||
///
|
///
|
||||||
|
@ -30,17 +31,9 @@ const HEIGHT: usize = 50;
|
||||||
pub struct Text40x50;
|
pub struct Text40x50;
|
||||||
|
|
||||||
impl Screen for Text40x50 {
|
impl Screen for Text40x50 {
|
||||||
fn get_width(&self) -> usize {
|
const WIDTH: usize = WIDTH;
|
||||||
WIDTH
|
const HEIGHT: usize = HEIGHT;
|
||||||
}
|
const SIZE: usize = SIZE;
|
||||||
|
|
||||||
fn get_height(&self) -> usize {
|
|
||||||
HEIGHT
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_size(&self) -> usize {
|
|
||||||
WIDTH * HEIGHT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextWriter for Text40x50 {
|
impl TextWriter for Text40x50 {
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
|
|
||||||
const WIDTH: usize = 80;
|
const WIDTH: usize = 80;
|
||||||
const HEIGHT: usize = 25;
|
const HEIGHT: usize = 25;
|
||||||
|
const SIZE: usize = WIDTH * HEIGHT;
|
||||||
|
|
||||||
/// A basic interface for interacting with vga text mode 80x25
|
/// A basic interface for interacting with vga text mode 80x25
|
||||||
///
|
///
|
||||||
|
@ -30,17 +31,9 @@ const HEIGHT: usize = 25;
|
||||||
pub struct Text80x25;
|
pub struct Text80x25;
|
||||||
|
|
||||||
impl Screen for Text80x25 {
|
impl Screen for Text80x25 {
|
||||||
fn get_width(&self) -> usize {
|
const WIDTH: usize = WIDTH;
|
||||||
WIDTH
|
const HEIGHT: usize = HEIGHT;
|
||||||
}
|
const SIZE: usize = SIZE;
|
||||||
|
|
||||||
fn get_height(&self) -> usize {
|
|
||||||
HEIGHT
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_size(&self) -> usize {
|
|
||||||
WIDTH * HEIGHT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextWriter for Text80x25 {
|
impl TextWriter for Text80x25 {
|
||||||
|
|
Loading…
Reference in a new issue