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