Simulate the VGA vertical refresh.
[wine/hacks.git] / miscemu / main.c
blob750c1cc40b3dc06b32ce5134207df79b0f9af135
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 "psdrv.h"
17 #include "thread.h"
18 #include "task.h"
19 #include "stackframe.h"
20 #include "windows.h"
22 static int MAIN_argc;
23 static char **MAIN_argv;
25 /***********************************************************************
26 * Emulator initialisation
28 BOOL32 MAIN_EmulatorInit(void)
30 /* Main initialization */
31 if (!MAIN_MainInit()) return FALSE;
33 /* Initialize relay code */
34 if (!RELAY_Init()) return FALSE;
36 /* Initialize signal handling */
37 if (!SIGNAL_InitEmulator()) return FALSE;
39 /* Create the Win16 printer driver */
40 if (!WIN16DRV_Init()) return FALSE;
42 /* Create the Postscript printer driver (FIXME: should be in Winelib) */
43 if (!PSDRV_Init()) return FALSE;
45 return TRUE;
48 /***********************************************************************
49 * Main loop of initial task
51 void MAIN_EmulatorRun( void )
53 char startProg[256], defProg[256];
54 int i,loaded;
55 HINSTANCE32 handle;
57 BOOL32 (*WINAPI pGetMessage)(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max);
58 BOOL32 (*WINAPI pTranslateMessage)( const MSG32* msg );
59 LONG (*WINAPI pDispatchMessage)( const MSG32* msg );
60 HMODULE32 hModule;
61 MSG32 msg;
63 /* Load system DLLs into the initial process (and initialize them) */
64 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibrary32A("GDI32.DLL" )
65 || !LoadLibrary16("USER.EXE") || !LoadLibrary32A("USER32.DLL"))
66 ExitProcess( 1 );
68 /* Add the Default Program if no program on the command line */
69 if (!MAIN_argv[1])
71 PROFILE_GetWineIniString( "programs", "Default", "",
72 defProg, sizeof(defProg) );
73 if (defProg[0]) MAIN_argv[MAIN_argc++] = defProg;
76 /* Add the Startup Program to the run list */
77 PROFILE_GetWineIniString( "programs", "Startup", "",
78 startProg, sizeof(startProg) );
79 if (startProg[0]) MAIN_argv[MAIN_argc++] = startProg;
81 loaded=0;
82 for (i = 1; i < MAIN_argc; i++)
84 if ((handle = WinExec32( MAIN_argv[i], SW_SHOWNORMAL )) < 32)
86 MSG("wine: can't exec '%s': ", MAIN_argv[i]);
87 switch (handle)
89 case 2: MSG("file not found\n" ); break;
90 case 11: MSG("invalid exe file\n" ); break;
91 case 21: MSG("win32 executable\n" ); break; /* FIXME: Obsolete? */
92 default: MSG("error=%d\n", handle ); break;
94 ExitProcess( 1 );
96 loaded++;
99 if (!loaded) { /* nothing loaded */
100 MAIN_Usage(MAIN_argv[0]);
101 ExitProcess( 1 );
104 if (GetNumTasks() <= 1)
106 MSG("wine: no executable file found.\n" );
107 ExitProcess( 0 );
110 if (Options.debug) DEBUG_AddModuleBreakpoints();
113 /* Start message loop for desktop window */
115 hModule = GetModuleHandle32A( "USER32" );
116 pGetMessage = GetProcAddress32( hModule, "GetMessageA" );
117 pTranslateMessage = GetProcAddress32( hModule, "TranslateMessage" );
118 pDispatchMessage = GetProcAddress32( hModule, "DispatchMessageA" );
120 assert( pGetMessage );
121 assert( pTranslateMessage );
122 assert( pDispatchMessage );
124 while ( GetNumTasks() > 1 && pGetMessage( &msg, 0, 0, 0 ) )
126 pTranslateMessage( &msg );
127 pDispatchMessage( &msg );
130 ExitProcess( 0 );
134 /**********************************************************************
135 * main
137 int main( int argc, char *argv[] )
139 NE_MODULE *pModule;
140 HINSTANCE16 hInstance;
141 extern char * DEBUG_argv0;
143 __winelib = 0; /* First of all, clear the Winelib flag */
144 ctx_debug_call = ctx_debug;
147 * Save this so that the internal debugger can get a hold of it if
148 * it needs to.
150 DEBUG_argv0 = argv[0];
152 /* Create the initial process */
153 if (!PROCESS_Init()) return FALSE;
155 /* Parse command-line */
156 if (!MAIN_WineInit( &argc, argv )) return 1;
157 MAIN_argc = argc; MAIN_argv = argv;
159 /* Handle -dll option (hack) */
160 if (Options.dllFlags)
162 if (!BUILTIN_ParseDLLOptions( Options.dllFlags ))
164 MSG("%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
165 argv[0] );
166 BUILTIN_PrintDLLs();
167 exit(1);
171 /* Initialize everything */
172 if (!MAIN_EmulatorInit()) return 1;
174 /* Load kernel modules */
175 if (!LoadLibrary16( "KERNEL" )) return 1;
176 if (!LoadLibrary32A( "KERNEL32" )) return 1;
178 /* Create initial task */
179 if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL32" ) )) ) return 1;
180 hInstance = NE_CreateInstance( pModule, NULL, TRUE );
181 PROCESS_Current()->task = TASK_Create( THREAD_Current(), pModule, hInstance, 0, FALSE );
183 /* Initialize CALL32 routines */
184 /* This needs to be done just before switching stacks */
185 IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
187 /* Switch to initial task */
188 CURRENT_STACK16->frame32->retaddr = (DWORD)MAIN_EmulatorRun;
189 TASK_StartTask( PROCESS_Current()->task );
190 MSG( "main: Should never happen: returned from TASK_StartTask()\n" );
191 return 0;