view clojure/com/aurellem/gb/pokedex.clj @ 270:49096b8b99d5

script: delivered oak's parcel; got pokedex.
author Robert McIntyre <rlm@mit.edu>
date Mon, 26 Mar 2012 23:54:52 -0500
parents 5becef6312b9
children 0e31aff20d5f
line wrap: on
line source
1 (ns com.aurellem.gb.pokedex
2 (:use (com.aurellem.gb gb-driver util species))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
5 (def pokedex-seen-start-address 0xD309)
7 (def pokedex-captured-start-address 0xD2F6)
9 (defn pokedex-offset [capture? species-num]
10 (+ (if capture?
11 pokedex-captured-start-address
12 pokedex-seen-start-address)
13 (int (/ (dec species-num) 8))))
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 (dec species-num) 8))))
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 (dec 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))))))
35 (defn read-pokedex-seen
36 ([^SaveState state species-or-num]
37 (read-pokedex state false
38 (species-name->pokedex-num
39 species-or-num species-or-num)))
40 ([species-or-num]
41 (read-pokedex-seen @current-state species-or-num)))
43 (defn set-pokedex-seen
44 ([^SaveState state species-or-num seen?]
45 (set-pokedex state false seen?
46 (species-name->pokedex-num
47 species-or-num species-or-num)))
48 ([species-or-num seen?]
49 (set-pokedex-seen @current-state species-or-num seen?)))
51 (defn read-pokedex-captured
52 ([^SaveState state species-or-num]
53 (read-pokedex state true
54 (species-name->pokedex-num
55 species-or-num species-or-num)))
56 ([species-or-num]
57 (read-pokedex-captured @current-state species-or-num)))
59 (defn set-pokedex-captured
60 ([^SaveState state species-or-num captured?]
61 (set-pokedex state true captured?
62 (species-name->pokedex-num
63 species-or-num species-or-num)))
64 ([species-or-num captured?]
65 (set-pokedex-captured @current-state species-or-num captured?)))
67 (defn print-pokedex
68 ([^SaveState state]
69 (println "+-----------+-------+-------+")
70 (println "|Pokemon | Seen? | Capt? |")
71 (println "+-----------+-------+-------+")
72 (dorun
73 (map
74 #(printf "|%-11s|%s|%s|\n" %1 %2 %3)
75 (map #(.toUpperCase (.substring (str %) 1))
76 (map pokedex-num->species-name (range 1 152)))
77 (map #(if % " X " " ")
78 (map read-pokedex-seen (range 1 152)))
79 (map #(if % " X " " ")
80 (map read-pokedex-captured (range 1 152)))))
81 (println "+-----------+-------+-------+"))
82 ([] (print-pokedex @current-state)))
84 (defn give-full-pokedex
85 ([^SaveState state]
86 (reduce
87 (fn [state n]
88 (-> state
89 (set-pokedex-seen n true)
90 (set-pokedex-captured n true)))
91 state (range 1 152)))
92 ([] (give-full-pokedex @current-state)))