VSync ...again!
Posted: Wed Nov 23, 2016 11:26 am
Hi all! I want to share here some facts about the VSync, which I think can be useful.
I. The Hardware VSync hack is well known as simple connection between RGB-SYNC output and TAPE-IN input. The output signal represents negative pulses - short for every scanline and long for every frame. Tanks to the TAPE-IN amplifier which acts as low-pass filter all short pulses are filtered and only the long pulses rich VIA's CB1. Important details are that the signal on CB1:
- has a delay of 12 microseconds compared to SYNC (pic.1)
- has the same shape as the SYNC i.e negative pulses (pic.2)
- lasts about 260 microseconds (pic.3) and is equal to the time for 4 scanlines plus the time for one short pulse (i.e 260uS = 4x64 + 4 uSec) - for both modes 50Hz and 60Hz.
That being said, to synchronize drawing with VSync you need to set properly bit 4 in VIA's PCR:
0 = IRQ flag will be set on NEGATIVE edge (or 12 uSec after the vertical retrace start)
1 = IRQ flag will be set on POSITIVE edge (or 12+260 uSec after the vertical retrace start)
Additionally, if you decide to use interrupt (instead polling) you have to enable it in VIA's IER, setting bit 4 to '1'. Practically, there is no big difference which edge will be used - it's 260 uSec, but sometimes this short time can be critical. More important is that keyboard scan or PSG addressing routines can modify PCR too!
I. The Hardware VSync hack is well known as simple connection between RGB-SYNC output and TAPE-IN input. The output signal represents negative pulses - short for every scanline and long for every frame. Tanks to the TAPE-IN amplifier which acts as low-pass filter all short pulses are filtered and only the long pulses rich VIA's CB1. Important details are that the signal on CB1:
- has a delay of 12 microseconds compared to SYNC (pic.1)
- has the same shape as the SYNC i.e negative pulses (pic.2)
- lasts about 260 microseconds (pic.3) and is equal to the time for 4 scanlines plus the time for one short pulse (i.e 260uS = 4x64 + 4 uSec) - for both modes 50Hz and 60Hz.
That being said, to synchronize drawing with VSync you need to set properly bit 4 in VIA's PCR:
0 = IRQ flag will be set on NEGATIVE edge (or 12 uSec after the vertical retrace start)
1 = IRQ flag will be set on POSITIVE edge (or 12+260 uSec after the vertical retrace start)
Additionally, if you decide to use interrupt (instead polling) you have to enable it in VIA's IER, setting bit 4 to '1'. Practically, there is no big difference which edge will be used - it's 260 uSec, but sometimes this short time can be critical. More important is that keyboard scan or PSG addressing routines can modify PCR too!