Tenocticatl
Posts: 19
Joined: Fri Jan 11, 2013 11:11 pm

native GBA games

Fri Nov 14, 2014 7:02 pm

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?

dwelch67
Posts: 955
Joined: Sat May 26, 2012 5:32 pm

Re: native GBA games

Sat Nov 15, 2014 3:51 am

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

Tenocticatl
Posts: 19
Joined: Fri Jan 11, 2013 11:11 pm

Re: native GBA games

Sat Nov 15, 2014 12:09 pm

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.

dwelch67
Posts: 955
Joined: Sat May 26, 2012 5:32 pm

Re: native GBA games

Sun Nov 16, 2014 3:03 am

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...

David

dwelch67
Posts: 955
Joined: Sat May 26, 2012 5:32 pm

Re: native GBA games

Sun Nov 16, 2014 8:01 am

I went ahead and finally did it, added an mmu example, github.com/dwelch67/raspberrypi mmu directory.
Last edited by dwelch67 on Sun Nov 16, 2014 8:01 pm, edited 1 time in total.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: native GBA games

Sun Nov 16, 2014 4:25 pm

I think you will find the work of Peter Lemon very helpful
https://github.com/PeterLemon/RaspberryPi

See Game Boy Emulation examples
Batteries not included, Some assembly required.

dwelch67
Posts: 955
Joined: Sat May 26, 2012 5:32 pm

Re: native GBA games

Sun Nov 16, 2014 8:02 pm

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...

krom
Posts: 61
Joined: Wed Dec 05, 2012 9:12 am
Contact: Website

Re: native GBA games

Thu Dec 11, 2014 8:25 am

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: http://www.gbadev.org
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
Mode3:
  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

**EDIT**
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 :(

dwelch67
Posts: 955
Joined: Sat May 26, 2012 5:32 pm

Re: native GBA games

Thu Dec 11, 2014 2:42 pm

Glad I could help...I am familiar with gbadev.org, didnt make the connection until you mentioned it, keep up the good work.

David

Return to “Bare metal, Assembly language”