annotate clojure/com/aurellem/fragments.clj @ 78:4a1b17917fc8

speed up emulation
author Robert McIntyre <rlm@mit.edu>
date Thu, 08 Mar 2012 21:50:46 -0600
parents d7c38ce83421
children
rev   line source
rlm@73 1 (ns com.aurellem.fragments
rlm@73 2 (:use (com.aurellem gb-driver vbm)))
rlm@73 3
rlm@75 4
rlm@75 5
rlm@75 6
rlm@75 7
rlm@75 8
rlm@75 9
rlm@75 10 (def start-frames 401)
rlm@75 11
rlm@75 12
rlm@75 13 (defn play-start [start n]
rlm@75 14 (let [moves
rlm@75 15 (concat (repeat n [])
rlm@75 16 [[:a]]
rlm@75 17 (repeat (- start-frames n 1) []))
rlm@75 18 moves (drop start moves)]
rlm@75 19 (goto start)
rlm@76 20 (dorun (map step! moves))
rlm@75 21 (nth (registers) 2)))
rlm@75 22
rlm@75 23 (defn earliest-press
rlm@75 24 [start]
rlm@75 25 (print "determining bad program-counter...")
rlm@76 26 (reset)
rlm@76 27 (dorun (dotimes [_ start-frames] (step)))
rlm@75 28 (let [bad-counter (play-start 0 0)]
rlm@75 29 (println bad-counter)
rlm@75 30 (loop [n start]
rlm@75 31 (print "trying" n "...")
rlm@76 32 (let [nth-counter (play-start (dec n) n)]
rlm@75 33 (println "got" nth-counter)
rlm@75 34 (if (= nth-counter bad-counter)
rlm@75 35 (recur (inc n)) n)))))
rlm@75 36
rlm@75 37
rlm@75 38
rlm@75 39 (def start->menu
rlm@75 40 [
rlm@75 41
rlm@75 42
rlm@75 43
rlm@75 44
rlm@75 45
rlm@75 46
rlm@75 47
rlm@75 48
rlm@75 49 ])
rlm@75 50
rlm@75 51
rlm@75 52
rlm@75 53 (defn full-script [] (concat start->menu))
rlm@75 54
rlm@75 55
rlm@75 56 (defn test-script []
rlm@75 57 (reset)
rlm@75 58 (dorun (map step (full-script))))
rlm@75 59