Skip to content

Commit 9161fd7

Browse files
committed
store VGA mode in config.
1 parent c87c266 commit 9161fd7

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ panic = "abort"
4141
panic = "abort"
4242

4343
[dependencies]
44-
neotron-common-bios = { git = "https://github.com/neotron-compute/neotron-common-bios", branch = "make-things-inline" }
44+
neotron-common-bios = "0.11.1"
4545
pc-keyboard = "0.7"
4646
r0 = "1.0"
4747
heapless = "0.7"

src/commands/config.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Configuration related commands for Neotron OS
22
3-
use crate::{config, osprintln, Ctx};
3+
use crate::{bios, config, osprintln, Ctx};
44

55
pub static COMMAND_ITEM: menu::Item<Ctx> = menu::Item {
66
item_type: menu::ItemType::Callback {
@@ -42,16 +42,25 @@ fn command(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx:
4242
}
4343
},
4444
"vga" => match args.get(1).cloned() {
45-
Some("on") => {
46-
ctx.config.set_vga_console(true);
47-
osprintln!("VGA now on");
48-
}
4945
Some("off") => {
50-
ctx.config.set_vga_console(false);
46+
ctx.config.set_vga_console(None);
5147
osprintln!("VGA now off");
5248
}
49+
Some(mode_str) => {
50+
let Some(mode) = mode_str
51+
.parse::<u8>()
52+
.ok()
53+
.and_then(bios::video::Mode::try_from_u8)
54+
.filter(|m| m.is_text_mode())
55+
else {
56+
osprintln!("Not a valid text mode");
57+
return;
58+
};
59+
ctx.config.set_vga_console(Some(mode));
60+
osprintln!("VGA set to mode {}", mode.as_u8());
61+
}
5362
_ => {
54-
osprintln!("Give on or off as argument");
63+
osprintln!("Give integer or off as argument");
5564
}
5665
},
5766
"serial" => match (args.get(1).cloned(), args.get(1).map(|s| s.parse::<u32>())) {
@@ -68,7 +77,14 @@ fn command(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx:
6877
}
6978
},
7079
"print" => {
71-
osprintln!("VGA : {}", ctx.config.get_vga_console());
80+
match ctx.config.get_vga_console() {
81+
Some(m) => {
82+
osprintln!("VGA : Mode {}", m.as_u8());
83+
}
84+
None => {
85+
osprintln!("VGA : off");
86+
}
87+
};
7288
match ctx.config.get_serial_console() {
7389
None => {
7490
osprintln!("Serial: off");
@@ -83,7 +99,7 @@ fn command(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx:
8399
osprintln!("config help - print this help text");
84100
osprintln!("config reset - load config from BIOS store");
85101
osprintln!("config save - save config to BIOS store");
86-
osprintln!("config vga on - turn VGA on");
102+
osprintln!("config vga <n> - enable VGA in Mode <n>");
87103
osprintln!("config vga off - turn VGA off");
88104
osprintln!("config serial off - turn serial console off");
89105
osprintln!("config serial <baud> - turn serial console on with given baud rate");

src/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
88
/// Represents our configuration information that we ask the BIOS to serialise
99
#[derive(Debug, Serialize, Deserialize)]
1010
pub struct Config {
11-
vga_console: bool,
11+
vga_console: Option<u8>,
1212
serial_console: bool,
1313
serial_baud: u32,
1414
}
@@ -39,13 +39,13 @@ impl Config {
3939
}
4040

4141
/// Should this system use the VGA console?
42-
pub fn get_vga_console(&self) -> bool {
43-
self.vga_console
42+
pub fn get_vga_console(&self) -> Option<bios::video::Mode> {
43+
self.vga_console.and_then(bios::video::Mode::try_from_u8)
4444
}
4545

4646
// Set whether this system should use the VGA console.
47-
pub fn set_vga_console(&mut self, new_value: bool) {
48-
self.vga_console = new_value;
47+
pub fn set_vga_console(&mut self, new_value: Option<bios::video::Mode>) {
48+
self.vga_console = new_value.map(|m| m.as_u8());
4949
}
5050

5151
/// Should this system use the UART console?
@@ -82,7 +82,7 @@ impl Config {
8282
impl core::default::Default for Config {
8383
fn default() -> Config {
8484
Config {
85-
vga_console: true,
85+
vga_console: Some(0),
8686
serial_console: false,
8787
serial_baud: 115200,
8888
}

src/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,20 +376,19 @@ pub extern "C" fn os_main(api: &bios::Api) -> ! {
376376
}
377377

378378
let api = API.get();
379-
if (api.api_version_get)() != neotron_common_bios::API_VERSION {
379+
if (api.api_version_get)() != bios::API_VERSION {
380380
panic!("API mismatch!");
381381
}
382382

383383
let config = config::Config::load().unwrap_or_default();
384384

385-
if config.get_vga_console() {
386-
// Try and set 80x30 mode for maximum compatibility
387-
(api.video_set_mode)(bios::video::Mode::new(
388-
bios::video::Timing::T640x480,
389-
bios::video::Format::Text8x16,
390-
));
385+
if let Some(mut mode) = config.get_vga_console() {
386+
// Set the configured mode
387+
if let bios::FfiResult::Err(_e) = (api.video_set_mode)(mode) {
388+
// Failed to change mode - check what mode we're in
389+
mode = (api.video_get_mode)();
390+
};
391391
// Work with whatever we get
392-
let mode = (api.video_get_mode)();
393392
let (width, height) = (mode.text_width(), mode.text_height());
394393

395394
if let (Some(width), Some(height)) = (width, height) {

0 commit comments

Comments
 (0)