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