Mercurial > vba-clojure
comparison clojure/com/aurellem/vbm.clj @ 87:e8855121f413
collect cruft, rename other files
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 10 Mar 2012 14:48:17 -0600 |
parents | 8a895ed4c0f9 |
children | 65c2854c5875 |
comparison
equal
deleted
inserted
replaced
86:9864032ef3c8 | 87:e8855121f413 |
---|---|
1 (ns com.aurellem.vbm | 1 (ns com.aurellem.vbm |
2 (:import java.io.File) | 2 (:import java.io.File) |
3 (:import org.apache.commons.io.FileUtils) | 3 (:import org.apache.commons.io.FileUtils) |
4 (:use com.aurellem.gb-driver)) | 4 (:use com.aurellem.gb-driver)) |
5 | |
6 (defn buttons [mask] | |
7 (loop [buttons [] | |
8 masks (seq (dissoc button-code :listen))] | |
9 (if (empty? masks) buttons | |
10 (let [[button value] (first masks)] | |
11 (if (not= 0x0000 (bit-and value mask)) | |
12 (recur (conj buttons button) (rest masks)) | |
13 (recur buttons (rest masks))))))) | |
5 | 14 |
6 (defn vbm-bytes [#^File vbm] | 15 (defn vbm-bytes [#^File vbm] |
7 (let [bytes (FileUtils/readFileToByteArray vbm) | 16 (let [bytes (FileUtils/readFileToByteArray vbm) |
8 ints (int-array (count bytes))] | 17 ints (int-array (count bytes))] |
9 (areduce bytes idx _ nil | 18 (areduce bytes idx _ nil |
33 | 42 |
34 (defn vbm-buttons [#^File vbm] | 43 (defn vbm-buttons [#^File vbm] |
35 (map buttons (vbm-masks vbm))) | 44 (map buttons (vbm-masks vbm))) |
36 | 45 |
37 (defn play-vbm [#^File vbm] | 46 (defn play-vbm [#^File vbm] |
38 (reset) | 47 (restart!) |
39 (dorun (map step (vbm-masks vbm)))) | 48 (dorun (map step (vbm-masks vbm)))) |
40 | 49 |
41 (defn convert-buttons | 50 (defn convert-buttons |
42 "To write a vbm file, we must remove the last two buttons after any | 51 "To write a vbm file, we must remove the last two buttons after any |
43 reset event." | 52 reset event." |