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