How much faster?

Started by nikoniko, April 26, 2007, 09:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nikoniko

I want an interrupt to kick in at the beginning of VDC's vertical blank, so this would be the basic strategy as I understand it:

1) Check for vertical blank. If already in vertical blank, wait until out of vertical blank and begin polling for the next vertical blank to catch it at the beginning.
2) As soon as VBLANK is detected, install an interrupt that is set to run slightly faster than the screen update frequency, which will be close to 50 or 60Hz, with some variance needing to be accounted for depending on individual VDCs (or so I gather from Risen from Oblivion).
3) Do whatever you were reserving for the blank period (or do nothing during some invocations, depending on your needs).
4) When the interrupt is triggered, poll until vertical blank. Go to step 2.

What I'm not sure about is the timing for the interrupt. How much faster than the screen update frequency should it be to happen as close as possible to VBLANK but without wasting much time with polling? How close can one reasonably cut it?

hydrophilic

Ideally your CIA timer should be exactly the same as the screen frequency, just occurring ahead of the blank so you can detect when it starts.  I would say within one raster time (about 64 slow or 32 fast CPU cycles) would be reasonable.

That would require experimentation to be sure, but in theory, the VDC is clocked at exactly 16.000 MHz while the CPU and CIA timers are clocked at 1.022734 MHz (NTSC).  If you want a generalized approach, your program would need

a. Examine VDC register to get the total width (in chars)
b. Multiply by 8 (assuming 8 pixel wide characters)
c. Divide by 16M to get 1 raster time (in seconds)
d. Save raster time
e. Examine VDC register to get total height (in chars)
f. Multiply by 8 (assuming 8 pixel tall characters)
g. Add VDC register vertical total adjust (usually zero)
h. This is the total rasters; multiply it by the saved raster time
i. Divide this time by the CPU/CIA cycle time 0.97777us (NTSC)
j. The result is the number of cycles / VDC screen refresh; program the CIA timers with this

The result in J. won't be an integer so round down making your interrupt ever so slightly faster than the VDC.  I'd recommend using an index register as a counter in the polling routine and resetting the timers after it gets to big.

Sorry I don't have specific details because I don't have VICE on this PC.  But assuming 128 chars VDC width (visible+borders) and 33 chars height(visible+borders), this works out to 0.016896 s/frame.  For NTSC, division by 0.97777us results in 17280.14 cycles / frame.  So in this scenario, try a CIA timer of 17280 ($4380) cycles.

Sounds like a fun experiment.  If you try it, I'd be curious to know what values work for you.

nikoniko

Thanks, I'll give it a try and report back.