summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorabial <abial@FreeBSD.org>1998-12-22 12:15:45 +0000
committerabial <abial@FreeBSD.org>1998-12-22 12:15:45 +0000
commit91bd0e66beb40a53efaf61eaad295aaf08f1384f (patch)
tree9987057310d8e7e856204299caf8e7b682674625
parentc1e3c82572f880584c99fbe75082f7db2c3c7279 (diff)
downloadFreeBSD-src-91bd0e66beb40a53efaf61eaad295aaf08f1384f.zip
FreeBSD-src-91bd0e66beb40a53efaf61eaad295aaf08f1384f.tar.gz
Add examples how to use the terminal emulation code in /boot/loader to
create nice startup menus. Improvements are warmly welcome. :-)
-rw-r--r--share/examples/bootforth/README22
-rw-r--r--share/examples/bootforth/boot.4th22
-rw-r--r--share/examples/bootforth/frames.4th90
-rw-r--r--share/examples/bootforth/menu.4th74
-rw-r--r--share/examples/bootforth/screen.4th36
5 files changed, 244 insertions, 0 deletions
diff --git a/share/examples/bootforth/README b/share/examples/bootforth/README
new file mode 100644
index 0000000..d86251b
--- /dev/null
+++ b/share/examples/bootforth/README
@@ -0,0 +1,22 @@
+Here you can find some simple examples how to use BootFORTH (part of the
+new bootloader) together with terminal emulation code (available when
+compiling /sys/boot/i386/libi386 with -DTERM_EMU).
+
+Normally, you can place the files in /boot as they are here, and they will be
+automatically loaded by /boot/loader.
+
+The files are:
+
+boot.4th example of file which is always loaded by /boot/loader, if
+ present in /boot/
+screen.4th helpful words for screen manipulation.
+frames.4th basic frame drawing primitives. Requires screen.4th.
+menu.4th example of simple startup menu.
+
+You're encouraged to add more features to these files - I'm not a Forth
+hacker, unfortunately...
+
+Andrzej Bialecki
+<abial@freebsd.org>
+
+$Id$
diff --git a/share/examples/bootforth/boot.4th b/share/examples/bootforth/boot.4th
new file mode 100644
index 0000000..467e968
--- /dev/null
+++ b/share/examples/bootforth/boot.4th
@@ -0,0 +1,22 @@
+\ Example of the file which is automatically loaded by /boot/loader
+\ on startup.
+\ $Id$
+
+\ Load the screen manipulation words
+
+cr .( Loading Forth extensions:)
+
+cr .( - screen.4th...)
+s" /boot/screen.4th" fopen dup fload fclose
+
+\ Load frame support
+cr .( - frames.4th...)
+s" /boot/frames.4th" fopen dup fload fclose
+
+\ Load our little menu
+cr .( - menu.4th...)
+s" /boot/menu.4th" fopen dup fload fclose
+
+\ Show it
+cr
+main_menu
diff --git a/share/examples/bootforth/frames.4th b/share/examples/bootforth/frames.4th
new file mode 100644
index 0000000..9895a74
--- /dev/null
+++ b/share/examples/bootforth/frames.4th
@@ -0,0 +1,90 @@
+\ Words implementing frame drawing
+\ XXX Filled boxes are left as an exercise for the reader... ;-/
+\ $Id$
+
+marker task-frames.4th
+
+variable h_el
+variable v_el
+variable lt_el
+variable lb_el
+variable rt_el
+variable rb_el
+variable fill
+
+\ Single frames
+196 constant sh_el
+179 constant sv_el
+218 constant slt_el
+192 constant slb_el
+191 constant srt_el
+217 constant srb_el
+\ Double frames
+205 constant dh_el
+186 constant dv_el
+201 constant dlt_el
+200 constant dlb_el
+187 constant drt_el
+188 constant drb_el
+\ Fillings
+0 constant fill_none
+32 constant fill_blank
+176 constant fill_dark
+177 constant fill_med
+178 constant fill_bright
+
+
+: hline ( len x y -- ) \ Draw horizontal single line
+ at-xy \ move cursor
+ 0 do
+ h_el @ emit
+ loop
+;
+
+: f_single ( -- ) \ set frames to single
+ sh_el h_el !
+ sv_el v_el !
+ slt_el lt_el !
+ slb_el lb_el !
+ srt_el rt_el !
+ srb_el rb_el !
+;
+
+: f_double ( -- ) \ set frames to double
+ dh_el h_el !
+ dv_el v_el !
+ dlt_el lt_el !
+ dlb_el lb_el !
+ drt_el rt_el !
+ drb_el rb_el !
+;
+
+: vline ( len x y -- ) \ Draw vertical single line
+ 2dup 4 pick
+ 0 do
+ at-xy
+ v_el @ emit
+ 1+
+ 2dup
+ loop
+ 2drop 2drop drop
+;
+
+: box ( w h x y -- ) \ Draw a box
+ 2dup 1+ 4 pick 1- -rot
+ vline \ Draw left vert line
+ 2dup 1+ swap 5 pick + swap 4 pick 1- -rot
+ vline \ Draw right vert line
+ 2dup swap 1+ swap 5 pick 1- -rot
+ hline \ Draw top horiz line
+ 2dup swap 1+ swap 4 pick + 5 pick 1- -rot
+ hline \ Draw bottom horiz line
+ 2dup at-xy lt_el @ emit \ Draw left-top corner
+ 2dup 4 pick + at-xy lb_el @ emit \ Draw left bottom corner
+ 2dup swap 5 pick + swap at-xy rt_el @ emit \ Draw right top corner
+ 2 pick + swap 3 pick + swap at-xy rb_el @ emit
+ 2drop
+;
+
+f_single
+fill_none fill !
diff --git a/share/examples/bootforth/menu.4th b/share/examples/bootforth/menu.4th
new file mode 100644
index 0000000..ad98029
--- /dev/null
+++ b/share/examples/bootforth/menu.4th
@@ -0,0 +1,74 @@
+\ Simple greeting screen, presenting basic options.
+\ XXX This is far too trivial - I don't have time now to think
+\ XXX about something more fancy... :-/
+\ $Id$
+
+: title
+ f_single
+ 60 11 10 4 box
+ 29 4 at-xy 15 fg 7 bg
+ ." Welcome to BootFORTH!"
+ me
+;
+
+: menu
+ 2 fg
+ 20 7 at-xy
+ ." 1. Start FreeBSD /kernel."
+ 20 8 at-xy
+ ." 2. Interact with BootFORTH."
+ 20 9 at-xy
+ ." 3. Reboot."
+ me
+;
+
+: prompt
+ 14 fg
+ 20 11 at-xy
+ ." Enter your option (1,2,3): "
+ key
+ dup emit
+ me
+;
+
+: help_text
+ 10 18 at-xy ." * Choose 1 if you just want to run FreeBSD."
+ 10 19 at-xy ." * Choose 2 if you want to use bootloader facilities."
+ 12 20 at-xy ." See '?' for available commands, and 'words' for"
+ 12 21 at-xy ." complete list of Forth words."
+ 10 22 at-xy ." * Choose 3 in order to warm boot your machine."
+;
+
+: main_menu
+ begin 1 while
+ clear
+ f_double
+ 79 23 1 1 box
+ title
+ menu
+ help_text
+ prompt
+ cr cr cr
+ dup 49 = if
+ drop
+ 1 25 at-xy cr
+ ." Loading kernel. Please wait..." cr
+ boot
+ then
+ dup 50 = if
+ drop
+ 1 25 at-xy cr
+ exit
+ then
+ dup 51 = if
+ drop
+ 1 25 at-xy cr
+ reboot
+ then
+ 20 12 at-xy
+ ." Key " emit ." is not a valid option!"
+ 20 13 at-xy
+ ." Press any key to continue..."
+ key drop
+ repeat
+;
diff --git a/share/examples/bootforth/screen.4th b/share/examples/bootforth/screen.4th
new file mode 100644
index 0000000..4b0a01e
--- /dev/null
+++ b/share/examples/bootforth/screen.4th
@@ -0,0 +1,36 @@
+\ Screen manipulation related words.
+\ $Id$
+
+marker task-screen.4th
+
+: escc ( -- ) \ emit Esc-[
+ 91 27 emit emit
+;
+
+: ho ( -- ) \ Home cursor
+ escc 72 emit \ Esc-[H
+;
+
+: cld ( -- ) \ Clear from current position to end of display
+ escc 74 emit \ Esc-[J
+;
+
+: clear ( -- ) \ clear screen
+ ho cld
+;
+
+: at-xy ( x y -- ) \ move cursor to x rows, y cols (1-based coords)
+ escc .# 59 emit .# 72 emit \ Esc-[%d;%dH
+;
+
+: fg ( x -- ) \ Set foreground color
+ escc 3 .# .# 109 emit \ Esc-[3%dm
+;
+
+: bg ( x -- ) \ Set background color
+ escc 4 .# .# 109 emit \ Esc-[4%dm
+;
+
+: me ( -- ) \ Mode end (clear attributes)
+ escc 109 emit
+;
OpenPOWER on IntegriCloud