X11 driver changes.
[wine.git] / miscemu / main.c
blobcda9fca106b4afe7743165353c612d907dde24dd
1 /*
2 * Emulator initialisation code
4 */
6 #include <assert.h>
7 #include "callback.h"
8 #include "debug.h"
9 #include "debugger.h"
10 #include "main.h"
11 #include "miscemu.h"
12 #include "module.h"
13 #include "options.h"
14 #include "process.h"
15 #include "win16drv.h"
16 #include "thread.h"
17 #include "task.h"
18 #include "stackframe.h"
19 #include "windows.h"
21 static int MAIN_argc;
22 static char **MAIN_argv;
24 /***********************************************************************
25 * Emulator initialisation
27 BOOL32 MAIN_EmulatorInit(void)
29 /* Main initialization */
30 if (!MAIN_MainInit()) return FALSE;
32 /* Initialize relay code */
33 if (!RELAY_Init()) return FALSE;
35 /* Initialize signal handling */
36 if (!SIGNAL_InitEmulator()) return FALSE;
37 SIGNAL_Reinit=SIGNAL_InitEmulator;
39 /* Create the Win16 printer driver */
40 if (!WIN16DRV_Init()) return FALSE;
42 return TRUE;
46 /***********************************************************************
47 * Main loop of initial task
49 void MAIN_EmulatorRun( void )
51 extern void THUNK_InitCallout( void );
52 char startProg[256], defProg[256];
53 HINSTANCE32 handle;
54 int i;
55 MSG32 msg;
57 /* Load system DLLs into the initial process (and initialize them) */
58 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibrary32A("GDI32.DLL" )
59 || !LoadLibrary16("USER.EXE") || !LoadLibrary32A("USER32.DLL"))
60 ExitProcess( 1 );
62 /* Get pointers to USER routines called by KERNEL */
63 THUNK_InitCallout();
65 /* Add the Default Program if no program on the command line */
66 if (!MAIN_argv[1])
68 PROFILE_GetWineIniString( "programs", "Default", "",
69 defProg, sizeof(defProg) );
70 if (defProg[0]) MAIN_argv[MAIN_argc++] = defProg;
73 /* Add the Startup Program to the run list */
74 PROFILE_GetWineIniString( "programs", "Startup", "",
75 startProg, sizeof(startProg) );
76 if (startProg[0]) MAIN_argv[MAIN_argc++] = startProg;
78 /* Abort if no executable on command line */
79 if (MAIN_argc <= 1)
81 MAIN_Usage(MAIN_argv[0]);
82 exit(1);
85 /* Load and run executables given on command line */
86 for (i = 1; i < MAIN_argc; i++)
87 if ((handle = WinExec32( MAIN_argv[i], SW_SHOWNORMAL )) < 32)
89 MSG("wine: can't exec '%s': ", MAIN_argv[i]);
90 switch (handle)
92 case 2: MSG("file not found\n" ); break;
93 case 11: MSG("invalid exe file\n" ); break;
94 default: MSG("error=%d\n", handle ); break;
98 if (GetNumTasks() <= 1)
100 MSG("wine: no executable file found.\n" );
101 ExitProcess( 0 );
105 /* Start message loop for desktop window */
107 while ( GetNumTasks() > 1 && Callout.GetMessage32A( &msg, 0, 0, 0 ) )
109 Callout.TranslateMessage32( &msg );
110 Callout.DispatchMessage32A( &msg );
113 ExitProcess( 0 );
117 /**********************************************************************
118 * main
120 int main( int argc, char *argv[] )
122 NE_MODULE *pModule;
123 HINSTANCE16 hInstance;
124 extern char * DEBUG_argv0;
126 __winelib = 0; /* First of all, clear the Winelib flag */
129 * Save this so that the internal debugger can get a hold of it if
130 * it needs to.
132 DEBUG_argv0 = argv[0];
134 /* Create the initial process */
135 if (!PROCESS_Init()) return FALSE;
137 /* Parse command-line */
138 if (!MAIN_WineInit( &argc, argv )) return 1;
139 MAIN_argc = argc; MAIN_argv = argv;
141 /* Handle -dll option (hack) */
142 if (Options.dllFlags)
144 if (!BUILTIN_ParseDLLOptions( Options.dllFlags ))
146 MSG("%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
147 argv[0] );
148 BUILTIN_PrintDLLs();
149 exit(1);
153 /* Set up debugger callback routines */
154 ctx_debug_call = ctx_debug;
155 if (Options.debug)
156 TASK_AddTaskEntryBreakpoint = DEBUG_AddTaskEntryBreakpoint;
158 /* Initialize everything */
159 if (!MAIN_EmulatorInit()) return 1;
161 /* Load kernel modules */
162 if (!LoadLibrary16( "KERNEL" )) return 1;
163 if (!LoadLibrary32A( "KERNEL32" )) return 1;
165 /* Create initial task */
166 if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL32" ) )) ) return 1;
167 hInstance = NE_CreateInstance( pModule, NULL, TRUE );
168 PROCESS_Current()->task = TASK_Create( THREAD_Current(), pModule, hInstance, 0, FALSE );
170 /* Initialize CALL32 routines */
171 /* This needs to be done just before switching stacks */
172 IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
174 /* Switch to initial task */
175 CURRENT_STACK16->frame32->retaddr = (DWORD)MAIN_EmulatorRun;
176 TASK_StartTask( PROCESS_Current()->task );
177 MSG( "main: Should never happen: returned from TASK_StartTask()\n" );
178 return 0;