annotate clojure/com/aurellem/gb/money.clj @ 599:4503899241e6

going to render the advanced choreo.
author Robert McIntyre <rlm@mit.edu>
date Sun, 02 Sep 2012 09:18:43 -0500
parents 10e26e7ceedb
children
rev   line source
rlm@224 1 (ns com.aurellem.gb.money
rlm@224 2 (:use (com.aurellem.gb gb-driver util))
rlm@224 3 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@224 4
rlm@224 5 (def money-address 0xD346)
rlm@224 6
rlm@224 7 (defn read-money
rlm@224 8 "lol money is stored in BCD."
rlm@224 9 ([^SaveState state]
rlm@224 10 (Integer/parseInt
rlm@224 11 (apply str
rlm@224 12 (map
rlm@224 13 #(Integer/toHexString %)
rlm@224 14 (subvec (vec (memory state)) money-address
rlm@224 15 (+ money-address 3)))) 10))
rlm@224 16 ([] (read-money @current-state)))
rlm@224 17
rlm@224 18 (defn set-money
rlm@224 19 ([^SaveState state new-money]
rlm@224 20 (let [str-money (str new-money)]
rlm@224 21 (assert (<= 0 (count str-money) 6))
rlm@224 22 (set-memory-range
rlm@224 23 state
rlm@224 24 money-address
rlm@224 25 (map #(Integer/parseInt % 16)
rlm@224 26 (map (partial apply str)
rlm@224 27 (partition
rlm@224 28 2
rlm@224 29 (concat (repeat (- 6 (count str-money)) "0")
rlm@224 30 (vec str-money))))))))
rlm@224 31 ([new-money] (set-money @current-state new-money)))