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