Group commit for recovery after disk crash.
[wine/multimedia.git] / loader / main.c
blob278c0e989a35c499f36ee9caaba014f6f8641c78
1 /*
2 * Main initialization code
3 */
5 #include <stdlib.h>
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <errno.h>
12 #include "windows.h"
13 #include "bitmap.h"
14 #include "comm.h"
15 #include "win.h"
16 #include "main.h"
17 #include "menu.h"
18 #include "message.h"
19 #include "multimedia.h"
20 #include "dialog.h"
21 #include "drive.h"
22 #include "queue.h"
23 #include "sysmetrics.h"
24 #include "file.h"
25 #include "gdi.h"
26 #include "heap.h"
27 #include "keyboard.h"
28 #include "mouse.h"
29 #include "input.h"
30 #include "miscemu.h"
31 #include "options.h"
32 #include "process.h"
33 #include "spy.h"
34 #include "tweak.h"
35 #include "user.h"
36 #include "global.h"
37 #include "dce.h"
38 #include "shell.h"
39 #include "winproc.h"
40 #include "syslevel.h"
41 #include "thread.h"
42 #include "task.h"
43 #include "debug.h"
44 #include "psdrv.h"
45 #include "server.h"
46 #include "console.h"
48 int __winelib = 1; /* Winelib run-time flag */
50 /***********************************************************************
51 * Main initialisation routine
53 BOOL32 MAIN_MainInit(void)
55 /* Set server debug level */
56 /* To fool make_debug: TRACE(server) */
57 CLIENT_SetDebug( TRACE_ON(server) );
59 /* Initialize syslevel handling */
60 SYSLEVEL_Init();
62 /* Initialize signal handling */
63 if (!SIGNAL_Init()) return FALSE;
65 /* Load the configuration file */
66 if (!PROFILE_LoadWineIni()) return FALSE;
68 /* Initialize DOS memory */
69 if (!DOSMEM_Init(0)) return FALSE;
71 /* Initialise DOS drives */
72 if (!DRIVE_Init()) return FALSE;
74 /* Initialise DOS directories */
75 if (!DIR_Init()) return FALSE;
77 /* Initialize event handling */
78 if (!EVENT_Init()) return FALSE;
80 /* Initialize communications */
81 COMM_Init();
83 /* Initialize IO-port permissions */
84 IO_port_init();
86 /* registry initialisation */
87 SHELL_LoadRegistry();
89 /* Set up text-mode stuff */
90 CONSOLE_ResizeScreen(80, 25);
92 /* Read DOS config.sys */
93 if (!DOSCONF_ReadConfig()) return FALSE;
95 return TRUE;
98 /***********************************************************************
99 * KERNEL initialisation routine
101 BOOL32 WINAPI MAIN_KernelInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
103 static BOOL32 initDone = FALSE;
105 HMODULE16 hModule;
107 if ( initDone ) return TRUE;
108 initDone = TRUE;
110 /* Initialize special KERNEL entry points */
111 hModule = GetModuleHandle16( "KERNEL" );
112 if ( hModule )
114 WORD cs, ds;
116 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
117 NE_SetEntryPoint( hModule, 178, GetWinFlags() );
119 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
120 GET_CS(cs); GET_DS(ds);
121 NE_SetEntryPoint( hModule, 454, cs );
122 NE_SetEntryPoint( hModule, 455, ds );
124 /* Initialize KERNEL.THHOOK */
125 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
126 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
128 /* Initialize the real-mode selector entry points */
129 #define SET_ENTRY_POINT( num, addr ) \
130 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
131 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
132 FALSE, FALSE, FALSE, NULL ))
134 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
135 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
136 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
137 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
138 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
139 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
140 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
141 SET_ENTRY_POINT( 173, 0xf0000 ); /* KERNEL.173: __ROMBIOS */
142 SET_ENTRY_POINT( 194, 0xf0000 ); /* KERNEL.194: __F000H */
143 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosSeg ); /* KERNEL.193: __0040H */
144 #undef SET_ENTRY_POINT
147 return TRUE;
150 /***********************************************************************
151 * GDI initialisation routine
153 BOOL32 WINAPI MAIN_GdiInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
155 NE_MODULE *pModule;
157 if ( GDI_HeapSel ) return TRUE;
159 /* Create GDI heap */
160 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
161 if ( pModule )
163 GDI_HeapSel = GlobalHandleToSel( (NE_SEG_TABLE( pModule ) +
164 pModule->dgroup - 1)->hSeg );
166 else
168 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
169 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
172 if (!TWEAK_Init()) return FALSE;
174 /* GDI initialisation */
175 if(!GDI_Init()) return FALSE;
178 /* PSDRV initialization */
179 if(!PSDRV_Init()) return FALSE;
181 return TRUE;
184 /***********************************************************************
185 * USER initialisation routine
187 BOOL32 WINAPI MAIN_UserInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
189 NE_MODULE *pModule;
190 int queueSize;
192 if ( USER_HeapSel ) return TRUE;
194 /* Create USER heap */
195 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
196 if ( pModule )
198 USER_HeapSel = GlobalHandleToSel( (NE_SEG_TABLE( pModule ) +
199 pModule->dgroup - 1)->hSeg );
201 else
203 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
204 LocalInit( USER_HeapSel, 0, 0xffff );
207 /* Global atom table initialisation */
208 if (!ATOM_Init( USER_HeapSel )) return FALSE;
210 /* Initialize system colors and metrics*/
211 SYSMETRICS_Init();
212 SYSCOLOR_Init();
214 /* Create the DCEs */
215 DCE_Init();
217 /* Initialize window procedures */
218 if (!WINPROC_Init()) return FALSE;
220 /* Initialize built-in window classes */
221 if (!WIDGETS_Init()) return FALSE;
223 /* Initialize dialog manager */
224 if (!DIALOG_Init()) return FALSE;
226 /* Initialize menus */
227 if (!MENU_Init()) return FALSE;
229 /* Initialize multimedia */
230 if (!MULTIMEDIA_Init()) return FALSE;
232 /* Initialize message spying */
233 if (!SPY_Init()) return FALSE;
235 /* Check wine.conf for old/bad entries */
236 if (!TWEAK_CheckConfiguration()) return FALSE;
238 /* Create system message queue */
239 queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
240 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
242 /* Set double click time */
243 SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
245 /* Create task message queue for the initial task */
246 queueSize = GetProfileInt32A( "windows", "DefaultQueueSize", 8 );
247 if (!SetMessageQueue32( queueSize )) return FALSE;
249 /* Create desktop window */
250 if (!WIN_CreateDesktopWindow()) return FALSE;
252 /* Install default USER Signal Handler */
253 SetTaskSignalProc( 0, (FARPROC16)USER_SignalProc );
255 /* Initialize keyboard driver */
256 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
258 /* Initialize mouse driver */
259 MOUSE_Enable( mouse_event );
261 return TRUE;
265 /***********************************************************************
266 * Winelib initialisation routine
268 HINSTANCE32 MAIN_WinelibInit( int *argc, char *argv[] )
270 WINE_MODREF *wm;
271 NE_MODULE *pModule;
272 OFSTRUCT ofs;
273 HMODULE16 hModule;
274 HINSTANCE16 hInstance;
276 /* Create the initial process */
277 if (!PROCESS_Init()) return 0;
279 /* Parse command line arguments */
280 MAIN_WineInit( argc, argv );
282 /* Main initialization */
283 if (!MAIN_MainInit()) return 0;
285 /* Initialize KERNEL */
286 if (!MAIN_KernelInit(0, 0, NULL)) return 0;
288 /* Create and switch to initial task */
289 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0], PROCESS_Current() )))
290 return 0;
291 PROCESS_Current()->exe_modref = wm;
293 strcpy( ofs.szPathName, wm->modname );
294 if ((hModule = MODULE_CreateDummyModule( &ofs, NULL )) < 32) return 0;
295 pModule = (NE_MODULE *)GlobalLock16( hModule );
296 pModule->flags = NE_FFLAGS_WIN32;
297 pModule->module32 = wm->module;
299 hInstance = NE_CreateInstance( pModule, NULL, TRUE );
300 PROCESS_Current()->task = TASK_Create( THREAD_Current(), pModule, hInstance, 0, FALSE );
302 TASK_StartTask( PROCESS_Current()->task );
304 /* Initialize GDI and USER */
305 if (!MAIN_GdiInit(0, 0, NULL)) return 0;
306 if (!MAIN_UserInit(0, 0, NULL)) return 0;
308 return wm->module;