CPUs, Motherboards & RAM
Graphics Cards
Peripherals
Modding & Cooling
Systems
Networking
Security
Operating Systems
PC Games
Console Games
Atomic.edu
Tutorials
Lifestyle
Entertainment
Science
Merchandise
Wallpapers
Power to the PC Tour 2010
Atomic Live 2008
WGT 2008
All Events
Login
|
Register
|
RSS
News
|
Reviews
|
Features
|
Group Tests
|
Opinions
|
Galleries
|
Videos
|
Downloads
|
Competitions
|
Newsletter
|
Subscribe
Sunday March 21, 2010 11:34 AM AEST
Atomic MPC
>
Features
>
Game
>
PC Games
>
Emulation 101
PC Games
Emulation 101
«
1 - Page 1
2 - Page 2
3 - Page 3
»
Related Articles
C64 no more
The Commodore 64 makes a surprising comeback
Inside your system BIOS
The computer age is yet to begin
By
James Matson
Apr 4, 2007
Tags:
emulator
|
snes
|
rom
|
mame
Operation Code Red
So how does it all work? What spooky imps are called upon to transmogrify computer to console at the click of a button?
Fortunately there are no Gremlins, Mogwai or other beasties required. What you do need, is a solid understanding of the machine to be emulated, the language to perform the emulation and large unmarked shipping crates of patience.
Research the engine you want to emulate. Trawling through official (and un-official) documentation, reverse engineering information and occasionally SDKs is the only way to achieve this. Know thy console before attempting to render it on a completely different platform.
It’s this need for detailed technical information which has stifled or at least prolonged the creative process of emulating many newer consoles, as most companies don’t employ a position of laying bare the inner workings of their hardware.
With this in mind, the road to understanding emulation is best started by tackling an older system, something in the 8-bit range. Due to their age, there’s a wealth of information and documentation available online to get you started.
Although more recent consoles use custom architecture in the form of specialized components performing specific functions, the CPU is still the central point from which all emulation code springs and in order to emulate a conventional system you need to grasp Opcodes (Operation Codes).
Opcode is the term for a CPU instruction, basically a segment of machine code that relates to an operation to be carried out. These opcodes are defined in the instruction set architecture (ISA) of a CPU or in some cases a more specialized processing unit.
Understanding and mapping out these opcodes is considered a good first step towards emulating them on a different platform, in essence allowing one platform to copy the programmatic tricks of another via duplicating functionality of these opcodes. The particular programming tools used aren’t important in theory; just about any language you’re competent in can be used to write emulator code. But be warned, an emulator can be written in both C++ and Visual Basic, but it’s unlikely to perform well if the latter language is employed.
Most authors taking those tentative first steps into emulator creation tend to focus on a machine with relatively simple functions to write emulation for. The ‘Chip8’ language – designed in the 1970s for ‘kit’ computers like the Telmac 1800 - is a perfect candidate for a project to get your feet wet.
With just 35 opcodes to emulate, monochROMe graphics and 12 bit addressing the Chip8 is the perfect way to break your emulation virginity. Sure, it’s been done before – but it’s not about that, it’s about learning the concepts behind emulation without turning into a gibbering wreck as you try to re-create the ‘emotion engine’.
Want your Chip8 emulator to clear the screen? Just duplicate the functionality of opcode 00E0. Need to set the sound timer? Write some code that functions like opcode FX18.
As a perfect example, let’s take a gander at opcode 8XY4 in Chip8, which is responsible for adding the value of two registers together and setting the carry flag should the total overflow the 8-bit limit. If you wanted to emulate Chip8 in C and run it on Windows, you might replicate the function of this opcode as follows,
[code]
void MathAdd(){ //8XY4 VX = VX + VY, VF = carry
if((Register[x] + Register[y]) > 0xFF) { // Is the result of Register X + Register Y greater than 0xFF (255, which is the limit for 8bit)
SetVF; //Set the carry bit if result is greater than 0xFF
} else {
ClearVF; //If it is less, clear the carry bit
}
Register[x] = Register[x] + Register[y]; // Do the operation, add register y to register x
}
[/code]
Easy huh? Well sort of, at least at this level.
If you wanted to start reverse engineering the original Nintendo, you’re looking at 135 opcodes, 255 for the SNES and the complexity grows from there. Keep in mind this is just dealing with the CPU emulation, you then have to consider branching out to the audio, video and other subsystems.
Suddenly the prospect of creating a PlayStation 3 Cell emulator on your Celeron box isn’t looking so likely.
You too can turn your flashy PC into one of these! Huzzah!
Once you’ve mapped out your plan in theory and coded it accordingly, the end result should be an emulation loop that can load a ROM image into memory and begin executing opcode after opcode and produce output from the various emulated components, while the end user happily destroys wave after wave of pixelated aliens.
Most emulation is tested first by using ‘homebrew’ applications - those written by the authors to test functionality, with the end target that of running full commercial quality games at the same speed and quality as the native environment. Once you can achieve that, you’re in emulator nirvana.
Pulling apart an engine like PlayStation 2 becomes an infinitely more complex affair than the humble Chip8. The use of dynamic translators, complex memory management schemes and component synchronization means if you want to play with the ‘big guns’ you had better do your homework.
So – how’s Chip8 looking again?
If you want a more in depth look at the emulator code for Chip8 emulation through C++, be sure to grab a complete copy here:
http://djxander.artists.mpfspromotions.com/RefChip8.rar
(Special thanks to Alex ‘Refraction’ brown for the source).
«
1 - Page 1
2 - Page 2
3 - Page 3
»
Want to check out the first Australian review of Final Fantasy XIII? We got in this month's Atomic!
Plus HD projectors, Napoleon: Total War, Intel's new six-core processor, PC upgrading guide, and a whole lot more.
ON SALE NOW!
Email this
Print this
Tweet this
Send us your tips
Ads by Google
Comments
Be the first to comment on this article.
Thoughts on this article? Add a comment below.
Login
or
register
to submit a comment.
Command & Conquer 4: Tiberium Twilight first impressions
KitLog issue 3 hits the interwebs!
Bad Company 2: Worst launch ever?
The pirate life for me
Video of the new PlayStation Move controller
Bad Company 2: Worst launch ever?
Video of the new PlayStation Move controller
Valve dishes DRM dirt
New Zealand filters the web
Bad Company 2 sells a motza
Editor's Choice
CM Storm Sentinel gaming mouse
The Storm Warriors
Getting around IWnet and Modern Warfare's lack of dedicated servers
Galaxy GTX295 OC Disassembly mini-guide
Studying Overseas
Area 53
CES 2010
The Modern Warfare 2 launch
BlizzCon 2009
Computex 2009
Electronic Entertainment Expo 2009
Atomic Magazine
Issue:
111
|
April, 2010
Atomic
is a magazine aimed squarely at computer enthusiasts, gamers, and serious PC upgraders.
Every month we bring you the latest reviews of new technology and PC components, in depth features on everything from overclocking to console hacking, and gaming previews and interviews.
What's in this issue?
Subscribe Now!
Latest Comments
"Send your good taste to celebration by delivering our mouthwatering cakes to Dehradun and exotic ..."
on
A blind soldier can see with his tongue
by rony24 | Mar 20, 2010 4:56 PM
"So. Much. Awesome."
on
Red Dead Redemption's western life
by The Manta | Mar 20, 2010 4:23 PM
"@sirtrancealot, BF started on the PC and BC1 only on Consoles was a kick to the PC gamers ..."
on
Bad Company 2: Worst launch ever?
by NRUFrost | Mar 20, 2010 8:14 AM
"RAGE!!!"
on
Bad Company 2 sells a motza
by Hawkeye | Mar 20, 2010 1:24 AM
"alex - bugger all. 78mg of caffeine. About the same as a cup of instant coffee. Taurine, Gurana ..."
on
V Energy Drink Black
by tantryl | Mar 20, 2010 12:51 AM
Plan Finder
Powered by
WhistleOut
Mobiles
Deals
Broadband
1)
Nokia E71
47 plans
33%
2)
Apple iPhone 3GS 32GB
36 plans
33%
3)
Apple iPhone 8GB
43 plans
22%
4)
HTC Magic
5 plans
33%
5)
Nokia N97
40 plans
33%
This Guy is Not
Bob. This is...
Super-fast in home wireless broadband + local and national calls.
Sony Deals
With Optus
Great Sony PlayStation® deals available for a limited time with Optus.
3 Months Free
on HTC Magic
The HTC Magic is now available on the $29 Cap from 3 Mobile with 3 months free access.
3 Months Free
on Nokia E71
The Nokia E71 is now available on the $29 Cap from 3 Mobile with 3 months free access.
Nokia E72 +
3 Months Free!
The Nokia E72 - new model with full keyboard and 3 months free on the $49 Cap.
3 Months Free
with 3 Mobile
Get 3 months free on Nokia E71, Samsung F480, Nokia E63 and more with 3 Mobile.
New iPhone Price
on $49 Cap
Vodafone have released new iPhone 3GS prices on the $49 Cap.
Save $100
on iPhone
Save up to $100 on an iPhone when you buy online with Optus.
Optus 90GB
Save $969.71!
Buy online and save $969.71 on a 90GB broadband plan from Optus.
«
1
of
»
1)
iiNet
32 plans
100%
2)
Optus
41 plans
14%
3)
Vodafone
7 plans
5%
4)
Telstra BigPond
30 plans
1%
5)
Dodo
34 plans
6%
Mobiles
|
Broadband
|
Credit Cards
Haymarket - Atomic MPC
Latest User Reviews
90%
Logitech MX518 Gaming-Grade Optical Mouse
Good shape, design and Ergonomics
By
T-Rav18
|
Mar 15, 2010
100%
Coolermaster HAF 922
A case to make a statment and give your pc the Heavy Hardcore Grunt it needs.
By
widow_mak3r
|
Mar 11, 2010
50%
Coolermaster Excalibur
Atomic is under attack
By
Fat_Bodybuilder
|
Mar 11, 2010
40%
XFX 9300 Motherboard
HUGE letdown
By
compshoptech
|
Mar 10, 2010
90%
CM Storm Sentinel gaming mouse
Sexy and instant geek respect.
By
widow_mak3r
|
Feb 10, 2010
more user reviews »