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