Home | History | Annotate | Line # | Download | only in pbsdboot
main.c revision 1.43
      1 /*	$NetBSD: main.c,v 1.43 2000/06/04 04:30:48 takemura 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.14.0 2000.06.04\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 	/*
    404 	 * create log file for debugging
    405 	 */
    406 	for (i = 0; i < path_list_items; i++) {
    407 		TCHAR filenamebuf[1024];
    408 		if (!(path_list[i].flags & PATH_SAVE)) {
    409 			continue;
    410 		}
    411 		wsprintf(filenamebuf, TEXT("%s%s"),
    412 		    path_list[i].name, LOGNAME);
    413 		if (set_debug_log(filenamebuf) == 0) {
    414 			msg_printf(MSG_INFO,
    415 			    TEXT("Debug"),
    416 			    TEXT("%s was created"), LOGNAME);
    417 			break;
    418 		}
    419 	}
    420 
    421 	debug_printf(TEXT("%s"), version_string);
    422 	debug_printf(TEXT("Compiled for %d, Runtime OS version %d\n"),
    423 		     _WIN32_WCE, osversion);
    424 
    425 	wc.style          = (UINT)NULL;
    426 	wc.lpfnWndProc    = (WNDPROC) WndProc;
    427 	wc.cbClsExtra     = 0;
    428 	wc.cbWndExtra     = 0;
    429 	wc.hInstance      = hInstance;
    430 	wc.hIcon          = NULL;
    431 	wc.hCursor        = NULL;
    432 	wc.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
    433 	wc.lpszMenuName   = NULL;
    434 	wc.lpszClassName  = whoami;
    435 
    436 	RegisterClass(&wc);
    437 
    438 	InitCommonControls();   // Initialize common controls - command bar
    439 	hInst = hInstance;      // Save handle to create command bar
    440 
    441 	hardware_test();
    442 
    443 	/*
    444 	 *	Main Window
    445          */
    446 #define WS_EX_CONTROLPARENT     0x00010000L
    447 	hWndMain = CreateWindowEx((osversion < 211) ? 0 : WS_EX_CONTROLPARENT,
    448 				  szAppName,
    449 				  szTitle,
    450 				  WS_VISIBLE,
    451 				  CW_USEDEFAULT,
    452 				  CW_USEDEFAULT,
    453 				  CW_USEDEFAULT,
    454 				  CW_USEDEFAULT,
    455 				  NULL,
    456 				  NULL,
    457 				  hInstance,
    458 				  NULL);
    459 
    460 	GetClientRect(hWndMain, &rect);
    461 	if (rect.right < rect.bottom) {
    462 		/*
    463 		 *	portrait
    464 		 */
    465 		CreateMainWindow(hInst, hWndMain,
    466 				 MAKEINTRESOURCE(IDD_MAIN_240X320),
    467 				 CommandBar_Height(hWndCB));
    468 	} else {
    469 		/*
    470 		 *	landscape
    471 		 */
    472 		CreateMainWindow(hInst, hWndMain,
    473 				 MAKEINTRESOURCE(IDD_MAIN_640X240),
    474 				 CommandBar_Height(hWndCB));
    475 	}
    476 	SetFocus(GetDlgItem(hWndMain, IDC_BOOT));
    477 	SetForegroundWindow(hWndMain);
    478 
    479 	/*
    480 	 *  load preferences
    481 	 */
    482 	pref_init(&pref);
    483 	if (pref_load(path_list, path_list_items) == 0) {
    484 		stat_printf(TEXT("%s is loaded."), where_pref_load_from);
    485 
    486 		fb_settings[0].type = pref.fb_type;
    487 		fb_settings[0].width = pref.fb_width;
    488 		fb_settings[0].height = pref.fb_height;
    489 		fb_settings[0].linebytes = pref.fb_linebytes;
    490 		fb_settings[0].addr = pref.fb_addr;
    491 		fb_settings[0].platid_cpu = pref.platid_cpu;
    492 		fb_settings[0].platid_machine = pref.platid_machine;
    493 	} else {
    494 		TCHAR tmpbuf[PATHBUFLEN];
    495 		wsprintf(tmpbuf, TEXT("%s%S"), path_list[0].name, "netbsd");
    496 		stat_printf(TEXT("preferences not loaded."));
    497 
    498 		pref.setting_idx = 1;
    499 		pref.fb_type = fb_settings[0].type;
    500 		pref.fb_width = fb_settings[0].width;
    501 		pref.fb_height = fb_settings[0].height;
    502 		pref.fb_linebytes = fb_settings[0].linebytes;
    503 		pref.fb_addr = fb_settings[0].addr;
    504 		pref.platid_cpu = fb_settings[0].platid_cpu;
    505 		pref.platid_machine = fb_settings[0].platid_machine;
    506 		wstrcpy(pref.setting_name, TEXT("User defined"));
    507 		wstrcpy(pref.kernel_name, tmpbuf);
    508 		wstrcpy(pref.options, TEXT(""));
    509 		pref.check_last_chance = FALSE;
    510 		pref.load_debug_info = FALSE;
    511 		pref.serial_port = FALSE;
    512 		pref.reverse_video = FALSE;
    513 	}
    514 	fb_settings[0].name = pref.setting_name;
    515 
    516 	/*
    517 	 *  initialize kernel file name list.
    518 	 */
    519 	for (i = 0; i < path_list_items; i++) {
    520 		if (path_list[i].langid == LANGID_DEFAULT ||
    521 		    path_list[i].langid == GetSystemDefaultLangID()) {
    522 			TCHAR tmpbuf[1024];
    523 			wsprintf(tmpbuf, TEXT("%s%S"),
    524 			    path_list[i].name, "netbsd");
    525 			SendDlgItemMessage(hWndMain, IDC_KERNEL,
    526 			    CB_ADDSTRING, 0, (LPARAM)tmpbuf);
    527 		}
    528 	}
    529 #ifdef ADDITIONAL_KERNELS
    530 	for (i = 0; i < kernel_list_items; i++) {
    531 		SendDlgItemMessage(hWndMain, IDC_KERNEL, CB_ADDSTRING, 0,
    532 				   (LPARAM)kernel_list[i]);
    533 	}
    534 #endif
    535 	/*
    536 	SendDlgItemMessage(hWndMain, IDC_KERNEL, CB_SETCURSEL, 0,
    537 			   (LPARAM)NULL);
    538 	*/
    539 	SetDlgItemText(hWndMain, IDC_KERNEL, pref.kernel_name);
    540 	SetDlgItemText(hWndMain, IDC_OPTIONS, pref.options);
    541 
    542 	/*
    543 	 *  Frame Buffer setting names.
    544 	 */
    545 	for (i = 0; i < ARRAYSIZEOF(fb_settings); i++) {
    546 		idx = SendDlgItemMessage(hWndMain, IDC_FBSELECT, CB_ADDSTRING,
    547 					 0, (LPARAM)fb_settings[i].name);
    548 		SendDlgItemMessage(hWndMain, IDC_FBSELECT,
    549 				   CB_SETITEMDATA, idx, (LPARAM)i);
    550 		if (i == 0) {
    551 			user_define_idx = idx;
    552 		}
    553 	}
    554 	SendDlgItemMessage(hWndMain, IDC_FBSELECT, CB_SETCURSEL,
    555 			   pref.setting_idx, (LPARAM)NULL);
    556 	/*
    557 	 *  Check box, 'Pause before boot'
    558 	 */
    559 	SendDlgItemMessage(hWndMain, IDC_PAUSE, BM_SETCHECK,
    560 			   pref.check_last_chance, 0);
    561 	SendDlgItemMessage(hWndMain, IDC_DEBUG, BM_SETCHECK,
    562 			   pref.load_debug_info, 0);
    563 	SendDlgItemMessage(hWndMain, IDC_COMM, BM_SETCHECK,
    564 			   pref.serial_port, 0);
    565 	SendDlgItemMessage(hWndMain, IDC_REVERSEVIDEO, BM_SETCHECK,
    566 			   pref.reverse_video, 0);
    567 
    568 	/*
    569 	 *  Map window and message loop
    570 	 */
    571 	ShowWindow(hWndMain, SW_SHOW);
    572 	UpdateWindow(hWndMain);
    573 	while (GetMessage(&msg, NULL, 0, 0)) {
    574 		if (osversion < 211 ||
    575 		    hWndMain == 0 || !IsDialogMessage(hWndMain, &msg)) {
    576 			TranslateMessage(&msg);
    577 			DispatchMessage(&msg);
    578 		}
    579 	}
    580 
    581 	return(msg.wParam);
    582 }
    583 
    584 BOOL CALLBACK DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    585 {
    586 	switch (message) {
    587 	case WM_INITDIALOG:
    588 		return (1);
    589 
    590 	case WM_PALETTECHANGED:
    591 		palette_check(hWnd);
    592 		break;
    593 
    594 	case WM_COMMAND:
    595 		switch (LOWORD(wParam)) {
    596 		case IDCANCEL:
    597 			dlgStatus = IDCANCEL;
    598 			break;
    599 		}
    600 		break;
    601 	default:
    602 		return (0);
    603 	}
    604 }
    605 
    606 BOOL CALLBACK DlgProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    607 {
    608 	switch (message) {
    609 	case WM_INITDIALOG:
    610 		SetDlgItemText(hWnd, IDC_ABOUT_EDIT, version_string);
    611 		return (1);
    612 
    613 	case WM_PALETTECHANGED:
    614 		palette_check(hWnd);
    615 		break;
    616 
    617 	case WM_COMMAND:
    618 		switch (LOWORD(wParam)) {
    619 		case IDC_ABOUT_EDIT:
    620 			switch (HIWORD(wParam)) {
    621 			case EN_SETFOCUS:
    622 				//SendDlgItemMessage(hWnd, IDC_ABOUT_EDIT, EM_SETSEL, -1, 0);
    623 				SetFocus(GetDlgItem(hWnd, IDC_ABOUT_BITMAP));
    624 				break;
    625 			}
    626 			break;
    627 
    628 		case IDCANCEL:
    629 			EndDialog(hWnd, LOWORD(wParam));
    630 			return (1);
    631 		}
    632 		break;
    633 	default:
    634 		return (0);
    635 	}
    636 }
    637 
    638 void
    639 SetBootInfo(struct bootinfo *bi, struct fb_setting *fbs)
    640 {
    641 	TIME_ZONE_INFORMATION tz;
    642 
    643 	GetTimeZoneInformation(&tz);
    644 	memset(bi, 0, sizeof(struct bootinfo));
    645 	bi->length = sizeof(struct bootinfo);
    646 	bi->reserved = 0;
    647 	bi->magic = BOOTINFO_MAGIC;
    648 	bi->fb_addr = (unsigned char*)(fbs->addr + 0xA0000000);
    649 	bi->fb_type = fbs->type;
    650 	bi->fb_line_bytes = fbs->linebytes;
    651 	bi->fb_width = fbs->width;
    652 	bi->fb_height = fbs->height;
    653 	bi->platid_cpu = fbs->platid_cpu;
    654 	bi->platid_machine = fbs->platid_machine;
    655 	bi->timezone = tz.Bias;
    656 
    657 	debug_printf(TEXT("fb setting: %s fb_type=%d 0x%X %dx%d %d\n"),
    658 		     fbs->name,
    659 		     bi->fb_type, bi->fb_addr,
    660 		     bi->fb_width, bi->fb_height, bi->fb_line_bytes);
    661 	debug_printf(TEXT("timezone: %02ld:00\n"), (bi->timezone / 60));
    662 }
    663 
    664 
    665 void
    666 UpdateFbDlg(HWND hWnd, struct fb_setting *fbs, int direction)
    667 {
    668 	int i;
    669 	TCHAR tmpbuf[PATHBUFLEN];
    670 	int type, width, height, linebytes;
    671 	long addr;
    672 
    673 	switch (direction) {
    674 	case UPDATE_DLGBOX:
    675 		SetDlgItemText(hWnd, IDC_FB_NAME, fbs->name);
    676 
    677 		for (i = 0; i < ARRAYSIZEOF(fb_types); i++) {
    678 			if (fb_types[i].type == fbs->type) break;
    679 		}
    680 		if (ARRAYSIZEOF(fb_types) <= i) {
    681 			MessageBox(NULL, TEXT("Unknown FrameBuffer type."),
    682 				   szAppName, MB_OK);
    683 			return;
    684 		}
    685 		debug_printf(TEXT("UpdateFbDlg(%s)\n"), fbs->name);
    686 		i = SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_FINDSTRINGEXACT,
    687 				       0, (LPARAM)fb_types[i].name);
    688 		SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_SETCURSEL, i, 0);
    689 
    690 		wsprintf(tmpbuf, TEXT("%X"), fbs->addr);
    691 		SetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf);
    692 		wsprintf(tmpbuf, TEXT("%d"), fbs->width);
    693 		SetDlgItemText(hWnd, IDC_FB_WIDTH, tmpbuf);
    694 		wsprintf(tmpbuf, TEXT("%d"), fbs->height);
    695 		SetDlgItemText(hWnd, IDC_FB_HEIGHT, tmpbuf);
    696 		wsprintf(tmpbuf, TEXT("%d"), fbs->linebytes);
    697 		SetDlgItemText(hWnd, IDC_FB_LINEBYTES, tmpbuf);
    698 		wsprintf(tmpbuf, TEXT("%08X"), fbs->platid_cpu);
    699 		SetDlgItemText(hWnd, IDC_FB_CPU, tmpbuf);
    700 		wsprintf(tmpbuf, TEXT("%08X"), fbs->platid_machine);
    701 		SetDlgItemText(hWnd, IDC_FB_MACHINE, tmpbuf);
    702 		break;
    703 	case UPDATE_DATA:
    704 		GetDlgItemText(hWnd, IDC_FB_NAME, fbs->name, PATHBUFLEN);
    705 		type = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
    706 					  CB_GETCURSEL, 0, 0);
    707 		type = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
    708 					  CB_GETITEMDATA, type, 0);
    709 		GetDlgItemText(hWnd, IDC_FB_WIDTH, tmpbuf, sizeof(tmpbuf));
    710 		width = _tcstol(tmpbuf, NULL, 10);
    711 		GetDlgItemText(hWnd, IDC_FB_HEIGHT, tmpbuf, sizeof(tmpbuf));
    712 		height = _tcstol(tmpbuf, NULL, 10);
    713 		GetDlgItemText(hWnd, IDC_FB_LINEBYTES, tmpbuf, sizeof(tmpbuf));
    714 		linebytes = _tcstol(tmpbuf, NULL, 10);
    715 		GetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf, sizeof(tmpbuf));
    716 		addr = _tcstoul(tmpbuf, NULL, 16);
    717 		GetDlgItemText(hWnd, IDC_FB_CPU, tmpbuf, sizeof(tmpbuf));
    718 		fbs->platid_cpu = _tcstoul(tmpbuf, NULL, 16);
    719 		GetDlgItemText(hWnd, IDC_FB_MACHINE, tmpbuf, sizeof(tmpbuf));
    720 		fbs->platid_machine = _tcstoul(tmpbuf, NULL, 16);
    721 		fbs->type = type;
    722 		fbs->addr = addr;
    723 		fbs->width = width;
    724 		fbs->height = height;
    725 		fbs->linebytes = linebytes;
    726 
    727 		debug_printf(TEXT("type=%d  %dx%d  %d bytes/line %08x %08x\n"),
    728 			     type, width, height, linebytes,
    729 			     fbs->platid_cpu,
    730 			     fbs->platid_machine);
    731 		break;
    732 	default:
    733 		debug_printf(TEXT("UpdateFbDlg(): internal error!\n"));
    734 		break;
    735 	}
    736 }
    737 
    738 BOOL CALLBACK FbDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    739 {
    740 	int idx, i;
    741 	TCHAR tmpbuf[100];
    742 
    743 	switch (message) {
    744 	case WM_INITDIALOG:
    745 		{
    746 		UDACCEL uda;
    747 		for (i = 0; i < ARRAYSIZEOF(fb_settings); i++) {
    748 			idx = SendDlgItemMessage(hWnd, IDC_FB_NAME,
    749 						 CB_ADDSTRING, 0,
    750 						 (LPARAM)fb_settings[i].name);
    751 			SendDlgItemMessage(hWnd, IDC_FB_NAME,
    752 					   CB_SETITEMDATA, idx, (LPARAM)i);
    753 		}
    754 		for (i = 0; i < ARRAYSIZEOF(fb_size); i++) {
    755 			wsprintf(tmpbuf, TEXT("%d"), fb_size[i]);
    756 			SendDlgItemMessage(hWnd, IDC_FB_WIDTH, CB_ADDSTRING,
    757 					   0, (LPARAM)tmpbuf);
    758 			SendDlgItemMessage(hWnd, IDC_FB_HEIGHT, CB_ADDSTRING,
    759 					   0, (LPARAM)tmpbuf);
    760 		}
    761 		for (i = 0; i < ARRAYSIZEOF(fb_bpl); i++) {
    762 			wsprintf(tmpbuf, TEXT("%d"), fb_bpl[i]);
    763 			SendDlgItemMessage(hWnd, IDC_FB_LINEBYTES,
    764 					   CB_ADDSTRING, 0,
    765 					   (LPARAM)tmpbuf);
    766 		}
    767 		for (i = 0; i < ARRAYSIZEOF(fb_types); i++) {
    768 			idx = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
    769 						 CB_ADDSTRING, 0,
    770 						 (LPARAM)fb_types[i].name);
    771 			SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_SETITEMDATA,
    772 					   idx, (LPARAM)fb_types[i].type);
    773 		}
    774 		UpdateFbDlg(hWnd, &fb_settings[0], UPDATE_DLGBOX);
    775 
    776 		uda.nSec = 1;
    777 		uda.nInc = 0x100;
    778 		/*
    779 		SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN, UDM_SETACCEL,
    780 				   0, (LPARAM)&uda);
    781 		*/
    782 		/*
    783 		SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN, UDM_SETRANGE,
    784 		                   0, MAKELPARAM(UD_MAXVAL, UD_MINVAL));
    785 		*/
    786 		}
    787 		return (1);
    788 
    789 	case WM_PALETTECHANGED:
    790 		palette_check(hWnd);
    791 		break;
    792 
    793 	case WM_VSCROLL:
    794 		if ((HWND)lParam == GetDlgItem(hWnd, IDC_FB_ADDRSPIN)) {
    795 			long addr;
    796 			switch (LOWORD(wParam)) {
    797 			case SB_THUMBPOSITION:
    798 			case SB_THUMBTRACK:
    799 				GetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf, 100);
    800 				addr = _tcstoul(tmpbuf, NULL, 16);
    801 				if (50 < HIWORD(wParam)) {
    802 					addr -= 0x400;
    803 				} else {
    804 					addr += 0x400;
    805 				}
    806 				SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN,
    807 						   UDM_SETPOS, 0,
    808 						   MAKELPARAM(50, 0));
    809 				wsprintf(tmpbuf, TEXT("%X"), addr);
    810 				SetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf);
    811 				return (1);
    812 			}
    813 		}
    814 		break;
    815 
    816 	case WM_COMMAND:
    817 		switch (LOWORD(wParam)) {
    818 		case IDC_FB_NAME:
    819 			switch (HIWORD(wParam)) {
    820 			case CBN_SELCHANGE:
    821 				idx = SendDlgItemMessage(hWnd, IDC_FB_NAME,
    822 							 CB_GETCURSEL, 0, 0);
    823 				i = SendDlgItemMessage(hWnd, IDC_FB_NAME,
    824 						       CB_GETITEMDATA, idx, 0);
    825 				if (0 <= i && i < ARRAYSIZEOF(fb_settings)) {
    826 					fb_settings[0] = fb_settings[i];
    827 					UpdateFbDlg(hWnd, &fb_settings[0],
    828 						    UPDATE_DLGBOX);
    829 				}
    830 				return (1);
    831 			}
    832 			break;
    833 		case IDOK:
    834 			UpdateFbDlg(hWnd, &fb_settings[0], UPDATE_DATA);
    835 
    836 			EndDialog(hWnd, IDOK);
    837 			return (1);
    838 
    839 		case IDCANCEL:
    840 			EndDialog(hWnd, IDCANCEL);
    841 			return (1);
    842 		}
    843 		break;
    844 	}
    845 	return (0);
    846 }
    847 
    848 
    849 BOOL SerialPort(BOOL on)
    850 {
    851 	static HANDLE hPort = INVALID_HANDLE_VALUE;
    852 	BOOL res = (hPort != INVALID_HANDLE_VALUE);
    853 
    854 	if (on != res) {
    855 		if (on) {
    856 			hPort = CreateFile(TEXT("COM1:"),
    857 					   GENERIC_READ | GENERIC_WRITE,
    858 					   0, NULL, OPEN_EXISTING,
    859 					   0,
    860 					   NULL);
    861 			debug_printf(TEXT("serial port ON\n"));
    862 			if ( hPort == INVALID_HANDLE_VALUE ) {
    863 				debug_printf(TEXT("open failed\n"));
    864 			} else {
    865 #if 0
    866 				DWORD Len;
    867 				BYTE x = 'X';
    868 				WriteFile (hPort, &x, 1, &Len, 0);
    869 				WriteFile (hPort, &x, 1, &Len, 0);
    870 				WriteFile (hPort, &x, 1, &Len, 0);
    871 				WriteFile (hPort, &x, 1, &Len, 0);
    872 #endif
    873 			}
    874 		} else {
    875 			debug_printf(TEXT("serial port OFF\n"));
    876 			CloseHandle(hPort);
    877 			hPort = INVALID_HANDLE_VALUE;
    878 		}
    879 	}
    880 
    881 	return (res);
    882 }
    883 
    884 
    885 BOOL CheckCancel(int progress)
    886 {
    887 	MSG msg;
    888 
    889 	if (0 <= progress) {
    890 		SendDlgItemMessage(hDlgLoad, IDC_PROGRESS,
    891 				   PBM_SETPOS, (WPARAM)progress, (LPARAM)NULL);
    892 	} else {
    893 		if (pref.check_last_chance) {
    894 			if (msg_printf(MB_YESNO | MB_ICONHAND,
    895 			    TEXT("Last chance..."),
    896 			    TEXT("Push OK to boot.")) != IDYES) {
    897 				dlgStatus = IDCANCEL;
    898 			}
    899 		}
    900 		palette_set(hDlgLoad);
    901 		if (palette_succeeded == -1) {
    902 			msg_printf(MSG_ERROR,
    903 			    TEXT("Warning"),
    904 			    TEXT("Sorry, palette failed"));
    905 		}
    906 	}
    907 
    908 	/*
    909 	 *  Put WM_TIMER in my message queue.
    910 	 *  (WM_TIMER has lowest priority.)
    911 	 */
    912 	SetTimer(hDlgLoad, 1, 1, NULL);
    913 
    914 	/*
    915 	 *  I tried PeekMessage() but it does not work.
    916 	 */
    917 	while (GetMessage(&msg, NULL, 0, 0)) {
    918 		if (msg.hwnd == hDlgLoad && msg.message == WM_TIMER) {
    919 			break;
    920 		}
    921 		TranslateMessage(&msg);
    922 		DispatchMessage(&msg);
    923 	}
    924 
    925 	return (dlgStatus != 0);
    926 }
    927 
    928 LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
    929                           WPARAM wParam, LPARAM lParam )
    930 {
    931 	int i, idx;
    932 
    933 	switch (message) {
    934 	case WM_CREATE:
    935 		sndPlaySound(TEXT("OpenProg"), SND_NODEFAULT | SND_ASYNC);
    936 		hWndCB = CommandBar_Create(hInst, hWnd, 1);
    937 		CommandBar_AddAdornments(hWndCB, STD_HELP, (DWORD)NULL);
    938 		palette_init(hWnd);
    939 		break;
    940 
    941 	case WM_PAINT:
    942 		{
    943 		HDC          hdc;
    944 		PAINTSTRUCT  ps;
    945 
    946 		hdc = BeginPaint(hWnd, &ps);
    947 		EndPaint(hWnd, &ps);
    948 		}
    949 		break;
    950 
    951 	case WM_PALETTECHANGED:
    952 		palette_check(hWnd);
    953 		break;
    954 
    955 	case WM_HELP:
    956 		/*
    957 		MessageBox (NULL, TEXT("HELP NOT AVAILABLE"),
    958 			    szAppName, MB_OK);
    959 		*/
    960 		DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, DlgProc2);
    961         break;
    962 
    963 	case WM_COMMAND:
    964 		switch (LOWORD(wParam)) {
    965 		case IDC_BOOT:
    966 			{
    967 		       	int argc;
    968 		       	TCHAR wkernel_name[PATHBUFLEN];
    969 			TCHAR woptions[PATHBUFLEN];
    970 			char options[PATHBUFLEN*2], kernel_name[PATHBUFLEN*2];
    971 			platid_t platid;
    972 
    973 			char *p, *argv[32];
    974 			struct bootinfo bi;
    975 
    976 			if (SendDlgItemMessage(hWndMain, IDC_PAUSE,
    977 					       BM_GETCHECK, 0, 0) ==
    978 								BST_CHECKED) {
    979 				pref.check_last_chance = TRUE;
    980 			} else {
    981 				pref.check_last_chance = FALSE;
    982 			}
    983 
    984 			if (SendDlgItemMessage(hWndMain, IDC_DEBUG,
    985 					       BM_GETCHECK, 0, 0) ==
    986 								BST_CHECKED) {
    987 				pref.load_debug_info = TRUE;
    988 			} else {
    989 				pref.load_debug_info = FALSE;
    990 			}
    991 
    992 			if (SendDlgItemMessage(hWndMain, IDC_COMM,
    993 					       BM_GETCHECK, 0, 0) ==
    994 								BST_CHECKED) {
    995 				pref.serial_port = TRUE;
    996 			} else {
    997 				pref.serial_port = FALSE;
    998 			}
    999 
   1000 			if (SendDlgItemMessage(hWndMain, IDC_REVERSEVIDEO,
   1001 					       BM_GETCHECK, 0, 0) ==
   1002 								BST_CHECKED) {
   1003 				pref.reverse_video = TRUE;
   1004 			} else {
   1005 				pref.reverse_video = FALSE;
   1006 			}
   1007 
   1008 			if (GetDlgItemText(hWndMain, IDC_KERNEL, wkernel_name,
   1009 					   sizeof(wkernel_name)) == 0) {
   1010 				MessageBox (NULL, TEXT("Kernel name required"),
   1011 					    szAppName, MB_OK);
   1012 				break;
   1013 			}
   1014 			GetDlgItemText(hWndMain, IDC_OPTIONS,
   1015 				       woptions, sizeof(woptions));
   1016 			if (wcstombs(options, woptions, sizeof(options)) < 0 ||
   1017 			    wcstombs(kernel_name, wkernel_name,
   1018 				     sizeof(kernel_name)) < 0) {
   1019 				MessageBox (NULL, TEXT("invalid character"),
   1020 					    szAppName, MB_OK);
   1021 				break;
   1022 			}
   1023 
   1024 			argc = 0;
   1025 			argv[argc++] = kernel_name;
   1026 			p = options;
   1027 			while (*p) {
   1028 				while (*p == ' ' || *p == '\t') {
   1029 					p++;
   1030 				}
   1031 				if (*p == '\0')
   1032 					break;
   1033 				if (ARRAYSIZEOF(argv) <= argc) {
   1034 					MessageBox (NULL,
   1035 						    TEXT("too many options"),
   1036 						    szAppName, MB_OK);
   1037 					argc++;
   1038 					break;
   1039 				} else {
   1040 					argv[argc++] = p;
   1041 				}
   1042 				while (*p != ' ' && *p != '\t' && *p != '\0') {
   1043 					p++;
   1044 				}
   1045 				if (*p == '\0') {
   1046 					break;
   1047 				} else {
   1048 					*p++ = '\0';
   1049 				}
   1050 			}
   1051 			if (ARRAYSIZEOF(argv) < argc) {
   1052 				break;
   1053 			}
   1054 
   1055 			EnableWindow(hWndMain, FALSE);
   1056 			if (MessageBox (hWndMain,
   1057 					TEXT("Data in memory will be lost.\nAre you sure?"),
   1058 					szAppName,
   1059 					MB_YESNO | MB_DEFBUTTON2 | MB_ICONHAND) == IDYES) {
   1060 				dlgStatus = 0;
   1061 				hDlgLoad =
   1062 				  CreateDialog(hInst,
   1063 					       MAKEINTRESOURCE(IDD_LOAD),
   1064 					       hWndMain, DlgProc);
   1065 				ShowWindow(hDlgLoad, SW_SHOWNORMAL);
   1066 				BringWindowToTop(hDlgLoad);
   1067 
   1068 				/*
   1069 				 *  save settings.
   1070 				 */
   1071 				pref.fb_type		= fb_settings[0].type;
   1072 				pref.fb_width		= fb_settings[0].width;
   1073 				pref.fb_height		= fb_settings[0].height;
   1074 				pref.fb_linebytes	= fb_settings[0].linebytes;
   1075 				pref.fb_addr		= fb_settings[0].addr;
   1076 				pref.platid_cpu		= fb_settings[0].platid_cpu;
   1077 				pref.platid_machine	= fb_settings[0].platid_machine;
   1078 				wstrcpy(pref.kernel_name, wkernel_name);
   1079 				wstrcpy(pref.options, woptions);
   1080 
   1081 				pref_save(path_list, path_list_items);
   1082 
   1083 				SetBootInfo(&bi, &fb_settings[pref.setting_idx]);
   1084 				debug_printf(TEXT("Args: "));
   1085 				for (i = 0; i < argc; i++) {
   1086 					debug_printf(TEXT("'%S' "), argv[i]);
   1087 				}
   1088 				debug_printf(TEXT("\n"));
   1089 				debug_printf(TEXT("Bootinfo: fb_type=%d 0x%X %dx%d %d\n"),
   1090 					     bi.fb_type, bi.fb_addr,
   1091 					     bi.fb_width, bi.fb_height,
   1092 					     bi.fb_line_bytes);
   1093 
   1094 				if (pref.serial_port) {
   1095 					SerialPort(TRUE);
   1096 				}
   1097 				if (pref.reverse_video) {
   1098 					bi.fb_type = reverse_fb_type(bi.fb_type);
   1099 				}
   1100 				/*
   1101 				 * Set system infomation
   1102 				 */
   1103 				platid.dw.dw0 = bi.platid_cpu;
   1104 				platid.dw.dw1 = bi.platid_machine;
   1105 				if (set_system_info(&platid)) {
   1106 					/*
   1107 					*  boot !
   1108 					*/
   1109 					pbsdboot(wkernel_name, argc, argv, &bi);
   1110 				}
   1111 				/*
   1112 				 *  Not return.
   1113 				 */
   1114 
   1115 				if (pref.serial_port) {
   1116 					SerialPort(FALSE);
   1117 				}
   1118 
   1119 				DestroyWindow(hDlgLoad);
   1120 			}
   1121 			EnableWindow(hWndMain, TRUE);
   1122 			}
   1123 			break;
   1124 		case IDC_FBSETTING:
   1125 			if (DialogBox(hInst, MAKEINTRESOURCE(IDD_FB),
   1126 				      hWndMain, FbDlgProc) == IDOK) {
   1127 				/* User defined */
   1128 				pref.setting_idx = 0;
   1129 				SendDlgItemMessage(hWndMain, IDC_FBSELECT,
   1130 						   CB_DELETESTRING,
   1131 						   (WPARAM)user_define_idx, 0);
   1132 				SendDlgItemMessage(hWndMain, IDC_FBSELECT,
   1133 						   CB_INSERTSTRING,
   1134 						   (WPARAM)user_define_idx,
   1135 						   (LPARAM)fb_settings[0].name);
   1136 				SendDlgItemMessage(hWnd, IDC_FBSELECT,
   1137 						   CB_SETCURSEL, 0, 0);
   1138 			}
   1139 			break;
   1140 		case IDC_FBSELECT:
   1141 			switch (HIWORD(wParam)) {
   1142 			case CBN_SELCHANGE:
   1143 				idx = SendDlgItemMessage(hWnd, IDC_FBSELECT,
   1144 							 CB_GETCURSEL, 0, 0);
   1145 				i = SendDlgItemMessage(hWnd, IDC_FBSELECT,
   1146 						       CB_GETITEMDATA, idx, 0);
   1147 				if (0 <= i && i < ARRAYSIZEOF(fb_settings)) {
   1148 					debug_printf(TEXT("fb_setting=%d\n"), i);
   1149 					pref.setting_idx = i;
   1150 				}
   1151 				break;
   1152 			}
   1153 			break;
   1154 		}
   1155 		break;
   1156 
   1157 	case WM_HIBERNATE:
   1158 		MessageBox(NULL, TEXT("MEMORY IS LOW"), szAppName, MB_OK);
   1159 		//Additional code to handle a low memory situation
   1160 
   1161 	case WM_CLOSE:
   1162 	        sndPlaySound(TEXT("Close"), SND_NODEFAULT | SND_ASYNC);
   1163 
   1164 		DestroyWindow(hWnd);
   1165 		break;
   1166 
   1167 	case WM_DESTROY:
   1168 	        PostQuitMessage(0);
   1169 		break;
   1170 
   1171 	default:
   1172         	return (DefWindowProc(hWnd, message, wParam, lParam));
   1173 	}
   1174 
   1175 	return (0);
   1176 }
   1177 
   1178 
   1179