PDA

View Full Version : What does it take to make an emulator?


imnonoitall
12-18-2004, 10:07 PM
The topic's pretty self-explanatory I guess. Mainly I need these questions answered:

1. What do I have to learn? (I know I'd have to be familiar with the instruction sets of the systems to be emulated and the system on which the emulation will take place, but what else?)
2. How many people do I need? (Probably varies, right? I'd probably start with something a little simpler like NES and then maybe get into PSX and N64. How many would you recommend for any of the above?)
3. How long will it take? (Of course, it would depend on our skill, and #2, but a round figure?)
4. What resources are needed? (Compilers, assemblers, dissasemblers, etc.)

I know the questions are a little general, but I don't need specifics, just educated guesses. Thanks!

<P ID="signature"></P>

icenine0
12-18-2004, 10:19 PM
Well, mostly, lots and lots of free time coupled with an unnatural interest in deciphering, interpreting, and replicating mathematically intense subject matter.

In short, unless your idea of a perfectly decent Friday night is memorizing a list of MIPS-3000 opcodes, don't bother.

<P ID="signature">The more often you fail, the sweeter the taste of success!</P>

Disch
12-19-2004, 12:44 AM
> 1. What do I have to learn? (I know I'd have to be familiar
> with the instruction sets of the systems to be emulated and
> the system on which the emulation will take place, but what
> else?)

You need to know:

1) How to program in any language that can perform the task.
2) The platform you're coding for. If you're making an emu for Windows... know how to code for Windows. Stuff like sound streaming, video stuff, input from the user... all that good stuff. You should be able to code a very simple game for the platform you're targetting before you can code an emu for it.
3) The system you're emulating. This includes not only the instruction set... but also various system stuff like how the graphics unit operates, audio stuff... and probably timing stuff (older systems like the NES have games which rely on precise timing in order to operate properly). Some people say you should code a demo for whatever system you're trying to emulate before you actually code an emulator... but I'm not sure I'd agree (I was able to code a 6502 emulator before I was able to code in 6502).


> 2. How many people do I need? (Probably varies, right? I'd
> probably start with something a little simpler like NES and
> then maybe get into PSX and N64. How many would you
> recommend for any of the above?)

You don't need any more than one.

> 3. How long will it take? (Of course, it would depend on
> our skill, and #2, but a round figure?)

That's completely relative. I could code an operating NES emu in about a week if I put the effort into it. But then again I've worked on emus before and have a pretty comprehensive understanding of how the NES operates.

If you've never done any real programming before (which, judging by the fact that you actually asked this question, I'm going to assume you haven't)... don't expect to make anything for a loooooooooooooong, long time. Making an emulator is no simple project... and probably not something a novice should take up.

> 4. What resources are needed? (Compilers, assemblers,
> dissasemblers, etc.)

1) A compiler for whatever language you're using on whatever OS you're coding for.

2) Any and all docs covering the workings of the system. The amount of information varies from system to system. Some systems are kind of hard to find info on... others have a metric fuckton available *cough*NES*cough*

<P ID="signature"></P>

imnonoitall
12-19-2004, 01:44 AM
Ok cool. It actually sounds a little easier than I had originally thought (though it still sounds hard). I've never written an emulator before, but I've been programming for a few years and have done some decent stuff in assembly, so with what you said I feel a bit more competent. Thanks for the info.

<P ID="signature"></P>

MooglyGuy
12-19-2004, 05:09 AM
> That's completely relative. I could code an operating NES
> emu in about a week if I put the effort into it. But then
> again I've worked on emus before and have a pretty
> comprehensive understanding of how the NES operates.

Incidentally, using a pre-made CPU core and then coding the rest typically cuts the development time down drastically. I managed to write a Pac-Man emulator for the GameCube within the span of about two days using a pre-made Z80 core.

<P ID="signature"></P>

Disch
12-19-2004, 06:14 AM
> Incidentally, using a pre-made CPU core and then coding the
> rest typically cuts the development time down drastically.

Man... I've written so many 6502 emulators.... I could do it from scratch in probably under an hour. Just give me a list of opcodes and a cycle chart.

Hardest part of the emulator is relaying all the stuff to the user... that part is always the shits for me. I would LOVE to make an NES emu.... if I don't have to make an interface or anything. I love doing the 'behind-the-scenes' stuff.

edit:

But yeah. The -first- working 6502 emu I made to for-freaking-ever and was riddled with bugs. Those bugs aren't exactly easy to find either unless you code a tracelogger or something (which typically takes me longer to write than the emu itself)

And a Z-80 emu would take significantly longer to code than a 6502 emu since there's so many more opcodes you have to catch.

imnonoitall
12-19-2004, 08:13 AM
> Hardest part of the emulator is relaying all the stuff to
> the user... that part is always the shits for me. I would
> LOVE to make an NES emu.... if I don't have to make an
> interface or anything. I love doing the 'behind-the-scenes'
> stuff.

That's me too, I hate designing user interfaces and love doing the stuff that makes things tick. Now, back to my newbish questions. Since I've never designed an emulator before, I'm a little lost as to where I should start. To keep things as simple as possible I'm writing the emulator (NES) for Windows in C++ (I'm more than willing to do some assembly too if necissary). How do emulators typically go about interpreting and executing ROM information? Do I just translate the whole ROM to native code in one big conversion and jump to the beginning or interpret as I go or what? Probably a bit more complicated then that, huh? Thanks for baring with me - I'm not too stupid, just incredibly ignorant. ;)

PS - If anyone knows of any online tutorials for writing an emulator, that would probably save lots of annoying newbie posts from yours truly. Thanks!

<P ID="signature"></P>

breadcrust
12-19-2004, 11:36 AM
> I love doing the
> 'behind-the-scenes'

yes, especially when there are 50+ different variables for a simple small peice of code like my current program project (current put on hold by some web projects) http://www.sourceforge.net/projects/xbashservXBashServ</a> that is used to manage temporary (as in a couple of days or so) server mainly for Lan partys which has seperate code modules for each game it can controll, and most of these modules are just config stuff (the Americas Army module is 4/5 config stuff!) and having to go through and make up a GUI for the module takes forever...

<P ID="signature">Breadcrust

Click me!, you know you want to... ('http://phantasyrpg.com/main.php?view=20335')
http://sigx.yuriy.net/images/skin/BlueSteel/0/xbreadcrust.png </P>

Disch
12-19-2004, 06:35 PM
> To keep things as simple as possible I'm writing the emulator
> (NES) for Windows in C++ (I'm more than willing to do some
> assembly too if necissary).

Probably a good choice.

> How do emulators typically go about interpreting and executing
> ROM information? Do I just translate the whole ROM to native
> code in one big conversion and jump to the beginning or interpret
> as I go or what?

I'm actually unsure how emus for more modern systems go about it... but the easiest way (and common way for NES emus) is to read bytes and interpret them as you go. I don't know if I'm explaining that well /wwwthreads/images/icons/tongue.gif. Here's an old copy of http://hypher.net/disch/NES_CPU.cppa 6502 emu</a> I wrote if it'll help serve as an example (if you can follow it... the tabs are kind of screwy and it isn't exactly commented well).

Anyway.... get the following:

http://www.obelisk.demon.co.uk/6502/reference.htmlhttp://www.obelisk.demon.co.uk/6502/reference.html</a> -- Great [error-free] 6502 reference charts. Although they're not great for learning what each instruction does.

http://nesdev.parodius.com/6502.txthttp://nesdev.parodius.com/6502.txt</a> -- Less great [occasional errors / misinformation] 6502 doc. It probably does a better job of explaining the overall concept of each instruction... but don't use it as the final word.

http://nesdev.parodius.com/ndox200.ziphttp://nesdev.parodius.com/ndox200.zip</a> -- NEStech. Comprehensive doc on the general workings of the NES. Beware occasional errors (but all around good doc)

http://nesdev.parodius.com/2C02%20technical%20reference.TXThttp://nesdev.parodius.com/2C02%20technical%20reference.TXT</a> - 2C02 Technical reference. A little dense.... but important to have to get proper timing in your emu.

http://nesdev.parodius.com/loopyppu.ziphttp://nesdev.parodius.com/loopyppu.zip</a> - Loopy's scrolling docs. Only doc to really touch base on the proper workings of the $2005 and $2006 registers.

When you're ready to impliment sound:

http://nesdev.parodius.com/NESSOUND.txthttp://nesdev.parodius.com/NESSOUND.txt</a> - The infamous NESSOUND.txt. Excellent doc.

http://nesdev.parodius.com/dmc.txthttp://nesdev.parodius.com/dmc.txt</a> - The sister-doc to the above covering the workings of the DMC.

http://nesdev.parodius.com/apu_ref.txthttp://nesdev.parodius.com/apu_ref.txt</a> - Followup sound doc which corrects some errors and clarifies some things.

When you're ready to impliment support for different mappers:

http://nesdev.parodius.com/mappers.ziphttp://nesdev.parodius.com/mappers.zip</a> - Firebug's mapper docs. Covers a lot of mappers... but also has many errors/inaccuracies. It's good enough for the simple mappers but for some mappers, you're better off using other sources....

http://www.tripoint.org/kevtris/mappers/mappers.htmlhttp://www.tripoint.org/kevtris/mappers/mappers.html</a> -- Like these



In case you haven't noticed the trend.... http://nesdev.parodius.com is where you want to be for NES emu development. If you get further questions, you might want to post there... the regulars are really helpful and knowledgable (not to say the people here on ZMD aren't... but the nesdev boards specialize on this subject so they're really better suited for it).

<P ID="signature"></P>

imnonoitall
12-19-2004, 10:03 PM
Thanks for all those references - they look perfect to get me on my way!

<P ID="signature"></P>