Reply 40 of 58, by Scali
wrote:Anyone knows why the display of the kefrens is scrolling up instead of being stationary? Scali?
I'm not sure if you're familiar with the 'classic' Kefrens bars effect, as it is performed on Amiga.
In short, the effect is performed by repeating the same scanline over the entire screen. If you draw a 'shade/gradient' thingie in there, it will get stretched over the entire width. This is how vertical bars are performed.
Step two is to make the bars move around horizontally. This is done by drawing a new shade/gradient at every scanline (not erasing what was already there), moving it around with some sine-based pattern for example.
On CGA, the effect is done in pretty much the same way. On Amiga it is trivial to repeat the same scanline: you can just do that with the modulo register, which contains the distance between scanlines in memory. With the proper value, it will restart at the same address for each scanline. The same can be done on VGA.
On CGA however, there is no concept of 'modulo', because the scanlines in memory are assumed to be contiguous.
Is there another way to reset the scanline address? Yes, you can set the start offset. However, this is latched, and when you write a new value, it won't become active until the current frame ends (vblank).
The trick in 8088 MPH is to compose a screen of multiple frames. Each frame is 2 scanlines high, and there is no vblank area. The result is that when a new address is written, it will become active after 2 scanlines (this is why the Kefrens bars work on a 2-scanline resolution, rather than single-scanline as on Amiga), because the CRTC starts a new frame.
Since the monitor just continues tracing the image, these scanlines will all get stacked on top of eachother, just like on a 'regular' frame. After the last scanline is drawn, a proper vblank is inserted so the monitor can retrace. So effectively the signal seen by the monitor is the same 262-line 59.92 Hz signal that you'd get in regular modes. The CRTC thinks it has done 100 frames though.
So in order to emulate this, you need to decouple the CRTC's concept of frames from the 'monitor' frames (I haven't seen any real VGA card that is capable either... generally what happens is that it draws an entire frame of 262 scanlines for every 2 scanlines. This also means that the effect is slowed down a lot).
An additional problem here is that the Kefrens code is timed cycle-exact for a real IBM PC/XT with real IBM CGA (there is no time for polling the CRTC status). So on this machine, the code for drawing the bar, updating the background colour and resetting the CRTC registers takes exactly 2 scanlines. If your timing is off even just a little, the CRTC will not be reprogrammed at the correct time, and the whole thing falls apart. You may miss scanlines, or the vblank is inserted in the wrong place etc.
A relatively easy way to tell if the timing is off is to check the background colour. At the proper speed, the colour is changed in the horizontal blank interval, so hidden in the left border. If it is too fast or too slow, you will see 'stair stepping' artifacts mid-screen, when the colour is changed.