Page 1 of 1

native GBA games

Posted: Fri Nov 14, 2014 7:02 pm
by Tenocticatl
If this is the wrong place to bring this up, sorry!

The GameBoy Advance had an ARM CPU, an ARM7TDMI running the ARMv4 instruction set. Does that mean that the Pi could be made to run GBA roms without needing emulation?

Re: native GBA games

Posted: Sat Nov 15, 2014 3:51 am
by dwelch67
Unfortunately the instruction set of the processor is only a small part of the problem/platform, in general, but specifically with Nintendo and the GBA, there is a fair amount of video logic, which the raspi doesnt have, sure one could argue the GPU could emulate that, but the address space is all wrong.

Now there should be plenty of processing power to emulate the gba, just like your x86 host computer can. The gba was a 16mhz processor with mostly 16 bit data busses, so it was pretty slow. google static binary translation. The nice thing about the arm that is not as fun with others, is that not every instruction affects the flags. Hmmm, the bad thing about the gba though is that to get performance you used thumb mode and those didnt have the arm mode option to not touch the flags...of course the downside is in arm mode you have to test the flags every instruction...

Now because the raspberry pi is an arm, you could attempt a virtual machine type approach (vmwhare, virtualbox, etc) where you try to run the native gba binary, when it accesses an address space that is not supported by the raspi hardware, then you have the mmu cause a fault on that space, and in the fault handler emulate the hardware.

Probably the easiest is to just recompile and/or port an existing emulator to this platform.

if you want more detail about any/all of the things above, that is not a problem we can help you understand

Re: native GBA games

Posted: Sat Nov 15, 2014 12:09 pm
by Tenocticatl
Thanks for the reply, this at least gives me new search terms to expand my knowledge with :D

I think there's a lot of value in studying Nintendo's approach to handhelds. Using older, thoroughly understood hardware that is only just powerful enough to achieve the desired functionality is a lot like what the Pi tries to do. I figured this kind of project (and learning why it can or can't work) would make for a more interesting intro to low-level programming than, say, learning to do basic arithmetic.

Re: native GBA games

Posted: Sun Nov 16, 2014 3:03 am
by dwelch67
Let us know how it goes. I think you probably want to start with a mode 7 game if I remember my numbers right. Basically a game that ideally uses one layer of pixels as a frame buffer, rather than a tile based game. there are many other examples out there, I have an mmu example at github, but I didnt do it the easiest way, I think 1 meg pages or something (need to look it up rather that rely on my memory), basically the single stage to physical address rather than one table pointing at another. Can probably do something like this allowing the code to run natively, and use that granularity as the only ram that is not virtualized is the rom and the two rams...


Re: native GBA games

Posted: Sun Nov 16, 2014 8:01 am
by dwelch67
I went ahead and finally did it, added an mmu example, mmu directory.

Re: native GBA games

Posted: Sun Nov 16, 2014 4:25 pm
by DexOS
I think you will find the work of Peter Lemon very helpful

See Game Boy Emulation examples

Re: native GBA games

Posted: Sun Nov 16, 2014 8:02 pm
by dwelch67
You are going to have to deal with the GBA bios, you may find that some of those functions are used by the applications. Should be plenty of info on it and/or someone has just taken the bios and used it in the emulators...

Re: native GBA games

Posted: Thu Dec 11, 2014 8:25 am
by krom
Hi Guys,
I was working on a way to make GBA code run on the RaspberryPi, MMU is def the way to go, thanks to dwelch67 for your MMU code examples btw =D
Lots of GBA homebrew exists on my website for us to test with:
Many of these demos/games do not even use the GBA Bios at all, an easy way to find out if a GBA ROM does not use/need the Bios, is to try running it in a GBA emulator like VisualBoyAdvance without including the Bios ROM in the emulators setup.

I am currently fixing up GBADEV with simonb atm, would be amazing for people to be able to try out their code on the Raspberry pi in baremetal if they do not have access to GBA HW.

Here is some code to convert GBA screen Mode 3 to R-PI VRAM (R12 is the start of R-Pi VRAM):

Code: Select all

; Convert GBA 15BPP 555 Mode 3 To R-PI 565 16BPP
mov r0,$6000000 ; R0 = GBA VRAM
mov r1,$9600	; R1 = Screen Pixels Counter
  ldrh r2,[r0],2  ; R2 = Load Pixel from GBA VRAM
  and r3,r2,$1F   ; R3 = GBA 5bit Red
  and r4,r2,$3E0  ; R4 = GBA 5bit Green
  and r5,r2,$7C00 ; R5 = GBA 5bit Blue
  mov r2,r3,lsl 11 ; Shift GBA 5bit Red   To R-PI 5bit Red
  add r2,r4,lsl 1  ; Shift GBA 5bit Green To R-PI 6bit Green
  add r2,r5,lsr 10 ; Shift GBA 5bit Blue  To R-PI 5bit Blue

  strh r2,[r12],2 ; Store Pixel To R-PI VRAM
  subs r1,1	  ; Screen Pixels Counter--
  bne Mode3	  ; IF(Screen Pixels Counter != 0) Loop Mode3
Using the R-Pi GPU texture color modes, we could automate any screen mode conversions like this, without the need for any code like this above...
Also we could use GPU alpha blended textured quads to emulate the GBA tiled background modes & sprites =D

Also we could use the Raspberry Pi PWM to easily playback the 2 * 8-bit GBA Audio DACs, for perfect GBA Stereo sound =D

P.S Dex sorry about not being about, my new years resolution will be todo way more R-Pi baremetal coding, I have been stuck in a N64/SNES dev loop for months now, there is so much GPU stuff I wanna work out on R-Pi for us :(

Re: native GBA games

Posted: Thu Dec 11, 2014 2:42 pm
by dwelch67
Glad I could help...I am familiar with, didnt make the connection until you mentioned it, keep up the good work.