]> git.sur5r.net Git - cc65/blob - src/sim65/main.c
Cosmetic change
[cc65] / src / sim65 / main.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  main.c                                   */
4 /*                                                                           */
5 /*                              sim65 main program                           */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2002      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <errno.h>
40
41 /* common */
42 #include "abend.h"
43 #include "cmdline.h"
44 #include "print.h"
45 #include "version.h"
46
47 /* sim65 */
48 #include "chip.h"
49 #include "chiplib.h"
50 #include "chippath.h"
51 #include "cpucore.h"
52 #include "cputype.h"
53 #include "global.h"
54 #include "memory.h"
55
56
57 /*****************************************************************************/
58 /*                                   Code                                    */
59 /*****************************************************************************/
60
61
62
63 static void Usage (void)
64 {
65     fprintf (stderr,
66              "Usage: %s [options] file\n"
67              "Short options:\n"
68              "  -V\t\t\tPrint the simulator version number\n"
69              "  -d\t\t\tDebug mode\n"
70              "  -h\t\t\tHelp (this text)\n"
71              "  -v\t\t\tIncrease verbosity\n"
72              "\n"
73              "Long options:\n"
74              "  --cpu type\t\tSet cpu type\n"
75              "  --debug\t\tDebug mode\n"
76              "  --help\t\tHelp (this text)\n"
77              "  --verbose\t\tIncrease verbosity\n"
78              "  --version\t\tPrint the simulator version number\n",
79              ProgName);
80 }
81
82
83
84 static void OptCPU (const char* Opt, const char* Arg)
85 /* Handle the --cpu option */
86 {
87     if (strcmp (Arg, "6502") == 0) {
88         CPU = CPU_6502;
89     } else if (strcmp (Arg, "65C02") == 0) {
90         CPU = CPU_65C02;
91     } else {
92         AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
93     }
94 }
95
96
97
98 static void OptDebug (const char* Opt attribute ((unused)),
99                       const char* Arg attribute ((unused)))
100 /* Simulator debug mode */
101 {
102     Debug = 1;
103 }
104
105
106
107 static void OptHelp (const char* Opt attribute ((unused)),
108                      const char* Arg attribute ((unused)))
109 /* Print usage information and exit */
110 {
111     Usage ();
112     exit (EXIT_SUCCESS);
113 }
114
115
116
117 static void OptVerbose (const char* Opt attribute ((unused)),
118                         const char* Arg attribute ((unused)))
119 /* Increase verbosity */
120 {
121     ++Verbosity;
122 }
123
124
125
126 static void OptVersion (const char* Opt attribute ((unused)),
127                         const char* Arg attribute ((unused)))
128 /* Print the assembler version */
129 {
130     fprintf (stderr,
131              "cc65 V%u.%u.%u\n",
132              VER_MAJOR, VER_MINOR, VER_PATCH);
133 }
134
135
136
137 int main (int argc, char* argv[])
138 {
139     /* Program long options */
140     static const LongOpt OptTab[] = {
141         { "--cpu",              1,      OptCPU                  },
142         { "--debug",            0,      OptDebug                },
143         { "--help",             0,      OptHelp                 },
144         { "--verbose",          0,      OptVerbose              },
145         { "--version",          0,      OptVersion              },
146     };
147
148     unsigned I;
149
150     /* Initialize the output file name */
151     const char* InputFile  = 0;
152
153     /* Initialize the cmdline module */
154     InitCmdLine (&argc, &argv, "sim65");
155
156     /* Parse the command line */
157     I = 1;
158     while (I < ArgCount) {
159
160         /* Get the argument */
161         const char* Arg = ArgVec[I];
162
163         /* Check for an option */
164         if (Arg [0] == '-') {
165
166             switch (Arg [1]) {
167
168                 case '-':
169                     LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
170                     break;
171
172                 case 'd':
173                     OptDebug (Arg, 0);
174                     break;
175
176                 case 'h':
177                 case '?':
178                     OptHelp (Arg, 0);
179                     break;
180
181                 case 'v':
182                     OptVerbose (Arg, 0);
183                     break;
184
185                 case 'V':
186                     OptVersion (Arg, 0);
187                     break;
188
189                 default:
190                     UnknownOption (Arg);
191                     break;
192             }
193         } else {
194             if (InputFile) {
195                 fprintf (stderr, "additional file specs ignored\n");
196             } else {
197                 InputFile = Arg;
198             }
199         }
200
201         /* Next argument */
202         ++I;
203     }
204
205     /* Initialize modules */
206     AddChipPath ("chips");
207     LoadChipLibrary ("ram.so");
208     LoadChips ();
209     MemInit ();
210     MemLoad ("uz.bin", 0x200, 0);
211     CPUInit ();
212     CPURun ();
213
214     /* Return an apropriate exit code */
215     return EXIT_SUCCESS;
216 }
217
218
219