Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/gb_driver.clj @ 154:3a3bb2197b7f
discovered hex-values for every move.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 20 Mar 2012 02:40:59 -0500 |
parents | 412ca096a9ba |
children | 893c753f8088 |
comparison
equal
deleted
inserted
replaced
153:6135504976e6 | 154:3a3bb2197b7f |
---|---|
29 (.rewind buffer) | 29 (.rewind buffer) |
30 dest))) | 30 dest))) |
31 | 31 |
32 (defn read-state [name] | 32 (defn read-state [name] |
33 (let [save (state-cache-file name)] | 33 (let [save (state-cache-file name)] |
34 (if (.exists save) | 34 (assert (.exists save)) |
35 (let [buffer (Gb/saveBuffer) | 35 (let [buffer (Gb/saveBuffer) |
36 bytes (FileUtils/readFileToByteArray save)] | 36 bytes (FileUtils/readFileToByteArray save)] |
37 (.put buffer bytes) | 37 (.put buffer bytes) |
38 (.flip buffer) | 38 (.flip buffer) |
39 (SaveState. buffer))))) | 39 (SaveState. buffer)))) |
40 ;;;;;;;;;;;;;;;; | 40 ;;;;;;;;;;;;;;;; |
41 | 41 |
42 ;; Gameboy management | 42 ;; Gameboy management |
43 (Gb/loadVBA) | 43 (Gb/loadVBA) |
44 | 44 |
138 (defn continue! | 138 (defn continue! |
139 ([state] | 139 ([state] |
140 (play state Integer/MAX_VALUE)) | 140 (play state Integer/MAX_VALUE)) |
141 ([] | 141 ([] |
142 (continue! @current-state))) | 142 (continue! @current-state))) |
143 | |
144 (defn run-moves [state moves] | |
145 (set-state! state) | |
146 (dorun (map #(Gb/step (button-mask %)) | |
147 moves)) | |
148 (update-state)) | |
143 | 149 |
144 (defn play-moves | 150 (defn play-moves |
145 ([moves [prev state]] | 151 ([moves [prev state]] |
146 (set-state! state) | 152 (set-state! state) |
147 (dorun (map (fn [move] (step @current-state move)) moves)) | 153 (dorun (map (fn [move] (step @current-state move)) moves)) |