comparison clojure/com/aurellem/gb/money.clj @ 224:10e26e7ceedb

added functions for setting current money.
author Robert McIntyre <rlm@mit.edu>
date Sat, 24 Mar 2012 04:29:37 -0500
parents
children
comparison
equal deleted inserted replaced
223:3dfb9dd3db9d 224:10e26e7ceedb
1 (ns com.aurellem.gb.money
2 (:use (com.aurellem.gb gb-driver util))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
4
5 (def money-address 0xD346)
6
7 (defn read-money
8 "lol money is stored in BCD."
9 ([^SaveState state]
10 (Integer/parseInt
11 (apply str
12 (map
13 #(Integer/toHexString %)
14 (subvec (vec (memory state)) money-address
15 (+ money-address 3)))) 10))
16 ([] (read-money @current-state)))
17
18 (defn set-money
19 ([^SaveState state new-money]
20 (let [str-money (str new-money)]
21 (assert (<= 0 (count str-money) 6))
22 (set-memory-range
23 state
24 money-address
25 (map #(Integer/parseInt % 16)
26 (map (partial apply str)
27 (partition
28 2
29 (concat (repeat (- 6 (count str-money)) "0")
30 (vec str-money))))))))
31 ([new-money] (set-money @current-state new-money)))