diff --git a/src/6502.c b/src/6502.c index 7d50ed72..c971eb2a 100644 --- a/src/6502.c +++ b/src/6502.c @@ -226,6 +226,7 @@ int output = 0; static int timetolive = 0; int cycles; +uint64_t stopwatch; static int otherstuffcount = 0; int romsel; @@ -237,6 +238,7 @@ static void polltime(int c) video_poll(c, 1); sound_poll(c); music5000_poll(c); + stopwatch += c; otherstuffcount -= c; if (motoron) { if (fdc_time) { @@ -1032,6 +1034,7 @@ void m6502_reset(void) nmi = oldnmi = 0; output = 0; tubecycle = tubecycles = 0; + stopwatch = 0; log_debug("PC : %04X\n", pc); } diff --git a/src/6502.h b/src/6502.h index 5c94c1b5..2a4d890c 100644 --- a/src/6502.h +++ b/src/6502.h @@ -5,7 +5,6 @@ extern uint8_t a,x,y,s; extern uint16_t pc; -extern uint_least32_t cycles_6502; extern PREG p; @@ -23,6 +22,7 @@ extern int interrupt; */ extern int nmi; +extern uint64_t stopwatch; extern int romsel; extern uint8_t ram1k, ram4k, ram8k; diff --git a/src/debugger.c b/src/debugger.c index 0742e595..46a05c1b 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -75,6 +75,9 @@ static int contcount = 0; static const char time_fmt[] = "%d/%m/%Y %H:%M:%S"; +static uint64_t user_stopwatches[] = { ~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0 }; +static const int user_stopwatch_count = sizeof(user_stopwatches)/sizeof(*user_stopwatches); + static void close_trace(const char *why) { if (trace_fp) { @@ -394,6 +397,9 @@ void debug_reset() fprintf(trace_fp, "Processor reset at %s\n", when); fflush(trace_fp); } + for (int i=0; i= 0 && user < user_stopwatch_count) { + if (user_stopwatches[user] < ~0) { + user_stopwatches[user] = ~0; + debug_outf("User stopwatch %d cleared.\n", user); + } + else { + user_stopwatches[user] = stopwatch; + debug_outf("User stopwatch %d started.\n", user); + } + } + else { + debug_outf("User stopwatches IDs must be in the range 0 to %d.\n", + user_stopwatch_count-1); + } + } + else { + debug_outf("%" PRIu64 " cycles since reset (%.3f s)\n", stopwatch, (double)stopwatch / 2000000.0); + if (stopwatch_vblank) { + uint64_t delta = stopwatch - stopwatch_vblank; + debug_outf("%" PRIu64 " cycles since vertical blank (%.3f s)\n", delta, (double)delta / 2000000.0); + } + for (int i=0; i> 1)) { @@ -1237,8 +1242,10 @@ void video_poll(int clocks, int timer_enable) if (ccount == 10 || ((!motor || !fasttape) && !is_free_run())) ccount = 0; scry = 0; - if (timer_enable) + if (timer_enable) { + stopwatch_vblank = stopwatch; sysvia_set_ca1(1); + } vsynctime = (crtc[3] >> 4) + 1; if (!(crtc[3] >> 4)) diff --git a/src/video.h b/src/video.h index 3f772c1e..b919bb4d 100644 --- a/src/video.h +++ b/src/video.h @@ -17,6 +17,7 @@ extern int crtc_i; extern int hc, vc, sc; extern uint16_t ma; +extern uint64_t stopwatch_vblank; /*Video ULA (VIDPROC)*/ void videoula_write(uint16_t addr, uint8_t val);