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