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