Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Emulator initialisation code |
| 3 | * |
| 4 | */ |
| 5 | |
David Luyer | ee517e8 | 1999-02-28 12:27:56 +0000 | [diff] [blame] | 6 | #include <stdlib.h> |
Ulrich Weigand | c75d0e1 | 1998-11-01 17:59:35 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 8 | #include "wine/winbase16.h" |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 9 | #include "callback.h" |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 10 | #include "main.h" |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 11 | #include "miscemu.h" |
| 12 | #include "module.h" |
| 13 | #include "options.h" |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 14 | #include "process.h" |
Ulrich Weigand | c75d0e1 | 1998-11-01 17:59:35 +0000 | [diff] [blame] | 15 | #include "thread.h" |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 16 | #include "task.h" |
| 17 | #include "stackframe.h" |
Alexandre Julliard | 410ae4f | 1999-06-18 18:23:11 +0000 | [diff] [blame] | 18 | #include "wine/exception.h" |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 19 | #include "debugtools.h" |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 20 | |
Alexandre Julliard | fe08568 | 2000-03-18 21:56:10 +0000 | [diff] [blame^] | 21 | extern DWORD DEBUG_WinExec(LPCSTR lpCmdLine, int sw); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 22 | |
Alexandre Julliard | fe08568 | 2000-03-18 21:56:10 +0000 | [diff] [blame^] | 23 | |
| 24 | static BOOL exec_program( LPCSTR cmdline ) |
| 25 | { |
| 26 | HINSTANCE handle; |
| 27 | |
| 28 | if (Options.debug) |
| 29 | handle = DEBUG_WinExec( cmdline, SW_SHOWNORMAL ); |
| 30 | else |
| 31 | handle = WinExec( cmdline, SW_SHOWNORMAL ); |
| 32 | |
| 33 | if (handle < 32) |
| 34 | { |
| 35 | MESSAGE( "%s: can't exec '%s': ", argv0, cmdline ); |
| 36 | switch (handle) |
| 37 | { |
| 38 | case 2: MESSAGE("file not found\n" ); break; |
| 39 | case 11: MESSAGE("invalid exe file\n" ); break; |
| 40 | default: MESSAGE("error=%d\n", handle ); break; |
| 41 | } |
| 42 | } |
| 43 | return (handle >= 32); |
| 44 | } |
Alexandre Julliard | c42dfdd | 1999-06-20 15:09:32 +0000 | [diff] [blame] | 45 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 46 | /*********************************************************************** |
Ulrich Weigand | c75d0e1 | 1998-11-01 17:59:35 +0000 | [diff] [blame] | 47 | * Main loop of initial task |
| 48 | */ |
| 49 | void MAIN_EmulatorRun( void ) |
| 50 | { |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 51 | char startProg[256], defProg[256]; |
Marcus Meissner | 4097865 | 1999-02-14 11:32:18 +0000 | [diff] [blame] | 52 | int i, tasks = 0; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 53 | MSG msg; |
Ulrich Weigand | c75d0e1 | 1998-11-01 17:59:35 +0000 | [diff] [blame] | 54 | |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 55 | /* Load system DLLs into the initial process (and initialize them) */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 56 | if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" ) |
| 57 | || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL")) |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 58 | ExitProcess( 1 ); |
| 59 | |
Ulrich Weigand | ff35e1f | 1998-12-24 15:13:54 +0000 | [diff] [blame] | 60 | /* Get pointers to USER routines called by KERNEL */ |
| 61 | THUNK_InitCallout(); |
| 62 | |
Ulrich Weigand | 98c3053 | 1999-07-27 17:10:06 +0000 | [diff] [blame] | 63 | /* Call FinalUserInit routine */ |
| 64 | Callout.FinalUserInit16(); |
| 65 | |
Ulrich Weigand | 7366307 | 1999-04-10 16:32:45 +0000 | [diff] [blame] | 66 | /* Call InitApp for initial task */ |
| 67 | Callout.InitApp16( MapHModuleLS( 0 ) ); |
| 68 | |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 69 | /* Add the Startup Program to the run list */ |
| 70 | PROFILE_GetWineIniString( "programs", "Startup", "", |
| 71 | startProg, sizeof(startProg) ); |
Alexandre Julliard | fe08568 | 2000-03-18 21:56:10 +0000 | [diff] [blame^] | 72 | if (startProg[0]) tasks += exec_program( startProg ); |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 73 | |
Alexandre Julliard | fe08568 | 2000-03-18 21:56:10 +0000 | [diff] [blame^] | 74 | /* Add the Default Program if no program on the command line */ |
| 75 | if (!Options.argv[1]) |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 76 | { |
Alexandre Julliard | fe08568 | 2000-03-18 21:56:10 +0000 | [diff] [blame^] | 77 | PROFILE_GetWineIniString( "programs", "Default", "", |
| 78 | defProg, sizeof(defProg) ); |
| 79 | if (defProg[0]) tasks += exec_program( defProg ); |
| 80 | else if (!tasks && !startProg[0]) OPTIONS_Usage(); |
Ulrich Weigand | afac2e4 | 1998-11-14 18:45:25 +0000 | [diff] [blame] | 81 | } |
Alexandre Julliard | fe08568 | 2000-03-18 21:56:10 +0000 | [diff] [blame^] | 82 | else |
Marcus Meissner | 4097865 | 1999-02-14 11:32:18 +0000 | [diff] [blame] | 83 | { |
Alexandre Julliard | fe08568 | 2000-03-18 21:56:10 +0000 | [diff] [blame^] | 84 | /* Load and run executables given on command line */ |
| 85 | for (i = 1; Options.argv[i]; i++) |
| 86 | { |
| 87 | tasks += exec_program( Options.argv[i] ); |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 88 | } |
Marcus Meissner | 4097865 | 1999-02-14 11:32:18 +0000 | [diff] [blame] | 89 | } |
Alexandre Julliard | fe08568 | 2000-03-18 21:56:10 +0000 | [diff] [blame^] | 90 | if (!tasks) ExitProcess( 0 ); |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 91 | |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 92 | /* Start message loop for desktop window */ |
| 93 | |
Ulrich Weigand | a1957c4 | 1999-05-24 08:10:46 +0000 | [diff] [blame] | 94 | while ( GetNumTasks16() > 1 && Callout.GetMessageA( &msg, 0, 0, 0 ) ) |
Ulrich Weigand | c75d0e1 | 1998-11-01 17:59:35 +0000 | [diff] [blame] | 95 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 96 | Callout.TranslateMessage( &msg ); |
| 97 | Callout.DispatchMessageA( &msg ); |
Ulrich Weigand | a1957c4 | 1999-05-24 08:10:46 +0000 | [diff] [blame] | 98 | } |
Ulrich Weigand | c75d0e1 | 1998-11-01 17:59:35 +0000 | [diff] [blame] | 99 | |
| 100 | ExitProcess( 0 ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
| 104 | /********************************************************************** |
| 105 | * main |
| 106 | */ |
| 107 | int main( int argc, char *argv[] ) |
| 108 | { |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 109 | NE_MODULE *pModule; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 110 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 111 | /* Initialize everything */ |
Ulrich Weigand | 7d43bce | 2000-01-30 21:16:45 +0000 | [diff] [blame] | 112 | if (!MAIN_MainInit( &argc, argv, FALSE )) return 1; |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 113 | |
| 114 | /* Create initial task */ |
Alexandre Julliard | 8d267a6 | 1999-05-02 19:09:07 +0000 | [diff] [blame] | 115 | if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1; |
Ulrich Weigand | fbea530 | 1999-07-03 12:26:29 +0000 | [diff] [blame] | 116 | if ( !TASK_Create( pModule, FALSE ) ) return 1; |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 117 | |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 118 | /* Switch to initial task */ |
Ulrich Weigand | bba76ee | 1999-06-06 14:49:55 +0000 | [diff] [blame] | 119 | PostEvent16( PROCESS_Current()->task ); |
| 120 | TASK_Reschedule(); |
| 121 | |
| 122 | /* Switch stacks and jump to MAIN_EmulatorRun */ |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 123 | CALL32_Init( &IF1632_CallLargeStack, MAIN_EmulatorRun, NtCurrentTeb()->stack_top ); |
Ulrich Weigand | bba76ee | 1999-06-06 14:49:55 +0000 | [diff] [blame] | 124 | |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 125 | MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 126 | return 0; |
| 127 | } |