From: mrdudz Date: Thu, 25 Sep 2014 16:47:23 +0000 (+0200) Subject: added commandline option to quit after X cycles X-Git-Tag: V2.15~31^2~13 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=adc5525e852ec61ea28eeaac66b47ad20e12b233;p=cc65 added commandline option to quit after X cycles --- 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 */