Skip to content

Commit

Permalink
Refactor vga driver (#688)
Browse files Browse the repository at this point in the history
* Add blank command

* Move vga driver to module

* Remove vga command

* Split vga module

* Rename vga device type

* Add /dev/vga/mode device file

* Restore font after mode change

* Remove cvs support for palette

* Refactor api::vga::color

* Move api::vga::color to sys::vga::color

* Move api::vga::palette to sys::vga::palette

* Use 256 colors palette

* Refactor Color

* Rename Color#to_vga_reg to Color#register

* Add Palette#set

* Add write-only /dev/vga/palette

* Remove unused set_palette

* Add read operation to /dev/vga/palette

* Add palette backup and restore

* Check for device presence

* Backup palette only in 80x25 mode

* Clear screen on mode change

* Make /dev/vga/mode readable

* Fix double buffer allocation

* Add framebuffer:addr()

* Add /dev/vga/buffer device

* Reorder device files

* Rename some functions

* Move test

* Run clippy

* Add color test

* Refactor code

* Move blank to userspace
  • Loading branch information
vinc authored Oct 16, 2024
1 parent 9259d22 commit bac1e92
Show file tree
Hide file tree
Showing 23 changed files with 936 additions and 769 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ user-rust:
basename -s .rs src/bin/*.rs | xargs -I {} \
cargo rustc $(user-cargo-opts) --bin {}
cargo rustc $(user-cargo-opts) --bin exec -- $(linker-opts)
cargo rustc $(user-cargo-opts) --bin blank -- $(linker-opts)
cargo rustc $(user-cargo-opts) --bin hello -- $(linker-opts)
cargo rustc $(user-cargo-opts) --bin geocal -- $(linker-opts)
cargo rustc $(user-cargo-opts) --bin geodate -- $(linker-opts)
Expand Down
17 changes: 0 additions & 17 deletions dsk/ini/palettes/gruvbox-dark.csv

This file was deleted.

17 changes: 0 additions & 17 deletions dsk/ini/palettes/gruvbox-light.csv

This file was deleted.

1 change: 1 addition & 0 deletions dsk/var/pkg/blank
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/blank
1 change: 1 addition & 0 deletions dsk/var/pkg/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
beep
blank
chess
exec
fonts
Expand Down
28 changes: 16 additions & 12 deletions src/api/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,24 @@ fn device_buffer(name: &str) -> Result<Vec<u8>, ()> {
Ok(buf)
}

// TODO: Move this to sys::fs::device
fn device_type(name: &str) -> Result<DeviceType, ()> {
match name {
"null" => Ok(DeviceType::Null),
"file" => Ok(DeviceType::File),
"console" => Ok(DeviceType::Console),
"random" => Ok(DeviceType::Random),
"uptime" => Ok(DeviceType::Uptime),
"realtime" => Ok(DeviceType::Realtime),
"rtc" => Ok(DeviceType::RTC),
"tcp" => Ok(DeviceType::TcpSocket),
"udp" => Ok(DeviceType::UdpSocket),
"font" => Ok(DeviceType::VgaFont),
"ata" => Ok(DeviceType::Drive),
_ => Err(()),
"null" => Ok(DeviceType::Null),
"file" => Ok(DeviceType::File),
"console" => Ok(DeviceType::Console),
"random" => Ok(DeviceType::Random),
"uptime" => Ok(DeviceType::Uptime),
"realtime" => Ok(DeviceType::Realtime),
"rtc" => Ok(DeviceType::RTC),
"tcp" => Ok(DeviceType::TcpSocket),
"udp" => Ok(DeviceType::UdpSocket),
"vga-buffer" => Ok(DeviceType::VgaBuffer),
"vga-font" => Ok(DeviceType::VgaFont),
"vga-mode" => Ok(DeviceType::VgaMode),
"vga-palette" => Ok(DeviceType::VgaPalette),
"ata" => Ok(DeviceType::Drive),
_ => Err(()),
}
}

Expand Down
95 changes: 0 additions & 95 deletions src/api/vga/color.rs

This file was deleted.

19 changes: 15 additions & 4 deletions src/api/vga/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
pub mod color;
pub mod palette;
use crate::api::fs;

pub use color::Color;
pub use palette::Palette;
pub fn graphic_mode() {
let dev = "/dev/vga/mode";
if fs::is_device(dev) {
fs::write(dev, b"320x200").ok();
}
}

pub fn text_mode() {
let dev = "/dev/vga/mode";
if fs::is_device(dev) {
fs::write(dev, b"80x25").ok();
print!("\x1b[2J\x1b[1;1H"); // Clear screen and move to top
}
}
65 changes: 0 additions & 65 deletions src/api/vga/palette.rs

This file was deleted.

20 changes: 20 additions & 0 deletions src/bin/blank.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![no_std]
#![no_main]

extern crate alloc;

use moros::print;
use moros::api::io;
use moros::api::vga;
use moros::entry_point;

entry_point!(main);

fn main(_args: &[&str]) {
vga::graphic_mode();
print!("\x1b]R\x1b[1A"); // Reset palette
while io::stdin().read_char().is_none() {
x86_64::instructions::hlt();
}
vga::text_mode();
}
Loading

0 comments on commit bac1e92

Please sign in to comment.