Rewrote timer code.

The new code is based on timestamps, rather than delays. This eliminates the
need to update every timer in timer_process(), which cost a non-trivial amount
of CPU time on low-end machines.

This involved changes to every user of the timer code, so this change almost
certainly introduces bugs.
This commit is contained in:
SarahW 2018-08-02 22:06:10 +01:00
commit a7d006b637
79 changed files with 1050 additions and 1033 deletions

View file

@ -106,54 +106,45 @@ void ym3812_timer_set_0(void *param, int timer, int64_t period)
{
opl_t *opl = (opl_t *)param;
opl->timers[0][timer] = period * TIMER_USEC * 20;
if (!opl->timers[0][timer]) opl->timers[0][timer] = 1;
opl->timers_enable[0][timer] = period ? 1 : 0;
if (period)
timer_set_delay_u64(&opl->timers[0][timer], period * TIMER_USEC * 20);
else
timer_disable(&opl->timers[0][timer]);
}
void ym3812_timer_set_1(void *param, int timer, int64_t period)
{
opl_t *opl = (opl_t *)param;
opl->timers[1][timer] = period * TIMER_USEC * 20;
if (!opl->timers[1][timer]) opl->timers[1][timer] = 1;
opl->timers_enable[1][timer] = period ? 1 : 0;
if (period)
timer_set_delay_u64(&opl->timers[1][timer], period * TIMER_USEC * 20);
else
timer_disable(&opl->timers[1][timer]);
}
void ymf262_timer_set(void *param, int timer, int64_t period)
{
opl_t *opl = (opl_t *)param;
opl->timers[0][timer] = period * TIMER_USEC * 20;
if (!opl->timers[0][timer]) opl->timers[0][timer] = 1;
opl->timers_enable[0][timer] = period ? 1 : 0;
if (period)
timer_set_delay_u64(&opl->timers[0][timer], period * TIMER_USEC * 20);
else
timer_disable(&opl->timers[0][timer]);
}
static void opl_timer_callback00(void *p)
{
opl_t *opl = (opl_t *)p;
opl->timers_enable[0][0] = 0;
opl_timer_over(0, 0);
}
static void opl_timer_callback01(void *p)
{
opl_t *opl = (opl_t *)p;
opl->timers_enable[0][1] = 0;
opl_timer_over(0, 1);
}
static void opl_timer_callback10(void *p)
{
opl_t *opl = (opl_t *)p;
opl->timers_enable[1][0] = 0;
opl_timer_over(1, 0);
}
static void opl_timer_callback11(void *p)
{
opl_t *opl = (opl_t *)p;
opl->timers_enable[1][1] = 0;
opl_timer_over(1, 1);
}
@ -161,16 +152,16 @@ void opl2_init(opl_t *opl)
{
opl_init(ym3812_timer_set_0, opl, 0, 0, 0);
opl_init(ym3812_timer_set_1, opl, 1, 0, 0);
timer_add(opl_timer_callback00, &opl->timers[0][0], &opl->timers_enable[0][0], (void *)opl);
timer_add(opl_timer_callback01, &opl->timers[0][1], &opl->timers_enable[0][1], (void *)opl);
timer_add(opl_timer_callback10, &opl->timers[1][0], &opl->timers_enable[1][0], (void *)opl);
timer_add(opl_timer_callback11, &opl->timers[1][1], &opl->timers_enable[1][1], (void *)opl);
timer_add(&opl->timers[0][0], opl_timer_callback00, (void *)opl, 0);
timer_add(&opl->timers[0][1], opl_timer_callback01, (void *)opl, 0);
timer_add(&opl->timers[1][0], opl_timer_callback10, (void *)opl, 0);
timer_add(&opl->timers[1][1], opl_timer_callback11, (void *)opl, 0);
}
void opl3_init(opl_t *opl, int opl_emu)
{
opl_init(ymf262_timer_set, opl, 0, 1, opl_emu);
timer_add(opl_timer_callback00, &opl->timers[0][0], &opl->timers_enable[0][0], (void *)opl);
timer_add(opl_timer_callback01, &opl->timers[0][1], &opl->timers_enable[0][1], (void *)opl);
timer_add(&opl->timers[0][0], opl_timer_callback00, (void *)opl, 0);
timer_add(&opl->timers[0][1], opl_timer_callback01, (void *)opl, 0);
}