Add support for selection of console mode drivers to use using the
[wine/multimedia.git] / loader / main.c
blob4c2d6677e32477dc2720560d41613cead8948fc4
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"
46 int __winelib = 1; /* Winelib run-time flag */
48 /***********************************************************************
49 * Main initialisation routine
51 BOOL32 MAIN_MainInit(void)
53 /* Initialize syslevel handling */
54 SYSLEVEL_Init();
56 /* Initialize signal handling */
57 if (!SIGNAL_Init()) return FALSE;
59 /* Load the configuration file */
60 if (!PROFILE_LoadWineIni()) return FALSE;
62 /* Initialize DOS memory */
63 if (!DOSMEM_Init(0)) return FALSE;
65 /* Initialise DOS drives */
66 if (!DRIVE_Init()) return FALSE;
68 /* Initialise DOS directories */
69 if (!DIR_Init()) return FALSE;
71 /* Initialize event handling */
72 if (!EVENT_Init()) return FALSE;
74 /* Initialize communications */
75 COMM_Init();
77 /* Initialize IO-port permissions */
78 IO_port_init();
80 /* registry initialisation */
81 SHELL_LoadRegistry();
83 return TRUE;
86 /***********************************************************************
87 * KERNEL initialisation routine
89 BOOL32 WINAPI MAIN_KernelInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
91 static BOOL32 initDone = FALSE;
93 HMODULE16 hModule;
95 if ( initDone ) return TRUE;
96 initDone = TRUE;
98 /* Initialize special KERNEL entry points */
99 hModule = GetModuleHandle16( "KERNEL" );
100 if ( hModule )
102 WORD cs, ds;
104 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
105 NE_SetEntryPoint( hModule, 178, GetWinFlags() );
107 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
108 GET_CS(cs); GET_DS(ds);
109 NE_SetEntryPoint( hModule, 454, cs );
110 NE_SetEntryPoint( hModule, 455, ds );
112 /* Initialize KERNEL.THHOOK */
113 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
114 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
116 /* Initialize the real-mode selector entry points */
117 #define SET_ENTRY_POINT( num, addr ) \
118 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
119 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
120 FALSE, FALSE, FALSE, NULL ))
122 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
123 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
124 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
125 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
126 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
127 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
128 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
129 SET_ENTRY_POINT( 173, 0xf0000 ); /* KERNEL.173: __ROMBIOS */
130 SET_ENTRY_POINT( 194, 0xf0000 ); /* KERNEL.194: __F000H */
131 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosSeg ); /* KERNEL.193: __0040H */
132 #undef SET_ENTRY_POINT
135 return TRUE;
138 /***********************************************************************
139 * GDI initialisation routine
141 BOOL32 WINAPI MAIN_GdiInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
143 NE_MODULE *pModule;
145 if ( GDI_HeapSel ) return TRUE;
147 /* Create GDI heap */
148 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
149 if ( pModule )
151 GDI_HeapSel = GlobalHandleToSel( (NE_SEG_TABLE( pModule ) +
152 pModule->dgroup - 1)->hSeg );
154 else
156 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
157 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
160 if (!TWEAK_Init()) return FALSE;
162 /* GDI initialisation */
163 if(!GDI_Init()) return FALSE;
166 /* PSDRV initialization */
167 if(!PSDRV_Init()) return FALSE;
169 return TRUE;
172 /***********************************************************************
173 * USER initialisation routine
175 BOOL32 WINAPI MAIN_UserInit(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
177 NE_MODULE *pModule;
178 int queueSize;
180 if ( USER_HeapSel ) return TRUE;
182 /* Create USER heap */
183 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
184 if ( pModule )
186 USER_HeapSel = GlobalHandleToSel( (NE_SEG_TABLE( pModule ) +
187 pModule->dgroup - 1)->hSeg );
189 else
191 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
192 LocalInit( USER_HeapSel, 0, 0xffff );
195 /* Global atom table initialisation */
196 if (!ATOM_Init( USER_HeapSel )) return FALSE;
198 /* Initialize system colors and metrics*/
199 SYSMETRICS_Init();
200 SYSCOLOR_Init();
202 /* Create the DCEs */
203 DCE_Init();
205 /* Initialize window procedures */
206 if (!WINPROC_Init()) return FALSE;
208 /* Initialize built-in window classes */
209 if (!WIDGETS_Init()) return FALSE;
211 /* Initialize dialog manager */
212 if (!DIALOG_Init()) return FALSE;
214 /* Initialize menus */
215 if (!MENU_Init()) return FALSE;
217 /* Initialize multimedia */
218 if (!MULTIMEDIA_Init()) return FALSE;
220 /* Initialize message spying */
221 if (!SPY_Init()) return FALSE;
223 /* Check wine.conf for old/bad entries */
224 if (!TWEAK_CheckConfiguration()) return FALSE;
226 /* Create system message queue */
227 queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
228 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
230 /* Set double click time */
231 SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
233 /* Create task message queue for the initial task */
234 queueSize = GetProfileInt32A( "windows", "DefaultQueueSize", 8 );
235 if (!SetMessageQueue32( queueSize )) return FALSE;
237 /* Create desktop window */
238 if (!WIN_CreateDesktopWindow()) return FALSE;
240 /* Install default USER Signal Handler */
241 SetTaskSignalProc( 0, (FARPROC16)USER_SignalProc );
243 /* Initialize keyboard driver */
244 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
246 /* Initialize mouse driver */
247 MOUSE_Enable( mouse_event );
249 return TRUE;
253 /***********************************************************************
254 * Winelib initialisation routine
256 HINSTANCE32 MAIN_WinelibInit( int *argc, char *argv[] )
258 WINE_MODREF *wm;
259 NE_MODULE *pModule;
260 OFSTRUCT ofs;
261 HMODULE16 hModule;
262 HINSTANCE16 hInstance;
264 /* Create the initial process */
265 if (!PROCESS_Init()) return 0;
267 /* Parse command line arguments */
268 MAIN_WineInit( argc, argv );
270 /* Main initialization */
271 if (!MAIN_MainInit()) return 0;
273 /* Initialize KERNEL */
274 if (!MAIN_KernelInit(0, 0, NULL)) return 0;
276 /* Create and switch to initial task */
277 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0], PROCESS_Current() )))
278 return 0;
279 PROCESS_Current()->exe_modref = wm;
281 strcpy( ofs.szPathName, wm->modname );
282 if ((hModule = MODULE_CreateDummyModule( &ofs )) < 32) return 0;
283 pModule = (NE_MODULE *)GlobalLock16( hModule );
284 pModule->flags = NE_FFLAGS_WIN32;
285 pModule->module32 = wm->module;
287 hInstance = NE_CreateInstance( pModule, NULL, TRUE );
288 PROCESS_Current()->task = TASK_Create( THREAD_Current(), pModule, hInstance, 0, FALSE );
290 TASK_StartTask( PROCESS_Current()->task );
292 /* Initialize GDI and USER */
293 if (!MAIN_GdiInit(0, 0, NULL)) return 0;
294 if (!MAIN_UserInit(0, 0, NULL)) return 0;
296 return wm->module;