Desktop window queue handling adapted.
[wine/multimedia.git] / loader / main.c
bloba2f64a83236a9c4e58c27be88f7c3fe58dae2d48
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 "console.h"
47 int __winelib = 1; /* Winelib run-time flag */
49 /***********************************************************************
50 * Main initialisation routine
52 BOOL32 MAIN_MainInit(void)
54 /* Initialize syslevel handling */
55 SYSLEVEL_Init();
57 /* Initialize signal handling */
58 if (!SIGNAL_Init()) return FALSE;
60 /* Load the configuration file */
61 if (!PROFILE_LoadWineIni()) return FALSE;
63 /* Initialize DOS memory */
64 if (!DOSMEM_Init(0)) return FALSE;
66 /* Initialise DOS drives */
67 if (!DRIVE_Init()) return FALSE;
69 /* Initialise DOS directories */
70 if (!DIR_Init()) return FALSE;
72 /* Initialize event handling */
73 if (!EVENT_Init()) return FALSE;
75 /* Initialize communications */
76 COMM_Init();
78 /* Initialize IO-port permissions */
79 IO_port_init();
81 /* registry initialisation */
82 SHELL_LoadRegistry();
84 /* Set up text-mode stuff */
85 CONSOLE_Init();
87 return TRUE;
90 /***********************************************************************
91 * KERNEL initialisation routine
93 BOOL32 WINAPI MAIN_KernelInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
95 static BOOL32 initDone = FALSE;
97 HMODULE16 hModule;
99 if ( initDone ) return TRUE;
100 initDone = TRUE;
102 /* Initialize special KERNEL entry points */
103 hModule = GetModuleHandle16( "KERNEL" );
104 if ( hModule )
106 WORD cs, ds;
108 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
109 NE_SetEntryPoint( hModule, 178, GetWinFlags() );
111 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
112 GET_CS(cs); GET_DS(ds);
113 NE_SetEntryPoint( hModule, 454, cs );
114 NE_SetEntryPoint( hModule, 455, ds );
116 /* Initialize KERNEL.THHOOK */
117 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
118 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
120 /* Initialize the real-mode selector entry points */
121 #define SET_ENTRY_POINT( num, addr ) \
122 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
123 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
124 FALSE, FALSE, FALSE, NULL ))
126 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
127 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
128 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
129 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
130 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
131 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
132 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
133 SET_ENTRY_POINT( 173, 0xf0000 ); /* KERNEL.173: __ROMBIOS */
134 SET_ENTRY_POINT( 194, 0xf0000 ); /* KERNEL.194: __F000H */
135 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosSeg ); /* KERNEL.193: __0040H */
136 #undef SET_ENTRY_POINT
139 return TRUE;
142 /***********************************************************************
143 * GDI initialisation routine
145 BOOL32 WINAPI MAIN_GdiInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
147 NE_MODULE *pModule;
149 if ( GDI_HeapSel ) return TRUE;
151 /* Create GDI heap */
152 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
153 if ( pModule )
155 GDI_HeapSel = GlobalHandleToSel( (NE_SEG_TABLE( pModule ) +
156 pModule->dgroup - 1)->hSeg );
158 else
160 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
161 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
164 if (!TWEAK_Init()) return FALSE;
166 /* GDI initialisation */
167 if(!GDI_Init()) return FALSE;
170 /* PSDRV initialization */
171 if(!PSDRV_Init()) return FALSE;
173 return TRUE;
176 /***********************************************************************
177 * USER initialisation routine
179 BOOL32 WINAPI MAIN_UserInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
181 NE_MODULE *pModule;
182 int queueSize;
184 if ( USER_HeapSel ) return TRUE;
186 /* Create USER heap */
187 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
188 if ( pModule )
190 USER_HeapSel = GlobalHandleToSel( (NE_SEG_TABLE( pModule ) +
191 pModule->dgroup - 1)->hSeg );
193 else
195 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
196 LocalInit( USER_HeapSel, 0, 0xffff );
199 /* Global atom table initialisation */
200 if (!ATOM_Init( USER_HeapSel )) return FALSE;
202 /* Initialize system colors and metrics*/
203 SYSMETRICS_Init();
204 SYSCOLOR_Init();
206 /* Create the DCEs */
207 DCE_Init();
209 /* Initialize window procedures */
210 if (!WINPROC_Init()) return FALSE;
212 /* Initialize built-in window classes */
213 if (!WIDGETS_Init()) return FALSE;
215 /* Initialize dialog manager */
216 if (!DIALOG_Init()) return FALSE;
218 /* Initialize menus */
219 if (!MENU_Init()) return FALSE;
221 /* Initialize multimedia */
222 if (!MULTIMEDIA_Init()) return FALSE;
224 /* Initialize message spying */
225 if (!SPY_Init()) return FALSE;
227 /* Check wine.conf for old/bad entries */
228 if (!TWEAK_CheckConfiguration()) return FALSE;
230 /* Create system message queue */
231 queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
232 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
234 /* Set double click time */
235 SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
237 /* Create task message queue for the initial task */
238 queueSize = GetProfileInt32A( "windows", "DefaultQueueSize", 8 );
239 if (!SetMessageQueue32( queueSize )) return FALSE;
241 /* Create desktop window */
242 if (!WIN_CreateDesktopWindow()) return FALSE;
244 /* Install default USER Signal Handler */
245 SetTaskSignalProc( 0, (FARPROC16)USER_SignalProc );
247 /* Initialize keyboard driver */
248 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
250 /* Initialize mouse driver */
251 MOUSE_Enable( mouse_event );
253 return TRUE;
257 /***********************************************************************
258 * Winelib initialisation routine
260 HINSTANCE32 MAIN_WinelibInit( int *argc, char *argv[] )
262 WINE_MODREF *wm;
263 NE_MODULE *pModule;
264 OFSTRUCT ofs;
265 HMODULE16 hModule;
266 HINSTANCE16 hInstance;
268 /* Create the initial process */
269 if (!PROCESS_Init()) return 0;
271 /* Parse command line arguments */
272 MAIN_WineInit( argc, argv );
274 /* Main initialization */
275 if (!MAIN_MainInit()) return 0;
277 /* Initialize KERNEL */
278 if (!MAIN_KernelInit(0, 0, NULL)) return 0;
280 /* Create and switch to initial task */
281 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0], PROCESS_Current() )))
282 return 0;
283 PROCESS_Current()->exe_modref = wm;
285 strcpy( ofs.szPathName, wm->modname );
286 if ((hModule = MODULE_CreateDummyModule( &ofs )) < 32) return 0;
287 pModule = (NE_MODULE *)GlobalLock16( hModule );
288 pModule->flags = NE_FFLAGS_WIN32;
289 pModule->module32 = wm->module;
291 hInstance = NE_CreateInstance( pModule, NULL, TRUE );
292 PROCESS_Current()->task = TASK_Create( THREAD_Current(), pModule, hInstance, 0, FALSE );
294 TASK_StartTask( PROCESS_Current()->task );
296 /* Initialize GDI and USER */
297 if (!MAIN_GdiInit(0, 0, NULL)) return 0;
298 if (!MAIN_UserInit(0, 0, NULL)) return 0;
300 return wm->module;