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