Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCP: Adjust timer calibrations if SET THROTTLE x/t type is enabled #336

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions sim_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ static void _rtcn_configure_calibrated_clock (int32 newtmr);
static t_bool _sim_coschedule_cancel (UNIT *uptr);
static t_bool _sim_wallclock_cancel (UNIT *uptr);
static t_bool _sim_wallclock_is_active (UNIT *uptr);
static void _sim_timer_adjust_cal(void);
t_stat sim_timer_show_idle_mode (FILE* st, UNIT* uptr, int32 val, CONST void * desc);


Expand Down Expand Up @@ -1753,9 +1754,10 @@ else {
sim_throt_wait = sim_throt_val;
}
}
if (sim_throt_type == SIM_THROT_SPC) /* Set initial value while correct one is determined */
if (sim_throt_type == SIM_THROT_SPC) { /* Set initial value while correct one is determined */
sim_throt_cps = (int32)((1000.0 * sim_throt_val) / (double)sim_throt_sleep_time);
else
_sim_timer_adjust_cal(); /* adjust timer calibrations */
} else
sim_throt_cps = sim_precalibrate_ips;
return SCPE_OK;
}
Expand Down Expand Up @@ -1960,21 +1962,7 @@ switch (sim_throt_state) {
sim_debug (DBG_THR, &sim_timer_dev, "sim_throt_svc() Throttle values a_cps = %f, d_cps = %f, wait = %d, sleep = %d ms\n",
a_cps, d_cps, sim_throt_wait, sim_throt_sleep_time);
sim_throt_cps = d_cps; /* save the desired rate */
/* Run through all timers and adjust the calibration for each */
/* one that is running to reflect the throttle rate */
for (tmr=0; tmr<=SIM_NTIMERS; tmr++) {
rtc = &rtcs[tmr];
if (rtc->hz) { /* running? */
rtc->currd = (int32)(sim_throt_cps / rtc->hz);/* use throttle calibration */
rtc->ticks = rtc->hz - 1; /* force clock calibration on next tick */
rtc->rtime = sim_throt_ms_start - 1000 + 1000/rtc->hz;/* adjust calibration parameters to reflect throttled rate */
rtc->gtime = sim_throt_inst_start - sim_throt_cps + sim_throt_cps/rtc->hz;
rtc->nxintv = 1000;
rtc->based = rtc->currd;
if (rtc->clock_unit)
sim_activate_abs (rtc->clock_unit, rtc->currd);/* reschedule next tick */
}
}
_sim_timer_adjust_cal(); /* adjust timer calibrations */
}
break;

Expand Down Expand Up @@ -2038,6 +2026,30 @@ sim_activate (uptr, sim_throt_wait); /* reschedule */
return SCPE_OK;
}

/* Run through all timers and adjust the calibration for each */
/* one that is running to reflect the throttle rate */
static void _sim_timer_adjust_cal(void)
{
int32 tmr;
RTC *rtc = NULL;

for (tmr=0; tmr<=SIM_NTIMERS; tmr++) {
rtc = &rtcs[tmr];

if (rtc->hz) { /* running? */
rtc->currd = (int32)(sim_throt_cps / rtc->hz);/* use throttle calibration */
rtc->ticks = rtc->hz - 1; /* force clock calibration on next tick */
rtc->rtime = sim_throt_ms_start - 1000 + 1000/rtc->hz;/* adjust calibration parameters to reflect throttled rate */
rtc->gtime = sim_throt_inst_start - sim_throt_cps + sim_throt_cps/rtc->hz;
rtc->nxintv = 1000;
rtc->based = rtc->currd;

if (rtc->clock_unit)
sim_activate_abs (rtc->clock_unit, rtc->currd);/* reschedule next tick */
}
}
}

/* Clock assist activites */
t_stat sim_timer_tick_svc (UNIT *uptr)
{
Expand Down