# HG changeset patch # User Andy Fiddaman # Date 1547042518 0 # Node ID 068da7e6bca0019ee7df868b96225737713848f3 # Parent 90242035d8ac74eedc2b33bafc570f0df1932aa6 10202 loader: use screen-#rows to find bottom left co-ordinates Reviewed by: Toomas Soome Reviewed by: Gergő Mihály Doma Approved by: Robert Mustacchi diff -r 90242035d8ac -r 068da7e6bca0 usr/src/boot/sys/boot/forth/check-password.4th --- a/usr/src/boot/sys/boot/forth/check-password.4th Fri Jan 04 13:56:48 2019 +0200 +++ b/usr/src/boot/sys/boot/forth/check-password.4th Wed Jan 09 14:01:58 2019 +0000 @@ -1,6 +1,7 @@ \ Copyright (c) 2006-2015 Devin Teske +\ Copyright 2019 OmniOS Community Edition (OmniOSce) Association. \ All rights reserved. -\ +\ \ Redistribution and use in source and binary forms, with or without \ modification, are permitted provided that the following conditions \ are met: @@ -9,7 +10,7 @@ \ 2. Redistributions in binary form must reproduce the above copyright \ notice, this list of conditions and the following disclaimer in the \ documentation and/or other materials provided with the distribution. -\ +\ \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -21,8 +22,6 @@ \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF \ SUCH DAMAGE. -\ -\ $FreeBSD$ marker task-check-password.4th @@ -49,7 +48,7 @@ \ this is to pass 0 as a stack parameter (ie. `0 sgetkey'). This function is \ called by the read function. You need not call it directly. NOTE: arrow keys \ show as 0 on the stack -\ +\ : sgetkey ( -- ) begin \ Loop forever @@ -68,7 +67,7 @@ dup 3 = if ( 4 ) ." |" else 1 spaces then then then then drop - read-start @ 25 at-xy + read-start @ sr at-xy exit then then @@ -94,7 +93,7 @@ : read ( c-addr/u -- ) \ Expects string prompt as stack input - 0 25 at-xy \ Move the cursor to the bottom-left + at-bl \ Move the cursor to the bottom-left dup 1+ read-start ! \ Store X offset after the prompt 0 readlen ! \ Initialize the read length type \ Print the prompt @@ -113,12 +112,12 @@ 10 emit \ Echo new line exit else dup ctrl_u = if - 3 spaces read-start @ 25 at-xy \ Erase the twiddle + 3 spaces read-start @ sr at-xy \ Erase the twiddle 0 readlen ! \ Reset input to NULL else dup bs_key = if readlen @ 1 - dup readlen ! \ Decrement input length dup 0< if drop 0 dup readlen ! then \ Don't go negative - 0= if 3 spaces read-start @ 25 at-xy then \ Twiddle + 0= if 3 spaces read-start @ sr at-xy then \ Twiddle else dup \ Store the character \ NB: sgetkey prevents overflow by way of blocking \ at readmax except for Backspace or Enter diff -r 90242035d8ac -r 068da7e6bca0 usr/src/boot/sys/boot/forth/menu.4th --- a/usr/src/boot/sys/boot/forth/menu.4th Fri Jan 04 13:56:48 2019 +0200 +++ b/usr/src/boot/sys/boot/forth/menu.4th Wed Jan 09 14:01:58 2019 +0000 @@ -1,8 +1,9 @@ \ Copyright (c) 2003 Scott Long \ Copyright (c) 2003 Aleksander Fafula \ Copyright (c) 2006-2015 Devin Teske +\ Copyright 2019 OmniOS Community Edition (OmniOSce) Association. \ All rights reserved. -\ +\ \ Redistribution and use in source and binary forms, with or without \ modification, are permitted provided that the following conditions \ are met: @@ -11,7 +12,7 @@ \ 2. Redistributions in binary form must reproduce the above copyright \ notice, this list of conditions and the following disclaimer in the \ documentation and/or other materials provided with the distribution. -\ +\ \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -23,8 +24,6 @@ \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF \ SUCH DAMAGE. -\ -\ $FreeBSD$ marker task-menu.4th @@ -204,7 +203,7 @@ \ increments the cursor position to the next row for the creation of the next \ menu item. This function is called by the menu-create function. You need not \ call it directly. -\ +\ : printmenuitem ( menu_item_str -- ascii_keycode ) loader_color? if [char] ^ escc! then @@ -256,7 +255,7 @@ \ display which kernel to boot when the [overloaded] `boot' word is interpreted. \ Used internally by menu-create, you need not (nor should you) call this \ directly. -\ +\ : parse-kernels ( N -- ) \ kernidx kernidx ! ( n -- ) \ store provided `x' value [char] 0 kernmenuidx ! \ initialize `y' value for menu_caption[x][y] @@ -393,7 +392,7 @@ \ This function goes through the kernels that were discovered by the \ parse-kernels function [above], adding " (# of #)" text to the end of each \ caption. -\ +\ : tag-kernels ( -- ) kernidx @ ( -- x ) dup 0= if exit then [char] 0 s" (Y of Z)" ( x -- x y c-addr/u ) @@ -482,7 +481,7 @@ \ This function creates the list of menu items. This function is called by the \ menu-display function. You need not call it directly. -\ +\ : menu-create ( -- ) \ Print the frame caption at (x,y) @@ -506,12 +505,12 @@ if ( use default center alignement? ) menuX @ 19 + over 2 / - menuY @ 1- then - at-xy type + at-xy type \ If $menu_init is set, evaluate it (allowing for whole menus to be \ constructed dynamically -- as this function could conceivably set \ the remaining environment variables to construct the menu entirely). - \ + \ s" menu_init" getenv dup -1 <> if evaluate else @@ -529,13 +528,13 @@ \ and the key required to activate that menu item will be the decimal \ ASCII of 48 plus the menu item (ie. 58 for the tenth item, aka. `:') \ which is misleading and not desirable. - \ + \ \ Thus, we do not allow more than 8 configurable items on the menu \ (with "Reboot" as the optional ninth and highest numbered item). - \ + \ \ Initialize the OsConsole option status. - \ + \ 0 menuosconsole ! s" menu_osconsole" getenv -1 <> if c@ dup 48 > over 57 < and if ( '1' <= c1 <= '8' ) @@ -569,9 +568,9 @@ drop then - \ + \ \ Initialize the ACPI option status. - \ + \ 0 menuacpi ! s" menu_acpi" getenv -1 <> if c@ dup 48 > over 57 < and if ( '1' <= c1 <= '8' ) @@ -605,9 +604,9 @@ drop then - \ + \ \ Initialize kernel captions after parsing $kernels - \ + \ 0 menukernel ! s" menu_kernel" getenv -1 <> if c@ dup 48 > over 57 < and if ( '1' <= c1 <= '8' ) @@ -646,9 +645,9 @@ drop then - \ + \ \ Initialize the menu_options visual separator. - \ + \ 0 menuoptions ! s" menu_options" getenv -1 <> if c@ dup 48 > over 57 < and if ( '1' <= c1 <= '8' ) @@ -742,7 +741,7 @@ \ Takes a single integer on the stack and updates the timeout display. The \ integer must be between 0 and 9 (we will only update a single digit in the \ source message). -\ +\ : menu-timeout-update ( N -- ) \ Enforce minimum/maximum @@ -763,7 +762,7 @@ 2drop ( n c-addr -- ) then - 0 25 at-xy ( position cursor back at bottom-left ) + at-bl ; \ This function blocks program flow (loops forever) until a key is pressed. @@ -772,7 +771,7 @@ \ function. You need not call it directly. \ note, the esc sequences will be dropped, this needs to be changed if \ menu is built based on arrow keys. -\ +\ : getkey ( -- ascii_keycode ) begin \ loop forever @@ -903,7 +902,7 @@ ansi_caption[x] else menu_caption[x] - then + then getenv dup -1 <> if 2 pick ( n c-addr/u -- n c-addr/u n ) @@ -1033,13 +1032,13 @@ \ At this point, we should have the following on the stack (in order, \ from bottom to top): - \ + \ \ n - Ascii numeral representing the menu choice (inherited) \ addr - address of our internal cycle_stateN variable \ k - zero-based number we intend to store to the above \ c-addr/u - string value we intend to store to menu_caption[x] \ (or ansi_caption[x] with loader_color enabled) - \ + \ \ Let's perform what we need to with the above. \ Assign array value text to menu caption @@ -1058,7 +1057,7 @@ \ Erase and redraw the menu. Useful if you change a caption and want to \ update the menu to reflect the new value. -\ +\ : menu-redraw ( -- ) menu-erase menu-create @@ -1066,7 +1065,7 @@ \ This function initializes the menu. Call this from your `loader.rc' file \ before calling any other menu-related functions. -\ +\ : menu-init ( -- ) menu_start 1- menuidx ! \ Initialize the starting index for the menu @@ -1109,13 +1108,13 @@ 42 13 menuX @ 3 - menuY @ 1- box \ Draw frame (w,h,x,y) then - 0 25 at-xy \ Move cursor to the bottom for output + at-bl ; also menu-namespace \ Main function. Call this from your `loader.rc' file. -\ +\ : menu-display ( -- ) 0 menu_timeout_enabled ! \ start with automatic timeout disabled @@ -1148,7 +1147,7 @@ dup 0< if drop menu-create - 0 25 at-xy + at-bl 0 boot then then @@ -1167,7 +1166,7 @@ then then menu_timeout_x ! ( store value on stack from above ) - + \ read custom row position (if set) s" loader_menu_timeout_y" getenv dup -1 = if drop \ no custom row position @@ -1186,7 +1185,7 @@ begin \ Loop forever - 0 25 at-xy \ Move cursor to the bottom for output + at-bl getkey \ Block here, waiting for a key to be pressed dup -1 = if @@ -1212,13 +1211,13 @@ rot tuck = if \ Adjust for missing ACPI menuitem on non-i386 -\ arch-i386? true <> menuacpi @ 0<> and if -\ menuacpi @ over 2dup < -rot = or -\ over 58 < and if -\ ( key >= menuacpi && key < 58: N -- N ) -\ 1+ -\ then -\ then +\ arch-i386? true <> menuacpi @ 0<> and if +\ menuacpi @ over 2dup < -rot = or +\ over 58 < and if +\ ( key >= menuacpi && key < 58: N -- N ) +\ 1+ +\ then +\ then \ Test for the environment variable dup menu_command[x] @@ -1253,9 +1252,9 @@ swap \ need iterator on top then - \ + \ \ Check for menu keycode shortcut(s) - \ + \ dup menu_keycode[x] getenv dup -1 = if drop @@ -1290,7 +1289,7 @@ \ This function unsets all the possible environment variables associated with \ creating the interactive menu. -\ +\ : menu-unset ( -- ) 49 \ Iterator start (loop range 49 to 56; ASCII '1' to '8') @@ -1341,7 +1340,7 @@ \ This function both unsets menu variables and visually erases the menu area \ in-preparation for another menu. -\ +\ : menu-clear ( -- ) menu-unset menu-erase diff -r 90242035d8ac -r 068da7e6bca0 usr/src/boot/sys/boot/forth/screen.4th --- a/usr/src/boot/sys/boot/forth/screen.4th Fri Jan 04 13:56:48 2019 +0200 +++ b/usr/src/boot/sys/boot/forth/screen.4th Wed Jan 09 14:01:58 2019 +0000 @@ -1,7 +1,8 @@ \ Copyright (c) 2003 Scott Long \ Copyright (c) 2015 Devin Teske +\ Copyright 2019 OmniOS Community Edition (OmniOSce) Association. \ All rights reserved. -\ +\ \ Redistribution and use in source and binary forms, with or without \ modification, are permitted provided that the following conditions \ are met: @@ -10,7 +11,7 @@ \ 2. Redistributions in binary form must reproduce the above copyright \ notice, this list of conditions and the following disclaimer in the \ documentation and/or other materials provided with the distribution. -\ +\ \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -22,8 +23,6 @@ \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF \ SUCH DAMAGE. -\ -\ $FreeBSD$ marker task-screen.4th @@ -72,3 +71,11 @@ repeat 2drop drop ; + +\ Get the number of screen rows/columns +: sr ( -- y ) 25 s" screen-#rows" getenvn ; +: sc ( -- x ) 80 s" screen-#cols" getenvn ; + +\ Place the cursor at the bottom left of the screen +: at-bl 0 sr at-xy ; + diff -r 90242035d8ac -r 068da7e6bca0 usr/src/boot/sys/boot/forth/support.4th --- a/usr/src/boot/sys/boot/forth/support.4th Fri Jan 04 13:56:48 2019 +0200 +++ b/usr/src/boot/sys/boot/forth/support.4th Wed Jan 09 14:01:58 2019 +0000 @@ -201,8 +201,31 @@ : 2r> postpone r> postpone r> ; immediate : 2r@ postpone 2r> postpone 2dup postpone 2>r ; immediate +\ Number to string +: n2s ( n -- c-addr/u ) s>d <# #s #> ; +\ String to number +: s2n ( c-addr/u1 -- u2 | -1 ) ?number 0= if -1 then ; + +\ Test if an environment variable is set : getenv? getenv -1 = if false else drop true then ; +\ Fetch a number from an environment variable, or a default if not set or does +\ not parse (s2n returns -1). +: getenvn ( n1 c-addr/u -- n1 | n2 ) + getenv dup -1 = if + \ environment variable not set + drop ( n1 -1 -- n1 ) + else + s2n ( n1 c-addr/u1 -- n1 n2 ) + dup -1 = if + \ parse failed + drop ( n1 n2 -- n1 ) + else + nip ( n1 n2 -- n2 ) + then + then +; + \ Returns TRUE if the framebuffer is active, FALSE otherwise : framebuffer? ( -- flag ) \ Use the screen-height variable as a proxy for framebuffer diff -r 90242035d8ac -r 068da7e6bca0 usr/src/boot/sys/boot/forth/version.4th --- a/usr/src/boot/sys/boot/forth/version.4th Fri Jan 04 13:56:48 2019 +0200 +++ b/usr/src/boot/sys/boot/forth/version.4th Wed Jan 09 14:01:58 2019 +0000 @@ -1,6 +1,7 @@ \ Copyright (c) 2006-2015 Devin Teske +\ Copyright 2019 OmniOS Community Edition (OmniOSce) Association. \ All rights reserved. -\ +\ \ Redistribution and use in source and binary forms, with or without \ modification, are permitted provided that the following conditions \ are met: @@ -9,7 +10,7 @@ \ 2. Redistributions in binary form must reproduce the above copyright \ notice, this list of conditions and the following disclaimer in the \ documentation and/or other materials provided with the distribution. -\ +\ \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -21,8 +22,6 @@ \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF \ SUCH DAMAGE. -\ -\ $FreeBSD$ marker task-version.4th @@ -90,7 +89,7 @@ -rot type if me then - 0 25 at-xy + at-bl ; only forth definitions