1
2 /*
3
4 main.c
5
6 This file contains the execution start-point.
7
8 */
9
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #ifndef _WIN32
16 #include <unistd.h>
17 #include <getopt.h>
18 #else
19 #include <windows.h>
20 #endif
21
22 #include "globals.h"
23 #include "gameboy.h"
24 #include "z80.h"
25 #include "arplay.h"
26 #include "sound.h"
27 #include "settings.h"
28
29 FILE *logfile;
30 int smallview=1,producesound=1,force_stdgameboy=0, check_xvideo=1;
31
32 #ifndef _WIN32
33 int main(int,char **);
34 #endif
35
36 char servername[64];
37
38 /* online help */
39
outhelp(char * execname)40 void outhelp(char *execname)
41 {
42
43
44 printf("\nSyntax: %s [options] romfile\n\n",execname);
45 #ifndef GLIDE
46 printf("Options: -d execute in double-size mode\n");
47 #endif
48 #ifdef WITH_XVIDEO
49 printf(" -x don't use XVideo extension\n");
50 #endif
51 #ifdef SOUND
52 printf(" -n sound off\n");
53 printf(" -f freq sound frequency (8000-44100)\n");
54 #endif
55 printf(" -o force old standard gameboy mode\n");
56 #ifdef DIALOGLINK
57 printf(" -c server connect to server (dialog link)\n");
58 printf(" -h start as server for dialog link\n");
59 #endif
60 printf(" -a code use action-replay code\n");
61
62 printf("\n");
63 exit(-1);
64 }
65
66 /* execution start-point */
67
68 #ifndef _WIN32
main(argc,argv)69 int main(argc,argv)
70 int argc;
71 char **argv;
72 #else
73 WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR lpCmdLine,int nShowCmd)
74 #endif
75 {
76
77 #ifndef _WIN32
78 int check=0x00000001;
79 char *chk;
80 #endif
81
82 int c;
83
84 #ifndef _WIN32
85 if ((sizeof(uchar)!=1)||(sizeof(uint)!=2)||(sizeof(ulong)!=4)) {
86 printf("Fixme: Compilation failed.\n");
87 return 1;
88 }
89
90 chk=(char *)(&check)+3;
91 #ifdef USE_LITTLE_ENDIAN
92 if (*chk!=0) {
93 #else
94 if (*chk!=1) {
95 #endif
96 printf("Compilation failed.\n");
97 #ifdef USE_LITTLE_ENDIAN
98 printf("Remove -DUSE_LITTLE_ENDIAN from the Makefile.\n");
99 #else
100 printf("Add -DUSE_LITTLE_ENDIAN to the Makefile.\n");
101 #endif
102 printf("Did you run ./configure ?\n");
103 return 1;
104 }
105
106 while ((c=getopt(argc,argv,"vdxonhc:a:f:"))!=EOF) {
107 switch (c) {
108 case 'v':
109 printf("cingb: version %s\n",VERSION_STRING);
110 exit(0);
111 break;
112 #ifdef WITH_XVIDEO
113 case 'x':
114 check_xvideo=0;
115 break;
116 #endif
117 case 'd':
118 smallview=0;
119 break;
120 #ifdef SOUND
121 case 'n':
122 producesound=0;
123 break;
124 case 'f':
125 sound_frequency=atoi(optarg);
126 if (sound_frequency<8000 || sound_frequency>48000) {
127 fprintf(OUTSTREAM,"Sound frequency must be in range 8000-44100.\n");
128 exit(1);
129 }
130 break;
131 #endif
132 case 'o':
133 force_stdgameboy=1;
134 break;
135 #ifdef DIALOGLINK
136 case 'h':
137 dialoglink=1;
138 servername[0]=0;
139 break;
140 case 'c':
141 dialoglink=1;
142 if (strlen(optarg)>=sizeof(servername)) {
143 fprintf(OUTSTREAM,"Server name too long.\n");
144 exit(1);
145 }
146 strcpy(servername,optarg);
147 break;
148 #endif
149 case 'a':
150 ar_setcode(optarg);
151 break;
152 default:
153 outhelp(argv[0]);
154 break;
155 }
156 }
157
158 c=argc-1;
159 while ((argv[c][0]=='-')&&(c>0)) c--;
160 if (c==0) outhelp(argv[0]);
161
162 #else
163
164 /* windows settings */
165 smallview=0;
166 producesound=0;
167 force_stdgameboy=0;
168 #ifdef DIALOGLINK
169 dialoglink=0;
170 #endif
171 c=1;
172
173 #endif
174
175
176 if (settings_read()<0) exit(-1);
177
178 /*
179 logfile=fopen("cingb.log","w");
180 */
181 logfile=stdout;
182
183 #ifdef _WIN32
184 if (!initcart("test.gb")) {
185 #else
186 if (!initcart(argv[c])) {
187 #endif
188
189 /* starting rom emulation */
190 StartCPU();
191 } else {
192 #ifndef _WIN32
193 printf("Couldn't start %s.\n",argv[c]);
194 #else
195 MessageBox(NULL,"Could not start the cartridge.","Error",MB_OK+MB_ICONSTOP);
196 #endif
197 tidyup();
198 return 1;
199 }
200
201 tidyup();
202 return 0;
203 }
204
205