# HG changeset patch # User Robert McIntyre # Date 1331203030 21600 # Node ID 8a895ed4c0f966f8af3d6e13bd3ff39e33e801dd # Parent c88ad4f6d9b4338e61250988403909e78661709d added history facilities diff -r c88ad4f6d9b4 -r 8a895ed4c0f9 clojure/com/aurellem/fragments.clj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clojure/com/aurellem/fragments.clj Thu Mar 08 04:37:10 2012 -0600 @@ -0,0 +1,3 @@ +(ns com.aurellem.fragments + (:use (com.aurellem gb-driver vbm))) + diff -r c88ad4f6d9b4 -r 8a895ed4c0f9 clojure/com/aurellem/gb_driver.clj --- a/clojure/com/aurellem/gb_driver.clj Thu Mar 08 03:41:24 2012 -0600 +++ b/clojure/com/aurellem/gb_driver.clj Thu Mar 08 04:37:10 2012 -0600 @@ -11,7 +11,10 @@ (def yellow-save-file (File. "/home/r/proj/pokemon-escape/roms/yellow.sav")) +(def current-frame (atom 0)) + (defn vba-init [] + (reset! current-frame 0) (.delete yellow-save-file) (Gb/startEmulator (.getCanonicalPath yellow-rom-image))) @@ -70,9 +73,41 @@ (recur (conj buttons button) (rest masks)) (recur buttons (rest masks))))))) + +(defn save-state [] (Gb/saveState)) + +(def history (atom {})) + +(defn goto [frame] + (let [save (@history frame)] + (if (not (nil? save)) + (do + (reset! current-frame frame) + (Gb/loadState save)) + (println "no backup state")))) + +(defn clear-history [] (reset! history {})) + +(defn rewind [] (goto (dec @current-frame))) + +(defn backup-state [frame] + (swap! history #(assoc % frame (save-state)))) + +(def ^:dynamic *save-history* true) + +(defn advance [] + (let [save (save-state)] + (backup-state @current-frame) + (swap! current-frame inc))) + (defn step - ([] (Gb/step)) + ([] (advance) (Gb/step)) ([mask-or-buttons] + (advance) (if (number? mask-or-buttons) (Gb/step mask-or-buttons) (Gb/step (button-mask mask-or-buttons))))) + +(defn frame [] @current-frame) + + diff -r c88ad4f6d9b4 -r 8a895ed4c0f9 clojure/com/aurellem/vbm.clj --- a/clojure/com/aurellem/vbm.clj Thu Mar 08 03:41:24 2012 -0600 +++ b/clojure/com/aurellem/vbm.clj Thu Mar 08 04:37:10 2012 -0600 @@ -46,7 +46,7 @@ pending buttons] (if (empty? pending) fixed (let [mask (first pending)] - (if (contains? (first pending) :reset) + (if (contains? (set (first pending)) :reset) (recur (conj fixed mask) (drop 3 pending)) (recur (conj fixed mask) (next pending))))))) @@ -88,8 +88,3 @@ (defn write-vbm [buttons #^File out] (clojure.java.io/copy (buttons->vbm-bytes buttons) out)) - - - - - \ No newline at end of file