Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/modules/GUI/GUI_module.c

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

Archive Download this file

Revision: 655