Subject: Re: How to ** WRITE ** an emulator? Path: lobby!newstf02.news.aol.com!portc02.blue.aol.com!pitt.edu!newsflash.concordia.ca!canopus.cc.umanitoba.ca!cyclone.mbnet.mb.ca!logbridge.uoregon.edu!nuq-peer.news.verio.net!news.verio.net!nuq-read.news.verio.net.POSTED!czempel From: czempel@ns.net (Chip Zempel) Newsgroups: comp.emulators.game-consoles,comp.emulators.mac.executor,comp.emulators.misc,comp.emulators.ms-windows.wine Message-ID: References: <7voiuf$5d$1@nntp2.atl.mindspring.net> Organization: who me? organized? Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 8bit X-Newsreader: Yet Another NewsWatcher 2.4.0 Lines: 104 Date: Wed, 03 Nov 1999 08:10:36 -0800 NNTP-Posting-Host: 209.162.65.148 X-Complaints-To: abuse@verio.net X-Trace: nuq-read.news.verio.net 941645396 209.162.65.148 (Wed, 03 Nov 1999 16:09:56 GMT) NNTP-Posting-Date: Wed, 03 Nov 1999 16:09:56 GMT Xref: lobby comp.emulators.game-consoles:43723 comp.emulators.mac.executor:13840 comp.emulators.misc:65548 comp.emulators.ms-windows.wine:33659 Charles- Thanks for the tip. I had pretty much figured out most of what you said already. The "big switch" statement seems like the simplest way to do it, but also the slowest. Something like a jump table seems more like the "right" way to do it - an array of pointers to the routines, using the instruction as the index into the array. I haven't tried this in C, but it looks like fun. FWIW, I'm toying with the idea of emulating a Z80 running CP/M, on a PowerPC as the host system. This has already been done (and I have the source code) but that seems like a good way to start. I'll have someone else's code to learn from. I'm not at all familiar with 680x0 or PowerPC assembly language, but I used to know my way around a Z80 very well. Paul Robson sent me a reply that mentioned a couple of web sites. It took me a few minutes to track them down, so I'm going to put them here in hopes that someone else with a question like mine will be more likely to stumble across them in a DejaNews search: EmuSchool http://members.home.net/teaguecl/ Dan's Emulator Page http://www.atarihq.com/danb/emulate.htm Thanks again for responding! Chip Zempel In article <7voiuf$5d$1@nntp2.atl.mindspring.net>, "Charles E. Bortle, Jr." wrote: >Hello Chip, > >Basically, an emulator is a program that makes one processor (cpu) >"look" like a different processor. > >Because of your experience with assembly programming you should >have some idea of what a processor (machine) instruction looks like >and what it does. Well...an emulator just makes another processor >appear to be that processor that you already know. > >There are a number of ways to build one, depending upon the implementation >language, the processor you are running it on, and the processor you intend >to >emulate. If you want to emulate a 6800 on a Pentium, and you were using C >you could us the brute-force method and just write a huge Switch statement >that took all possible values of the 8bit instruction op code and vectored >control >to a routine designed to handle that instruction. Now that routine just >does >processing to, in effect, execute that instruction. > >This is simplistic, thougth, since you might want to handle addressing >modes, >but on the other hand, the single Switch is faster. > >Just build a "fetch" routine that fetches each instruction from a memory >buffer that >emulates the processor's memory address space. Pass that to the Switch, >which >will dispatch that instruction to the proper handler, and, after that one is >done, fetch >another instruction and do the same. > >Hope this gets you started :-) > > >-- >Charles cbrtjr@ix.netcom.com >"For God So Loved The World, That He Gave His >Only Begotten Son, That Whosoever Believeth >In Him Should Not Perish, But Have Everlasting >Life"John3:16 * http://pw2.netcom.com/~cbrtjr/wrdthing.html * >Chip Zempel wrote in message ... >>(I apologize for cross-posting this to several NGs, but since I can't seem >>to find one that deals specifically with the design of emulators, I'm >>hoping a programmer who can help me will stumble across this question!) >> >>I'm looking for information (in print or online) about writing emulators - >>theory, design, optimization, that sort of thing. Source code would be nice >>too! >> >>I'm just an amateur programmer and this is mostly idle curiosity - I'll >>probably never get around to actually _writing_ an emulator! On the other >>hand, I'm pretty familiar with C and I did some assembly language >>programming way back in CP/M's heyday, so I'm fairly comfortable with >>high-level and low-level programming and concepts. >> >>Thanks in advance for any info. >> >>------------------------------------------------------------------- >>Chip Zempel >>czempel@ns.net >>------------------------------------------------------------------- >>If a cluttered desk is a sign of a cluttered mind, >>then what does an empty desk signify? ------------------------------------------------------------------- Chip Zempel czempel@ns.net ------------------------------------------------------------------- If a cluttered desk is a sign of a cluttered mind, then what does an empty desk signify?