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