ramapcsx2 / gbs-control

GNU General Public License v3.0
771 stars 110 forks source link

Wrong scanline on 240P (chroma not darkened) #458

Closed ArcheyChen closed 8 months ago

ArcheyChen commented 1 year ago

I get a prebuild gbsc, and try using it to connect my ps1 to a CRT monitor with VGA input.

while there is an option to turn on the scanline, the line that was supposed to be black didn't go completely black.

It looks like a filter aiming to have a crt-like display on LCD, but display wrong on crt.

Any option to make the scanline completely black?

ArcheyChen commented 1 year ago

I look the code, and it seems like GBS::MADPT_VIIR_COEF::write(0x08); write some param to the VIIR filter.

I don't know what a VIIR filter is, but based on its name, it looks like a V-IIR filter, which will blend the lines.

That can explain why even I turn the scanlineStrength to zero, I still see colors at the line that suppose to be completely black

Am I correct?

ArcheyChen commented 1 year ago

also, with some google, I found that 240p@120 hz will make crt display scanlines( 240p@60hz can't display on many crts)

it can also increase the brightness.like: https://imgsli.com/MTE2MDQ

and dooklink/gbs-control repo has a double scan mode set.

don't know the relation between these two projects, but can you add 120hz support as well?

https://github.com/dooklink/gbs-control/blob/master/settings/RGBHV_320x240%40120Hz_RGB_240p60.set

ArcheyChen commented 1 year ago

        GBS::MADPT_VIIR_COEF::write(0x00);                     // 2_27 VIIR filter strength
        GBS::MADPT_Y_MI_OFFSET::write(0); // 2_0b offset (mixing factor here)

I turn these 2 params to 0, but it will still blend the colors.

I noticed that the white and yellow color seems fine, but red and blue will mix to blank lines.

Is this a software issue or a hardware issue?

Any chance to fix it?

ramapcsx2 commented 1 year ago

Hey, please realize that these scanlines aren't an intended hardware feature, but an interesting exploit. :) And as such, feel free to tune anything you see to your liking, but don't expect any form of "correct" look or anything. Pick what looks fine.

ArcheyChen commented 1 year ago

Hey, please realize that these scanlines aren't an intended hardware feature, but an interesting exploit. :) as such, feel free to tune anything you see to your liking, but don't expect any form of "correct" look or anything. Pick what looks fine.

Can you tell me how does the scanline filter work?

I can't find any document, and I don't know what will happen if I change the registers.

I can only see the code that changes the registers, but didn't find a code that uses it.

I couldn't find the Vram either, dose gbsc use a Vram?

Like, what will I need to do if I want to draw something on screen?

I will be glad if you can provide some link to the document, thanks.

ramapcsx2 commented 1 year ago

You have the right idea how this thing might work, but you're asking the wrong person to confirm or deny any details. I basically toggled bits when exploring the ASIC register space, and this register had an interesting effect. This is saying, I found this useful bug by accident, and some other registers would affect the scanline look. I can guess that the hardware is trying to blend fields, one of which would be from non-configured DRAM, and that one might be a black line.. but that's the best I can do as well :)

nyanpasu64 commented 1 year ago

First you're probably better off switching to 1280x960 output and enabling "line filter" for (IMO) optimal scanline appearance. Then try pressing the "intensity" button next to "scanlines" until the dark lines become dark enough for your tastes.

nyanpasu64 commented 1 year ago

Is the problem fixed and working to your satisfaction? If so, could you close the issue to avoid cluttering the issue list?

ArcheyChen commented 1 year ago

Is the problem fixed and working to your satisfaction? If so, could you close the issue to avoid cluttering the issue list?

Actually, no.

pressing the "intensity" button next to "scanlines"

this will dark the lines, but not completely black.

nyanpasu64 commented 1 year ago

I did testing on 240p Test Suite's "Color Bars". Interestingly, with Scanline Strength: 0, I get colored lines between adjacent red lines, and adjacent blue scanlines (less so on green), but none on white areas. Is this consistent with your observations? (EDIT: Reading your earlier messages, it seems correct.)

I think this occurs because the dark lines (emulated scanline gaps)' luma is properly sourced from a black "virtual previous field" (producing dark lines between input lines), but chroma is incorrectly blended between adjacent lines on the current field (causing dark lines to pick up the dominant color of their adjacent lines). I don't know if this can be fixed, and don't have time to look into it at the moment.

ArcheyChen commented 1 year ago

and what about 240P@120hz? I see the dooklink version has a profile of 120hz, is is possible porting it to this repo?

nyanpasu64 commented 8 months ago

I found that uncommenting both code blocks labeled by "following lines set up UV deinterlacer", fixes scanlines such that blue lines are properly darkened. The code was added in https://github.com/ramapcsx2/gbs-control/commit/81a0d53a17b1dafedc5fae9afd7ea2f8f755c27f, but commented out from the get-go.

IMG_20231030_044715

I don't know if there are negative side effects to uncommenting these lines; for example rama mentioned something like 1 frame latency in chroma or luma deinterlacing? @ramapcsx2 do you remember why you commented-out this code initially?

        // following lines set up UV deinterlacer (on top of normal Y)
        GBS::MADPT_UVDLY_PD_SP::write(0);     // 2_39 0..3
        GBS::MADPT_UVDLY_PD_ST::write(0);     // 2_39 4..7
        GBS::MADPT_EN_UV_DEINT::write(1);     // 2_3a 0
        GBS::MADPT_UV_MI_DET_BYPS::write(1);  // 2_3a 7 enables 2_3b adjust
        GBS::MADPT_UV_MI_OFFSET::write(0x40); // 2_3b 0x40 for mix, 0x00 to test
        GBS::MADPT_MO_ADP_UV_EN::write(1);    // 2_16 5 (try to do this some other way?)

Looking at the register docs:

Apparently MADPT_UV_MI_OFFSET is a 7-bit "is pixel moving" index, where low values weave the previous "field" (black) with the current one (as if the scene was still), and high values interpolate adjacent scanlines on the current field (as if the scene was moving).

...

nyanpasu64 commented 8 months ago

@ArcheyChen do you want to test #508? (git fetch && git checkout fix-chroma-scanlines)

ramapcsx2 commented 8 months ago

Oh I don't remember any reasoning for any of the values. Try to make it look good, test it on some other displays and other source consoles, and it'll be fine? A lag test setup will be required to tell if the changes add any more latency.

nyanpasu64 commented 8 months ago

Try to make it look good, test it on some other displays and other source consoles, and it'll be fine? A lag test setup will be required to tell if the changes add any more latency.

https://github.com/ramapcsx2/gbs-control/pull/508#issuecomment-1788758345