From 97b517a8923e028ba06b4aab3e98aa2fd8d627f1 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 5 Jul 2016 17:07:39 +0200 Subject: [PATCH] sim65: add command line parameter to print number of CPU cycles at exit --- doc/sim65.sgml | 11 ++++++++++- src/sim65/6502.c | 2 ++ src/sim65/6502.h | 2 ++ src/sim65/main.c | 18 +++++++++++++++++- src/sim65/paravirt.c | 3 +++ 5 files changed, 34 insertions(+), 2 deletions(-) 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 <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. 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 <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; diff --git a/src/sim65/paravirt.c b/src/sim65/paravirt.c index 56211b5c1..f4fc3e285 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); } -- 2.39.5