Skip to content

Commit

Permalink
Add swatch command to debugger.
Browse files Browse the repository at this point in the history
  • Loading branch information
komadori committed Jan 3, 2024
1 parent 12d7ba4 commit 538e6a3
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/6502.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ int output = 0;
static int timetolive = 0;

int cycles;
uint64_t stopwatch;
static int otherstuffcount = 0;
int romsel;

Expand All @@ -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) {
Expand Down Expand Up @@ -1032,6 +1034,7 @@ void m6502_reset(void)
nmi = oldnmi = 0;
output = 0;
tubecycle = tubecycles = 0;
stopwatch = 0;
log_debug("PC : %04X\n", pc);
}

Expand Down
2 changes: 1 addition & 1 deletion src/6502.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

extern uint8_t a,x,y,s;
extern uint16_t pc;
extern uint_least32_t cycles_6502;

extern PREG p;

Expand All @@ -23,6 +22,7 @@ extern int interrupt;
*/
extern int nmi;

extern uint64_t stopwatch;
extern int romsel;
extern uint8_t ram1k, ram4k, ram8k;

Expand Down
44 changes: 44 additions & 0 deletions src/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -394,6 +397,9 @@ void debug_reset()
fprintf(trace_fp, "Processor reset at %s\n", when);
fflush(trace_fp);
}
for (int i=0; i<user_stopwatch_count; i++) {
user_stopwatches[i] = ~0;
}
}

static const char helptext[] =
Expand Down Expand Up @@ -429,6 +435,7 @@ static const char helptext[] =
" ruler [s [c]] - draw a ruler to help with hexdumps.\n"
" starts at 's' for 'c' bytes\n"
" s [n] - step n instructions (or 1 if no parameter)\n"
" swatch [n] - start/clear/print stopwatches\n"
" symbol name=[rom:]addr\n"
" - add debugger symbol\n"
" symlist - list all symbols\n"
Expand Down Expand Up @@ -765,6 +772,41 @@ static void debugger_save(cpu_debug_t *cpu, char *iptr)
debug_outf("Nothing to save (no breakpoints)\n");
}

static void debugger_stopwatch(cpu_debug_t *cpu, const char* iptr)
{
if (*iptr) {
int user = atoi(iptr);
if (user >= 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<user_stopwatch_count; i++) {
if (user_stopwatches[i] < ~0) {
uint64_t delta = stopwatch - user_stopwatches[i];
debug_outf("%" PRIu64 " cycles since user stopwatch %d (%.3f s)\n",
delta, i, (double)delta / 2000000.0);
}
}
}
}

void trimnl(char *buf) {
int len = strlen(buf);

Expand Down Expand Up @@ -1516,6 +1558,8 @@ void debugger_do(cpu_debug_t *cpu, uint32_t addr)
else
debug_outf("Missing filename\n");
}
else if (!strncmp(cmd, "swatch", cmdlen))
debugger_stopwatch(cpu, iptr);
else
badcmd = true;
break;
Expand Down
11 changes: 9 additions & 2 deletions src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "b-em.h"

#include "config.h"
#include "6502.h"
#include "mem.h"
#include "model.h"
#include "serial.h"
Expand Down Expand Up @@ -41,10 +42,13 @@ static enum {
CRTC_LOFREQ
} crtc_mode;

uint64_t stopwatch_vblank;

void crtc_reset()
{
hc = vc = sc = vadj = 0;
crtc[9] = 10;
stopwatch_vblank = 0;
}

static void set_intern_dtype(enum vid_disptype dtype)
Expand Down Expand Up @@ -1123,8 +1127,9 @@ void video_poll(int clocks, int timer_enable)
}
if (hvblcount) {
hvblcount--;
if (!hvblcount && timer_enable)
if (!hvblcount && timer_enable) {
sysvia_set_ca1(0);
}
}

if (interline && hc == (crtc[0] >> 1)) {
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 538e6a3

Please sign in to comment.