summaryrefslogtreecommitdiffstats
path: root/rsnix/src/gop.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--rsnix/src/gop.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/rsnix/src/gop.rs b/rsnix/src/gop.rs
index 77cc514..0d24d7d 100644
--- a/rsnix/src/gop.rs
+++ b/rsnix/src/gop.rs
@@ -105,23 +105,25 @@ pub fn clear_screen() {
105 crate::vt::clear_all(); 105 crate::vt::clear_all();
106} 106}
107 107
108/// Raw-pointer accessor for the framebuffer static (single-threaded
109/// kernel; keeps `static_mut_refs` quiet).
110fn fb() -> &'static mut Option<Framebuffer> {
111 unsafe { &mut *core::ptr::addr_of_mut!(FB) }
112}
113
108/// (cols, rows) of the text surface, from the current framebuffer mode. 114/// (cols, rows) of the text surface, from the current framebuffer mode.
109pub fn dims() -> (usize, usize) { 115pub fn dims() -> (usize, usize) {
110 unsafe { 116 match fb().as_ref() {
111 match FB.as_ref() { 117 Some(f) => (f.width / 8, f.height / 16),
112 Some(f) => (f.width / 8, f.height / 16), 118 None => (0, 0),
113 None => (0, 0),
114 }
115 } 119 }
116} 120}
117 121
118/// Pack an (r, g, b) colour for the framebuffer's pixel format. 122/// Pack an (r, g, b) colour for the framebuffer's pixel format.
119pub fn rgb(r: u8, g: u8, b: u8) -> u32 { 123pub fn rgb(r: u8, g: u8, b: u8) -> u32 {
120 unsafe { 124 match fb().as_ref() {
121 match FB.as_ref() { 125 Some(f) if f.bgr => ((r as u32) << 16) | ((g as u32) << 8) | b as u32,
122 Some(f) if f.bgr => ((r as u32) << 16) | ((g as u32) << 8) | b as u32, 126 _ => ((b as u32) << 16) | ((g as u32) << 8) | r as u32,
123 _ => ((b as u32) << 16) | ((g as u32) << 8) | r as u32,
124 }
125 } 127 }
126} 128}
127 129
@@ -340,7 +342,7 @@ fn unicode_glyph_bits(ch: u16) -> Option<[u8; 16]> {
340} 342}
341 343
342pub(crate) fn blit_glyph(col: usize, row: usize, ch: u16, fg: (u8, u8, u8), bg: (u8, u8, u8)) { 344pub(crate) fn blit_glyph(col: usize, row: usize, ch: u16, fg: (u8, u8, u8), bg: (u8, u8, u8)) {
343 if let Some(fb) = unsafe { FB.as_ref() } { 345 if let Some(fb) = fb().as_ref() {
344 let glyph = font::GLYPH_8X16; 346 let glyph = font::GLYPH_8X16;
345 let data = if ch < 256 { 347 let data = if ch < 256 {
346 match glyph.get(ch as usize) { 348 match glyph.get(ch as usize) {
@@ -381,7 +383,7 @@ pub(crate) fn blit_glyph(col: usize, row: usize, ch: u16, fg: (u8, u8, u8), bg:
381/// Shift the framebuffer content up `n` text rows and clear the exposed 383/// Shift the framebuffer content up `n` text rows and clear the exposed
382/// bottom rows. `n` batches deferred scrolls into one push. 384/// bottom rows. `n` batches deferred scrolls into one push.
383pub(crate) fn shift_up_n(n: usize) { 385pub(crate) fn shift_up_n(n: usize) {
384 if let Some(fb) = unsafe { FB.as_ref() } { 386 if let Some(fb) = fb().as_ref() {
385 fb.shift_up_n(n); 387 fb.shift_up_n(n);
386 } 388 }
387} 389}