diff --git a/doc/sim65.sgml b/doc/sim65.sgml
index 24b43831c..a2ebbac25 100644
--- a/doc/sim65.sgml
+++ b/doc/sim65.sgml
@@ -4,7 +4,7 @@
sim65 Users Guide
-2016-01-05
+2016-07-05
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 Exit simulator after cycles
Long options:
--help Help (this text)
+ --cycles Print amount of executed CPU cycles
--verbose Increase verbosity
--version Print the simulator version number
@@ -53,6 +55,13 @@ Here is a description of all the command line options:
Print the short option summary shown above.
+ -c, --cycles
+
+ Print the number of executed CPU cycles when the program terminates.
+ The cycles for the final "jmp exit" are not included in this
+ count.
+
+
-v, --verbose
Increase the simulator verbosity.
diff --git a/src/sim65/6502.c b/src/sim65/6502.c
index 312eb2fe1..e6f358295 100644
--- a/src/sim65/6502.c
+++ b/src/sim65/6502.c
@@ -67,6 +67,8 @@ static unsigned HaveNMIRequest;
/* IRQ request active */
static unsigned HaveIRQRequest;
+/* flag to print cycles at program termination */
+int PrintCycles;
/*****************************************************************************/
diff --git a/src/sim65/6502.h b/src/sim65/6502.h
index 2cf2d4f1e..f8e894567 100644
--- a/src/sim65/6502.h
+++ b/src/sim65/6502.h
@@ -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 */
diff --git a/src/sim65/main.c b/src/sim65/main.c
index dab9b0be8..5405af29f 100644
--- a/src/sim65/main.c
+++ b/src/sim65/main.c
@@ -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 \t\tExit simulator after 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;
diff --git a/src/sim65/paravirt.c b/src/sim65/paravirt.c
index 56211b5c1..a13c670a2 100644
--- a/src/sim65/paravirt.c
+++ b/src/sim65/paravirt.c
@@ -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);
}