Waits until CRTC produces vertical synchronization signal (VSYNC), counting the number of active wait loop cycles done.
<u16> | Total number of iterations done of the wait loop until VSYNC was active. |
call cpct_count2VSYNC_asm
This function implements a wait loop that exists only when VSYNC signal from the CRTC is detected. It works in the same way as cpct_waitVSYNC, but with one addition: it keeps counting the number of iterations of the waiting loop. This count is returned when VSYNC is detected and the function ends. For more reference about VSYNC and this waiting loop, see cpct_waitVSYNC.
The main utility of counting loop iteration is to have an estimate of free cycles in a main loop. If you are planning to make a game or application running at 50/25/12.5 FPS, all your CPU operations must fit into the allowed time for that. A way to know if you still have time to include more operations is using this function during development phase to know how much time is still available between the end of your calculations and the VSYNC.
The value returned by this function refers to the number of loop iteration waiting for VSYNC. If you wanted to know the total amount of CPU cycles or microseconds, you can do this calculations,
availableMicroSecs = 14 + 9 * cpct_count2VSYNC(); availableCycles = 4 * availableMicroSecs;
Take into account that VSYNC occurs with a frequency of 19968 microseconds (roughtly 20 millisenonds, 1/50 seconds) which corresponds to 79872 CPU Cycles. That is, in effect, the available time for calculations during every frame drawn on the scren.
AF, HL, BC
12 bytes
Case | microSecs(us) | CPU Cycles ------------------------------------- Best | 17 | 68 ------------------------------------- Any | 9 + 9L | 36 + 36L -------------------------------------
L=Number of times loop is executed
As this is an active wait loop, it does not actually mind at all the time needed to process. It will vary depending on how much time has passed since the last VSYNC.