Home | History | Annotate | Line # | Download | only in pbsdboot
main.c revision 1.33
      1 /*	$NetBSD: main.c,v 1.33 2000/03/19 11:10:57 takemura Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999 Shin Takemura.
      5  * All rights reserved.
      6  *
      7  * This software is part of the PocketBSD.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by the PocketBSD project
     20  *	and its contributors.
     21  * 4. Neither the name of the project nor the names of its contributors
     22  *    may be used to endorse or promote products derived from this software
     23  *    without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  */
     38 #include <pbsdboot.h>
     39 #include <commctrl.h>
     40 #include <res/resource.h>
     41 
     42 /*
     43  * If you modify this program and update pbsdboot.uu,
     44  * change version string which is coded in main.c
     45  * appropriately.
     46  *
     47  * The version string is in format:
     48  *
     49  *   Version A.B.C YYYY.MM.DD
     50  *
     51  * in where:
     52  *
     53  *   A: Don't change this.
     54  *   B: Increment this number if you change program's behavior,
     55  *      fix some bugs or add new features.
     56  *   C: Increment this number if you change/add some
     57  *      parameters, constants, windows' resources.
     58  *   YYYY.MM.DD: date
     59  */
     60 TCHAR *version_string =
     61 	TEXT("PocketBSD boot loader\r\n")
     62 	TEXT("Version 1.11.0 2000.03.19\r\n")
     63 #if ( _WIN32_WCE < 200 )
     64 	TEXT("Compiled for WinCE 1.01\r\n")
     65 #else
     66 	TEXT("Compiled for WinCE 2.00\r\n")
     67 #endif
     68 	TEXT("\r\n")
     69 	TEXT("Copyright(C) 1999 Shin Takemura,\r\n")
     70 	TEXT("All rights reserved.\r\n")
     71 	TEXT("\r\n")
     72 	TEXT("http://www.netbsd.org/Ports/hpcmips\r\n");
     73 
     74 /*-----------------------------------------------------------------------------
     75 
     76   type difinitions
     77 
     78 -----------------------------------------------------------------------------*/
     79 enum {
     80 	UPDATE_DLGBOX,
     81 	UPDATE_DATA,
     82 };
     83 
     84 struct fb_type {
     85 	int type;
     86 	TCHAR *name;
     87 };
     88 
     89 struct fb_setting {
     90 	TCHAR *name;
     91 	int type;
     92 	int width, height, linebytes;
     93 	long addr;
     94 	unsigned long platid_cpu, platid_machine;
     95 };
     96 
     97 /*-----------------------------------------------------------------------------
     98 
     99   variable declarations
    100 
    101 -----------------------------------------------------------------------------*/
    102 HINSTANCE  hInst = NULL;
    103 HWND		hWndMain;
    104 HWND		hWndCB = NULL;
    105 HWND		hDlgLoad = NULL;
    106 unsigned int	dlgStatus;
    107 int		user_define_idx;
    108 
    109 /*-----------------------------------------------------------------------------
    110 
    111   data
    112 
    113 -----------------------------------------------------------------------------*/
    114 TCHAR szAppName[ ] = TEXT("PocketBSD boot");
    115 TCHAR szTitle[ ]   = TEXT("Welcome to PocketBSD!");
    116 
    117 /*
    118  * Wince_conf  identify executable binary file.
    119  */
    120 #if ( _WIN32_WCE < 200 )
    121 static char *wince_conf = "Compiled for WinCE 1.01";
    122 #else
    123 static char *wince_conf = "Compiled for WinCE 2.00";
    124 #endif
    125 
    126 struct fb_type fb_types[] = {
    127 	{ BIFB_D2_M2L_3,	TEXT(BIFBN_D2_M2L_3)	},
    128 	{ BIFB_D2_M2L_3x2,	TEXT(BIFBN_D2_M2L_3x2)	},
    129 	{ BIFB_D2_M2L_0,	TEXT(BIFBN_D2_M2L_0)	},
    130 	{ BIFB_D8_00,		TEXT(BIFBN_D8_00)	},
    131 	{ BIFB_D8_FF,		TEXT(BIFBN_D8_FF)	},
    132 	{ BIFB_D16_0000,	TEXT(BIFBN_D16_0000)	},
    133 	{ BIFB_D16_FFFF,	TEXT(BIFBN_D16_FFFF)	},
    134 };
    135 
    136 int fb_size[] = {
    137 	160, 240, 320, 400, 480, 600, 640,
    138 	768, 800, 1024, 1150, 1280, 1600
    139 };
    140 
    141 int fb_bpl[] = {
    142 	40, 80, 128, 160, 240, 256, 320,
    143 	384, 400, 480, 512, 600, 640, 768, 800, 1024, 1150, 1280, 1600
    144 };
    145 
    146 struct fb_setting fb_settings[] = {
    147 	/*
    148 	 * You must choose fb_type to make the screen look black-on-white.
    149 	 * (Foreground color is black and background color is white.)
    150 	 */
    151 	{ NULL, BIFB_D2_M2L_3,
    152 		320, 240, 80, 0xa000000,
    153 		PLATID_UNKNOWN, PLATID_UNKNOWN },
    154 	{ TEXT("FreeStyle"), BIFB_D2_M2L_3,
    155 		320, 240, 80, 0xa000000,
    156 		PLATID_CPU_MIPS_VR_41XX, PLATID_MACH_EVEREX_FREESTYLE_AXX },
    157 	{ TEXT("FreeStyle(Small Font)"), BIFB_D2_M2L_3x2,
    158 		640, 240, 80, 0xa000000,
    159 		PLATID_CPU_MIPS_VR_41XX, PLATID_MACH_EVEREX_FREESTYLE_AXX },
    160 	{ TEXT("MobileGear MC-CS11"), BIFB_D2_M2L_0,
    161 		480, 240, 256, 0xa000000,
    162 		PLATID_CPU_MIPS_VR_4102, PLATID_MACH_NEC_MCCS_11 },
    163 	{ TEXT("MobileGear MC-CS12"), BIFB_D2_M2L_0,
    164 		480, 240, 256, 0xa000000,
    165 		PLATID_CPU_MIPS_VR_4102, PLATID_MACH_NEC_MCCS_12 },
    166 	{ TEXT("MobileGear MC-CS13"), BIFB_D2_M2L_0,
    167 		480, 240, 256, 0xa000000,
    168 		PLATID_CPU_MIPS_VR_4102, PLATID_MACH_NEC_MCCS_13 },
    169 	{ TEXT("MobileGearII MC-R300"), BIFB_D2_M2L_0,
    170 		640, 240, 256, 0xa000000,
    171 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_300 },
    172 	{ TEXT("MobileGearII for DoCoMo"), BIFB_D2_M2L_0,
    173 		640, 240, 256, 0xa000000,
    174 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_FORDOCOMO },
    175 	{ TEXT("MobileGearII MC-R320"), BIFB_D2_M2L_0,
    176 		640, 240, 160, 0xa000000,
    177 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_320 },
    178 	{ TEXT("MobileGearII MC/R430"), BIFB_D16_0000,
    179 		640, 240, 1280, 0xa180100,
    180 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_430 },
    181 	{ TEXT("MobileGearII MC-R500"), BIFB_D8_00,
    182 		640, 240, 1024, 0x13000000,
    183 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_500 },
    184 	{ TEXT("Mobile Pro 750c"), BIFB_D8_00,
    185 		640, 240, 1024, 0x13000000,
    186 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_500A },
    187 	{ TEXT("MobileGearII MC-R510"), BIFB_D8_00,
    188 		640, 240, 1024, 0xa000000,
    189 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_510 },
    190 	{ TEXT("NEC MC-R510(15bit color)"), BIFB_D16_0000,
    191 		640, 240, 1600, 0xa000000,
    192 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_510 },
    193 	{ TEXT("MobileGearII MC-R520"), BIFB_D16_0000,
    194 		640, 240, 1600, 0xa000000,
    195 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_520 },
    196 	{ TEXT("MobileGearII MC/R530"), BIFB_D16_0000,
    197 		640, 240, 1280, 0xa180100,
    198 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_530 },
    199 	{ TEXT("Mobile Pro 770"), BIFB_D16_0000,
    200 		640, 240, 1600, 0xa000000,
    201 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_520A },
    202 	{ TEXT("MobileGearII MC-R700"), BIFB_D16_0000,
    203 		800, 600, 1600, 0xa000000,
    204 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_700 },
    205 	{ TEXT("Mobile Pro 800"), BIFB_D16_0000,
    206 		800, 600, 1600, 0xa000000,
    207 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_700A },
    208 	{ TEXT("MobileGearII MC/R730"), BIFB_D16_0000,
    209 		800, 600, 1600, 0xa0ea600,
    210 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_730 },
    211 	{ TEXT("Tripad PV-6000"), BIFB_D8_00,
    212 		640, 480, 640, 0xa000000,
    213 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_SHARP_TRIPAD_PV6000 },
    214 	{ TEXT("Vadem Clio"), BIFB_D8_00,
    215 		640, 480, 640, 0xa000000,
    216 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_SHARP_TRIPAD_PV6000 },
    217 	{ TEXT("E-55"), BIFB_D2_M2L_0,
    218 		240, 320, 256, 0xa000000,
    219 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_CASIO_CASSIOPEIAE_E55 },
    220 	{ TEXT("E-55(Small Font)"), BIFB_D2_M2L_0x2,
    221 		480, 320, 256, 0xa000000,
    222 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_CASIO_CASSIOPEIAE_E55 },
    223 	{ TEXT("E-100"), BIFB_D16_FFFF,
    224 		240, 320, 512, 0xa200000,
    225 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_CASIO_CASSIOPEIAE_E100 },
    226 	{ TEXT("E-500"), BIFB_D16_FFFF,
    227 		240, 320, 512, 0xa200000,
    228 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_CASIO_CASSIOPEIAE_E500 },
    229 	{ TEXT("INTERTOP CX300"), BIFB_D8_00,
    230 		640, 480, 640, 0xa000000,
    231 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_FUJITSU_INTERTOP_IT300 },
    232 	{ TEXT("INTERTOP CX310"), BIFB_D8_00,
    233 		640, 480, 640, 0xa000000,
    234 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_FUJITSU_INTERTOP_IT310 },
    235 	{ TEXT("IBM WorkPad z50"), BIFB_D16_0000,
    236 		640, 480, 1280, 0xa000000,
    237 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_IBM_WORKPAD_26011AU },
    238 	{ TEXT("Philips Nino 312"), BIFB_D2_M2L_0,
    239 		240, 320, 0, 0,
    240 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_PHILIPS_NINO_312 },
    241 	{ TEXT("Compaq C-series 810"), BIFB_D2_M2L_0,
    242 		640, 240, 0, 0,
    243 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_COMPAQ_C_810 },
    244 	{ TEXT("Compaq C-series 2010c"), BIFB_D8_00,
    245 		640, 240, 0, 0,
    246 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_COMPAQ_C_2010 },
    247 	{ TEXT("Compaq C-series 2015c"), BIFB_D8_00,
    248 		640, 240, 0, 0,
    249 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_COMPAQ_C_2015 },
    250 	{ TEXT("Compaq PRESARIO 213"), BIFB_D8_00,
    251 		320, 240, 0, 0,
    252 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_COMPAQ_PRESARIO_213 },
    253 	{ TEXT("Compaq Aero 1530"), BIFB_D2_M2L_0,
    254 		320, 240, 0, 0,
    255 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_COMPAQ_AERO_1530 },
    256 	{ TEXT("Victor InterLink MP-C101"), BIFB_D16_0000,
    257 		640, 480, 0, 0,
    258 		PLATID_CPU_MIPS_TX_3922, PLATID_MACH_VICTOR_INTERLINK_MPC101},
    259 	{ TEXT("Sharp Telios HC-AJ1"), BIFB_D16_0000,
    260 		800, 600, 0, 0,
    261 		PLATID_CPU_MIPS_TX_3922, PLATID_MACH_SHARP_TELIOS_HCAJ1},
    262 	{ TEXT("Sharp Mobilon HC-4100"), BIFB_D2_M2L_0, /* XXX 4bit greyscale */
    263 		640, 240, 0, 0,
    264 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_SHARP_MOBILON_HC4100},
    265 	{ TEXT("Sharp HC-1200"), BIFB_D2_M2L_0, /* XXX 4bit greyscale */
    266 		640, 240, 0, 0,
    267 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_SHARP_MOBILON_HC1200},
    268 };
    269 
    270 #define ARRAYSIZEOF(a)	(sizeof(a)/sizeof(*(a)))
    271 
    272 #ifdef UNDER_CE
    273 	/* 'memory card' in HANKAKU KANA */
    274 #define UNICODE_MEMORY_CARD \
    275 	TEXT('\\'), 0xff92, 0xff93, 0xff98, TEXT(' '), 0xff76, 0xff70, \
    276 	0xff84, 0xff9e
    277 TCHAR unicode_memory_card[] = { UNICODE_MEMORY_CARD,  TEXT('\\') };
    278 TCHAR unicode_memory_card1[] = { UNICODE_MEMORY_CARD,  TEXT('1'), TEXT('\\') };
    279 TCHAR unicode_memory_card2[] = { UNICODE_MEMORY_CARD,  TEXT('2'), TEXT('\\') };
    280 #endif
    281 
    282 #define LANGID_DEFAULT MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT)
    283 struct path_s path_list[] = {
    284 	{ TEXT("/"),
    285 	  LANGID_DEFAULT, 0 },
    286 	{ TEXT("2:/"),
    287 	  LANGID_DEFAULT, 0 },
    288 	{ TEXT("\\"),
    289 	  LANGID_DEFAULT, 0 },
    290 	{ TEXT("\\My Documents\\"),
    291 	  LANGID_DEFAULT, 0 },
    292 	{ TEXT("\\Storage Card\\"),
    293 	  LANGID_DEFAULT, PATH_SAVE },
    294 	{ TEXT("\\Storage Card1\\"),
    295 	  LANGID_DEFAULT, PATH_SAVE },
    296 	{ TEXT("\\Storage Card2\\"),
    297 	  LANGID_DEFAULT, PATH_SAVE },
    298 #ifdef UNDER_CE
    299 	{ unicode_memory_card,
    300 	  MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), PATH_SAVE },
    301 	{ unicode_memory_card1,
    302 	  MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), PATH_SAVE },
    303 	{ unicode_memory_card2,
    304 	  MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), PATH_SAVE },
    305 #endif
    306 };
    307 int path_list_items = ARRAYSIZEOF(path_list);
    308 
    309 #ifdef ADDITIONAL_KERNELS
    310 TCHAR* kernel_list[] = {
    311 
    312 };
    313 int kernel_list_items = ARRAYSIZEOF(kernel_list);
    314 #endif
    315 
    316 /*-----------------------------------------------------------------------------
    317 
    318   function prototypes
    319 
    320 -----------------------------------------------------------------------------*/
    321 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    322 void SetBootInfo(struct bootinfo *bi, struct fb_setting *fbs);
    323 void wstrcpy(TCHAR* dst, TCHAR* src);
    324 int reverse_fb_type(int type);
    325 
    326 /*-----------------------------------------------------------------------------
    327 
    328   function definitions
    329 
    330 -----------------------------------------------------------------------------*/
    331 void wstrcpy(TCHAR* dst, TCHAR* src)
    332 {
    333 	while (*src) {
    334 		*dst++ = *src++;
    335 	}
    336 	*dst = *src;
    337 }
    338 
    339 int reverse_fb_type(int type)
    340 {
    341 	int i;
    342 	struct {
    343 		int type0, type1;
    344 	} types[] = {
    345 		{ BIFB_D2_M2L_3,	BIFB_D2_M2L_0	},
    346 		{ BIFB_D2_M2L_3x2,	BIFB_D2_M2L_0x2	},
    347 		{ BIFB_D8_FF,		BIFB_D8_00		},
    348 		{ BIFB_D16_FFFF,	BIFB_D16_0000,	},
    349 	};
    350 
    351 	for (i = 0; i < ARRAYSIZEOF(types); i++) {
    352 		if (types[i].type0 == type) {
    353 			return (types[i].type1);
    354 		}
    355 		if (types[i].type1 == type) {
    356 			return (types[i].type0);
    357 		}
    358 	}
    359 	debug_printf(TEXT("reverse_fb_type(): unknown type %d\n"), type);
    360 	return (type);
    361 }
    362 
    363 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    364                     LPTSTR lpCmdLine, int nCmdShow )
    365 {
    366 	MSG          msg;
    367 	WNDCLASS     wc;
    368 	int i, idx;
    369 	RECT rect;
    370 
    371 	wc.style          = (UINT)NULL;
    372 	wc.lpfnWndProc    = (WNDPROC) WndProc;
    373 	wc.cbClsExtra     = 0;
    374 	wc.cbWndExtra     = 0;
    375 	wc.hInstance      = hInstance;
    376 	wc.hIcon          = NULL;
    377 	wc.hCursor        = NULL;
    378 	wc.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
    379 	wc.lpszMenuName   = NULL;
    380 	wc.lpszClassName  = whoami;
    381 
    382 	RegisterClass(&wc);
    383 
    384 	InitCommonControls();   // Initialize common controls - command bar
    385 	hInst = hInstance;      // Save handle to create command bar
    386 
    387 	hardware_test();
    388 
    389 	/*
    390 	 *	Main Window
    391          */
    392 	hWndMain = CreateWindow(szAppName,		// Class
    393 				szTitle,		// Title
    394 				WS_VISIBLE,		// Style
    395 				CW_USEDEFAULT,		// x-position
    396 				CW_USEDEFAULT,		// y-position
    397 				CW_USEDEFAULT,		// x-size
    398 				CW_USEDEFAULT,		// y-size
    399 				NULL,			// Parent handle
    400 				NULL,			// Menu handle
    401 				hInstance,		// Instance handle
    402 				NULL);			// Creation
    403 
    404 	GetClientRect(hWndMain, &rect);
    405 	if (rect.right < rect.bottom) {
    406 		/*
    407 		 *	portrait
    408 		 */
    409 		CreateMainWindow(hInst, hWndMain,
    410 				 MAKEINTRESOURCE(IDD_MAIN_240X320),
    411 				 CommandBar_Height(hWndCB));
    412 	} else {
    413 		/*
    414 		 *	landscape
    415 		 */
    416 		CreateMainWindow(hInst, hWndMain,
    417 				 MAKEINTRESOURCE(IDD_MAIN_640X240),
    418 				 CommandBar_Height(hWndCB));
    419 	}
    420 
    421 	/*
    422 	 *  load preferences
    423 	 */
    424 	pref_init(&pref);
    425 	if (pref_load(path_list, path_list_items) == 0) {
    426 		TCHAR tmp[256];
    427 		wsprintf(tmp, TEXT("%s is loaded."), where_pref_load_from);
    428 		SetDlgItemText(hWndMain, IDC_STATUS, tmp);
    429 
    430 		fb_settings[0].type = pref.fb_type;
    431 		fb_settings[0].width = pref.fb_width;
    432 		fb_settings[0].height = pref.fb_height;
    433 		fb_settings[0].linebytes = pref.fb_linebytes;
    434 		fb_settings[0].addr = pref.fb_addr;
    435 		fb_settings[0].platid_cpu = pref.platid_cpu;
    436 		fb_settings[0].platid_machine = pref.platid_machine;
    437 	} else {
    438 		TCHAR tmpbuf[PATHBUFLEN];
    439 		wsprintf(tmpbuf, TEXT("%s%S"), path_list[0].name, "netbsd");
    440 		SetDlgItemText(hWndMain, IDC_STATUS,
    441 			       TEXT("preferences not loaded."));
    442 
    443 		pref.setting_idx = 1;
    444 		pref.fb_type = fb_settings[0].type;
    445 		pref.fb_width = fb_settings[0].width;
    446 		pref.fb_height = fb_settings[0].height;
    447 		pref.fb_linebytes = fb_settings[0].linebytes;
    448 		pref.fb_addr = fb_settings[0].addr;
    449 		pref.platid_cpu = fb_settings[0].platid_cpu;
    450 		pref.platid_machine = fb_settings[0].platid_machine;
    451 		wstrcpy(pref.setting_name, TEXT("User defined"));
    452 		wstrcpy(pref.kernel_name, tmpbuf);
    453 		wstrcpy(pref.options, TEXT(""));
    454 		pref.check_last_chance = FALSE;
    455 		pref.load_debug_info = FALSE;
    456 		pref.serial_port = FALSE;
    457 		pref.reverse_video = FALSE;
    458 	}
    459 	fb_settings[0].name = pref.setting_name;
    460 
    461 	/*
    462 	 *  initialize kernel file name list.
    463 	 */
    464 	for (i = 0; i < path_list_items; i++) {
    465 		if (path_list[i].langid == LANGID_DEFAULT ||
    466 		    path_list[i].langid == GetSystemDefaultLangID()) {
    467 			TCHAR tmpbuf[1024];
    468 			wsprintf(tmpbuf, TEXT("%s%S"),
    469 			    path_list[i].name, "netbsd");
    470 			SendDlgItemMessage(hWndMain, IDC_KERNEL,
    471 			    CB_ADDSTRING, 0, (LPARAM)tmpbuf);
    472 		}
    473 	}
    474 #ifdef ADDITIONAL_KERNELS
    475 	for (i = 0; i < kernel_list_items; i++) {
    476 		SendDlgItemMessage(hWndMain, IDC_KERNEL, CB_ADDSTRING, 0,
    477 				   (LPARAM)kernel_list[i]);
    478 	}
    479 #endif
    480 	/*
    481 	SendDlgItemMessage(hWndMain, IDC_KERNEL, CB_SETCURSEL, 0,
    482 			   (LPARAM)NULL);
    483 	*/
    484 	SetDlgItemText(hWndMain, IDC_KERNEL, pref.kernel_name);
    485 	SetDlgItemText(hWndMain, IDC_OPTIONS, pref.options);
    486 
    487 	/*
    488 	 *  Frame Buffer setting names.
    489 	 */
    490 	for (i = 0; i < ARRAYSIZEOF(fb_settings); i++) {
    491 		idx = SendDlgItemMessage(hWndMain, IDC_FBSELECT, CB_ADDSTRING,
    492 					 0, (LPARAM)fb_settings[i].name);
    493 		SendDlgItemMessage(hWndMain, IDC_FBSELECT,
    494 				   CB_SETITEMDATA, idx, (LPARAM)i);
    495 		if (i == 0) {
    496 			user_define_idx = idx;
    497 		}
    498 	}
    499 	SendDlgItemMessage(hWndMain, IDC_FBSELECT, CB_SETCURSEL,
    500 			   pref.setting_idx, (LPARAM)NULL);
    501 
    502 	/*
    503 	 *  Check box, 'Pause before boot'
    504 	 */
    505 	SendDlgItemMessage(hWndMain, IDC_PAUSE, BM_SETCHECK,
    506 			   pref.check_last_chance, 0);
    507 	SendDlgItemMessage(hWndMain, IDC_DEBUG, BM_SETCHECK,
    508 			   pref.load_debug_info, 0);
    509 	SendDlgItemMessage(hWndMain, IDC_COMM, BM_SETCHECK,
    510 			   pref.serial_port, 0);
    511 	SendDlgItemMessage(hWndMain, IDC_REVERSEVIDEO, BM_SETCHECK,
    512 			   pref.reverse_video, 0);
    513 
    514 	/*
    515 	 *  Map window and message loop
    516 	 */
    517 	ShowWindow(hWndMain, SW_SHOW);
    518 	UpdateWindow(hWndMain);
    519 	while ( GetMessage(&msg, NULL, 0, 0) != FALSE ) {
    520 		TranslateMessage(&msg);
    521 		DispatchMessage(&msg);
    522 	}
    523 
    524 	return(msg.wParam);
    525 }
    526 
    527 BOOL CALLBACK DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    528 {
    529 	switch (message) {
    530 	case WM_INITDIALOG:
    531 		return (1);
    532 
    533 	case WM_PALETTECHANGED:
    534 		palette_check(hWnd);
    535 		break;
    536 
    537 	case WM_COMMAND:
    538 		switch (LOWORD(wParam)) {
    539 		case IDCANCEL:
    540 			dlgStatus = IDCANCEL;
    541 			break;
    542 		}
    543 		break;
    544 	default:
    545 		return (0);
    546 	}
    547 }
    548 
    549 BOOL CALLBACK DlgProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    550 {
    551 	switch (message) {
    552 	case WM_INITDIALOG:
    553 		SetDlgItemText(hWnd, IDC_ABOUT_EDIT, version_string);
    554 		return (1);
    555 
    556 	case WM_PALETTECHANGED:
    557 		palette_check(hWnd);
    558 		break;
    559 
    560 	case WM_COMMAND:
    561 		switch (LOWORD(wParam)) {
    562 		case IDC_ABOUT_EDIT:
    563 			switch (HIWORD(wParam)) {
    564 			case EN_SETFOCUS:
    565 				//SendDlgItemMessage(hWnd, IDC_ABOUT_EDIT, EM_SETSEL, -1, 0);
    566 				SetFocus(GetDlgItem(hWnd, IDC_ABOUT_BITMAP));
    567 				break;
    568 			}
    569 			break;
    570 
    571 		case IDCANCEL:
    572 			EndDialog(hWnd, LOWORD(wParam));
    573 			return (1);
    574 		}
    575 		break;
    576 	default:
    577 		return (0);
    578 	}
    579 }
    580 
    581 void
    582 SetBootInfo(struct bootinfo *bi, struct fb_setting *fbs)
    583 {
    584 	TIME_ZONE_INFORMATION tz;
    585 
    586 	GetTimeZoneInformation(&tz);
    587 	memset(bi, 0, sizeof(struct bootinfo));
    588 	bi->length = sizeof(struct bootinfo);
    589 	bi->reserved = 0;
    590 	bi->magic = BOOTINFO_MAGIC;
    591 	bi->fb_addr = (unsigned char*)(fbs->addr + 0xA0000000);
    592 	bi->fb_type = fbs->type;
    593 	bi->fb_line_bytes = fbs->linebytes;
    594 	bi->fb_width = fbs->width;
    595 	bi->fb_height = fbs->height;
    596 	bi->platid_cpu = fbs->platid_cpu;
    597 	bi->platid_machine = fbs->platid_machine;
    598 	bi->timezone = tz.Bias;
    599 
    600 	debug_printf(TEXT("fb setting: %s fb_type=%d 0x%X %dx%d %d\n"),
    601 		     fbs->name,
    602 		     bi->fb_type, bi->fb_addr,
    603 		     bi->fb_width, bi->fb_height, bi->fb_line_bytes);
    604 	debug_printf(TEXT("timezone: %02ld:00\n"), (bi->timezone / 60));
    605 }
    606 
    607 
    608 void
    609 UpdateFbDlg(HWND hWnd, struct fb_setting *fbs, int direction)
    610 {
    611 	int i;
    612 	TCHAR tmpbuf[PATHBUFLEN];
    613 	int type, width, height, linebytes;
    614 	long addr;
    615 
    616 	switch (direction) {
    617 	case UPDATE_DLGBOX:
    618 		SetDlgItemText(hWnd, IDC_FB_NAME, fbs->name);
    619 
    620 		for (i = 0; i < ARRAYSIZEOF(fb_types); i++) {
    621 			if (fb_types[i].type == fbs->type) break;
    622 		}
    623 		if (ARRAYSIZEOF(fb_types) <= i) {
    624 			MessageBox(NULL, TEXT("Unknown FrameBuffer type."),
    625 				   szAppName, MB_OK);
    626 			return;
    627 		}
    628 		debug_printf(TEXT("UpdateFbDlg(%s)\n"), fbs->name);
    629 		i = SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_FINDSTRINGEXACT,
    630 				       0, (LPARAM)fb_types[i].name);
    631 		SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_SETCURSEL, i, 0);
    632 
    633 		wsprintf(tmpbuf, TEXT("%X"), fbs->addr);
    634 		SetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf);
    635 		wsprintf(tmpbuf, TEXT("%d"), fbs->width);
    636 		SetDlgItemText(hWnd, IDC_FB_WIDTH, tmpbuf);
    637 		wsprintf(tmpbuf, TEXT("%d"), fbs->height);
    638 		SetDlgItemText(hWnd, IDC_FB_HEIGHT, tmpbuf);
    639 		wsprintf(tmpbuf, TEXT("%d"), fbs->linebytes);
    640 		SetDlgItemText(hWnd, IDC_FB_LINEBYTES, tmpbuf);
    641 		wsprintf(tmpbuf, TEXT("%08X"), fbs->platid_cpu);
    642 		SetDlgItemText(hWnd, IDC_FB_CPU, tmpbuf);
    643 		wsprintf(tmpbuf, TEXT("%08X"), fbs->platid_machine);
    644 		SetDlgItemText(hWnd, IDC_FB_MACHINE, tmpbuf);
    645 		break;
    646 	case UPDATE_DATA:
    647 		GetDlgItemText(hWnd, IDC_FB_NAME, fbs->name, PATHBUFLEN);
    648 		type = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
    649 					  CB_GETCURSEL, 0, 0);
    650 		type = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
    651 					  CB_GETITEMDATA, type, 0);
    652 		GetDlgItemText(hWnd, IDC_FB_WIDTH, tmpbuf, sizeof(tmpbuf));
    653 		width = _tcstol(tmpbuf, NULL, 10);
    654 		GetDlgItemText(hWnd, IDC_FB_HEIGHT, tmpbuf, sizeof(tmpbuf));
    655 		height = _tcstol(tmpbuf, NULL, 10);
    656 		GetDlgItemText(hWnd, IDC_FB_LINEBYTES, tmpbuf, sizeof(tmpbuf));
    657 		linebytes = _tcstol(tmpbuf, NULL, 10);
    658 		GetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf, sizeof(tmpbuf));
    659 		addr = _tcstoul(tmpbuf, NULL, 16);
    660 		GetDlgItemText(hWnd, IDC_FB_CPU, tmpbuf, sizeof(tmpbuf));
    661 		fbs->platid_cpu = _tcstoul(tmpbuf, NULL, 16);
    662 		GetDlgItemText(hWnd, IDC_FB_MACHINE, tmpbuf, sizeof(tmpbuf));
    663 		fbs->platid_machine = _tcstoul(tmpbuf, NULL, 16);
    664 		fbs->type = type;
    665 		fbs->addr = addr;
    666 		fbs->width = width;
    667 		fbs->height = height;
    668 		fbs->linebytes = linebytes;
    669 
    670 		debug_printf(TEXT("type=%d  %dx%d  %d bytes/line %08x %08x\n"),
    671 			     type, width, height, linebytes,
    672 			     fbs->platid_cpu,
    673 			     fbs->platid_machine);
    674 		break;
    675 	default:
    676 		debug_printf(TEXT("UpdateFbDlg(): internal error!\n"));
    677 		break;
    678 	}
    679 }
    680 
    681 BOOL CALLBACK FbDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    682 {
    683 	int idx, i;
    684 	TCHAR tmpbuf[100];
    685 
    686 	switch (message) {
    687 	case WM_INITDIALOG:
    688 		{
    689 		UDACCEL uda;
    690 		for (i = 0; i < ARRAYSIZEOF(fb_settings); i++) {
    691 			idx = SendDlgItemMessage(hWnd, IDC_FB_NAME,
    692 						 CB_ADDSTRING, 0,
    693 						 (LPARAM)fb_settings[i].name);
    694 			SendDlgItemMessage(hWnd, IDC_FB_NAME,
    695 					   CB_SETITEMDATA, idx, (LPARAM)i);
    696 		}
    697 		for (i = 0; i < ARRAYSIZEOF(fb_size); i++) {
    698 			wsprintf(tmpbuf, TEXT("%d"), fb_size[i]);
    699 			SendDlgItemMessage(hWnd, IDC_FB_WIDTH, CB_ADDSTRING,
    700 					   0, (LPARAM)tmpbuf);
    701 			SendDlgItemMessage(hWnd, IDC_FB_HEIGHT, CB_ADDSTRING,
    702 					   0, (LPARAM)tmpbuf);
    703 		}
    704 		for (i = 0; i < ARRAYSIZEOF(fb_bpl); i++) {
    705 			wsprintf(tmpbuf, TEXT("%d"), fb_bpl[i]);
    706 			SendDlgItemMessage(hWnd, IDC_FB_LINEBYTES,
    707 					   CB_ADDSTRING, 0,
    708 					   (LPARAM)tmpbuf);
    709 		}
    710 		for (i = 0; i < ARRAYSIZEOF(fb_types); i++) {
    711 			idx = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
    712 						 CB_ADDSTRING, 0,
    713 						 (LPARAM)fb_types[i].name);
    714 			SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_SETITEMDATA,
    715 					   idx, (LPARAM)fb_types[i].type);
    716 		}
    717 		UpdateFbDlg(hWnd, &fb_settings[0], UPDATE_DLGBOX);
    718 
    719 		uda.nSec = 1;
    720 		uda.nInc = 0x100;
    721 		/*
    722 		SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN, UDM_SETACCEL,
    723 				   0, (LPARAM)&uda);
    724 		*/
    725 		/*
    726 		SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN, UDM_SETRANGE,
    727 		                   0, MAKELPARAM(UD_MAXVAL, UD_MINVAL));
    728 		*/
    729 		}
    730 		return (1);
    731 
    732 	case WM_PALETTECHANGED:
    733 		palette_check(hWnd);
    734 		break;
    735 
    736 	case WM_VSCROLL:
    737 		if ((HWND)lParam == GetDlgItem(hWnd, IDC_FB_ADDRSPIN)) {
    738 			long addr;
    739 			switch (LOWORD(wParam)) {
    740 			case SB_THUMBPOSITION:
    741 			case SB_THUMBTRACK:
    742 				GetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf, 100);
    743 				addr = _tcstoul(tmpbuf, NULL, 16);
    744 				if (50 < HIWORD(wParam)) {
    745 					addr -= 0x400;
    746 				} else {
    747 					addr += 0x400;
    748 				}
    749 				SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN,
    750 						   UDM_SETPOS, 0,
    751 						   MAKELPARAM(50, 0));
    752 				wsprintf(tmpbuf, TEXT("%X"), addr);
    753 				SetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf);
    754 				return (1);
    755 			}
    756 		}
    757 		break;
    758 
    759 	case WM_COMMAND:
    760 		switch (LOWORD(wParam)) {
    761 		case IDC_FB_NAME:
    762 			switch (HIWORD(wParam)) {
    763 			case CBN_SELCHANGE:
    764 				idx = SendDlgItemMessage(hWnd, IDC_FB_NAME,
    765 							 CB_GETCURSEL, 0, 0);
    766 				i = SendDlgItemMessage(hWnd, IDC_FB_NAME,
    767 						       CB_GETITEMDATA, idx, 0);
    768 				if (0 <= i && i < ARRAYSIZEOF(fb_settings)) {
    769 					fb_settings[0] = fb_settings[i];
    770 					UpdateFbDlg(hWnd, &fb_settings[0],
    771 						    UPDATE_DLGBOX);
    772 				}
    773 				return (1);
    774 			}
    775 			break;
    776 		case IDOK:
    777 			UpdateFbDlg(hWnd, &fb_settings[0], UPDATE_DATA);
    778 
    779 			EndDialog(hWnd, IDOK);
    780 			return (1);
    781 
    782 		case IDCANCEL:
    783 			EndDialog(hWnd, IDCANCEL);
    784 			return (1);
    785 		}
    786 		break;
    787 	}
    788 	return (0);
    789 }
    790 
    791 
    792 BOOL SerialPort(BOOL on)
    793 {
    794 	static HANDLE hPort = INVALID_HANDLE_VALUE;
    795 	BOOL res = (hPort != INVALID_HANDLE_VALUE);
    796 
    797 	if (on != res) {
    798 		if (on) {
    799 			hPort = CreateFile(TEXT("COM1:"),
    800 					   GENERIC_READ | GENERIC_WRITE,
    801 					   0, NULL, OPEN_EXISTING,
    802 					   0,
    803 					   NULL);
    804 			debug_printf(TEXT("serial port ON\n"));
    805 			if ( hPort == INVALID_HANDLE_VALUE ) {
    806 				debug_printf(TEXT("open failed\n"));
    807 			} else {
    808 #if 0
    809 				DWORD Len;
    810 				BYTE x = 'X';
    811 				WriteFile (hPort, &x, 1, &Len, 0);
    812 				WriteFile (hPort, &x, 1, &Len, 0);
    813 				WriteFile (hPort, &x, 1, &Len, 0);
    814 				WriteFile (hPort, &x, 1, &Len, 0);
    815 #endif
    816 			}
    817 		} else {
    818 			debug_printf(TEXT("serial port OFF\n"));
    819 			CloseHandle(hPort);
    820 			hPort = INVALID_HANDLE_VALUE;
    821 		}
    822 	}
    823 
    824 	return (res);
    825 }
    826 
    827 
    828 BOOL CheckCancel(int progress)
    829 {
    830 	MSG msg;
    831 
    832 	if (0 <= progress) {
    833 		SendDlgItemMessage(hDlgLoad, IDC_PROGRESS,
    834 				   PBM_SETPOS, (WPARAM)progress, (LPARAM)NULL);
    835 	} else {
    836 		if (pref.check_last_chance) {
    837 			if (msg_printf(MB_YESNO | MB_ICONHAND,
    838 			    TEXT("Last chance..."),
    839 			    TEXT("Push OK to boot.")) != IDYES) {
    840 				dlgStatus = IDCANCEL;
    841 			}
    842 		}
    843 		palette_set(hDlgLoad);
    844 		if (palette_succeeded == -1) {
    845 			msg_printf(MSG_ERROR,
    846 			    TEXT("Warning"),
    847 			    TEXT("Sorry, palette failed"));
    848 		}
    849 	}
    850 
    851 	/*
    852 	 *  Put WM_TIMER in my message queue.
    853 	 *  (WM_TIMER has lowest priority.)
    854 	 */
    855 	SetTimer(hDlgLoad, 1, 1, NULL);
    856 
    857 	/*
    858 	 *  I tried PeekMessage() but it does not work.
    859 	 */
    860 	while (GetMessage(&msg, NULL, 0, 0)) {
    861 		if (msg.hwnd == hDlgLoad && msg.message == WM_TIMER) {
    862 			break;
    863 		}
    864 		TranslateMessage(&msg);
    865 		DispatchMessage(&msg);
    866 	}
    867 
    868 	return (dlgStatus != 0);
    869 }
    870 
    871 LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
    872                           WPARAM wParam, LPARAM lParam )
    873 {
    874 	int i, idx;
    875 
    876 	switch (message) {
    877 	case WM_CREATE:
    878 		sndPlaySound(TEXT("OpenProg"), SND_NODEFAULT | SND_ASYNC);
    879 		hWndCB = CommandBar_Create(hInst, hWnd, 1);
    880 		CommandBar_AddAdornments(hWndCB, STD_HELP, (DWORD)NULL);
    881 		palette_init(hWnd);
    882 		break;
    883 
    884 	case WM_PAINT:
    885 		{
    886 		HDC          hdc;
    887 		PAINTSTRUCT  ps;
    888 
    889 		hdc = BeginPaint(hWnd, &ps);
    890 		EndPaint(hWnd, &ps);
    891 		}
    892 		break;
    893 
    894 	case WM_PALETTECHANGED:
    895 		palette_check(hWnd);
    896 		break;
    897 
    898 	case WM_HELP:
    899 		/*
    900 		MessageBox (NULL, TEXT("HELP NOT AVAILABLE"),
    901 			    szAppName, MB_OK);
    902 		*/
    903 		DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, DlgProc2);
    904         break;
    905 
    906 	case WM_COMMAND:
    907 		switch (LOWORD(wParam)) {
    908 		case IDC_BOOT:
    909 			{
    910 		       	int argc;
    911 		       	TCHAR wkernel_name[PATHBUFLEN];
    912 			TCHAR woptions[PATHBUFLEN];
    913 			char options[PATHBUFLEN*2], kernel_name[PATHBUFLEN*2];
    914 			platid_t platid;
    915 
    916 			char *p, *argv[32];
    917 			struct bootinfo bi;
    918 
    919 			if (SendDlgItemMessage(hWndMain, IDC_PAUSE,
    920 					       BM_GETCHECK, 0, 0) ==
    921 								BST_CHECKED) {
    922 				pref.check_last_chance = TRUE;
    923 			} else {
    924 				pref.check_last_chance = FALSE;
    925 			}
    926 
    927 			if (SendDlgItemMessage(hWndMain, IDC_DEBUG,
    928 					       BM_GETCHECK, 0, 0) ==
    929 								BST_CHECKED) {
    930 				pref.load_debug_info = TRUE;
    931 			} else {
    932 				pref.load_debug_info = FALSE;
    933 			}
    934 
    935 			if (SendDlgItemMessage(hWndMain, IDC_COMM,
    936 					       BM_GETCHECK, 0, 0) ==
    937 								BST_CHECKED) {
    938 				pref.serial_port = TRUE;
    939 			} else {
    940 				pref.serial_port = FALSE;
    941 			}
    942 
    943 			if (SendDlgItemMessage(hWndMain, IDC_REVERSEVIDEO,
    944 					       BM_GETCHECK, 0, 0) ==
    945 								BST_CHECKED) {
    946 				pref.reverse_video = TRUE;
    947 			} else {
    948 				pref.reverse_video = FALSE;
    949 			}
    950 
    951 			if (GetDlgItemText(hWndMain, IDC_KERNEL, wkernel_name,
    952 					   sizeof(wkernel_name)) == 0) {
    953 				MessageBox (NULL, TEXT("Kernel name required"),
    954 					    szAppName, MB_OK);
    955 				break;
    956 			}
    957 			GetDlgItemText(hWndMain, IDC_OPTIONS,
    958 				       woptions, sizeof(woptions));
    959 			if (wcstombs(options, woptions, sizeof(options)) < 0 ||
    960 			    wcstombs(kernel_name, wkernel_name,
    961 				     sizeof(kernel_name)) < 0) {
    962 				MessageBox (NULL, TEXT("invalid character"),
    963 					    szAppName, MB_OK);
    964 				break;
    965 			}
    966 
    967 			argc = 0;
    968 			argv[argc++] = kernel_name;
    969 			p = options;
    970 			while (*p) {
    971 				while (*p == ' ' || *p == '\t') {
    972 					p++;
    973 				}
    974 				if (*p == '\0')
    975 					break;
    976 				if (ARRAYSIZEOF(argv) <= argc) {
    977 					MessageBox (NULL,
    978 						    TEXT("too many options"),
    979 						    szAppName, MB_OK);
    980 					argc++;
    981 					break;
    982 				} else {
    983 					argv[argc++] = p;
    984 				}
    985 				while (*p != ' ' && *p != '\t' && *p != '\0') {
    986 					p++;
    987 				}
    988 				if (*p == '\0') {
    989 					break;
    990 				} else {
    991 					*p++ = '\0';
    992 				}
    993 			}
    994 			if (ARRAYSIZEOF(argv) < argc) {
    995 				break;
    996 			}
    997 
    998 			EnableWindow(hWndMain, FALSE);
    999 			if (MessageBox (hWndMain,
   1000 					TEXT("Data in memory will be lost.\nAre you sure?"),
   1001 					szAppName,
   1002 					MB_YESNO | MB_DEFBUTTON2 | MB_ICONHAND) == IDYES) {
   1003 				dlgStatus = 0;
   1004 				hDlgLoad =
   1005 				  CreateDialog(hInst,
   1006 					       MAKEINTRESOURCE(IDD_LOAD),
   1007 					       hWndMain, DlgProc);
   1008 				ShowWindow(hDlgLoad, SW_SHOWNORMAL);
   1009 				BringWindowToTop(hDlgLoad);
   1010 
   1011 				/*
   1012 				 *  save settings.
   1013 				 */
   1014 				pref.fb_type		= fb_settings[0].type;
   1015 				pref.fb_width		= fb_settings[0].width;
   1016 				pref.fb_height		= fb_settings[0].height;
   1017 				pref.fb_linebytes	= fb_settings[0].linebytes;
   1018 				pref.fb_addr		= fb_settings[0].addr;
   1019 				pref.platid_cpu		= fb_settings[0].platid_cpu;
   1020 				pref.platid_machine	= fb_settings[0].platid_machine;
   1021 				wstrcpy(pref.kernel_name, wkernel_name);
   1022 				wstrcpy(pref.options, woptions);
   1023 
   1024 				pref_save(path_list, path_list_items);
   1025 
   1026 				SetBootInfo(&bi, &fb_settings[pref.setting_idx]);
   1027 				debug_printf(TEXT("Args: "));
   1028 				for (i = 0; i < argc; i++) {
   1029 					debug_printf(TEXT("'%S' "), argv[i]);
   1030 				}
   1031 				debug_printf(TEXT("\n"));
   1032 				debug_printf(TEXT("Bootinfo: fb_type=%d 0x%X %dx%d %d\n"),
   1033 					     bi.fb_type, bi.fb_addr,
   1034 					     bi.fb_width, bi.fb_height,
   1035 					     bi.fb_line_bytes);
   1036 
   1037 				if (pref.serial_port) {
   1038 					SerialPort(TRUE);
   1039 				}
   1040 				if (pref.reverse_video) {
   1041 					bi.fb_type = reverse_fb_type(bi.fb_type);
   1042 				}
   1043 				/*
   1044 				 * Set system infomation
   1045 				 */
   1046 				platid.dw.dw0 = bi.platid_cpu;
   1047 				platid.dw.dw1 = bi.platid_machine;
   1048 				if (set_system_info(&platid)) {
   1049 					/*
   1050 					*  boot !
   1051 					*/
   1052 					pbsdboot(wkernel_name, argc, argv, &bi);
   1053 				}
   1054 				/*
   1055 				 *  Not return.
   1056 				 */
   1057 
   1058 				if (pref.serial_port) {
   1059 					SerialPort(FALSE);
   1060 				}
   1061 
   1062 				DestroyWindow(hDlgLoad);
   1063 			}
   1064 			EnableWindow(hWndMain, TRUE);
   1065 			}
   1066 			break;
   1067 		case IDC_FBSETTING:
   1068 			if (DialogBox(hInst, MAKEINTRESOURCE(IDD_FB),
   1069 				      hWndMain, FbDlgProc) == IDOK) {
   1070 				/* User defined */
   1071 				pref.setting_idx = 0;
   1072 				SendDlgItemMessage(hWndMain, IDC_FBSELECT,
   1073 						   CB_DELETESTRING,
   1074 						   (WPARAM)user_define_idx, 0);
   1075 				SendDlgItemMessage(hWndMain, IDC_FBSELECT,
   1076 						   CB_INSERTSTRING,
   1077 						   (WPARAM)user_define_idx,
   1078 						   (LPARAM)fb_settings[0].name);
   1079 				SendDlgItemMessage(hWnd, IDC_FBSELECT,
   1080 						   CB_SETCURSEL, 0, 0);
   1081 			}
   1082 			break;
   1083 		case IDC_FBSELECT:
   1084 			switch (HIWORD(wParam)) {
   1085 			case CBN_SELCHANGE:
   1086 				idx = SendDlgItemMessage(hWnd, IDC_FBSELECT,
   1087 							 CB_GETCURSEL, 0, 0);
   1088 				i = SendDlgItemMessage(hWnd, IDC_FBSELECT,
   1089 						       CB_GETITEMDATA, idx, 0);
   1090 				if (0 <= i && i < ARRAYSIZEOF(fb_settings)) {
   1091 					debug_printf(TEXT("fb_setting=%d\n"), i);
   1092 					pref.setting_idx = i;
   1093 				}
   1094 				break;
   1095 			}
   1096 			break;
   1097 		}
   1098 		break;
   1099 
   1100 	case WM_HIBERNATE:
   1101 		MessageBox(NULL, TEXT("MEMORY IS LOW"), szAppName, MB_OK);
   1102 		//Additional code to handle a low memory situation
   1103 
   1104 	case WM_CLOSE:
   1105 	        sndPlaySound(TEXT("Close"), SND_NODEFAULT | SND_ASYNC);
   1106 
   1107 		DestroyWindow(hWnd);
   1108 		break;
   1109 
   1110 	case WM_DESTROY:
   1111 	        PostQuitMessage(0);
   1112 		break;
   1113 
   1114 	default:
   1115         	return (DefWindowProc(hWnd, message, wParam, lParam));
   1116 	}
   1117 
   1118 	return (0);
   1119 }
   1120 
   1121 
   1122