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