AMOS:Multiple 'Every N Proc'

From Amiga Coding
Jump to: navigation, search

From: Richard Ling
Date: Sun, 30 May 1993 18:52:45 +1000 (EST)

wrt. the problem of multiple "Every N Proc" calls:

Why not just have one call to Every N Proc, using the greatest common divisor of the counts you really want. Increment a counter in the procedure, and call the procedures you want when it gets to the appropriate value (that is, the count divided by the greatest common divisor).

eg. you want to use Every 6 Proc FIRST_PROC Every 9 Proc SECOND_PROC

Greatest common divisor is 3, so use Every 3 Proc TIMER_PROC

6/3 = 2, you want to call FIRST_PROC every 2nd interrupt 9/3 = 3, you want to call SECOND_PROC every 3rd interrupt

So use:

Procedure TIMER_PROC

  If (TIMER_VALUE mod 2) = 0 Then FIRST_PROC
  If (TIMER_VALUE mod 3) = 0 Then SECOND_PROC

End Proc

Hope this is of use...


PS. 3D demo will be uploaded to an FTP site soon... please hang loose!