Skip to content

Commit bf27d34

Browse files
committed
Update crates.
Picks up changes to the Bios API for mode setting.
1 parent 4e5bcea commit bf27d34

File tree

5 files changed

+51
-48
lines changed

5 files changed

+51
-48
lines changed

Cargo.lock

Lines changed: 6 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ panic = "abort"
4141
panic = "abort"
4242

4343
[dependencies]
44-
neotron-common-bios = { git = "https://github.com/neotron-compute/neotron-common-bios" }
45-
pc-keyboard = "0.7"
46-
r0 = "1.0"
44+
chrono = { version = "0.4", default-features = false }
45+
embedded-sdmmc = { git = "https://github.com/rust-embedded-community/embedded-sdmmc-rs.git", rev = "ae5e116", default-features = false }
4746
heapless = "0.7"
48-
postcard = "1.0"
49-
serde = { version = "1.0", default-features = false }
5047
menu = "0.3"
51-
chrono = { version = "0.4", default-features = false }
52-
embedded-sdmmc = { git = "https://github.com/rust-embedded-community/embedded-sdmmc-rs.git", rev = "2f14459", default-features = false }
5348
neotron-api = "0.1"
49+
neotron-common-bios = "0.12.0"
5450
neotron-loader = "0.1"
51+
pc-keyboard = "0.7"
52+
postcard = "1.0"
53+
r0 = "1.0"
54+
serde = { version = "1.0", default-features = false }
5555
vte = "0.12"
5656

5757
[features]

src/commands/screen.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub static MODE_ITEM: menu::Item<Ctx> = menu::Item {
2626
}],
2727
},
2828
command: "mode",
29-
help: Some("List possible video modes"),
29+
help: Some("List/change video mode"),
3030
};
3131

3232
/// Called when the "cls" command is executed.
@@ -63,7 +63,15 @@ fn mode_cmd(_menu: &menu::Menu<Ctx>, item: &menu::Item<Ctx>, args: &[&str], _ctx
6363
return;
6464
}
6565
}
66-
match (api.video_set_mode)(mode) {
66+
if (api.video_mode_needs_vram)(mode) {
67+
// The OS currently has no VRAM for text modes
68+
osprintln!("That mode requires more VRAM than the BIOS has.");
69+
return;
70+
}
71+
// # Safety
72+
//
73+
// It's always OK to pass NULl to this API.
74+
match unsafe { (api.video_set_mode)(mode, core::ptr::null_mut()) } {
6775
ApiResult::Ok(_) => {
6876
let mut guard = crate::VGA_CONSOLE.lock();
6977
if let Some(console) = guard.as_mut() {

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ pub extern "C" fn os_main(api: &bios::Api) -> ! {
389389

390390
if let Some(mut mode) = config.get_vga_console() {
391391
// Set the configured mode
392-
if let bios::FfiResult::Err(_e) = (api.video_set_mode)(mode) {
392+
if let bios::FfiResult::Err(_e) =
393+
unsafe { (api.video_set_mode)(mode, core::ptr::null_mut()) }
394+
{
393395
// Failed to change mode - check what mode we're in
394396
mode = (api.video_get_mode)();
395397
};

src/vgaconsole.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl VgaConsole {
5252
false,
5353
);
5454

55-
pub fn new(addr: *mut u8, width: isize, height: isize) -> VgaConsole {
55+
pub fn new(addr: *mut u32, width: isize, height: isize) -> VgaConsole {
5656
VgaConsole {
5757
inner: ConsoleInner {
5858
addr,
@@ -112,16 +112,31 @@ impl VgaConsole {
112112
///
113113
/// Separate from the parser, so it can be passed to the `advance` method.
114114
struct ConsoleInner {
115-
addr: *mut u8,
115+
/// The start of our text buffer.
116+
///
117+
/// Always 32-bit aligned.
118+
addr: *mut u32,
119+
/// The width of the screen in characters
116120
width: isize,
121+
/// The height of the screen in characters
117122
height: isize,
123+
/// The current row position in characters
118124
row: isize,
125+
/// The current column position in characters
119126
col: isize,
127+
/// The attribute to apply to the next character we draw
120128
attr: Attr,
129+
/// Have we seen the ANSI 'bold' command?
121130
bright: bool,
131+
/// Have we seen the ANSI 'reverse' command?
122132
reverse: bool,
133+
/// Should we draw a cursor?
123134
cursor_wanted: bool,
135+
/// How many times has the cursor been turned off?
136+
///
137+
/// The cursor is only enabled when at `0`.
124138
cursor_depth: u8,
139+
/// What character should be where the cursor currently is?
125140
cursor_holder: Option<u8>,
126141
}
127142

@@ -237,7 +252,8 @@ impl ConsoleInner {
237252
}
238253

239254
let offset = ((row * self.width) + col) * 2;
240-
unsafe { core::ptr::write_volatile(self.addr.offset(offset), glyph) };
255+
let byte_addr = self.addr as *mut u8;
256+
unsafe { core::ptr::write_volatile(byte_addr.offset(offset), glyph) };
241257
let attr = if self.reverse {
242258
let new_fg = self.attr.bg().make_foreground();
243259
let new_bg = self.attr.fg().make_background();
@@ -246,7 +262,7 @@ impl ConsoleInner {
246262
self.attr
247263
};
248264

249-
unsafe { core::ptr::write_volatile(self.addr.offset(offset + 1), attr.as_u8()) };
265+
unsafe { core::ptr::write_volatile(byte_addr.offset(offset + 1), attr.as_u8()) };
250266
}
251267

252268
/// Read a glyph at the current position
@@ -266,20 +282,21 @@ impl ConsoleInner {
266282
assert!(self.cursor_holder.is_none());
267283
}
268284
let offset = ((row * self.width) + col) * 2;
269-
unsafe { core::ptr::read_volatile(self.addr.offset(offset)) }
285+
let byte_addr = self.addr as *const u8;
286+
unsafe { core::ptr::read_volatile(byte_addr.offset(offset)) }
270287
}
271288

272289
/// Move everyone on screen up one line, losing the top line.
273290
///
274291
/// The bottom line will be all space characters.
275292
fn scroll_page(&mut self) {
276-
let row_len_bytes = self.width * 2;
293+
let row_len_words = self.width / 2;
277294
unsafe {
278295
// Scroll rows[1..=height-1] to become rows[0..=height-2].
279296
core::ptr::copy(
280-
self.addr.offset(row_len_bytes),
297+
self.addr.offset(row_len_words),
281298
self.addr,
282-
(row_len_bytes * (self.height - 1)) as usize,
299+
(row_len_words * (self.height - 1)) as usize,
283300
);
284301
}
285302
// Blank the bottom line of the screen (rows[height-1]).

0 commit comments

Comments
 (0)