Starting implementation of MCI creator tasks
[wine/dcerpc.git] / miscemu / main.c
blobd26b7ac4b35d350a821a26b9e4005f82b14b1eb6
1 /*
2 * Emulator initialisation code
4 */
6 #include <stdlib.h>
7 #include <assert.h>
8 #include "wine/winbase16.h"
9 #include "callback.h"
10 #include "debugger.h"
11 #include "main.h"
12 #include "miscemu.h"
13 #include "win16drv.h"
14 #include "module.h"
15 #include "options.h"
16 #include "process.h"
17 #include "thread.h"
18 #include "task.h"
19 #include "stackframe.h"
20 #include "debug.h"
22 static int MAIN_argc;
23 static char **MAIN_argv;
25 /***********************************************************************
26 * Emulator initialisation
28 BOOL MAIN_EmulatorInit(void)
30 /* Main initialization */
31 if (!MAIN_MainInit()) return FALSE;
33 /* Initialize relay code */
34 if (!RELAY_Init()) return FALSE;
36 /* Create the Win16 printer driver */
37 if (!WIN16DRV_Init()) return FALSE;
39 return TRUE;
43 /***********************************************************************
44 * Main loop of initial task
46 void MAIN_EmulatorRun( void )
48 extern void THUNK_InitCallout( void );
49 char startProg[256], defProg[256];
50 HINSTANCE handle;
51 int i, tasks = 0;
52 MSG msg;
54 /* Load system DLLs into the initial process (and initialize them) */
55 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
56 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
57 ExitProcess( 1 );
59 /* Get pointers to USER routines called by KERNEL */
60 THUNK_InitCallout();
62 /* Add the Default Program if no program on the command line */
63 if (!MAIN_argv[1])
65 PROFILE_GetWineIniString( "programs", "Default", "",
66 defProg, sizeof(defProg) );
67 if (defProg[0]) MAIN_argv[MAIN_argc++] = defProg;
70 /* Add the Startup Program to the run list */
71 PROFILE_GetWineIniString( "programs", "Startup", "",
72 startProg, sizeof(startProg) );
73 if (startProg[0]) MAIN_argv[MAIN_argc++] = startProg;
75 /* Abort if no executable on command line */
76 if (MAIN_argc <= 1)
78 MAIN_Usage(MAIN_argv[0]);
79 exit(1);
82 /* Load and run executables given on command line */
83 for (i = 1; i < MAIN_argc; i++)
85 if ((handle = WinExec( MAIN_argv[i], SW_SHOWNORMAL )) < 32)
87 MSG("wine: can't exec '%s': ", MAIN_argv[i]);
88 switch (handle)
90 case 2: MSG("file not found\n" ); break;
91 case 11: MSG("invalid exe file\n" ); break;
92 default: MSG("error=%d\n", handle ); break;
95 else tasks++;
98 if (!tasks)
100 MSG("wine: no executable file found.\n" );
101 ExitProcess( 0 );
105 /* Start message loop for desktop window */
107 while ( GetNumTasks16() > 1 && Callout.GetMessageA( &msg, 0, 0, 0 ) )
109 Callout.TranslateMessage( &msg );
110 Callout.DispatchMessageA( &msg );
113 ExitProcess( 0 );
117 /**********************************************************************
118 * main
120 int main( int argc, char *argv[] )
122 NE_MODULE *pModule;
123 extern char * DEBUG_argv0;
125 __winelib = 0; /* First of all, clear the Winelib flag */
128 * Save this so that the internal debugger can get a hold of it if
129 * it needs to.
131 DEBUG_argv0 = argv[0];
133 /* Create the initial process */
134 if (!PROCESS_Init()) return FALSE;
136 /* Parse command-line */
137 if (!MAIN_WineInit( &argc, argv )) return 1;
138 MAIN_argc = argc; MAIN_argv = argv;
140 /* Handle -dll option (hack) */
141 if (Options.dllFlags)
143 /* If there are options left, or if the parser had errors, report it */
144 if (!BUILTIN_ParseDLLOptions( Options.dllFlags )||Options.dllFlags[0]) {
145 MSG("%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
146 argv[0] );
147 BUILTIN_PrintDLLs();
148 exit(1);
152 /* Set up debugger/instruction emulation callback routines */
153 ctx_debug_call = ctx_debug;
154 fnWINE_Debugger = wine_debug;
155 fnINSTR_EmulateInstruction = INSTR_EmulateInstruction;
157 if (Options.debug)
158 TASK_AddTaskEntryBreakpoint = DEBUG_AddTaskEntryBreakpoint;
160 /* Initialize everything */
161 if (!MAIN_EmulatorInit()) return 1;
163 /* Load kernel modules */
164 if (!LoadLibrary16( "KERNEL" )) return 1;
165 if (!LoadLibraryA( "KERNEL32" )) return 1;
167 /* Create initial task */
168 if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL32" ) )) ) return 1;
169 if ( !TASK_Create( THREAD_Current(), pModule, 0, 0, FALSE ) ) return 1;
171 /* Initialize CALL32 routines */
172 /* This needs to be done just before switching stacks */
173 IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
175 /* Switch to initial task */
176 CURRENT_STACK16->frame32->retaddr = (DWORD)MAIN_EmulatorRun;
177 TASK_StartTask( PROCESS_Current()->task );
178 MSG( "main: Should never happen: returned from TASK_StartTask()\n" );
179 return 0;