Added beginnings of server-side file handling.
[wine/multimedia.git] / loader / main.c
blob002f29d7bfa0d07a018c57725c092ce5e4f73e43
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"
47 int __winelib = 1; /* Winelib run-time flag */
49 /***********************************************************************
50 * Main initialisation routine
52 BOOL32 MAIN_MainInit(void)
54 /* Set server debug level */
55 /* To fool make_debug: TRACE(server) */
56 CLIENT_SetDebug( TRACE_ON(server) );
58 /* Initialize syslevel handling */
59 SYSLEVEL_Init();
61 /* Initialize signal handling */
62 if (!SIGNAL_Init()) return FALSE;
64 /* Load the configuration file */
65 if (!PROFILE_LoadWineIni()) return FALSE;
67 /* Initialize DOS memory */
68 if (!DOSMEM_Init(0)) return FALSE;
70 /* Initialise DOS drives */
71 if (!DRIVE_Init()) return FALSE;
73 /* Initialise DOS directories */
74 if (!DIR_Init()) return FALSE;
76 /* Initialize event handling */
77 if (!EVENT_Init()) return FALSE;
79 /* Initialize communications */
80 COMM_Init();
82 /* Initialize IO-port permissions */
83 IO_port_init();
85 /* registry initialisation */
86 SHELL_LoadRegistry();
88 return TRUE;
91 /***********************************************************************
92 * KERNEL initialisation routine
94 BOOL32 WINAPI MAIN_KernelInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
96 static BOOL32 initDone = FALSE;
98 HMODULE16 hModule;
100 if ( initDone ) return TRUE;
101 initDone = TRUE;
103 /* Initialize special KERNEL entry points */
104 hModule = GetModuleHandle16( "KERNEL" );
105 if ( hModule )
107 WORD cs, ds;
109 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
110 NE_SetEntryPoint( hModule, 178, GetWinFlags() );
112 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
113 GET_CS(cs); GET_DS(ds);
114 NE_SetEntryPoint( hModule, 454, cs );
115 NE_SetEntryPoint( hModule, 455, ds );
117 /* Initialize KERNEL.THHOOK */
118 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
119 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
121 /* Initialize the real-mode selector entry points */
122 #define SET_ENTRY_POINT( num, addr ) \
123 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
124 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
125 FALSE, FALSE, FALSE, NULL ))
127 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
128 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
129 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
130 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
131 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
132 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
133 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
134 SET_ENTRY_POINT( 173, 0xf0000 ); /* KERNEL.173: __ROMBIOS */
135 SET_ENTRY_POINT( 194, 0xf0000 ); /* KERNEL.194: __F000H */
136 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosSeg ); /* KERNEL.193: __0040H */
137 #undef SET_ENTRY_POINT
140 return TRUE;
143 /***********************************************************************
144 * GDI initialisation routine
146 BOOL32 WINAPI MAIN_GdiInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
148 NE_MODULE *pModule;
150 if ( GDI_HeapSel ) return TRUE;
152 /* Create GDI heap */
153 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
154 if ( pModule )
156 GDI_HeapSel = GlobalHandleToSel( (NE_SEG_TABLE( pModule ) +
157 pModule->dgroup - 1)->hSeg );
159 else
161 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
162 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
165 if (!TWEAK_Init()) return FALSE;
167 /* GDI initialisation */
168 if(!GDI_Init()) return FALSE;
171 /* PSDRV initialization */
172 if(!PSDRV_Init()) return FALSE;
174 return TRUE;
177 /***********************************************************************
178 * USER initialisation routine
180 BOOL32 WINAPI MAIN_UserInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
182 NE_MODULE *pModule;
183 int queueSize;
185 if ( USER_HeapSel ) return TRUE;
187 /* Create USER heap */
188 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
189 if ( pModule )
191 USER_HeapSel = GlobalHandleToSel( (NE_SEG_TABLE( pModule ) +
192 pModule->dgroup - 1)->hSeg );
194 else
196 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
197 LocalInit( USER_HeapSel, 0, 0xffff );
200 /* Global atom table initialisation */
201 if (!ATOM_Init( USER_HeapSel )) return FALSE;
203 /* Initialize system colors and metrics*/
204 SYSMETRICS_Init();
205 SYSCOLOR_Init();
207 /* Create the DCEs */
208 DCE_Init();
210 /* Initialize window procedures */
211 if (!WINPROC_Init()) return FALSE;
213 /* Initialize built-in window classes */
214 if (!WIDGETS_Init()) return FALSE;
216 /* Initialize dialog manager */
217 if (!DIALOG_Init()) return FALSE;
219 /* Initialize menus */
220 if (!MENU_Init()) return FALSE;
222 /* Initialize multimedia */
223 if (!MULTIMEDIA_Init()) return FALSE;
225 /* Initialize message spying */
226 if (!SPY_Init()) return FALSE;
228 /* Check wine.conf for old/bad entries */
229 if (!TWEAK_CheckConfiguration()) return FALSE;
231 /* Create system message queue */
232 queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
233 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
235 /* Set double click time */
236 SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
238 /* Create task message queue for the initial task */
239 queueSize = GetProfileInt32A( "windows", "DefaultQueueSize", 8 );
240 if (!SetMessageQueue32( queueSize )) return FALSE;
242 /* Create desktop window */
243 if (!WIN_CreateDesktopWindow()) return FALSE;
245 /* Install default USER Signal Handler */
246 SetTaskSignalProc( 0, (FARPROC16)USER_SignalProc );
248 /* Initialize keyboard driver */
249 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
251 /* Initialize mouse driver */
252 MOUSE_Enable( mouse_event );
254 return TRUE;
258 /***********************************************************************
259 * Winelib initialisation routine
261 HINSTANCE32 MAIN_WinelibInit( int *argc, char *argv[] )
263 WINE_MODREF *wm;
264 NE_MODULE *pModule;
265 OFSTRUCT ofs;
266 HMODULE16 hModule;
267 HINSTANCE16 hInstance;
269 /* Create the initial process */
270 if (!PROCESS_Init()) return 0;
272 /* Parse command line arguments */
273 MAIN_WineInit( argc, argv );
275 /* Main initialization */
276 if (!MAIN_MainInit()) return 0;
278 /* Initialize KERNEL */
279 if (!MAIN_KernelInit(0, 0, NULL)) return 0;
281 /* Create and switch to initial task */
282 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0], PROCESS_Current() )))
283 return 0;
284 PROCESS_Current()->exe_modref = wm;
286 strcpy( ofs.szPathName, wm->modname );
287 if ((hModule = MODULE_CreateDummyModule( &ofs )) < 32) return 0;
288 pModule = (NE_MODULE *)GlobalLock16( hModule );
289 pModule->flags = NE_FFLAGS_WIN32;
290 pModule->module32 = wm->module;
292 hInstance = NE_CreateInstance( pModule, NULL, TRUE );
293 PROCESS_Current()->task = TASK_Create( THREAD_Current(), pModule, hInstance, 0, FALSE );
295 TASK_StartTask( PROCESS_Current()->task );
297 /* Initialize GDI and USER */
298 if (!MAIN_GdiInit(0, 0, NULL)) return 0;
299 if (!MAIN_UserInit(0, 0, NULL)) return 0;
301 return wm->module;