240p and mame scaling
@arkive A/V Composite Cable - 3.5mm to 3 x RCA. Both Mame2003 and FBA do the same thing.
A Former User last edited by
@chizzer Maybe you should try Advance MAME. @sirhenrythe3rd in this thread https://retropie.org.uk/forum/topic/11352/running-advance-mame-with-pi2scart was successful, judging by the photos, and he didn't mention any scaling artifacts (like that "shimmer" either). Similar to you he connects by composite.
@arkive Thanks for that. I'll have a look. :)
A Former User last edited by
@arkive Yes. I recommend those options over 3.5mm to composite any day.
A Former User last edited by A Former User
@arkive Sadly no. I don't own a Crt myself yet. But Pi2Scart or even better RetroTINK is the best viable option i would recommend over the built-in support over composite using 3.5mm.
If you have another look at RetroTINK there are links and information related to horizontal resolution. non-integer scaling artifacts etc.
Galaga last edited by
@chizzer Seems like 240p isn't the easiest thing to get working. Having some issues myself xd.
ghogan42 last edited by
Hi, I realized that there wasn't a decent guide to getting good quality out of the 3.5mm jack's composite output so I decided to write something up. Keep in mind that I've actually switched over to using svideo and component out of a retrotink myself, but the native composite is actually ok if you set it up correctly. So here it is from the beginning even though everyone in this thread has done some of this already...
SHORT (haha) METHOD: This is what you would need to do from a freshly imaged RetroPie 4.2 to get decent 240p set up.
(1) Boot up RetroPie for the first time. Doesn't matter if you use a CRT or hdtv
(2) Setup WiFi using a USB keyboard
(3) Press f4 to quit emulationstation
(4) Run the following commands at the command prompt to install the newest firmware. It takes a little while
sudo apt-get install rpi-update sudo rpi-update sudo reboot
(5) You're mostly done with the the rpi itself. But you need to disable overscan. You can do this through a menu from emulationstation. Or you can pop the sd card into a card reader and edit the config.txt to add/edit this line:
(6) Boot up your Pi again. We'll do everything else over the network. I'm assuming you can access your PI via a windows PC by navigating to "\\RETROPIE" in explorer.
(7) On your PC, download and extract the zip file PI_FILES_240P from here:
(8) You need to put these files in the correct locations over the network. Here's where to put them:
\\RETROPIE\configs\all\retroarch.cfg \\RETROPIE\configs\all\runcommand-onend.sh \\RETROPIE\configs\all\runcommand-onstart.sh \\RETROPIE\configs\all\retroarch\shaders\pi_iq_horz_nearest_vert.glslp \\RETROPIE\configs\all\retroarch\shaders\shaders\pi_iq_horz_nearest_vert.glsl \\RETROPIE\configs\all\retroarch\shaders\shaders\pi_iq_horz_nearest_vert_GBA.glsl
(9) Make core by core tweaks (or game by game for arcade games) in the following way. You MUST do this if the core you're running is outputting 240 vertical pixels (and not 224).
(a) Load the rom for the system.
(b) Press select+x for the Retroarch menu
(c) Navigate to settings and then video
(d) Change any options.
Specifically, you will need to edit "Custom Aspect Ratio Height" to 480 for some cores. Usually if it says "224 (2x)" and not "224" than 224 is the correct setting and if you change it to "480" and it adds a "(2x)" to get "480 (2x)" than 480 is correct. But not always... You need to verify that there are no scaling errors in the game. If you do change a core to 480, you will also have to set "Custom Aspect Ratio Y Pos" to 0. The equivalent settings for the horizontal scaling and position should be set to whatever looks good on your TV.
(e) If you've changed any options in the last step you need to save them. Back up to the base retroarch menu and go to "Quick Menu" and select "Save Core Overrides" or for arcade games "Save Game Override"
(a) For best results you should go into "Quick Menu" and "Options" for most cores and disable any overscan cropping settings you see. If you do, you may need to set the height from 448 to 480 if the texture height changes!
(b) If you use the nestopia core for NES, you might try my palette that is the average of a couple of palettes that I like (FBX, wavebeam, and a shift towards the SONY ntsc decoder). The file is here: https://drive.google.com/file/d/0B5_cUiAJwMMvU0Y2LWpVWTVPN1U/view?usp=sharing
and you put it in the \RETROPIE\bios folder. Then you can select the "custom" Palette from the "Quick Menu", "Options" menu.
(11) That's it??!!?
Here's a picture of the result. It's a blurry phone picture but you get the idea
Here is a much longer post where I break down what exactly is edited in some of these files and why. If you have your 240P setup mostly working then you might only need to make a few changes and not follow the guide I wrote above.
I lost an earlier post with more information/explanation than this, but if anything doesn't make sense than just let me know. I'm going to refer to paths as the path over SMB on the network. So "\RETROPIE\configs\all" is the main congiguration directory. If you are navigating the native filesystem, you'll have to look up the actual paths...
First of all, I'm assuming you have your config.txt set up properly. In this case, I mean that you have a both the correct video mode set up and have overscan disabled in config.txt. I recommend that you actually set it for 480i in config.txt because imo it's nicer to have emulationstation at 480i and just switch to 240p when you load emulators.
Second, if you do want 480i emulationstation and 240p emulators than you need to create (or download mine) a file: "\\RETROPIE\configs\all\runcommand-onstart.sh " that contains the line:
tvservice -c "NTSC 4:3 P" ; fbset -depth 8 ; fbset -depth 32; tvservice -s
and a file "\\RETROPIE\configs\all\runcommand-onend.sh" containing the line
tvservice -c "NTSC 4:3" ; fbset -depth 8 ; fbset -depth 32; tvservice -s
That should take care of the resolution switching you need. And now your emulators will see a resolution of 720x480 of which half of the lines are discarded and shows up as 240P.
I think that this is where most of the people in the thread are already. But there is more work to do to get decent quality. There are two issues: horizontal scaling and vertical scaling. Basically it's like this:
(a) Horizontal scaling needs to NOT be nearest neighbor. If it is, you'll get shimmer during horizontal scrolling because certain pixels will be doubled. You can take care of thus in a pixel shader (BEST) or by enabling bilinear filtering (NOT GREAT). But bilinear will mess up the vertical scaling. Also, integer scaling is NOT a good option for horisontal scaling because very few resolutions will go evenly into the ~680 or so pixel width that will be visible on your TV.
(b) Vertical scaling needs to be a nearest neighbor integer scaling. If you don't have nearest neighbor scaling, than you'll get blur. If you do have nearest neighbor scaling, but it's not integer scaling (1x, 2x, 4x, etc) than you'll get doubled pixels and bad vertical scrolling.
So THE ONLY WAY to get decent quality that I know of is as follows:
(1) Use a pixel shader that properly does the horizontal and vertical scaling. I wrote one that does this using the algorithm here for horizontal scaling: http://iquilezles.org/www/articles/texture/texture.htm And for vertical scaling it's just nearest neighbor.
You can download my shader (pi_iq_horz_nearest_vert.glsl) at the link below.
Where to put shader: \\RETROPIE\configs\all\retroarch\shaders\shaders.
Shader Download: https://drive.google.com/file/d/0B5_cUiAJwMMvOG9saVlSb01VMGc/view?usp=sharing
So you will have this file now on your pi: \\RETROPIE\configs\all\retroarch\shaders\shaders\pi_iq_horz_nearest_vert.glsl
If you want GBA emulation, you might download another shader too. It's the same but adjusts the gamma because the GBA has around 3.0 for it's screen gamma.
It's here: https://drive.google.com/file/d/0B5_cUiAJwMMvdHFPUzVCVjZOQnM/view?usp=sharing
(2) Set up your emulators to use the shader AND set the the video options with the correct scaling sizes. I'll show you how to set up RETROARCH cores, but I'm sure there is a way to do MAME too. Look at this picture here. This is the old retroarch menu but the new one has the same options if that's the one you use...
(a) In "Quick Menu" you need to go to "Shaders" and set it up so that:
"Shader Passes" is "1"
"Shader #0" is your shader file. (You'll need to nevigate to the correct file. It should be something like: )
"Shader #0 Filter" is "Linear" (The horz. scaling relies on the fact that we fetch bilinear samples...)
It doesn't hurt to select "Save Core Preset" when you're done here.
(3) Back at the main setting window, go to "Settings" and then "Driver" and make sure the video driver is "gl" and not "dispmanx" or some other option. We can't run our shader otherwise.
(4) Back at the main setting window, go to "Settings" and then "Video". You have a lot to do in here. And every emulator is potentially different. Set the following:
"Aspect Ratio" to "Custom"
"Custom Aspect Ratio Width" to a width that covers your TV screen. It will be somewhere between 640 and 700. I only have studio monitors that don't have much overscan so I can't tell you exactly what number.
"Custom Aspect Ratio Height" to "480" or "448" This depends on the specific retroarch core (and it's overscan settings) but it will be one of these 95% of the time. Usually (but not always) it will be the number that says "2x" next to it when you set it, This indicates that retroarch thinks you've chesen an integer multiple of the vertical resolution. But sometimes retroarch is wrong...
"Custom Aspect Ratio X Pos." is whatever centers the screen left/right for you.
"Custom Aspect Ratio Y Pos." is whatever centers the screen up/down for you. It's probably 0 if you're the height is 480. And 16 if yo're at 448.
(5) Back at the main settings menu, go to "Quick Menu" and then select "Save Core Overrides"
And that should be one Retroarch Core down. Others can be done similarly. To save time, you might want to edit the default retroarch.cfg with your best guesses for these options before starting. If so, what you want to is go to "\RETROPIE\configs\all\retroarch.cfg" and change the following settings. You might have to add a couple of them don't already exist:
video_smooth = false
video_crop_overscan = false
video_driver = "gl"
video_shader_enable = true
video_shader_dir = "/opt/retropie/configs/all/retroarch/shaders/"
video_shader = "/opt/retropie/configs/all/retroarch/shaders/pi_iq_horz_nearest_vert.glslp"
aspect_ratio_index = 22
video_fullscreen_x = "720"
video_fullscreen_y = "480"
custom_viewport_width = "660"
custom_viewport_height = "448"
custom_viewport_x = "25"
custom_viewport_y = "16"
@ghogan42 Thanks man. That worked great. I love the script that switches between 480i and 240p. Ideal for emulationstation.
@ghogan42 Nice Guide with alot of information! Would you mind making this avaliable to the author of RetroThink and Pi2Scart?
ghogan42 last edited by
@rion Probably the only thing that will be new to them is the shader that I use to do proper horizontal scaling without messing up the vertical scaling (or non-scaling actually). At least, when I use the RetroTink, that's the only part of this that I use.
The reason for that is with those pieces of hardware, you usually use hdmi modelines for resolution switching. And then they set a high horizontal resolution like 2048x240 when the emulator loads, and then just do nearest neighbor scaling on both axes. At a high enough resolution, uneven scaling isn't visible anymore. We can't do that at 720x480 because the bad scaling is obvious. To be on the safe side, I still use my shader anyway, but if you have a RetroTink I don't think you really need to.
So basically with the RetroTink, the shader is optional, the resolution switching on emulator start/stop uses different commands, and the specific numbers in the retroarch.cfg would be completely different.
So they might find it interesting, but I don't know if any of it would be useful to them. Maybe I can go post a link in the discord channel that some RetroTink people use if I can find it.
@ghogan42 Yes that would be great. The more places your shader will be posted the easier it will be to find it along the road if the link will go down.
a_piori last edited by
@ghogan42 I realize this thread is old as hell now, but I wanted to ask if you would be amenable to including your guide and config files/scripts etc. into a good stable location like GitHub? I would be willing to put it there if you need help.
I ask because it took me forever to find advice to set up the retropie for a CRT tv, and yours is really the only comprehensive advice out there. As someone else hinted at, it would be a shame if your great info was lost.
If you're interested please let me know. I tried to PM you but just joined the forum so not sure if I don't have enough cred or if PMs are globally disabled.
youxia last edited by
This guide is great but it's meant for those using composite connection. So, it's not really for RetroTink, Pi2SCART or other RGB devices since they use their own solutions, there's no need for shaders.
I'd say, why not make a separate Retropie Wiki entry dealing with CRT TVs and make this a Composite subsection. I had it in mind for a long time but I'm snowed in with other projects and RL stuff.
zefolhadela last edited by
@ghogan42 so you are saying you already upgrade your retropie with a retrotink, which means got that godlike scanlines and fix res resolution right? what i am asking is if something like retrotink or a pi2scart is really a good choice for a better compatiblity and quality overall. thanks
kcorcoran last edited by
WIthout going into every game in MAME and doing per game settings for vertical and horizontal games, is there a way to set up all horizontal games with one setting and all vertical games with another?
Then when I'm in individual games, if they don't look right, I can tweak them but they'd generally be close to start.