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