tags:

views:

581

answers:

6

Hello, I want to take an interest in writing my own simple emulator for the z80 processor. I have no experience with this type of programming. I am mostly fine with using c-based languages as they are the ones I know best. If anyone could please tell me what I need to accomplish this and give me some good tutorials/references that could aid me in this project I would be very thankful. I would also like a tutorial for coding a ROM-dumping application for my ti-84 calculator so I can use its ROM with this emulator. Thanks in advance for any help!

+9  A: 

Perhaps start by looking at these:

A good tutorial can be found here: Independent Z80 Assembly Guide

Z80 DOCUMENTATION

The Undocumented Z80 Documented v0.91 (pdf)

The Complete Z80 Instruction Reference

Z80 Microprocessor Instruction Set Summary

Mitch Wheat
This is a great start. Thanks for the help. I'll get started reading it.
Bobice M.
+3  A: 

Mitch is completely correct. Start by understanding the processor. Then play around a bit by writing code to implement particular instructions. Use C++ for this, BTW, not C, or the concepts of the processor will not map to classes in your code.

In the process of implementing instructions, you'll find you need to define things like the flags, and the instruction pointer. That should eventually get you to where you need to implement the memory model, and even the I/O model.

You'll eventually have to figure out how to load code and data into memory, and maybe how to dump it back out to disk.

Only then do you need to get to the point of emulating the execution of code, loaded into memory, at a given instruction pointer.

Good luck. It would be interesting to look at. I wrote the dispatch logic for one of these back in 1976. Mine was better than yours will ever be, I guarantee it.

(ok, maybe hackier, rather than better)

John Saunders
I want to say thanks for your advice as well.
Bobice M.
+10  A: 

It's a bit of a side trip, but since you say you have no experience with this type of programming, you might want to start by building an emulator for the Universal Virtual Machine from the 2006 ICFP programming contest. This is a task that takes an experienced programmer 90 minutes, but many teams with no experience were able to complete it in a few days. When you finish the emulator it unlocks a bunch of fun stuff, and it might be a good warmup before you tackle the Z80.

Norman Ramsey
+1 Thanks for the contest link.
AraK
+1 for the contest link!
Dan
+2  A: 

You seem to want an emulator for more than a processor, but for a complete machine. You'll have also the task of emulating the rest of the hardware, and finding the documentation for that could well be the more difficult task waiting you.

Depending on your goal, you may want to start with an already existing emulator for Z80. A quick search gives several of them but no emulator for TI-84. simh, a framework for old computers emulation has already the emulation of a Z80 processor, adding emulation of the rest of your hardware should be easier than starting from scratch. Even if you don't go that road, there are some design documents there which could help you.

AProgrammer
+2  A: 

I'd recommend you consider starting by writing an emulator for a slightly simpler but releated CPU, the 8080. The Z80 is actually rather complicated (multi-byte instructions, more addressing modes, index registers etc.) , whereas 8080 instructions are very easy to decode (you can just use a 256-entry lookup table , as a first order solution).

All the code you write to control the program (display, data entry, memory dumps etc.) should be re-useable if you then decide to go on to attempt the Z80, and indeed you should design the user interface to be simulated processor independant.

anon
I disagree about the decoding. Z80 instructions are easily decoded, breaking them into {2, 3, 3} bit fields. I've done it.
John Saunders
The Z80 has both single byte and two-byte opcodes (excluding eddress info). The 8080 (which only has single byte opcodes) are thus inately easier to decode. Also, the number of addressing modes you need to deal with is smaller on the 8080. Thus, writing an 8080 emulator is easier. I've written both, BTW.
anon
+2  A: 

Try to take a look to Sega Master System and Game Gear emulators (i'm pretty sure that some are open source), those consoles have a z80 as CPU ZX Spectrum used it too, http://www.worldofspectrum.org/emulators.html

tr3