CGA Video Snow and CLS Flash
█▌Video Snow▐█
When writing a program that may run on a CGA, you must take special action
to avoid annoying artifacts that appear on the screen when you access
video memory directly. (Note: This is NOT a problem with any other
monitor types; even many CGAs, such as emulated CGA on an LCD screen, do
not have the "video snow" problem).
To avoid video snow, you must write to video memory only during the
retrace period. You can check for retrace by using:
les di,vidAddr ;ES:DI=> address to write (e.g., b800:0000)
cli ;stop interrupts from screwing up the timing
waitForNoRetrace:
mov dx,3daH ;CRT Status register. See CGA I/O Ports.
in al,dx
test al,01h ;out of retrace yet?
jz waitForNoRetrace
waitForRetrace:
in al,dx
test al,01h ;in retrace yet?
jz waitForRetrace
okToWrite:
mov ax,charAndAttr ;get character and attribute to write
stosw ;write it
sti ;let interrupts happen
This sequence first waits until the CGA is NOT in retrace, then waits
until retrace begins, then immediately writes the data. On the oldest
4.77 Mhz PCs, there is just enough time to write one or maybe two
characters to video memory before horizontal retrace ends.
A CGA-optimized video library can squeeze out better performance by
waiting for vertical retrace (test dx,08h). At that point, you can
write just over 160 bytes without causing snow.
There is no way to know if a CGA has this problem. Most software provides
a means, such as a command-line option, to enable or disable the code that
synchronizes video access with video retrace.
█▌CLS Flash▐█
The oldest CGA BIOS uses an irritating technique when it clears the screen
(for instance, via INT 10H 06H. It disables the video signal, so it can
write lots of data to video memory without awaiting retrace.
This works fine when most of the screen is black, but if the screen is
mostly blue (or other color), then you see an annoying flash of black
whenever the screen scrolls.
A complete video library should include its own CGA-aware CLS function to
avoid this problem.
See Also: CGA
Video Memory Layouts
Video Modes
-♦-