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