Home | History | Annotate | Line # | Download | only in pbsdboot
main.c revision 1.37
      1 /*	$NetBSD: main.c,v 1.37 2000/04/12 15:07:34 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.13.0 2000.04.12\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("Mobile Pro 700"), BIFB_D2_M2L_0,
    170 		640, 240, 256, 0xa000000,
    171 		PLATID_CPU_MIPS_VR_4102, PLATID_MACH_NEC_MCR_MPRO700 },
    172 	{ TEXT("MobileGearII MC-R300"), BIFB_D2_M2L_0,
    173 		640, 240, 256, 0xa000000,
    174 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_300 },
    175 	{ TEXT("MobileGearII for DoCoMo"), BIFB_D2_M2L_0,
    176 		640, 240, 256, 0xa000000,
    177 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_FORDOCOMO },
    178 	{ TEXT("MobileGearII MC-R320"), BIFB_D2_M2L_0,
    179 		640, 240, 160, 0xa000000,
    180 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_320 },
    181 	{ TEXT("MobileGearII MC/R430"), BIFB_D16_0000,
    182 		640, 240, 1280, 0xa180100,
    183 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_430 },
    184 	{ TEXT("MobileGearII MC-R500"), BIFB_D8_00,
    185 		640, 240, 1024, 0x13000000,
    186 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_500 },
    187 	{ TEXT("Mobile Pro 750c"), BIFB_D8_00,
    188 		640, 240, 1024, 0x13000000,
    189 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_500A },
    190 	{ TEXT("MobileGearII MC-R510"), BIFB_D8_00,
    191 		640, 240, 1024, 0xa000000,
    192 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_510 },
    193 	{ TEXT("NEC MC-R510(15bit color)"), BIFB_D16_0000,
    194 		640, 240, 1600, 0xa000000,
    195 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_510 },
    196 	{ TEXT("MobileGearII MC-R520"), BIFB_D16_0000,
    197 		640, 240, 1600, 0xa000000,
    198 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_520 },
    199 	{ TEXT("MobileGearII MC/R530"), BIFB_D16_0000,
    200 		640, 240, 1280, 0xa180100,
    201 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_530 },
    202 	{ TEXT("Mobile Pro 770"), BIFB_D16_0000,
    203 		640, 240, 1600, 0xa000000,
    204 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_520A },
    205 	{ TEXT("MobileGearII MC-R700"), BIFB_D16_0000,
    206 		800, 600, 1600, 0xa000000,
    207 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_700 },
    208 	{ TEXT("Mobile Pro 800"), BIFB_D16_0000,
    209 		800, 600, 1600, 0xa000000,
    210 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_700A },
    211 	{ TEXT("MobileGearII MC/R730"), BIFB_D16_0000,
    212 		800, 600, 1600, 0xa0ea600,
    213 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_730 },
    214 	{ TEXT("Tripad PV-6000"), BIFB_D8_00,
    215 		640, 480, 640, 0xa000000,
    216 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_SHARP_TRIPAD_PV6000 },
    217 	{ TEXT("Vadem Clio"), BIFB_D8_00,
    218 		640, 480, 640, 0xa000000,
    219 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_SHARP_TRIPAD_PV6000 },
    220 	{ TEXT("E-55"), BIFB_D2_M2L_0,
    221 		240, 320, 256, 0xa000000,
    222 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_CASIO_CASSIOPEIAE_E55 },
    223 	{ TEXT("E-55(Small Font)"), BIFB_D2_M2L_0x2,
    224 		480, 320, 256, 0xa000000,
    225 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_CASIO_CASSIOPEIAE_E55 },
    226 	{ TEXT("E-100"), BIFB_D16_FFFF,
    227 		240, 320, 512, 0xa200000,
    228 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_CASIO_CASSIOPEIAE_E100 },
    229 	{ TEXT("E-500"), BIFB_D16_FFFF,
    230 		240, 320, 512, 0xa200000,
    231 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_CASIO_CASSIOPEIAE_E500 },
    232 	{ TEXT("INTERTOP CX300"), BIFB_D8_00,
    233 		640, 480, 640, 0xa000000,
    234 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_FUJITSU_INTERTOP_IT300 },
    235 	{ TEXT("INTERTOP CX310"), BIFB_D8_00,
    236 		640, 480, 640, 0xa000000,
    237 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_FUJITSU_INTERTOP_IT310 },
    238 	{ TEXT("IBM WorkPad z50"), BIFB_D16_0000,
    239 		640, 480, 1280, 0xa000000,
    240 		PLATID_CPU_MIPS_VR_4121, PLATID_MACH_IBM_WORKPAD_26011AU },
    241 	{ TEXT("Philips Nino 312"), BIFB_D2_M2L_0,
    242 		240, 320, 0, 0,
    243 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_PHILIPS_NINO_312 },
    244 	{ TEXT("Compaq C-series 810"), BIFB_D2_M2L_0,
    245 		640, 240, 0, 0,
    246 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_COMPAQ_C_810 },
    247 	{ TEXT("Compaq C-series 2010c"), BIFB_D8_00,
    248 		640, 240, 0, 0,
    249 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_COMPAQ_C_2010 },
    250 	{ TEXT("Compaq C-series 2015c"), BIFB_D8_00,
    251 		640, 240, 0, 0,
    252 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_COMPAQ_C_2015 },
    253 	{ TEXT("Compaq PRESARIO 213"), BIFB_D8_00,
    254 		320, 240, 0, 0,
    255 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_COMPAQ_PRESARIO_213 },
    256 	{ TEXT("Compaq Aero 1530"), BIFB_D2_M2L_0,
    257 		320, 240, 0, 0,
    258 		PLATID_CPU_MIPS_VR_4111, PLATID_MACH_COMPAQ_AERO_1530 },
    259 	{ TEXT("Victor InterLink MP-C101"), BIFB_D16_0000,
    260 		640, 480, 0, 0,
    261 		PLATID_CPU_MIPS_TX_3922, PLATID_MACH_VICTOR_INTERLINK_MPC101},
    262 	{ TEXT("Sharp Telios HC-AJ1"), BIFB_D16_0000,
    263 		800, 600, 0, 0,
    264 		PLATID_CPU_MIPS_TX_3922, PLATID_MACH_SHARP_TELIOS_HCAJ1},
    265 	{ TEXT("Sharp Mobilon HC-4100"), BIFB_D2_M2L_0, /* XXX 4bit greyscale */
    266 		640, 240, 0, 0,
    267 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_SHARP_MOBILON_HC4100},
    268 	{ TEXT("Sharp HC-1200"), BIFB_D2_M2L_0, /* XXX 4bit greyscale */
    269 		640, 240, 0, 0,
    270 		PLATID_CPU_MIPS_TX_3912, PLATID_MACH_SHARP_MOBILON_HC1200},
    271 };
    272 
    273 #define ARRAYSIZEOF(a)	(sizeof(a)/sizeof(*(a)))
    274 
    275 #ifdef UNDER_CE
    276 	/* 'memory card' in HANKAKU KANA */
    277 #define UNICODE_MEMORY_CARD \
    278 	TEXT('\\'), 0xff92, 0xff93, 0xff98, TEXT(' '), 0xff76, 0xff70, \
    279 	0xff84, 0xff9e
    280 TCHAR unicode_memory_card[] = { UNICODE_MEMORY_CARD,  TEXT('\\') };
    281 TCHAR unicode_memory_card1[] = { UNICODE_MEMORY_CARD,  TEXT('1'), TEXT('\\') };
    282 TCHAR unicode_memory_card2[] = { UNICODE_MEMORY_CARD,  TEXT('2'), TEXT('\\') };
    283 #endif
    284 
    285 #define LANGID_DEFAULT MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT)
    286 struct path_s path_list[] = {
    287 	{ TEXT("/"),
    288 	  LANGID_DEFAULT, 0 },
    289 	{ TEXT("2:/"),
    290 	  LANGID_DEFAULT, 0 },
    291 	{ TEXT("\\"),
    292 	  LANGID_DEFAULT, 0 },
    293 	{ TEXT("\\My Documents\\"),
    294 	  LANGID_DEFAULT, 0 },
    295 	{ TEXT("\\Storage Card\\"),
    296 	  LANGID_DEFAULT, PATH_SAVE },
    297 	{ TEXT("\\Storage Card1\\"),
    298 	  LANGID_DEFAULT, PATH_SAVE },
    299 	{ TEXT("\\Storage Card2\\"),
    300 	  LANGID_DEFAULT, PATH_SAVE },
    301 #ifdef UNDER_CE
    302 	{ unicode_memory_card,
    303 	  MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), PATH_SAVE },
    304 	{ unicode_memory_card1,
    305 	  MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), PATH_SAVE },
    306 	{ unicode_memory_card2,
    307 	  MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), PATH_SAVE },
    308 #endif
    309 };
    310 int path_list_items = ARRAYSIZEOF(path_list);
    311 
    312 #ifdef ADDITIONAL_KERNELS
    313 TCHAR* kernel_list[] = {
    314 
    315 };
    316 int kernel_list_items = ARRAYSIZEOF(kernel_list);
    317 #endif
    318 
    319 /*-----------------------------------------------------------------------------
    320 
    321   function prototypes
    322 
    323 -----------------------------------------------------------------------------*/
    324 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    325 void SetBootInfo(struct bootinfo *bi, struct fb_setting *fbs);
    326 void wstrcpy(TCHAR* dst, TCHAR* src);
    327 int reverse_fb_type(int type);
    328 
    329 /*-----------------------------------------------------------------------------
    330 
    331   function definitions
    332 
    333 -----------------------------------------------------------------------------*/
    334 void wstrcpy(TCHAR* dst, TCHAR* src)
    335 {
    336 	while (*src) {
    337 		*dst++ = *src++;
    338 	}
    339 	*dst = *src;
    340 }
    341 
    342 int reverse_fb_type(int type)
    343 {
    344 	int i;
    345 	struct {
    346 		int type0, type1;
    347 	} types[] = {
    348 		{ BIFB_D2_M2L_3,	BIFB_D2_M2L_0	},
    349 		{ BIFB_D2_M2L_3x2,	BIFB_D2_M2L_0x2	},
    350 		{ BIFB_D8_FF,		BIFB_D8_00		},
    351 		{ BIFB_D16_FFFF,	BIFB_D16_0000,	},
    352 	};
    353 
    354 	for (i = 0; i < ARRAYSIZEOF(types); i++) {
    355 		if (types[i].type0 == type) {
    356 			return (types[i].type1);
    357 		}
    358 		if (types[i].type1 == type) {
    359 			return (types[i].type0);
    360 		}
    361 	}
    362 	debug_printf(TEXT("reverse_fb_type(): unknown type %d\n"), type);
    363 	return (type);
    364 }
    365 
    366 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    367                     LPTSTR lpCmdLine, int nCmdShow )
    368 {
    369 	MSG          msg;
    370 	WNDCLASS     wc;
    371 	int i, idx;
    372 	RECT rect;
    373 
    374 	wc.style          = (UINT)NULL;
    375 	wc.lpfnWndProc    = (WNDPROC) WndProc;
    376 	wc.cbClsExtra     = 0;
    377 	wc.cbWndExtra     = 0;
    378 	wc.hInstance      = hInstance;
    379 	wc.hIcon          = NULL;
    380 	wc.hCursor        = NULL;
    381 	wc.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
    382 	wc.lpszMenuName   = NULL;
    383 	wc.lpszClassName  = whoami;
    384 
    385 	RegisterClass(&wc);
    386 
    387 	InitCommonControls();   // Initialize common controls - command bar
    388 	hInst = hInstance;      // Save handle to create command bar
    389 
    390 	hardware_test();
    391 
    392 	/*
    393 	 *	Main Window
    394          */
    395 #define WS_EX_CONTROLPARENT     0x00010000L
    396 	hWndMain = CreateWindowEx(WS_EX_CONTROLPARENT,
    397 				  szAppName,
    398 				  szTitle,
    399 				  WS_VISIBLE,
    400 				  CW_USEDEFAULT,
    401 				  CW_USEDEFAULT,
    402 				  CW_USEDEFAULT,
    403 				  CW_USEDEFAULT,
    404 				  NULL,
    405 				  NULL,
    406 				  hInstance,
    407 				  NULL);
    408 
    409 	GetClientRect(hWndMain, &rect);
    410 	if (rect.right < rect.bottom) {
    411 		/*
    412 		 *	portrait
    413 		 */
    414 		CreateMainWindow(hInst, hWndMain,
    415 				 MAKEINTRESOURCE(IDD_MAIN_240X320),
    416 				 CommandBar_Height(hWndCB));
    417 	} else {
    418 		/*
    419 		 *	landscape
    420 		 */
    421 		CreateMainWindow(hInst, hWndMain,
    422 				 MAKEINTRESOURCE(IDD_MAIN_640X240),
    423 				 CommandBar_Height(hWndCB));
    424 	}
    425 	SetFocus(GetDlgItem(hWndMain, IDC_BOOT));
    426 
    427 	/*
    428 	 *  load preferences
    429 	 */
    430 	pref_init(&pref);
    431 	if (pref_load(path_list, path_list_items) == 0) {
    432 		TCHAR tmp[256];
    433 		wsprintf(tmp, TEXT("%s is loaded."), where_pref_load_from);
    434 		SetDlgItemText(hWndMain, IDC_STATUS, tmp);
    435 
    436 		fb_settings[0].type = pref.fb_type;
    437 		fb_settings[0].width = pref.fb_width;
    438 		fb_settings[0].height = pref.fb_height;
    439 		fb_settings[0].linebytes = pref.fb_linebytes;
    440 		fb_settings[0].addr = pref.fb_addr;
    441 		fb_settings[0].platid_cpu = pref.platid_cpu;
    442 		fb_settings[0].platid_machine = pref.platid_machine;
    443 	} else {
    444 		TCHAR tmpbuf[PATHBUFLEN];
    445 		wsprintf(tmpbuf, TEXT("%s%S"), path_list[0].name, "netbsd");
    446 		SetDlgItemText(hWndMain, IDC_STATUS,
    447 			       TEXT("preferences not loaded."));
    448 
    449 		pref.setting_idx = 1;
    450 		pref.fb_type = fb_settings[0].type;
    451 		pref.fb_width = fb_settings[0].width;
    452 		pref.fb_height = fb_settings[0].height;
    453 		pref.fb_linebytes = fb_settings[0].linebytes;
    454 		pref.fb_addr = fb_settings[0].addr;
    455 		pref.platid_cpu = fb_settings[0].platid_cpu;
    456 		pref.platid_machine = fb_settings[0].platid_machine;
    457 		wstrcpy(pref.setting_name, TEXT("User defined"));
    458 		wstrcpy(pref.kernel_name, tmpbuf);
    459 		wstrcpy(pref.options, TEXT(""));
    460 		pref.check_last_chance = FALSE;
    461 		pref.load_debug_info = FALSE;
    462 		pref.serial_port = FALSE;
    463 		pref.reverse_video = FALSE;
    464 	}
    465 	fb_settings[0].name = pref.setting_name;
    466 
    467 	/*
    468 	 *  initialize kernel file name list.
    469 	 */
    470 	for (i = 0; i < path_list_items; i++) {
    471 		if (path_list[i].langid == LANGID_DEFAULT ||
    472 		    path_list[i].langid == GetSystemDefaultLangID()) {
    473 			TCHAR tmpbuf[1024];
    474 			wsprintf(tmpbuf, TEXT("%s%S"),
    475 			    path_list[i].name, "netbsd");
    476 			SendDlgItemMessage(hWndMain, IDC_KERNEL,
    477 			    CB_ADDSTRING, 0, (LPARAM)tmpbuf);
    478 		}
    479 	}
    480 #ifdef ADDITIONAL_KERNELS
    481 	for (i = 0; i < kernel_list_items; i++) {
    482 		SendDlgItemMessage(hWndMain, IDC_KERNEL, CB_ADDSTRING, 0,
    483 				   (LPARAM)kernel_list[i]);
    484 	}
    485 #endif
    486 	/*
    487 	SendDlgItemMessage(hWndMain, IDC_KERNEL, CB_SETCURSEL, 0,
    488 			   (LPARAM)NULL);
    489 	*/
    490 	SetDlgItemText(hWndMain, IDC_KERNEL, pref.kernel_name);
    491 	SetDlgItemText(hWndMain, IDC_OPTIONS, pref.options);
    492 
    493 	/*
    494 	 *  Frame Buffer setting names.
    495 	 */
    496 	for (i = 0; i < ARRAYSIZEOF(fb_settings); i++) {
    497 		idx = SendDlgItemMessage(hWndMain, IDC_FBSELECT, CB_ADDSTRING,
    498 					 0, (LPARAM)fb_settings[i].name);
    499 		SendDlgItemMessage(hWndMain, IDC_FBSELECT,
    500 				   CB_SETITEMDATA, idx, (LPARAM)i);
    501 		if (i == 0) {
    502 			user_define_idx = idx;
    503 		}
    504 	}
    505 	SendDlgItemMessage(hWndMain, IDC_FBSELECT, CB_SETCURSEL,
    506 			   pref.setting_idx, (LPARAM)NULL);
    507 	/*
    508 	 *  Check box, 'Pause before boot'
    509 	 */
    510 	SendDlgItemMessage(hWndMain, IDC_PAUSE, BM_SETCHECK,
    511 			   pref.check_last_chance, 0);
    512 	SendDlgItemMessage(hWndMain, IDC_DEBUG, BM_SETCHECK,
    513 			   pref.load_debug_info, 0);
    514 	SendDlgItemMessage(hWndMain, IDC_COMM, BM_SETCHECK,
    515 			   pref.serial_port, 0);
    516 	SendDlgItemMessage(hWndMain, IDC_REVERSEVIDEO, BM_SETCHECK,
    517 			   pref.reverse_video, 0);
    518 
    519 	/*
    520 	 *  Map window and message loop
    521 	 */
    522 	ShowWindow(hWndMain, SW_SHOW);
    523 	UpdateWindow(hWndMain);
    524 	while (GetMessage(&msg, NULL, 0, 0)) {
    525 #if ( 200 <= _WIN32_WCE )
    526 		if (hWndMain == 0 || !IsDialogMessage(hWndMain, &msg))
    527 #endif
    528 		{
    529 			TranslateMessage(&msg);
    530 			DispatchMessage(&msg);
    531 		}
    532 	}
    533 
    534 	return(msg.wParam);
    535 }
    536 
    537 BOOL CALLBACK DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    538 {
    539 	switch (message) {
    540 	case WM_INITDIALOG:
    541 		return (1);
    542 
    543 	case WM_PALETTECHANGED:
    544 		palette_check(hWnd);
    545 		break;
    546 
    547 	case WM_COMMAND:
    548 		switch (LOWORD(wParam)) {
    549 		case IDCANCEL:
    550 			dlgStatus = IDCANCEL;
    551 			break;
    552 		}
    553 		break;
    554 	default:
    555 		return (0);
    556 	}
    557 }
    558 
    559 BOOL CALLBACK DlgProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    560 {
    561 	switch (message) {
    562 	case WM_INITDIALOG:
    563 		SetDlgItemText(hWnd, IDC_ABOUT_EDIT, version_string);
    564 		return (1);
    565 
    566 	case WM_PALETTECHANGED:
    567 		palette_check(hWnd);
    568 		break;
    569 
    570 	case WM_COMMAND:
    571 		switch (LOWORD(wParam)) {
    572 		case IDC_ABOUT_EDIT:
    573 			switch (HIWORD(wParam)) {
    574 			case EN_SETFOCUS:
    575 				//SendDlgItemMessage(hWnd, IDC_ABOUT_EDIT, EM_SETSEL, -1, 0);
    576 				SetFocus(GetDlgItem(hWnd, IDC_ABOUT_BITMAP));
    577 				break;
    578 			}
    579 			break;
    580 
    581 		case IDCANCEL:
    582 			EndDialog(hWnd, LOWORD(wParam));
    583 			return (1);
    584 		}
    585 		break;
    586 	default:
    587 		return (0);
    588 	}
    589 }
    590 
    591 void
    592 SetBootInfo(struct bootinfo *bi, struct fb_setting *fbs)
    593 {
    594 	TIME_ZONE_INFORMATION tz;
    595 
    596 	GetTimeZoneInformation(&tz);
    597 	memset(bi, 0, sizeof(struct bootinfo));
    598 	bi->length = sizeof(struct bootinfo);
    599 	bi->reserved = 0;
    600 	bi->magic = BOOTINFO_MAGIC;
    601 	bi->fb_addr = (unsigned char*)(fbs->addr + 0xA0000000);
    602 	bi->fb_type = fbs->type;
    603 	bi->fb_line_bytes = fbs->linebytes;
    604 	bi->fb_width = fbs->width;
    605 	bi->fb_height = fbs->height;
    606 	bi->platid_cpu = fbs->platid_cpu;
    607 	bi->platid_machine = fbs->platid_machine;
    608 	bi->timezone = tz.Bias;
    609 
    610 	debug_printf(TEXT("fb setting: %s fb_type=%d 0x%X %dx%d %d\n"),
    611 		     fbs->name,
    612 		     bi->fb_type, bi->fb_addr,
    613 		     bi->fb_width, bi->fb_height, bi->fb_line_bytes);
    614 	debug_printf(TEXT("timezone: %02ld:00\n"), (bi->timezone / 60));
    615 }
    616 
    617 
    618 void
    619 UpdateFbDlg(HWND hWnd, struct fb_setting *fbs, int direction)
    620 {
    621 	int i;
    622 	TCHAR tmpbuf[PATHBUFLEN];
    623 	int type, width, height, linebytes;
    624 	long addr;
    625 
    626 	switch (direction) {
    627 	case UPDATE_DLGBOX:
    628 		SetDlgItemText(hWnd, IDC_FB_NAME, fbs->name);
    629 
    630 		for (i = 0; i < ARRAYSIZEOF(fb_types); i++) {
    631 			if (fb_types[i].type == fbs->type) break;
    632 		}
    633 		if (ARRAYSIZEOF(fb_types) <= i) {
    634 			MessageBox(NULL, TEXT("Unknown FrameBuffer type."),
    635 				   szAppName, MB_OK);
    636 			return;
    637 		}
    638 		debug_printf(TEXT("UpdateFbDlg(%s)\n"), fbs->name);
    639 		i = SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_FINDSTRINGEXACT,
    640 				       0, (LPARAM)fb_types[i].name);
    641 		SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_SETCURSEL, i, 0);
    642 
    643 		wsprintf(tmpbuf, TEXT("%X"), fbs->addr);
    644 		SetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf);
    645 		wsprintf(tmpbuf, TEXT("%d"), fbs->width);
    646 		SetDlgItemText(hWnd, IDC_FB_WIDTH, tmpbuf);
    647 		wsprintf(tmpbuf, TEXT("%d"), fbs->height);
    648 		SetDlgItemText(hWnd, IDC_FB_HEIGHT, tmpbuf);
    649 		wsprintf(tmpbuf, TEXT("%d"), fbs->linebytes);
    650 		SetDlgItemText(hWnd, IDC_FB_LINEBYTES, tmpbuf);
    651 		wsprintf(tmpbuf, TEXT("%08X"), fbs->platid_cpu);
    652 		SetDlgItemText(hWnd, IDC_FB_CPU, tmpbuf);
    653 		wsprintf(tmpbuf, TEXT("%08X"), fbs->platid_machine);
    654 		SetDlgItemText(hWnd, IDC_FB_MACHINE, tmpbuf);
    655 		break;
    656 	case UPDATE_DATA:
    657 		GetDlgItemText(hWnd, IDC_FB_NAME, fbs->name, PATHBUFLEN);
    658 		type = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
    659 					  CB_GETCURSEL, 0, 0);
    660 		type = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
    661 					  CB_GETITEMDATA, type, 0);
    662 		GetDlgItemText(hWnd, IDC_FB_WIDTH, tmpbuf, sizeof(tmpbuf));
    663 		width = _tcstol(tmpbuf, NULL, 10);
    664 		GetDlgItemText(hWnd, IDC_FB_HEIGHT, tmpbuf, sizeof(tmpbuf));
    665 		height = _tcstol(tmpbuf, NULL, 10);
    666 		GetDlgItemText(hWnd, IDC_FB_LINEBYTES, tmpbuf, sizeof(tmpbuf));
    667 		linebytes = _tcstol(tmpbuf, NULL, 10);
    668 		GetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf, sizeof(tmpbuf));
    669 		addr = _tcstoul(tmpbuf, NULL, 16);
    670 		GetDlgItemText(hWnd, IDC_FB_CPU, tmpbuf, sizeof(tmpbuf));
    671 		fbs->platid_cpu = _tcstoul(tmpbuf, NULL, 16);
    672 		GetDlgItemText(hWnd, IDC_FB_MACHINE, tmpbuf, sizeof(tmpbuf));
    673 		fbs->platid_machine = _tcstoul(tmpbuf, NULL, 16);
    674 		fbs->type = type;
    675 		fbs->addr = addr;
    676 		fbs->width = width;
    677 		fbs->height = height;
    678 		fbs->linebytes = linebytes;
    679 
    680 		debug_printf(TEXT("type=%d  %dx%d  %d bytes/line %08x %08x\n"),
    681 			     type, width, height, linebytes,
    682 			     fbs->platid_cpu,
    683 			     fbs->platid_machine);
    684 		break;
    685 	default:
    686 		debug_printf(TEXT("UpdateFbDlg(): internal error!\n"));
    687 		break;
    688 	}
    689 }
    690 
    691 BOOL CALLBACK FbDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    692 {
    693 	int idx, i;
    694 	TCHAR tmpbuf[100];
    695 
    696 	switch (message) {
    697 	case WM_INITDIALOG:
    698 		{
    699 		UDACCEL uda;
    700 		for (i = 0; i < ARRAYSIZEOF(fb_settings); i++) {
    701 			idx = SendDlgItemMessage(hWnd, IDC_FB_NAME,
    702 						 CB_ADDSTRING, 0,
    703 						 (LPARAM)fb_settings[i].name);
    704 			SendDlgItemMessage(hWnd, IDC_FB_NAME,
    705 					   CB_SETITEMDATA, idx, (LPARAM)i);
    706 		}
    707 		for (i = 0; i < ARRAYSIZEOF(fb_size); i++) {
    708 			wsprintf(tmpbuf, TEXT("%d"), fb_size[i]);
    709 			SendDlgItemMessage(hWnd, IDC_FB_WIDTH, CB_ADDSTRING,
    710 					   0, (LPARAM)tmpbuf);
    711 			SendDlgItemMessage(hWnd, IDC_FB_HEIGHT, CB_ADDSTRING,
    712 					   0, (LPARAM)tmpbuf);
    713 		}
    714 		for (i = 0; i < ARRAYSIZEOF(fb_bpl); i++) {
    715 			wsprintf(tmpbuf, TEXT("%d"), fb_bpl[i]);
    716 			SendDlgItemMessage(hWnd, IDC_FB_LINEBYTES,
    717 					   CB_ADDSTRING, 0,
    718 					   (LPARAM)tmpbuf);
    719 		}
    720 		for (i = 0; i < ARRAYSIZEOF(fb_types); i++) {
    721 			idx = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
    722 						 CB_ADDSTRING, 0,
    723 						 (LPARAM)fb_types[i].name);
    724 			SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_SETITEMDATA,
    725 					   idx, (LPARAM)fb_types[i].type);
    726 		}
    727 		UpdateFbDlg(hWnd, &fb_settings[0], UPDATE_DLGBOX);
    728 
    729 		uda.nSec = 1;
    730 		uda.nInc = 0x100;
    731 		/*
    732 		SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN, UDM_SETACCEL,
    733 				   0, (LPARAM)&uda);
    734 		*/
    735 		/*
    736 		SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN, UDM_SETRANGE,
    737 		                   0, MAKELPARAM(UD_MAXVAL, UD_MINVAL));
    738 		*/
    739 		}
    740 		return (1);
    741 
    742 	case WM_PALETTECHANGED:
    743 		palette_check(hWnd);
    744 		break;
    745 
    746 	case WM_VSCROLL:
    747 		if ((HWND)lParam == GetDlgItem(hWnd, IDC_FB_ADDRSPIN)) {
    748 			long addr;
    749 			switch (LOWORD(wParam)) {
    750 			case SB_THUMBPOSITION:
    751 			case SB_THUMBTRACK:
    752 				GetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf, 100);
    753 				addr = _tcstoul(tmpbuf, NULL, 16);
    754 				if (50 < HIWORD(wParam)) {
    755 					addr -= 0x400;
    756 				} else {
    757 					addr += 0x400;
    758 				}
    759 				SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN,
    760 						   UDM_SETPOS, 0,
    761 						   MAKELPARAM(50, 0));
    762 				wsprintf(tmpbuf, TEXT("%X"), addr);
    763 				SetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf);
    764 				return (1);
    765 			}
    766 		}
    767 		break;
    768 
    769 	case WM_COMMAND:
    770 		switch (LOWORD(wParam)) {
    771 		case IDC_FB_NAME:
    772 			switch (HIWORD(wParam)) {
    773 			case CBN_SELCHANGE:
    774 				idx = SendDlgItemMessage(hWnd, IDC_FB_NAME,
    775 							 CB_GETCURSEL, 0, 0);
    776 				i = SendDlgItemMessage(hWnd, IDC_FB_NAME,
    777 						       CB_GETITEMDATA, idx, 0);
    778 				if (0 <= i && i < ARRAYSIZEOF(fb_settings)) {
    779 					fb_settings[0] = fb_settings[i];
    780 					UpdateFbDlg(hWnd, &fb_settings[0],
    781 						    UPDATE_DLGBOX);
    782 				}
    783 				return (1);
    784 			}
    785 			break;
    786 		case IDOK:
    787 			UpdateFbDlg(hWnd, &fb_settings[0], UPDATE_DATA);
    788 
    789 			EndDialog(hWnd, IDOK);
    790 			return (1);
    791 
    792 		case IDCANCEL:
    793 			EndDialog(hWnd, IDCANCEL);
    794 			return (1);
    795 		}
    796 		break;
    797 	}
    798 	return (0);
    799 }
    800 
    801 
    802 BOOL SerialPort(BOOL on)
    803 {
    804 	static HANDLE hPort = INVALID_HANDLE_VALUE;
    805 	BOOL res = (hPort != INVALID_HANDLE_VALUE);
    806 
    807 	if (on != res) {
    808 		if (on) {
    809 			hPort = CreateFile(TEXT("COM1:"),
    810 					   GENERIC_READ | GENERIC_WRITE,
    811 					   0, NULL, OPEN_EXISTING,
    812 					   0,
    813 					   NULL);
    814 			debug_printf(TEXT("serial port ON\n"));
    815 			if ( hPort == INVALID_HANDLE_VALUE ) {
    816 				debug_printf(TEXT("open failed\n"));
    817 			} else {
    818 #if 0
    819 				DWORD Len;
    820 				BYTE x = 'X';
    821 				WriteFile (hPort, &x, 1, &Len, 0);
    822 				WriteFile (hPort, &x, 1, &Len, 0);
    823 				WriteFile (hPort, &x, 1, &Len, 0);
    824 				WriteFile (hPort, &x, 1, &Len, 0);
    825 #endif
    826 			}
    827 		} else {
    828 			debug_printf(TEXT("serial port OFF\n"));
    829 			CloseHandle(hPort);
    830 			hPort = INVALID_HANDLE_VALUE;
    831 		}
    832 	}
    833 
    834 	return (res);
    835 }
    836 
    837 
    838 BOOL CheckCancel(int progress)
    839 {
    840 	MSG msg;
    841 
    842 	if (0 <= progress) {
    843 		SendDlgItemMessage(hDlgLoad, IDC_PROGRESS,
    844 				   PBM_SETPOS, (WPARAM)progress, (LPARAM)NULL);
    845 	} else {
    846 		if (pref.check_last_chance) {
    847 			if (msg_printf(MB_YESNO | MB_ICONHAND,
    848 			    TEXT("Last chance..."),
    849 			    TEXT("Push OK to boot.")) != IDYES) {
    850 				dlgStatus = IDCANCEL;
    851 			}
    852 		}
    853 		palette_set(hDlgLoad);
    854 		if (palette_succeeded == -1) {
    855 			msg_printf(MSG_ERROR,
    856 			    TEXT("Warning"),
    857 			    TEXT("Sorry, palette failed"));
    858 		}
    859 	}
    860 
    861 	/*
    862 	 *  Put WM_TIMER in my message queue.
    863 	 *  (WM_TIMER has lowest priority.)
    864 	 */
    865 	SetTimer(hDlgLoad, 1, 1, NULL);
    866 
    867 	/*
    868 	 *  I tried PeekMessage() but it does not work.
    869 	 */
    870 	while (GetMessage(&msg, NULL, 0, 0)) {
    871 		if (msg.hwnd == hDlgLoad && msg.message == WM_TIMER) {
    872 			break;
    873 		}
    874 		TranslateMessage(&msg);
    875 		DispatchMessage(&msg);
    876 	}
    877 
    878 	return (dlgStatus != 0);
    879 }
    880 
    881 LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
    882                           WPARAM wParam, LPARAM lParam )
    883 {
    884 	int i, idx;
    885 
    886 	switch (message) {
    887 	case WM_CREATE:
    888 		sndPlaySound(TEXT("OpenProg"), SND_NODEFAULT | SND_ASYNC);
    889 		hWndCB = CommandBar_Create(hInst, hWnd, 1);
    890 		CommandBar_AddAdornments(hWndCB, STD_HELP, (DWORD)NULL);
    891 		palette_init(hWnd);
    892 		break;
    893 
    894 	case WM_PAINT:
    895 		{
    896 		HDC          hdc;
    897 		PAINTSTRUCT  ps;
    898 
    899 		hdc = BeginPaint(hWnd, &ps);
    900 		EndPaint(hWnd, &ps);
    901 		}
    902 		break;
    903 
    904 	case WM_PALETTECHANGED:
    905 		palette_check(hWnd);
    906 		break;
    907 
    908 	case WM_HELP:
    909 		/*
    910 		MessageBox (NULL, TEXT("HELP NOT AVAILABLE"),
    911 			    szAppName, MB_OK);
    912 		*/
    913 		DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, DlgProc2);
    914         break;
    915 
    916 	case WM_COMMAND:
    917 		switch (LOWORD(wParam)) {
    918 		case IDC_BOOT:
    919 			{
    920 		       	int argc;
    921 		       	TCHAR wkernel_name[PATHBUFLEN];
    922 			TCHAR woptions[PATHBUFLEN];
    923 			char options[PATHBUFLEN*2], kernel_name[PATHBUFLEN*2];
    924 			platid_t platid;
    925 
    926 			char *p, *argv[32];
    927 			struct bootinfo bi;
    928 
    929 			if (SendDlgItemMessage(hWndMain, IDC_PAUSE,
    930 					       BM_GETCHECK, 0, 0) ==
    931 								BST_CHECKED) {
    932 				pref.check_last_chance = TRUE;
    933 			} else {
    934 				pref.check_last_chance = FALSE;
    935 			}
    936 
    937 			if (SendDlgItemMessage(hWndMain, IDC_DEBUG,
    938 					       BM_GETCHECK, 0, 0) ==
    939 								BST_CHECKED) {
    940 				pref.load_debug_info = TRUE;
    941 			} else {
    942 				pref.load_debug_info = FALSE;
    943 			}
    944 
    945 			if (SendDlgItemMessage(hWndMain, IDC_COMM,
    946 					       BM_GETCHECK, 0, 0) ==
    947 								BST_CHECKED) {
    948 				pref.serial_port = TRUE;
    949 			} else {
    950 				pref.serial_port = FALSE;
    951 			}
    952 
    953 			if (SendDlgItemMessage(hWndMain, IDC_REVERSEVIDEO,
    954 					       BM_GETCHECK, 0, 0) ==
    955 								BST_CHECKED) {
    956 				pref.reverse_video = TRUE;
    957 			} else {
    958 				pref.reverse_video = FALSE;
    959 			}
    960 
    961 			if (GetDlgItemText(hWndMain, IDC_KERNEL, wkernel_name,
    962 					   sizeof(wkernel_name)) == 0) {
    963 				MessageBox (NULL, TEXT("Kernel name required"),
    964 					    szAppName, MB_OK);
    965 				break;
    966 			}
    967 			GetDlgItemText(hWndMain, IDC_OPTIONS,
    968 				       woptions, sizeof(woptions));
    969 			if (wcstombs(options, woptions, sizeof(options)) < 0 ||
    970 			    wcstombs(kernel_name, wkernel_name,
    971 				     sizeof(kernel_name)) < 0) {
    972 				MessageBox (NULL, TEXT("invalid character"),
    973 					    szAppName, MB_OK);
    974 				break;
    975 			}
    976 
    977 			argc = 0;
    978 			argv[argc++] = kernel_name;
    979 			p = options;
    980 			while (*p) {
    981 				while (*p == ' ' || *p == '\t') {
    982 					p++;
    983 				}
    984 				if (*p == '\0')
    985 					break;
    986 				if (ARRAYSIZEOF(argv) <= argc) {
    987 					MessageBox (NULL,
    988 						    TEXT("too many options"),
    989 						    szAppName, MB_OK);
    990 					argc++;
    991 					break;
    992 				} else {
    993 					argv[argc++] = p;
    994 				}
    995 				while (*p != ' ' && *p != '\t' && *p != '\0') {
    996 					p++;
    997 				}
    998 				if (*p == '\0') {
    999 					break;
   1000 				} else {
   1001 					*p++ = '\0';
   1002 				}
   1003 			}
   1004 			if (ARRAYSIZEOF(argv) < argc) {
   1005 				break;
   1006 			}
   1007 
   1008 			EnableWindow(hWndMain, FALSE);
   1009 			if (MessageBox (hWndMain,
   1010 					TEXT("Data in memory will be lost.\nAre you sure?"),
   1011 					szAppName,
   1012 					MB_YESNO | MB_DEFBUTTON2 | MB_ICONHAND) == IDYES) {
   1013 				dlgStatus = 0;
   1014 				hDlgLoad =
   1015 				  CreateDialog(hInst,
   1016 					       MAKEINTRESOURCE(IDD_LOAD),
   1017 					       hWndMain, DlgProc);
   1018 				ShowWindow(hDlgLoad, SW_SHOWNORMAL);
   1019 				BringWindowToTop(hDlgLoad);
   1020 
   1021 				/*
   1022 				 *  save settings.
   1023 				 */
   1024 				pref.fb_type		= fb_settings[0].type;
   1025 				pref.fb_width		= fb_settings[0].width;
   1026 				pref.fb_height		= fb_settings[0].height;
   1027 				pref.fb_linebytes	= fb_settings[0].linebytes;
   1028 				pref.fb_addr		= fb_settings[0].addr;
   1029 				pref.platid_cpu		= fb_settings[0].platid_cpu;
   1030 				pref.platid_machine	= fb_settings[0].platid_machine;
   1031 				wstrcpy(pref.kernel_name, wkernel_name);
   1032 				wstrcpy(pref.options, woptions);
   1033 
   1034 				pref_save(path_list, path_list_items);
   1035 
   1036 				SetBootInfo(&bi, &fb_settings[pref.setting_idx]);
   1037 				debug_printf(TEXT("Args: "));
   1038 				for (i = 0; i < argc; i++) {
   1039 					debug_printf(TEXT("'%S' "), argv[i]);
   1040 				}
   1041 				debug_printf(TEXT("\n"));
   1042 				debug_printf(TEXT("Bootinfo: fb_type=%d 0x%X %dx%d %d\n"),
   1043 					     bi.fb_type, bi.fb_addr,
   1044 					     bi.fb_width, bi.fb_height,
   1045 					     bi.fb_line_bytes);
   1046 
   1047 				if (pref.serial_port) {
   1048 					SerialPort(TRUE);
   1049 				}
   1050 				if (pref.reverse_video) {
   1051 					bi.fb_type = reverse_fb_type(bi.fb_type);
   1052 				}
   1053 				/*
   1054 				 * Set system infomation
   1055 				 */
   1056 				platid.dw.dw0 = bi.platid_cpu;
   1057 				platid.dw.dw1 = bi.platid_machine;
   1058 				if (set_system_info(&platid)) {
   1059 					/*
   1060 					*  boot !
   1061 					*/
   1062 					pbsdboot(wkernel_name, argc, argv, &bi);
   1063 				}
   1064 				/*
   1065 				 *  Not return.
   1066 				 */
   1067 
   1068 				if (pref.serial_port) {
   1069 					SerialPort(FALSE);
   1070 				}
   1071 
   1072 				DestroyWindow(hDlgLoad);
   1073 			}
   1074 			EnableWindow(hWndMain, TRUE);
   1075 			}
   1076 			break;
   1077 		case IDC_FBSETTING:
   1078 			if (DialogBox(hInst, MAKEINTRESOURCE(IDD_FB),
   1079 				      hWndMain, FbDlgProc) == IDOK) {
   1080 				/* User defined */
   1081 				pref.setting_idx = 0;
   1082 				SendDlgItemMessage(hWndMain, IDC_FBSELECT,
   1083 						   CB_DELETESTRING,
   1084 						   (WPARAM)user_define_idx, 0);
   1085 				SendDlgItemMessage(hWndMain, IDC_FBSELECT,
   1086 						   CB_INSERTSTRING,
   1087 						   (WPARAM)user_define_idx,
   1088 						   (LPARAM)fb_settings[0].name);
   1089 				SendDlgItemMessage(hWnd, IDC_FBSELECT,
   1090 						   CB_SETCURSEL, 0, 0);
   1091 			}
   1092 			break;
   1093 		case IDC_FBSELECT:
   1094 			switch (HIWORD(wParam)) {
   1095 			case CBN_SELCHANGE:
   1096 				idx = SendDlgItemMessage(hWnd, IDC_FBSELECT,
   1097 							 CB_GETCURSEL, 0, 0);
   1098 				i = SendDlgItemMessage(hWnd, IDC_FBSELECT,
   1099 						       CB_GETITEMDATA, idx, 0);
   1100 				if (0 <= i && i < ARRAYSIZEOF(fb_settings)) {
   1101 					debug_printf(TEXT("fb_setting=%d\n"), i);
   1102 					pref.setting_idx = i;
   1103 				}
   1104 				break;
   1105 			}
   1106 			break;
   1107 		}
   1108 		break;
   1109 
   1110 	case WM_HIBERNATE:
   1111 		MessageBox(NULL, TEXT("MEMORY IS LOW"), szAppName, MB_OK);
   1112 		//Additional code to handle a low memory situation
   1113 
   1114 	case WM_CLOSE:
   1115 	        sndPlaySound(TEXT("Close"), SND_NODEFAULT | SND_ASYNC);
   1116 
   1117 		DestroyWindow(hWnd);
   1118 		break;
   1119 
   1120 	case WM_DESTROY:
   1121 	        PostQuitMessage(0);
   1122 		break;
   1123 
   1124 	default:
   1125         	return (DefWindowProc(hWnd, message, wParam, lParam));
   1126 	}
   1127 
   1128 	return (0);
   1129 }
   1130 
   1131 
   1132