<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Wed, 25 Feb 2004 12:33:07 GMT 
From   : "Thomas Harte " <thomasharte@...>
Subject: Re: Draft protocal for externally emulated hardware

--=_NextPart_Lycos_0063541077712387_ID

Coming into this a little late, I think it is interesting to explain how
ElectrEm (ElectrEm Future onwards, 
anyway) does things, as it pretty much allows any 6502 plugin to be written.
Its all C++ based, so I don't expect 
it is suitable for all.

Every component (my term for 6502 attachments) has a number of function calls.
These are:

Attach
Detach
Update
Write
Read

Attach and Detach are pretty obvious. They are called when the component
is attached or detached from the 
6502. At that time they declare any registers they provide. In future, if
a memory access occurs to any 
address declared as a register, the Read or Write function is called. Those
functions get a timestamp, an 
address and a data value (which in ElectrEm means both an 8bit and a 32bit
data value, as ElectrEm does 'bit 
multiplexing' - the common technology I have still yet to learn a decent
name for).

The Update function is the really interesting one. It is called with the
number of cycles to run for and a flag 
indicating whether the emulator is lagging behind realtime speed or not.
This flag is of interest mostly to the 
ULA screen output component, which can decide to skip frames if things are
tight, and is also factored in by 
the sound outputter, but is not conclusive there.

At the end of the period passed to Update is the only time at which CPU control
lines such as reset, interrupt or 
NMI may be adjusted. To make this all work irrespective of the hardware,
Update has a return result. That 
result is the number of cycles for which the device can be certain it won't
want to adjust any of these lines. 
The emulator ensures that the component will get a chance to make any required
changes at the end of that 
time, although the next step may not necessarily be as long as the period
returned, and may actually be zero.

There is a specially defined value 'CYCLENO_ANY' which means that the component
will not be adjusting the CPU 
control lines in the foreseeable future.

There is also the possibility to force an early break. If a register write
or read (through the Read and Write 
functions) has the effect that the old time returned is no longer accurate,
a component can return a message 
to that effect, and it will get an Update call to the current cycle in order
for the emulation proper to learn the 
new value.

Of course, to this end for perfectly accurate emulation, every component
must be able to break at any cycle 
count. This is achieved in ElectrEm. Even the 6502, which fully emulates
every memory read and write of the 
6502 (the 6502 reads or writes every single cycle, regardless of whether
it really needs to - very important to 
grasp this if your CPUs clock rate is dependant on memory access as in the
Electron) and can break at any 
cycle, mid-operation or not. You can thank your modern multithreaded operating
systems and hardware for 
that system being at all workable.

In order to achieve full hardware emulation accuracy, and now completely
off the point of the thread proper, 
the ElectrEm 6502 is actually an enhanced device with a memory mapper and
a parallel DMA engine. The memory 
mapper is just enough for ROM and JIM paging, and Slogger Master RAM Board
emulation (which secretly pages 
according to PC location), and the DMA just enough for cycle perfect video
memory collection.

ElectrEm Future is actually cycle perfect in all documented respects, although
the tape emulation and exact 
interrupt timing remains a best guess based on testing against available
software as either Acorn never saw fit 
to document those devices, or else I've simply not found the documentation.
And I'm not really good enough 
with hardware to determine these things for myself.

-Thomas

SIZE does matter - The UK's biggest *Free* Web based mail - 10 MB Free 
mail.lycos.co.uk


--=_NextPart_Lycos_0063541077712387_ID--
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>