]> git.sur5r.net Git - cc65/blobdiff - src/cc65/main.c
Fixed a bug
[cc65] / src / cc65 / main.c
index 28ba50dd830b3e0550be2f296ae62e0a11b26390..9fda4f169c7e71a07b20361b81728f00cf3c6658 100644 (file)
 #include "abend.h"
 #include "chartype.h"
 #include "cmdline.h"
+#include "cpu.h"
+#include "debugflag.h"
 #include "fname.h"
 #include "print.h"
+#include "segnames.h"
 #include "target.h"
 #include "tgttrans.h"
 #include "version.h"
@@ -53,7 +56,6 @@
 #include "asmcode.h"
 #include "compile.h"
 #include "codeopt.h"
-#include "cpu.h"
 #include "error.h"
 #include "global.h"
 #include "incpath.h"
@@ -208,8 +210,12 @@ static void SetSys (const char* Sys)
             DefineNumericMacro ("__ATMOS__", 1);
             break;
 
+        case TGT_NES:
+            DefineNumericMacro ("__NES__", 1);
+            break;
+
        default:
-                   AbEnd ("Unknown target system type");
+                   AbEnd ("Unknown target system type %d", Target);
     }
 
     /* Initialize the translation tables for the target system */
@@ -376,11 +382,8 @@ static void OptCreateDep (const char* Opt attribute ((unused)),
 static void OptCPU (const char* Opt, const char* Arg)
 /* Handle the --cpu option */
 {
-    if (strcmp (Arg, "6502") == 0) {
-               CPU = CPU_6502;
-    } else if (strcmp (Arg, "65C02") == 0) {
-       CPU = CPU_65C02;
-    } else {
+    CPU = FindCPU (Arg);
+    if (CPU != CPU_6502 && CPU != CPU_65C02) {
                AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
     }
 }
@@ -400,10 +403,10 @@ static void OptDataName (const char* Opt attribute ((unused)), const char* Arg)
 
 
 static void OptDebug (const char* Opt attribute ((unused)),
-                     const char* Arg attribute ((unused)))
+                     const char* Arg attribute ((unused)))
 /* Compiler debug mode */
 {
-    Debug = 1;
+    ++Debug;
 }
 
 
@@ -793,23 +796,23 @@ int main (int argc, char* argv[])
        OutputFile = MakeFilename (InputFile, ".s");
     }
 
+    /* If no CPU given, use the default CPU for the target */
+    if (CPU == CPU_UNKNOWN) {
+        if (Target != TGT_UNKNOWN) {
+            CPU = DefaultCPU[Target];
+        } else {
+            CPU = CPU_6502;
+        }
+    }
+
     /* Go! */
     Compile (InputFile);
 
     /* Create the output file if we didn't had any errors */
     if (ErrorCount == 0 || Debug) {
 
-       FILE* F;
-
-#if 0
-       /* Optimize the output if requested */
-       if (Optimize) {
-           OptDoOpt ();
-       }
-#endif
-
        /* Open the file */
-       F = fopen (OutputFile, "w");
+       FILE* F = fopen (OutputFile, "w");
        if (F == 0) {
            Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno));
        }