Writing emulators [Was: Re: VCF PNW 2018: Pictures!]

Sean Conner spc at conman.org
Tue Feb 20 19:18:09 CST 2018

It was thus said that the Great Eric Christopherson via cctalk once stated:
> On Tue, Feb 20, 2018 at 5:30 PM, dwight via cctalk <cctalk at classiccmp.org>
> wrote:
> > In order to connect to the outside world, you need a way to queue event
> > based on cycle counts, execution of particular address or particular
> > instructions. This allows you to connect to the outside world. Other than
> > that it is just looking up instructions in an instruction table.
> >
> > Dwight
> >
> What I've always wondered about was how the heck cycle-accurate emulation
> is done. In the past I've always felt overwhelmed looking in the sources of
> emulators like that to see how they do it, but maybe it's time I tried
> again.

  It depends upon how cycle accurate you want.  My own MC6809 emulator [1]
keeps track of cycles on a per-instruction basis, so it's easy to figure out
how many cycles have passed.  Hardware emulation can be done between
instructions by updating per the number of cycles passed (if required).  I
don't have the code for the MC6840 (a timer chip) in my MC6809 emulator
repository (it's still somewhat under construction) but I do update the
timer based upon the elapsed cycle count of the previous instruction [2].

  -spc (Code available upon request if you want to look at it)

[1]	https://github.com/spc476/mc6809

[2]	It's not emulating any existing machine.  Rather, I'm emulating a
	system with a few serial ports (MC6850) and a few timer chips
	(MC6840).  I have plans on adding a few floppy controllers (MC6843)
	and a DMA chip (6844).

More information about the cctalk mailing list