blob: 98dc871bb65eabfd5fc173e8959c8eae5db625fb [file] [log] [blame]
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001/*
2 * Emulator initialisation code
3 *
4 */
5
6#include <stdio.h>
7#include "windows.h"
8#include "callback.h"
9#include "debugger.h"
10#include "miscemu.h"
11#include "module.h"
12#include "options.h"
13
14
15/***********************************************************************
16 * Emulator initialisation
17 */
18BOOL32 MAIN_EmulatorInit(void)
19{
20 extern BOOL32 MAIN_KernelInit(void);
21 extern BOOL32 MAIN_UserInit(void);
22 extern BOOL32 WIN16DRV_Init(void);
23 extern BOOL32 RELAY_Init(void);
24
25 /* Initialize the kernel */
26 if (!MAIN_KernelInit()) return FALSE;
27
28 /* Initialize relay code */
29 if (!RELAY_Init()) return FALSE;
30
31 /* Initialize signal handling */
32 if (!SIGNAL_InitEmulator()) return FALSE;
33
34 /* Create the Win16 printer driver */
35 if (!WIN16DRV_Init()) return FALSE;
36
37 /* Initialize all the USER stuff */
38 return MAIN_UserInit();
39}
40
41
42/**********************************************************************
43 * main
44 */
45int main( int argc, char *argv[] )
46{
47 extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
48 extern void *CALL32_Init(void);
49 extern char * DEBUG_argv0;
50
51 int i,loaded;
52 HINSTANCE32 handle;
53
54 __winelib = 0; /* First of all, clear the Winelib flag */
55
56 /*
57 * Save this so that the internal debugger can get a hold of it if
58 * it needs to.
59 */
60 DEBUG_argv0 = argv[0];
61
62 if (!MAIN_WineInit( &argc, argv )) return 1;
63
64 /* Handle -dll option (hack) */
65
66 if (Options.dllFlags)
67 {
68 if (!BUILTIN_ParseDLLOptions( Options.dllFlags ))
69 {
70 fprintf( stderr, "%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
71 argv[0] );
72 BUILTIN_PrintDLLs();
73 exit(1);
74 }
75 }
76
77 /* Initialize everything */
78
79 if (!MAIN_EmulatorInit()) return 1;
80
81 /* Initialize CALL32 routines */
82 /* This needs to be done just before task-switching starts */
83 IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
84
85 loaded=0;
86 for (i = 1; i < argc; i++)
87 {
88 if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
89 {
90 fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
91 switch (handle)
92 {
93 case 2: fprintf( stderr, "file not found\n" ); break;
94 case 11: fprintf( stderr, "invalid exe file\n" ); break;
95 case 21: fprintf( stderr, "win32 executable\n" ); break;
96 default: fprintf( stderr, "error=%d\n", handle ); break;
97 }
98 return 1;
99 }
100 loaded++;
101 }
102
103 if (!loaded) { /* nothing loaded */
104 extern void MAIN_Usage(char*);
105 MAIN_Usage(argv[0]);
106 return 1;
107 }
108
109 if (!GetNumTasks())
110 {
111 fprintf( stderr, "wine: no executable file found.\n" );
112 return 0;
113 }
114
115 if (Options.debug) DEBUG_AddModuleBreakpoints();
116
117 Yield(); /* Start the first task */
118 fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
119 return 0;
120}