Merge from vendor branch NTPD:
[dragonfly.git] / sys / boot / forth / beastie.4th
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: src/sys/boot/forth/beastie.4th,v 1.7 2003/10/28 17:18:42 scottl Exp $
27 \ $DragonFly: src/sys/boot/forth/beastie.4th,v 1.6 2004/01/22 12:04:58 eirikn Exp $
28
29 marker task-beastie.4th
30
31 include /boot/screen.4th
32 include /boot/frames.4th
33
34 hide
35
36 variable menuidx
37 variable menubllt
38 variable menuX
39 variable menuY
40 variable promptwidth
41
42 variable bootkey
43 variable bootacpikey
44 variable bootsafekey
45 variable bootverbosekey
46 variable bootsinglekey
47 variable escapekey
48 variable rebootkey
49
50 46 constant dot
51
52 \ The BSD Daemon.  He is 19 rows high and 34 columns wide
53 : technicolor-beastie ( x y -- )
54 2dup at-xy ."               \e[1;31m,        ," 1+
55 2dup at-xy ."              /(        )`" 1+
56 2dup at-xy ."              \ \___   / |" 1+
57 2dup at-xy ."              /- \e[37m_\e[31m  `-/  '" 1+
58 2dup at-xy ."             (\e[37m/\/ \\e[31m \   /\" 1+
59 2dup at-xy ."             \e[37m/ /   |\e[31m `    \" 1+
60 2dup at-xy ."             \e[34mO O   \e[37m) \e[31m/    |" 1+
61 2dup at-xy ."             \e[37m`-^--'\e[31m`<     '" 1+
62 2dup at-xy ."            (_.)  _  )   /" 1+
63 2dup at-xy ."             `.___/`    /       " 1+
64 2dup at-xy ."               `-----' /" 1+
65 2dup at-xy ."  \e[33m<----.\e[31m     __ / __   \" 1+
66 2dup at-xy ."  \e[33m<----|====\e[31mO)))\e[33m==\e[31m) \) /\e[33m====|" 1+
67 2dup at-xy ."  \e[33m<----'\e[31m    `--' `.__,' \" 1+
68 2dup at-xy ."               |        |" 1+
69 2dup at-xy ."                \       /       /\" 1+
70 2dup at-xy ."           \e[36m______\e[31m( (_  / \______/" 1+
71 2dup at-xy ."         \e[36m,'  ,-----'   |" 1+
72 at-xy ."         `--{__________) \e[0m" 1+
73 ;
74
75 : boring-fred ( 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 ."       `------(   )------'" 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 ."               | |" 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 : print-beastie ( x y -- )
98         s" loader_color" getenv
99         dup -1 = if
100                 drop
101                 boring-fred
102                 exit
103         then
104         s" YES" compare-insensitive 0<> if
105                 boring-fred
106                 exit
107         then
108         technicolor-beastie
109 ;
110
111 : acpienabled? ( -- flag )
112         s" acpi_load" getenv
113         dup -1 = if
114                 drop false exit
115         then
116         s" YES" compare-insensitive 0<> if
117                 false exit
118         then
119         s" hint.acpi.0.disabled" getenv
120         dup -1 <> if
121                 s" 0" compare 0<> if
122                         false exit
123                 then
124         then
125         true
126 ;
127
128 : printmenuitem ( -- n )
129         menuidx @
130         1+ dup
131         menuidx !
132         menuY @ + dup menuX @ swap at-xy
133         menuidx @ .
134         menuX @ 1+ swap at-xy
135         menubllt @ emit
136         menuidx @ 48 +
137 ;
138
139 : beastie-menu ( -- )
140         0 menuidx !
141         dot menubllt !
142         8 menuY !
143         5 menuX !
144         clear
145         46 4 print-beastie
146         42 20 2 2 box
147         13 6 at-xy ." Welcome to DragonFly!"
148         printmenuitem ."  Boot DragonFly [default]" bootkey !
149         s" arch-i386" environment? if
150                 printmenuitem ."  Boot DragonFly with ACPI " bootacpikey !
151                 acpienabled? if
152                         ." disabled"
153                 else
154                         ." enabled"
155                 then
156         else
157                 -2 bootacpikey !
158         then
159         printmenuitem ."  Boot DragonFly in Safe Mode" bootsafekey !
160         printmenuitem ."  Boot DragonFly in single user mode" bootsinglekey !
161         printmenuitem ."  Boot DragonFly with verbose logging" bootverbosekey !
162         printmenuitem ."  Escape to loader prompt" escapekey !
163         printmenuitem ."  Reboot" rebootkey !
164         menuX @ 20 at-xy
165         ." Select option, [Enter] for default"
166         menuX @ 21 at-xy
167         s" or [Space] to pause timer    " dup 2 - promptwidth !
168         type
169 ;
170
171 : tkey
172         dup
173         seconds +
174         begin 1 while
175                 over 0<> if
176                         dup seconds u< if
177                                 drop
178                                 -1
179                                 exit
180                         then
181                         menuX @ promptwidth @ + 21 at-xy dup seconds - .
182                 then
183                 key? if
184                         drop
185                         key
186                         exit
187                 then
188         50 ms
189         repeat
190 ;
191
192 set-current
193
194 : beastie-start
195         s" beastie_disable" getenv
196         dup -1 <> if
197                 s" YES" compare-insensitive 0= if
198                         exit
199                 then
200         then
201         beastie-menu
202         s" autoboot_delay" getenv
203         dup -1 = if
204                 drop
205                 10
206         else
207                 0 0 2swap >number drop drop drop
208         then
209         begin true while
210                 dup tkey
211                 0 25 at-xy
212                 dup 32 = if nip 0 swap then
213                 dup -1 = if 0 boot then
214                 dup 13 = if 0 boot then
215                 dup bootkey @ = if 0 boot then
216                 dup bootacpikey @ = if
217                         acpienabled? if
218                                 s" acpi_load" unsetenv
219                                 s" 1" s" hint.acpi.0.disabled" setenv
220                                 s" 1" s" loader.acpi_disabled_by_user" setenv
221                         else
222                                 s" YES" s" acpi_load" setenv
223                                 s" 0" s" hint.acpi.0.disabled" setenv
224                         then
225                         0 boot
226                 then
227                 dup bootsafekey @ = if
228                         s" arch-i386" environment? if
229                                 s" acpi_load" unsetenv
230                                 s" 1" s" hint.acpi.0.disabled" setenv
231                                 s" 1" s" loader.acpi_disabled_by_user" setenv
232                         then
233                         s" 0" s" hw.ata.ata_dma" setenv
234                         s" 0" s" hw.ata.atapi_dma" setenv
235                         s" 0" s" hw.ata.wc" setenv
236                         s" 0" s" hw.eisa_slots" setenv
237                         0 boot
238                 then
239                 dup bootverbosekey @ = if
240                         s" YES" s" boot_verbose" setenv
241                         0 boot
242                 then
243                 dup bootsinglekey @ = if
244                         s" YES" s" boot_single" setenv
245                         0 boot
246                 then
247                 dup escapekey @ = if
248                         2drop
249                         s" NO" s" autoboot_delay" setenv
250                         exit
251                 then
252                 rebootkey @ = if 0 reboot then
253         repeat
254 ;
255
256 previous