annotate clojure/com/aurellem/gb/pokedex.clj @ 450:f04d6368049e

simplified notes
author Robert McIntyre <rlm@mit.edu>
date Thu, 03 May 2012 06:42:58 -0500
parents 0e31aff20d5f
children
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@235 13 (int (/ (dec 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@235 20 (rem (dec 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@223 28 bit-offset (rem (dec 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@223 36 ([^SaveState state species-or-num]
rlm@223 37 (read-pokedex state false
rlm@223 38 (species-name->pokedex-num
rlm@223 39 species-or-num species-or-num)))
rlm@223 40 ([species-or-num]
rlm@223 41 (read-pokedex-seen @current-state species-or-num)))
rlm@222 42
rlm@222 43 (defn set-pokedex-seen
rlm@223 44 ([^SaveState state species-or-num seen?]
rlm@223 45 (set-pokedex state false seen?
rlm@223 46 (species-name->pokedex-num
rlm@223 47 species-or-num species-or-num)))
rlm@223 48 ([species-or-num seen?]
rlm@223 49 (set-pokedex-seen @current-state species-or-num seen?)))
rlm@222 50
rlm@222 51 (defn read-pokedex-captured
rlm@223 52 ([^SaveState state species-or-num]
rlm@223 53 (read-pokedex state true
rlm@223 54 (species-name->pokedex-num
rlm@223 55 species-or-num species-or-num)))
rlm@223 56 ([species-or-num]
rlm@223 57 (read-pokedex-captured @current-state species-or-num)))
rlm@222 58
rlm@222 59 (defn set-pokedex-captured
rlm@223 60 ([^SaveState state species-or-num captured?]
rlm@223 61 (set-pokedex state true captured?
rlm@223 62 (species-name->pokedex-num
rlm@223 63 species-or-num species-or-num)))
rlm@223 64 ([species-or-num captured?]
rlm@223 65 (set-pokedex-captured @current-state species-or-num captured?)))
rlm@222 66
rlm@222 67 (defn print-pokedex
rlm@222 68 ([^SaveState state]
rlm@222 69 (println "+-----------+-------+-------+")
rlm@222 70 (println "|Pokemon | Seen? | Capt? |")
rlm@222 71 (println "+-----------+-------+-------+")
rlm@222 72 (dorun
rlm@222 73 (map
rlm@222 74 #(printf "|%-11s|%s|%s|\n" %1 %2 %3)
rlm@222 75 (map #(.toUpperCase (.substring (str %) 1))
rlm@222 76 (map pokedex-num->species-name (range 1 152)))
rlm@222 77 (map #(if % " X " " ")
rlm@235 78 (map read-pokedex-seen (range 1 152)))
rlm@222 79 (map #(if % " X " " ")
rlm@235 80 (map read-pokedex-captured (range 1 152)))))
rlm@222 81 (println "+-----------+-------+-------+"))
rlm@223 82 ([] (print-pokedex @current-state)))
rlm@222 83
rlm@223 84 (defn give-full-pokedex
rlm@223 85 ([^SaveState state]
rlm@223 86 (reduce
rlm@223 87 (fn [state n]
rlm@223 88 (-> state
rlm@223 89 (set-pokedex-seen n true)
rlm@223 90 (set-pokedex-captured n true)))
rlm@223 91 state (range 1 152)))
rlm@223 92 ([] (give-full-pokedex @current-state)))
rlm@286 93
rlm@286 94 (defn give-empty-pokedex
rlm@286 95 ([^SaveState state]
rlm@286 96 (reduce
rlm@286 97 (fn [state n]
rlm@286 98 (-> state
rlm@286 99 (set-pokedex-seen n false)
rlm@286 100 (set-pokedex-captured n false)))
rlm@286 101 state (range 1 152)))
rlm@286 102 ([] (give-empty-pokedex @current-state)))