lronaldo / cpctelera

Astonishingly fast Amstrad CPC game engine for C developers
http://lronaldo.github.io/cpctelera/
GNU Lesser General Public License v3.0
222 stars 53 forks source link

Added waitVSYNCStart and getVSYNCActive functions #131

Closed nestornillo closed 2 years ago

nestornillo commented 3 years ago

This PR implements Kevin Thacker's contributed routines for VSYNC test from Issue #50

nestornillo commented 3 years ago

cpct_waitVSYNCStart I've named the function cpct_waitVSYNCStart instead of cpct_syncVSYNCStart: The purpose of the code is to 'sync', but the function just 'waits'. It is ok?

Kevin's code in issue #50 had 3 wait loops, I don't think the first one is needed. Or am I missing something?

Not sure about worst case time measurement: worst case is when vsync is activated just before 'wait_for_vs_inactive' loop starts. Next vsync (19968 us later, I think) will start during 'wait_for_vs_active' loop, but I don't know exactly in which points can happen (also, what happens if vsync raises in the middle of a 'in a,(c)'?). I've supposed for worst case that vsync raises again just before rra in 'wait_for_vs_active' loop, so I've used this: 2 (ld) + 19968 + 4 (rra + jr_no_cc) + 7 (in + rra + jr_cc) + 3 (ret) = 19984

cpct_getVSYNCActive Kevin's routine uses HL to return the result, but I've chopped the code to use only L, as it only returns 1 or 0.

lronaldo commented 2 years ago

I think your reviews and comments are very valuable. Thank you again for taking the time to analyze things deep and make the best proposals possible. Users will certainly be very grateful for your efforts :+1: :smile:

I have made a review of your proposal with detailed comments for you to check and comment back. If you don't mind, I will accept your PR and proceed to add proposed changes. Then, if you have more interesting comments on them, we can continue reviewing and updating files later on :)