Mercurial > vba-clojure
diff clojure/com/aurellem/vbm.clj @ 71:39928bf4622d
refactored
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 08 Mar 2012 02:47:09 -0600 |
parents | ff6f1acae59e |
children | c88ad4f6d9b4 |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/vbm.clj Thu Mar 08 02:25:20 2012 -0600 1.2 +++ b/clojure/com/aurellem/vbm.clj Thu Mar 08 02:47:09 2012 -0600 1.3 @@ -1,6 +1,7 @@ 1.4 (ns com.aurellem.vbm 1.5 (:import java.io.File) 1.6 - (:import org.apache.commons.io.FileUtils)) 1.7 + (:import org.apache.commons.io.FileUtils) 1.8 + (:use com.aurellem.gb-driver)) 1.9 1.10 (defn vbm-bytes [#^File vbm] 1.11 (let [bytes (FileUtils/readFileToByteArray vbm) 1.12 @@ -10,36 +11,6 @@ 1.13 (bit-and 0xFF (aget bytes idx)))) 1.14 ints)) 1.15 1.16 -(def button-mask 1.17 - {;; main buttons 1.18 - :a 0x0001 1.19 - :b 0x0002 1.20 - 1.21 - ;; directional pad 1.22 - :r 0x0010 1.23 - :l 0x0020 1.24 - :u 0x0040 1.25 - :d 0x0080 1.26 - 1.27 - ;; meta buttons 1.28 - :select 0x0004 1.29 - :start 0x0008 1.30 - 1.31 - ;; hard reset -- not really a button 1.32 - :reset 0x0800}) 1.33 - 1.34 -(defn button-code [buttons] 1.35 - (reduce bit-or 0x0000 (map button-mask buttons))) 1.36 - 1.37 -(defn buttons [mask] 1.38 - (loop [buttons [] 1.39 - masks (seq button-mask)] 1.40 - (if (empty? masks) buttons 1.41 - (let [[button value] (first masks)] 1.42 - (if (not= 0x0000 (bit-and value mask)) 1.43 - (recur (conj buttons button) (rest masks)) 1.44 - (recur buttons (rest masks))))))) 1.45 - 1.46 (def vbm-header-length 255) 1.47 1.48 (defn repair-vbm 1.49 @@ -49,7 +20,7 @@ 1.50 pending vbm-seq] 1.51 (if (empty? pending) fixed 1.52 (let [mask (first pending)] 1.53 - (if (not= 0x0000 (bit-and mask (button-mask :reset))) 1.54 + (if (not= 0x0000 (bit-and mask (button-code :reset))) 1.55 (recur (conj fixed mask 0x0000 0x0000) (next pending)) 1.56 (recur (conj fixed mask) (next pending))))))) 1.57 1.58 @@ -63,6 +34,9 @@ 1.59 (defn vbm-buttons [#^File vbm] 1.60 (map buttons (vbm-masks vbm))) 1.61 1.62 +(defn play-vbm [#^File vbm] 1.63 + (reset) 1.64 + (dorun (map step (vbm-masks vbm)))) 1.65 1.66 1.67