EDIT: I thought of a better way to do this. What I wrote in this post should work, but I was able to shorten the program, use one less variable, and add the option for additional features that would only happen on bootup.
CTS I'm sure will be a nice feature. I rewrote the above program using CTS. The program needed a few more lines but it will startup immediately on boot instead of waiting to the top of the minute. It will make no difference what VAR1 is at boot, it will correct VAR1 to allow for instant activiation of the input/output time counters.
The premise is that VAR1 stays one second ahead of cts and as soon as cts catches up to VAR1, it runs the subroutine which
1) checks the input/output status and
2) sets var1 ahead 1 more second again to wait for cts to catch up again and trigger the subroutine again.
I added two provisions for the immediate startup regardless of what var1 might be relative to the current total secdons on boot. First, var1 should never be less than cts, so if it is, it resets it to cts. Second, var1 should never be more than 1 second higher than cts, so if it is, then it gets reset to cts. This second provision requires the use of another variable, I used ram1.
START
TSTEQ VAR1 CTS this line and the next keep checking for total current seconds to catch up to var1
CALLSUB COUNT
TSTLT VAR1 CTS this line and the next check if var1 is less than current total seconds
SET VAR1 CTS
SUB VAR1 CTS RAM1 this line and the next 2 checks to see if var1 is more than 1 second higher than CTS
TSTGT RAM1 1 the only way it could be higher is if the time was reset or someone manually set var1 higher.
SET VAR1 CTS
END
COUNT:
INC VAR1
TSTEQ IN1 1
INC VAR2
TSTEQ IN1 0
SET VAR2 0
RET
A nice feature to add to the CAI might be to have a command for doing "on boot" so you could set variables/outputs or run a specific subroutine only on boot.