summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTerminalCursor <tcurse@terminalcursor.xyz>2022-06-29 21:14:02 -0700
committerTerminalCursor <tcurse@terminalcursor.xyz>2022-06-29 21:14:02 -0700
commit27d323f7ce88b238b5dc94f350832b081e7ca6ff (patch)
tree0b9ef10eca68ce97a21565bdf3e1b2df345e25cf /src
Initial commit
Diffstat (limited to 'src')
-rw-r--r--src/gfx.rs54
-rw-r--r--src/main.rs33
2 files changed, 87 insertions, 0 deletions
diff --git a/src/gfx.rs b/src/gfx.rs
new file mode 100644
index 0000000..fda870c
--- /dev/null
+++ b/src/gfx.rs
@@ -0,0 +1,54 @@
+use uefi::prelude::*;
+use uefi::proto::console::gop::*;
+
+pub struct GOP<'boot>(&'boot mut GraphicsOutput<'boot>);
+
+impl<'boot> GOP<'boot> {
+ pub fn new(st: &SystemTable<Boot>) -> Result<GOP<'boot>, uefi::Error> {
+ let res = st.boot_services().locate_protocol::<GraphicsOutput>();
+ match res {
+ Ok(protocol) => {
+ return Ok(unsafe { GOP(&mut *protocol.get()) })
+ },
+ Err(e) => {return Err(e)}
+ }
+ }
+
+ pub fn get_modes(&'boot self) -> impl ExactSizeIterator<Item = Mode> + 'boot {
+ self.0.modes()
+ }
+
+ pub fn set_mode(&mut self, mode: &Mode) -> Result<(), uefi::Error> {
+ self.0.set_mode(mode)
+ }
+
+ pub fn set_highest_resolution(&mut self) -> Result<(), uefi::Error> {
+ let mut last_mode;
+ let res = self.0.query_mode(0);
+ match res {
+ Ok(mode) => {last_mode = mode;},
+ Err(e) => {return Err(e)}
+ }
+ for mode in self.0.modes() {
+ last_mode = mode;
+ }
+ self.0.set_mode(&last_mode)
+ }
+
+ pub fn get_resolution(&self) -> (usize, usize) {
+ self.0.current_mode_info().resolution()
+ }
+
+ pub fn fill_box(&mut self,
+ x: usize, y: usize,
+ dx: usize, dy: usize,
+ r: u8, g: u8, b: u8)
+ -> Result<(), uefi::Error> {
+ let blt_op = BltOp::VideoFill {
+ color: BltPixel::new(r, g, b),
+ dest: (x, y),
+ dims: (dx, dy)
+ };
+ self.0.blt(blt_op)
+ }
+}
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..da78328
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,33 @@
+#![no_main]
+#![no_std]
+#![feature(abi_efiapi)]
+
+mod gfx;
+use crate::gfx::*;
+
+use uefi::prelude::*;
+use core::fmt::Write;
+
+#[entry]
+fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
+ uefi_services::init(&mut system_table).unwrap();
+
+ system_table.stdout().clear().unwrap();
+ writeln!(system_table.stdout(), "Clearing the screen!").unwrap();
+
+ let mut gop = GOP::new(&system_table).unwrap();
+ gop.set_highest_resolution().unwrap();
+ writeln!(system_table.stdout(), "Set max resolution!").unwrap();
+
+ let gop = GOP::new(&system_table).unwrap();
+ let (dx, dy) = gop.get_resolution();
+ writeln!(system_table.stdout(), "Resolution: {}x{}", dx, dy).unwrap();
+
+ let mut gop = GOP::new(&system_table).unwrap();
+ gop.fill_box(0, 0, 16, 16, 128, 0, 0).unwrap();
+
+ #[cfg(not(debug_assertions))]
+ loop {}
+ #[allow(unreachable_code)]
+ Status::SUCCESS
+}