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