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