diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/clojure/com/aurellem/gb/pokedex.clj	Sat Mar 24 03:10:56 2012 -0500
     1.3 @@ -0,0 +1,76 @@
     1.4 +(ns com.aurellem.gb.pokedex
     1.5 +  (:use (com.aurellem.gb gb-driver util species))
     1.6 +  (:import [com.aurellem.gb.gb_driver SaveState]))
     1.7 +
     1.8 +(def pokedex-seen-start-address 0xD309)
     1.9 +
    1.10 +(def pokedex-captured-start-address 0xD2F6)
    1.11 +
    1.12 +(defn pokedex-offset [capture? species-num]
    1.13 +  (+ (if capture?
    1.14 +       pokedex-captured-start-address
    1.15 +       pokedex-seen-start-address)
    1.16 +     (int (/ species-num 8))))
    1.17 +  
    1.18 +(defn read-pokedex
    1.19 +  ([^SaveState state capture? species-num]
    1.20 +     (bit-test
    1.21 +      (aget (memory state)
    1.22 +            (pokedex-offset capture? species-num))
    1.23 +      (rem species-num 8))))
    1.24 +
    1.25 +(defn set-pokedex
    1.26 +  ([^SaveState state capture? set? species-num]
    1.27 +     (let [target (pokedex-offset capture? species-num)
    1.28 +           current-bits
    1.29 +           (aget (memory state)
    1.30 +                 (pokedex-offset capture? species-num))
    1.31 +           bit-offset (rem species-num 8)]
    1.32 +       (set-memory
    1.33 +        state target
    1.34 +        (if set?
    1.35 +          (bit-set   current-bits bit-offset)
    1.36 +          (bit-clear current-bits bit-offset))))))
    1.37 +
    1.38 +(defn read-pokedex-seen
    1.39 +  ([^SaveState state species-num]
    1.40 +     (read-pokedex state false species-num))
    1.41 +  ([species-num]
    1.42 +     (read-pokedex-seen @current-state species-num)))
    1.43 +
    1.44 +(defn set-pokedex-seen
    1.45 +  ([^SaveState state species-num]
    1.46 +     (set-pokedex state false species-num))
    1.47 +  ([species-num]
    1.48 +     (set-pokedex-seen @current-state species-num)))
    1.49 +
    1.50 +(defn read-pokedex-captured
    1.51 +  ([^SaveState state species-num]
    1.52 +     (read-pokedex state true species-num))
    1.53 +  ([species-num]
    1.54 +     (read-pokedex-captured @current-state species-num)))
    1.55 +
    1.56 +(defn set-pokedex-captured
    1.57 +  ([^SaveState state species-num]
    1.58 +     (set-pokedex state true species-num))
    1.59 +  ([species-num]
    1.60 +     (set-pokedex-captured @current-state species-num)))
    1.61 +
    1.62 +(defn print-pokedex
    1.63 +  ([^SaveState state]
    1.64 +     (println "+-----------+-------+-------+")
    1.65 +     (println "|Pokemon    | Seen? | Capt? |")
    1.66 +     (println "+-----------+-------+-------+")
    1.67 +     (dorun
    1.68 +      (map
    1.69 +       #(printf "|%-11s|%s|%s|\n" %1 %2 %3)
    1.70 +       (map #(.toUpperCase (.substring (str %) 1))
    1.71 +            (map pokedex-num->species-name (range 1 152)))
    1.72 +       (map #(if % "   X   " "       ")
    1.73 +            (map read-pokedex-seen (range 152)))
    1.74 +       (map #(if % "   X   " "       ")
    1.75 +            (map read-pokedex-captured (range 152)))))
    1.76 +     (println "+-----------+-------+-------+"))
    1.77 +
    1.78 +  ([] (print-pokedex @current-state)))
    1.79 +     
    1.80 \ No newline at end of file