2 * Emulator initialisation code
7 #include "wine/winbase16.h"
18 #include "stackframe.h"
22 static char **MAIN_argv
;
24 /***********************************************************************
25 * Emulator initialisation
27 BOOL
MAIN_EmulatorInit(void)
29 /* Main initialization */
30 if (!MAIN_MainInit()) return FALSE
;
32 /* Initialize relay code */
33 if (!RELAY_Init()) return FALSE
;
35 /* Create the Win16 printer driver */
36 if (!WIN16DRV_Init()) return FALSE
;
42 /***********************************************************************
43 * Main loop of initial task
45 void MAIN_EmulatorRun( void )
47 extern void THUNK_InitCallout( void );
48 char startProg
[256], defProg
[256];
53 /* Load system DLLs into the initial process (and initialize them) */
54 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
55 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
58 /* Get pointers to USER routines called by KERNEL */
61 /* Add the Default Program if no program on the command line */
64 PROFILE_GetWineIniString( "programs", "Default", "",
65 defProg
, sizeof(defProg
) );
66 if (defProg
[0]) MAIN_argv
[MAIN_argc
++] = defProg
;
69 /* Add the Startup Program to the run list */
70 PROFILE_GetWineIniString( "programs", "Startup", "",
71 startProg
, sizeof(startProg
) );
72 if (startProg
[0]) MAIN_argv
[MAIN_argc
++] = startProg
;
74 /* Abort if no executable on command line */
77 MAIN_Usage(MAIN_argv
[0]);
81 /* Load and run executables given on command line */
82 for (i
= 1; i
< MAIN_argc
; i
++)
84 if ((handle
= WinExec( MAIN_argv
[i
], SW_SHOWNORMAL
)) < 32)
86 MSG("wine: can't exec '%s': ", MAIN_argv
[i
]);
89 case 2: MSG("file not found\n" ); break;
90 case 11: MSG("invalid exe file\n" ); break;
91 default: MSG("error=%d\n", handle
); break;
99 MSG("wine: no executable file found.\n" );
104 /* Start message loop for desktop window */
106 while ( GetNumTasks16() > 1 && Callout
.GetMessageA( &msg
, 0, 0, 0 ) )
108 Callout
.TranslateMessage( &msg
);
109 Callout
.DispatchMessageA( &msg
);
116 /**********************************************************************
119 int main( int argc
, char *argv
[] )
122 extern char * DEBUG_argv0
;
124 __winelib
= 0; /* First of all, clear the Winelib flag */
127 * Save this so that the internal debugger can get a hold of it if
130 DEBUG_argv0
= argv
[0];
132 /* Create the initial process */
133 if (!PROCESS_Init()) return FALSE
;
135 /* Parse command-line */
136 if (!MAIN_WineInit( &argc
, argv
)) return 1;
137 MAIN_argc
= argc
; MAIN_argv
= argv
;
139 /* Handle -dll option (hack) */
140 if (Options
.dllFlags
)
142 if (!BUILTIN_ParseDLLOptions( Options
.dllFlags
))
144 MSG("%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
151 /* Set up debugger/instruction emulation callback routines */
152 ctx_debug_call
= ctx_debug
;
153 fnWINE_Debugger
= wine_debug
;
154 fnINSTR_EmulateInstruction
= INSTR_EmulateInstruction
;
157 TASK_AddTaskEntryBreakpoint
= DEBUG_AddTaskEntryBreakpoint
;
159 /* Initialize everything */
160 if (!MAIN_EmulatorInit()) return 1;
162 /* Load kernel modules */
163 if (!LoadLibrary16( "KERNEL" )) return 1;
164 if (!LoadLibraryA( "KERNEL32" )) return 1;
166 /* Create initial task */
167 if ( !(pModule
= NE_GetPtr( GetModuleHandle16( "KERNEL32" ) )) ) return 1;
168 if ( !TASK_Create( THREAD_Current(), pModule
, 0, 0, FALSE
) ) return 1;
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" );