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