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