diff options
Diffstat (limited to 'share/examples/bootforth')
-rw-r--r-- | share/examples/bootforth/README | 35 | ||||
-rw-r--r-- | share/examples/bootforth/boot.4th | 22 | ||||
-rw-r--r-- | share/examples/bootforth/frames.4th | 112 | ||||
-rw-r--r-- | share/examples/bootforth/loader.rc | 34 | ||||
-rw-r--r-- | share/examples/bootforth/menu.4th | 99 | ||||
-rw-r--r-- | share/examples/bootforth/menuconf.4th | 110 | ||||
-rw-r--r-- | share/examples/bootforth/screen.4th | 36 |
7 files changed, 448 insertions, 0 deletions
diff --git a/share/examples/bootforth/README b/share/examples/bootforth/README new file mode 100644 index 0000000..b8eb8a0 --- /dev/null +++ b/share/examples/bootforth/README @@ -0,0 +1,35 @@ +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. You must choose between boot.4th or +loader.rc, though. Copy one or the other, but not both. Also, menu.4th is +only used by boot.4th, and menuconf.4th is only used by loader.rc, so you +don't need to copy both files. + +The files are: + +boot.4th example of file which is always loaded by /boot/loader, if + present in /boot/ +loader.rc example of file which is always loader 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. +menuconf.4th another example of simples startup menu. + +You're encouraged to add more features to these files - I'm not a Forth +hacker, unfortunately... + +Andrzej Bialecki +<abial@freebsd.org> + +If you use loader.rc/menuconf.4th, be sure to create /boot/stable.conf and +/boot/current.conf, like described in loader.conf(5), with appropriate +configuration to distinguish one from the other. + +Daniel C. Sobral +<dcs@freebsd.org> + +$FreeBSD$ diff --git a/share/examples/bootforth/boot.4th b/share/examples/bootforth/boot.4th new file mode 100644 index 0000000..8f26e0d --- /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. +\ $FreeBSD$ + +\ Load the screen manipulation words + +cr .( Loading Forth extensions:) + +cr .( - screen.4th...) +s" /boot/screen.4th" O_RDONLY fopen dup fload fclose + +\ Load frame support +cr .( - frames.4th...) +s" /boot/frames.4th" O_RDONLY fopen dup fload fclose + +\ Load our little menu +cr .( - menu.4th...) +s" /boot/menu.4th" O_RDONLY 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..3b1f404 --- /dev/null +++ b/share/examples/bootforth/frames.4th @@ -0,0 +1,112 @@ +\ Words implementing frame drawing +\ XXX Filled boxes are left as an exercise for the reader... ;-/ +\ $FreeBSD$ + +marker task-frames.4th + +variable h_el +variable v_el +variable lt_el +variable lb_el +variable rt_el +variable rb_el +variable fill + +s" arch-pc98" environment? [if] + \ Single frames + 149 constant sh_el + 150 constant sv_el + 152 constant slt_el + 154 constant slb_el + 153 constant srt_el + 155 constant srb_el + \ Double frames + 149 constant dh_el + 150 constant dv_el + 152 constant dlt_el + 154 constant dlb_el + 153 constant drt_el + 155 constant drb_el + \ Fillings + 0 constant fill_none + 32 constant fill_blank + 135 constant fill_dark + 135 constant fill_med + 135 constant fill_bright +[else] + \ 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 +[then] + +: 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/loader.rc b/share/examples/bootforth/loader.rc new file mode 100644 index 0000000..617bc3d --- /dev/null +++ b/share/examples/bootforth/loader.rc @@ -0,0 +1,34 @@ +\ Example of the file which is automatically loaded by /boot/loader +\ on startup. +\ $FreeBSD$ + +cr .( Loading Forth extensions:) + +\ Load configuration file words + +cr .( - loader.4th...) + +include /boot/loader.4th + +\ Load the screen manipulation words + +cr .( - screen.4th...) +s" /boot/screen.4th" O_RDONLY fopen dup fload fclose + +\ Load frame support +cr .( - frames.4th...) +s" /boot/frames.4th" O_RDONLY fopen dup fload fclose + +\ Load our little menu +cr .( - menuconf.4th...) +s" /boot/menuconf.4th" O_RDONLY fopen dup fload fclose + +\ Initialize loader.4th stuff + +cr cr .( Initializing loader.4th...) +initialize drop + +\ Show the menu +cr +main_menu + diff --git a/share/examples/bootforth/menu.4th b/share/examples/bootforth/menu.4th new file mode 100644 index 0000000..5c5c3e9 --- /dev/null +++ b/share/examples/bootforth/menu.4th @@ -0,0 +1,99 @@ +\ 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... :-/ +\ $FreeBSD$ + +: 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 +; + +: tkey ( d -- flag | char ) + seconds + + begin 1 while + dup seconds u< if + drop + -1 + exit + then + key? if + drop + key + exit + then + repeat +; + +: prompt + 14 fg + 20 11 at-xy + ." Enter your option (1,2,3): " + 10 tkey + dup 32 = if + drop key + then + dup 0< if + drop 49 + then + 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." +; + +: (boot) 0 boot ; +: (reboot) 0 reboot ; + +: 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) catch abort" Error booting" + then + dup 50 = if + drop + 1 25 at-xy cr + exit + then + dup 51 = if + drop + 1 25 at-xy cr + ['] (reboot) catch abort" Error rebooting" + 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/menuconf.4th b/share/examples/bootforth/menuconf.4th new file mode 100644 index 0000000..a769f77 --- /dev/null +++ b/share/examples/bootforth/menuconf.4th @@ -0,0 +1,110 @@ +\ 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... :-/ +\ $FreeBSD$ + +: 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 with /boot/stable.conf." + 20 8 at-xy + ." 2. Start FreeBSD with /boot/current.conf." + 20 9 at-xy + ." 3. Start FreeBSD with standard configuration. " + 20 10 at-xy + ." 4. Reboot." + me +; + +: tkey ( d -- flag | char ) + seconds + + begin 1 while + dup seconds u< if + drop + -1 + exit + then + key? if + drop + key + exit + then + repeat +; + +: prompt + 14 fg + 20 12 at-xy + ." Enter your option (1,2,3,4): " + 10 tkey + dup 32 = if + drop key + then + dup 0< if + drop 51 + then + dup emit + me +; + +: help_text + 10 18 at-xy ." * Choose 1 or 2 to run special configuration file." + 10 19 at-xy ." * Choose 3 to proceed with standard bootstrapping." + 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 4 in order to warm boot your machine." +; + +: (reboot) 0 reboot ; + +: 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 /boot/stable.conf. Please wait..." cr + s" /boot/stable.conf" read-conf + 0 boot-conf exit + then + dup 50 = if + drop + 1 25 at-xy cr + ." Loading /boot/current.conf. Please wait..." cr + s" /boot/current.conf" read-conf + 0 boot-conf exit + then + dup 51 = if + drop + 1 25 at-xy cr + ." Proceeding with standard boot. Please wait..." cr + 0 boot-conf exit + then + dup 52 = if + drop + 1 25 at-xy cr + ['] (reboot) catch abort" Error rebooting" + 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..3ea79e4 --- /dev/null +++ b/share/examples/bootforth/screen.4th @@ -0,0 +1,36 @@ +\ Screen manipulation related words. +\ $FreeBSD$ + +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 +; |