raspberrypi / firmware

This repository contains pre-compiled binaries of the current Raspberry Pi kernel and modules, userspace libraries, and bootloader/GPU firmware.
5.11k stars 1.68k forks source link

Support for progressive PAL60 in config.txt/sdtv_mode #811

Open manekinekodesu opened 7 years ago

manekinekodesu commented 7 years ago

I use my Raspberry Pi 3 to emulate consoles. And my crt tv only supports PAL/PAL60 modes. Most games were not/badly optimized for PAL 50 Hz mode. And PAL60 can be used to play NTSC content full screen and full speed, as it was meant to be played.

JamesH65 commented 5 years ago

OK, I'm taking a look at this, but but appears will have to redo the work of before as the code seems to have gone missing. Think I have a general handle on it, so hopefully will match what @popcornmix did before. Need to find a composite monitor, haven't seen one of those for years (someone above said they are prevelent - not around here!). Might have one in the loft at home.

elfoam commented 5 years ago

That would be awesome JamesH65. CRTs are becoming hugely collectable right now, there is still plenty around for gamers but you have to hunt them out. Rather than have to get a SCART hat for the Pi, PAL 60 would overcome a lot of the dodgy picture quality NTSC gives over composite. I've kinda moved on myself as I'm looking for more high end picture quality and I'm using Nintendo Wiis over component and RGB and also building some SCART hats for the pi. But for guys that are starting out on CRT gaming with a Pi PAL 60 on composite would be very nice. I'd be happy to help with any testing on the 3b+

AlistairThom commented 5 years ago

Thanks for taking the time to look at this @JamesH65

I’d be delighted to test your code with the equipment I’ve got here, especially if it will save you a trip to the loft!

I’ve got a CRT, which I know supports both PAL and NTSC, and a modern-ish projector with a composite port which should give me information on the compostite signal it’s receiving, as a sanity check.

Pi wise, I’ve got a 3B, 3B+, and the first B model.

Thanks again.

JamesH65 commented 5 years ago

OK, so have something that appears to be PAL60, firmware here https://drive.google.com/open?id=1B-tlXmTXxJ5xYrFFS85Def2f85YSvp18

Please try out and report back.

AlistairThom commented 5 years ago

Thanks @JamesH65

I’ll be able to test shortly. Which sd_tvmode should I use? 19?

shaum257 commented 5 years ago

@JamesH65 I tried the firmware you have published and it's still 50HZ. I even tried setting the sdtv_mode to 0x22 and it still gives me 50HZ ingame. And another thing is that you have only published the start_x.elf file whereas @popcornmix published more files than just start_x.elf for the firmware but yeah as I said, I tried the firmware without any success. It could be that I've missed something. I just don't know what else to do.

JamesH65 commented 5 years ago

To use start_x.elf you need to have start_x=1 in config.txt othereisse it will use start.elf. Might be some other files I need to supply, will check.

I tested mode 0x22, which should be NTSC carrier with PAL colour at 60Hz. It's the 0x2x but that is important - that swaps the NTSC/PAL settings as Dom I think described above.

JamesH65 commented 5 years ago

Dom did appear to make other changes to do with porches, I've not done that. When I tested on the composite monitor I have here, tvservice -s claimed PAL on NTSC at 60Hz, and the sync on the monitor was correct.

shaum257 commented 5 years ago

@JamesH65 You are a genius. By following your instructions and also by setting the sdtv_mode to 0x22 it now finally shows 60HZ in the retroarch menu instead of 50HZ when going to the video options. Now I am able to play every game in 60HZ with PAL colours without any compromises and I couldn't be happier. Thank you very much for everything!!! :)

JamesH65 commented 5 years ago

I think genius is a bit strong, but I'll take it. Glad it's working. Would appreciate any other testers with different composite kit giving it a once over.

Note, I do not believe this works in progressive mode (0x32) but worth trying.

AlistairThom commented 5 years ago

I've only had chance to do a very quick test, but so far, so good in both 0x32 progressive, and 0x22 interlaced modes on my CRT. I'll be able to dig deeper at the weekend.

Forgive the pun, but this is game changing.

Thanks again James.

JamesH65 commented 5 years ago

That's good news, wasn't sure about progressive. Will need some testing from other people on other devices, but since this is an entirely backwards compatible change, I'm sure it will go in the release firmware fairly soon.

elfoam commented 5 years ago

Very nice, I have had a quick look tonight but couldn't get it to run at 60hz yet on my 3b+ , PAL colours are working. My retroarch is showing 60hz but the pi is running at 50, Retroarch isn't giving me video options though like it does on the Wii and being over 40 celcius here today.. I can't deal. I will check it again tomorrow once it cools down to see if I can figure it out :)

On Thu, Jan 24, 2019 at 8:58 PM James Hughes notifications@github.com wrote:

That's good news, wasn't sure about progressive. Will need some testing from other people on other devices, but since this is an entirely backwards compatible change, I'm sure it will go in the release firmware fairly soon.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/raspberrypi/firmware/issues/811#issuecomment-457137218, or mute the thread https://github.com/notifications/unsubscribe-auth/AmdGQDkZYHHQxuZiveZ2dne-4RGE9Gsvks5vGYOvgaJpZM4Nh6dl .

JamesH65 commented 5 years ago

If PAL colours are working and you have 0x22 for the mode, and you have start_x=1 in config.txt, then I cannot see how it cannot be running at 60Hz. 0x22 is basically NTSC60 with PAL, so will be running at 60Hz.

elfoam commented 5 years ago

Yeah I must be doing something wrong, I hashed out start_x=1 and nothing is any different than with it enabled. So it seems to be not loading that new video code.It's definitely running in 50hz, I have a very good eye for that, can see it from a mile away.

These are the relevant changes I've made on the 3b+

-rwxr-xr-x 1 root root 3941508 Jan 24 22:16 start_x.elf -rwxr-xr-x 1 root root 4047876 Oct 8 07:40 start_x.elf.bak

start_x=1

60hz PAL 480i

sdtv_mode=0x22

I can switch it to NTSC and it runs 60hz no problem

Maybe I need to update the firmware on the pi or something I haven't used it in a while so it might not be on the same spec you guys are running. I'll try that.

On Fri, Jan 25, 2019 at 12:04 AM James Hughes notifications@github.com wrote:

If PAL colours are working and you have 0x22 for the mode, and you have start_x=1 in config.txt, then I cannot see how it cannot be running at 60Hz. 0x22 is basically NTSC60 with PAL, so will be running at 60Hz.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/raspberrypi/firmware/issues/811#issuecomment-457189077, or mute the thread https://github.com/notifications/unsubscribe-auth/AmdGQOnY77h80Pi2rcLX_hGNuEY3kLHOks5vGa9ggaJpZM4Nh6dl .

JamesH65 commented 5 years ago

Odd. Not sure what that can be, When you do vcgencmd version what numbers do you get out? Date and size look correct though...

elfoam commented 5 years ago

I updated the firmware and nothing changed other than my networking is now broken, something about a not connected by UART (hard to tell at 240p, I'll have to try and fix that tomorrow on a HDMI display so I can read exactly what broke on the update). I will have to get a pen and paper to write down this version number... Ok The version number is 628a079674.. etc (I ran out of pencil patience and the overscan is wonky) but that should tell you what I'm on. The other one when I have start_x=1 disabled is 7BF etc. I have a few TVs here to test this on. The current one I have it plugged into can not display NTSC and gives me a 60hz black and white picture in NTSC mode, this is the kind of set it would be perfect for if I could get it to work. But I have a more modern set that can do all formats also which I'm also testing it on.

JamesH65 commented 5 years ago

Odd, the change has nothing to do with networking (it's not handled by the firmware at all). Probably some dt blob parameters or something.

I tested on a Philips CM 8833 CRT, NTSC came up in B/W, but went to colour when used mode 0x22. Pi thought it was output PAL at NTSC resolutions and 60fps.

That version number appears correct. Odd.

elfoam commented 5 years ago

Well that's what I see also except it's 50hz, How good is your eyeball for 60hz ? or did your TV show up 60hz on the on screen display?. Not saying for sure that you mistook 60 frames for 50 but I think lots of people could make that mistake if you don't have an aversion for none perfect scrolling like I do :)

JamesH65 commented 5 years ago

I have no way of checking the actual frequency, but the Pi itself said it was outputting 60Hz, and the code was set up for NTSC resolution, but I was getting colour on the device which originally showed B/W when its was pure NTSC. It's certainly possible that it's not right of course!

What does tvservice -s report?

I get No mode set (default NTSC - B/W) [NTSC 4:3], 720x480 @ 60.00Hz, Interlaced

Mode 0x02, COlour [PAL 4:3], 720x576 @ 50.00Hz, Interlaced

Mode=0x22, Colour [PAL 4:3], 720x480 @ 60.00Hz, Interlaced

elfoam commented 5 years ago

Yep I get those same readings, but it isn't true. I have some TV's here which will report how many HZ they running at. I already know it's running at 50hz because I can tell from the scrolling in the games, when you are ex demo scene Amiga you can see this :), I'm 1000% positive. I have an idea to prove it though, if I use one of my Sony Trinitrons it will report how many HZ it's running at in service mode. I'll be back with a picture..

elfoam commented 5 years ago

Here you go, 50hz

img-20190125-00750

popcornmix commented 5 years ago

@JamesH65 you can measure framerate with vc_dispmanx_vsync_callback See second example program here: https://github.com/raspberrypi/userland/issues/218

Sobakin76 commented 5 years ago

I downloaded start_x.elf and replaced original file (just did rpi-update before this). added start_x=1 to config.txt and sdtv_mode=0x22, also tried 0x32 for progressive. "tvservice -s" says it was PAL 720x480 60Hz, but for sure really it was PAL 720x576 50Hz. Just watch first picture below (it's in 0x32 mode, but in 0x22 it's the same just interlaced), this is on JVC TM-H150C monitor. There is 36 text lines of "8x8 vga" font pixel to pixel, showing 288p mode available only at 50Hz scaling_kernel=8 framebuffer_height=288 overscan_top=-32 overscan_bottom=-32 jvc

Second picture from Hitron 15" CRT monitor (sdtv_mode=0x22) which I manually set to NTSC mode and picture is out of sync instead just go to B&W, in auto mode its works normally as PAL (exposure is 1/10s): hitron

@popcornmix in May 2017 uploaded firmware files and in 0x22 mode on JVC monitor (which detects sync and color system independently) all worked with some flickering (more than just like normal interlaced), but in progressive mode 0x32 it gone out of sync, Hitron monitor on 0x22 autodetected NTSC and displayed B&W picture (so it cannot display PAL60 in color but 100% is PAL-M capable, it has this mode in menu). Model is RPi 3B.

JamesH65 commented 5 years ago

OK, looks like something isn't right, I'll quickly do the test @popcornmix mix has suggested and see what comes up.

JamesH65 commented 5 years ago

So, yes, its 50Hz. I just don't know yet why tvservice -s says its 60Hz! Or indeed why its not 60Hz! Will keep looking.

manekinekodesu commented 5 years ago

This is great news @JamesH65! I'm also ready to test new firmware on my RPi 3b and two ctr TVs. On previous firmware versions by @popcornmix progressive PAL60 almost worked (240p 60Hz with PAL color) but it just would not sync properly. I assume there is no way to fine tune porches manually for composite video output.

JamesH65 commented 5 years ago

I've just uploaded a new version of start_x.elf, can anyone give it a go? Not sure about this one, the monitor I have here might not be able to cope with PAL-60.

Yes, the porches can be tuned, woudl be a bit of effort as the code doesn't lend itself to changes of that type, but not impossible.

elfoam commented 5 years ago

James, seems something is broken deeper in the code. My TVs which can't display NTSC colours (and wouldn't want to even if they could) are wishing you the best of luck so they can live a productive life on retroarch :)

On Fri, Jan 25, 2019 at 11:08 PM manekinekodesu notifications@github.com wrote:

This is great news @JamesH65 https://github.com/JamesH65! I'm also ready to test new firmware on my RPi 3b and two ctr TVs. On previous firmware versions by @popcornmix https://github.com/popcornmix progressive PAL60 almost worked (240p 60Hz with PAL color) but it just would not sync properly. I assume there is no way to fine tune porches manually for composite video output.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/raspberrypi/firmware/issues/811#issuecomment-457553371, or mute the thread https://github.com/notifications/unsubscribe-auth/AmdGQJ1VBal6qIAh-TuPOIi-ppR3iQwgks5vGvOkgaJpZM4Nh6dl .

elfoam commented 5 years ago

I've just uploaded a new version of start_x.elf, can anyone give it a go? Not sure about this one, the monitor I have here might not be able to cope with PAL-60.

Will give it a go soon @JamesH65 (I got a VGA CRT today so I'm trying to get that looking good at 240p 120hz at the moment. Bit excited)

JamesH65 commented 5 years ago

Probably best not to get excited. Found some bits in the code where I hadn't taken the switch in to account, so have fixed up that, but still not convinced it will work.

JamesH65 commented 5 years ago

Ah, don't bother with that one, 6by9 just spotted a bug in the code. We now appear to get PAL over NTSC, but it's not syncing. Will investigate further.

Sobakin76 commented 5 years ago

Just replaced start_x.elf for new, and now it's pure NTSC 240p/480i 60Hz and NTSC color with standard NTSC color artifacts, and JVC's monitor's autodetection says it's NTSC (it's saying about color system, for PAL colors it should say "PAL" for both 50 and 60Hz). In this picture sdtv_mode=0x32 (progressive), at 0x22 colors the same, just interlaced. jvc_ntsc

pi@raspberrypi:~ $ vcgencmd version Jan 25 2019 12:49:50 Copyright (c) 2012 Broadcom version cf3d773ad691f98695e09cdb9d83c9fbe8cf86a3 (tainted) (release)

JamesH65 commented 5 years ago

OK, can you try the one I just uploaded? I suspect that might be OK.

Sobakin76 commented 5 years ago

@JamesH65 I tried, now it works in interlaced 0x22 mode (JVC monitor says it's PAL and for sure it's 60Hz), but again with some flickering which is more than just interlace flickering. And at 0x32 it again out of sync, all seems like @popcornmix's firmware 2 years ago. Hitron monitor at 0x22 displays B&W picture (and goes out of sync at 0x32 too), so it doesn't support PAL colors at 60Hz, only PAL-M. Or PAL at only 50Hz. I can make video if it could help.

JamesH65 commented 5 years ago

OK. That's progress. Unfortunately popcorn mixes changes were lost before they were merged to mainline firmware so we are working our way back to that.

I think the problem is with the front and back porches, maybe sync width. Anyone know what they should be for PAL-60?. If I use the NTSC values I get the skewing reported above. By changing the FP I can stop the slew, but there is an apparent flicker, so would be useful to know the correct values. Wikipedia doesn;t seem to have anything specific.

Sobakin76 commented 5 years ago

I know nothing about this, I just know that scanline rate and each line timings almost the same for 50 and 60Hz, just 50Hz fitted proportionally more lines for each frame, why not using PAL values for h-syncs and porches for PAL60?

Sobakin76 commented 5 years ago

This is Midnight Commander at sdtv_mode=0x32 (progressive), looks like h-sync is ok, just v-sync problem? Picture taken with long exposure: 0x32

The same picture (with colors!) at Hitron monitor

upd: Just tried 0x30 mode (It should be NTSC 50Hz?), and there was out of both h-sync and v-sync. At mode 0x20 picture rolled down and skewed, but steady (each frame is equal).

JamesH65 commented 5 years ago

Odd. AIUI, PAL60 is actually NTSC timings but using the PAL colour scheme, so effectviely I am using slightly adjusted NTSC settings. I've now modifed the firmware so the timings can be set in config.txt, which should make it easier to test at this end.

shaum257 commented 5 years ago

@JamesH65 I tried the updated version of your firmware and it flickers from the top. Could you please re-upload the very first start_x.elf firmware file which you uploaded 2 days ago, as it was that one which worked perfectly for me. The thing is that I accidentally deleted your first version of start_x.elf firmware file on my PC.

elfoam commented 5 years ago

@JamesH65 I think you are going to find the video code in the 3b+ is just completely broken and that's why what you are trying to do isn't working. Right now I've got a VGA 666 hat outputting RGB on my pi zero and one on my 3b+. Same config on both machines and the 3b+ is chugging roughly at 50hz while the zero is running smooth 60hz..... I'm using forced timings and the monitor tells me it's running at 60hz but the 3b+ isn't. I don't think it's ever worked. But the good news is maybe now it can be fixed. If I'm right I think you should try your code on a pi Zero.

manekinekodesu commented 5 years ago

@JamesH65 I've tested new firmware with the following results:

0x20 - Ntsc color, no sync(scew+roll)
0x22 - Pal color 60Hz, Strange reddish blinking on top of the screen(same as before)
0x30 - Ntsc color, no sync (scew+roll)
0x31 - Same as 0x30
0x32 - Pal color, no sync(roll)

How do I set timings for composite video in config.txt?

JamesH65 commented 5 years ago

You cannot do it without modified firmware, I've modified mine to allow me to change the settings in config.txt. I might upload that so people can try different values. Will discuss with boss. Might make this whole proces easier.

JamesH65 commented 5 years ago

OK, have uploaded a new firmware. This one allows setting of the composite timings in the config.txt file. Parameters are:

composite_timings=h_active_pixels h_front_porch h_sync_width h_back_porch v_active_lines v_front_porch v_sync_width v_back_porch even_active_lines even_front_porch even_sync_width even_back_porch first_field_odd

Default settings for

PAL original composite_timings=720 20 64 60 288 2 3 20 288 2 3 19 0

NTSC original composite_timings=720 14 64 60 480 3 3 16 240 3 3 16 1

For PAL-60 I use

composite_timings=720 20 64 60 240 3 3 16 240 4 3 16 1

Feel free to try different settings to see how things change, but I suspect there's not much can be done. with timings. Will continue to look at other internal parameters. Its useful to be able to SSh in when the changes mean you get an unreadable display, otherwise you need to remove the SD card and edit the config.txt in another machine.

Sobakin76 commented 5 years ago

I got progressive PAL-60 (but in sdtv_mode=0x22 which must be interlaced) with composite_timings=720 20 64 60 240 3 3 16 240 2 3 17 1 But some artifacts in display's top You can see on video (60 fps): https://youtu.be/8LBKWscY1Hg Whole config.txt of my RPi3b: scaling_kernel=8 max_usb_current=1 sdtv_aspect=1 sdtv_mode=0x22 overscan_top=-32 overscan_bottom=-32 overscan_left=8 overscan_right=8 framebuffer_width=640 framebuffer_height=240 composite_timings=720 20 64 60 240 3 3 16 240 2 3 17 1 hdmi_group=1 hdmi_mode=4 hdmi_drive=2 dtparam=i2c_arm=off dtparam=i2s=off dtparam=spi=off dtparam=audio=on gpu_mem=128 start_x=1

In mode 0x32 its out of sync It's chroma flickering, not luma - there is almost no visible flickering, then I turn monitor to B&W, but not such clear like in NTSC mode

shaum257 commented 5 years ago

Yeah I'm in the same boat as @Sobakin76 when it comes to artifacts at the top of the screen when choosing sdtv_mode=0x22 and also out of sync, so vertical rolling in sdtv_mode=0x32 for PAL progressive. Is there anything else we can do to fix this?

JamesH65 commented 5 years ago

Giving end users access to change the timing themselves to try and tweak the settings until they are right was my plan.

Sobakin76 commented 5 years ago

Looks like problem not just in timings but there are some bugs in code? I got synched progressive PAL-60 but with artifacts of display's top.

JamesH65 commented 5 years ago

The code is pretty simple, the problem may be the HW simply cannot do what is being asked of it. It was never really designed for unusual composite use, targetted more to HDMI.

Although PAL60i works on my two devices here, no sync issues. Progressive not so good, no vsync. If I have time wil try the settings above to see if things improve. Might be some other settings in the system that can be tweaked, will need to read the HW datasheet.

Sobakin76 commented 5 years ago

@JamesH65 so is there any sence to continue timings searching if now we get some for working progressive (but in 0x22 mode) or just adopt this data for work in 0x32 mode? I feel that it's impossible to get rid of this blinking artifacts by timings only, or am I wrong?