beastie.4th revision 151873
1\ Copyright (c) 2003 Scott Long <scottl@freebsd.org>
2\ Copyright (c) 2003 Aleksander Fafula <alex@fafula.com>
3\ All rights reserved.
4\
5\ Redistribution and use in source and binary forms, with or without
6\ modification, are permitted provided that the following conditions
7\ are met:
8\ 1. Redistributions of source code must retain the above copyright
9\    notice, this list of conditions and the following disclaimer.
10\ 2. Redistributions in binary form must reproduce the above copyright
11\    notice, this list of conditions and the following disclaimer in the
12\    documentation and/or other materials provided with the distribution.
13\
14\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24\ SUCH DAMAGE.
25\
26\ $FreeBSD: head/sys/boot/forth/beastie.4th 151873 2005-10-30 05:36:23Z scottl $
27
28marker task-beastie.4th
29
30include /boot/screen.4th
31include /boot/frames.4th
32
33hide
34
35variable menuidx
36variable menubllt
37variable menuX
38variable menuY
39variable promptwidth
40
41variable bootkey
42variable bootacpikey
43variable bootusbkey
44variable bootsafekey
45variable bootverbosekey
46variable bootsinglekey
47variable escapekey
48variable rebootkey
49
5046 constant dot
51
52\ The BSD Daemon.  He is 19 rows high and 34 columns wide
53: beastie-logo ( x y -- )
542dup at-xy ."               [1;31m,        ," 1+
552dup at-xy ."              /(        )`" 1+
562dup at-xy ."              \ \___   / |" 1+
572dup at-xy ."              /- [37m_[31m  `-/  '" 1+
582dup at-xy ."             ([37m/\/ \[31m \   /\" 1+
592dup at-xy ."             [37m/ /   |[31m `    \" 1+
602dup at-xy ."             [34mO O   [37m) [31m/    |" 1+
612dup at-xy ."             [37m`-^--'[31m`<     '" 1+
622dup at-xy ."            (_.)  _  )   /" 1+
632dup at-xy ."             `.___/`    /       " 1+
642dup at-xy ."               `-----' /" 1+
652dup at-xy ."  [33m<----.[31m     __ / __   \" 1+
662dup at-xy ."  [33m<----|====[31mO)))[33m==[31m) \) /[33m====|" 1+
672dup at-xy ."  [33m<----'[31m    `--' `.__,' \" 1+
682dup at-xy ."               |        |" 1+
692dup at-xy ."                \       /       /\" 1+
702dup at-xy ."           [36m______[31m( (_  / \______/" 1+
712dup at-xy ."         [36m,'  ,-----'   |" 1+
72at-xy ."         `--{__________) [0m"
73;
74
75: beastiebw-logo ( x y -- )
76	2dup at-xy ."              ,        ," 1+
77	2dup at-xy ."             /(        )`" 1+
78	2dup at-xy ."             \ \___   / |" 1+
79	2dup at-xy ."             /- _  `-/  '" 1+
80	2dup at-xy ."            (/\/ \ \   /\" 1+
81	2dup at-xy ."            / /   | `    \" 1+
82	2dup at-xy ."            O O   ) /    |" 1+
83	2dup at-xy ."            `-^--'`<     '" 1+
84	2dup at-xy ."           (_.)  _  )   /" 1+
85	2dup at-xy ."            `.___/`    /" 1+
86	2dup at-xy ."              `-----' /" 1+
87	2dup at-xy ." <----.     __ / __   \" 1+
88	2dup at-xy ." <----|====O)))==) \) /====" 1+
89	2dup at-xy ." <----'    `--' `.__,' \" 1+
90	2dup at-xy ."              |        |" 1+
91	2dup at-xy ."               \       /       /\" 1+
92	2dup at-xy ."          ______( (_  / \______/" 1+
93	2dup at-xy ."        ,'  ,-----'   |" 1+
94	     at-xy ."        `--{__________)"
95;
96
97: fbsdbw-logo ( x y -- )
98	2dup at-xy ."      ______" 1+
99	2dup at-xy ."     |  ____| __ ___  ___ " 1+
100	2dup at-xy ."     | |__ | '__/ _ \/ _ \" 1+
101	2dup at-xy ."     |  __|| | |  __/  __/" 1+
102	2dup at-xy ."     | |   | | |    |    |" 1+
103	2dup at-xy ."     |_|   |_|  \___|\___|" 1+
104	2dup at-xy ."      ____   _____ _____" 1+
105	2dup at-xy ."     |  _ \ / ____|  __ \" 1+
106	2dup at-xy ."     | |_) | (___ | |  | |" 1+
107	2dup at-xy ."     |  _ < \___ \| |  | |" 1+
108	2dup at-xy ."     | |_) |____) | |__| |" 1+
109	2dup at-xy ."     |     |      |      |" 1+
110	     at-xy ."     |____/|_____/|_____/"
111;
112
113: print-logo ( x y -- )
114	s" loader_logo" getenv
115	dup -1 = if
116		drop
117		fbsdbw-logo
118		exit
119	then
120	2dup s" fbsdbw" compare-insensitive 0= if
121		2drop
122		fbsdbw-logo
123		exit
124	then
125	2dup s" beastiebw" compare-insensitive 0= if
126		2drop
127		beastiebw-logo
128		exit
129	then
130	2dup s" beastie" compare-insensitive 0= if
131		2drop
132		beastie-logo
133		exit
134	then
135	2dup s" none" compare-insensitive 0= if
136		2drop
137		\ no logo
138		exit
139	then
140	2drop
141	fbsdbw-logo
142;
143
144: acpienabled? ( -- flag )
145	s" acpi_load" getenv
146	dup -1 = if
147		drop false exit
148	then
149	s" YES" compare-insensitive 0<> if
150		false exit
151	then
152	s" hint.acpi.0.disabled" getenv
153	dup -1 <> if
154		s" 0" compare 0<> if
155			false exit
156		then
157	else
158		drop
159	then
160	true
161;
162
163: printmenuitem ( -- n )
164	menuidx @
165	1+ dup
166	menuidx !
167	menuY @ + dup menuX @ swap at-xy
168	menuidx @ .
169	menuX @ 1+ swap at-xy
170	menubllt @ emit
171	menuidx @ 48 +
172;
173
174: beastie-menu ( -- )
175	0 menuidx !
176	dot menubllt !
177	8 menuY !
178	5 menuX !
179	clear
180	46 4 print-logo
181	42 20 2 2 box
182	13 6 at-xy ." Welcome to FreeBSD!"
183	printmenuitem ."  Boot FreeBSD [default]" bootkey !
184	s" arch-i386" environment? if
185		drop
186		printmenuitem ."  Boot FreeBSD with ACPI " bootacpikey !
187		acpienabled? if
188			." disabled"
189		else
190			." enabled"
191		then
192	else
193		-2 bootacpikey !
194	then
195	printmenuitem ."  Boot FreeBSD in Safe Mode" bootsafekey !
196	printmenuitem ."  Boot FreeBSD in single user mode" bootsinglekey !
197	printmenuitem ."  Boot FreeBSD with verbose logging" bootverbosekey !
198	printmenuitem ."  Escape to loader prompt" escapekey !
199	s" arch-i386" environment? if
200		drop
201		printmenuitem ."  Boot FreeBSD with USB keyboard" bootusbkey !
202	else
203		-2 bootusbkey !
204	then
205	printmenuitem ."  Reboot" rebootkey !
206	menuX @ 20 at-xy
207	." Select option, [Enter] for default"
208	menuX @ 21 at-xy
209	s" or [Space] to pause timer    " dup 2 - promptwidth !
210	type
211;
212
213: tkey
214	seconds +
215	begin 1 while
216		over 0<> if
217			dup seconds u< if
218				drop
219				-1
220				exit
221			then
222			menuX @ promptwidth @ + 21 at-xy dup seconds - .
223		then
224		key? if
225			drop
226			key
227			exit
228		then
229	50 ms
230	repeat
231;
232
233set-current
234
235: beastie-start
236	s" beastie_disable" getenv
237	dup -1 <> if
238		s" YES" compare-insensitive 0= if
239			exit
240		then
241	else
242		drop
243	then
244	beastie-menu
245	s" autoboot_delay" getenv
246	dup -1 = if
247		drop
248		10
249	else
250		0 0 2swap >number drop drop drop
251	then
252	begin
253		dup tkey
254		0 25 at-xy
255		dup 32 = if nip 0 swap then
256		dup -1 = if 0 boot then
257		dup 13 = if 0 boot then
258		dup bootkey @ = if 0 boot then
259		dup bootacpikey @ = if
260			acpienabled? if
261				s" acpi_load" unsetenv
262				s" 1" s" hint.acpi.0.disabled" setenv
263				s" 1" s" loader.acpi_disabled_by_user" setenv
264			else
265				s" YES" s" acpi_load" setenv
266				s" 0" s" hint.acpi.0.disabled" setenv
267			then
268			0 boot
269		then
270		dup bootusbkey @ = if
271			s" 0x1" s" hint.atkbd.0.flags" setenv
272			0 boot
273		then
274		dup bootsafekey @ = if
275			s" arch-i386" environment? if
276				drop
277				s" acpi_load" unsetenv
278				s" 1" s" hint.acpi.0.disabled" setenv
279				s" 1" s" loader.acpi_disabled_by_user" setenv
280				s" 1" s" hint.apic.0.disabled" setenv
281			then
282			s" 0" s" hw.ata.ata_dma" setenv
283			s" 0" s" hw.ata.atapi_dma" setenv
284			s" 0" s" hw.ata.wc" setenv
285			s" 0" s" hw.eisa_slots" setenv
286			0 boot
287		then
288		dup bootverbosekey @ = if
289			s" YES" s" boot_verbose" setenv
290			0 boot
291		then
292		dup bootsinglekey @ = if
293			s" YES" s" boot_single" setenv
294			0 boot
295		then
296		dup escapekey @ = if
297			2drop
298			s" NO" s" autoboot_delay" setenv
299			exit
300		then
301		rebootkey @ = if 0 reboot then
302	again
303;
304
305previous
306