Skip to content

Commit b19e74e

Browse files
authored
Merge pull request #27 from Neotron-Compute/set-colour-correctly
Set colours correctly.
2 parents d1ddb0f + 5cc2c3b commit b19e74e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/vgaconsole.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! Code for dealing with a VGA-style console, where there's a buffer of 16-bit
44
//! values, each corresponding to a glyph and some attributes.
55
6+
use neotron_common_bios::video::{Attr, TextBackgroundColour, TextForegroundColour};
7+
68
#[derive(Debug)]
79
pub struct VgaConsole {
810
addr: *mut u8,
@@ -14,7 +16,11 @@ pub struct VgaConsole {
1416

1517
impl VgaConsole {
1618
/// White on Black
17-
const DEFAULT_ATTR: u8 = 15 << 3;
19+
const DEFAULT_ATTR: Attr = Attr::new(
20+
TextForegroundColour::WHITE,
21+
TextBackgroundColour::BLACK,
22+
false,
23+
);
1824

1925
pub fn new(addr: *mut u8, width: isize, height: isize) -> VgaConsole {
2026
VgaConsole {
@@ -60,17 +66,17 @@ impl VgaConsole {
6066
self.reset_cursor();
6167
}
6268

63-
fn write(&mut self, glyph: u8, attr: Option<u8>) {
69+
fn write(&mut self, glyph: u8, attr: Option<Attr>) {
6470
self.write_at(self.row, self.col, glyph, attr);
6571
}
6672

67-
fn write_at(&mut self, row: isize, col: isize, glyph: u8, attr: Option<u8>) {
73+
fn write_at(&mut self, row: isize, col: isize, glyph: u8, attr: Option<Attr>) {
6874
assert!(row < self.height, "{} >= {}?", row, self.height);
6975
assert!(col < self.width, "{} => {}?", col, self.width);
7076
let offset = ((row * self.width) + col) * 2;
7177
unsafe { core::ptr::write_volatile(self.addr.offset(offset), glyph) };
7278
if let Some(a) = attr {
73-
unsafe { core::ptr::write_volatile(self.addr.offset(offset + 1), a) };
79+
unsafe { core::ptr::write_volatile(self.addr.offset(offset + 1), a.0) };
7480
}
7581
}
7682

0 commit comments

Comments
 (0)