Mercurial > vba-clojure
changeset 75:eb7d4efe0f34
added play command
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 08 Mar 2012 06:01:09 -0600 |
parents | aaddd7b72a0e |
children | d7c38ce83421 |
files | clojure/com/aurellem/fragments.clj clojure/com/aurellem/gb_driver.clj |
diffstat | 2 files changed, 63 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/fragments.clj Thu Mar 08 04:40:18 2012 -0600 1.2 +++ b/clojure/com/aurellem/fragments.clj Thu Mar 08 06:01:09 2012 -0600 1.3 @@ -1,3 +1,58 @@ 1.4 (ns com.aurellem.fragments 1.5 (:use (com.aurellem gb-driver vbm))) 1.6 1.7 + 1.8 + 1.9 + 1.10 + 1.11 + 1.12 + 1.13 +(def start-frames 401) 1.14 + 1.15 + 1.16 +(defn play-start [start n] 1.17 + (let [moves 1.18 + (concat (repeat n []) 1.19 + [[:a]] 1.20 + (repeat (- start-frames n 1) [])) 1.21 + moves (drop start moves)] 1.22 + (goto start) 1.23 + (dorun (map step moves)) 1.24 + (nth (registers) 2))) 1.25 + 1.26 + 1.27 +(defn earliest-press 1.28 + [start] 1.29 + (print "determining bad program-counter...") 1.30 + (let [bad-counter (play-start 0 0)] 1.31 + (println bad-counter) 1.32 + (loop [n start] 1.33 + (print "trying" n "...") 1.34 + (let [nth-counter (play-start n)] 1.35 + (println "got" nth-counter) 1.36 + (if (= nth-counter bad-counter) 1.37 + (recur (inc n)) n))))) 1.38 + 1.39 + 1.40 + 1.41 +(def start->menu 1.42 + [ 1.43 + 1.44 + 1.45 + 1.46 + 1.47 + 1.48 + 1.49 + 1.50 + 1.51 + ]) 1.52 + 1.53 + 1.54 + 1.55 +(defn full-script [] (concat start->menu)) 1.56 + 1.57 + 1.58 +(defn test-script [] 1.59 + (reset) 1.60 + (dorun (map step (full-script)))) 1.61 +
2.1 --- a/clojure/com/aurellem/gb_driver.clj Thu Mar 08 04:40:18 2012 -0600 2.2 +++ b/clojure/com/aurellem/gb_driver.clj Thu Mar 08 06:01:09 2012 -0600 2.3 @@ -98,9 +98,10 @@ 2.4 (def ^:dynamic *save-history* true) 2.5 2.6 (defn advance [] 2.7 - (let [save (save-state)] 2.8 - (backup-state @current-frame) 2.9 - (swap! current-frame inc))) 2.10 + (swap! current-frame inc) 2.11 + (if *save-history* 2.12 + (let [save (save-state)] 2.13 + (backup-state @current-frame)))) 2.14 2.15 (defn step 2.16 ([] (advance) (Gb/step)) 2.17 @@ -110,6 +111,10 @@ 2.18 (Gb/step mask-or-buttons) 2.19 (Gb/step (button-mask mask-or-buttons))))) 2.20 2.21 +(defn step! [& args] 2.22 + (binding [*save-history* false] 2.23 + (apply step args))) 2.24 + 2.25 (defn frame [] @current-frame) 2.26 2.27