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