Sorry, Mac, but there is one situation where that fails:
If the overflow flag sets AFTER he has reads the counter, but BEFORE he tests the flag, the 32 bit value will be wrong. The low 16 bits will be pre-overflow, and the high 16 bits will be post-overflow.
I can't think of any way to do this without doing a check on the value read from the counter. Almost exactly like you described, but also qualifying the increment decision with the most significant bit of the counter.
This is a tough problem . . .
--------------------------- little later:
Ok, I see that you ARE qualifying the decision with the count value. However, a test for $0000 or $FFFF may not be adequate for a fast counter, as the counter can increment a few times in the course of one instruction. Again, a test of the msb should work.
Message Edited by rocco on 2007-02-0102:28 PM