comparison clojure/com/aurellem/gb/vbm.clj @ 250:b7f682bb3090

updated title and save_corruption to work with all the recent updates
author Robert McIntyre <rlm@mit.edu>
date Mon, 26 Mar 2012 03:49:33 -0500
parents 412ca096a9ba
children abd1ca8a25cc
comparison
equal deleted inserted replaced
248:e94d20ad853e 250:b7f682bb3090
4 (:use com.aurellem.gb.gb-driver)) 4 (:use com.aurellem.gb.gb-driver))
5 5
6 ;;;;;;;;;;;;; read vbm file 6 ;;;;;;;;;;;;; read vbm file
7 7
8 (def ^:dynamic *moves-cache* 8 (def ^:dynamic *moves-cache*
9 (File. user-home "proj/pokemon-escape/moves/")) 9 (File. user-home "proj/vba-clojure/moves/"))
10 10
11 (defn buttons [mask] 11 (defn buttons [mask]
12 (loop [buttons [] 12 (loop [buttons []
13 masks (seq (dissoc button-code :listen))] 13 masks (seq (dissoc button-code :listen))]
14 (if (empty? masks) buttons 14 (if (empty? masks) buttons
58 (let [mask (first pending)] 58 (let [mask (first pending)]
59 (if (contains? (set (first pending)) :reset) 59 (if (contains? (set (first pending)) :reset)
60 (recur (conj fixed mask) (drop 3 pending)) 60 (recur (conj fixed mask) (drop 3 pending))
61 (recur (conj fixed mask) (next pending))))))) 61 (recur (conj fixed mask) (next pending)))))))
62 62
63 (defn moves->filename [frame] 63 (defn moves-filename [name]
64 (File. *moves-cache* (format "%07d.vbm" frame))) 64 (File. *moves-cache* (format "%s.vbm" name)))
65 65
66 (defn read-moves [frame] 66 (defn read-moves [name]
67 (let [target (moves->filename frame)] 67 (let [target (moves-filename name)]
68 (if (.exists target) 68 (if (.exists target)
69 (vbm-buttons target)))) 69 (vbm-buttons target))))
70 ;;;;;;;;;;;;;; write moves to vbm file 70 ;;;;;;;;;;;;;; write moves to vbm file
71 71
72 72
104 vbm-header 104 vbm-header
105 (map convert-byte (interleave high-bits low-bits)) 105 (map convert-byte (interleave high-bits low-bits))
106 vbm-trailer))] 106 vbm-trailer))]
107 contents)) 107 contents))
108 108
109 (defn write-moves! [moves] 109 (defn write-moves! [moves name]
110 (let [target (moves->filename (count moves))] 110 (let [target (moves-filename name)]
111 (clojure.java.io/copy (buttons->vbm-bytes moves) target) 111 (clojure.java.io/copy (buttons->vbm-bytes moves) target)
112 target)) 112 target))
113 113
114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
115 115