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