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