I have this bit of code, I'm expecting it to sleep for 18 seconds, then print to screen and loop back etc. When I run the code the length of time the sleep happens reduces each time it loops. So the first time is 18 seconds, but towards the end the sleep is only 2-3 seconds. I can't understand why this would be the case, can anyone help?
That is weird, I can see the speeding up happen on OZVM (though I'm not convinced the first pause is for 18 seconds), does it happen on real hardware as well?
EDIT: The header defines the function as __z88dk_fastcall, but the code isn't so it was taking the loop variable as the sleep time.
Fc=1
BC - remaining time out
A - error code
RC.ESC(&01) - escape
RC.SUSP(&69) - process suspended
RC.TIME(&02) - timeout
So suspension/resuming or pressing the escape key (if detection isn't disabled) will terminate the sleep. So, you'll need to check the return value and loop until the value is 0.
In general on the z88 you should never busy loop (as your second snippet is doing) - it will drain the battery and also prevents application switching.