1 /*****************************************************************************/
5 /* sim65 main program */
9 /* (C) 2002-2009, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
54 /*****************************************************************************/
56 /*****************************************************************************/
60 /* Name of program file */
61 const char* ProgramFile;
65 /*****************************************************************************/
67 /*****************************************************************************/
71 static void Usage (void)
73 printf ("Usage: %s [options] file [arguments]\n"
75 " -h\t\t\tHelp (this text)\n"
76 " -v\t\t\tIncrease verbosity\n"
77 " -V\t\t\tPrint the simulator version number\n"
80 " --help\t\tHelp (this text)\n"
81 " --verbose\t\tIncrease verbosity\n"
82 " --version\t\tPrint the simulator version number\n",
88 static void OptHelp (const char* Opt attribute ((unused)),
89 const char* Arg attribute ((unused)))
90 /* Print usage information and exit */
98 static void OptVerbose (const char* Opt attribute ((unused)),
99 const char* Arg attribute ((unused)))
100 /* Increase verbosity */
107 static void OptVersion (const char* Opt attribute ((unused)),
108 const char* Arg attribute ((unused)))
109 /* Print the simulator version */
111 fprintf (stderr, "sim65 V%s\n", GetVersionAsString ());
116 static void ReadProgramFile (void)
117 /* Load program into memory */
120 unsigned Addr = 0x0200;
123 FILE* F = fopen (ProgramFile, "rb");
125 Error ("Cannot open `%s': %s", ProgramFile, strerror (errno));
128 /* Get the CPU type from the file header */
129 if ((Val = fgetc(F)) != EOF) {
130 if (Val != CPU_6502 && Val != CPU_65C02) {
131 Error ("`%s': Invalid CPU type", ProgramFile);
136 /* Read the file body into memory */
137 while ((Val = fgetc(F)) != EOF) {
138 if (Addr == 0xFF00) {
139 Error ("`%s': To large to fit into $0200-$FFF0", ProgramFile);
141 MemWriteByte (Addr++, (unsigned char) Val);
144 /* Check for errors */
146 Error ("Error reading from `%s': %s", ProgramFile, strerror (errno));
152 Print (stdout, 1, "Loaded `%s' at $0200-$%04X\n", ProgramFile, Addr - 1);
157 int main (int argc, char* argv[])
159 /* Program long options */
160 static const LongOpt OptTab[] = {
161 { "--help", 0, OptHelp },
162 { "--verbose", 0, OptVerbose },
163 { "--version", 0, OptVersion },
168 /* Initialize the cmdline module */
169 InitCmdLine (&argc, &argv, "sim65");
171 /* Parse the command line */
173 while (I < ArgCount) {
175 /* Get the argument */
176 const char* Arg = ArgVec[I];
178 /* Check for an option */
179 if (Arg [0] == '-') {
184 LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
213 /* Do we have a program file? */
214 if (ProgramFile == 0) {
215 AbEnd ("No program file");
230 /* Return an apropriate exit code */