Adding support for gpsp to CupCade + NES with the PiTFT

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
TehVulpes
 
Posts: 5
Joined: Fri Jul 25, 2014 9:38 pm

Adding support for gpsp to CupCade + NES with the PiTFT

Post by TehVulpes »

I'm trying to add support for gpsp (GBA emulator) to cupcade, and I'm having a bit of difficulty.

What I have working:
I installed libsdl-dev and was able to compile gpsp (https://github.com/DPRCZ/gpsp). After copying the GBA BIOS to the same directory, exporting FRAMEBUFFER=/dev/fb1 and SDL_FBDEV=/dev/fb1, I can run gpsp. When I give gpsp arguments to try to run something other than a GBA ROM, I can hear the GBA bootup sound from the bios.

What doesn't work:
GPSP starts ok, but the PiTFT shows a black screen. Even if it had text previously, the screen changes to black, and if I kill the gpsp process, the screen returns to showing text or whatever was previously using it. I've also tried to get fceu working from the CLI and not from gamera simply so I can understand more fully what it takes to get it running. Even when FRAMEBUFFER=/dev/fb1 and SDL_FBDEV=/dev/fb1, fceu similarly shows a black screen. I've also tried setting SDL_VIDEODRIVER=fbcon, and that doesn't change anything for fceu or gpsp. Looking around in gamera.c, it looks like the only argument to fceu when run is the location of the ROM, so I'm not sure why video works when fceu is started from gamera and not from the CLI.

What I'm wondering:
Would anyone have any ideas as to how to get gpsp to correctly show video? Even if no one can help with that, how would I get fceu to work correctly from the CLI? I figure if I can understand everything needed to get fceu working, I could tinker with that a bit to get gpsp working, since both gpsp and fceu show the same black screen when I run them currently, and both use SDL.

I'm very comfortable coding in C and writing shell scripts, so recompiling a custom version of gamera or retrogame is something I can try. If I get this working I'd gladly share how I got this working. Besides, who wouldn't want a GameGrrl that actually plays gameboy games?

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Adding support for gpsp to CupCade + NES with the PiTFT

Post by pburgess »

If those two environment variables are set, I'm not sure why fceu refuses to display. Those are the only items set by /etc/inittab before launching gamera.
I don't recall specifics, just that getting fceu running at all with the TFT was a major ordeal, and The One True Working Executable has been lovingly handed back and forth with kid gloves so as not to anger it.

As for GPSP, try hooking up a regular monitor at the same time, see if its output is going there. Is this also an SDL application, and do you need to issue any command line options to enable that (vs. GL or something)? Other possibility might be clipping...is your TFT vertical or horizontal? fceu fails catastrophically on a vertical screen, it doesn't handle scaling or clipping at all.

TehVulpes
 
Posts: 5
Joined: Fri Jul 25, 2014 9:38 pm

Re: Adding support for gpsp to CupCade + NES with the PiTFT

Post by TehVulpes »

So I realize this response is really quite late, but anyway...

Hooking up a regular monitor worked, and the TFT is horizontal so I doubt it would be a clipping issue. Regardless, I rather quickly gave up and just wrote my own version of gpsp and gamera. Gamera now looks for .gba ROMs, and I made my own version of gles_video.c for gpsp that writes graphics data directly to /dev/fb1. It's really messy, and only gets about 20 fps, but it works, and perhaps later I'll get around to writing my own SDL code for better framerates. When started from the now modified version of gamera, everything works. I'm still not sure why fceu so sternly refuses to work outside of gamera...

I may decide to share my modifications when I decide they work well enough. The gpsp changes boil down to writing the gameboy framebuffer directly to /dev/fb1 (a messy hack, but it works), and the changes to gemera basically just make it look for .gba ROMs in /boot/gpsp/roms.

User avatar
egutting
 
Posts: 297
Joined: Wed Nov 14, 2012 12:57 am

Re: Adding support for gpsp to CupCade + NES with the PiTFT

Post by egutting »

I would love to place a GB or GBA emulator on my cupcade!!!

TehVulpes
 
Posts: 5
Joined: Fri Jul 25, 2014 9:38 pm

Re: Adding support for gpsp to CupCade + NES with the PiTFT

Post by TehVulpes »

emulator.zip
(325.65 KiB) Downloaded 145 times
@egutting I put together a little pack using the existing files I've already made if you wanna play GBA roms now. Note, again, that framerates aren't that great because I chose a really poor but easy-to-implement way of writing to the display, and haven't gotten my SDL code satisfactory yet. I've only tested this on the most recent version of cupcade, so if it doesn't work for you that's something to check out... Also, please, before doing anything, make a backup of your SD card. It can't hurt and restoring an image is much less work than setting up a new one if something breaks (which is not entirely unlikely).

While I have the source files also included in the src folder, you don't need them; they're just there to show how I got it working. Also, while .gb and .gbc games will show up in gamera if you have them in your /boot/gpsp/rom folder, gpsp can't actually play them, so attempting to play one will just crash. If you want to set up my custom gamera and gpsp binaries, here's what you should do...

1. Copy the extracted folder to your pi's home directory (i.e. /home/pi)
2. Copy the GBA bios to the emulator folder in your home directory. Unfortunately I can't really include it here since it would be illegal, but the file is exactly 16,384 bytes long and has an md5sum of a860e8c0b6d573d191e4ec7db1b1e4f6. Google is useful! Regardless of what the name is when you download it, you should rename it to gba_bios.bin on your pi, and place it inside the emulator folder.
3. From a terminal, issue the following command, which will basically just copy the gamera and gpsp binaries and some config files.

Code: Select all

sudo sh ~/emulator/install.sh
4. Put some GBA roms in /boot/gpsp/rom, reboot, and all should work.

I've made the controls for gpsp the same as for fceu, so up, down, left, and right are the same, A is Z on the keyboard, B is X on the keyboard, Select is Q on the keyboard, and Start is R on the keyboard. L is A, and R is S.

User avatar
d3rax
 
Posts: 16
Joined: Mon Aug 25, 2014 8:40 am

Re: Adding support for gpsp to CupCade + NES with the PiTFT

Post by d3rax »

When I issue: sudo sh ~/emulator/install.sh

I get an error
cannot state 'root'; no such file or directory
cannot state 'usr'; no such file or directory
cannot state 'boot'; no such file or directory

I did place all the folders in home/pi/emulator?

TehVulpes
 
Posts: 5
Joined: Fri Jul 25, 2014 9:38 pm

Re: Adding support for gpsp to CupCade + NES with the PiTFT

Post by TehVulpes »

I quickly made this installation script a few months ago and haven't touched it much since, things may have changed since then. However, based on the error you're getting, it sounds like a bug in my script is to blame. Try changing to the root directory before running the command with

Code: Select all

cd /
Again, though, it may be something else, and I've been too busy to put any time towards this little project. Sorry :-)

User avatar
d3rax
 
Posts: 16
Joined: Mon Aug 25, 2014 8:40 am

Re: Adding support for gpsp to CupCade + NES with the PiTFT

Post by d3rax »

Unfortunately i'm not able to get it to work.

Install.sh seemed to have worked but now gamerra does not start. In the boot sequence I get an error openvt: exec: permission denied.

To bad you can't put anymore time towards this project. I hope you will again in the future ;).
Maybe you could make an image with gpsp build in that can be burned to an sd (ofcourse without the bios file)?

Just two different questions. I would also like to play the orginal gameboy games (.gb). Do you have any tips on how I could get this to work with the PiTFT?

I also would like to crop the view on the Pitft a bit and move it a bit to the left. This way I can fit the display better in my gameboy case. Do you have any Idea how this can be done?

I'm a bit dissapointed with the PiTFT screen, because i thougth it was possible to scale and crop the view as with a regular display. Also dissapointed that retropie does not work.

Anyways thanks for your input!

TehVulpes
 
Posts: 5
Joined: Fri Jul 25, 2014 9:38 pm

Re: Adding support for gpsp to CupCade + NES with the PiTFT

Post by TehVulpes »

The "permission denied" problem is probably due to gamera not having executable permissions, you could fix that with

Code: Select all

sudo chmod a+x /usr/local/bin/gamera
sudo chmod a+x /usr/local/bin/gpsp
obviously replacing the /path/to/gamera with the actual filepath.

As for original gameboy games, you'll have to find an emulator that plays gameboy games and that works on raspberry pi. Then, to get it to work with the PiTFT, you'll have to compile it such that whatever library it uses for its graphics can see and use framebuffers, then run it with the correct framebuffer. I think I remember fb1 (in /dev/fb1) being the correct one, but it may be fb0.

I actually never got that to work with gpsp so I just looked around in the gpsp source code until I found the method that takes the emulated frame buffer (the image about to be drawn) and draws it. Then I resized and centered that image in a new buffer sized correctly for the PiTFT, opened the PiTFT's framebuffer (again, I think in /dev/fb1) as a file, and wrote the image. That however requires that you can program in whatever language the emulator is written in and are comfortable editing and compiling its source code. It's also slow, and if you saw the method I wrote would show my own unfamiliarity with C's file IO.

As for resizing and framing, I don't really know how, although you might try taking a look at the fbset command. You can find the fbset manual pages here (http://linux.die.net/man/8/fbset). However, using fbset may make gamera or the emulators not work since they both probably expect a framebuffer of a certain size. If however you got a gameboy emulator working by rewriting some of its source code, you could choose to move the image around and transform it any way you want provided you can program it in the emulator's language.

I realize both of my replies are decently complicated, but it's tough getting these emulators to play nice framebuffers! Sorry.

User avatar
dinobot9bbq
 
Posts: 1
Joined: Thu Jun 25, 2015 7:03 pm

Re: Adding support for gpsp to CupCade + NES with the PiTFT

Post by dinobot9bbq »

I know this has probably been long forgotten about, but I recently bought all components to build Adafruit's PiGRRL, and I want to play GBA games on it. I download the "emulator" file and tried to follow your instructions but was confused. Do you think you can make a video or explain a little bit more clearly? I have pretty much no knowledge of this stuff, just want to play GBA games on my PiGRRL. Being able to play Gameboy Color games also would be ideal if that's in some way an option, just in case. Thanks!

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”