Mercurial > vba-clojure
view clojure/com/aurellem/gb/pokedex.clj @ 573:40f62391db9d
implemented row and column increment logic.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 01 Sep 2012 03:56:30 -0500 |
parents | 0e31aff20d5f |
children |
line wrap: on
line source
1 (ns com.aurellem.gb.pokedex2 (: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-address12 pokedex-seen-start-address)13 (int (/ (dec species-num) 8))))15 (defn read-pokedex16 ([^SaveState state capture? species-num]17 (bit-test18 (aget (memory state)19 (pokedex-offset capture? species-num))20 (rem (dec species-num) 8))))22 (defn set-pokedex23 ([^SaveState state capture? set? species-num]24 (let [target (pokedex-offset capture? species-num)25 current-bits26 (aget (memory state)27 (pokedex-offset capture? species-num))28 bit-offset (rem (dec species-num) 8)]29 (set-memory30 state target31 (if set?32 (bit-set current-bits bit-offset)33 (bit-clear current-bits bit-offset))))))35 (defn read-pokedex-seen36 ([^SaveState state species-or-num]37 (read-pokedex state false38 (species-name->pokedex-num39 species-or-num species-or-num)))40 ([species-or-num]41 (read-pokedex-seen @current-state species-or-num)))43 (defn set-pokedex-seen44 ([^SaveState state species-or-num seen?]45 (set-pokedex state false seen?46 (species-name->pokedex-num47 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-captured52 ([^SaveState state species-or-num]53 (read-pokedex state true54 (species-name->pokedex-num55 species-or-num species-or-num)))56 ([species-or-num]57 (read-pokedex-captured @current-state species-or-num)))59 (defn set-pokedex-captured60 ([^SaveState state species-or-num captured?]61 (set-pokedex state true captured?62 (species-name->pokedex-num63 species-or-num species-or-num)))64 ([species-or-num captured?]65 (set-pokedex-captured @current-state species-or-num captured?)))67 (defn print-pokedex68 ([^SaveState state]69 (println "+-----------+-------+-------+")70 (println "|Pokemon | Seen? | Capt? |")71 (println "+-----------+-------+-------+")72 (dorun73 (map74 #(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-pokedex85 ([^SaveState state]86 (reduce87 (fn [state n]88 (-> state89 (set-pokedex-seen n true)90 (set-pokedex-captured n true)))91 state (range 1 152)))92 ([] (give-full-pokedex @current-state)))94 (defn give-empty-pokedex95 ([^SaveState state]96 (reduce97 (fn [state n]98 (-> state99 (set-pokedex-seen n false)100 (set-pokedex-captured n false)))101 state (range 1 152)))102 ([] (give-empty-pokedex @current-state)))