Compare commits
8 commits
master
...
primitives
Author | SHA1 | Date | |
---|---|---|---|
45abc17ab8 | |||
1b21920052 | |||
60ea020282 | |||
57799a188b | |||
689ecc7bf3 | |||
2b781e647d | |||
87cbf76faf | |||
6ba531a957 |
10
.github/workflows/rust.yml
vendored
10
.github/workflows/rust.yml
vendored
|
@ -29,7 +29,7 @@ jobs:
|
||||||
- name: Install Rustup
|
- name: Install Rustup
|
||||||
run: |
|
run: |
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
|
||||||
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
echo ::add-path::$HOME/.cargo/bin
|
||||||
if: runner.os == 'macOS'
|
if: runner.os == 'macOS'
|
||||||
|
|
||||||
- name: "Print Rust Version"
|
- name: "Print Rust Version"
|
||||||
|
@ -43,7 +43,7 @@ jobs:
|
||||||
path: binaries
|
path: binaries
|
||||||
key: ${{ runner.OS }}-binaries
|
key: ${{ runner.OS }}-binaries
|
||||||
- name: Add binaries/bin to PATH
|
- name: Add binaries/bin to PATH
|
||||||
run: echo "$GITHUB_WORKSPACE/binaries/bin" >> $GITHUB_PATH
|
run: echo ::add-path::$GITHUB_WORKSPACE/binaries/bin
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: "Run cargo build"
|
- name: "Run cargo build"
|
||||||
|
@ -75,7 +75,7 @@ jobs:
|
||||||
- name: Install Scoop (Windows)
|
- name: Install Scoop (Windows)
|
||||||
run: |
|
run: |
|
||||||
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
|
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
|
||||||
echo "$HOME\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
echo ::add-path::$HOME\scoop\shims
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
- name: Install QEMU (Windows)
|
- name: Install QEMU (Windows)
|
||||||
|
@ -100,7 +100,7 @@ jobs:
|
||||||
timeout-minutes: 2
|
timeout-minutes: 2
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- run: rustup toolchain install nightly --profile minimal --component rustfmt
|
- run: rustup install nightly
|
||||||
- run: cargo +nightly fmt -- --check
|
- run: cargo +nightly fmt -- --check
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
|
@ -109,5 +109,5 @@ jobs:
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- run: rustup toolchain install nightly --profile minimal --component clippy
|
- run: rustup install nightly
|
||||||
- run: cargo +nightly clippy -- -D warnings
|
- run: cargo +nightly clippy -- -D warnings
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,3 @@
|
||||||
/target
|
/target
|
||||||
/testing/target
|
/testing/target
|
||||||
/testing/binaries
|
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
|
35
Cargo.toml
35
Cargo.toml
|
@ -1,12 +1,17 @@
|
||||||
[package]
|
[package]
|
||||||
name = "vga"
|
name = "vga"
|
||||||
version = "0.2.7"
|
version = "0.2.1"
|
||||||
authors = ["Ryan Kennedy <rkennedy9064@gmail.com>"]
|
authors = ["Ryan Kennedy <rkennedy9064@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Support for vga specific functions, data structures, and registers."
|
description = "Support for vga specific functions, data structures, and registers."
|
||||||
documentation = "https://docs.rs/vga"
|
documentation = "https://docs.rs/vga"
|
||||||
keywords = ["vga", "no_std"]
|
keywords = [
|
||||||
categories = ["no-std"]
|
"vga",
|
||||||
|
"no_std",
|
||||||
|
]
|
||||||
|
categories = [
|
||||||
|
"no-std",
|
||||||
|
]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://github.com/rust-osdev/vga"
|
repository = "https://github.com/rust-osdev/vga"
|
||||||
|
@ -15,20 +20,18 @@ repository = "https://github.com/rust-osdev/vga"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
spin = "0.9"
|
conquer-once = { version = "0.2.0", default-features = false }
|
||||||
log = "*"
|
font8x8 = { version = "0.2.5", default-features = false, features = ["unicode"] }
|
||||||
|
spinning_top = { version = "0.1.0", features = ["nightly"] }
|
||||||
|
x86_64 = "0.9.6"
|
||||||
|
|
||||||
conquer-once = { version = "0.3.2", default-features = false }
|
|
||||||
font8x8 = { version = "0.3.1", default-features = false, features = [
|
|
||||||
"unicode",
|
|
||||||
] }
|
|
||||||
spinning_top = { version = "0.2.4", features = ["nightly"] }
|
|
||||||
x86_64 = "0.14.2"
|
|
||||||
[dependencies.num-traits]
|
[dependencies.num-traits]
|
||||||
version = "0.2.14"
|
version = "0.2.11"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies.ab_glyph]
|
[features]
|
||||||
version = "0.2.15"
|
default = []
|
||||||
default-features = false
|
alloc = []
|
||||||
features = ["libm"]
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
features = ["alloc"]
|
||||||
|
|
32
Changelog.md
32
Changelog.md
|
@ -1,35 +1,3 @@
|
||||||
# 0.2.6
|
|
||||||
|
|
||||||
- Updatex `x86_64` to build with lastest rust nightly.
|
|
||||||
|
|
||||||
# 0.2.5
|
|
||||||
|
|
||||||
- Updated various out of date crates.
|
|
||||||
|
|
||||||
# 0.2.4
|
|
||||||
|
|
||||||
- Updated `x86_64` to fix deprecated `asm!` macro.
|
|
||||||
|
|
||||||
# 0.2.3
|
|
||||||
|
|
||||||
- Added support for 320x240x256 mode via `Graphics320x240x256`.
|
|
||||||
- Added the ability to easily get a pointer to the modes frame buffer via `GraphicsWriter::get_frame_buffer`.
|
|
||||||
|
|
||||||
# 0.2.2
|
|
||||||
|
|
||||||
## Breaking
|
|
||||||
|
|
||||||
- `Screen::get_width()` now accessed by associated constant `i.e Text80x25::WIDTH`.
|
|
||||||
- `Screen::get_height()` now accessed by associated constant `i.e Text80x25::HEIGHT`.
|
|
||||||
- `Screen::get_size()` now accessed by associated constant `i.e Text80x25::SIZE`.
|
|
||||||
- `Graphics320x200x256::new`, `Graphics640x480x16::new`, `Text40x25::new`, `Text40x50::new`, `Text80x25::new` and `ScreenCharacter::new` are now `const fn`.
|
|
||||||
- `Graphics320x200x256`, `Graphics640x480x16`, `Text40x25`, `Text40x50`, and `Text80x25` now derive `Copy` and `Clone`.
|
|
||||||
|
|
||||||
## Other
|
|
||||||
|
|
||||||
- Added `TextWriter::fill_screen(ScreenCharacter)` for convenience.
|
|
||||||
|
|
||||||
|
|
||||||
# 0.2.1
|
# 0.2.1
|
||||||
|
|
||||||
- Added `Graphics320x200x256` mode.
|
- Added `Graphics320x200x256` mode.
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -4,7 +4,7 @@
|
||||||
pub const PALETTE_SIZE: usize = 768;
|
pub const PALETTE_SIZE: usize = 768;
|
||||||
|
|
||||||
/// Represents a 16 bit color used for vga display.
|
/// Represents a 16 bit color used for vga display.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Color16 {
|
pub enum Color16 {
|
||||||
/// Represents the color `Black (0x0)`.
|
/// Represents the color `Black (0x0)`.
|
||||||
|
@ -48,7 +48,7 @@ impl From<Color16> for u8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a color for vga text modes.
|
/// Represents a color for vga text modes.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct TextModeColor(u8);
|
pub struct TextModeColor(u8);
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ impl TextModeColor {
|
||||||
self.0 = foreground as u8;
|
self.0 = foreground as u8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the default vga 256 color palette.
|
/// Represents the default vga 256 color palette.
|
||||||
pub const DEFAULT_PALETTE: [u8; PALETTE_SIZE] = [
|
pub const DEFAULT_PALETTE: [u8; PALETTE_SIZE] = [
|
||||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x2A, 0x0, 0x2A, 0x0, 0x0, 0x2A, 0x2A, 0x2A, 0x0, 0x0, 0x2A, 0x0,
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x2A, 0x0, 0x2A, 0x0, 0x0, 0x2A, 0x2A, 0x2A, 0x0, 0x0, 0x2A, 0x0,
|
||||||
|
|
|
@ -249,7 +249,7 @@ pub const MODE_640X480X16_CONFIGURATION: VgaConfiguration = VgaConfiguration {
|
||||||
sequencer_registers: &[
|
sequencer_registers: &[
|
||||||
(SequencerIndex::SequencerReset, 0x03),
|
(SequencerIndex::SequencerReset, 0x03),
|
||||||
(SequencerIndex::ClockingMode, 0x01),
|
(SequencerIndex::ClockingMode, 0x01),
|
||||||
(SequencerIndex::PlaneMask, 0x08),
|
(SequencerIndex::PlaneMask, 0x0F),
|
||||||
(SequencerIndex::CharacterFont, 0x00),
|
(SequencerIndex::CharacterFont, 0x00),
|
||||||
(SequencerIndex::MemoryMode, 0x06),
|
(SequencerIndex::MemoryMode, 0x06),
|
||||||
],
|
],
|
||||||
|
@ -286,7 +286,7 @@ pub const MODE_640X480X16_CONFIGURATION: VgaConfiguration = VgaConfiguration {
|
||||||
(GraphicsControllerIndex::ColorCompare, 0x00),
|
(GraphicsControllerIndex::ColorCompare, 0x00),
|
||||||
(GraphicsControllerIndex::DataRotate, 0x00),
|
(GraphicsControllerIndex::DataRotate, 0x00),
|
||||||
(GraphicsControllerIndex::ReadPlaneSelect, 0x03),
|
(GraphicsControllerIndex::ReadPlaneSelect, 0x03),
|
||||||
(GraphicsControllerIndex::GraphicsMode, 0x00),
|
(GraphicsControllerIndex::GraphicsMode, 0x02),
|
||||||
(GraphicsControllerIndex::Miscellaneous, 0x05),
|
(GraphicsControllerIndex::Miscellaneous, 0x05),
|
||||||
(GraphicsControllerIndex::ColorDontCare, 0x0F),
|
(GraphicsControllerIndex::ColorDontCare, 0x0F),
|
||||||
(GraphicsControllerIndex::BitMask, 0xFF),
|
(GraphicsControllerIndex::BitMask, 0xFF),
|
||||||
|
@ -316,7 +316,7 @@ pub const MODE_640X480X16_CONFIGURATION: VgaConfiguration = VgaConfiguration {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Register values for Vga mode 320x200x256 Graphics.
|
/// Register values for Vga mode 640x480x16 Graphics.
|
||||||
pub const MODE_320X200X256_CONFIGURATION: VgaConfiguration = VgaConfiguration {
|
pub const MODE_320X200X256_CONFIGURATION: VgaConfiguration = VgaConfiguration {
|
||||||
// Configuration values acquired from https://www.singlix.com/trdos/archive/vga/Graphics%20in%20pmode.pdf
|
// Configuration values acquired from https://www.singlix.com/trdos/archive/vga/Graphics%20in%20pmode.pdf
|
||||||
miscellaneous_output: 0x63,
|
miscellaneous_output: 0x63,
|
||||||
|
@ -389,77 +389,3 @@ pub const MODE_320X200X256_CONFIGURATION: VgaConfiguration = VgaConfiguration {
|
||||||
(AttributeControllerIndex::ColorSelect, 0x00),
|
(AttributeControllerIndex::ColorSelect, 0x00),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Register values for Vga mode 320x200x256x Graphics.
|
|
||||||
pub const MODE_320X240X256_CONFIGURATION: VgaConfiguration = VgaConfiguration {
|
|
||||||
// Configuration values acquired from https://www.singlix.com/trdos/archive/vga/Graphics%20in%20pmode.pdf
|
|
||||||
miscellaneous_output: 0x63,
|
|
||||||
sequencer_registers: &[
|
|
||||||
(SequencerIndex::SequencerReset, 0x03),
|
|
||||||
(SequencerIndex::ClockingMode, 0x01),
|
|
||||||
(SequencerIndex::PlaneMask, 0x0F),
|
|
||||||
(SequencerIndex::CharacterFont, 0x00),
|
|
||||||
(SequencerIndex::MemoryMode, 0x06),
|
|
||||||
],
|
|
||||||
crtc_controller_registers: &[
|
|
||||||
(CrtcControllerIndex::HorizontalTotal, 0x5F),
|
|
||||||
(CrtcControllerIndex::HorizontalDisplayEnableEnd, 0x4F),
|
|
||||||
(CrtcControllerIndex::HorizontalBlankingStart, 0x50),
|
|
||||||
(CrtcControllerIndex::HorizontalBlankingEnd, 0x82),
|
|
||||||
(CrtcControllerIndex::HorizontalSyncStart, 0x54),
|
|
||||||
(CrtcControllerIndex::HorizontalSyncEnd, 0x80),
|
|
||||||
(CrtcControllerIndex::VeritcalTotal, 0x0D),
|
|
||||||
(CrtcControllerIndex::Overflow, 0x3E),
|
|
||||||
(CrtcControllerIndex::PresetRowScan, 0x00),
|
|
||||||
(CrtcControllerIndex::MaximumScanLine, 0x41),
|
|
||||||
(CrtcControllerIndex::TextCursorStart, 0x00),
|
|
||||||
(CrtcControllerIndex::TextCursorEnd, 0x00),
|
|
||||||
(CrtcControllerIndex::StartAddressHigh, 0x00),
|
|
||||||
(CrtcControllerIndex::StartAddressLow, 0x00),
|
|
||||||
(CrtcControllerIndex::TextCursorLocationHigh, 0x00),
|
|
||||||
(CrtcControllerIndex::TextCursorLocationLow, 0x00),
|
|
||||||
(CrtcControllerIndex::VerticalSyncStart, 0xEA),
|
|
||||||
(CrtcControllerIndex::VerticalSyncEnd, 0xAC),
|
|
||||||
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0xDF),
|
|
||||||
(CrtcControllerIndex::Offset, 0x28),
|
|
||||||
(CrtcControllerIndex::UnderlineLocation, 0x00),
|
|
||||||
(CrtcControllerIndex::VerticalBlankingStart, 0xE7),
|
|
||||||
(CrtcControllerIndex::VerticalBlankingEnd, 0x06),
|
|
||||||
(CrtcControllerIndex::ModeControl, 0xE3),
|
|
||||||
(CrtcControllerIndex::LineCompare, 0xFF),
|
|
||||||
],
|
|
||||||
graphics_controller_registers: &[
|
|
||||||
(GraphicsControllerIndex::SetReset, 0x00),
|
|
||||||
(GraphicsControllerIndex::EnableSetReset, 0x00),
|
|
||||||
(GraphicsControllerIndex::ColorCompare, 0x00),
|
|
||||||
(GraphicsControllerIndex::DataRotate, 0x00),
|
|
||||||
(GraphicsControllerIndex::ReadPlaneSelect, 0x00),
|
|
||||||
(GraphicsControllerIndex::GraphicsMode, 0x40),
|
|
||||||
(GraphicsControllerIndex::Miscellaneous, 0x05),
|
|
||||||
(GraphicsControllerIndex::ColorDontCare, 0x0F),
|
|
||||||
(GraphicsControllerIndex::BitMask, 0xFF),
|
|
||||||
],
|
|
||||||
attribute_controller_registers: &[
|
|
||||||
(AttributeControllerIndex::PaletteRegister0, 0x00),
|
|
||||||
(AttributeControllerIndex::PaletteRegister1, 0x01),
|
|
||||||
(AttributeControllerIndex::PaletteRegister2, 0x02),
|
|
||||||
(AttributeControllerIndex::PaletteRegister3, 0x03),
|
|
||||||
(AttributeControllerIndex::PaletteRegister4, 0x04),
|
|
||||||
(AttributeControllerIndex::PaletteRegister5, 0x05),
|
|
||||||
(AttributeControllerIndex::PaletteRegister6, 0x06),
|
|
||||||
(AttributeControllerIndex::PaletteRegister7, 0x07),
|
|
||||||
(AttributeControllerIndex::PaletteRegister8, 0x08),
|
|
||||||
(AttributeControllerIndex::PaletteRegister9, 0x09),
|
|
||||||
(AttributeControllerIndex::PaletteRegisterA, 0x0A),
|
|
||||||
(AttributeControllerIndex::PaletteRegisterB, 0x0B),
|
|
||||||
(AttributeControllerIndex::PaletteRegisterC, 0x0C),
|
|
||||||
(AttributeControllerIndex::PaletteRegisterD, 0x0D),
|
|
||||||
(AttributeControllerIndex::PaletteRegisterE, 0x0E),
|
|
||||||
(AttributeControllerIndex::PaletteRegisterF, 0x0F),
|
|
||||||
(AttributeControllerIndex::ModeControl, 0x41),
|
|
||||||
(AttributeControllerIndex::OverscanColor, 0x00),
|
|
||||||
(AttributeControllerIndex::MemoryPlaneEnable, 0x0F),
|
|
||||||
(AttributeControllerIndex::HorizontalPixelPanning, 0x00),
|
|
||||||
(AttributeControllerIndex::ColorSelect, 0x00),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
|
@ -16,15 +16,15 @@ impl<T: SignedNum> Bresenham<T> {
|
||||||
let start = octant.to(start);
|
let start = octant.to(start);
|
||||||
let end = octant.to(end);
|
let end = octant.to(end);
|
||||||
|
|
||||||
let delta_x = end.0 - start.0;
|
let delta_x = end.x - start.x;
|
||||||
let delta_y = end.1 - start.1;
|
let delta_y = end.y - start.y;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
delta_x,
|
delta_x,
|
||||||
delta_y,
|
delta_y,
|
||||||
octant,
|
octant,
|
||||||
point: start,
|
point: start,
|
||||||
end_x: end.0,
|
end_x: end.x,
|
||||||
error: delta_y - delta_x,
|
error: delta_y - delta_x,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,15 +38,15 @@ where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.point.0 <= self.end_x {
|
if self.point.x <= self.end_x {
|
||||||
let point = self.octant.from(self.point);
|
let point = self.octant.from(self.point);
|
||||||
|
|
||||||
if self.error >= T::zero() {
|
if self.error >= T::zero() {
|
||||||
self.point.1 += T::one();
|
self.point.y += T::one();
|
||||||
self.error -= self.delta_x;
|
self.error -= self.delta_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.point.0 += T::one();
|
self.point.x += T::one();
|
||||||
self.error += self.delta_y;
|
self.error += self.delta_y;
|
||||||
|
|
||||||
Some(point)
|
Some(point)
|
||||||
|
|
83
src/drawing/device.rs
Normal file
83
src/drawing/device.rs
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
use super::Point;
|
||||||
|
use crate::writers::{GraphicsWriter, Screen};
|
||||||
|
use core::cmp::{max, min};
|
||||||
|
|
||||||
|
/// A helper trait used to draw to the vga screen in graphics mode.
|
||||||
|
pub trait Device<Color>
|
||||||
|
where
|
||||||
|
Self: Screen + GraphicsWriter<Color>,
|
||||||
|
Color: Clone + Copy,
|
||||||
|
{
|
||||||
|
/// Draws an 8x8 character at the given `(x, y)` coordinant to the specified `color`.
|
||||||
|
///
|
||||||
|
/// **Note:** This does no bounds checking and will panick if
|
||||||
|
/// any of the pixels fall outside of the screen range.
|
||||||
|
/// `x + 8 >= self.get_width() || y + 8 >= self.get_height()`.
|
||||||
|
fn draw_character(&mut self, x: usize, y: usize, character: char, color: Color);
|
||||||
|
|
||||||
|
/// Draws a line from `start` to `end` with the specified `color`.
|
||||||
|
///
|
||||||
|
/// **Note:** This does no bounds checking and will panick if
|
||||||
|
/// `x >= self.get_width() || y >= self.get_height()`.
|
||||||
|
fn draw_line(&mut self, start: Point<isize>, end: Point<isize>, color: Color);
|
||||||
|
|
||||||
|
/// Draws a triangle to the screen with the given points `(v0, v1, v2)`
|
||||||
|
/// and the given `color`.
|
||||||
|
///
|
||||||
|
/// **Note:** This function will clip any pixels that are
|
||||||
|
/// not contained within the screen coordinates.
|
||||||
|
/// `x < 0 || x >= self.get_width() || y < 0 || y >= self.get_height()`.
|
||||||
|
fn draw_triangle(&mut self, v0: Point<i32>, v1: Point<i32>, v2: Point<i32>, color: Color) {
|
||||||
|
let screen_width = self.get_width() as i32;
|
||||||
|
let screen_height = self.get_height() as i32;
|
||||||
|
let (a01, b01) = (v0.y - v1.y, v1.x - v0.x);
|
||||||
|
let (a12, b12) = (v1.y - v2.y, v2.x - v1.x);
|
||||||
|
let (a20, b20) = (v2.y - v0.y, v0.x - v2.x);
|
||||||
|
|
||||||
|
let mut min_x = min(v0.x, min(v1.x, v2.x));
|
||||||
|
let mut min_y = min(v0.y, min(v1.y, v2.y));
|
||||||
|
let mut max_x = max(v0.x, max(v1.x, v2.x));
|
||||||
|
let mut max_y = max(v0.y, max(v1.y, v2.y));
|
||||||
|
|
||||||
|
min_x = max(min_x, 0);
|
||||||
|
min_y = max(min_y, 0);
|
||||||
|
max_x = min(max_x, screen_width - 1);
|
||||||
|
max_y = min(max_y, screen_height - 1);
|
||||||
|
|
||||||
|
let p = Point::new(min_x, min_y);
|
||||||
|
let mut w0_row = orient2d(v1, v2, p);
|
||||||
|
let mut w1_row = orient2d(v2, v0, p);
|
||||||
|
let mut w2_row = orient2d(v0, v1, p);
|
||||||
|
|
||||||
|
for y in p.y..=max_y {
|
||||||
|
let mut w0 = w0_row;
|
||||||
|
let mut w1 = w1_row;
|
||||||
|
let mut w2 = w2_row;
|
||||||
|
|
||||||
|
for x in p.x..=max_x {
|
||||||
|
if (w0 | w1 | w2) >= 0 {
|
||||||
|
self.set_pixel(x as usize, y as usize, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
w0 += a12;
|
||||||
|
w1 += a20;
|
||||||
|
w2 += a01;
|
||||||
|
}
|
||||||
|
|
||||||
|
w0_row += b12;
|
||||||
|
w1_row += b20;
|
||||||
|
w2_row += b01;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Copies the screen buffer in the `GraphicsWriter` to vga memory.
|
||||||
|
///
|
||||||
|
/// **Note:** No draw calls will be displayed on the screen unless
|
||||||
|
/// this method is called.
|
||||||
|
fn present(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn orient2d(a: Point<i32>, b: Point<i32>, c: Point<i32>) -> i32 {
|
||||||
|
(b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
||||||
|
}
|
|
@ -3,13 +3,28 @@
|
||||||
use num_traits::{NumAssignOps, NumCast, Signed};
|
use num_traits::{NumAssignOps, NumCast, Signed};
|
||||||
|
|
||||||
mod bresenham;
|
mod bresenham;
|
||||||
|
mod device;
|
||||||
mod octant;
|
mod octant;
|
||||||
|
|
||||||
pub(crate) use bresenham::Bresenham;
|
pub(crate) use bresenham::Bresenham;
|
||||||
|
pub use device::Device;
|
||||||
use octant::Octant;
|
use octant::Octant;
|
||||||
|
|
||||||
/// A point in 2D space.
|
/// A point in 2D space.
|
||||||
pub type Point<T> = (T, T);
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct Point<T> {
|
||||||
|
/// The x coordinate of the `Point`.
|
||||||
|
pub x: T,
|
||||||
|
/// The y coordinate of the `Point`.
|
||||||
|
pub y: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Point<T> {
|
||||||
|
/// Creates a new `Point` with the given `(x, y)` coordinates.
|
||||||
|
pub fn new(x: T, y: T) -> Point<T> {
|
||||||
|
Point { x, y }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) trait SignedNum: Signed + Ord + Copy + NumCast + NumAssignOps {
|
pub(crate) trait SignedNum: Signed + Ord + Copy + NumCast + NumAssignOps {
|
||||||
fn cast<T: NumCast>(value: T) -> Self {
|
fn cast<T: NumCast>(value: T) -> Self {
|
||||||
|
|
|
@ -15,8 +15,8 @@ impl Octant {
|
||||||
T: Sub<Output = T> + Neg<Output = T> + PartialOrd + Zero,
|
T: Sub<Output = T> + Neg<Output = T> + PartialOrd + Zero,
|
||||||
{
|
{
|
||||||
let mut value = 0;
|
let mut value = 0;
|
||||||
let mut dx = end.0 - start.0;
|
let mut dx = end.x - start.x;
|
||||||
let mut dy = end.1 - start.1;
|
let mut dy = end.y - start.y;
|
||||||
|
|
||||||
if dy < T::zero() {
|
if dy < T::zero() {
|
||||||
dx = -dx;
|
dx = -dx;
|
||||||
|
@ -45,14 +45,14 @@ impl Octant {
|
||||||
T: Neg<Output = T>,
|
T: Neg<Output = T>,
|
||||||
{
|
{
|
||||||
match self.value {
|
match self.value {
|
||||||
0 => (point.0, point.1),
|
0 => Point::new(point.x, point.y),
|
||||||
1 => (point.1, point.0),
|
1 => Point::new(point.y, point.x),
|
||||||
2 => (point.1, -point.0),
|
2 => Point::new(point.y, -point.x),
|
||||||
3 => (-point.0, point.1),
|
3 => Point::new(-point.x, point.y),
|
||||||
4 => (-point.0, -point.1),
|
4 => Point::new(-point.x, -point.y),
|
||||||
5 => (-point.1, -point.0),
|
5 => Point::new(-point.y, -point.x),
|
||||||
6 => (-point.1, point.0),
|
6 => Point::new(-point.y, point.x),
|
||||||
7 => (point.0, -point.1),
|
7 => Point::new(point.x, -point.y),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,14 +61,14 @@ impl Octant {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from<T: Neg<Output = T>>(&self, point: Point<T>) -> Point<T> {
|
pub fn from<T: Neg<Output = T>>(&self, point: Point<T>) -> Point<T> {
|
||||||
match self.value {
|
match self.value {
|
||||||
0 => (point.0, point.1),
|
0 => Point::new(point.x, point.y),
|
||||||
1 => (point.1, point.0),
|
1 => Point::new(point.y, point.x),
|
||||||
2 => (-point.1, point.0),
|
2 => Point::new(-point.y, point.x),
|
||||||
3 => (-point.0, point.1),
|
3 => Point::new(-point.x, point.y),
|
||||||
4 => (-point.0, -point.1),
|
4 => Point::new(-point.x, -point.y),
|
||||||
5 => (-point.1, -point.0),
|
5 => Point::new(-point.y, -point.x),
|
||||||
6 => (point.1, -point.0),
|
6 => Point::new(point.y, -point.x),
|
||||||
7 => (point.0, -point.1),
|
7 => Point::new(point.x, -point.y),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,12 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
pub mod colors;
|
pub mod colors;
|
||||||
pub mod configurations;
|
pub mod configurations;
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
pub mod drawing;
|
pub mod drawing;
|
||||||
pub mod fonts;
|
pub mod fonts;
|
||||||
pub mod registers;
|
pub mod registers;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use super::{
|
use super::{
|
||||||
FCR_CGA_WRITE_ADDRESS, FCR_MDA_WRITE_ADDRESS, FCR_READ_ADDRESS, MSR_READ_ADDRESS,
|
EmulationMode, FCR_CGA_WRITE_ADDRESS, FCR_MDA_WRITE_ADDRESS, FCR_READ_ADDRESS,
|
||||||
MSR_WRITE_ADDRESS, ST00_READ_ADDRESS, ST01_READ_CGA_ADDRESS, ST01_READ_MDA_ADDRESS,
|
MSR_READ_ADDRESS, MSR_WRITE_ADDRESS, ST00_READ_ADDRESS, ST01_READ_CGA_ADDRESS,
|
||||||
|
ST01_READ_MDA_ADDRESS,
|
||||||
};
|
};
|
||||||
use x86_64::instructions::port::{PortReadOnly, PortWriteOnly};
|
use x86_64::instructions::port::{PortReadOnly, PortWriteOnly};
|
||||||
|
|
||||||
|
@ -42,4 +43,13 @@ impl GeneralRegisters {
|
||||||
self.msr_write.write(value);
|
self.msr_write.write(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reads the current value from the input status 1 register
|
||||||
|
/// as specified by the `emulation_mode`.
|
||||||
|
pub fn read_st01(&mut self, emulation_mode: EmulationMode) -> u8 {
|
||||||
|
match emulation_mode {
|
||||||
|
EmulationMode::Cga => unsafe { self.st01_read_cga.read() },
|
||||||
|
EmulationMode::Mda => unsafe { self.st01_read_mda.read() },
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl SequencerRegisters {
|
||||||
|
|
||||||
/// Sets the plane mask of the sequencer controller, as specified by `plane_mask`.
|
/// Sets the plane mask of the sequencer controller, as specified by `plane_mask`.
|
||||||
pub fn set_plane_mask(&mut self, plane_mask: PlaneMask) {
|
pub fn set_plane_mask(&mut self, plane_mask: PlaneMask) {
|
||||||
let original_value = self.read(SequencerIndex::PlaneMask) & 0xF0;
|
let original_value = self.read(SequencerIndex::PlaneMask);
|
||||||
self.write(
|
self.write(
|
||||||
SequencerIndex::PlaneMask,
|
SequencerIndex::PlaneMask,
|
||||||
original_value | u8::from(plane_mask),
|
original_value | u8::from(plane_mask),
|
||||||
|
|
14
src/vga.rs
14
src/vga.rs
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
configurations::{
|
configurations::{
|
||||||
VgaConfiguration, MODE_320X200X256_CONFIGURATION, MODE_320X240X256_CONFIGURATION,
|
VgaConfiguration, MODE_320X200X256_CONFIGURATION, MODE_40X25_CONFIGURATION,
|
||||||
MODE_40X25_CONFIGURATION, MODE_40X50_CONFIGURATION, MODE_640X480X16_CONFIGURATION,
|
MODE_40X50_CONFIGURATION, MODE_640X480X16_CONFIGURATION, MODE_80X25_CONFIGURATION,
|
||||||
MODE_80X25_CONFIGURATION,
|
|
||||||
},
|
},
|
||||||
fonts::VgaFont,
|
fonts::VgaFont,
|
||||||
registers::{
|
registers::{
|
||||||
|
@ -60,8 +59,6 @@ pub enum VideoMode {
|
||||||
Mode80x25,
|
Mode80x25,
|
||||||
/// Represents graphics mode 320x200x256.
|
/// Represents graphics mode 320x200x256.
|
||||||
Mode320x200x256,
|
Mode320x200x256,
|
||||||
/// Represents graphics mode 320x240x256.
|
|
||||||
Mode320x240x256,
|
|
||||||
/// Represents graphics mode 640x480x16.
|
/// Represents graphics mode 640x480x16.
|
||||||
Mode640x480x16,
|
Mode640x480x16,
|
||||||
}
|
}
|
||||||
|
@ -104,7 +101,6 @@ impl Vga {
|
||||||
VideoMode::Mode40x50 => self.set_video_mode_40x50(),
|
VideoMode::Mode40x50 => self.set_video_mode_40x50(),
|
||||||
VideoMode::Mode80x25 => self.set_video_mode_80x25(),
|
VideoMode::Mode80x25 => self.set_video_mode_80x25(),
|
||||||
VideoMode::Mode320x200x256 => self.set_video_mode_320x200x256(),
|
VideoMode::Mode320x200x256 => self.set_video_mode_320x200x256(),
|
||||||
VideoMode::Mode320x240x256 => self.set_video_mode_320x240x256(),
|
|
||||||
VideoMode::Mode640x480x16 => self.set_video_mode_640x480x16(),
|
VideoMode::Mode640x480x16 => self.set_video_mode_640x480x16(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,12 +275,6 @@ impl Vga {
|
||||||
self.most_recent_video_mode = Some(VideoMode::Mode320x200x256);
|
self.most_recent_video_mode = Some(VideoMode::Mode320x200x256);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the video card to Mode 320x200x256x.
|
|
||||||
fn set_video_mode_320x240x256(&mut self) {
|
|
||||||
self.set_registers(&MODE_320X240X256_CONFIGURATION);
|
|
||||||
self.most_recent_video_mode = Some(VideoMode::Mode320x240x256);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the video card to Mode 640x480x16.
|
/// Sets the video card to Mode 640x480x16.
|
||||||
fn set_video_mode_640x480x16(&mut self) {
|
fn set_video_mode_640x480x16(&mut self) {
|
||||||
self.set_registers(&MODE_640X480X16_CONFIGURATION);
|
self.set_registers(&MODE_640X480X16_CONFIGURATION);
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use super::{GraphicsWriter, Screen};
|
use super::{GraphicsWriter, Screen};
|
||||||
use crate::{
|
use crate::{
|
||||||
colors::DEFAULT_PALETTE,
|
colors::DEFAULT_PALETTE,
|
||||||
drawing::{Bresenham, Point},
|
drawing::{Bresenham, Device, Point},
|
||||||
vga::{VideoMode, VGA},
|
vga::{VideoMode, VGA},
|
||||||
};
|
};
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
use core::ptr;
|
||||||
use font8x8::UnicodeFonts;
|
use font8x8::UnicodeFonts;
|
||||||
|
|
||||||
const WIDTH: usize = 320;
|
const WIDTH: usize = 320;
|
||||||
|
@ -19,7 +21,7 @@ const SIZE: usize = WIDTH * HEIGHT;
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// use vga::colors::Color16;
|
/// use vga::colors::Color16;
|
||||||
/// use vga::writers::{Graphics320x200x256, GraphicsWriter};
|
/// use vga::writers::{Graphics320x200x256, GraphicsWriter};
|
||||||
///
|
|
||||||
/// let mode = Graphics320x200x256::new();
|
/// let mode = Graphics320x200x256::new();
|
||||||
/// mode.set_mode();
|
/// mode.set_mode();
|
||||||
/// mode.clear_screen(0);
|
/// mode.clear_screen(0);
|
||||||
|
@ -32,33 +34,30 @@ const SIZE: usize = WIDTH * HEIGHT;
|
||||||
/// mode.draw_character(118 + offset * 8, 27, character, 255);
|
/// mode.draw_character(118 + offset * 8, 27, character, 255);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Default)]
|
||||||
pub struct Graphics320x200x256;
|
pub struct Graphics320x200x256 {
|
||||||
|
screen_buffer: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
impl Screen for Graphics320x200x256 {
|
impl Screen for Graphics320x200x256 {
|
||||||
const WIDTH: usize = WIDTH;
|
#[inline]
|
||||||
const HEIGHT: usize = HEIGHT;
|
fn get_width(&self) -> usize {
|
||||||
const SIZE: usize = SIZE;
|
WIDTH
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphicsWriter<u8> for Graphics320x200x256 {
|
#[inline]
|
||||||
fn clear_screen(&self, color: u8) {
|
fn get_height(&self) -> usize {
|
||||||
unsafe {
|
HEIGHT
|
||||||
self.get_frame_buffer().write_bytes(color, Self::SIZE);
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn get_size(&self) -> usize {
|
||||||
|
SIZE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn draw_line(&self, start: Point<isize>, end: Point<isize>, color: u8) {
|
|
||||||
for (x, y) in Bresenham::new(start, end) {
|
impl Device<u8> for Graphics320x200x256 {
|
||||||
self.set_pixel(x as usize, y as usize, color);
|
fn draw_character(&mut self, x: usize, y: usize, character: char, color: u8) {
|
||||||
}
|
|
||||||
}
|
|
||||||
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) {
|
let character = match font8x8::BASIC_FONTS.get(character) {
|
||||||
Some(character) => character,
|
Some(character) => character,
|
||||||
// Default to a filled block if the character isn't found
|
// Default to a filled block if the character isn't found
|
||||||
|
@ -74,6 +73,42 @@ impl GraphicsWriter<u8> for Graphics320x200x256 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_line(&mut self, start: Point<isize>, end: Point<isize>, color: u8) {
|
||||||
|
for Point { x, y } in Bresenham::new(start, end) {
|
||||||
|
self.set_pixel(x as usize, y as usize, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn present(&self) {
|
||||||
|
{
|
||||||
|
let mut vga = VGA.lock();
|
||||||
|
let emulation_mode = vga.get_emulation_mode();
|
||||||
|
while vga.general_registers.read_st01(emulation_mode) & 0x3 != 0 {}
|
||||||
|
}
|
||||||
|
unsafe {
|
||||||
|
ptr::copy_nonoverlapping(
|
||||||
|
self.screen_buffer.as_ptr(),
|
||||||
|
self.get_frame_buffer(),
|
||||||
|
self.screen_buffer.len(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GraphicsWriter<u8> for Graphics320x200x256 {
|
||||||
|
fn clear_screen(&mut self, color: u8) {
|
||||||
|
unsafe {
|
||||||
|
self.screen_buffer
|
||||||
|
.as_mut_ptr()
|
||||||
|
.write_bytes(color, self.screen_buffer.len());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_pixel(&mut self, x: usize, y: usize, color: u8) {
|
||||||
|
self.screen_buffer[(y * WIDTH) + x] = color;
|
||||||
|
}
|
||||||
|
|
||||||
fn set_mode(&self) {
|
fn set_mode(&self) {
|
||||||
let mut vga = VGA.lock();
|
let mut vga = VGA.lock();
|
||||||
vga.set_video_mode(VideoMode::Mode320x200x256);
|
vga.set_video_mode(VideoMode::Mode320x200x256);
|
||||||
|
@ -86,7 +121,15 @@ impl GraphicsWriter<u8> for Graphics320x200x256 {
|
||||||
|
|
||||||
impl Graphics320x200x256 {
|
impl Graphics320x200x256 {
|
||||||
/// Creates a new `Graphics320x200x256`.
|
/// Creates a new `Graphics320x200x256`.
|
||||||
pub const fn new() -> Graphics320x200x256 {
|
pub fn new() -> Graphics320x200x256 {
|
||||||
Graphics320x200x256
|
let mut screen_buffer = Vec::with_capacity(SIZE);
|
||||||
|
for _ in 0..SIZE {
|
||||||
|
screen_buffer.push(0);
|
||||||
|
}
|
||||||
|
Graphics320x200x256 { screen_buffer }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_frame_buffer(&self) -> *mut u8 {
|
||||||
|
u32::from(VGA.lock().get_frame_buffer()) as *mut u8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,102 +0,0 @@
|
||||||
use super::{GraphicsWriter, Screen};
|
|
||||||
use crate::{
|
|
||||||
colors::DEFAULT_PALETTE,
|
|
||||||
drawing::{Bresenham, Point},
|
|
||||||
registers::PlaneMask,
|
|
||||||
vga::{VideoMode, VGA},
|
|
||||||
};
|
|
||||||
use font8x8::UnicodeFonts;
|
|
||||||
|
|
||||||
const WIDTH: usize = 320;
|
|
||||||
const HEIGHT: usize = 240;
|
|
||||||
const SIZE: usize = (WIDTH * HEIGHT) / 4;
|
|
||||||
|
|
||||||
/// A basic interface for interacting with vga graphics mode 320x200x256.
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// Basic usage:
|
|
||||||
///
|
|
||||||
/// ```no_run
|
|
||||||
/// use vga::colors::Color16;
|
|
||||||
/// use vga::writers::{Graphics320x240x256, GraphicsWriter};
|
|
||||||
///
|
|
||||||
/// let mode = Graphics320x240x256::new();
|
|
||||||
/// mode.set_mode();
|
|
||||||
/// mode.clear_screen(0);
|
|
||||||
/// mode.draw_line((60, 20), (260, 20), 255);
|
|
||||||
/// mode.draw_line((60, 20), (60, 180), 255);
|
|
||||||
/// mode.draw_line((60, 180), (260, 180), 255);
|
|
||||||
/// mode.draw_line((260, 180), (260, 20), 255);
|
|
||||||
/// mode.draw_line((60, 40), (260, 40), 255);
|
|
||||||
/// for (offset, character) in "Hello World!".chars().enumerate() {
|
|
||||||
/// mode.draw_character(118 + offset * 8, 27, character, 255);
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
|
||||||
pub struct Graphics320x240x256;
|
|
||||||
|
|
||||||
impl Screen for Graphics320x240x256 {
|
|
||||||
const WIDTH: usize = WIDTH;
|
|
||||||
const HEIGHT: usize = HEIGHT;
|
|
||||||
const SIZE: usize = SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GraphicsWriter<u8> for Graphics320x240x256 {
|
|
||||||
fn clear_screen(&self, color: u8) {
|
|
||||||
let frame_buffer = self.get_frame_buffer();
|
|
||||||
VGA.lock()
|
|
||||||
.sequencer_registers
|
|
||||||
.set_plane_mask(PlaneMask::ALL_PLANES);
|
|
||||||
unsafe {
|
|
||||||
frame_buffer.write_bytes(color, Self::SIZE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn draw_line(&self, start: Point<isize>, end: Point<isize>, color: u8) {
|
|
||||||
for (x, y) in Bresenham::new(start, end) {
|
|
||||||
self.set_pixel(x as usize, y as usize, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn set_pixel(&self, x: usize, y: usize, color: u8) {
|
|
||||||
let frame_buffer = self.get_frame_buffer();
|
|
||||||
unsafe {
|
|
||||||
let offset = (WIDTH * y + x) / 4;
|
|
||||||
let plane_mask = 0x1 << (x & 3);
|
|
||||||
VGA.lock()
|
|
||||||
.sequencer_registers
|
|
||||||
.set_plane_mask(PlaneMask::from_bits(plane_mask).unwrap());
|
|
||||||
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,
|
|
||||||
// Default to a filled block if the character isn't found
|
|
||||||
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::Mode320x240x256);
|
|
||||||
|
|
||||||
// Some bios mess up the palette when switching modes,
|
|
||||||
// so explicitly set it.
|
|
||||||
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Graphics320x240x256 {
|
|
||||||
/// Creates a new `Graphics320x240x256`.
|
|
||||||
pub const fn new() -> Graphics320x240x256 {
|
|
||||||
Graphics320x240x256
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +1,15 @@
|
||||||
use super::{GraphicsWriter, Screen};
|
use super::{GraphicsWriter, Screen};
|
||||||
use crate::{
|
use crate::{
|
||||||
colors::{Color16, DEFAULT_PALETTE},
|
colors::{Color16, DEFAULT_PALETTE},
|
||||||
drawing::{Bresenham, Point},
|
drawing::{Bresenham, Device, Point},
|
||||||
registers::{PlaneMask, WriteMode},
|
|
||||||
vga::{VideoMode, VGA},
|
vga::{VideoMode, VGA},
|
||||||
};
|
};
|
||||||
use core::convert::From;
|
use alloc::vec::Vec;
|
||||||
use font8x8::UnicodeFonts;
|
use font8x8::UnicodeFonts;
|
||||||
|
|
||||||
const WIDTH: usize = 640;
|
const WIDTH: usize = 640;
|
||||||
const HEIGHT: usize = 480;
|
const HEIGHT: usize = 480;
|
||||||
const SIZE: usize = (WIDTH * HEIGHT) / 8;
|
const SIZE: usize = WIDTH * HEIGHT;
|
||||||
const WIDTH_IN_BYTES: usize = WIDTH / 8;
|
|
||||||
|
|
||||||
/// A basic interface for interacting with vga graphics mode 640x480x16
|
/// A basic interface for interacting with vga graphics mode 640x480x16
|
||||||
///
|
///
|
||||||
|
@ -35,33 +33,25 @@ const WIDTH_IN_BYTES: usize = WIDTH / 8;
|
||||||
/// mode.draw_character(270 + offset * 8, 72, character, Color16::White)
|
/// mode.draw_character(270 + offset * 8, 72, character, Color16::White)
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Default)]
|
||||||
pub struct Graphics640x480x16;
|
pub struct Graphics640x480x16 {
|
||||||
|
screen_buffer: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
impl Screen for Graphics640x480x16 {
|
impl Screen for Graphics640x480x16 {
|
||||||
const WIDTH: usize = WIDTH;
|
fn get_width(&self) -> usize {
|
||||||
const HEIGHT: usize = HEIGHT;
|
WIDTH
|
||||||
const SIZE: usize = SIZE;
|
|
||||||
}
|
}
|
||||||
|
fn get_height(&self) -> usize {
|
||||||
impl GraphicsWriter<Color16> for Graphics640x480x16 {
|
HEIGHT
|
||||||
fn clear_screen(&self, color: Color16) {
|
}
|
||||||
self.set_write_mode_2();
|
fn get_size(&self) -> usize {
|
||||||
unsafe {
|
SIZE
|
||||||
self.get_frame_buffer()
|
|
||||||
.write_bytes(u8::from(color), Self::SIZE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_line(&self, start: Point<isize>, end: Point<isize>, color: Color16) {
|
impl Device<Color16> for Graphics640x480x16 {
|
||||||
self.set_write_mode_0(color);
|
fn draw_character(&mut self, x: usize, y: usize, character: char, color: Color16) {
|
||||||
for (x, y) in Bresenham::new(start, end) {
|
|
||||||
self._set_pixel(x as usize, y as usize, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_character(&self, x: usize, y: usize, character: char, color: Color16) {
|
|
||||||
self.set_write_mode_2();
|
|
||||||
let character = match font8x8::BASIC_FONTS.get(character) {
|
let character = match font8x8::BASIC_FONTS.get(character) {
|
||||||
Some(character) => character,
|
Some(character) => character,
|
||||||
// Default to a filled block if the character isn't found
|
// Default to a filled block if the character isn't found
|
||||||
|
@ -72,19 +62,51 @@ impl GraphicsWriter<Color16> for Graphics640x480x16 {
|
||||||
for bit in 0..8 {
|
for bit in 0..8 {
|
||||||
match *byte & 1 << bit {
|
match *byte & 1 << bit {
|
||||||
0 => (),
|
0 => (),
|
||||||
_ => self._set_pixel(x + bit, y + row, color),
|
_ => self.set_pixel(x + bit, y + row, color),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// **Note:** This method is provided for convenience, but has terrible
|
fn draw_line(&mut self, start: Point<isize>, end: Point<isize>, color: Color16) {
|
||||||
/// performance since it needs to ensure the correct `WriteMode` per pixel
|
for Point { x, y } in Bresenham::new(start, end) {
|
||||||
/// drawn. If you need to draw more then one pixel, consider using a method
|
self.set_pixel(x as usize, y as usize, color);
|
||||||
/// such as `draw_line`.
|
}
|
||||||
fn set_pixel(&self, x: usize, y: usize, color: Color16) {
|
}
|
||||||
self.set_write_mode_2();
|
|
||||||
self._set_pixel(x, y, color);
|
fn present(&self) {
|
||||||
|
let frame_buffer = self.get_frame_buffer();
|
||||||
|
let mut vga = VGA.lock();
|
||||||
|
let emulation_mode = vga.get_emulation_mode();
|
||||||
|
while vga.general_registers.read_st01(emulation_mode) & 0x3 != 0 {}
|
||||||
|
for offset in 0..SIZE {
|
||||||
|
let color = self.screen_buffer[offset];
|
||||||
|
// Set the mask to the pixel being modified
|
||||||
|
vga.graphics_controller_registers
|
||||||
|
.set_bit_mask(0x80 >> (offset & 0x7));
|
||||||
|
// Faster then offset / 8 ?
|
||||||
|
let offset = offset >> 3;
|
||||||
|
unsafe {
|
||||||
|
// Load the memory latch with 8 pixels
|
||||||
|
frame_buffer.add(offset).read_volatile();
|
||||||
|
// Write the color to the masked pixel
|
||||||
|
frame_buffer.add(offset).write_volatile(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GraphicsWriter<Color16> for Graphics640x480x16 {
|
||||||
|
fn clear_screen(&mut self, color: Color16) {
|
||||||
|
for x in 0..WIDTH {
|
||||||
|
for y in 0..HEIGHT {
|
||||||
|
self.set_pixel(x, y, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_pixel(&mut self, x: usize, y: usize, color: Color16) {
|
||||||
|
self.screen_buffer[(WIDTH * y) + x] = color as u8;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_mode(&self) {
|
fn set_mode(&self) {
|
||||||
|
@ -99,113 +121,15 @@ impl GraphicsWriter<Color16> for Graphics640x480x16 {
|
||||||
|
|
||||||
impl Graphics640x480x16 {
|
impl Graphics640x480x16 {
|
||||||
/// Creates a new `Graphics640x480x16`.
|
/// Creates a new `Graphics640x480x16`.
|
||||||
pub const fn new() -> Graphics640x480x16 {
|
pub fn new() -> Graphics640x480x16 {
|
||||||
Graphics640x480x16
|
let mut screen_buffer = Vec::with_capacity(SIZE);
|
||||||
|
for _ in 0..SIZE {
|
||||||
|
screen_buffer.push(0);
|
||||||
|
}
|
||||||
|
Graphics640x480x16 { screen_buffer }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_write_mode_0(self, color: Color16) {
|
fn get_frame_buffer(&self) -> *mut u8 {
|
||||||
let mut vga = VGA.lock();
|
u32::from(VGA.lock().get_frame_buffer()) as *mut u8
|
||||||
vga.graphics_controller_registers.write_set_reset(color);
|
|
||||||
vga.graphics_controller_registers
|
|
||||||
.write_enable_set_reset(0xF);
|
|
||||||
vga.graphics_controller_registers
|
|
||||||
.set_write_mode(WriteMode::Mode0);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_write_mode_2(self) {
|
|
||||||
let mut vga = VGA.lock();
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn _set_pixel(self, x: usize, y: usize, color: Color16) {
|
|
||||||
if x < 640 && y < 480 {
|
|
||||||
let frame_buffer = self.get_frame_buffer();
|
|
||||||
let offset = x / 8 + y * WIDTH_IN_BYTES;
|
|
||||||
let pixel_mask = 0x80 >> (x & 0x07);
|
|
||||||
VGA.lock()
|
|
||||||
.graphics_controller_registers
|
|
||||||
.set_bit_mask(pixel_mask);
|
|
||||||
unsafe {
|
|
||||||
frame_buffer.add(offset).read_volatile();
|
|
||||||
frame_buffer.add(offset).write_volatile(u8::from(color));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use ab_glyph::{Font, FontRef, Glyph};
|
|
||||||
use log::trace;
|
|
||||||
use spin::Lazy;
|
|
||||||
|
|
||||||
const FONT_BASIC: Lazy<FontRef> = Lazy::new({
|
|
||||||
|| FontRef::try_from_slice(include_bytes!("../../assets/fonts/unifont-14.0.01.ttf")).unwrap()
|
|
||||||
});
|
|
||||||
|
|
||||||
const FONT_SUPPLEMENTARY: Lazy<FontRef> = Lazy::new(|| {
|
|
||||||
FontRef::try_from_slice(include_bytes!(
|
|
||||||
"../../assets/fonts/unifont_upper-14.0.01.ttf"
|
|
||||||
))
|
|
||||||
.unwrap()
|
|
||||||
});
|
|
||||||
|
|
||||||
const FONT_SCALE: f32 = 14.0;
|
|
||||||
const GLYPH_HEIGHT: f32 = 10.0;
|
|
||||||
const GLYPH_WIDTH: f32 = 8.0;
|
|
||||||
|
|
||||||
impl Graphics640x480x16 {
|
|
||||||
/// Draw a glyph on the screen at the given position
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
/// * `x` - the x position of the glyph
|
|
||||||
/// * `y` - the y position of the glyph
|
|
||||||
/// * `glyph` - the glyph to draw
|
|
||||||
/// * `color` - the color of the glyph
|
|
||||||
pub fn draw_unicode_char(&self, mut x: usize, mut y: usize, character: char, color: Color16) {
|
|
||||||
self.set_write_mode_2();
|
|
||||||
|
|
||||||
// trace!("Char {}", character);
|
|
||||||
|
|
||||||
// if character == '\n' {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
if x == 80 {
|
|
||||||
x = 0;
|
|
||||||
y += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if character != '\0' {
|
|
||||||
let real_x = x as f32 * GLYPH_WIDTH;
|
|
||||||
let real_y = (y as f32 + 1.0) * GLYPH_HEIGHT;
|
|
||||||
// trace!("REALX{}\nREALY{}", real_x, real_y);
|
|
||||||
|
|
||||||
let in_supp_plane = character as u32 > 0xffff;
|
|
||||||
|
|
||||||
let plane = match in_supp_plane {
|
|
||||||
false => FONT_BASIC,
|
|
||||||
true => FONT_SUPPLEMENTARY,
|
|
||||||
};
|
|
||||||
|
|
||||||
let q_glyph: Glyph = plane
|
|
||||||
.glyph_id(character)
|
|
||||||
.with_scale_and_position(FONT_SCALE, ab_glyph::point(real_x, real_y));
|
|
||||||
|
|
||||||
if let Some(q) = plane.outline_glyph(q_glyph) {
|
|
||||||
q.draw(|gx, gy, c| {
|
|
||||||
if c > 0.1 {
|
|
||||||
let corner = q.px_bounds().min;
|
|
||||||
self._set_pixel(
|
|
||||||
gx as usize + corner.x as usize,
|
|
||||||
gy as usize + corner.y as usize,
|
|
||||||
color,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! Writers for common vga modes.
|
//! Writers for common vga modes.
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
mod graphics_320x200x256;
|
mod graphics_320x200x256;
|
||||||
mod graphics_320x240x256;
|
#[cfg(feature = "alloc")]
|
||||||
mod graphics_640x480x16;
|
mod graphics_640x480x16;
|
||||||
mod text_40x25;
|
mod text_40x25;
|
||||||
mod text_40x50;
|
mod text_40x50;
|
||||||
|
@ -8,21 +9,20 @@ mod text_80x25;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
colors::{Color16, TextModeColor},
|
colors::{Color16, TextModeColor},
|
||||||
drawing::Point,
|
|
||||||
registers::CrtcControllerIndex,
|
registers::CrtcControllerIndex,
|
||||||
vga::{Vga, VGA},
|
vga::VGA,
|
||||||
};
|
};
|
||||||
use spinning_top::SpinlockGuard;
|
|
||||||
|
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
pub use graphics_320x200x256::Graphics320x200x256;
|
pub use graphics_320x200x256::Graphics320x200x256;
|
||||||
pub use graphics_320x240x256::Graphics320x240x256;
|
#[cfg(feature = "alloc")]
|
||||||
pub use graphics_640x480x16::Graphics640x480x16;
|
pub use graphics_640x480x16::Graphics640x480x16;
|
||||||
pub use text_40x25::Text40x25;
|
pub use text_40x25::Text40x25;
|
||||||
pub use text_40x50::Text40x50;
|
pub use text_40x50::Text40x50;
|
||||||
pub use text_80x25::Text80x25;
|
pub use text_80x25::Text80x25;
|
||||||
|
|
||||||
/// Represents a `ScreenCharacter` in vga text modes.
|
/// Represents a `ScreenCharacter` in vga text modes.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct ScreenCharacter {
|
pub struct ScreenCharacter {
|
||||||
character: u8,
|
character: u8,
|
||||||
|
@ -31,7 +31,7 @@ pub struct ScreenCharacter {
|
||||||
|
|
||||||
impl ScreenCharacter {
|
impl ScreenCharacter {
|
||||||
/// Creates a new `ScreenCharacter` with the specified `character` and `TextModeColor`.
|
/// Creates a new `ScreenCharacter` with the specified `character` and `TextModeColor`.
|
||||||
pub const fn new(character: u8, color: TextModeColor) -> ScreenCharacter {
|
pub fn new(character: u8, color: TextModeColor) -> ScreenCharacter {
|
||||||
ScreenCharacter { character, color }
|
ScreenCharacter { character, color }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,12 +53,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 {
|
||||||
/// The width of the `Screen`.
|
/// Returns the width of the `Screen`.
|
||||||
const WIDTH: usize;
|
fn get_width(&self) -> usize;
|
||||||
/// The height of the `Screen`.
|
/// Returns the height of the `Screen`.
|
||||||
const HEIGHT: usize;
|
fn get_height(&self) -> usize;
|
||||||
/// The size (total area) of the `Screen`.
|
/// Returns the size of the `Screen`.
|
||||||
const SIZE: usize;
|
fn get_size(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper trait used to interact with various vga text modes.
|
/// A helper trait used to interact with various vga text modes.
|
||||||
|
@ -67,35 +67,29 @@ pub trait TextWriter: Screen {
|
||||||
/// the `TextWriter` implementation.
|
/// the `TextWriter` implementation.
|
||||||
fn set_mode(&self);
|
fn set_mode(&self);
|
||||||
|
|
||||||
/// Returns the start of the `FrameBuffer` as `*mut ScreenCharacter`
|
/// Returns the start of the `FrameBuffer` as `*mut ScreenCharacter`.
|
||||||
/// as well as a lock to the vga driver. This ensures the vga
|
fn get_frame_buffer(&self) -> *mut ScreenCharacter {
|
||||||
/// driver stays locked while the frame buffer is in use.
|
|
||||||
fn get_frame_buffer(&self) -> (SpinlockGuard<Vga>, *mut ScreenCharacter) {
|
|
||||||
let mut vga = VGA.lock();
|
let mut vga = VGA.lock();
|
||||||
let frame_buffer = vga.get_frame_buffer();
|
let frame_buffer = vga.get_frame_buffer();
|
||||||
(vga, u32::from(frame_buffer) as *mut ScreenCharacter)
|
u32::from(frame_buffer) as *mut ScreenCharacter
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clears the screen by setting all cells to `b' '` with
|
/// Clears the screen by setting all cells to `b' '` with
|
||||||
/// a background color of `Color16::Black` and a foreground
|
/// a background color of `Color16::Black` and a foreground
|
||||||
/// color of `Color16::Yellow`.
|
/// color of `Color16::Yellow`.
|
||||||
fn clear_screen(&self) {
|
fn clear_screen(&self) {
|
||||||
self.fill_screen(BLANK_CHARACTER);
|
let frame_buffer = self.get_frame_buffer();
|
||||||
}
|
let screen_size = self.get_width() * self.get_height();
|
||||||
|
for i in 0..screen_size {
|
||||||
/// Fills the screen by setting all cells to the given screen character.
|
|
||||||
fn fill_screen(&self, character: ScreenCharacter) {
|
|
||||||
let (_vga, frame_buffer) = self.get_frame_buffer();
|
|
||||||
for i in 0..Self::SIZE {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
frame_buffer.add(i).write_volatile(character);
|
frame_buffer.add(i).write_volatile(BLANK_CHARACTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disables the cursor in vga text modes.
|
/// Disables the cursor in vga text modes.
|
||||||
fn disable_cursor(&self) {
|
fn disable_cursor(&self) {
|
||||||
let (mut vga, _frame_buffer) = self.get_frame_buffer();
|
let mut vga = VGA.lock();
|
||||||
let emulation_mode = vga.get_emulation_mode();
|
let emulation_mode = vga.get_emulation_mode();
|
||||||
let cursor_start = vga
|
let cursor_start = vga
|
||||||
.crtc_controller_registers
|
.crtc_controller_registers
|
||||||
|
@ -109,7 +103,7 @@ pub trait TextWriter: Screen {
|
||||||
|
|
||||||
/// Enables the cursor in vga text modes.
|
/// Enables the cursor in vga text modes.
|
||||||
fn enable_cursor(&self) {
|
fn enable_cursor(&self) {
|
||||||
let (mut vga, _frame_buffer) = self.get_frame_buffer();
|
let mut vga = VGA.lock();
|
||||||
let emulation_mode = vga.get_emulation_mode();
|
let emulation_mode = vga.get_emulation_mode();
|
||||||
let cursor_start = vga
|
let cursor_start = vga
|
||||||
.crtc_controller_registers
|
.crtc_controller_registers
|
||||||
|
@ -123,8 +117,8 @@ 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 frame_buffer = self.get_frame_buffer();
|
||||||
let offset = Self::WIDTH * y + x;
|
let offset = self.get_width() * y + x;
|
||||||
unsafe { frame_buffer.add(offset).read_volatile() }
|
unsafe { frame_buffer.add(offset).read_volatile() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +129,7 @@ pub trait TextWriter: Screen {
|
||||||
/// determined by `CrtcControllerIndex::MaxiumumScanLine (usually 15)`.
|
/// determined by `CrtcControllerIndex::MaxiumumScanLine (usually 15)`.
|
||||||
/// If `scan_line_start > scan_line_end`, the cursor isn't drawn.
|
/// If `scan_line_start > scan_line_end`, the cursor isn't drawn.
|
||||||
fn set_cursor(&self, scan_line_start: u8, scan_line_end: u8) {
|
fn set_cursor(&self, scan_line_start: u8, scan_line_end: u8) {
|
||||||
let (mut vga, _frame_buffer) = self.get_frame_buffer();
|
let mut vga = VGA.lock();
|
||||||
let emulation_mode = vga.get_emulation_mode();
|
let emulation_mode = vga.get_emulation_mode();
|
||||||
let cursor_start = vga
|
let cursor_start = vga
|
||||||
.crtc_controller_registers
|
.crtc_controller_registers
|
||||||
|
@ -160,8 +154,8 @@ 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::WIDTH * y + x;
|
let offset = self.get_width() * y + x;
|
||||||
let (mut vga, _frame_buffer) = self.get_frame_buffer();
|
let mut vga = VGA.lock();
|
||||||
let emulation_mode = vga.get_emulation_mode();
|
let emulation_mode = vga.get_emulation_mode();
|
||||||
let cursor_start = offset & 0xFF;
|
let cursor_start = offset & 0xFF;
|
||||||
let cursor_end = (offset >> 8) & 0xFF;
|
let cursor_end = (offset >> 8) & 0xFF;
|
||||||
|
@ -179,8 +173,8 @@ 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 frame_buffer = self.get_frame_buffer();
|
||||||
let offset = Self::WIDTH * y + x;
|
let offset = self.get_width() * y + x;
|
||||||
unsafe {
|
unsafe {
|
||||||
frame_buffer.add(offset).write_volatile(screen_character);
|
frame_buffer.add(offset).write_volatile(screen_character);
|
||||||
}
|
}
|
||||||
|
@ -190,17 +184,12 @@ pub trait TextWriter: Screen {
|
||||||
/// A helper trait used to interact with various vga graphics modes.
|
/// A helper trait used to interact with various vga graphics modes.
|
||||||
pub trait GraphicsWriter<Color> {
|
pub trait GraphicsWriter<Color> {
|
||||||
/// Clears the screen by setting all pixels to the specified `color`.
|
/// Clears the screen by setting all pixels to the specified `color`.
|
||||||
fn clear_screen(&self, color: Color);
|
fn clear_screen(&mut self, color: Color);
|
||||||
/// Draws a line from `start` to `end` with the specified `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`.
|
||||||
fn set_pixel(&self, x: usize, y: usize, color: Color);
|
///
|
||||||
|
/// **Note:** This does no bounds checking and will panick if
|
||||||
|
/// `x >= self.get_width() || y >= self.get_height()`.
|
||||||
|
fn set_pixel(&mut self, x: usize, y: usize, color: Color);
|
||||||
/// Sets the graphics device to a `VideoMode`.
|
/// Sets the graphics device to a `VideoMode`.
|
||||||
fn set_mode(&self);
|
fn set_mode(&self);
|
||||||
/// Returns the frame buffer for this vga mode.
|
|
||||||
fn get_frame_buffer(&self) -> *mut u8 {
|
|
||||||
u32::from(VGA.lock().get_frame_buffer()) as *mut u8
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ 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
|
||||||
///
|
///
|
||||||
|
@ -27,13 +26,21 @@ const SIZE: usize = WIDTH * HEIGHT;
|
||||||
/// text_mode.clear_screen();
|
/// text_mode.clear_screen();
|
||||||
/// text_mode.write_character(0, 0, screen_character);
|
/// text_mode.write_character(0, 0, screen_character);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Default)]
|
||||||
pub struct Text40x25;
|
pub struct Text40x25;
|
||||||
|
|
||||||
impl Screen for Text40x25 {
|
impl Screen for Text40x25 {
|
||||||
const WIDTH: usize = WIDTH;
|
fn get_width(&self) -> usize {
|
||||||
const HEIGHT: usize = HEIGHT;
|
WIDTH
|
||||||
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 {
|
||||||
|
@ -51,7 +58,7 @@ impl TextWriter for Text40x25 {
|
||||||
|
|
||||||
impl Text40x25 {
|
impl Text40x25 {
|
||||||
/// Creates a new `Text40x25`.
|
/// Creates a new `Text40x25`.
|
||||||
pub const fn new() -> Text40x25 {
|
pub fn new() -> Text40x25 {
|
||||||
Text40x25
|
Text40x25 {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ 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
|
||||||
///
|
///
|
||||||
|
@ -27,13 +26,21 @@ const SIZE: usize = WIDTH * HEIGHT;
|
||||||
/// text_mode.clear_screen();
|
/// text_mode.clear_screen();
|
||||||
/// text_mode.write_character(0, 0, screen_character);
|
/// text_mode.write_character(0, 0, screen_character);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Default)]
|
||||||
pub struct Text40x50;
|
pub struct Text40x50;
|
||||||
|
|
||||||
impl Screen for Text40x50 {
|
impl Screen for Text40x50 {
|
||||||
const WIDTH: usize = WIDTH;
|
fn get_width(&self) -> usize {
|
||||||
const HEIGHT: usize = HEIGHT;
|
WIDTH
|
||||||
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 {
|
||||||
|
@ -51,7 +58,7 @@ impl TextWriter for Text40x50 {
|
||||||
|
|
||||||
impl Text40x50 {
|
impl Text40x50 {
|
||||||
/// Creates a new `Text40x50`.
|
/// Creates a new `Text40x50`.
|
||||||
pub const fn new() -> Text40x50 {
|
pub fn new() -> Text40x50 {
|
||||||
Text40x50
|
Text40x50 {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ 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
|
||||||
///
|
///
|
||||||
|
@ -27,13 +26,21 @@ const SIZE: usize = WIDTH * HEIGHT;
|
||||||
/// text_mode.clear_screen();
|
/// text_mode.clear_screen();
|
||||||
/// text_mode.write_character(0, 0, screen_character);
|
/// text_mode.write_character(0, 0, screen_character);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Default)]
|
||||||
pub struct Text80x25;
|
pub struct Text80x25;
|
||||||
|
|
||||||
impl Screen for Text80x25 {
|
impl Screen for Text80x25 {
|
||||||
const WIDTH: usize = WIDTH;
|
fn get_width(&self) -> usize {
|
||||||
const HEIGHT: usize = HEIGHT;
|
WIDTH
|
||||||
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 {
|
||||||
|
@ -50,7 +57,7 @@ impl TextWriter for Text80x25 {
|
||||||
|
|
||||||
impl Text80x25 {
|
impl Text80x25 {
|
||||||
/// Creates a new `Text80x25`.
|
/// Creates a new `Text80x25`.
|
||||||
pub const fn new() -> Text80x25 {
|
pub fn new() -> Text80x25 {
|
||||||
Text80x25
|
Text80x25 {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@ authors = ["Ryan Kennedy <rkennedy9064@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bootloader = { version = "0.9.11", features = ["map_physical_memory"] }
|
bootloader = { version = "0.9.0", features = ["map_physical_memory"] }
|
||||||
conquer-once = { version = "0.3.2", default-features = false }
|
conquer-once = { version = "0.2.0", default-features = false }
|
||||||
spinning_top = { version = "0.2.4", features = ["nightly"] }
|
spinning_top = { version = "0.1.0", features = ["nightly"] }
|
||||||
pic8259 = "0.10.1"
|
pic8259_simple = "0.1.1"
|
||||||
vga = { path = "../" }
|
vga = { path = "../" }
|
||||||
uart_16550 = "0.2.14"
|
uart_16550 = "0.2.4"
|
||||||
x86_64 = "0.14.2"
|
x86_64 = "0.9.6"
|
||||||
|
|
||||||
[package.metadata.bootimage]
|
[package.metadata.bootimage]
|
||||||
test-args = [
|
test-args = [
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::gdt;
|
||||||
use crate::{hlt_loop, serial_print, serial_println};
|
use crate::{hlt_loop, serial_print, serial_println};
|
||||||
use conquer_once::spin::Lazy;
|
use conquer_once::spin::Lazy;
|
||||||
use core::convert::Into;
|
use core::convert::Into;
|
||||||
use pic8259::ChainedPics;
|
use pic8259_simple::ChainedPics;
|
||||||
use spinning_top::Spinlock;
|
use spinning_top::Spinlock;
|
||||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
|
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
|
||||||
|
|
||||||
|
@ -49,14 +49,14 @@ pub fn init_idt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn double_fault_handler(
|
extern "x86-interrupt" fn double_fault_handler(
|
||||||
stack_frame: InterruptStackFrame,
|
stack_frame: &mut InterruptStackFrame,
|
||||||
_error_code: u64,
|
_error_code: u64,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
|
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn page_fault_handler(
|
extern "x86-interrupt" fn page_fault_handler(
|
||||||
stack_frame: InterruptStackFrame,
|
stack_frame: &mut InterruptStackFrame,
|
||||||
error_code: PageFaultErrorCode,
|
error_code: PageFaultErrorCode,
|
||||||
) {
|
) {
|
||||||
use x86_64::registers::control::Cr2;
|
use x86_64::registers::control::Cr2;
|
||||||
|
@ -69,7 +69,7 @@ extern "x86-interrupt" fn page_fault_handler(
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn segment_not_present(
|
extern "x86-interrupt" fn segment_not_present(
|
||||||
_stack_frame: InterruptStackFrame,
|
_stack_frame: &mut InterruptStackFrame,
|
||||||
_error_code: u64,
|
_error_code: u64,
|
||||||
) {
|
) {
|
||||||
// For some reason this sometimes gets thrown when running tests in qemu,
|
// For some reason this sometimes gets thrown when running tests in qemu,
|
||||||
|
|
Loading…
Reference in a new issue