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

@ -17,8 +17,8 @@ typedef struct mda_t
uint8_t ctrl, stat;
int dispontime, dispofftime;
int vidtime;
uint64_t dispontime, dispofftime;
pc_timer_t timer;
int firstline, lastline;
@ -96,8 +96,8 @@ void mda_recalctimings(mda_t *mda)
_dispofftime = disptime - _dispontime;
_dispontime *= MDACONST;
_dispofftime *= MDACONST;
mda->dispontime = (int)(_dispontime * (1 << TIMER_SHIFT));
mda->dispofftime = (int)(_dispofftime * (1 << TIMER_SHIFT));
mda->dispontime = (uint64_t)_dispontime;
mda->dispofftime = (uint64_t)_dispofftime;
}
void mda_poll(void *p)
@ -112,7 +112,7 @@ void mda_poll(void *p)
int blink;
if (!mda->linepos)
{
mda->vidtime += mda->dispofftime;
timer_advance_u64(&mda->timer, mda->dispofftime);
mda->stat |= 1;
mda->linepos = 1;
oldsc = mda->sc;
@ -166,7 +166,7 @@ void mda_poll(void *p)
}
else
{
mda->vidtime += mda->dispontime;
timer_advance_u64(&mda->timer, mda->dispontime);
if (mda->dispon) mda->stat&=~1;
mda->linepos=0;
if (mda->vsynctime)
@ -270,7 +270,7 @@ void *mda_init()
mda->vram = malloc(0x1000);
timer_add(mda_poll, &mda->vidtime, TIMER_ALWAYS_ENABLED, mda);
timer_add(&mda->timer, mda_poll, mda, 1);
mem_mapping_add(&mda->mapping, 0xb0000, 0x08000, mda_read, NULL, NULL, mda_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, mda);
io_sethandler(0x03b0, 0x0010, mda_in, NULL, NULL, mda_out, NULL, NULL, mda);