printf(1): don't use getopt, second take
[dragonfly.git] / sys / boot / forth / beastie.4th
blobeb26674cc6e46212a60f155567979767b65de947
1 \ Copyright (c) 2003 Scott Long <scottl@freebsd.org>
2 \ Copyright (c) 2003 Aleksander Fafula <alex@fafula.com>
3 \ All rights reserved.
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.
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.
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.9 2008/09/02 17:21:15 dillon Exp $
29 marker task-beastie.4th
31 include screen.4th
32 include frames.4th
34 hide
36 variable menuidx
37 variable menubllt
38 variable menuX
39 variable menuY
40 variable promptwidth
42 variable bootkey
43 variable bootacpikey
44 variable bootsafekey
45 variable bootverbosekey
46 variable bootahcikey
47 variable bootsinglekey
48 variable escapekey
49 variable rebootkey
51 46 constant dot
53 \ Fred, the official DragonFly BSD mascot.
54 \ He is 19 rows high and 34 columns wide
55 : technicolor-fred ( x y -- )
56         2dup at-xy ." " 1+
57         2dup at-xy ." " 1+
58         2dup at-xy ." ,--,           \e[31m|           \e[37m,--," 1+
59         2dup at-xy ." |   `-,       \e[31m,^,       \e[37m,-'   |" 1+
60         2dup at-xy ."  `,    `-,   \e[32m(\e[31m/ \\e[32m)   \e[37m,-'    ,'" 1+
61         2dup at-xy ."    `-,    `-,\e[31m/   \\e[37m,-'    ,-'" 1+
62         2dup at-xy ."       `------\e[31m(   )\e[37m------'" 1+
63         2dup at-xy ."   ,----------\e[31m(   )\e[37m----------," 1+
64         2dup at-xy ."  |        _,-\e[31m(   )\e[37m-,_        |" 1+
65         2dup at-xy ."   `-,__,-'   \e[31m\   /   \e[37m`-,__,-'" 1+
66         2dup at-xy ."               \e[31m| |" 1+
67         2dup at-xy ."               | |" 1+
68         2dup at-xy ."               | |" 1+
69         2dup at-xy ."               | |" 1+
70         2dup at-xy ."               | |" 1+
71         2dup at-xy ."               | |" 1+
72         2dup at-xy ."               `|'\e[0m" 1+
73         2dup at-xy ." " 1+
74              at-xy ."
77 : boring-fred ( x y -- )
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         2dup at-xy ."               `|'" 1+
95         2dup at-xy ." " 1+
96              at-xy ."
99 : print-fred ( x y -- )
100         s" loader_color" getenv
101         dup -1 = if
102                 drop
103                 boring-fred
104                 exit
105         then
106         s" YES" compare-insensitive 0<> if
107                 boring-fred
108                 exit
109         then
110         technicolor-fred
113 : acpienabled? ( -- flag )
114         s" acpi_load" getenv
115         dup -1 = if
116                 drop false exit
117         then
118         s" YES" compare-insensitive 0<> if
119                 false exit
120         then
121         s" hint.acpi.0.disabled" getenv
122         dup -1 <> if
123                 s" 0" compare 0<> if
124                         false exit
125                 then
126         then
127         true
130 : printmenuitem ( -- n )
131         menuidx @
132         1+ dup
133         menuidx !
134         menuY @ + dup menuX @ swap at-xy
135         menuidx @ .
136         menuX @ 1+ swap at-xy
137         menubllt @ emit
138         menuidx @ 48 +
141 : fred-menu ( -- )
142         0 menuidx !
143         dot menubllt !
144         8 menuY !
145         5 menuX !
146         clear
147         46 4 print-fred
148         42 20 2 2 box
149         13 6 at-xy ." Welcome to DragonFly!"
150         printmenuitem ."  Boot DragonFly [default]" bootkey !
151         s" arch-i386" environment? if
152                 printmenuitem ."  Boot DragonFly with ACPI " bootacpikey !
153                 acpienabled? if
154                         ." disabled"
155                 else
156                         ." enabled"
157                 then
158         else
159                 -2 bootacpikey !
160         then
161         printmenuitem ."  Boot DragonFly in Safe Mode" bootsafekey !
162         printmenuitem ."  Boot DragonFly in single user mode" bootsinglekey !
163         printmenuitem ."  Boot DragonFly with verbose logging" bootverbosekey !
164         printmenuitem ."  Boot DragonFly without AHCI driver " bootahcikey !
165         printmenuitem ."  Escape to loader prompt" escapekey !
166         printmenuitem ."  Reboot" rebootkey !
167         menuX @ 20 at-xy
168         ." Select option, [Enter] for default"
169         menuX @ 21 at-xy
170         s" or [Space] to pause timer    " dup 2 - promptwidth !
171         type
174 : tkey
175         dup
176         seconds +
177         begin 1 while
178                 over 0<> if
179                         dup seconds u< if
180                                 drop
181                                 -1
182                                 exit
183                         then
184                         menuX @ promptwidth @ + 21 at-xy dup seconds - .
185                 then
186                 key? if
187                         drop
188                         key
189                         exit
190                 then
191         50 ms
192         repeat
195 set-current
197 : beastie-start
198         s" fred_disable" getenv
199         dup -1 <> if
200                 s" YES" compare-insensitive 0= if
201                         exit
202                 then
203         then
204         fred-menu
205         s" autoboot_delay" getenv
206         dup -1 = if
207                 drop
208                 10
209         else
210                 0 0 2swap >number drop drop drop
211         then
212         begin true while
213                 dup tkey
214                 0 25 at-xy
215                 dup 32 = if nip 0 swap then
216                 dup -1 = if 0 boot then
217                 dup 13 = if 0 boot then
218                 dup bootkey @ = if 0 boot then
219                 dup bootacpikey @ = if
220                         acpienabled? if
221                                 s" acpi_load" unsetenv
222                                 s" 1" s" hint.acpi.0.disabled" setenv
223                                 s" 1" s" loader.acpi_disabled_by_user" setenv
224                         else
225                                 s" YES" s" acpi_load" setenv
226                                 s" 0" s" hint.acpi.0.disabled" setenv
227                         then
228                         0 boot
229                 then
230                 dup bootsafekey @ = if
231                         s" arch-i386" environment? if
232                                 s" acpi_load" unsetenv
233                                 s" 1" s" hint.acpi.0.disabled" setenv
234                                 s" 1" s" loader.acpi_disabled_by_user" setenv
235                         then
236                         s" 0" s" hw.ata.ata_dma" setenv
237                         s" 0" s" hw.ata.atapi_dma" setenv
238                         s" 0" s" hw.ata.wc" setenv
239                         s" 0" s" hw.eisa_slots" setenv
240                         0 boot
241                 then
242                 dup bootverbosekey @ = if
243                         s" YES" s" boot_verbose" setenv
244                         0 boot
245                 then
246                 dup bootahcikey @ = if
247                         s" YES" s" hint.ahci.disabled" setenv
248                         0 boot
249                 then
250                 dup bootsinglekey @ = if
251                         s" YES" s" boot_single" setenv
252                         0 boot
253                 then
254                 dup escapekey @ = if
255                         2drop
256                         s" NO" s" autoboot_delay" setenv
257                         exit
258                 then
259                 rebootkey @ = if 0 reboot then
260         repeat
263 previous