5667Re: creating a cosmacelf simulator in C
- Oct 3, 2008I just uploaded the source code to my Elf emulator in the
Files/Simulators folder (TedsElf.zip). It is in C++ but should give
you some hints on how to proceed. The source is for a Visual Studio
project. The real meat is in 1802.cpp and 1802.h. You can find
programs that will run and instuctions on my web site:
One problem with many of the 1802 emulators that I tried is that
they are not coded up for real-time operation. They tend to run as
fast as they can which tends to be much faster than the real machine
and varies based on processor speed. I use Windows timers to step
my emulator at a periodic rate (I think every 50ms) for a tunable
number of steps. This keeps the simulator speed constant across
multiple machines. I don't have it perfectly tuned up but it does
run within 10% of my real Elf system.
The point I'm trying to make is to not make your emulator a giant
while loop but instead write it such that it is a subroutine that
maintains the state of the machine so that it can be called once per
unit of activity. For example, you could model all the machine
states and call the subroutine once per clock cycle. I choose to do
it once per instruction but I maintain state as to the number of
machine cycles executed (2 or 3 per instruction). Machine cycles
are 8 clock cycles.
This also allows you to hook up devices to your emulator such as
LEDs, keyboards or 1861 video chips.
Good luck and have fun. I enjoyed the process and am now able to
develope code for my 1.6 MHz Elf on a 3.0 GHz PC.
--- In firstname.lastname@example.org, akshay parelkar <va7aax@...> wrote:
> Hi Fans of Cosmac Elfs,
> I recently discovered this fancy little computer while searchig on
the web. I dont have a Real Cosmac Elf yet(Have digital ones
> Lately, I have been thinking about writing up my own code (in C)
to simulate the Cosmac elf. I dont expect this project to compete
with the ones already available, just something with which I can
undertand more about the 1802 itself and improve and exercise my own
(rather limited) knowledge of C.
> Can somebody give some suggestions as to how and where I
> Also, another idea rolling in my mind is, Would it be possible to
build a replica Cosmac Elf based on a PIC or has anyone already done
> Long live cosmac elfs!
> [Non-text portions of this message have been removed]
- << Previous post in topic Next post in topic >>