Got rid of -debug wine's option (wine now requires an external debugger).
[wine.git] / miscemu / main.c
blobe4bdd3d824bdfebe8283cc99192d85fc445b969b
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 "main.h"
11 #include "miscemu.h"
12 #include "module.h"
13 #include "options.h"
14 #include "process.h"
15 #include "thread.h"
16 #include "task.h"
17 #include "stackframe.h"
18 #include "wine/exception.h"
19 #include "debugtools.h"
21 static BOOL exec_program( LPCSTR cmdline )
23 HINSTANCE handle = WinExec( cmdline, SW_SHOWNORMAL );
24 if (handle < 32)
26 MESSAGE( "%s: can't exec '%s': ", argv0, cmdline );
27 switch (handle)
29 case 2: MESSAGE("file not found\n" ); break;
30 case 11: MESSAGE("invalid exe file\n" ); break;
31 default: MESSAGE("error=%d\n", handle ); break;
34 return (handle >= 32);
37 /***********************************************************************
38 * Main loop of initial task
40 void MAIN_EmulatorRun( void )
42 char startProg[256], defProg[256];
43 int i, tasks = 0;
44 MSG msg;
46 /* Load system DLLs into the initial process (and initialize them) */
47 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
48 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
49 ExitProcess( 1 );
51 /* Get pointers to USER routines called by KERNEL */
52 THUNK_InitCallout();
54 /* Call FinalUserInit routine */
55 Callout.FinalUserInit16();
57 /* Call InitApp for initial task */
58 Callout.InitApp16( MapHModuleLS( 0 ) );
60 /* Add the Startup Program to the run list */
61 PROFILE_GetWineIniString( "programs", "Startup", "",
62 startProg, sizeof(startProg) );
63 if (startProg[0]) tasks += exec_program( startProg );
65 /* Add the Default Program if no program on the command line */
66 if (!Options.argv[1])
68 PROFILE_GetWineIniString( "programs", "Default", "",
69 defProg, sizeof(defProg) );
70 if (defProg[0]) tasks += exec_program( defProg );
71 else if (!tasks && !startProg[0]) OPTIONS_Usage();
73 else
75 /* Load and run executables given on command line */
76 for (i = 1; Options.argv[i]; i++)
78 tasks += exec_program( Options.argv[i] );
81 if (!tasks) ExitProcess( 0 );
83 /* Start message loop for desktop window */
85 while ( GetNumTasks16() > 1 && Callout.GetMessageA( &msg, 0, 0, 0 ) )
87 Callout.TranslateMessage( &msg );
88 Callout.DispatchMessageA( &msg );
91 ExitProcess( 0 );
95 /**********************************************************************
96 * main
98 int main( int argc, char *argv[] )
100 NE_MODULE *pModule;
102 /* Initialize everything */
103 if (!MAIN_MainInit( argc, argv, FALSE )) return 1;
105 /* Create initial task */
106 if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
107 if ( !TASK_Create( pModule, FALSE ) ) return 1;
109 /* Switch to initial task */
110 PostEvent16( PROCESS_Current()->task );
111 TASK_Reschedule();
113 /* Switch stacks and jump to MAIN_EmulatorRun */
114 CALL32_Init( &IF1632_CallLargeStack, MAIN_EmulatorRun, NtCurrentTeb()->stack_top );
116 MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );
117 return 0;