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