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