fceux (NES) port with native GLES2 rendering


27 posts   Page 1 of 2   1, 2
by Andrey » Sat Apr 06, 2013 12:27 am
Hi!)

After some hacking i'm proudly present to you subj emulator.
The main goal is vsynced PAL/NTSC video and good sound (but without uber-filters).

Get it here:
https://www.dropbox.com/s/uu751ibdqmvq0co/fceux.zip

Unpack binary from zip to some folder in your home folder.
Then remove ~/.fceux folder (if you installed fceux already by another way).
To launch fceux you need to provide rom name in command line because there is no GUI.
./fceux <rom file>

By default raspberry pi HDMI out is configured to 60Hz (NTSC).
But you can change this if you have PAL rom's and want to play in PAL mode.
In this case you need to provide --pal 1 option in command line.
Note: this option stored in config at exit, so for launching back in NTSC mode you need to provide --pal 0 option.

Also note that pixel aspect ratio is configured for NTSC mode.

edit /boot/config.txt

for PAL version (50 Hz):
720p mode:
Code: Select all
hdmi_group=1
hdmi_mode=19
1080p mode:
Code: Select all
hdmi_group=1
hdmi_mode=31


for NTSC version (60 Hz):
720p mode:
Code: Select all
hdmi_group=1
hdmi_mode=4

1080p mode:
Code: Select all
hdmi_group=1
hdmi_mode=16


(see http://elinux.org/RPiconfig for more info)

Project home page
http://www.fceux.com/web/home.html
Posts: 71
Joined: Sat Sep 01, 2012 9:52 am
by kalehrl » Sat Apr 06, 2013 7:17 am
Hi Audry
Thank you for your fceux.
I use stock fceux and with your version I get a much better picture quality.
Unfortunately, the sound is bad (crackles a lot) and the game (super mario bros.) is slowed down a bit.
I don't use HDMI but composite so those hdmi instructions you posted don't apply to me.
In my boot config I have:
Code: Select all
sdtv_mode=2
sdtv_aspect=1

When I force PAL with SDL.PAL = 1 in fceux.conf I get a slightly better sound (no crackling) but it seems garbled.
Any ideas?
EDIT:
By commenting sdtv_mode=2 and thus forcing NTSC, after reboot, the emulator works fine and the sound as well. The problem is, my CRT TV is PAL and there are a lot of artifacts like colour bleeding and picture blurring unless I use sdtv_mode=2.
Posts: 342
Joined: Tue Jul 24, 2012 10:49 am
by Vanfanel » Sat Apr 06, 2013 12:47 pm
I get perfect sound and picture quality with raspbian from back in september :D
I also don't use X at all: my Pi boots to console as intended.
I've heard latest Raspbian versions include some kind of audio crapware over ALSA, PulseAudio or whatever that's called. Maybe that's causing problems. I'd remove it.

Awesome work, Audrey! You're bringing emulators on the Pi to quality level they SHOULD be!! :D
Keep up the good work, please!
Posts: 244
Joined: Sat Aug 18, 2012 5:58 pm
by obcd » Sat Apr 06, 2013 12:50 pm
There is also a firmware change Dom added to fix the plopping when the audio driver is enabled. I think you can disable it with a parameter in the /boot/cmdline.txt. I remember reading mame4all was having trouble with it. It should be fixed for Mame now. Maybe it's related?
Posts: 890
Joined: Sun Jul 29, 2012 9:06 pm
by Vanfanel » Sat Apr 06, 2013 1:51 pm
How can I configure USB pad input, if possible at all?
I tried:

Code: Select all
./fceux --inputcfg gamepad1 mario.nes


but it doesn't work, it takes me back to the console.
Posts: 244
Joined: Sat Aug 18, 2012 5:58 pm
by kalehrl » Sat Apr 06, 2013 2:03 pm
I'd remove it.

I removed pulse audio a long time ago.
Also, I run it from the terminal.
Maybe it's related?

Dom fixed mame4all and all other emulator audio problems with his latest firmware commit a couple of days ago so it's not related.
My CRT TV needs sdtv_mode=2 in raspi config otherwise I get crappy picture quality.
But with this entry, I get audio problems with this version of fceux.
Posts: 342
Joined: Tue Jul 24, 2012 10:49 am
by Vanfanel » Sat Apr 06, 2013 6:17 pm
@obcd & kalehrl:

I've just update Raspberry Pi firmware to latest version and now I also have broken sound in fceux...
What's that cmdline.txt parameter, please?
Posts: 244
Joined: Sat Aug 18, 2012 5:58 pm
by kalehrl » Sat Apr 06, 2013 7:38 pm
I'm not sure there is a command line parameter for that.
I guess @dom would have mentioned it when he introduced those alsa sound changes.
I went back to older firmware before the alsa sound changes aimed at eliminating audio pop were introduced and I get the same audio problem as with the latest fw. That's why I think those recent alsa changes did not break anything.
Code: Select all
sudo rpi-update eeb2e51c3e08cd5efa4246aa8dc54a09b25ada12

This will revert alsa audio pop fix but, as I mentioned above, it didn't fix the audio problem I have with this fceux version.
Posts: 342
Joined: Tue Jul 24, 2012 10:49 am
by Andrey » Sat Apr 06, 2013 8:08 pm
Sometimes i got fuzzy buggy sound via HDMI.
But thit bug appears in all programs (xbmc, etc).
Fixed by turning tv off and on %) or switching to analog in and back to HDMI.
Posts: 71
Joined: Sat Sep 01, 2012 9:52 am
by kalehrl » Sun Apr 07, 2013 12:32 pm
After some more testing, I concluded that only this combination is usable:

PAL rom
PAL setting in config.txt, i.e. uncommented sdtv_mode=2
SDL.PAL = 1 in fceux.conf
The sound is sped up a bit and possibly emulation speed.

The following is perfect regarding emulation speed and sound:
NTSC rom
NTSC setting in config.txt, i.e. commented sdtv_mode=2
SDL.PAL = 0 in fceux.conf
But the problem is, my CRT TV is PAL and NTSC looks terrible on it-blurry picture, colour bleeding etc.

All other combinations of NTSC rom, sdtv_mode=2, SDL.PAL = 0 give much worse results.
Andrey, I read that your other GLES2 ports suffer the same limitations that correct video mode must be setup:
viewtopic.php?f=78&t=30889
Can this be overcome in any way?
I thought that setting all variables to PAL would make emulation perfect but it is not the case as you see from the example above.
Posts: 342
Joined: Tue Jul 24, 2012 10:49 am
by Andrey » Sun Apr 07, 2013 7:25 pm
@kalehrl

If you have PAL tv, then only settings for you is PAL mode (sdtv_mode=2, --pal 1, PAL rom's).
Strange that you have some speedup in PAL.
Normally there is some slowdown in PAL games. It's the same on real NES (watch videos on youtube with comparision).

Do not mix PAL/NTSC settings in emulator, rom and /boot/config.txt.
It's lead to strange results (crackling sound).
Posts: 71
Joined: Sat Sep 01, 2012 9:52 am
by Vanfanel » Sun Apr 07, 2013 7:57 pm
@Andrey: does this emulator sync on video or does it sync on audio? NES video is 60.1 HZ, not exactly NTSC.

If it's syncing on video, then that's why I'm getting glitchy audio. NOT exactly crackling audio, it's just that it's full of pops and small noises. Is your audio perfect?
Posts: 244
Joined: Sat Aug 18, 2012 5:58 pm
by Andrey » Sun Apr 07, 2013 8:36 pm
@Vanfanel

It's syncing by audio.
Video can jerk sometimes, when audio is run out of video.
Do you use HDMI or analog TV in?
Maybe you encountered the same problem?

Sometimes i got fuzzy buggy sound via HDMI.
But thit bug appears in all programs (xbmc, etc).
Fixed by turning tv off and on %) or switching to analog in and back to HDMI.


After fixing yes, my audio is perfect.
Posts: 71
Joined: Sat Sep 01, 2012 9:52 am
by kalehrl » Mon Apr 08, 2013 1:54 pm
Strange that you have some speedup in PAL.
Normally there is some slowdown in PAL games. It's the same on real NES

I just watched this video and indeed this is exactly the sped up audio I'm referring to:
http://www.youtube.com/watch?v=RbW0qBmv ... =endscreen
I've now learned that this is normal so I can now say that audio is as good as it can possibly be. :D
So far, I used NTSC rom and maybe I got used to it so when I tried PAL, I thought I had problem with your fceux but it is not the case.
Have you thought of porting a snes emulator?
SNES is my all time favourite games console.
If you are interested, here are the links to so far the best snes emulator on rpi (snes9x):
original palerider's version:
viewtopic.php?f=78&t=23272
modified chep's version with alsa audio and multicontrolers but with some bugs:
https://github.com/chep/snes9x-rpi
Posts: 342
Joined: Tue Jul 24, 2012 10:49 am
by Vanfanel » Mon Apr 08, 2013 7:39 pm
@kalehlr: both ports are based on the old SNES9X versions before 1.53, so if you like the snes that much you wouldn't like the results: prior to SNES9X 1.51, snes audio emulation was atrocious.
In 1.51, blargg's SPC700 emulation was merged and sound is good, but it's way too heavy for the Pi.
Posts: 244
Joined: Sat Aug 18, 2012 5:58 pm
by kalehrl » Mon Apr 08, 2013 7:58 pm
I'm aware of the sound issues but it doesn't bother me too much.
You should listen to the sound quality of snes emulator used by retroarch. :D
Snes9x gives much better sound than retroarch.
I hope that opengles2 port would give much better picture quality like it did with fceux opengles2 port by Andrey.
Posts: 342
Joined: Tue Jul 24, 2012 10:49 am
by Andrey » Tue Apr 09, 2013 1:48 pm
@kalehrl

I think snes9x to Pi porters can look at my gles2 implementation/explanation and insert it to their ports.

But i think raspberry is not capable to emulate 16-bit CPU and many custom SNES chips at full speed. This will result in dropped frames.
Posts: 71
Joined: Sat Sep 01, 2012 9:52 am
by Andrey » Tue Apr 09, 2013 3:32 pm
Posts: 71
Joined: Sat Sep 01, 2012 9:52 am
by kalehrl » Tue Apr 09, 2013 6:50 pm
snes9x-1.39 runs at full speed most of the time on the rpi overclocked to 900MHz.
It is an old snes9x without the new sound core which is CPU hungry.
Posts: 342
Joined: Tue Jul 24, 2012 10:49 am
by Andrey » Tue Apr 09, 2013 9:17 pm
Snes9x is ancient unsupported emulator.
http://www.snes9x.com/news.asp
The latest news are dated 2006 year.
Posts: 71
Joined: Sat Sep 01, 2012 9:52 am
by petrockblog » Fri May 03, 2013 4:24 pm
Is there a chance that you provide the source code for your fceux port somewhere? I am currently looking at ways for including it into the RetroPie Script.
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 260
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
by Andrey » Sun May 05, 2013 8:33 pm
@petrockblog

of course, because of GPL license :-)

there is a patch for 2823 revision (i tried to apply it to latest revision, but got conflicts).
how to build:

Code: Select all
svn co svn://svn.code.sf.net/p/fceultra/code/fceu fceux-rpi -r 2823


then unpack .diff from this attach
fceux2823-rpi.zip
(10.27 KiB) Downloaded 68 times
to fceux-rpi folder

Code: Select all
cd fceux-rpi
svn patch fceux2823-rpi.diff


I configured SConstruct file to cross-build. (because building on raspberry pi takes ~20 mins of time, it unacceptable to write-debug-test process).
You need to get toolchain here:
https://github.com/raspberrypi/tools/tr ... f-raspbian
Also you need to copy SDL headers and libs from Raspberry Pi device to this toolchain.
Then you need to export RPI_SDK pointed to the rpi toolchain root folder.
Prepare build environment:
Code: Select all
export CC=$RPI_SDK/bin/arm-linux-gnueabihf-gcc
export CXX=$RPI_SDK/bin/arm-linux-gnueabihf-g++


if you dont want to cross-build, you need to remove RPI_SDK from SConstruct and replace some values to analogues on raspberry pi device.

build it:
Code: Select all
scons
Posts: 71
Joined: Sat Sep 01, 2012 9:52 am
by petrockblog » Wed May 08, 2013 5:12 am
Thanks a lot for this detailed description :)
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 260
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
by Andrey » Thu May 09, 2013 8:03 pm
You're welcome :)

BTW, can you add other my ports to your retropie script?

viewtopic.php?f=78&t=16707
viewtopic.php?f=78&t=30889
Posts: 71
Joined: Sat Sep 01, 2012 9:52 am
by petrockblog » Thu May 09, 2013 9:00 pm
Andrey wrote:You're welcome :)

BTW, can you add other my ports to your retropie script?

viewtopic.php?f=78&t=16707
viewtopic.php?f=78&t=30889

Sure, I have added this to the issues list in Github at https://github.com/petrockblog/RetroPie-Setup/issues.
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 260
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany