\ Copyright (c) 2003 Scott Long <scottl@freebsd.org>
\ Copyright (c) 2003 Aleksander Fafula <alex@fafula.com>
\ Copyright (c) 2006-2013 Devin Teske <dteske@FreeBSD.org>
\ All rights reserved.
\ 
\ Redistribution and use in source and binary forms, with or without
\ modification, are permitted provided that the following conditions
\ are met:
\ 1. Redistributions of source code must retain the above copyright
\    notice, this list of conditions and the following disclaimer.
\ 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
\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\ 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.
\ 
\ $BSDSUniX$

marker task-beastie.4th

only forth definitions also support-functions

variable logoX
variable logoY

\ Initialize logo placement to defaults
46 logoX !
4  logoY !

: cutebear-logo ( x y -- ) \ color Cute Bear (19 rows x 34 columns)

2dup at-xy ."                 _  _._" 1+
2dup at-xy ."      .,-,_  .,-+\`'`  `\ ,-,." 1+
2dup at-xy ."     (  ,,,/`            `,--,\" 1+
2dup at-xy ."     | ( /                 ',' :" 1+
2dup at-xy ."      \.|   /-.  /-.         )/" 1+
2dup at-xy ."        |   ((   ((,         |" 1+
2dup at-xy ."        |                    |" 1+
2dup at-xy ."        ', \--||+      ,    ," 1+
2dup at-xy ."         ',  `      ._/    (" 1+
2dup at-xy ."           `-,          ,- " 1+
2dup at-xy ."        --+`\  )+      |" 1+
2dup at-xy ."       \     ` ,        )" 1+
2dup at-xy ."        \,,-`+`     -  \ \" 1+
2dup at-xy ."     ,++., /`     ,`    |,|" 1+
2dup at-xy ."     /   / -++-.   ``),,/  )" 1+
2dup at-xy ."     |  |,` ,,  `        \" 1+
2dup at-xy ."      '+,|_ ''            '" 1+
     at-xy ."           \|`,,,,,-,--+`"

	\ Put the cursor back at the bottom
	0 25 at-xy
;

: cutebearbw-logo ( x y -- ) \ B/W Cute Bear (19 rows x 34 columns)

2dup at-xy ."                 _  _._" 1+
2dup at-xy ."      .,-,_  .,-+\`'`  `\ ,-,." 1+
2dup at-xy ."     (  ,,,/`            `,--,\" 1+
2dup at-xy ."     | ( /                 ',' :" 1+
2dup at-xy ."      \.|   /-.  /-.         )/" 1+
2dup at-xy ."        |   ((   ((,         |" 1+
2dup at-xy ."        |                    |" 1+
2dup at-xy ."        ', \--||+      ,    ," 1+
2dup at-xy ."         ',  `      ._/    (" 1+
2dup at-xy ."           `-,          ,- " 1+
2dup at-xy ."        --+`\  )+      |" 1+
2dup at-xy ."       \     ` ,        )" 1+
2dup at-xy ."        \,,-`+`     -  \ \" 1+
2dup at-xy ."     ,++., /`     ,`    |,|" 1+
2dup at-xy ."     /   / -++-.   ``),,/  )" 1+
2dup at-xy ."     |  |,` ,,  `^         \" 1+
2dup at-xy ."      '+,|_ ''            '" 1+
     at-xy ."           \|`,,,,,-,--+`"

	\ Put the cursor back at the bottom
	0 25 at-xy
;

: bsdsuxbw-logo ( x y -- ) \ "BSDSUniX" logo in B/W (13 rows x 21 columns)

	5 + swap 6 + swap

	2dup at-xy ."  ____   _____ _____" 1+
	2dup at-xy ." |  _ \ / ____|  __ \" 1+
	2dup at-xy ." | |_) | (___ | |  | |" 1+
	2dup at-xy ." |  _ < \___ \| |  | |" 1+
	2dup at-xy ." | |_) |____) | |__| |" 1+
	2dup at-xy ." |____/|_____/|_____/" 1+
	2dup at-xy ."   _____" 1+
	2dup at-xy ."  / ____|             " 1+
	2dup at-xy ." | (____              " 1+
	2dup at-xy ."  \____  \.-. .-./\ /\" 1+
	2dup at-xy ."  _____) || | | |\ v /" 1+
	2dup at-xy ." |       || \_/ |/ ^ \" 1+
	     at-xy ." \______/  \___/ \/ \/" 1+

	\ Put the cursor back at the bottom
	0 25 at-xy
;

: tribute-art ( x y -- ) \ see tribute[bw]-logo

	\ Disable the brand art (we're going to use that space)
	s" set loader_brand=none" evaluate

	\ Blank out the frame of the menu and move the title to left
	s" set loader_menu_title=" evaluate
	s" set loader_menu_frame=none" evaluate

	\ Move the menu to the center of the screen
	s" set loader_menu_x=26" evaluate
	s" set loader_menu_y=12" evaluate
	s" set loader_menu_timeout_x=21" evaluate
	s" set loader_menu_timeout_y=24" evaluate

	2 - swap 39 - swap \ top-left (see `fbsdbw-logo' comments above)

	2dup at-xy 11 spaces ." ,d      b." 1+
	2dup at-xy ."         ,d88]      [88b." 1+
	2dup at-xy ."      ,d888P" 34 emit ."  ,d88b. " 34 emit ." Y888b." 1+
	2dup at-xy ."  , <888P" 34 emit ."  ,dP" 34 emit ." ,db." 34 emit
	           ." Yb. " 34 emit ." Y888> ," 1+
	2dup at-xy ." <88b.~ ,d888  " 34 emit ." YP" 34 emit
	           ."   888b. ~,d88>" 1+
	2dup at-xy ."  ," 34 emit ." Y888888P" 34 emit ." ,db.,db." 34 emit
	           ." Y888888P" 34 emit ." ," 1+
	2dup at-xy ." <88b." 34 emit ." YP" 34 emit ."  _ " 34 emit
	           ." YP" 34 emit 34 emit ." YP" 34 emit ."  _ " 34 emit
	           ." YP" 34 emit ." ,d88>" 1+
	2dup at-xy ."   " 34 emit ." Y88b.,dP          Yb.,d88P" 34 emit 1+
	     at-xy ."      " 34 emit ." YP" 34 emit ."               " 34 emit
	           ." YP" 34 emit ." "
;

: tribute-text ( x y -- ) \ see tribute[bw]-logo

	swap 2 - swap \ cutebare adjustment (see `cutebearbw-logo' comments above)

	2dup at-xy ." CEO Workstation" 1+
	1+
	2dup at-xy ." Nakatomi Socrates BSDSUniX 1.0" 1+
	2dup at-xy ." Z-Level Central Core" 1+
	1+
	     at-xy ." Preliminary Clearance Approved."
;

: tribute-logo ( x y -- ) \ color Socrates tribute (16 rows x 32 columns)

	\ Produce the tribute art in bright green
	2dup at-xy ." " 2dup tribute-art ." "

	\ Produce the tribute text in regular green
	2dup at-xy ." " 2dup tribute-text ." "

	\ Distinguish the ``Free'' in tribute-text
	2 + swap 16 + swap at-xy ." Free"

 	\ Put the cursor back at the bottom
 	0 25 at-xy
;

: tributebw-logo ( x y -- ) \ Socrates tribute (16 rows x 32 columns)

	\ Produce the tribute art and text
	2dup tribute-art tribute-text

 	\ Put the cursor back at the bottom
 	0 25 at-xy
;

\ This function draws any number of beastie logos at (loader_logo_x,
\ loader_logo_y) if defined, else (46,4) (to the right of the menu). To choose
\ your beastie, set the variable `loader_logo' to the respective logo name.
\ 
\ Currently available:
\ 
\ 	NAME        DESCRIPTION
\ 	cutebear    Color ``Cute Bear'' (19 rows x 34 columns)
\ 	cutebearbw  B/W ``Cute Bear'' (19 rows x 34 columns)
\ 	bsdsuxbw    "BSDSUniX" logo in B/W (13 rows x 21 columns)
\ 	tribute     Color ``Tribute'' (must fit 19 rows x 34 columns) (default)
\ 	tributebw   B/W ``Tribute'' (must fit 19 rows x 34 columns)
\ 
\ NOTE: Setting `loader_logo' to an undefined value (such as "none") will
\       prevent beastie from being drawn.
\ 
: draw-beastie ( -- ) \ at (loader_logo_x,loader_logo_y), else (46,4)

	s" loader_logo_x" getenv dup -1 <> if
		?number 1 = if logoX ! then
	else
		drop
	then
	s" loader_logo_y" getenv dup -1 <> if
		?number 1 = if logoY ! then
	else
		drop
	then

	s" loader_logo" getenv dup -1 <> if
		dup 5 + allocate if ENOMEM throw then
		0 2swap strcat s" -logo" strcat
		over -rot ( a-addr/u -- a-addr a-addr/u )
		sfind     ( a-addr a-addr/u -- a-addr xt bool )
		rot       ( a-addr xt bool -- xt bool a-addr )
		free      ( xt bool a-addr -- xt bool ior )
		if EFREE throw then
	else
		0 ( cruft -- cruft bool ) \ load the default below
	then
	0= if
		drop ( cruft -- )
		loader_color? if
			['] cutebear-logo
		else
			['] cutebearbw-logo
		then
	then
	logoX @ logoY @ rot execute
;

: clear-beastie ( -- ) \ clears beastie from the screen
	logoX @ logoY @
	2dup at-xy 34 spaces 1+		2dup at-xy 34 spaces 1+
	2dup at-xy 34 spaces 1+		2dup at-xy 34 spaces 1+
	2dup at-xy 34 spaces 1+		2dup at-xy 34 spaces 1+
	2dup at-xy 34 spaces 1+		2dup at-xy 34 spaces 1+
	2dup at-xy 34 spaces 1+		2dup at-xy 34 spaces 1+
	2dup at-xy 34 spaces 1+		2dup at-xy 34 spaces 1+
	2dup at-xy 34 spaces 1+		2dup at-xy 34 spaces 1+
	2dup at-xy 34 spaces 1+		2dup at-xy 34 spaces 1+
	2dup at-xy 34 spaces 1+		2dup at-xy 34 spaces 1+
	2dup at-xy 34 spaces		2drop

	\ Put the cursor back at the bottom
	0 25 at-xy
;

: beastie-start ( -- ) \ starts the menu
	s" beastie_disable" getenv
	dup -1 <> if
		s" YES" compare-insensitive 0= if
			any_conf_read? if
				load_kernel
				load_modules
			then
			exit \ to autoboot (default)
		then
	else
		drop
	then

	s" loader_delay" getenv
	-1 = if
		s" include /boot/menu.rc" evaluate
	else
		drop
		." Loading Menu (Ctrl-C to Abort)" cr
		s" set delay_command='include /boot/menu.rc'" evaluate
		s" set delay_showdots" evaluate
		delay_execute
	then
;

only forth also