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