An emulator is a program that basically reproduces the behaviour
of the hardware of an old machine (ex : video cards, CPU,
mainboard, RAM). People that program emulators have to first obtain
some information about the console they want to emulate; for
example : what are the operations performed by the CPU. How is the
RAM divided ?
Emulation is a very a complicated process of an application
(emulator) acting like (emulating) another
One commonly emulated platform is the video game console,
including systems like the Nintendo Game Boy, Nintendo
Entertainment System, Sony Playstation, Sega Genesis, NeoGeo Pocket
Color to name a few, although, just about anything can be emulated,
from computers, to calculators, to video game consoles. Even the
computer used in the spacecraft for the Apollo space missions has
The basic process of emulation looks something like this:
Fetch the current instruction from memory (RAM).
Interpret that instruction. (Interpreting is taking an
instruction that is supposed to run on another platform and
executing or doing the equivalent instruction(s) on the machine
that is doing the emulating/running the emulator program.)
Increment the emulated PC (program counter; a register that
points to the currently executing instruction) the appropriate
(OPTIONAL) Allow the machine running the emulator program to
sleep/rest or stop execution of the emulator for a certain amount
of time to regulate frame rate (FPS; Frame Per Second) or the
emulated platform's processor speed.
(OPTIONAL) Do any other things that need to be done. (Draw an
emulated screen, process emulated audio, etc.)
Repeat the process.
Hopefully that makes some sense to the person who asked this
question. Emulation is not the sort of thing that can be explained
in detail to a non-programmer or non-techie.
If you want to write an emulator yourself, and feel you know
enough to get started, then do the following:
Get as much info on the system you're looking to emulate AS
POSSIBLE! This is EXTREMELY important, otherwise you'll have no
idea what to do in the next steps.
Pick an appropriate programming language to use. Using a
scripting language or a language/tool that is interpreted is
probably not the best idea if you're looking to emulate a fast
Figure out how you're going to emulate registers, RAM, etc. One
of the simplest ways of emulating RAM is creating a large array to
put all the emulated RAM's contents in. Registers can be done in
multiple ways, but my WIP GB emulator simply uses char variables,
since one char is 8 bits (1 byte) in size, which is the size of
most of the GB's registers. (The GB's 16-bit registers are emulated
Start coding! Take it easy though. Make sure you're not making
too many mistakes. Assuming you're emulating some kind of
"complete" platform (a platform with everything need to run and
function), emulation of the CPU and RAM is what you should focus on
first. (Remember! Focus on accuracy and proper emulation first. You
can speed things up later, when your emulator actually does
Debug. This is what's gonna make you want to shoot yourself.
Emulators are going to require a ton of debugging.
Repeat steps 4 and 5 many, many, many, many, many times.
As far as info, you should have several resources available to
compare with and get info from. I use Google and Wikipedia to get
my info. You might have to search for info for quite a while to get
what you want. (I took about two days to find and bookmark enough
info that I think I will need.)
You probably want to code your emulator in C/C++ or ASM. I know
some people even code emulator in Java, although, don't expect an
emulator in Java to run as fast as one in C/C++ or ASM.
If you want, you can look at a very basic version of my code for
my WIP GameBoy emulator below (use as you please):
//This is all done in C++ using MinGW and Code::Blocks IDE
//Define our RAM, VRAM, registers, etc:
char gb_a, gb_f; //Emulated registers A and F. Sometimes paired
as one 16-bit register
char gb_b, gb_c; //More registers. Sometimes paired as one
char gb_d, gb_e; //...
char gb_h, gb_l; //...
short gb_pc; //Emulated Program Counter register (16-bit)
short gb_sp; //Emulated Stack Pointer register
char* gb_ram_main; //Emulated RAM
char* gb_ram_video; //Emulated Video RAM
char* gb_cart_rom; //Emulated contents of the ROM
char* gb_cart_ram; //Emulated RAM in some cartridges
int main ()
gb_pc = 0x0100;
gb_pc_ = 0x0099;
gb_sp = 0x0000;
gb_ram_main = new char[ 8192 ];
gb_ram_video = new char[ 8192 ];
while( true )
if( InterpretInstruction() == 0 ) //My interpreting function
returns 0 on OK
//Nothing. PC incrementing is handled in
exit(1); //Abort if there's an error.
It is said that switch statements are inefficient for a matter
like this, but it seems to depend. According to some sources, this
only holds true for switches with a small number of cases, which
will compile into a chain of if() ... else if() ... statements -
whereas with larger numbers of conditions [100-200+] a switch will
compile into a jump table, and thus be more efficient than avoiding
switch( gb_ram_main[ gb_pc ] )
case 0x00: //NOP instruction
return 0; //Everything went OK
case 0xc3: //JMP instruction Jump to the 16-bit address
following this instruction