From adc5525e852ec61ea28eeaac66b47ad20e12b233 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Thu, 25 Sep 2014 18:47:23 +0200 Subject: [PATCH] added commandline option to quit after X cycles --- src/sim65/main.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/sim65/main.c b/src/sim65/main.c index 3ed273bf8..10dbe3f91 100644 --- a/src/sim65/main.c +++ b/src/sim65/main.c @@ -60,7 +60,8 @@ /* Name of program file */ const char* ProgramFile; - +/* exit simulator after MaxCycles Cycles */ +unsigned long MaxCycles = 0; /*****************************************************************************/ /* Code */ @@ -75,6 +76,7 @@ static void Usage (void) " -h\t\t\tHelp (this text)\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" @@ -111,7 +113,12 @@ static void OptVersion (const char* Opt attribute ((unused)), fprintf (stderr, "sim65 V%s\n", GetVersionAsString ()); } - +static void OptQuitXIns (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* quit after MaxCycles cycles */ +{ + MaxCycles = strtoul(Arg, NULL, 0); +} static void ReadProgramFile (void) /* Load program into memory */ @@ -197,6 +204,10 @@ int main (int argc, char* argv[]) OptVersion (Arg, 0); break; + case 'x': + OptQuitXIns (Arg, GetArg (&I, 2)); + break; + default: UnknownOption (Arg); break; @@ -225,6 +236,10 @@ int main (int argc, char* argv[]) while (1) { ExecuteInsn (); + if (MaxCycles && (GetCycles () >= MaxCycles)) { + Error ("Maximum number of cycles reached."); + exit (EXIT_FAILURE); + } } /* Return an apropriate exit code */ -- 2.39.5