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