View Full Version : here is an 8080 emulator core

Mike Chambers
May 25th, 2007, 01:14 AM
i put the 8086 project on hold for a little bit, while i tried something a bit easier first. i spent some time writing an intel 8080 emulation core for VB6. :)

i'm going to use it to emulate some sort of 8080-based computer, possibly an altair 8800. i'll post the core module tomorrow after a test a few things out in case anybody else wants to mess with it.

May 25th, 2007, 04:39 PM
I'll be curious to see how it compares to our 8085 project. The 8080, being the predecessor processor, only lacks a few instrucions of the 8085. I'm interested to see what you've come up with...

Mike Chambers
May 25th, 2007, 05:52 PM
here you go, swedaguy. i've attached a ZIP which extracts to a 37 KB core8080.bas file. just stick it into a VB6 project as a module, load a binary into the proper location in the RAM array. set the PC and other registers accordingly, of course. and just as a note, the Reset8080 sub will reset ALL registers and flags to zero if called.

the Exec8080 sub will execute the current instruction pointer specified by PC. i think its a little buggy right now, but i ran a few .BIN files and they don't seem to crash. i'll need to do a lot more testing on this thing.

June 19th, 2007, 07:59 AM
Hello there, Mike...

I finally got a chance to do a good read of your code. I haven't worked in BASIC for a long time, so I had to do some thinking and remembering while reading...

We've taken a slightly different approach, in that we were able to condense the case structure a bit by doing some bit manipulation. We read in the upper two bits (7 & 6) and interpret their pattern, either 00, 01, 10 or 11. Based on that, we can branch to 4 different routines. Of course if you do the binary math, you can see that:

00 = Instructions 00h -> 3Fh
01 = Instructions 40h -> 7Fh
10 = Instructions 80h -> BFh
11 = Instructions C0h -> FFh

Now the "01" instructions are easy. You have to trap for 76h, which is HLT, otherwise all of the instructions in this range are moves. Read bits 2, 1 & 0 to determine the source and read bits 5, 4 & 3 to determine the destination. There is a table in the 8080 reference book that tells you which bit patterns represent which registers.

The "10" instructions are almost as easy. These are the Math and Logic instructions ADD, ADC, SUB, SBB, ANA, XRA, ORA & CMP. In this range, bits 2, 1 & 0 are still the source (remember, the Accumulator is always the destination) but bits 5, 4 & 3 represent the type of operation. I don't think it's detailed in the Intel book, so:

ADD = 000
ADC = 001
SUB = 010
SBB = 011
ANA = 100
XRA = 101
ORA = 110
CMP = 111


Now, the "00" and "11" functions are more difficult to parse out.

The "00" instructions do have (to a degree) the destination bits encoded just like the "01" instructions. You have to keep straight, however, which operations work on one byte (ex., DCR) and which operations work on two bytes (ex., DCX). This can be determined (to a degree) by reading bits 2, 1 & 0.

The "11" instructions have some similar encoding. For example, all RST instructions have the same bit pattern in 2, 1 & 0, and the restart vector number (0 - 7) is encoded in bits 5, 4 & 3. This range of instructions is fairly complicated as well and I think we ended up using a case construct for simplicity sake.

If you want, I can elaborate more on the "00" and "11" range patterns, but I'll have get my notes in front of me.

Best of luck on your project!

Mike Chambers
June 21st, 2007, 08:50 PM
thats an intelligent way of doing it. what i think i'm going to do when i get the motivation, is try to emulate the old S-100 Dazzler card and turn this into an Altair 8800 emulator. :D

should be a fun project.

June 25th, 2007, 09:01 AM
We, too, are emulating a specific hardware configuration, not just simulating a processor. That said, we're incorporating specific I/O handling and timing requirements, and actually running 3 concurrent 8085 sessions.

I was impressed with how you handled issues that I didn't think had a very clear solution in BASIC. Actually, I spent some time this weekend figuring out if I could modify the code to run under DG's Business BASIC. It would take a lot of modification, as BB doesn't do procedures as such, and it is still a line-number oriented interpreter. But, if I get the ambition, I just might try it...

June 25th, 2007, 04:28 PM
thats an intelligent way of doing it. what i think i'm going to do when i get the motivation, is try to emulate the old S-100 Dazzler card and turn this into an Altair 8800 emulator. :D

should be a fun project.

If you haven't already, take a look at my Altair32 Emulator project. Granted, it's written in C, but you can readily see the rendering and joystick logic in the Dazzler module.