I made a game which uses the time for calculating the effect of gravity in relation of the time (speed and movement). Although the game uses mostly r5rs functions, I used the thread
, sleep
and other functions to update and remember the time, which are defined in racket.
Now I want to make te game work on a microcontroller which has only r5rs available.
Is it possible to make something similar using only r5rs?
This is the code I currently use (which uses the racket functions):
(define (make-timer)
(define time 0)
(define wait-time (/ 1 CPU_FREQ))
(define timer-thread
(thread (lambda ()
(let loop ()
(sleep wait-time)
(set! time (+ 1 time))
(loop)))))
(define (dispatch msg)
(cond ((eq? msg 'time) time)
((eq? msg 'start)
(thread-resume timer-thread))
((eq? msg 'restart)
(set! time 0)
(thread-resume timer-thread))
((eq? msg 'reset)
(thread-suspend timer-thread)
(set! time 0))
((eq? msg 'stop) (thread-suspend timer-thread))
((eq? msg 'set-period!)
(lambda (period)
(set! wait-time (* (+ period 1) (/ 1 CPU_FREQ)))))
))
(thread-suspend timer-thread)
(set! time 0)
dispatch)