comparison clojure/com/aurellem/gb/pokedex.clj @ 222:c9a855de1d07

enabled pokedex printing.
author Robert McIntyre <rlm@mit.edu>
date Sat, 24 Mar 2012 03:10:56 -0500
parents
children 3dfb9dd3db9d
comparison
equal deleted inserted replaced
221:2fac825a4de9 222:c9a855de1d07
1 (ns com.aurellem.gb.pokedex
2 (:use (com.aurellem.gb gb-driver util species))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
4
5 (def pokedex-seen-start-address 0xD309)
6
7 (def pokedex-captured-start-address 0xD2F6)
8
9 (defn pokedex-offset [capture? species-num]
10 (+ (if capture?
11 pokedex-captured-start-address
12 pokedex-seen-start-address)
13 (int (/ species-num 8))))
14
15 (defn read-pokedex
16 ([^SaveState state capture? species-num]
17 (bit-test
18 (aget (memory state)
19 (pokedex-offset capture? species-num))
20 (rem species-num 8))))
21
22 (defn set-pokedex
23 ([^SaveState state capture? set? species-num]
24 (let [target (pokedex-offset capture? species-num)
25 current-bits
26 (aget (memory state)
27 (pokedex-offset capture? species-num))
28 bit-offset (rem species-num 8)]
29 (set-memory
30 state target
31 (if set?
32 (bit-set current-bits bit-offset)
33 (bit-clear current-bits bit-offset))))))
34
35 (defn read-pokedex-seen
36 ([^SaveState state species-num]
37 (read-pokedex state false species-num))
38 ([species-num]
39 (read-pokedex-seen @current-state species-num)))
40
41 (defn set-pokedex-seen
42 ([^SaveState state species-num]
43 (set-pokedex state false species-num))
44 ([species-num]
45 (set-pokedex-seen @current-state species-num)))
46
47 (defn read-pokedex-captured
48 ([^SaveState state species-num]
49 (read-pokedex state true species-num))
50 ([species-num]
51 (read-pokedex-captured @current-state species-num)))
52
53 (defn set-pokedex-captured
54 ([^SaveState state species-num]
55 (set-pokedex state true species-num))
56 ([species-num]
57 (set-pokedex-captured @current-state species-num)))
58
59 (defn print-pokedex
60 ([^SaveState state]
61 (println "+-----------+-------+-------+")
62 (println "|Pokemon | Seen? | Capt? |")
63 (println "+-----------+-------+-------+")
64 (dorun
65 (map
66 #(printf "|%-11s|%s|%s|\n" %1 %2 %3)
67 (map #(.toUpperCase (.substring (str %) 1))
68 (map pokedex-num->species-name (range 1 152)))
69 (map #(if % " X " " ")
70 (map read-pokedex-seen (range 152)))
71 (map #(if % " X " " ")
72 (map read-pokedex-captured (range 152)))))
73 (println "+-----------+-------+-------+"))
74
75 ([] (print-pokedex @current-state)))
76