comparison clojure/com/aurellem/gb/stats.clj @ 202:1ce54929bc0c

enhanced pokemon printing to print out current HP as well as current total HP.
author Robert McIntyre <rlm@mit.edu>
date Fri, 23 Mar 2012 03:31:49 -0500
parents fd549c8f42ae
children 912496041f98
comparison
equal deleted inserted replaced
201:53a74450dc8a 202:1ce54929bc0c
7 (defn pokemon-stats-address [poke-num] 7 (defn pokemon-stats-address [poke-num]
8 (+ pokemon-1-stats-start-address 8 (+ pokemon-1-stats-start-address
9 (* poke-num pokemon-record-width))) 9 (* poke-num pokemon-record-width)))
10 10
11 (def stats-record-size 11) 11 (def stats-record-size 11)
12
13 (def pokemon-1-current-hp-address 0xD16B)
14
15 (defn current-hp-address [poke-num]
16 (+ pokemon-1-current-hp-address
17 (* pokemon-record-width poke-num)))
18
19 (defn read-current-hp
20 ([^SaveState state poke-num]
21 (let [mem (memory state)
22 start (current-hp-address poke-num)
23 hp-h (aget mem start)
24 hp-l (aget mem (inc start))]
25 (glue-bytes hp-h hp-l)))
26 ([poke-num]
27 (read-current-hp @current-state poke-num)))
28
29 (defn set-current-hp
30 ([^SaveState state poke-num new-hp]
31 (set-memory state (current-hp-address poke-num)
32 (disect-bytes-2 new-hp)))
33 ([poke-num new-hp]
34 (set-current-hp @current-state poke-num new-hp)))
12 35
13 (defn read-stats 36 (defn read-stats
14 ([^SaveState state poke-num] 37 ([^SaveState state poke-num]
15 (let [start (pokemon-stats-address poke-num) 38 (let [start (pokemon-stats-address poke-num)
16 [level 39 [level
25 special-h 48 special-h
26 special-l] 49 special-l]
27 (subvec (vec (memory state)) 50 (subvec (vec (memory state))
28 start (+ start stats-record-size ))] 51 start (+ start stats-record-size ))]
29 {:level level 52 {:level level
53 :current-hp (read-current-hp state poke-num)
30 :hp (glue-bytes hp-h hp-l) 54 :hp (glue-bytes hp-h hp-l)
31 :attack (glue-bytes attack-h attack-l) 55 :attack (glue-bytes attack-h attack-l)
32 :defense (glue-bytes defense-h defense-l) 56 :defense (glue-bytes defense-h defense-l)
33 :speed (glue-bytes speed-h speed-l) 57 :speed (glue-bytes speed-h speed-l)
34 :special (glue-bytes special-h special-l)})) 58 :special (glue-bytes special-h special-l)}))
45 (disect-bytes-2 (:hp new-stats*)) 69 (disect-bytes-2 (:hp new-stats*))
46 (disect-bytes-2 (:attack new-stats*)) 70 (disect-bytes-2 (:attack new-stats*))
47 (disect-bytes-2 (:defense new-stats*)) 71 (disect-bytes-2 (:defense new-stats*))
48 (disect-bytes-2 (:speed new-stats*)) 72 (disect-bytes-2 (:speed new-stats*))
49 (disect-bytes-2 (:special new-stats*))])] 73 (disect-bytes-2 (:special new-stats*))])]
50 (set-memory-range state (pokemon-stats-address poke-num) 74 (set-current-hp
51 raw-stats))) 75 (set-memory-range state (pokemon-stats-address poke-num)
76 raw-stats)
77 (:current-hp new-stats*))))
52 ([poke-num new-stats] 78 ([poke-num new-stats]
53 (give-stats @current-state poke-num new-stats))) 79 (give-stats @current-state poke-num new-stats)))
80
81
82
83