473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to write a simple simulator

Was wondering how I could write a simple simulator
(assembler CPU Z80). Thanks for any advice, link.
Feb 23 '06 #1
1 4444
On Thu, 23 Feb 2006 14:58:24 GMT, Ciko <ci***@ciko.it> wrote in
comp.lang.c:
Was wondering how I could write a simple simulator
(assembler CPU Z80). Thanks for any advice, link.


While getting into the specific details of the Z80 would be off-topic
here, I can offer some basic ideas that do not go beyond the range of
standard C. In general, defining a simulator for a target processor
"smaller" than the computer that will execute the simulator is not too
difficult.

First, define structure types to represent the registers of the
processor. For the Z80 you would need three types, I would think.

One type for A and flags (two instances of these).

One type for BC, DE, HL (two instances of these).

One for the other registers, SP, PC, IX, IY.

I would use a pointer to each of the first two types to address the
contents, and swap the address in the pointer to appropriate instance
on exchange instructions.

As for the instruction simulation, all Z80 instructions start with a
single (8-bit) byte, so you can build either a switch table with 256
cases, or 256 pointers to functions. The functions/switches for the
bytes that are prefixes (0xed, 0xdd, 0xfd, isn't there one more?)
would each be processed using a secondary switch table or array of
function pointers.

Of course you need to have a 64K byte block of memory to serve as the
Z80 address space, and the value in your simulated PC register, and
all other values used as addresses, would actually be offsets into
this block.

The moderately tricky part would be updating the emulated flags after
each instruction. The really tricky part would be figuring out what
to do with access to I/O space. Emulating actual peripherals can be
quite complicated.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Feb 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alex Vinokur | last post by:
C++ Simulator of a Universal Turing Machine can be downloaded at : * http://alexvn.freeservers.com/s1/utm.html * http://sourceforge.net/projects/turing-machine/ The program simulates a...
61
by: /* frank */ | last post by:
I have to do a homework: make a CPU simulator using C language. I have a set of asm instructions so I have to write a program that should: - load .asm file - view .asm file - do a step by step...
0
by: SatishPasala | last post by:
Hi I am developing a Windows Mobile application. I want Visual Studio to use Palm Simulator to display the application. Now it is pointing to Default Simulator. I downloaded the Palm...
0
by: François | last post by:
Hi, My current job is to develop VoiceXML dialogs. The voice platform that we use provides neither a debugger nor a simulator, and each time I want to test a new dialog, I have to upload it on...
0
by: Killingkids | last post by:
hello, everyone...im facing a big problem in my final year project, hope that u all can help me solve the problem ... i was doing a mobile web application which enable student to check the college...
0
by: Killingkids | last post by:
hello, everyone...im facing a big problem in my final year project, hope that u all can help me solve the problem ... i was doing a mobile web application which enable student to check the college...
0
by: Andrea Gavana | last post by:
Hi All, in our office we work with quite complex input files for a reservoir simulator. Those files have thousands of keywords, switches, sub-keywords and whatever. Every time a modification is...
3
by: DanielJohnson | last post by:
I was wondering if anyblody can suggest me a network simulator written in python in which I can add on my own code and extend its functionality. I am looking for a simulator which will simualte...
18
by: activearun.83 | last post by:
Hi everyone, Can anyone give some idea about developing an 8085 simulator program in C? What techniques can be handled to develop this?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.