duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 7ab521ddf5dcd20e904644954e7cf37f5cc4aa6f
parent 4e89006de870a1694a9526aecb3eadd565854ea1
Author: Michael Schierl <schierlm@gmx.de>
Date:   Wed, 26 Apr 2023 00:12:34 +0200

drv/fbgrid: Add framebuffer grid driver

While slower than native grid drivers, this can be used wherever a
screen driver is available, and may show more text than the native
console.

The included 7x7 font has been taken from Collapse OS.

To use, load fbgrid.fs and run "fbgrid$". This will activate the
graphics screen and redirect stdio to the framebuffer grid.

Diffstat:
Afs/drv/fbgrid/7x7.fnt | 48++++++++++++++++++++++++++++++++++++++++++++++++
Afs/drv/fbgrid/fbgrid.fs | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 133 insertions(+), 0 deletions(-)

diff --git a/fs/drv/fbgrid/7x7.fnt b/fs/drv/fbgrid/7x7.fnt @@ -0,0 +1,48 @@ + ....... ..##... .##.##. .##.##. ...##.. ##..... .###... ...##.. ...##.. .##.... ....... ....... ....... ....... ....... ....... + ....... ..##... .##.##. .##.##. .###### ##..##. ##.##.. ..##... ..##... ..##... ..##... ..##... ....... ....... ....... ....##. + ....... ..##... .##.##. ####### ##.#... ...##.. ##.##.. .##.... .##.... ...##.. ######. ..##... ....... ....... ....... ...##.. + ....... ..##... ....... .##.##. .#####. ..##... .###... ....... .##.... ...##.. .####.. ######. ....... ######. ....... ..##... + ....... ..##... ....... ####### ...#.## .##.... ##.##.# ....... .##.... ...##.. ######. ..##... ....... ....... ....... .##.... + ....... ....... ....... .##.##. ######. ##..##. ##..##. ....... ..##... ..##... ..##... ..##... ..##... ....... ..##... ##..... + ....... ..##... ....... .##.##. ..##... ....##. .###.## ....... ...##.. .##.... ....... ....... .##.... ....... ..##... ....... + + .####.. ..##... .####.. .####.. ...##.. ######. ..###.. ######. .####.. .####.. ....... ....... ...##.. ....... ##..... .####.. + ##..##. .###... ##..##. ##..##. ..###.. ##..... .##.... ....##. ##..##. ##..##. ....... ....... ..##... ....... .##.... ##..##. + ##.###. ..##... ....##. ....##. .####.. #####.. ##..... ...##.. ##..##. ##..##. ..##... ..##... .##.... ######. ..##... ...##.. + ######. ..##... ...##.. ..###.. ##.##.. ....##. #####.. ..##... .####.. .#####. ..##... ..##... ##..... ....... ...##.. ..##... + ###.##. ..##... ..##... ....##. ######. ....##. ##..##. .##.... ##..##. ....##. ....... ....... .##.... ######. ..##... ..##... + ##..##. ..##... .##.... ##..##. ...##.. ##..##. ##..##. .##.... ##..##. ...##.. ..##... ..##... ..##... ....... .##.... ....... + .####.. ######. ######. .####.. ...##.. .####.. .####.. .##.... .####.. .###... ..##... .##.... ...##.. ....... ##..... ..##... + + .####.. .####.. #####.. .####.. ####... ######. ######. .####.. ##..##. ######. .#####. ##..##. ##..... ##...## ##..##. .####.. + ##..##. ##..##. ##..##. ##..##. ##.##.. ##..... ##..... ##..##. ##..##. ..##... ...##.. ##.##.. ##..... ###.### ##..##. ##..##. + ##.###. ##..##. ##..##. ##..... ##..##. ##..... ##..... ##..... ##..##. ..##... ...##.. ####... ##..... ####### ###.##. ##..##. + ##.#.#. ######. #####.. ##..... ##..##. #####.. #####.. ##.###. ######. ..##... ...##.. ###.... ##..... ##.#.## ######. ##..##. + ##.###. ##..##. ##..##. ##..... ##..##. ##..... ##..... ##..##. ##..##. ..##... ...##.. ####... ##..... ##.#.## ##.###. ##..##. + ##..... ##..##. ##..##. ##..##. ##.##.. ##..... ##..... ##..##. ##..##. ..##... ##.##.. ##.##.. ##..... ##...## ##..##. ##..##. + .####.. ##..##. #####.. .####.. ####... ######. ##..... .####.. ##..##. ######. .###... ##..##. ######. ##...## ##..##. .####.. + + #####.. .####.. #####.. .####.. ######. ##..##. ##..##. ##...## ##..##. ##..##. ######. #####.. ....... #####.. ..##... ....... + ##..##. ##..##. ##..##. ##..##. ..##... ##..##. ##..##. ##...## ##..##. ##..##. ....##. ##..... ##..... ...##.. .####.. ....... + ##..##. ##..##. ##..##. ##..... ..##... ##..##. ##..##. ##.#.## .####.. ##..##. ...##.. ##..... .##.... ...##.. ##..##. ....... + #####.. ##..##. #####.. .####.. ..##... ##..##. ##..##. ##.#.## ..##... .####.. ..##... ##..... ..##... ...##.. #....#. ....... + ##..... ##.#.#. ##.##.. ....##. ..##... ##..##. ##..##. ####### .####.. ..##... .##.... ##..... ...##.. ...##.. ....... ....... + ##..... ##.##.. ##..##. ##..##. ..##... ##..##. .####.. ###.### ##..##. ..##... ##..... ##..... ....##. ...##.. ....... ....... + ##..... .##.##. ##..##. .####.. ..##... .####.. ..##... ##...## ##..##. ..##... ######. #####.. ....... #####.. ....... ####### + + .##.... ....... ##..... ....... ....##. ....... ..###.. ....... ##..... ..##... ..##... ##..... .###... ....... ....... ....... + ..##... ....... ##..... ....... ....##. ....... .##.... .####.. ##..... ....... ....... ##..... ..##... ....... ....... ....... + ...##.. .####.. #####.. .####.. .#####. .####.. .##.... ##..##. #####.. .###... .###... ##..##. ..##... .##.##. #####.. .####.. + ....... ....##. ##..##. ##..##. ##..##. ##..##. #####.. ##..##. ##..##. ..##... ..##... ##.##.. ..##... ####### ##..##. ##..##. + ....... .#####. ##..##. ##..... ##..##. ######. .##.... .#####. ##..##. ..##... ..##... ####... ..##... ##.#.## ##..##. ##..##. + ....... ##..##. ##..##. ##..##. ##..##. ##..... .##.... ....##. ##..##. ..##... ..##... ##.##.. ..##... ##.#.## ##..##. ##..##. + ....... .#####. #####.. .####.. .#####. .####.. .##.... .###... ##..##. .####.. ##..... ##..##. .####.. ##...## ##..##. .####.. + + ....... ....... ....... ....... .##.... ....... ....... ....... ....... ....... ....... ...##.. ..##... ##..... .##...# ....... + ....... ....... ....... ....... .##.... ....... ....... ....... ....... ....... ....... ..##... ..##... .##.... ##.#.## ....... + #####.. .#####. ##.##.. .#####. #####.. ##..##. ##..##. ##...## ##..##. ##..##. ######. ..##... ..##... .##.... #...##. ....... + ##..##. ##..##. ###.##. ##..... .##.... ##..##. ##..##. ##.#.## .####.. ##..##. ...##.. ###.... ..##... ..###.. ....... ....... + ##..##. ##..##. ##..... .####.. .##.... ##..##. ##..##. ##.#.## ..##... ##..##. ..##... ..##... ..##... .##.... ....... ....... + #####.. .#####. ##..... ....##. .##.... ##..##. .####.. ####### .####.. .#####. .##.... ..##... ..##... .##.... ....... ....... + ##..... ....##. ##..... #####.. ..###.. .#####. ..##... .##.##. ##..##. ....##. ######. ...##.. ..##... ##..... ....... ....... + diff --git a/fs/drv/fbgrid/fbgrid.fs b/fs/drv/fbgrid/fbgrid.fs @@ -0,0 +1,85 @@ +\ Grid video driver for screen framebuffer +require /sys/screen.fs + +?f<< /sys/grid.fs +?f<< /sys/file.fs +?f<< /gr/plane.fs + +7 96 7 * COLOR_RGB565 Plane :new structbind Plane _font +_font :allotbuf +0 structbind Plane _scrollbuf +0 value _cpos + +: _ + 8 syspad :allot >r \ V1 = font buffer + 0 >r \ V2 = font row count + 0 >r \ V3 = font line count + 0 >r \ V4 = letter count + begin V2 6 < while 0 to V3 \ parse font row + begin V3 7 < while 0 to V4 \ parse font line + begin V4 16 < while \ parse font line glyph part + file :getc 32 <> if abort" space missing in font file" then + 0 V2 16 * V4 + 7 * V3 + _font :pos! + V1 7 file :read + 7 for \ parse character + V1 7 i - + c@ '#' = if $ffff else 0 then to _font color + _font :pixel! 1 _font :tx+ + next + 1 to+ V4 + repeat \ end parse font line glyph part + file :getc 10 <> if abort" newline missing in font file" then + 1 to+ V3 + repeat + file :getc 10 <> if abort" newline missing in font file" then + 1 to+ V2 + repeat + rdrop rdrop rdrop rdrop file$ ; + +f" /drv/fbgrid/7x7.fnt" _ + +extends Grid struct[ FbGrid + : cell! ( c pos -- ) + grid COLS /mod 3 lshift swap 3 lshift swap screen :pos! + 0 swap 32 - 7 * 7 7 Rect :tmpnew _font :self screen :copy< ; + : _cursorstate ( on -- ) + _cpos grid COLS /mod 3 lshift 7 + swap 3 lshift swap screen :pos! + if 255 255 0 >rgb565 else 0 then to screen color 8 1 screen :fill ; + : cursor! ( pos -- ) _cpos if 0 _cursorstate then to _cpos 1 _cursorstate ; + : scroll ( -- ) + 0 >r \ V1 = line + 0 0 screen width 8 Rect :tmpnew >r \ V2 = rect + begin V1 grid LINES < while + 0 V1 3 lshift 8 + screen :pos! V2 _scrollbuf :self screen :copy> + 0 V1 3 lshift screen :pos! V2 _scrollbuf :self screen :copy< + 1 to+ V1 + repeat rdrop rdrop + _cpos if _cpos grid COLS - to _cpos then ; + : newln ( oldln -- newln ) dup grid LINES 1- = if scroll else 1+ then + dup 3 lshift 0 swap screen :pos! 0 to screen color screen width 8 screen :fill ; + : highlight ( f pos -- ) + grid COLS /mod 3 lshift swap 3 lshift swap screen :xyoff + screen buffer + >r \ V1 = rowaddr + >r \ V2 = f + 0 >r \ V3 = y + begin V3 8 < while + 8 for + V1 i 1- << + dup w@ ( addr value ) + dup 0 = V2 and if drop $7bef then + dup $7bef = V2 not and if drop 0 then + swap w! + next + screen width << to+ V1 + 1 to+ V3 + repeat rdrop rdrop rdrop ; + : :new ( -- grid ) + screen width 8 / screen height 8 / Grid :new + ['] cell! over ['] :cell! sfield! + ['] cursor! over ['] :cursor! sfield! + ['] newln over ['] :newln sfield! + ['] highlight over ['] :highlight sfield! ; +]struct + +: fbgrid$ screen :activate FbGrid :new ['] grid rebind + screen width 8 COLOR_RGB565 Plane :new ['] _scrollbuf rebind + _scrollbuf :allotbuf + grid :self dup to console writeio to stdio writeio ;