Useful VGA registers, I/O access, detecting vertical retrace

I sounds crazy, but drawing directly on the screen is not a good idea. At least in case when you want to make some animations. The problem is - and this is a common issue for all computers and videocards, not just for VGA - that if you make modifications on the screen while the card reads the data from the video memory, the screen might be flickering and sometimes you see glitches. To avoid this issue we have to synchronize our operations to the electron beam. This means that you have to wait while the electron beam starts its retrace (usually vertical retrace, becasue the horizontal retrace is really short) and then make all modifications on the screen as soon as possible. In this was the screen will be updated when the electron beam does not draw anything, in other words the VGA card does not read the video memory.