ramapcsx2 / gbs-control

GNU General Public License v3.0
793 stars 111 forks source link

Don't call prepareSyncProcessor() when applying custom presets #446

Closed nyanpasu64 closed 1 year ago

nyanpasu64 commented 1 year ago

This fixes a bug where after saving and loading a custom preset on 480p input, the image would be shifted downwards because the input is sampled too early after vsync.

When we load a fixed output resolution on 480p, doPostPresetLoadSteps() first calls prepareSyncProcessor() which writes to SP_SDCS_VSSP_REG_L (and other registers in segment 5), then adjusts the registers by calling setCsVsStart and setCsVsStop. This controls the sync separator, and indirectly increases the number of scanlines we wait after vsync before sampling the input, which is is necessary because 480p video has a longer back porch after vsync than 480i video.

When we save the configuration as a custom preset, all values written by prepareSyncProcessor(), including those adjusted by setCsVsStop(), are saved to flash. The problem arises when we load this custom preset and call doPostPresetLoadSteps() again. This time, the function calls prepareSyncProcessor() and erases the changes to vertical sampling, but doesn't adjust the registers again by calling setCsVsStop() etc. This results in the input being sampled too soon and the output image shifting downwards.

As far as I can tell, it's actually unnecessary to call prepareSyncProcessor() when loading a custom preset, because in any saved preset the function has already been called, incorrect values replaced by calling setCsVsStop() etc., and all register values touched by prepareSyncProcessor() have been saved to the custom preset file. So to prevent prepareSyncProcessor() from writing incorrect register values when loading saved custom presets, don't call the function at all.

Fixes #401.

Unrelated: Can writeOneByte(0xF0, y) cause UReg::write() -> SegmentedSlave::setSeg() to falsely assume the segment is curSeg, and not bother writing the segment ID, when in fact the segment is y and writes are going to the wrong page?

nyanpasu64 commented 1 year ago
nyanpasu64 commented 1 year ago

it works i guess