1
0
mirror of https://github.com/simh/simh.git synced 2026-01-11 23:52:58 +00:00

SCP: Make debug timestamps consistent when in NOCALIBRATE mode

This commit is contained in:
Mark Pizzolato 2024-04-04 09:56:18 -10:00
parent b6f02f3e0c
commit b404ccd050
5 changed files with 30 additions and 11 deletions

13
scp.c
View File

@ -668,7 +668,6 @@ size_t sim_deb_buffer_size = 0; /* debug memory buffer s
char *sim_deb_buffer = NULL; /* debug memory buffer */
size_t sim_debug_buffer_offset = 0; /* debug memory buffer insertion offset */
size_t sim_debug_buffer_inuse = 0; /* debug memory buffer inuse count */
struct timespec sim_deb_basetime; /* debug timestamp relative base time */
char *sim_prompt = NULL; /* prompt string */
static FILE *sim_gotofile; /* the currently open do file */
static int32 sim_goto_line[MAX_DO_NEST_LVL+1]; /* the current line number in the currently open do file */
@ -3455,6 +3454,10 @@ if (cptr && *cptr) {
sim_exit_status = atoi (cptr);
r |= SCPE_NOMESSAGE; /* exit silently with the specified status */
}
if (sim_deb) { /* If debugging, then close debugging cleanly */
sim_switches |= SWMASK ('Q'); /* and quietly */
sim_set_deboff (0, NULL);
}
return r;
}
@ -14532,11 +14535,13 @@ static t_stat _sim_debug_flush (void)
int32 saved_quiet = sim_quiet;
int32 saved_sim_switches = sim_switches;
int32 saved_deb_switches = sim_deb_switches;
struct timespec saved_deb_basetime = sim_deb_basetime;
struct timespec saved_deb_basetime;
if (sim_deb == NULL) /* no debug? */
return SCPE_OK;
saved_deb_basetime = *sim_rtcn_get_debug_basetime ();
_sim_debug_write_flush ("", 0, TRUE);
if (sim_deb == sim_log) { /* debug is log */
@ -14553,7 +14558,7 @@ if ((saved_deb_switches & SWMASK ('B')) != 0) {
sim_set_deboff (0, NULL);
sim_switches = saved_deb_switches;
sim_set_debon (0, saved_debug_filename);
sim_deb_basetime = saved_deb_basetime;
sim_rtcn_set_debug_basetime (&saved_deb_basetime);
sim_switches = saved_sim_switches;
sim_quiet = saved_quiet;
}
@ -14600,7 +14605,7 @@ struct timespec time_now;
if (sim_deb_switches & (SWMASK ('T') | SWMASK ('R') | SWMASK ('A'))) {
sim_rtcn_debug_time(&time_now);
if (sim_deb_switches & SWMASK ('R'))
sim_timespec_diff (&time_now, &time_now, &sim_deb_basetime);
sim_timespec_diff (&time_now, &time_now, sim_rtcn_get_debug_basetime ());
if (sim_deb_switches & SWMASK ('T')) {
time_t tnow = (time_t)time_now.tv_sec;
struct tm *now = localtime(&tnow);

1
scp.h
View File

@ -326,7 +326,6 @@ extern size_t sim_deb_buffer_size; /* debug memory buffer s
extern char *sim_deb_buffer; /* debug memory buffer */
extern size_t sim_debug_buffer_offset; /* debug memory buffer insertion offset */
extern size_t sim_debug_buffer_inuse; /* debug memory buffer inuse count */
extern struct timespec sim_deb_basetime; /* debug base time for relative time output */
extern DEVICE **sim_internal_devices;
extern uint32 sim_internal_device_count;
extern UNIT *sim_clock_queue;

View File

@ -2369,13 +2369,15 @@ sim_set_deb_switches (sim_switches);
if (sim_deb_switches & SWMASK ('R')) {
struct tm loc_tm, gmt_tm;
time_t time_t_now;
struct timespec basetime;
sim_rtcn_get_time(&sim_deb_basetime, 0);
time_t_now = (time_t)sim_deb_basetime.tv_sec;
sim_rtcn_get_time(&basetime, 0);
time_t_now = (time_t)basetime.tv_sec;
/* Adjust the relative timebase to reflect the localtime GMT offset */
loc_tm = *localtime (&time_t_now);
gmt_tm = *gmtime (&time_t_now);
sim_deb_basetime.tv_sec -= mktime (&gmt_tm) - mktime (&loc_tm);
basetime.tv_sec -= mktime (&gmt_tm) - mktime (&loc_tm);
sim_rtcn_set_debug_basetime (&basetime);
if (!(sim_deb_switches & (SWMASK ('A') | SWMASK ('T'))))
sim_deb_switches |= SWMASK ('T');
}

View File

@ -721,7 +721,7 @@ return SCPE_OK;
/* diff = min - sub */
void
sim_timespec_diff (struct timespec *diff, struct timespec *min, struct timespec *sub)
sim_timespec_diff (struct timespec *diff, struct timespec *min, const struct timespec *sub)
{
/* move the minuend value to the difference and operate there. */
*diff = *min;
@ -1524,6 +1524,7 @@ if (arg != 0) { /* Enabling Calibration? */
return sim_messagef (SCPE_ARG, "Invalid calibration idle percentage: %s\n", gbuf);
}
}
/* Disabling Calibration */
if (!sim_timer_calib_enabled)
return sim_messagef (SCPE_OK, "calibration already disabled running at %s %s per pseudo second\n",
@ -2350,6 +2351,16 @@ t_stat sim_timer_stop_svc (UNIT *uptr)
return SCPE_STOP;
}
void sim_rtcn_set_debug_basetime (const struct timespec *basetime)
{
sim_timer_uncalib_base_time = *basetime;
}
const struct timespec *sim_rtcn_get_debug_basetime (void)
{
return &sim_timer_uncalib_base_time;
}
void sim_rtcn_debug_time (struct timespec *now)
{
if (sim_timer_calib_enabled)

View File

@ -102,11 +102,13 @@ int clock_gettime(int clock_id, struct timespec *tp);
#define TIMER_DBG_MUX 0x004 /* Debug Flag for Asynch Queue Debugging */
t_bool sim_timer_init (void);
void sim_timespec_diff (struct timespec *diff, struct timespec *min, struct timespec *sub);
void sim_timespec_diff (struct timespec *diff, struct timespec *min, const struct timespec *sub);
double sim_timenow_double (void);
int32 sim_rtcn_init (int32 time, int32 tmr);
int32 sim_rtcn_init_unit (UNIT *uptr, int32 time, int32 tmr);
int32 sim_rtcn_init_unit_ticks (UNIT *uptr, int32 time, int32 tmr, int32 ticksper);
void sim_rtcn_set_debug_basetime (const struct timespec *basetime);
const struct timespec *sim_rtcn_get_debug_basetime (void);
void sim_rtcn_debug_time (struct timespec *now);
void sim_rtcn_get_time (struct timespec *now, int tmr);
time_t sim_get_time (time_t *now);