Reply 140 of 236, by jmarsh
clb wrote on 2024-11-27, 21:26:One way that I thought to mitigate this problem might be for the PALTSR interrupt to use a heuristic : when the update interrupt it reads the currently active palette write index from 3C8h, it would compare it to what the active palette write index at the start of the previous interrupt run would be. If the previously active palette write index is different than the current one, the idea is to think "maybe we're right in the middle of an update", and the interrupt would skip mirroring the palette to CRTT. I.e. only when the palette index is seen to be identical twice in a row, the palette is mirrored to CRTT.
I was thinking of something slightly different for the beginning of the TSR's update loop:
- read 0x3C8
- write a dummy value to 0x3C9
- read 0x3C8 again, if the index has incremented we know the app was about to write a "B" value. At the end of the update loop we need to restore the write index and write the previous red and green values.
- else write another dummy value to 0x3C9, again check if 0x3C8 has changed. If so then the app was about to write a "G" value, do the same as above but only write the red value.
Obviously this depends on the hardware only updating palette entries when all 3 values have been written / discarding the dummy values, otherwise it would modify existing palette data.
Another option would be skipping the TSR's update loop if vsync is active, since most games will only do palette updates during that time. So the CRTT might see updates a little bit later but the risk of corruption would be less.