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