Open npatrick04 opened 7 years ago
Or shorter and more understandable using https://github.com/npatrick04/rate-monotonic...
(defconstant +cycles-per-second+ 500)
(defconstant +cycles-before-sleep+ 10)
(defconstant +cycles-period+ (/ +cycles-before-sleep+ +cycles-per-second+))
(defun run-cpu (chip)
(let ((cycle-period (rm:make-timer-period)))
(rm:with-timer-period (+cycles-period+)
;; Kick the first period off
(rm:period cycle-period :seconds +cycles-period+)
(iterate
(while (chip-running chip))
(emulate-cycle chip)
(for tick :every-nth +cycles-before-sleep+
:do (rm:period cycle-period :seconds +cycles-period+))))))
Hey Steve,
I was planning on commenting on your blog...but since there is no way to do that...and you linked to your github account, I figured I'd put this here.
The sleeps you're doing in run-cpu, emulate-cycle, run-sound, and run-timers all will result in skew that varies from cycle to cycle. It'd be better to use a constant frequency tick for those things. I actually have a library that could be used (though it's probably more complicated than what this needs).
Using https://github.com/npatrick04/timer-wheel,