Mercurial > vba-clojure
comparison clojure/com/aurellem/gb_driver.clj @ 73:8a895ed4c0f9
added history facilities
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 08 Mar 2012 04:37:10 -0600 |
parents | 39928bf4622d |
children | aaddd7b72a0e |
comparison
equal
deleted
inserted
replaced
72:c88ad4f6d9b4 | 73:8a895ed4c0f9 |
---|---|
9 (File. "/home/r/proj/pokemon-escape/roms/yellow.gbc")) | 9 (File. "/home/r/proj/pokemon-escape/roms/yellow.gbc")) |
10 | 10 |
11 (def yellow-save-file | 11 (def yellow-save-file |
12 (File. "/home/r/proj/pokemon-escape/roms/yellow.sav")) | 12 (File. "/home/r/proj/pokemon-escape/roms/yellow.sav")) |
13 | 13 |
14 (def current-frame (atom 0)) | |
15 | |
14 (defn vba-init [] | 16 (defn vba-init [] |
17 (reset! current-frame 0) | |
15 (.delete yellow-save-file) | 18 (.delete yellow-save-file) |
16 (Gb/startEmulator (.getCanonicalPath yellow-rom-image))) | 19 (Gb/startEmulator (.getCanonicalPath yellow-rom-image))) |
17 | 20 |
18 (defn shutdown [] (Gb/shutdown)) | 21 (defn shutdown [] (Gb/shutdown)) |
19 | 22 |
68 (let [[button value] (first masks)] | 71 (let [[button value] (first masks)] |
69 (if (not= 0x0000 (bit-and value mask)) | 72 (if (not= 0x0000 (bit-and value mask)) |
70 (recur (conj buttons button) (rest masks)) | 73 (recur (conj buttons button) (rest masks)) |
71 (recur buttons (rest masks))))))) | 74 (recur buttons (rest masks))))))) |
72 | 75 |
76 | |
77 (defn save-state [] (Gb/saveState)) | |
78 | |
79 (def history (atom {})) | |
80 | |
81 (defn goto [frame] | |
82 (let [save (@history frame)] | |
83 (if (not (nil? save)) | |
84 (do | |
85 (reset! current-frame frame) | |
86 (Gb/loadState save)) | |
87 (println "no backup state")))) | |
88 | |
89 (defn clear-history [] (reset! history {})) | |
90 | |
91 (defn rewind [] (goto (dec @current-frame))) | |
92 | |
93 (defn backup-state [frame] | |
94 (swap! history #(assoc % frame (save-state)))) | |
95 | |
96 (def ^:dynamic *save-history* true) | |
97 | |
98 (defn advance [] | |
99 (let [save (save-state)] | |
100 (backup-state @current-frame) | |
101 (swap! current-frame inc))) | |
102 | |
73 (defn step | 103 (defn step |
74 ([] (Gb/step)) | 104 ([] (advance) (Gb/step)) |
75 ([mask-or-buttons] | 105 ([mask-or-buttons] |
106 (advance) | |
76 (if (number? mask-or-buttons) | 107 (if (number? mask-or-buttons) |
77 (Gb/step mask-or-buttons) | 108 (Gb/step mask-or-buttons) |
78 (Gb/step (button-mask mask-or-buttons))))) | 109 (Gb/step (button-mask mask-or-buttons))))) |
110 | |
111 (defn frame [] @current-frame) | |
112 | |
113 |