Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / hpcmips / stand / pbsdboot / main.c
blob49da0ecb82f1840c3d496e3016649890d9427013
1 /* $NetBSD: main.c,v 1.61 2006/03/09 18:08:32 wiz Exp $ */
3 /*-
4 * Copyright (c) 1999, 2000 Shin Takemura.
5 * All rights reserved.
7 * This software is part of the PocketBSD.
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.
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.
38 #include <pbsdboot.h>
39 #include <commctrl.h>
40 #include <res/resource.h>
43 * If you modify this program and update pbsdboot.uu,
44 * change version string which is coded in main.c
45 * appropriately.
47 * The version string is in format:
49 * Version A.B.C YYYY.MM.DD
51 * in where:
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
60 TCHAR *version_string =
61 TEXT("PocketBSD boot loader\r\n")
62 TEXT("Version 1.17.5 2001.05.05\r\n")
63 #if ( _WIN32_WCE < 200 )
64 TEXT("Compiled for WinCE 1.01\r\n")
65 #else
66 TEXT("Compiled for WinCE 2.00\r\n")
67 #endif
68 TEXT("\r\n")
69 TEXT("Copyright(C) 1999 Shin Takemura,\r\n")
70 TEXT("All rights reserved.\r\n")
71 TEXT("\r\n")
72 TEXT("http://www.NetBSD.org/ports/hpcmips/\r\n");
74 /*-----------------------------------------------------------------------------
76 type difinitions
78 -----------------------------------------------------------------------------*/
79 enum {
80 UPDATE_DLGBOX,
81 UPDATE_DATA,
84 struct fb_type {
85 int type;
86 TCHAR *name;
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;
99 /*-----------------------------------------------------------------------------
101 variable declarations
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;
115 /*-----------------------------------------------------------------------------
117 data
119 -----------------------------------------------------------------------------*/
120 TCHAR szAppName[ ] = TEXT("PocketBSD boot");
121 TCHAR szTitle[ ] = TEXT("Welcome to PocketBSD!");
122 int errno;
125 * Wince_conf identify executable binary file.
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
133 #define IDD_TIMER 300
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) },
150 int fb_size[] = {
151 160, 240, 320, 400, 480, 600, 640,
152 768, 800, 1024, 1150, 1280, 1600
155 int boot_times[] = {
156 30,25,20,15,10,5
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
164 struct fb_setting fb_settings[] = {
166 * You must choose fb_type to make the screen looks like:
167 * black-on-white on monochrome or gray scale screen
168 * white-on-black on color screen
169 * without 'reverse video' on the properties daialog.
171 * 'black-on-white' means that Foreground color is black and
172 * background color is white.
174 { NULL, BIFB_D2_M2L_3,
175 320, 240, 80, 0xa000000,
176 PLATID_UNKNOWN, PLATID_UNKNOWN },
177 { TEXT("FreeStyle"), BIFB_D2_M2L_3,
178 320, 240, 80, 0xa000000,
179 PLATID_CPU_MIPS_VR_41XX, PLATID_MACH_EVEREX_FREESTYLE_AXX },
180 { TEXT("FreeStyle(Small Font)"), BIFB_D2_M2L_3x2,
181 640, 240, 80, 0xa000000,
182 PLATID_CPU_MIPS_VR_41XX, PLATID_MACH_EVEREX_FREESTYLE_AXX },
183 { TEXT("MobileGear MC-CS11"), BIFB_D2_M2L_0,
184 480, 240, 256, 0xa000000,
185 PLATID_CPU_MIPS_VR_4102, PLATID_MACH_NEC_MCCS_11 },
186 { TEXT("MobileGear MC-CS12"), BIFB_D2_M2L_0,
187 480, 240, 256, 0xa000000,
188 PLATID_CPU_MIPS_VR_4102, PLATID_MACH_NEC_MCCS_12 },
189 { TEXT("MobileGear MC-CS13"), BIFB_D2_M2L_0,
190 480, 240, 256, 0xa000000,
191 PLATID_CPU_MIPS_VR_4102, PLATID_MACH_NEC_MCCS_13 },
192 { TEXT("Mobile Pro 700"), BIFB_D2_M2L_0,
193 640, 240, 256, 0xa000000,
194 PLATID_CPU_MIPS_VR_4102, PLATID_MACH_NEC_MCR_MPRO700 },
195 { TEXT("MobileGearII MC-R300"), BIFB_D2_M2L_0,
196 640, 240, 256, 0xa000000,
197 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_300 },
198 { TEXT("MobileGearII for DoCoMo"), BIFB_D2_M2L_0,
199 640, 240, 256, 0xa000000,
200 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_FORDOCOMO },
201 { TEXT("MobileGearII MC-R320"), BIFB_D2_M2L_0,
202 640, 240, 160, 0xa000000,
203 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_320 },
204 { TEXT("MobileGearII MC/R330"), BIFB_D2_M2L_0,
205 640, 240, 160, 0xa000000,
206 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_330 },
207 { TEXT("MobileGearII MC/R430"), BIFB_D16_0000,
208 640, 240, 1280, 0xa180100,
209 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_430 },
210 { TEXT("MobileGearII MC-R500"), BIFB_D8_00,
211 640, 240, 1024, 0x13000000,
212 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_500 },
213 { TEXT("Mobile Pro 750c"), BIFB_D8_00,
214 640, 240, 1024, 0x13000000,
215 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_NEC_MCR_500A },
216 { TEXT("MobileGearII MC-R510"), BIFB_D8_00,
217 640, 240, 1024, 0xa000000,
218 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_510 },
219 { TEXT("NEC MC-R510(15bit color)"), BIFB_D16_0000,
220 640, 240, 1600, 0xa000000,
221 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_510 },
222 { TEXT("MobileGearII MC-R520"), BIFB_D16_0000,
223 640, 240, 1600, 0xa000000,
224 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_520 },
225 { TEXT("NEC MC/R530(256 colors)"), BIFB_D8_00,
226 640, 240, 640, 0xa1d4c00,
227 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_530 },
228 { TEXT("MobileGearII MC/R530"), BIFB_D16_0000,
229 640, 240, 1280, 0xa180100,
230 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_530 },
231 { TEXT("MobileGearII MC/R550"), BIFB_D16_0000,
232 640, 240, 1280, 0xa180100,
233 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_530 },
234 { TEXT("DoCoMo sigmarion"), BIFB_D16_0000,
235 640, 240, 1280, 0xa000000,
236 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_SIGMARION },
237 { TEXT("Mobile Pro 770"), BIFB_D16_0000,
238 640, 240, 1600, 0xa000000,
239 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_520A },
240 { TEXT("Mobile Pro 780"), BIFB_D16_0000,
241 640, 240, 1280, 0xa180100,
242 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_530A },
243 { TEXT("MobileGearII MC-R700"), BIFB_D16_0000,
244 800, 600, 1600, 0xa000000,
245 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_700 },
246 { TEXT("Mobile Pro 800"), BIFB_D16_0000,
247 800, 600, 1600, 0xa000000,
248 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_700A },
249 { TEXT("MobileGearII MC/R730"), BIFB_D16_0000,
250 800, 600, 1600, 0xa0ea600,
251 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_730 },
252 { TEXT("Mobile Pro 880"), BIFB_D16_0000,
253 800, 600, 1600, 0xa0ea600,
254 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_NEC_MCR_730A },
255 { TEXT("Tripad PV-6000"), BIFB_D8_00,
256 640, 480, 640, 0xa000000,
257 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_SHARP_TRIPAD_PV6000 },
258 { TEXT("Vadem Clio C-1000"), BIFB_D8_00,
259 640, 480, 640, 0xa000000,
260 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_SHARP_TRIPAD_PV6000 },
261 { TEXT("Vadem Clio C-1050"), BIFB_D16_FFFF,
262 640, 480, 1280, 0xa200000,
263 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_SHARP_TRIPAD_PV6000 },
264 { TEXT("E-55"), BIFB_D2_M2L_0,
265 240, 320, 256, 0xa000000,
266 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_CASIO_CASSIOPEIAE_E55 },
267 { TEXT("E-55(Small Font)"), BIFB_D2_M2L_0x2,
268 480, 320, 256, 0xa000000,
269 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_CASIO_CASSIOPEIAE_E55 },
270 { TEXT("E-100"), BIFB_D16_FFFF,
271 240, 320, 512, 0xa200000,
272 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_CASIO_CASSIOPEIAE_E100 },
273 { TEXT("E-500"), BIFB_D16_FFFF,
274 240, 320, 512, 0xa200000,
275 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_CASIO_CASSIOPEIAE_E500 },
276 { TEXT("PocketPostPet"), BIFB_D16_FFFF,
277 320, 240, 1024, 0xa200000,
278 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_CASIO_POCKETPOSTPET_POCKETPOSTPET },
279 { TEXT("INTERTOP CX300"), BIFB_D8_00,
280 640, 480, 640, 0xa000000,
281 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_FUJITSU_INTERTOP_IT300 },
282 { TEXT("INTERTOP CX300(16bpp)"), BIFB_D16_0000,
283 640, 480, 1280, 0xa000000,
284 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_FUJITSU_INTERTOP_IT300 },
285 { TEXT("INTERTOP CX310"), BIFB_D8_00,
286 640, 480, 640, 0xa000000,
287 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_FUJITSU_INTERTOP_IT310 },
288 { TEXT("PenCentra 130"), BIFB_D8_00,
289 640, 480, 640, 0x10201e00,
290 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_FUJITSU_PENCENTRA_130 },
291 { TEXT("IBM WorkPad z50"), BIFB_D16_0000,
292 640, 480, 1280, 0xa000000,
293 PLATID_CPU_MIPS_VR_4121, PLATID_MACH_IBM_WORKPAD_26011AU },
294 { TEXT("Philips Nino 312"), BIFB_D2_M2L_0,
295 240, 320, 0, 0,
296 PLATID_CPU_MIPS_TX_3912, PLATID_MACH_PHILIPS_NINO_312 },
297 { TEXT("Compaq C-series 810"), BIFB_D2_M2L_0,
298 640, 240, 0, 0,
299 PLATID_CPU_MIPS_TX_3912, PLATID_MACH_COMPAQ_C_810 },
300 { TEXT("Compaq C-series 2010c"), BIFB_D8_00,
301 640, 240, 0, 0,
302 PLATID_CPU_MIPS_TX_3912, PLATID_MACH_COMPAQ_C_2010 },
303 { TEXT("Compaq C-series 2015c"), BIFB_D8_00,
304 640, 240, 0, 0,
305 PLATID_CPU_MIPS_TX_3912, PLATID_MACH_COMPAQ_C_2015 },
306 { TEXT("Compaq PRESARIO 213"), BIFB_D8_00,
307 320, 240, 0, 0,
308 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_COMPAQ_PRESARIO_213 },
309 { TEXT("Compaq Aero 1530"), BIFB_D4_M2L_F,
310 320, 240, 160, 0x0a000000,
311 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_COMPAQ_AERO_1530 },
312 { TEXT("Aero1530(Small Font)"), BIFB_D4_M2L_Fx2,
313 640, 240, 160, 0x0a000000,
314 PLATID_CPU_MIPS_VR_4111, PLATID_MACH_COMPAQ_AERO_1530 },
315 { TEXT("Victor InterLink MP-C101"), BIFB_D16_0000,
316 640, 480, 0, 0,
317 PLATID_CPU_MIPS_TX_3922, PLATID_MACH_VICTOR_INTERLINK_MPC101},
318 { TEXT("Sharp Telios HC-AJ1/AJ2"), BIFB_D16_0000,
319 800, 600, 0, 0,
320 PLATID_CPU_MIPS_TX_3922, PLATID_MACH_SHARP_TELIOS_HCAJ1},
321 { TEXT("Sharp Telios HC-VJ1C (Japanese)"), BIFB_D16_0000,
322 800, 480, 0, 0,
323 PLATID_CPU_MIPS_TX_3922, PLATID_MACH_SHARP_TELIOS_HCVJ1C_JP},
324 { TEXT("Sharp Mobilon HC-4100/4500"), BIFB_D2_M2L_0, /* XXX 4bit greyscale */
325 640, 240, 0, 0,
326 PLATID_CPU_MIPS_TX_3912, PLATID_MACH_SHARP_MOBILON_HC4100},
327 { TEXT("Sharp HC-1200"), BIFB_D2_M2L_0, /* XXX 4bit greyscale */
328 640, 240, 0, 0,
329 PLATID_CPU_MIPS_TX_3912, PLATID_MACH_SHARP_MOBILON_HC1200},
332 #define ARRAYSIZEOF(a) (sizeof(a)/sizeof(*(a)))
334 #ifdef UNDER_CE
335 /* 'memory card' in HANKAKU KANA */
336 #define UNICODE_MEMORY_CARD \
337 TEXT('\\'), 0xff92, 0xff93, 0xff98, TEXT(' '), 0xff76, 0xff70, \
338 0xff84, 0xff9e
339 TCHAR unicode_memory_card[] = { UNICODE_MEMORY_CARD, TEXT('\\'), 0 };
340 TCHAR unicode_memory_card1[] = { UNICODE_MEMORY_CARD, TEXT('1'),TEXT('\\'),0 };
341 TCHAR unicode_memory_card2[] = { UNICODE_MEMORY_CARD, TEXT('2'),TEXT('\\'),0 };
342 #endif
344 #define LANGID_DEFAULT MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT)
345 struct path_s path_list[] = {
346 { TEXT("/"),
347 LANGID_DEFAULT, 0 },
348 { TEXT("2:/"),
349 LANGID_DEFAULT, 0 },
350 { TEXT("\\"),
351 LANGID_DEFAULT, 0 },
352 { TEXT("\\My Documents\\"),
353 LANGID_DEFAULT, 0 },
354 { TEXT("\\Storage Card\\"),
355 LANGID_DEFAULT, PATH_SAVE },
356 { TEXT("\\Storage Card1\\"),
357 LANGID_DEFAULT, PATH_SAVE },
358 { TEXT("\\Storage Card2\\"),
359 LANGID_DEFAULT, PATH_SAVE },
360 #ifdef UNDER_CE
361 { unicode_memory_card,
362 MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), PATH_SAVE },
363 { unicode_memory_card1,
364 MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), PATH_SAVE },
365 { unicode_memory_card2,
366 MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), PATH_SAVE },
367 #endif
369 int path_list_items = ARRAYSIZEOF(path_list);
371 #ifdef ADDITIONAL_KERNELS
372 TCHAR* kernel_list[] = {
375 int kernel_list_items = ARRAYSIZEOF(kernel_list);
376 #endif
378 /*-----------------------------------------------------------------------------
380 function prototypes
382 -----------------------------------------------------------------------------*/
383 BOOL CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);
384 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
385 void SetBootInfo(struct bootinfo *bi, struct fb_setting *fbs);
386 void wstrcpy(TCHAR* dst, TCHAR* src);
387 int reverse_fb_type(int type);
389 /*-----------------------------------------------------------------------------
391 function definitions
393 -----------------------------------------------------------------------------*/
394 void wstrcpy(TCHAR* dst, TCHAR* src)
396 while (*src) {
397 *dst++ = *src++;
399 *dst = *src;
402 int reverse_fb_type(int type)
404 int i;
405 struct {
406 int type0, type1;
407 } types[] = {
408 { BIFB_D2_M2L_3, BIFB_D2_M2L_0 },
409 { BIFB_D2_M2L_3x2, BIFB_D2_M2L_0x2 },
410 { BIFB_D4_M2L_F, BIFB_D4_M2L_0 },
411 { BIFB_D4_M2L_Fx2, BIFB_D4_M2L_0x2 },
412 { BIFB_D8_FF, BIFB_D8_00 },
413 { BIFB_D16_FFFF, BIFB_D16_0000, },
416 for (i = 0; i < ARRAYSIZEOF(types); i++) {
417 if (types[i].type0 == type) {
418 return (types[i].type1);
420 if (types[i].type1 == type) {
421 return (types[i].type0);
424 debug_printf(TEXT("reverse_fb_type(): unknown type %d\n"), type);
425 return (type);
428 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
429 LPTSTR lpCmdLine, int nCmdShow )
431 MSG msg;
432 WNDCLASS wc;
433 HDC hdc;
434 int i, idx,width,height;
436 #if ( 200 <= _WIN32_WCE )
437 OSVERSIONINFO osverinfo;
439 osverinfo.dwOSVersionInfoSize = sizeof(osverinfo);
440 if (!GetVersionEx(&osverinfo)) {
441 msg_printf(MSG_ERROR,
442 TEXT("Error"),
443 TEXT("GetVersionEx() failed"));
445 osversion = osverinfo.dwMajorVersion * 100 + osverinfo.dwMinorVersion;
446 #else
447 osversion = 100;
448 #endif
451 * create log file for debugging
453 for (i = 0; i < path_list_items; i++) {
454 TCHAR filenamebuf[1024];
455 if (!(path_list[i].flags & PATH_SAVE)) {
456 continue;
458 wsprintf(filenamebuf, TEXT("%s%s"),
459 path_list[i].name, LOGNAME);
460 if (set_debug_log(filenamebuf) == 0) {
461 msg_printf(MSG_INFO,
462 TEXT("Debug"),
463 TEXT("%s was created"), LOGNAME);
464 break;
468 debug_printf(TEXT("%s"), version_string);
469 debug_printf(TEXT("Compiled for %d, Runtime OS version %d\n"),
470 _WIN32_WCE, osversion);
472 wc.style = (UINT)NULL;
473 wc.lpfnWndProc = (WNDPROC) WndProc;
474 wc.cbClsExtra = 0;
475 wc.cbWndExtra = 0;
476 wc.hInstance = hInstance;
477 wc.hIcon = NULL;
478 wc.hCursor = NULL;
479 wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
480 wc.lpszMenuName = NULL;
481 wc.lpszClassName = whoami;
483 RegisterClass(&wc);
485 InitCommonControls(); // Initialize common controls - command bar
486 hInst = hInstance; // Save handle to create command bar
488 hardware_test();
491 hBack = CreateWindowEx(0,
492 szAppName,
493 szTitle,
494 WS_VISIBLE,
495 CW_USEDEFAULT,
496 CW_USEDEFAULT,
497 CW_USEDEFAULT,
498 CW_USEDEFAULT,
499 NULL,
500 NULL,
501 hInstance,
502 NULL);
505 hdc = GetDC(0);
506 width = GetDeviceCaps(hdc,HORZRES);
507 height = GetDeviceCaps(hdc,VERTRES);
508 ReleaseDC(0,hdc);
510 if(width > height){
511 hDlgMain = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_MAIN_320X240),hBack,MainDlgProc);
513 else{
514 hDlgMain = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_MAIN_240X320),hBack,MainDlgProc);
517 SetFocus(GetDlgItem(hDlgMain, IDC_BOOT));
518 SetForegroundWindow(hDlgMain);
521 * load preferences
523 pref_init(&pref);
524 if (pref_load(path_list, path_list_items) == 0) {
525 stat_printf(TEXT("%s is loaded."), where_pref_load_from);
527 fb_settings[0].type = pref.fb_type;
528 fb_settings[0].width = pref.fb_width;
529 fb_settings[0].height = pref.fb_height;
530 fb_settings[0].linebytes = pref.fb_linebytes;
531 fb_settings[0].addr = pref.fb_addr;
532 fb_settings[0].platid_cpu = pref.platid_cpu;
533 fb_settings[0].platid_machine = pref.platid_machine;
534 } else {
535 TCHAR tmpbuf[PATHBUFLEN];
536 wsprintf(tmpbuf, TEXT("%s%S"), path_list[0].name, "netbsd");
537 stat_printf(TEXT("preferences not loaded."));
539 pref.setting_idx = 1;
540 pref.fb_type = fb_settings[0].type;
541 pref.fb_width = fb_settings[0].width;
542 pref.fb_height = fb_settings[0].height;
543 pref.fb_linebytes = fb_settings[0].linebytes;
544 pref.fb_addr = fb_settings[0].addr;
545 pref.platid_cpu = fb_settings[0].platid_cpu;
546 pref.platid_machine = fb_settings[0].platid_machine;
547 wstrcpy(pref.setting_name, TEXT("User defined"));
548 wstrcpy(pref.kernel_name, tmpbuf);
549 wstrcpy(pref.options, TEXT(""));
550 pref.check_last_chance = FALSE;
551 pref.load_debug_info = FALSE;
552 pref.serial_port = FALSE;
553 pref.reverse_video = FALSE;
555 fb_settings[0].name = pref.setting_name;
558 * initialize kernel file name list.
560 for (i = 0; i < path_list_items; i++) {
561 if (path_list[i].langid == LANGID_DEFAULT ||
562 path_list[i].langid == GetSystemDefaultLangID()) {
563 TCHAR tmpbuf[1024];
564 wsprintf(tmpbuf, TEXT("%s%S"),
565 path_list[i].name, "netbsd");
566 SendDlgItemMessage(hDlgMain, IDC_KERNEL,
567 CB_ADDSTRING, 0, (LPARAM)tmpbuf);
570 #ifdef ADDITIONAL_KERNELS
571 for (i = 0; i < kernel_list_items; i++) {
572 SendDlgItemMessage(hDlgMain, IDC_KERNEL, CB_ADDSTRING, 0,
573 (LPARAM)kernel_list[i]);
575 #endif
577 SendDlgItemMessage(hDlgMain, IDC_KERNEL, CB_SETCURSEL, 0,
578 (LPARAM)NULL);
580 SetDlgItemText(hDlgMain, IDC_KERNEL, pref.kernel_name);
581 SetDlgItemText(hDlgMain, IDC_OPTIONS, pref.options);
584 * Frame Buffer setting names.
586 for (i = 0; i < ARRAYSIZEOF(fb_settings); i++) {
587 idx = SendDlgItemMessage(hDlgMain, IDC_FBSELECT, CB_ADDSTRING,
588 0, (LPARAM)fb_settings[i].name);
589 SendDlgItemMessage(hDlgMain, IDC_FBSELECT,
590 CB_SETITEMDATA, idx, (LPARAM)i);
591 if (i == 0) {
592 user_define_idx = idx;
595 SendDlgItemMessage(hDlgMain, IDC_FBSELECT, CB_SETCURSEL,
596 pref.setting_idx, (LPARAM)NULL);
598 if(pref.autoboot){
599 if(pref.boot_time > 0){/* 0 can't use */
600 booting = TRUE;
601 how_long_to_boot = pref.boot_time;
602 SetTimer(hDlgMain,IDD_TIMER,1000,NULL);
603 stat_printf(
604 TEXT("autoboot after %d second,tap or hit any key to interrupt"),
605 pref.boot_time);
609 * Map window and message loop
611 ShowWindow(hDlgMain, SW_SHOW);
612 UpdateWindow(hDlgMain);
615 while (GetMessage(&msg, NULL, 0, 0)) {
616 // if (osversion < 211 ||
617 if(booting){
618 if(msg.message == WM_KEYDOWN || msg.message == WM_LBUTTONDOWN){
619 booting = FALSE;
620 how_long_to_boot = -1;
621 KillTimer(hDlgMain,IDD_TIMER);
622 stat_printf(TEXT("interrupt"));
623 continue;
627 if(!IsDialogMessage(hDlgMain, &msg)) {
629 TranslateMessage(&msg);
630 DispatchMessage(&msg);
634 return(msg.wParam);
637 BOOL CALLBACK DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
639 switch (message) {
641 case WM_INITDIALOG:
642 return (1);
644 case WM_PALETTECHANGED:
645 palette_check(hWnd);
646 break;
648 case WM_COMMAND:
649 switch (LOWORD(wParam)) {
650 case IDCANCEL:
651 dlgStatus = IDCANCEL;
652 break;
654 break;
655 default:
656 return (0);
660 BOOL CALLBACK DlgProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
662 switch (message) {
663 case WM_INITDIALOG:
664 SetDlgItemText(hWnd, IDC_ABOUT_EDIT, version_string);
665 return (1);
667 case WM_PALETTECHANGED:
668 palette_check(hWnd);
669 break;
671 case WM_COMMAND:
673 switch (LOWORD(wParam)) {
674 case IDC_ABOUT_EDIT:
675 switch (HIWORD(wParam)) {
676 case EN_SETFOCUS:
677 //SendDlgItemMessage(hWnd, IDC_ABOUT_EDIT, EM_SETSEL, -1, 0);
678 SetFocus(GetDlgItem(hWnd, IDC_ABOUT_BITMAP));
679 break;
681 break;
683 case IDCANCEL:
684 EndDialog(hWnd, LOWORD(wParam));
685 return (1);
687 break;
688 default:
689 return (0);
695 BOOL CALLBACK PropDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
697 HWND hwnd;
698 TCHAR tempbuf[PATHBUFLEN];
699 static BOOL autop;
700 int i;
701 switch (message) {
702 case WM_INITDIALOG:
703 autop = pref.autoboot;
705 SendDlgItemMessage(hWnd, IDC_PAUSE, BM_SETCHECK,
706 pref.check_last_chance, 0);
707 SendDlgItemMessage(hWnd, IDC_DEBUG, BM_SETCHECK,
708 pref.load_debug_info, 0);
709 SendDlgItemMessage(hWnd, IDC_COMM, BM_SETCHECK,
710 pref.serial_port, 0);
711 SendDlgItemMessage(hWnd, IDC_REVERSEVIDEO, BM_SETCHECK,
712 pref.reverse_video, 0);
713 SendDlgItemMessage(hWnd,IDC_AUTOBOOT,BM_SETCHECK,pref.autoboot,0);
715 for (i = 0; i < ARRAYSIZEOF(boot_times); i++) {
716 wsprintf(tempbuf, TEXT("%d"), boot_times[i]);
717 SendDlgItemMessage(hWnd, IDC_BOOT_TIME, CB_ADDSTRING,
718 0, (LPARAM)tempbuf);
721 if(pref.boot_time){
722 wsprintf(tempbuf,TEXT("%d"),pref.boot_time);
723 SetDlgItemText(hWnd,IDC_BOOT_TIME,tempbuf);
725 else{
726 wsprintf(tempbuf, TEXT("%d"), boot_times[0]);
727 SendDlgItemMessage(hWnd, IDC_BOOT_TIME, CB_ADDSTRING,
728 0, (LPARAM)tempbuf);
732 hwnd = GetDlgItem(hWnd,IDC_BOOT_TIME);
733 EnableWindow(hwnd,pref.autoboot);
735 return (1);
737 case WM_PALETTECHANGED:
738 palette_check(hWnd);
739 break;
741 case WM_COMMAND:
742 switch (LOWORD(wParam)) {
743 case IDC_AUTOBOOT:
744 autop = !autop;
745 SendDlgItemMessage(hWnd,IDC_AUTOBOOT,BM_SETCHECK,
746 autop,0);
748 hwnd = GetDlgItem(hWnd,IDC_BOOT_TIME);
749 EnableWindow(hwnd,autop);
751 break;
752 case IDPROPOK:
753 if (SendDlgItemMessage(hWnd, IDC_PAUSE,
754 BM_GETCHECK, 0, 0) ==
755 BST_CHECKED) {
756 pref.check_last_chance = TRUE;
757 } else {
758 pref.check_last_chance = FALSE;
761 if (SendDlgItemMessage(hWnd, IDC_DEBUG,
762 BM_GETCHECK, 0, 0) ==
763 BST_CHECKED) {
764 pref.load_debug_info = TRUE;
765 } else {
766 pref.load_debug_info = FALSE;
769 if (SendDlgItemMessage(hWnd, IDC_COMM,
770 BM_GETCHECK, 0, 0) ==
771 BST_CHECKED) {
772 pref.serial_port = TRUE;
773 } else {
774 pref.serial_port = FALSE;
777 if (SendDlgItemMessage(hWnd, IDC_REVERSEVIDEO,
778 BM_GETCHECK, 0, 0) ==
779 BST_CHECKED) {
780 pref.reverse_video = TRUE;
781 } else {
782 pref.reverse_video = FALSE;
785 if (SendDlgItemMessage(hWnd, IDC_AUTOBOOT,
786 BM_GETCHECK, 0, 0) ==
787 BST_CHECKED) {
788 pref.autoboot = TRUE;
789 } else {
790 pref.autoboot = FALSE;
792 GetDlgItemText(hWnd,IDC_BOOT_TIME,tempbuf,PATHBUFLEN);
793 pref.boot_time = _wtoi(tempbuf);
795 EndDialog(hWnd, 0);
796 return (1);
797 case IDCANCEL:
798 EndDialog(hWnd,0);
799 return(1);
801 break;
802 default:
803 return (0);
807 void
808 SetBootInfo(struct bootinfo *bi, struct fb_setting *fbs)
810 TIME_ZONE_INFORMATION tz;
812 GetTimeZoneInformation(&tz);
813 memset(bi, 0, sizeof(struct bootinfo));
814 bi->length = sizeof(struct bootinfo);
815 bi->reserved = 0;
816 bi->magic = BOOTINFO_MAGIC;
817 bi->fb_addr = (unsigned char*)(fbs->addr + 0xA0000000);
818 bi->fb_type = fbs->type;
819 bi->fb_line_bytes = fbs->linebytes;
820 bi->fb_width = fbs->width;
821 bi->fb_height = fbs->height;
822 bi->platid_cpu = fbs->platid_cpu;
823 bi->platid_machine = fbs->platid_machine;
824 bi->timezone = tz.Bias;
826 debug_printf(TEXT("fb setting: %s fb_type=%d 0x%X %dx%d %d\n"),
827 fbs->name,
828 bi->fb_type, bi->fb_addr,
829 bi->fb_width, bi->fb_height, bi->fb_line_bytes);
830 debug_printf(TEXT("timezone: %02ld:00\n"), (bi->timezone / 60));
834 void
835 UpdateFbDlg(HWND hWnd, struct fb_setting *fbs, int direction)
837 int i;
838 TCHAR tmpbuf[PATHBUFLEN];
839 int type, width, height, linebytes;
840 long addr;
842 switch (direction) {
843 case UPDATE_DLGBOX:
844 SetDlgItemText(hWnd, IDC_FB_NAME, fbs->name);
846 for (i = 0; i < ARRAYSIZEOF(fb_types); i++) {
847 if (fb_types[i].type == fbs->type) break;
849 if (ARRAYSIZEOF(fb_types) <= i) {
850 MessageBox(NULL, TEXT("Unknown FrameBuffer type."),
851 szAppName, MB_OK);
852 return;
854 debug_printf(TEXT("UpdateFbDlg(%s)\n"), fbs->name);
855 i = SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_FINDSTRINGEXACT,
856 0, (LPARAM)fb_types[i].name);
857 SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_SETCURSEL, i, 0);
859 wsprintf(tmpbuf, TEXT("%X"), fbs->addr);
860 SetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf);
861 wsprintf(tmpbuf, TEXT("%d"), fbs->width);
862 SetDlgItemText(hWnd, IDC_FB_WIDTH, tmpbuf);
863 wsprintf(tmpbuf, TEXT("%d"), fbs->height);
864 SetDlgItemText(hWnd, IDC_FB_HEIGHT, tmpbuf);
865 wsprintf(tmpbuf, TEXT("%d"), fbs->linebytes);
866 SetDlgItemText(hWnd, IDC_FB_LINEBYTES, tmpbuf);
867 wsprintf(tmpbuf, TEXT("%08X"), fbs->platid_cpu);
868 SetDlgItemText(hWnd, IDC_FB_CPU, tmpbuf);
869 wsprintf(tmpbuf, TEXT("%08X"), fbs->platid_machine);
870 SetDlgItemText(hWnd, IDC_FB_MACHINE, tmpbuf);
871 break;
872 case UPDATE_DATA:
873 GetDlgItemText(hWnd, IDC_FB_NAME, fbs->name, PATHBUFLEN);
874 type = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
875 CB_GETCURSEL, 0, 0);
876 type = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
877 CB_GETITEMDATA, type, 0);
878 GetDlgItemText(hWnd, IDC_FB_WIDTH, tmpbuf, sizeof(tmpbuf));
879 width = _tcstol(tmpbuf, NULL, 10);
880 GetDlgItemText(hWnd, IDC_FB_HEIGHT, tmpbuf, sizeof(tmpbuf));
881 height = _tcstol(tmpbuf, NULL, 10);
882 GetDlgItemText(hWnd, IDC_FB_LINEBYTES, tmpbuf, sizeof(tmpbuf));
883 linebytes = _tcstol(tmpbuf, NULL, 10);
884 GetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf, sizeof(tmpbuf));
885 addr = _tcstoul(tmpbuf, NULL, 16);
886 GetDlgItemText(hWnd, IDC_FB_CPU, tmpbuf, sizeof(tmpbuf));
887 fbs->platid_cpu = _tcstoul(tmpbuf, NULL, 16);
888 GetDlgItemText(hWnd, IDC_FB_MACHINE, tmpbuf, sizeof(tmpbuf));
889 fbs->platid_machine = _tcstoul(tmpbuf, NULL, 16);
890 fbs->type = type;
891 fbs->addr = addr;
892 fbs->width = width;
893 fbs->height = height;
894 fbs->linebytes = linebytes;
896 debug_printf(TEXT("type=%d %dx%d %d bytes/line %08x %08x\n"),
897 type, width, height, linebytes,
898 fbs->platid_cpu,
899 fbs->platid_machine);
900 break;
901 default:
902 debug_printf(TEXT("UpdateFbDlg(): internal error!\n"));
903 break;
907 BOOL CALLBACK FbDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
909 int idx, i;
910 TCHAR tmpbuf[100];
912 switch (message) {
913 case WM_INITDIALOG:
915 UDACCEL uda;
916 for (i = 0; i < ARRAYSIZEOF(fb_settings); i++) {
917 idx = SendDlgItemMessage(hWnd, IDC_FB_NAME,
918 CB_ADDSTRING, 0,
919 (LPARAM)fb_settings[i].name);
920 SendDlgItemMessage(hWnd, IDC_FB_NAME,
921 CB_SETITEMDATA, idx, (LPARAM)i);
923 for (i = 0; i < ARRAYSIZEOF(fb_size); i++) {
924 wsprintf(tmpbuf, TEXT("%d"), fb_size[i]);
925 SendDlgItemMessage(hWnd, IDC_FB_WIDTH, CB_ADDSTRING,
926 0, (LPARAM)tmpbuf);
927 SendDlgItemMessage(hWnd, IDC_FB_HEIGHT, CB_ADDSTRING,
928 0, (LPARAM)tmpbuf);
930 for (i = 0; i < ARRAYSIZEOF(fb_bpl); i++) {
931 wsprintf(tmpbuf, TEXT("%d"), fb_bpl[i]);
932 SendDlgItemMessage(hWnd, IDC_FB_LINEBYTES,
933 CB_ADDSTRING, 0,
934 (LPARAM)tmpbuf);
936 for (i = 0; i < ARRAYSIZEOF(fb_types); i++) {
937 idx = SendDlgItemMessage(hWnd, IDC_FB_TYPE,
938 CB_ADDSTRING, 0,
939 (LPARAM)fb_types[i].name);
940 SendDlgItemMessage(hWnd, IDC_FB_TYPE, CB_SETITEMDATA,
941 idx, (LPARAM)fb_types[i].type);
943 UpdateFbDlg(hWnd, &fb_settings[0], UPDATE_DLGBOX);
945 uda.nSec = 1;
946 uda.nInc = 0x100;
948 SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN, UDM_SETACCEL,
949 0, (LPARAM)&uda);
952 SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN, UDM_SETRANGE,
953 0, MAKELPARAM(UD_MAXVAL, UD_MINVAL));
956 return (1);
958 case WM_PALETTECHANGED:
959 palette_check(hWnd);
960 break;
962 case WM_VSCROLL:
963 if ((HWND)lParam == GetDlgItem(hWnd, IDC_FB_ADDRSPIN)) {
964 long addr;
965 switch (LOWORD(wParam)) {
966 case SB_THUMBPOSITION:
967 case SB_THUMBTRACK:
968 GetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf, 100);
969 addr = _tcstoul(tmpbuf, NULL, 16);
970 if (50 < HIWORD(wParam)) {
971 addr -= 0x400;
972 } else {
973 addr += 0x400;
975 SendDlgItemMessage(hWnd, IDC_FB_ADDRSPIN,
976 UDM_SETPOS, 0,
977 MAKELPARAM(50, 0));
978 wsprintf(tmpbuf, TEXT("%X"), addr);
979 SetDlgItemText(hWnd, IDC_FB_ADDR, tmpbuf);
980 return (1);
983 break;
985 case WM_COMMAND:
986 switch (LOWORD(wParam)) {
987 case IDC_FB_NAME:
988 switch (HIWORD(wParam)) {
989 case CBN_SELCHANGE:
990 idx = SendDlgItemMessage(hWnd, IDC_FB_NAME,
991 CB_GETCURSEL, 0, 0);
992 i = SendDlgItemMessage(hWnd, IDC_FB_NAME,
993 CB_GETITEMDATA, idx, 0);
994 if (0 <= i && i < ARRAYSIZEOF(fb_settings)) {
995 fb_settings[0] = fb_settings[i];
996 UpdateFbDlg(hWnd, &fb_settings[0],
997 UPDATE_DLGBOX);
999 return (1);
1001 break;
1002 case IDOK:
1003 UpdateFbDlg(hWnd, &fb_settings[0], UPDATE_DATA);
1005 EndDialog(hWnd, IDOK);
1006 return (1);
1008 case IDCANCEL:
1009 EndDialog(hWnd, IDCANCEL);
1010 return (1);
1012 break;
1014 return (0);
1018 BOOL SerialPort(BOOL on)
1020 static HANDLE hPort = INVALID_HANDLE_VALUE;
1021 BOOL res = (hPort != INVALID_HANDLE_VALUE);
1023 if (on != res) {
1024 if (on) {
1025 hPort = CreateFile(TEXT("COM1:"),
1026 GENERIC_READ | GENERIC_WRITE,
1027 0, NULL, OPEN_EXISTING,
1029 NULL);
1030 debug_printf(TEXT("serial port ON\n"));
1031 if ( hPort == INVALID_HANDLE_VALUE ) {
1032 debug_printf(TEXT("open failed\n"));
1033 } else {
1034 #if 0
1035 DWORD Len;
1036 BYTE x = 'X';
1037 WriteFile (hPort, &x, 1, &Len, 0);
1038 WriteFile (hPort, &x, 1, &Len, 0);
1039 WriteFile (hPort, &x, 1, &Len, 0);
1040 WriteFile (hPort, &x, 1, &Len, 0);
1041 #endif
1043 } else {
1044 debug_printf(TEXT("serial port OFF\n"));
1045 CloseHandle(hPort);
1046 hPort = INVALID_HANDLE_VALUE;
1050 return (res);
1054 BOOL CheckCancel(int progress)
1056 MSG msg;
1058 if (0 <= progress) {
1059 SendDlgItemMessage(hDlgLoad, IDC_PROGRESS,
1060 PBM_SETPOS, (WPARAM)progress, (LPARAM)NULL);
1061 } else {
1062 if (pref.check_last_chance) {
1063 if (msg_printf(MB_YESNO | MB_ICONHAND,
1064 TEXT("Last chance..."),
1065 TEXT("Push OK to boot.")) != IDYES) {
1066 dlgStatus = IDCANCEL;
1069 palette_set(hDlgLoad);
1070 if (palette_succeeded == -1) {
1071 msg_printf(MSG_ERROR,
1072 TEXT("Warning"),
1073 TEXT("Sorry, palette failed"));
1078 * Put WM_TIMER in my message queue.
1079 * (WM_TIMER has lowest priority.)
1081 SetTimer(hDlgLoad, 1, 1, NULL);
1084 * I tried PeekMessage() but it does not work.
1086 while (GetMessage(&msg, NULL, 0, 0)) {
1087 if (msg.hwnd == hDlgLoad && msg.message == WM_TIMER) {
1088 break;
1090 TranslateMessage(&msg);
1091 DispatchMessage(&msg);
1094 return (dlgStatus != 0);
1097 BOOL BootKernel(int directboot)
1099 int argc;
1100 int i;
1101 TCHAR wkernel_name[PATHBUFLEN];
1102 TCHAR woptions[PATHBUFLEN];
1104 char options[PATHBUFLEN*2], kernel_name[PATHBUFLEN*2];
1106 platid_t platid;
1108 char *p, *argv[32];
1109 struct bootinfo bi;
1111 if (GetDlgItemText(hDlgMain, IDC_KERNEL, wkernel_name,
1112 sizeof(wkernel_name)) == 0) {
1113 MessageBox (NULL, TEXT("Kernel name required"),
1114 szAppName, MB_OK);
1115 return FALSE;
1117 GetDlgItemText(hDlgMain, IDC_OPTIONS,
1118 woptions, sizeof(woptions));
1119 if (wcstombs(options, woptions, sizeof(options)) < 0 ||
1120 wcstombs(kernel_name, wkernel_name,
1121 sizeof(kernel_name)) < 0) {
1122 MessageBox (NULL, TEXT("invalid character"),
1123 szAppName, MB_OK);
1124 return FALSE;
1127 argc = 0;
1128 argv[argc++] = kernel_name;
1129 p = options;
1130 while (*p) {
1131 while (*p == ' ' || *p == '\t') {
1132 p++;
1134 if (*p == '\0')
1135 return FALSE;
1136 if (ARRAYSIZEOF(argv) <= argc) {
1137 MessageBox (NULL,
1138 TEXT("too many options"),
1139 szAppName, MB_OK);
1140 argc++;
1141 break;
1142 } else {
1143 argv[argc++] = p;
1145 while (*p != ' ' && *p != '\t' && *p != '\0') {
1146 p++;
1148 if (*p == '\0') {
1149 break;
1150 } else {
1151 *p++ = '\0';
1154 if (ARRAYSIZEOF(argv) < argc) {
1155 return FALSE;
1159 EnableWindow(hDlgMain, FALSE);
1161 if (directboot || (MessageBox (hDlgMain,
1162 TEXT("Data in memory will be lost.\nAre you sure?"),
1163 szAppName,
1164 MB_YESNO | MB_DEFBUTTON2 | MB_ICONHAND) == IDYES)) {
1165 booting = FALSE;
1166 dlgStatus = 0;
1167 hDlgLoad =
1168 CreateDialog(hInst,
1169 MAKEINTRESOURCE(IDD_LOAD),
1170 hDlgMain, DlgProc);
1171 ShowWindow(hDlgLoad, SW_SHOWNORMAL);
1172 BringWindowToTop(hDlgLoad);
1175 * save settings.
1177 pref.fb_type = fb_settings[0].type;
1178 pref.fb_width = fb_settings[0].width;
1179 pref.fb_height = fb_settings[0].height;
1180 pref.fb_linebytes = fb_settings[0].linebytes;
1181 pref.fb_addr = fb_settings[0].addr;
1182 pref.platid_cpu = fb_settings[0].platid_cpu;
1183 pref.platid_machine = fb_settings[0].platid_machine;
1184 wstrcpy(pref.kernel_name, wkernel_name);
1185 wstrcpy(pref.options, woptions);
1187 pref_save(path_list, path_list_items);
1189 SetBootInfo(&bi, &fb_settings[pref.setting_idx]);
1190 debug_printf(TEXT("Args: "));
1191 for (i = 0; i < argc; i++) {
1192 debug_printf(TEXT("'%S' "), argv[i]);
1194 debug_printf(TEXT("\n"));
1195 debug_printf(TEXT("Bootinfo: fb_type=%d 0x%X %dx%d %d\n"),
1196 bi.fb_type, bi.fb_addr,
1197 bi.fb_width, bi.fb_height,
1198 bi.fb_line_bytes);
1200 if (pref.serial_port) {
1201 SerialPort(TRUE);
1203 if (pref.reverse_video) {
1204 bi.fb_type = reverse_fb_type(bi.fb_type);
1207 * Set system information
1209 platid.dw.dw0 = bi.platid_cpu;
1210 platid.dw.dw1 = bi.platid_machine;
1211 if (set_system_info(&platid)) {
1213 * boot !
1215 pbsdboot(wkernel_name, argc, argv, &bi);
1218 * Not return.
1221 if (pref.serial_port) {
1222 SerialPort(FALSE);
1225 DestroyWindow(hDlgLoad);
1227 EnableWindow(hDlgMain, TRUE);
1229 return FALSE;
1232 LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
1233 WPARAM wParam, LPARAM lParam ){
1234 switch (message) {
1235 case WM_CREATE:
1236 palette_init(hWnd);
1237 break;
1239 case WM_PALETTECHANGED:
1240 palette_check(hWnd);
1241 break;
1243 case WM_QUERYNEWPALETTE:
1244 return(TRUE);
1246 case WM_CLOSE:
1247 sndPlaySound(TEXT("Close"), SND_NODEFAULT | SND_ASYNC);
1249 DestroyWindow(hWnd);
1250 break;
1252 case WM_DESTROY:
1253 PostQuitMessage(0);
1254 break;
1256 default:
1257 return (DefWindowProc(hWnd, message, wParam, lParam));
1260 return 0;
1263 BOOL CALLBACK MainDlgProc(HWND hWnd, UINT message,
1264 WPARAM wParam, LPARAM lParam )
1266 int i, idx;
1268 switch (message) {
1269 case WM_CREATE:
1270 sndPlaySound(TEXT("OpenProg"), SND_NODEFAULT | SND_ASYNC);
1271 hWndCB = CommandBar_Create(hInst, hWnd, 1);
1272 CommandBar_AddAdornments(hWndCB, STD_HELP, (DWORD)NULL);
1273 break;
1274 case WM_PAINT:
1276 HDC hdc;
1277 PAINTSTRUCT ps;
1279 hdc = BeginPaint(hWnd, &ps);
1280 EndPaint(hWnd, &ps);
1282 break;
1284 case WM_PALETTECHANGED:
1285 palette_check(hWnd);
1286 break;
1288 case WM_HELP:
1290 MessageBox (NULL, TEXT("HELP NOT AVAILABLE"),
1291 szAppName, MB_OK);
1293 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, DlgProc2);
1294 break;
1297 case WM_TIMER:
1298 if(!booting){/* ignore! */
1299 KillTimer(hWnd,IDD_TIMER);
1300 stat_printf(TEXT("interrupt2"));
1301 return (1);
1303 if(how_long_to_boot > 0){
1304 how_long_to_boot--;
1305 stat_printf(
1306 TEXT("autoboot after %d second,tap or hit any key to interrupt"),
1307 how_long_to_boot);
1309 else{
1310 KillTimer(hWnd,IDD_TIMER);
1311 BootKernel(1);
1313 break;
1315 case WM_COMMAND:
1316 switch (LOWORD(wParam)) {
1317 case IDC_BOOT:
1318 BootKernel(0);
1319 break;
1320 case IDC_FBSETTING:
1321 if (DialogBox(hInst, MAKEINTRESOURCE(IDD_FB),
1322 hDlgMain, FbDlgProc) == IDOK) {
1323 /* User defined */
1324 pref.setting_idx = 0;
1325 SendDlgItemMessage(hDlgMain, IDC_FBSELECT,
1326 CB_DELETESTRING,
1327 (WPARAM)user_define_idx, 0);
1328 SendDlgItemMessage(hDlgMain, IDC_FBSELECT,
1329 CB_INSERTSTRING,
1330 (WPARAM)user_define_idx,
1331 (LPARAM)fb_settings[0].name);
1332 SendDlgItemMessage(hWnd, IDC_FBSELECT,
1333 CB_SETCURSEL, 0, 0);
1335 break;
1336 case IDC_PROPERTY:
1337 DialogBox(hInst, MAKEINTRESOURCE(IDD_PROP), hWnd, PropDlgProc);
1338 break;
1339 case IDC_FBSELECT:
1340 switch (HIWORD(wParam)) {
1341 case CBN_SELCHANGE:
1342 idx = SendDlgItemMessage(hWnd, IDC_FBSELECT,
1343 CB_GETCURSEL, 0, 0);
1344 i = SendDlgItemMessage(hWnd, IDC_FBSELECT,
1345 CB_GETITEMDATA, idx, 0);
1346 if (0 <= i && i < ARRAYSIZEOF(fb_settings)) {
1347 debug_printf(TEXT("fb_setting=%d\n"), i);
1348 pref.setting_idx = i;
1350 break;
1352 break;
1354 break;
1356 case WM_HIBERNATE:
1357 MessageBox(NULL, TEXT("MEMORY IS LOW"), szAppName, MB_OK);
1358 //Additional code to handle a low memory situation
1360 case WM_CLOSE:
1361 sndPlaySound(TEXT("Close"), SND_NODEFAULT | SND_ASYNC);
1363 DestroyWindow(hWnd);
1364 break;
1366 case WM_DESTROY:
1367 PostQuitMessage(0);
1368 break;
1372 return (0);