Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » i know kigb is a game boy/gbcolor emulator

This thread is locked; no one can reply to it. rss feed Print
i know kigb is a game boy/gbcolor emulator
BAF
Member #2,981
December 2002
avatar

but how do i make a gameboy advance emulator" how do i go about making an emulator???

Thomas Harte
Member #33
April 2000
avatar

A genuine emulation of the hardware? Not too tricky:

- get a list of all the logic bearing components in the GBA
- consider their inputs and output, and how they connect to one another
- find out how the outputs of each chip depend upon the inputs
- write code to reproduce all of the above behaviour

If the thing you want to emulate is quite fast compared to the thing you want to emulate on, you'll need to start cheating. The common technique is to identify the 'prime' component of a system and focus your emulation around that. The prime component of a GBA is the ARM CPU.

You'd then write code which fetched, decoded and executed ARM instructions. If you really had very little regard for accuracy whatsoever you might then do something like perform ARM instructions for the number of cycles it takes for one iteration of the display to be drawn, then take a break to update the display, then return to doing the CPU stuff.

A better implementation might do a similar thing but run the CPU for as long as it takes one scanline to appear, then draw the scanline. And so on.

If you are lucky you'll get a system whereby the components external to the prime component have only fixed effects upon it (i.e. interrupts always at the same time, timing always affected in the same way...), in which case cheats like the above can be made to be very close to the way the real hardware is working.

spellcaster
Member #1,493
September 2001
avatar

Get the hardware specs.
Define a struct holding all the registers.
Then implement a table for all opcodes. Then implement these opcodes.
Then you can either repat for the other components, or start working on the timing (so your emulated piece has the same speed as the original hardware (per instruction).

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Thomas Harte
Member #33
April 2000
avatar

Be aware that often you will not derive a fully accurate model from just registers, opcodes and opcode cycle length information - on almost all computers other factors affect timing and therefore other implicit elements of interaction.

For example, on a GBA (and most things), the timing for memory which describes the display is different than that elsewhere. It may also be dependant upon exactly what the display chip is doing at the time (although it may not be, I know nothing of GBA specifics). Furthermore, well written software might exploit these differences to achieve effects that might not otherwise be possible - especially on the messed up 80s style 'sprite lists' that Nintendo still cling to.

An example from another platform is a particular ZX Spectrum game which exploits the way that RAM refresh is internal to the CPU in order to starve the video display circuits of memory access and selectively create a noise effect on screen.

Johnny13
Member #805
October 2000
avatar

Quote:

but how do i make a gameboy advance emulator

check http://sf.net/projects/vba

Alg3D Praise my Games!!<code>#define SPAMMER (post>=666&&postperday>=6)</code><Mr.spellcaster>What post? <Mr.spellcaster>A useful post by me.

BAF
Member #2,981
December 2002
avatar

osunds tricky... :-/

Mars
Member #971
February 2001
avatar

What did you expect, an emulate_system() function that you'd pass a SYSTEM_GBA constant and a "super_mario_advance.gba" filename? ;)

--
This posting is a natural product. The slight variations in spelling and grammar enhance its individual character and beauty and in no way are to be considered flaws or defects.

Thomas Harte
Member #33
April 2000
avatar

The GBA is actually one of the easier to emulate. It had only one CPU and simple timing rules and non-CPU hardware. Additionally the CPU is quite slow and best of all is a proper RISC design, meaning that everything about it is simple.

If you wanted to make life hard, you might have a bash at dynamic recompilation! I keep meaning to do this, but my primary project continues to take up the majority of my time.

BAF
Member #2,981
December 2002
avatar

hehe. humm, what exactly is dynamoc recompilation? Sounds hard:-/

Thomas Fjellstrom
Member #476
June 2000
avatar

Bobby: Its a concept thats an order of magnitude harder to comprehend than "Copy & Paste".

Quote:

dynamoc

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Carrus85
Member #2,633
August 2002
avatar

Dynamic Recompilation- Recompiling Dynamically ;D

Not that easy to implement, I would imagine. Essentually what you do is recompile the rom into an easily read/understood form so you can execute it easilier. But, to do this effectively, you would probably have to write some form of a custom compiler... which, I'm sad to say, I have ZERO experience in.

FYI: Do we really need to turn this into a flame, people? Don't turn it into a flame.

X-G
Member #856
December 2000
avatar

You compile it to native code on whatever platform you're running on.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Thomas Fjellstrom
Member #476
June 2000
avatar

From what I've learned (could be wrong), Dynamic Recompilation is somewhat akin to JIT, where at runtime, you convert the code to native opcodes and run on the host cpu instead of on an emulator.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

BAF
Member #2,981
December 2002
avatar

i have -25 experience in it. i thought you were getting at that. i wonder .. which would be easier-arm instruction table or recompilation.
are gba games written in c or c++? you could decompile and recompile and run the resulting exe! damn, i know it can;t be that easy:(

ot: how do you decompile an exe into c/c++ code?

Thomas Fjellstrom
Member #476
June 2000
avatar

That is pretty impossible. There is no way to go back to the code you originally wrote.. Unles you had an infinite amount of monkeys. Especially after the optimizer gets done with the code, its just not the same code you wrote.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

spellcaster
Member #1,493
September 2001
avatar

Bobby, don't you think you should code something simple before starting with more complex concepts might be a good idea?

You still have problems with the C/C++ syntax. So, try to finish a few small programs. Then get some good books on the advanced topics (I'd suggest the Dragon book and "Operating Systems") work through them, and then start again.
Alternativly, you could read (silently) the corresponding emulation coding newsgroups until you actually understand what it's going on there.

This kind of stuff is complex. Right now you're not ready for it. First, you need to become a Jedi, then you can face Darth Emulator.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

BAF
Member #2,981
December 2002
avatar

ok. i made a demo and i am making a ss right now:)

Cage
Member #1,277
March 2001

GBA games are written in C, C++, you name it, as long as you have a proper compiler that can create binary executables for the ARM CPU ;). I personally prefer C++, though ;D.

-----
"I'm dumb!. it prolly wont do anything just like Sub7 when u extract it to ur own system I'm dumb!." - theforgotten
"heh i got hit by sub7 before. I just dont know how i got it. It took me about 2 yrs to figure out which virus i had. I'm dumb!. then i started wanting to hack and i got sub7 just ot play around with it and i found the features in it that i had been affected by when i got the virus." - theforgotten

spellcaster
Member #1,493
September 2001
avatar

Quote:

ok. i made a demo and i am making a ss right now

What's a "ss"?
"Something Simple"?
"Something stupid"?
"simply stupid"?
"Stupid simple"?
"sun signal"?

--
There are no stupid questions, but there are a lot of inquisitive idiots.

gillius
Member #119
April 2000

I think he means screensaver. I finially figured it out in the other thread when you asked why he would want that code. Then I saw it exits when you do any input, which acts like a screensaver does, hence ss. But it took me almost 2 days to figure that out.

Gillius
Gillius's Programming -- https://gillius.org/

BAF
Member #2,981
December 2002
avatar

heh. it is a screen saver::)

gnolam
Member #2,030
March 2002
avatar

Why don't you say it straight out then? :P
(my personal association was Schutzstaffel, and that's not an association you want to give people...)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

BAF
Member #2,981
December 2002
avatar

too lazy

(see, no punctuation :P)

spellcaster
Member #1,493
September 2001
avatar

Quote:

too lazy

That's teh 2nd time you gave that answer. From now on, I'll be to lazy to answer your posts correctly.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Thomas Harte
Member #33
April 2000
avatar

Quote:

From what I've learned (could be wrong), Dynamic Recompilation is somewhat akin to JIT

That is exactly to what I was referring. Some emulators (notably N64 and Playstation ones) can go even further by spotting references to particular functions from the footprint the manufacturer supplied compiler generates and can then head off into highly optimised pre-supplied interpretations of the same functions.

Dynamic recompilation is particularly applicable to older ROM based formats where, on the whole, code cannot dynamically modify itself, and to newer 32bit and above consoles where large sections of code tend to have been spat out by a compiler of some sort and for that reason doesn't do much that is very unpredictable.

I suspect because the CPU and graphics hardware are so massively mismatched in the GBA, a lot of people will produce highly optimised assembly written code for their inner loops, although hopefully they'll leave it in ROM meaning that dynamic recompilation is still a 'good' idea.

Quote:

i wonder .. which would be easier-arm instruction table or recompilation

'Instruction tables' are always easier, although it'd be silly to use an actual table for the ARM because all of the opcodes have meaningful bit patterns, and there is the option for 32bit instructions meaning that only if you represented every entry in your table by exactly one byte and had no code whatsoever could you fit a genuine table into your PC's RAM.

Go to: