0

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)
Óscar López
  • 232,561
  • 37
  • 312
  • 386
Arno Moonens
  • 1,163
  • 1
  • 10
  • 19
  • 1
    There are no concept of threads in R5RS. But do you have a particular microprocessor / Scheme implementation in mind? – soegaard Apr 02 '13 at 20:10
  • Although not R5RS, ypsilon is an R6RS Scheme that has been used for game development and has multiprocessing primitives built in. – GoZoner Apr 03 '13 at 15:13

1 Answers1

0

No, in R5RS there are no threading primitives (check the index of the specification to see the available procedures). And it can't be implemented in terms of just R5RS, because necessarily at some point you'll have to access native operating system calls.

Óscar López
  • 232,561
  • 37
  • 312
  • 386