]> git.sur5r.net Git - cc65/commitdiff
Merge pull request #320 from groessler/something_to_pull
authorOliver Schmidt <ol.sc@web.de>
Wed, 6 Jul 2016 07:12:54 +0000 (09:12 +0200)
committerGitHub <noreply@github.com>
Wed, 6 Jul 2016 07:12:54 +0000 (09:12 +0200)
sim65: add command line parameter to print number of CPU cycles at exit

doc/sim65.sgml
src/sim65/6502.c
src/sim65/6502.h
src/sim65/main.c
src/sim65/paravirt.c

index 24b43831c4520a4ca761461cfd54b8fac7b5b95a..a2ebbac255db266652a5bfeee4c654853a59d07d 100644 (file)
@@ -4,7 +4,7 @@
 
 <title>sim65 Users Guide
 <author><url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal">
-<date>2016-01-05
+<date>2016-07-05
 
 <abstract>
 sim65 is a simulator for 6502 and 65C02 CPUs. It allows to test target
@@ -31,12 +31,14 @@ The simulator is called as follows:
        Usage: sim65 [options] file [arguments]
        Short options:
          -h                    Help (this text)
+         -c                    Print amount of executed CPU cycles
          -v                    Increase verbosity
          -V                    Print the simulator version number
          -x <num>              Exit simulator after <num> cycles
 
        Long options:
          --help                Help (this text)
+         --cycles              Print amount of executed CPU cycles
          --verbose             Increase verbosity
          --version             Print the simulator version number
 </verb></tscreen>
@@ -53,6 +55,13 @@ Here is a description of all the command line options:
   Print the short option summary shown above.
 
 
+  <tag><tt>-c, --cycles</tt></tag>
+
+  Print the number of executed CPU cycles when the program terminates.
+  The cycles for the final "<tt>jmp exit</tt>" are not included in this
+  count.
+
+
   <tag><tt>-v, --verbose</tt></tag>
 
   Increase the simulator verbosity.
index 312eb2fe1e3cf8d717ed06a8290c5b4d93bca851..e6f35829527a06f2d4aebd1c5bae2f1bb445e3ab 100644 (file)
@@ -67,6 +67,8 @@ static unsigned HaveNMIRequest;
 /* IRQ request active */
 static unsigned HaveIRQRequest;
 
+/* flag to print cycles at program termination */
+int PrintCycles;
 
 
 /*****************************************************************************/
index 2cf2d4f1ecd6e242f191f99a6f104ade9315d664..f8e894567aaa78e59f8797c65f937c136c126982 100644 (file)
@@ -99,6 +99,8 @@ unsigned ExecuteInsn (void);
 unsigned long GetCycles (void);
 /* Return the total number of clock cycles executed */
 
+extern int PrintCycles;
+/* flag to print cycles at program termination */
 
 
 /* End of 6502.h */
index dab9b0be8dda94255bd9b63aefd1c2420079c094..5405af29ff87f2293c3421f472c89ddd124bffd1 100644 (file)
@@ -61,7 +61,7 @@
 const char* ProgramFile;
 
 /* exit simulator after MaxCycles Cycles */
-unsigned long MaxCycles = 0;
+unsigned long MaxCycles;
 
 /*****************************************************************************/
 /*                                   Code                                    */
@@ -74,12 +74,14 @@ static void Usage (void)
     printf ("Usage: %s [options] file [arguments]\n"
             "Short options:\n"
             "  -h\t\t\tHelp (this text)\n"
+            "  -c\t\t\tPrint amount of executed CPU cycles\n"
             "  -v\t\t\tIncrease verbosity\n"
             "  -V\t\t\tPrint the simulator version number\n"
             "  -x <num>\t\tExit simulator after <num> cycles\n"
             "\n"
             "Long options:\n"
             "  --help\t\tHelp (this text)\n"
+            "  --cycles\t\tPrint amount of executed CPU cycles\n"
             "  --verbose\t\tIncrease verbosity\n"
             "  --version\t\tPrint the simulator version number\n",
             ProgName);
@@ -106,6 +108,15 @@ static void OptVerbose (const char* Opt attribute ((unused)),
 
 
 
+static void OptCycles (const char* Opt attribute ((unused)),
+                       const char* Arg attribute ((unused)))
+/* Set flag to print amount of cycles at the end */
+{
+    PrintCycles = 1;
+}
+
+
+
 static void OptVersion (const char* Opt attribute ((unused)),
                         const char* Arg attribute ((unused)))
 /* Print the simulator version */
@@ -166,6 +177,7 @@ int main (int argc, char* argv[])
     /* Program long options */
     static const LongOpt OptTab[] = {
         { "--help",             0,      OptHelp                 },
+        { "--cycles",           0,      OptCycles               },
         { "--verbose",          0,      OptVerbose              },
         { "--version",          0,      OptVersion              },
     };
@@ -196,6 +208,10 @@ int main (int argc, char* argv[])
                     OptHelp (Arg, 0);
                     break;
 
+                case 'c':
+                    OptCycles (Arg, 0);
+                    break;
+
                 case 'v':
                     OptVerbose (Arg, 0);
                     break;
index 56211b5c17558d57e56d3132cd7b9f2c483ffb8d..a13c670a26fb69bbf4bdfedfa208d650d7e6dc1c 100644 (file)
@@ -156,6 +156,9 @@ static void PVArgs (CPURegs* Regs)
 static void PVExit (CPURegs* Regs)
 {
     Print (stderr, 1, "PVExit ($%02X)\n", Regs->AC);
+    if (PrintCycles) {
+        Print (stdout, 0, "%lu cycles\n", GetCycles ());
+    }
 
     exit (Regs->AC);
 }