1 | /*␊ |
2 | * Copyright (c) 2009 Evan Lojewski. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | ␊ |
6 | #include "libsaio.h"␊ |
7 | #include "options.h"␊ |
8 | #include "graphic_utils.h"␊ |
9 | #include "ramdisk.h"␊ |
10 | #include "embedded.h"␊ |
11 | ␊ |
12 | #include "picopng.h"␊ |
13 | #include "gui.h"␊ |
14 | ␊ |
15 | #include "modules.h"␊ |
16 | ␊ |
17 | /* Kabyl: BooterLog */␊ |
18 | #define BOOTER_LOG_SIZE␉(64 * 1024)␊ |
19 | #define SAFE_LOG_SIZE␉80␊ |
20 | ␊ |
21 | #ifndef DEBUG_GUI␊ |
22 | #define DEBUG_GUI 0␊ |
23 | #endif␊ |
24 | ␊ |
25 | #if DEBUG_GUI␊ |
26 | #define DBG(x...) GUI_verbose(x)␊ |
27 | #else␊ |
28 | #define DBG(x...) ␊ |
29 | #endif␊ |
30 | ␊ |
31 | ␊ |
32 | ␊ |
33 | bool useGUI;␊ |
34 | ␊ |
35 | //void GUI_Kernel_Start_hook(void* kernelEntry, void* arg2, void* arg3, void* arg4);␊ |
36 | void GUI_PreBoot_hook(void* arg1, void* arg2, void* arg3, void* arg4);␊ |
37 | void GUI_ModulesLoaded_hook(void* arg1, void* arg2, void* arg3, void* arg4);␊ |
38 | ␊ |
39 | int GUI_getBootOptions(bool firstRun);␊ |
40 | ␊ |
41 | static void GUI_updateBootArgs( int key );␊ |
42 | void GUI_clearBootArgs(void);␊ |
43 | static void GUI_showBootPrompt(int row, bool visible);␊ |
44 | static void GUI_showMenu( const MenuItem * items, int count, int selection, int row, int height );␊ |
45 | static int GUI_updateMenu( int key, void ** paramPtr );␊ |
46 | static void GUI_showHelp(void);␊ |
47 | ␊ |
48 | int GUI_printf(const char * fmt, ...);␊ |
49 | int GUI_verbose(const char * fmt, ...);␊ |
50 | int GUI_error(const char * fmt, ...);␊ |
51 | void GUI_stop(const char * fmt, ...);␊ |
52 | ␊ |
53 | ␊ |
54 | /* console.c */␊ |
55 | struct putc_info {␊ |
56 | char * str;␊ |
57 | char * last_str;␊ |
58 | };␊ |
59 | void sputc(int c, struct putc_info * pi);␊ |
60 | extern char *msgbuf;␊ |
61 | extern char *cursor;␊ |
62 | ␊ |
63 | ␊ |
64 | ␊ |
65 | ␊ |
66 | char GUI_bootRescanPrompt[] =␊ |
67 | "Press Enter to start up Darwin/x86 with no options, or you can:\n"␊ |
68 | " Press F5 after you swapped the media. The drive will be rescanned.\n"␊ |
69 | " Type -v and press Enter to start up with diagnostic messages\n"␊ |
70 | " Type ? and press Enter to learn about advanced startup options\n\n"␊ |
71 | "boot: ";␊ |
72 | ␊ |
73 | ␊ |
74 | ␊ |
75 | /**␊ |
76 | ** The kernel is about to start, draw the boot graphics if we are not in␊ |
77 | ** verbose mode.␊ |
78 | **/␊ |
79 | void GUI_ExecKernel_hook(void* kernelEntry, void* arg2, void* arg3, void* arg4)␊ |
80 | {␊ |
81 | ␉if(!gVerboseMode)␊ |
82 | ␉{␊ |
83 | ␉␉// Note: shouldn't be needed, but just in case␊ |
84 | ␉␉drawBootGraphics();␊ |
85 | ␉}␊ |
86 | ␉else if(!useGUI)␊ |
87 | ␉{␊ |
88 | ␉␉setVideoMode( GRAPHICS_MODE, 0 ); //Slice - Why GRAPHICS_MODE if gVerboseMode?␊ |
89 | //␉␉DBG("GUI set GRAPHICS_MODE\n");␊ |
90 | ␉}␉␊ |
91 | }␊ |
92 | ␊ |
93 | /**␊ |
94 | ** A boot option has been selected, disable the graphical elements on screen.␊ |
95 | **/␊ |
96 | void GUI_PreBoot_hook(void* arg1, void* arg2, void* arg3, void* arg4)␊ |
97 | {␊ |
98 | ␉// Turn off any GUI elements␊ |
99 | ␉if( useGUI )␊ |
100 | ␉{␊ |
101 | ␉␉gui.devicelist.draw = false;␊ |
102 | ␉␉gui.bootprompt.draw = false;␊ |
103 | ␉␉gui.menu.draw = false;␊ |
104 | ␉␉gui.infobox.draw = false;␊ |
105 | ␉␉gui.logo.draw = false;␊ |
106 | ␉␉drawBackground();␊ |
107 | ␉␉//updateVRAM();␊ |
108 | ␊ |
109 | ␉␉if(!gVerboseMode)␊ |
110 | ␉␉{␊ |
111 | ␉␉␉// Disable outputs, they will still show in the boot log.␊ |
112 | ␉␉␉replace_function("_printf", &GUI_verbose);␊ |
113 | //␉␉␉drawBootGraphics();␊ |
114 | ␉␉}␊ |
115 | ␉␉␊ |
116 | ␉}␊ |
117 | }␊ |
118 | ␊ |
119 | void GUI_ModulesLoaded_hook(void* kernelEntry, void* arg2, void* arg3, void* arg4)␊ |
120 | {␊ |
121 | ␉// Start the gui␊ |
122 | ␉useGUI = true;␊ |
123 | ␉// Override useGUI default␊ |
124 | ␉getBoolForKey(kGUIKey, &useGUI, &bootInfo->bootConfig);␊ |
125 | ␉if (useGUI && initGUI())␊ |
126 | ␉{␊ |
127 | ␉␉// initGUI() returned with an error, disabling GUI.␊ |
128 | ␉␉useGUI = false;␊ |
129 | ␉}␊ |
130 | ␉else if(useGUI)␊ |
131 | ␉{␊ |
132 | ␉␉replace_function("_initGraphicsMode", &GUI_initGraphicsMode);␊ |
133 | ␉␉replace_function("_getBootOptions", &GUI_getBootOptions);␊ |
134 | ␉␉replace_function("_clearBootArgs", &GUI_clearBootArgs);␊ |
135 | ␉␉replace_function("_showHelp", &GUI_showHelp);␊ |
136 | ␉␉␊ |
137 | ␉␉replace_function("_printf", &GUI_printf);␊ |
138 | ␉␉replace_function("_verbose", &GUI_verbose);␊ |
139 | ␉␉replace_function("_error", &GUI_error);␊ |
140 | ␉␉replace_function("_stop", &GUI_stop);␉␉␊ |
141 | ␉␉␊ |
142 | ␉␉setVideoMode( GRAPHICS_MODE, 0 );␊ |
143 | ␉␉drawBackground();␊ |
144 | ␉␊ |
145 | ␉}␊ |
146 | //␉DBG("GUI loaded\n");␊ |
147 | }␊ |
148 | ␊ |
149 | /**␊ |
150 | ** Module startup code. Replace console only print functions as well as␊ |
151 | ** replace various menu functions. Finaly, initialize the gui and hook␊ |
152 | ** into important events.␊ |
153 | **/␊ |
154 | void GUI_start()␊ |
155 | {␊ |
156 | ␉// Hoot for the boot screen ␊ |
157 | ␉//ExecKernel register_hook_callback("Kernel Start", &GUI_Kernel_Start_hook);␊ |
158 | ␉register_hook_callback("ExecKernel", &GUI_ExecKernel_hook);␊ |
159 | ␉register_hook_callback("PreBoot", &GUI_PreBoot_hook);␉␉␊ |
160 | ␉register_hook_callback("ModulesLoaded", &GUI_ModulesLoaded_hook);␊ |
161 | }␊ |
162 | ␊ |
163 | /**␊ |
164 | ** Overriden chameleon function. Draws the updated menu.␊ |
165 | **/␊ |
166 | static int GUI_updateMenu( int key, void ** paramPtr )␊ |
167 | {␊ |
168 | int moved = 0;␊ |
169 | ␉␊ |
170 | union {␊ |
171 | struct {␊ |
172 | unsigned int␊ |
173 | ␉␉␉selectionUp : 1,␊ |
174 | ␉␉␉selectionDown : 1,␊ |
175 | ␉␉␉scrollUp : 1,␊ |
176 | ␉␉␉scrollDown : 1;␊ |
177 | } f;␊ |
178 | unsigned int w;␊ |
179 | } draw = {{0}};␊ |
180 | ␉␊ |
181 | if ( gMenuItems == NULL )␊ |
182 | ␉␉return 0;␊ |
183 | ␉␊ |
184 | ␉if( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
185 | ␉{␊ |
186 | ␉␉int res;␊ |
187 | ␉␉␊ |
188 | ␉␉// set navigation keys for horizontal layout as defaults␊ |
189 | ␉␉int previous␉= 0x4B00;␉␉// left arrow␊ |
190 | ␉␉int subsequent␉= 0x4D00;␉␉// right arrow␊ |
191 | ␉␉int menu␉␉= 0x5000;␉␉// down arrow␊ |
192 | ␉␉␊ |
193 | ␉␉if ( gui.layout == VerticalLayout )␊ |
194 | ␉␉{␊ |
195 | ␉␉␉// set navigation keys for vertical layout␊ |
196 | ␉␉␉previous␉= 0x4800;␉␉// up arrow␊ |
197 | ␉␉␉subsequent␉= 0x5000;␉␉// down arrow␊ |
198 | ␉␉␉menu␉␉= 0x4B00;␉␉// right arrow␊ |
199 | ␉␉} ␊ |
200 | ␉␉␊ |
201 | ␉␉if ( key == previous )␊ |
202 | ␉␉{␊ |
203 | ␉␉␉if ( gMenuSelection > gMenuTop )␊ |
204 | ␉␉␉␉draw.f.selectionUp = 1;␊ |
205 | ␉␉␉else if ( gMenuTop > 0 )␊ |
206 | ␉␉␉␉draw.f.scrollDown = 1;␊ |
207 | ␉␉␉␊ |
208 | ␉␉}␊ |
209 | ␉␉␊ |
210 | ␉␉else if ( key == subsequent )␊ |
211 | ␉␉{␊ |
212 | ␉␉␉if ( gMenuSelection != gMenuBottom)␊ |
213 | ␉␉␉␉draw.f.selectionDown = 1;␊ |
214 | ␉␉␉else if ( gMenuBottom < ( gMenuItemCount - 1 ) )␊ |
215 | ␉␉␉␉draw.f.scrollUp = 1;␊ |
216 | ␉␉}␊ |
217 | ␉␉␊ |
218 | ␉␉else if ( key == menu )␊ |
219 | ␉␉{␊ |
220 | ␉␉␉if ( gui.menu.draw )␊ |
221 | ␉␉␉␉updateInfoMenu(key);␊ |
222 | ␉␉␉else␊ |
223 | ␉␉␉␉drawInfoMenu();␊ |
224 | ␉␉}␊ |
225 | ␉␉␊ |
226 | ␉␉else if ( gui.menu.draw )␊ |
227 | ␉␉{␊ |
228 | ␉␉␉res = updateInfoMenu(key);␊ |
229 | ␉␉␉␊ |
230 | ␉␉␉if ( res == CLOSE_INFO_MENU )␊ |
231 | ␉␉␉␉gui.menu.draw = false;␊ |
232 | ␉␉␉else␊ |
233 | ␉␉␉{␊ |
234 | ␉␉␉␉shouldboot = ( res != DO_NOT_BOOT );␊ |
235 | ␉␉␉␉␊ |
236 | ␉␉␉␉if ( shouldboot )␊ |
237 | ␉␉␉␉␉gui.menu.draw = false;␊ |
238 | ␉␉␉␉␊ |
239 | ␉␉␉␉switch (res)␊ |
240 | ␉␉␉␉{␊ |
241 | ␉␉␉␉␉case BOOT_NORMAL:␊ |
242 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
243 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
244 | ␉␉␉␉␉␉break;␊ |
245 | ␉␉␉␉␉␉␊ |
246 | ␉␉␉␉␉case BOOT_VERBOSE:␊ |
247 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
248 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
249 | ␉␉␉␉␉␉addBootArg(kVerboseModeFlag);␊ |
250 | ␉␉␉␉␉␉break;␊ |
251 | ␉␉␉␉␉␉␊ |
252 | ␉␉␉␉␉case BOOT_IGNORECACHE:␊ |
253 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
254 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
255 | ␉␉␉␉␉␉addBootArg(kIgnoreCachesFlag);␊ |
256 | ␉␉␉␉␉␉break;␊ |
257 | ␉␉␉␉␉␉␊ |
258 | /*␉␉␉␉␉␉␊ |
259 | ␉␉␉␉␉case BOOT_SAFEMODE:␊ |
260 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
261 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
262 | ␉␉␉␉␉␉addBootArg(kSafeModeFlag);␊ |
263 | ␉␉␉␉␉␉break;␊ |
264 | */␉␉␉␉␉␉␊ |
265 | ␉␉␉␉␉␉␊ |
266 | ␉␉␉␉␉case BOOT_SINGLEUSER:␊ |
267 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
268 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
269 | ␉␉␉␉␉␉addBootArg(kSingleUserModeFlag);␊ |
270 | ␉␉␉␉␉␉break;␊ |
271 | ␉␉␉␉}␊ |
272 | ␉␉␉␉␊ |
273 | ␉␉␉}␊ |
274 | ␉␉␉␊ |
275 | ␉␉}␉␊ |
276 | ␉␉␊ |
277 | ␉} else {␊ |
278 | ␉␉switch ( key )␊ |
279 | ␉␉{␊ |
280 | ␉case 0x4800: // Up Arrow␊ |
281 | ␉␉␉␉if ( gMenuSelection != gMenuTop )␊ |
282 | ␉␉␉␉{␊ |
283 | ␉␉␉␉␉draw.f.selectionUp = 1;␊ |
284 | ␉␉␉␉}␊ |
285 | ␉␉␉␉else if ( gMenuTop > 0 )␊ |
286 | ␉␉␉␉{␊ |
287 | ␉␉␉␉␉draw.f.scrollDown = 1;␊ |
288 | ␉␉␉␉}␊ |
289 | ␉␉␉␉break;␊ |
290 | ␉␉␉␉␊ |
291 | ␉␉␉case 0x5000: // Down Arrow␊ |
292 | ␉␉␉␉if ( gMenuSelection != gMenuBottom )␊ |
293 | ␉␉␉␉{␊ |
294 | ␉␉␉␉␉draw.f.selectionDown = 1;␊ |
295 | ␉␉␉␉}␊ |
296 | ␉␉␉␉else if ( gMenuBottom < (gMenuItemCount - 1) ) ␊ |
297 | ␉␉␉␉{␊ |
298 | ␉␉␉␉␉draw.f.scrollUp = 1;␊ |
299 | ␉␉␉␉}␊ |
300 | ␉␉␉␉break;␊ |
301 | ␉␉}␊ |
302 | ␉}␊ |
303 | ␉␊ |
304 | if ( draw.w )␊ |
305 | {␊ |
306 | if ( draw.f.scrollUp )␊ |
307 | {␊ |
308 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, 1);␊ |
309 | gMenuTop++; gMenuBottom++;␊ |
310 | ␉␉␉gMenuStart++; gMenuEnd++;␊ |
311 | draw.f.selectionDown = 1;␊ |
312 | }␊ |
313 | ␉␉␊ |
314 | if ( draw.f.scrollDown )␊ |
315 | {␊ |
316 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, -1);␊ |
317 | gMenuTop--; gMenuBottom--;␊ |
318 | gMenuStart--; gMenuEnd--;␊ |
319 | draw.f.selectionUp = 1;␊ |
320 | }␊ |
321 | ␉␉␊ |
322 | if ( draw.f.selectionUp || draw.f.selectionDown )␊ |
323 | {␊ |
324 | ␉␉␉␊ |
325 | ␉␉␉CursorState cursorState;␊ |
326 | ␉␉␉␊ |
327 | ␉␉␉// Set cursor at current position, and clear inverse video.␊ |
328 | ␉␉␉␊ |
329 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
330 | ␉␉␉{␊ |
331 | ␉␉␉␉changeCursor( 0, (gMenuRow + gMenuSelection - gMenuTop), kCursorTypeHidden, &cursorState );␊ |
332 | ␉␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 0 );␊ |
333 | ␉␉␉}␊ |
334 | ␉␉␉␊ |
335 | ␉␉␉if ( draw.f.selectionUp )␊ |
336 | ␉␉␉{␊ |
337 | ␉␉␉␉gMenuSelection--;␊ |
338 | ␉␉␉␉if(( gMenuSelection - gMenuStart) == -1 )␊ |
339 | ␉␉␉␉{␊ |
340 | ␉␉␉␉␉gMenuStart--;␊ |
341 | ␉␉␉␉␉gMenuEnd--;␊ |
342 | ␉␉␉␉}␊ |
343 | ␉␉␉␉␊ |
344 | ␉␉␉} else {␊ |
345 | ␉␉␉␉gMenuSelection++;␊ |
346 | ␉␉␉␉if(( gMenuSelection - ( gui.maxdevices - 1) - gMenuStart) > 0 )␊ |
347 | ␉␉␉␉{␊ |
348 | ␉␉␉␉␉gMenuStart++;␊ |
349 | ␉␉␉␉␉gMenuEnd++;␊ |
350 | ␉␉␉␉}␊ |
351 | ␉␉␉}␊ |
352 | ␉␉␉␊ |
353 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
354 | ␉␉␉{␊ |
355 | ␉␉␉␉moveCursor( 0, gMenuRow + gMenuSelection - gMenuTop );␊ |
356 | ␉␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 1 );␊ |
357 | ␉␉␉␉restoreCursor( &cursorState );␊ |
358 | ␉␉␉␉␊ |
359 | ␉␉␉}␊ |
360 | ␉␉␉else␊ |
361 | ␉␉␉{␊ |
362 | ␉␉␉␉drawDeviceList (gMenuStart, gMenuEnd, gMenuSelection);␊ |
363 | ␉␉␉}␊ |
364 | ␉␉␉␊ |
365 | ␉␉}␊ |
366 | ␉␉␊ |
367 | *paramPtr = gMenuItems[gMenuSelection].param; ␊ |
368 | moved = 1;␊ |
369 | }␊ |
370 | ␉␊ |
371 | ␉return moved;␊ |
372 | }␊ |
373 | ␊ |
374 | ␊ |
375 | static void GUI_showMenu( const MenuItem * items, int count,␊ |
376 | ␉␉␉␉␉␉ int selection, int row, int height )␊ |
377 | {␊ |
378 | int i;␊ |
379 | CursorState cursorState;␊ |
380 | ␉␊ |
381 | if ( items == NULL || count == 0 ) ␊ |
382 | ␉␉return;␊ |
383 | ␉␊ |
384 | // head and tail points to the start and the end of the list.␊ |
385 | // top and bottom points to the first and last visible items␊ |
386 | // in the menu window.␊ |
387 | ␉␊ |
388 | gMenuItems␉␉= items;␊ |
389 | gMenuRow␉␉= row;␊ |
390 | gMenuHeight␉␉= height;␊ |
391 | gMenuItemCount␉= count;␊ |
392 | gMenuTop␉␉= 0;␊ |
393 | gMenuBottom␉␉= min( count, height ) - 1;␊ |
394 | gMenuSelection␉= selection;␊ |
395 | ␉␊ |
396 | gMenuStart␉␉= 0;␊ |
397 | gMenuEnd␉ = min( count, gui.maxdevices ) - 1;␊ |
398 | ␉␊ |
399 | ␉// If the selected item is not visible, shift the list down.␊ |
400 | ␉␊ |
401 | if ( gMenuSelection > gMenuBottom )␊ |
402 | {␊ |
403 | gMenuTop += ( gMenuSelection - gMenuBottom );␊ |
404 | gMenuBottom = gMenuSelection;␊ |
405 | }␊ |
406 | ␉␊ |
407 | ␉if ( gMenuSelection > gMenuEnd )␊ |
408 | {␊ |
409 | ␉␉gMenuStart += ( gMenuSelection - gMenuEnd );␊ |
410 | gMenuEnd = gMenuSelection;␊ |
411 | }␊ |
412 | ␉␊ |
413 | ␉// Draw the visible items.␊ |
414 | ␉␊ |
415 | ␉if( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
416 | ␉{␊ |
417 | ␉␉drawDeviceList(gMenuStart, gMenuEnd, gMenuSelection);␊ |
418 | ␉}␊ |
419 | ␉else ␊ |
420 | ␉{␊ |
421 | ␉␉␊ |
422 | ␉␉changeCursor( 0, row, kCursorTypeHidden, &cursorState );␊ |
423 | ␉␉␊ |
424 | ␉␉for ( i = gMenuTop; i <= gMenuBottom; i++ )␊ |
425 | ␉␉{␊ |
426 | ␉␉␉printMenuItem( &items[i], (i == gMenuSelection) );␊ |
427 | ␉␉}␊ |
428 | ␉␉␊ |
429 | ␉␉restoreCursor( &cursorState );␊ |
430 | }␊ |
431 | }␊ |
432 | ␊ |
433 | ␊ |
434 | static void GUI_updateBootArgs( int key )␊ |
435 | {␊ |
436 | key &= kASCIIKeyMask;␊ |
437 | ␉␊ |
438 | switch ( key )␊ |
439 | {␊ |
440 | case kBackspaceKey:␊ |
441 | if ( gBootArgsPtr > gBootArgs )␊ |
442 | {␊ |
443 | int x, y, t;␊ |
444 | getCursorPositionAndType( &x, &y, &t );␊ |
445 | if ( x == 0 && y )␊ |
446 | {␊ |
447 | x = 80; y--;␊ |
448 | }␊ |
449 | if (x)␊ |
450 | ␉␉␉␉␉x--;␊ |
451 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
452 | ␉␉␉␉{␊ |
453 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
454 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
455 | ␉␉␉␉} else␊ |
456 | ␉␉␉␉{␊ |
457 | ␉␉␉␉␉updateGraphicBootPrompt(kBackspaceKey);␊ |
458 | ␉␉␉␉}␊ |
459 | ␉␉␉␉␊ |
460 | ␉␉␉␉*gBootArgsPtr-- = '\0';␊ |
461 | ␉␉␉}␊ |
462 | ␊ |
463 | ␉␉␉break;␊ |
464 | ␉␉␉␊ |
465 | default:␊ |
466 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
467 | {␊ |
468 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
469 | ␉␉␉␉{␊ |
470 | ␉␉␉␉␉putchar(key); // echo to screen␊ |
471 | ␉␉␉␉}␊ |
472 | ␉␉␉␉else␊ |
473 | ␉␉␉␉{␊ |
474 | ␉␉␉␉␉updateGraphicBootPrompt(key);␊ |
475 | ␉␉␉␉}␊ |
476 | ␉␉␉␉*gBootArgsPtr++ = key;␊ |
477 | ␉␉␉}␊ |
478 | ␊ |
479 | ␉␉␉break;␊ |
480 | }␊ |
481 | }␊ |
482 | ␊ |
483 | ␊ |
484 | static void GUI_showBootPrompt(int row, bool visible)␊ |
485 | {␊ |
486 | ␉extern char bootPrompt[];␊ |
487 | ␉␊ |
488 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
489 | ␉{␊ |
490 | ␉␉changeCursor( 0, row, kCursorTypeUnderline, 0 ); ␊ |
491 | ␉␉clearScreenRows( row, kScreenLastRow );␊ |
492 | ␉}␊ |
493 | ␉␊ |
494 | ␉clearBootArgs();␊ |
495 | ␉␊ |
496 | ␉if (visible)␊ |
497 | ␉{␊ |
498 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) ␊ |
499 | ␉␉{␊ |
500 | ␉␉␉if (gEnableCDROMRescan)␊ |
501 | ␉␉␉{␊ |
502 | ␉␉␉␉printf( GUI_bootRescanPrompt );␊ |
503 | ␉␉␉} ␊ |
504 | ␉␉␉else␊ |
505 | ␉␉␉{␊ |
506 | ␉␉␉␉printf( bootPrompt );␊ |
507 | ␉␉␉}␊ |
508 | ␉␉}␊ |
509 | ␉} ␊ |
510 | ␉else␊ |
511 | ␉{␊ |
512 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
513 | ␉␉{␊ |
514 | ␉␉␉clearGraphicBootPrompt();␊ |
515 | ␉␉} ␊ |
516 | ␉␉else␊ |
517 | ␉␉{␊ |
518 | ␉␉␉printf("Press Enter to start up the foreign OS. ");␊ |
519 | ␉␉}␊ |
520 | ␉}␊ |
521 | }␊ |
522 | ␊ |
523 | ␊ |
524 | void GUI_clearBootArgs(void)␊ |
525 | {␊ |
526 | ␉gBootArgsPtr = gBootArgs;␊ |
527 | ␉memset(gBootArgs, '\0', BOOT_STRING_LEN);␊ |
528 | ␉␊ |
529 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) ␊ |
530 | ␉{␊ |
531 | ␉␉clearGraphicBootPrompt();␊ |
532 | ␉}␊ |
533 | }␊ |
534 | ␊ |
535 | ␊ |
536 | int GUI_getBootOptions(bool firstRun)␊ |
537 | {␊ |
538 | ␉int i;␊ |
539 | ␉int key;␊ |
540 | ␉int nextRow;␊ |
541 | ␉int timeout;␊ |
542 | ␉int bvCount;␊ |
543 | ␉BVRef bvr;␊ |
544 | ␉BVRef menuBVR;␊ |
545 | ␉bool showPrompt, newShowPrompt, isCDROM;␊ |
546 | ␉␊ |
547 | ␉// Initialize default menu selection entry.␊ |
548 | ␉gBootVolume = menuBVR = selectBootVolume(bvChain);␊ |
549 | ␉␊ |
550 | ␉if (biosDevIsCDROM(gBIOSDev))␊ |
551 | ␉{␊ |
552 | ␉␉isCDROM = true;␊ |
553 | ␉␉DBG("GUI gBIOSDev is CDROM\n");␊ |
554 | ␉} ␊ |
555 | ␉else␊ |
556 | ␉{␊ |
557 | ␉␉isCDROM = false;␊ |
558 | ␉}␊ |
559 | ␉␊ |
560 | ␉// ensure we're in graphics mode if gui is setup␊ |
561 | ␉if (gui.initialised && bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
562 | ␉{␊ |
563 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
564 | ␉}␊ |
565 | ␉␊ |
566 | ␉// Clear command line boot arguments␊ |
567 | ␉clearBootArgs();␊ |
568 | ␉␊ |
569 | ␉// Allow user to override default timeout.␊ |
570 | ␉if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->bootConfig))␊ |
571 | ␉{␊ |
572 | ␉␉/* If there is no timeout key in the file use the default timeout␊ |
573 | ␉␉ which is different for CDs vs. hard disks. However, if not booting␊ |
574 | ␉␉ a CD and no config file could be loaded set the timeout␊ |
575 | ␉␉ to zero which causes the menu to display immediately.␊ |
576 | ␉␉ This way, if no partitions can be found, that is the disk is unpartitioned␊ |
577 | ␉␉ or simply cannot be read) then an empty menu is displayed.␊ |
578 | ␉␉ If some partitions are found, for example a Windows partition, then␊ |
579 | ␉␉ these will be displayed in the menu as foreign partitions.␊ |
580 | ␉␉ */␊ |
581 | ␉␉if (isCDROM)␊ |
582 | ␉␉{␊ |
583 | ␉␉␉timeout = kCDBootTimeout;␊ |
584 | ␉␉}␊ |
585 | ␉␉else ␊ |
586 | ␉␉{␊ |
587 | ␉␉␉timeout = sysConfigValid ? kBootTimeout : 0;␊ |
588 | ␉␉}␊ |
589 | ␉}␊ |
590 | ␉␊ |
591 | ␉if (timeout < 0) ␊ |
592 | ␉{␊ |
593 | ␉␉gBootMode |= kBootModeQuiet;␊ |
594 | ␉}␊ |
595 | ␉␊ |
596 | ␉// If the user is holding down a modifier key, enter safe mode.␊ |
597 | ␉if ((readKeyboardShiftFlags() & 0x0F) != 0) ␊ |
598 | ␉{␊ |
599 | ␉␉␊ |
600 | ␉␉//gBootMode |= kBootModeSafe;␊ |
601 | ␉}␊ |
602 | ␉␊ |
603 | ␉// Checking user pressed keys␊ |
604 | ␉bool f8press = false, spress = false, vpress = false;␊ |
605 | ␉while (readKeyboardStatus())␊ |
606 | ␉{␊ |
607 | ␉␉key = bgetc ();␊ |
608 | ␉␉if (key == 0x4200) f8press = true;␊ |
609 | ␉␉if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;␊ |
610 | ␉␉if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;␊ |
611 | ␉}␊ |
612 | ␉// If user typed F8, abort quiet mode, and display the menu.␊ |
613 | ␉if (f8press)␊ |
614 | ␉{␊ |
615 | ␉␉gBootMode &= ~kBootModeQuiet;␊ |
616 | ␉␉timeout = 0;␊ |
617 | ␉}␊ |
618 | ␉// If user typed 'v' or 'V', boot in verbose mode.␊ |
619 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && vpress)␊ |
620 | ␉{␊ |
621 | ␉␉addBootArg(kVerboseModeFlag);␊ |
622 | ␉}␊ |
623 | ␉// If user typed 's' or 'S', boot in single user mode.␊ |
624 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && spress)␊ |
625 | ␉{␊ |
626 | ␉␉addBootArg(kSingleUserModeFlag);␊ |
627 | ␉}␊ |
628 | ␉␊ |
629 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
630 | ␉{␊ |
631 | ␉␉setCursorPosition(0, 0, 0);␊ |
632 | ␉␉clearScreenRows(0, kScreenLastRow);␊ |
633 | ␉␉if (!(gBootMode & kBootModeQuiet)) ␊ |
634 | ␉␉{␊ |
635 | ␉␉␉// Display banner and show hardware info.␊ |
636 | ␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
637 | ␉␉␉printf(getVBEInfoString());␊ |
638 | ␉␉}␊ |
639 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
640 | ␉␉msglog("GUI_Scanning device %x...", gBIOSDev);␊ |
641 | ␉}␊ |
642 | ␉␊ |
643 | ␉// When booting from CD, default to hard drive boot when possible. ␊ |
644 | ␉if (isCDROM && firstRun)␊ |
645 | ␉{␊ |
646 | ␉␉const char *val;␊ |
647 | ␉␉char *prompt = NULL;␊ |
648 | ␉␉char *name = NULL;␊ |
649 | ␉␉int cnt;␊ |
650 | ␉␉int optionKey;␊ |
651 | ␉␉␊ |
652 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig))␊ |
653 | ␉␉{␊ |
654 | ␉␉␉prompt = malloc(cnt + 1);␊ |
655 | ␉␉␉strncat(prompt, val, cnt);␊ |
656 | ␉␉}␊ |
657 | ␉␉else ␊ |
658 | ␉␉{␊ |
659 | ␉␉␉name = malloc(80);␊ |
660 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 79, false);␊ |
661 | ␉␉␉prompt = malloc(256);␊ |
662 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
663 | ␉␉␉free(name);␊ |
664 | ␉␉}␊ |
665 | ␉␉␊ |
666 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig ))␊ |
667 | ␉␉{␊ |
668 | ␉␉␉// The key specified is a special key.␊ |
669 | ␉␉}␊ |
670 | ␉␉else␊ |
671 | ␉␉{␊ |
672 | ␉␉␉// Default to F8.␊ |
673 | ␉␉␉optionKey = 0x4200;␊ |
674 | ␉␉}␊ |
675 | ␉␉␊ |
676 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
677 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
678 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
679 | ␉␉if (timeout != 0) {␊ |
680 | ␉␉␉key = GUI_countdown(prompt, kMenuTopRow, timeout);␊ |
681 | ␉␉} ␊ |
682 | ␉␉else ␊ |
683 | ␉␉{␊ |
684 | ␉␉␉key = optionKey;␊ |
685 | ␉␉}␊ |
686 | ␉␉␊ |
687 | ␉␉if (prompt != NULL)␊ |
688 | ␉␉{␊ |
689 | ␉␉␉free(prompt);␊ |
690 | ␉␉}␊ |
691 | ␉␉␊ |
692 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
693 | ␉␉␊ |
694 | ␉␉// Hit the option key ?␊ |
695 | ␉␉if (key == optionKey) ␊ |
696 | ␉␉{␊ |
697 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
698 | ␉␉␉timeout = 0;␊ |
699 | ␉␉} ␊ |
700 | ␉␉else ␊ |
701 | ␉␉{␊ |
702 | ␉␉␉key = key & 0xFF;␊ |
703 | ␉␉␉␊ |
704 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
705 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h')␊ |
706 | ␉␉␉{␊ |
707 | ␉␉␉␉BVRef bvr;␊ |
708 | ␉␉␉␉␊ |
709 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
710 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next)␊ |
711 | ␉␉␉␉{␊ |
712 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev)␊ |
713 | ␉␉␉␉␉{␊ |
714 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
715 | ␉␉␉␉␉}␊ |
716 | ␉␉␉␉}␊ |
717 | ␉␉␉}␊ |
718 | ␉␉␉goto done;␊ |
719 | ␉␉}␊ |
720 | ␉}␊ |
721 | ␉␊ |
722 | ␉if (gBootMode & kBootModeQuiet)␊ |
723 | ␉{␊ |
724 | ␉␉// No input allowed from user.␊ |
725 | ␉␉goto done;␊ |
726 | ␉}␊ |
727 | ␉␊ |
728 | ␉if (firstRun && timeout > 0 && GUI_countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0)␊ |
729 | ␉{␊ |
730 | ␉␉// If the user is holding down a modifier key,␊ |
731 | ␉␉// enter safe mode.␊ |
732 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0)␊ |
733 | ␉␉{␊ |
734 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
735 | ␉␉}␊ |
736 | ␉␉goto done;␊ |
737 | ␉}␊ |
738 | ␉␊ |
739 | ␉if (gDeviceCount)␊ |
740 | ␉{␊ |
741 | ␉␉// Allocate memory for an array of menu items.␊ |
742 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
743 | ␉␉if (menuItems == NULL) ␊ |
744 | ␉␉{␊ |
745 | ␉␉␉goto done;␊ |
746 | ␉␉}␊ |
747 | ␉␉␊ |
748 | ␉␉// Associate a menu item for each BVRef.␊ |
749 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next)␊ |
750 | ␉␉{␊ |
751 | //␉␉␉DBG("GUI menu for device %d\n", bvr->biosdev);␊ |
752 | ␉␉␉if (bvr->visible)␊ |
753 | ␉␉␉{␊ |
754 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true);␊ |
755 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
756 | ␉␉␉␉if (bvr == menuBVR)␊ |
757 | ␉␉␉␉{␊ |
758 | ␉␉␉␉␉selectIndex = i;␊ |
759 | ␉␉␉␉}␊ |
760 | ␉␉␉␉i--;␊ |
761 | ␉␉␉}␊ |
762 | ␉␉}␊ |
763 | ␉}␊ |
764 | ␉␊ |
765 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
766 | ␉{␊ |
767 | ␉␉// redraw the background buffer␊ |
768 | ␉␉gui.logo.draw = true;␊ |
769 | ␉␉drawBackground();␊ |
770 | ␉␉gui.devicelist.draw = true;␊ |
771 | ␉␉gui.redraw = true;␊ |
772 | ␉␉if (!(gBootMode & kBootModeQuiet))␊ |
773 | ␉␉{␊ |
774 | ␉␉␉bool showBootBanner = false;␊ |
775 | ␉␉␉␊ |
776 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
777 | ␉␉␉if (getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->bootConfig) && showBootBanner)␊ |
778 | ␉␉␉{␊ |
779 | ␉␉␉␉// Display banner and show hardware info.␊ |
780 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
781 | ␉␉␉}␊ |
782 | ␉␉␉␊ |
783 | ␉␉␉// redraw background␊ |
784 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
785 | ␉␉}␊ |
786 | ␉}␊ |
787 | ␉else ␊ |
788 | ␉{␊ |
789 | ␉␉// Clear screen and hide the blinking cursor.␊ |
790 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
791 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
792 | ␉}␊ |
793 | ␉␊ |
794 | ␉nextRow = kMenuTopRow;␊ |
795 | ␉showPrompt = true;␊ |
796 | ␉␊ |
797 | ␉if (gDeviceCount)␊ |
798 | ␉{␊ |
799 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
800 | ␉␉{␊ |
801 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
802 | ␉␉}␊ |
803 | ␉␉GUI_showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
804 | ␉␉nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;␊ |
805 | ␉}␊ |
806 | ␉␊ |
807 | ␉// Show the boot prompt.␊ |
808 | ␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
809 | ␉GUI_showBootPrompt( nextRow, showPrompt );␊ |
810 | ␉␊ |
811 | ␉do {␊ |
812 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
813 | ␉␉{␊ |
814 | ␉␉␉// redraw background␊ |
815 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
816 | ␉␉␉// reset cursor co-ords␊ |
817 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
818 | ␉␉}␊ |
819 | ␉␉key = getc();␊ |
820 | ␉␉GUI_updateMenu( key, (void **) &menuBVR );␊ |
821 | ␉␉newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
822 | ␉␉␊ |
823 | ␉␉if (newShowPrompt != showPrompt)␊ |
824 | ␉␉{␊ |
825 | ␉␉␉showPrompt = newShowPrompt;␊ |
826 | ␉␉␉GUI_showBootPrompt( nextRow, showPrompt );␊ |
827 | ␉␉}␊ |
828 | ␉␉␊ |
829 | ␉␉if (showPrompt)␊ |
830 | ␉␉{␊ |
831 | ␉␉␉GUI_updateBootArgs(key);␊ |
832 | ␉␉}␊ |
833 | ␉␉␊ |
834 | ␉␉switch (key)␊ |
835 | ␉␉{␊ |
836 | ␉␉␉case kReturnKey:␊ |
837 | ␉␉␉␉if (gui.menu.draw)␊ |
838 | ␉␉␉␉{ ␊ |
839 | ␉␉␉␉␉key=0;␊ |
840 | ␉␉␉␉␉break;␊ |
841 | ␉␉␉␉}␊ |
842 | ␉␉␉␉if (*gBootArgs == '?')␊ |
843 | ␉␉␉␉{␊ |
844 | ␉␉␉␉␉char * argPtr = gBootArgs;␊ |
845 | ␉␉␉␉␉␊ |
846 | ␉␉␉␉␉// Skip the leading "?" character.␊ |
847 | ␉␉␉␉␉argPtr++;␊ |
848 | ␉␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
849 | ␉␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
850 | ␉␉␉␉␉␊ |
851 | ␉␉␉␉␉/*␊ |
852 | ␉␉␉␉␉ * TODO: this needs to be refactored.␊ |
853 | ␉␉␉␉␉ */␊ |
854 | ␉␉␉␉␉if (strcmp( booterCommand, "video" ) == 0)␊ |
855 | ␉␉␉␉␉{␊ |
856 | ␉␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
857 | ␉␉␉␉␉␉{␊ |
858 | ␉␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
859 | ␉␉␉␉␉␉}␊ |
860 | ␉␉␉␉␉␉else␊ |
861 | ␉␉␉␉␉␉{␊ |
862 | ␉␉␉␉␉␉␉printVBEModeInfo();␊ |
863 | ␉␉␉␉␉␉}␊ |
864 | ␉␉␉␉␉}␊ |
865 | ␉␉␉␉␉else if ( strcmp( booterCommand, "memory" ) == 0)␊ |
866 | ␉␉␉␉␉{␊ |
867 | ␉␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE ) ␊ |
868 | ␉␉␉␉␉␉{␊ |
869 | ␉␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
870 | ␉␉␉␉␉␉}␊ |
871 | ␉␉␉␉␉␉else␊ |
872 | ␉␉␉␉␉␉{␊ |
873 | ␉␉␉␉␉␉␉printMemoryInfo();␊ |
874 | ␉␉␉␉␉␉}␊ |
875 | ␉␉␉␉␉}␊ |
876 | ␉␉␉␉␉else if (strcmp(booterCommand, "lspci") == 0)␊ |
877 | ␉␉␉␉␉{␊ |
878 | ␉␉␉␉␉␉lspci();␊ |
879 | ␉␉␉␉␉}␊ |
880 | ␉␉␉␉␉else if (strcmp(booterCommand, "more") == 0)␊ |
881 | ␉␉␉␉␉{␊ |
882 | ␉␉␉␉␉␉showTextFile(booterParam);␊ |
883 | ␉␉␉␉␉}␊ |
884 | ␉␉␉␉␉else if (strcmp(booterCommand, "rd") == 0)␊ |
885 | ␉␉␉␉␉{␊ |
886 | ␉␉␉␉␉␉processRAMDiskCommand(&argPtr, booterParam);␊ |
887 | ␉␉␉␉␉} ␊ |
888 | ␉␉␉␉␉else if (strcmp(booterCommand, "norescan") == 0)␊ |
889 | ␉␉␉␉␉{␊ |
890 | ␉␉␉␉␉␉if (gEnableCDROMRescan)␊ |
891 | ␉␉␉␉␉␉{␊ |
892 | ␉␉␉␉␉␉␉gEnableCDROMRescan = false;␊ |
893 | ␉␉␉␉␉␉␉break;␊ |
894 | ␉␉␉␉␉␉}␊ |
895 | ␉␉␉␉␉} ␊ |
896 | ␉␉␉␉␉else␊ |
897 | ␉␉␉␉␉{␊ |
898 | ␉␉␉␉␉␉showHelp();␊ |
899 | ␉␉␉␉␉}␊ |
900 | ␉␉␉␉␉key = 0;␊ |
901 | ␉␉␉␉␉GUI_showBootPrompt(nextRow, showPrompt);␊ |
902 | ␉␉␉␉␉break;␊ |
903 | ␉␉␉␉}␊ |
904 | ␉␉␉␉gBootVolume = menuBVR;␊ |
905 | ␉␉␉␉setRootVolume(menuBVR);␊ |
906 | ␉␉␉␉gBIOSDev = menuBVR->biosdev;␊ |
907 | ␉␉␉␉break;␊ |
908 | ␉␉␉␉␊ |
909 | ␉␉␉case kEscapeKey:␊ |
910 | ␉␉␉␉clearBootArgs();␊ |
911 | ␉␉␉␉break;␊ |
912 | ␉␉␉␉␊ |
913 | ␉␉␉case kF5Key:␊ |
914 | ␉␉␉␉// New behavior:␊ |
915 | ␉␉␉␉// Clear gBootVolume to restart the loop␊ |
916 | ␉␉␉␉// if the user enabled rescanning the optical drive.␊ |
917 | ␉␉␉␉// Otherwise boot the default boot volume.␊ |
918 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
919 | ␉␉␉␉{␊ |
920 | ␉␉␉␉␉gBootVolume = NULL;␊ |
921 | ␉␉␉␉␉clearBootArgs();␊ |
922 | ␉␉␉␉}␊ |
923 | ␉␉␉␉break;␊ |
924 | ␉␉␉␉␊ |
925 | ␉␉␉case kF10Key:␊ |
926 | ␉␉␉␉gScanSingleDrive = false;␊ |
927 | ␉␉␉␉scanDisks(gBIOSDev, &bvCount);␊ |
928 | ␉␉␉␉gBootVolume = NULL;␊ |
929 | ␉␉␉␉clearBootArgs();␊ |
930 | ␉␉␉␉key = 0;␊ |
931 | ␉␉␉␉break;␊ |
932 | ␉␉␉␉␊ |
933 | ␉␉␉case kTabKey:␊ |
934 | ␉␉␉␉// New behavior:␊ |
935 | ␉␉␉␉// Switch between text & graphic interfaces␊ |
936 | ␉␉␉␉// Only Permitted if started in graphics interface␊ |
937 | ␉␉␉␉if (useGUI)␊ |
938 | ␉␉␉␉{␊ |
939 | ␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
940 | ␉␉␉␉␉{␊ |
941 | ␉␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
942 | ␉␉␉␉␉␉␊ |
943 | ␉␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
944 | ␉␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
945 | ␉␉␉␉␉␉␊ |
946 | ␉␉␉␉␉␉// Display banner and show hardware info.␊ |
947 | ␉␉␉␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
948 | ␉␉␉␉␉␉printf(getVBEInfoString());␊ |
949 | ␉␉␉␉␉␉␊ |
950 | ␉␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
951 | ␉␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
952 | ␉␉␉␉␉␉␊ |
953 | ␉␉␉␉␉␉nextRow = kMenuTopRow;␊ |
954 | ␉␉␉␉␉␉showPrompt = true;␊ |
955 | ␉␉␉␉␉␉␊ |
956 | ␉␉␉␉␉␉if (gDeviceCount)␊ |
957 | ␉␉␉␉␉␉{␊ |
958 | ␉␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
959 | ␉␉␉␉␉␉␉GUI_showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
960 | ␉␉␉␉␉␉␉nextRow += min(gDeviceCount, kMenuMaxItems) + 3;␊ |
961 | ␉␉␉␉␉␉}␊ |
962 | ␉␉␉␉␉␉␊ |
963 | ␉␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
964 | ␉␉␉␉␉␉GUI_showBootPrompt(nextRow, showPrompt);␊ |
965 | ␉␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
966 | ␉␉␉␉␉} ␊ |
967 | ␉␉␉␉␉else ␊ |
968 | ␉␉␉␉␉{␊ |
969 | ␉␉␉␉␉␉gui.redraw = true;␊ |
970 | ␉␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
971 | ␉␉␉␉␉␉updateVRAM();␊ |
972 | ␉␉␉␉␉}␊ |
973 | ␉␉␉␉}␊ |
974 | ␉␉␉␉key = 0;␊ |
975 | ␉␉␉␉break;␊ |
976 | ␉␉␉␉␊ |
977 | ␉␉␉default:␊ |
978 | ␉␉␉␉key = 0;␊ |
979 | ␉␉␉␉break;␊ |
980 | ␉␉}␊ |
981 | ␉} while (0 == key);␊ |
982 | ␉␊ |
983 | done:␊ |
984 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
985 | ␉{␊ |
986 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
987 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
988 | ␉}␊ |
989 | ␉shouldboot = false;␊ |
990 | ␉gui.menu.draw = false;␊ |
991 | ␉if (menuItems)␊ |
992 | ␉{␊ |
993 | ␉␉free(menuItems);␊ |
994 | ␉␉menuItems = NULL;␊ |
995 | ␉}␊ |
996 | ␉return 0;␊ |
997 | }␊ |
998 | ␊ |
999 | ␊ |
1000 | ␊ |
1001 | int GUI_error(const char * fmt, ...)␊ |
1002 | {␊ |
1003 | va_list ap;␊ |
1004 | gErrors = true;␊ |
1005 | va_start(ap, fmt);␊ |
1006 | ␉␊ |
1007 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
1008 | ␉{␊ |
1009 | ␉␉prf(fmt, ap, putchar, 0);␊ |
1010 | }␊ |
1011 | ␉else␊ |
1012 | ␉{␊ |
1013 | ␉␉vprf(fmt, ap);␊ |
1014 | ␉}␊ |
1015 | ␉␊ |
1016 | ␉va_end(ap);␊ |
1017 | return(0);␊ |
1018 | }␊ |
1019 | ␊ |
1020 | int GUI_verbose(const char * fmt, ...)␊ |
1021 | {␊ |
1022 | va_list ap;␊ |
1023 | ␊ |
1024 | ␉va_start(ap, fmt);␊ |
1025 | if (gVerboseMode)␊ |
1026 | {␊ |
1027 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
1028 | ␉␉{␊ |
1029 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
1030 | ␉␉}␊ |
1031 | ␉␉else␊ |
1032 | ␉␉{␊ |
1033 | ␉␉␉vprf(fmt, ap);␊ |
1034 | ␉␉}␊ |
1035 | }␊ |
1036 | ␉␊ |
1037 | ␉/* Kabyl: BooterLog */␊ |
1038 | ␉struct putc_info pi;␊ |
1039 | ␉␊ |
1040 | ␉if (!msgbuf)␊ |
1041 | ␉␉return 0;␊ |
1042 | ␉␊ |
1043 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
1044 | ␉␉return 0;␊ |
1045 | ␉pi.str = cursor;␊ |
1046 | ␉pi.last_str = 0;␊ |
1047 | ␉prf(fmt, ap, sputc, &pi);␊ |
1048 | ␉cursor += strlen((char *)cursor);␊ |
1049 | ␉␊ |
1050 | ␉␊ |
1051 | va_end(ap);␊ |
1052 | return(0);␊ |
1053 | }␊ |
1054 | ␊ |
1055 | int GUI_printf(const char * fmt, ...)␊ |
1056 | {␊ |
1057 | va_list ap;␊ |
1058 | ␉va_start(ap, fmt);␊ |
1059 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
1060 | ␉{␊ |
1061 | ␉␉prf(fmt, ap, putchar, 0);␊ |
1062 | ␉}␊ |
1063 | ␉else␊ |
1064 | ␉{␊ |
1065 | ␉␉vprf(fmt, ap);␊ |
1066 | ␉}␊ |
1067 | ␉␊ |
1068 | ␉/* Kabyl: BooterLog */␊ |
1069 | ␉struct putc_info pi;␊ |
1070 | ␉␊ |
1071 | ␉if (!msgbuf)␊ |
1072 | ␉␉return 0;␊ |
1073 | ␉␊ |
1074 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
1075 | ␉␉return 0;␊ |
1076 | ␉pi.str = cursor;␊ |
1077 | ␉pi.last_str = 0;␊ |
1078 | ␉prf(fmt, ap, sputc, &pi);␊ |
1079 | ␉cursor += strlen((char *)cursor);␊ |
1080 | ␉␊ |
1081 | ␉va_end(ap);␊ |
1082 | return 0;␊ |
1083 | }␊ |
1084 | ␊ |
1085 | void GUI_stop(const char * fmt, ...)␊ |
1086 | {␊ |
1087 | ␉va_list ap;␊ |
1088 | ␉␊ |
1089 | ␉printf("\n");␊ |
1090 | ␉va_start(ap, fmt);␊ |
1091 | ␉␊ |
1092 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
1093 | ␉{␊ |
1094 | ␉␉prf(fmt, ap, putchar, 0);␊ |
1095 | ␉} ␊ |
1096 | ␉else ␊ |
1097 | ␉{␊ |
1098 | ␉␉vprf(fmt, ap);␊ |
1099 | ␉}␊ |
1100 | ␉va_end(ap);␊ |
1101 | ␉␊ |
1102 | ␉printf("\nThis is a non recoverable error! System HALTED!!!");␊ |
1103 | ␉halt();␊ |
1104 | ␉while (1);␊ |
1105 | }␊ |
1106 | ␊ |
1107 | void GUI_showHelp(void)␊ |
1108 | {␊ |
1109 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
1110 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1111 | ␉} else {␊ |
1112 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1113 | ␉}␊ |
1114 | }␊ |
1115 | |