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