changeset 348:497ca041f5af

finished working for now. i've completed more carving up of code blocks.
author Dylan Holmes <ocsenave@gmail.com>
date Sun, 08 Apr 2012 07:55:06 -0500
parents ff65ee0944fe
children 37616a97beaa 5aabbe326eb0
files clojure/com/aurellem/gb/hxc.clj org/rom.org
diffstat 2 files changed, 856 insertions(+), 782 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/hxc.clj	Sun Apr 08 06:13:39 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/hxc.clj	Sun Apr 08 07:55:06 2012 -0500
     1.3 @@ -4,9 +4,6 @@
     1.4                           constants species))
     1.5    (:import [com.aurellem.gb.gb_driver SaveState]))
     1.6  
     1.7 -
     1.8 -
     1.9 -
    1.10  ; ************* HANDWRITTEN CONSTANTS
    1.11  
    1.12  (def pkmn-types
    1.13 @@ -163,7 +160,6 @@
    1.14  ;; --------------------------------------------------
    1.15  
    1.16  
    1.17 -
    1.18  (defn hxc-pokenames-raw
    1.19    "The hardcoded names of the 190 species in memory. List begins at
    1.20  ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters
    1.21 @@ -202,6 +198,10 @@
    1.22           
    1.23           names)))))
    1.24  
    1.25 +(def hxc-types
    1.26 +  "The hardcoded type names in memory. List begins at ROM@27D99,
    1.27 +  shortly before hxc-titles."
    1.28 +  (hxc-thunk-words 0x27D99 102))
    1.29  
    1.30  
    1.31  ;; http://hax.iimarck.us/topic/581/
    1.32 @@ -248,15 +248,20 @@
    1.33      (map second
    1.34           ((hxc-cry) pkmn)))))
    1.35  
    1.36 +
    1.37 +
    1.38 +
    1.39  (def hxc-items-raw
    1.40    "The hardcoded names of the items in memory. List begins at
    1.41  ROM@045B7"
    1.42    (hxc-thunk-words 0x45B7 870))
    1.43  
    1.44 -(def hxc-types
    1.45 -  "The hardcoded type names in memory. List begins at ROM@27D99,
    1.46 -  shortly before hxc-titles."
    1.47 -  (hxc-thunk-words 0x27D99 102))
    1.48 +(def hxc-items
    1.49 +  "The hardcoded names of the items in memory, presented as
    1.50 +  keywords. List begins at ROM@045B7. See also, hxc-items-raw."
    1.51 +  (comp (partial map format-name) hxc-items-raw))
    1.52 +
    1.53 +
    1.54  
    1.55  (def hxc-titles
    1.56    "The hardcoded names of the trainer titles in memory. List begins at
    1.57 @@ -271,10 +276,6 @@
    1.58  
    1.59  
    1.60  
    1.61 -(def hxc-items
    1.62 -  "The hardcoded names of the items in memory, presented as
    1.63 -  keywords. List begins at ROM@045B7. See also, hxc-items-raw."
    1.64 -  (comp (partial map format-name) hxc-items-raw))
    1.65  
    1.66  (defn hxc-pokedex-text
    1.67    "The hardcoded pokedex entries in memory, presented as an
    1.68 @@ -288,7 +289,6 @@
    1.69  
    1.70  ;; In red/blue, pokedex stats are in internal order.
    1.71  ;; In yellow, pokedex stats are in pokedex order.
    1.72 -
    1.73  (defn hxc-pokedex-stats
    1.74    "The hardcoded pokedex stats (species height weight) in memory. List
    1.75  begins at ROM@40687"
    1.76 @@ -348,9 +348,6 @@
    1.77  
    1.78  
    1.79  
    1.80 -
    1.81 -
    1.82 -
    1.83  (def hxc-places
    1.84    "The hardcoded place names in memory. List begins at
    1.85  ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."
    1.86 @@ -373,8 +370,6 @@
    1.87  (def hxc-move-names
    1.88    "The hardcoded move names in memory. List begins at ROM@BC000"
    1.89    (hxc-thunk-words 0xBC000 1551))
    1.90 -
    1.91 -
    1.92  (defn hxc-move-data
    1.93    "The hardcoded (basic (move effects)) in memory. List begins at
    1.94  0x38000. Returns a map of {:name :power :accuracy :pp :fx-id
    1.95 @@ -457,6 +452,7 @@
    1.96  
    1.97  
    1.98  
    1.99 +
   1.100  (defn internal-id
   1.101    ([rom]
   1.102       (zipmap 
   1.103 @@ -487,22 +483,6 @@
   1.104  
   1.105  
   1.106  
   1.107 -(defn hxc-advantage
   1.108 -  ;; in-game multipliers are stored as 10x their effective value
   1.109 -  ;; to allow for fractional multipliers like 1/2
   1.110 -  
   1.111 -  "The hardcoded type advantages in memory, returned as tuples of
   1.112 -  atk-type def-type multiplier. By default (i.e. if not listed here),
   1.113 -the multiplier is 1. List begins at 0x3E62D."
   1.114 -  ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))
   1.115 -  ([rom]
   1.116 -     (map
   1.117 -      (fn [[atk def mult]] [(get pkmn-types atk (hex atk))
   1.118 -                            (get pkmn-types def (hex def))
   1.119 -                            (/ mult 10)])
   1.120 -      (partition 3
   1.121 -                 (take-while (partial not= 0xFF)
   1.122 -                             (drop 0x3E62D rom))))))
   1.123  
   1.124  
   1.125  
   1.126 @@ -595,63 +575,6 @@
   1.127               
   1.128                                    
   1.129  
   1.130 -
   1.131 -(defn hxc-evolution
   1.132 -  "Hardcoded evolution data in memory. The data exists at ROM@34000,
   1.133 -  sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."
   1.134 -  ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
   1.135 -  ([rom]
   1.136 -       (apply assoc {}
   1.137 -               (interleave
   1.138 -                (hxc-pokenames rom)
   1.139 -                (map
   1.140 -                 (comp
   1.141 -                  format-evo
   1.142 -                  (partial take-while (comp not zero?))
   1.143 -                  #(drop % rom))
   1.144 -                 (hxc-ptrs-evolve rom)
   1.145 -                 )))))
   1.146 -
   1.147 -(defn hxc-evolution-pretty
   1.148 -  "Like hxc-evolution, except it uses the names of items and pokemon
   1.149 ---- grabbed from ROM --- rather than their numerical identifiers."
   1.150 -  ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))
   1.151 -  ([rom]
   1.152 -     (let
   1.153 -         [poke-names (vec (hxc-pokenames rom))
   1.154 -          item-names (vec (hxc-items rom))
   1.155 -          use-names
   1.156 -          (fn [m]
   1.157 -            (loop [ks (keys m) new-map m]
   1.158 -              (let [k (first ks)]
   1.159 -                (cond (nil? ks) new-map
   1.160 -                      (= k :into)
   1.161 -                      (recur
   1.162 -                       (next ks)
   1.163 -                       (assoc new-map
   1.164 -                         :into
   1.165 -                         (poke-names
   1.166 -                          (:into
   1.167 -                           new-map))))
   1.168 -                      (= k :item)
   1.169 -                      (recur
   1.170 -                       (next ks)
   1.171 -                       (assoc new-map
   1.172 -                         :item
   1.173 -                         (item-names
   1.174 -                          (:item new-map))))
   1.175 -                      :else
   1.176 -                      (recur
   1.177 -                       (next ks)
   1.178 -                       new-map)
   1.179 -                      ))))]
   1.180 -
   1.181 -       (into {}
   1.182 -             (map (fn [[pkmn evo-coll]]
   1.183 -                    [pkmn (map use-names evo-coll)])
   1.184 -                  (hxc-evolution rom))))))
   1.185 -
   1.186 -
   1.187  (defn hxc-pokemon-base
   1.188    ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))
   1.189    ([rom]
   1.190 @@ -751,6 +674,7 @@
   1.191                      (take (* entry-size pkmn-count)
   1.192                            (drop 0x383DE
   1.193                                  rom))))))))
   1.194 +
   1.195    
   1.196    
   1.197  (defn hxc-intro-pkmn
   1.198 @@ -826,7 +750,6 @@
   1.199  
   1.200  
   1.201  
   1.202 -
   1.203  (defn hxc-ptrs-wild
   1.204    "A list of the hardcoded wild encounter data in memory. Pointers
   1.205    begin at ROM@0CB95; data begins at ROM@0x04D89" 
   1.206 @@ -860,17 +783,6 @@
   1.207  
   1.208  
   1.209  
   1.210 -
   1.211 -
   1.212 -
   1.213 -
   1.214 -
   1.215 -
   1.216 -
   1.217 -
   1.218 -
   1.219 -
   1.220 -
   1.221  ;; ********************** MANIPULATION FNS
   1.222  
   1.223  
     2.1 --- a/org/rom.org	Sun Apr 08 06:13:39 2012 -0500
     2.2 +++ b/org/rom.org	Sun Apr 08 07:55:06 2012 -0500
     2.3 @@ -12,6 +12,826 @@
     2.4  # pokedollar: U+20B1
     2.5  * Introduction
     2.6  
     2.7 +
     2.8 +** COMMENT Getting linguistic data: names, words, etc.
     2.9 +
    2.10 +Some of the simplest data 
    2.11 +
    2.12 +
    2.13 +One of the simplest data structures in the Pok\eacute{} ROM is an
    2.14 +unbroken list of strings that either (a) all have a specific length,
    2.15 +or (b) are all separated by the same character.
    2.16 +
    2.17 +Because lots of good data has this format, we'll start by writing a
    2.18 +template function to extract it:
    2.19 +
    2.20 +#+name: hxc-thunks
    2.21 +#+begin_src clojure :results silent
    2.22 +(defn hxc-thunk
    2.23 +  "Creates a thunk (nullary fn) that grabs data in a certain region of rom and
    2.24 +splits it into a collection by 0x50. If rom is not supplied, uses the
    2.25 +  original rom data."
    2.26 +  [start length]
    2.27 +  (fn self
    2.28 +    ([rom]
    2.29 +       (take-nth 2
    2.30 +                 (partition-by #(= % 0x50)
    2.31 +                               (take length
    2.32 +                                     (drop start rom)))))
    2.33 +    ([]
    2.34 +      (self com.aurellem.gb.gb-driver/original-rom))))
    2.35 +
    2.36 +(def hxc-thunk-words
    2.37 +  "Same as hxc-thunk, except it interprets the rom data as characters,
    2.38 +  returning a collection of strings."
    2.39 +  (comp
    2.40 +   (partial comp (partial map character-codes->str))
    2.41 +   hxc-thunk))
    2.42 +
    2.43 +#+end_src
    2.44 +
    2.45 +
    2.46 +* Pok\eacute{}mon I
    2.47 +** Names of each species
    2.48 +The names of the Pok\eacute{}mon species are stored in
    2.49 +ROM@E8000. This name list is interesting, for a number of reasons:
    2.50 +- The names are stored in [[ ][internal order]] rather than in the familiar
    2.51 +  Pok\eacute{}dex order. This seemingly random order probably represents the order in which the authors created or
    2.52 +  programmed in the Pok\eacute{}mon; it's used throughout the game.
    2.53 +- There is enough space allocated for 190 Pok\eacute{}mon. As I
    2.54 +  understand it, there were originally going to be 190 Pok\eacute{}mon
    2.55 +  in Generation I, but the creators decided to defer some to
    2.56 +  Generation II. This explains why many Gen I and Gen II Pok\eacute{}mon
    2.57 +  have the same aesthetic feel.
    2.58 +- The list is pockmarked with random gaps, due to the strange internal
    2.59 +  ordering
    2.60 +  and the 39 unused spaces [fn::190 allocated spaces minus 151 true Pok\eacute{}mon]. These missing spaces are filled with the
    2.61 +  placeholder name  =MISSINGNO.= (\ldquo{}Missing number\rdquo{}).
    2.62 +
    2.63 +Each name is exactly ten letters long; whenever a name would be too short, the extra
    2.64 +space is padded with the character 0x50. 
    2.65 +
    2.66 +*** See the data
    2.67 +
    2.68 +Here you can see the raw data in three stages: in the first stage, we
    2.69 +just grab the first few bytes starting from position 0xE8000. In the
    2.70 +second stage, we partition it into ten-letter chunks to show you
    2.71 +where the names begin and end. In the final stage, we convert each
    2.72 +byte into the letter it represents using the =character-codes->str=
    2.73 +function. (0x50 is rendered as the symbol \ldquo{} =#= \rdquo{} for
    2.74 +ease of reading).
    2.75 +
    2.76 +#+begin_src clojure :exports both :cache no :results output 
    2.77 +(ns com.aurellem.gb.hxc
    2.78 +  (:use (com.aurellem.gb assembly characters gb-driver util mem-util
    2.79 +                         constants))
    2.80 +  (:import [com.aurellem.gb.gb_driver SaveState]))
    2.81 +
    2.82 +(println (take 100 (drop 0xE8000 (rom))))
    2.83 +
    2.84 +(println (partition 10 (take 100 (drop 0xE8000 (rom)))))
    2.85 +
    2.86 +(println (character-codes->str (take 100 (drop 0xE8000 (rom)))))
    2.87 +
    2.88 +
    2.89 +#+end_src
    2.90 +
    2.91 +#+results:
    2.92 +: (145 135 152 131 142 141 80 80 80 80 138 128 141 134 128 146 138 135 128 141 141 136 131 142 145 128 141 239 80 80 130 139 132 133 128 136 145 152 80 80 146 143 132 128 145 142 150 80 80 80 149 142 139 147 142 145 129 80 80 80 141 136 131 142 138 136 141 134 80 80 146 139 142 150 129 145 142 80 80 80 136 149 152 146 128 148 145 80 80 80 132 151 132 134 134 148 147 142 145 80)
    2.93 +: ((145 135 152 131 142 141 80 80 80 80) (138 128 141 134 128 146 138 135 128 141) (141 136 131 142 145 128 141 239 80 80) (130 139 132 133 128 136 145 152 80 80) (146 143 132 128 145 142 150 80 80 80) (149 142 139 147 142 145 129 80 80 80) (141 136 131 142 138 136 141 134 80 80) (146 139 142 150 129 145 142 80 80 80) (136 149 152 146 128 148 145 80 80 80) (132 151 132 134 134 148 147 142 145 80))
    2.94 +: RHYDON####KANGASKHANNIDORAN♂##CLEFAIRY##SPEAROW###VOLTORB###NIDOKING##SLOWBRO###IVYSAUR###EXEGGUTOR#
    2.95 +
    2.96 +
    2.97 +*** Automatically grab the data.
    2.98 +
    2.99 +    #+name: pokenames
   2.100 +    #+begin_src clojure
   2.101 +
   2.102 +(defn hxc-pokenames-raw
   2.103 +  "The hardcoded names of the 190 species in memory. List begins at
   2.104 +ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters
   2.105 +  long, these names are stripped of padding. See also, hxc-pokedex-names"
   2.106 +  ([]
   2.107 +     (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom))
   2.108 +  ([rom]
   2.109 +     (let [count-species 190
   2.110 +           name-length 10]
   2.111 +       (map character-codes->str
   2.112 +            (partition name-length
   2.113 +                       (map #(if (= 0x50 %) 0x00 %)
   2.114 +                            (take (* count-species name-length)
   2.115 +                                  (drop 0xE8000
   2.116 +                                        rom))))))))
   2.117 +(def hxc-pokenames
   2.118 +  (comp
   2.119 +   (partial map format-name)
   2.120 +   hxc-pokenames-raw))
   2.121 +
   2.122 +
   2.123 +
   2.124 +
   2.125 +(defn hxc-pokedex-names
   2.126 +  "The names of the pokemon in hardcoded pokedex order. List begins at
   2.127 +ROM@410B1. See also, hxc-pokenames."
   2.128 +  ([] (hxc-pokedex-names
   2.129 +       com.aurellem.gb.gb-driver/original-rom))
   2.130 +  ([rom]
   2.131 +     (let [names (hxc-pokenames rom)]
   2.132 +       (#(mapv %
   2.133 +               ((comp range count keys) %))
   2.134 +        (zipmap
   2.135 +         (take (count names)
   2.136 +               (drop 0x410b1 rom))
   2.137 +         
   2.138 +         names)))))
   2.139 +
   2.140 +    #+end_src
   2.141 +
   2.142 +
   2.143 +
   2.144 +** Generic species information
   2.145 +
   2.146 +#+name: pokebase
   2.147 +#+begin_src clojure
   2.148 +(defn hxc-pokemon-base
   2.149 +  ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))
   2.150 +  ([rom]
   2.151 +     (let [entry-size 28
   2.152 +           pkmn-count (count (hxc-pokedex-text rom))
   2.153 +           pokemon (rest (hxc-pokedex-names))
   2.154 +           types (apply assoc {}
   2.155 +                        (interleave
   2.156 +                         (range)
   2.157 +                         pkmn-types)) ;;!! softcoded
   2.158 +           moves (apply assoc {}
   2.159 +                        (interleave
   2.160 +                         (range)
   2.161 +                         (map format-name
   2.162 +                              (hxc-move-names rom))))
   2.163 +           machines (hxc-machines)
   2.164 +           ]
   2.165 +       (zipmap
   2.166 +        pokemon
   2.167 +        (map
   2.168 +         (fn [[n
   2.169 +               rating-hp
   2.170 +               rating-atk
   2.171 +               rating-def
   2.172 +               rating-speed
   2.173 +               rating-special
   2.174 +               type-1
   2.175 +               type-2
   2.176 +               rarity
   2.177 +               rating-xp
   2.178 +               pic-dimensions ;; tile_width|tile_height (8px/tile)
   2.179 +               ptr-pic-obverse-1
   2.180 +               ptr-pic-obverse-2
   2.181 +               ptr-pic-reverse-1
   2.182 +               ptr-pic-reverse-2
   2.183 +               move-1
   2.184 +               move-2
   2.185 +               move-3
   2.186 +               move-4
   2.187 +               growth-rate
   2.188 +               &
   2.189 +               TMs|HMs]]
   2.190 +           (let
   2.191 +               [base-moves
   2.192 +                (mapv moves
   2.193 +                      ((comp
   2.194 +                        ;; since the game uses zero as a delimiter,
   2.195 +                        ;; it must also increment all move indices by 1.
   2.196 +                        ;; heren we decrement to correct this.
   2.197 +                        (partial map dec)
   2.198 +                        (partial take-while (comp not zero?)))
   2.199 +                       [move-1 move-2 move-3 move-4]))
   2.200 +                
   2.201 +                types
   2.202 +                (set (list (types type-1)
   2.203 +                           (types type-2)))
   2.204 +                TMs|HMs
   2.205 +                (map
   2.206 +                 (comp
   2.207 +                  (partial map first)
   2.208 +                  (partial remove (comp zero? second)))
   2.209 +                 (split-at
   2.210 +                  50
   2.211 +                  (map vector
   2.212 +                       (rest(range))
   2.213 +                       (reduce concat
   2.214 +                               (map
   2.215 +                                #(take 8
   2.216 +                                       (concat (bit-list %)
   2.217 +                                               (repeat 0)))
   2.218 +                                
   2.219 +                                TMs|HMs)))))
   2.220 +                
   2.221 +                TMs  (vec (first TMs|HMs))
   2.222 +                HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))
   2.223 +                
   2.224 +                
   2.225 +                ]
   2.226 +             
   2.227 +             
   2.228 +             {:dex# n
   2.229 +              :base-moves base-moves
   2.230 +              :types types
   2.231 +              :TMs TMs
   2.232 +              :HMs HMs
   2.233 +              :base-hp rating-hp
   2.234 +              :base-atk rating-atk
   2.235 +              :base-def rating-def
   2.236 +              :base-speed rating-speed
   2.237 +              :base-special rating-special
   2.238 +              :o0 pic-dimensions
   2.239 +              :o1 ptr-pic-obverse-1
   2.240 +              :o2 ptr-pic-obverse-2
   2.241 +              }))
   2.242 +         
   2.243 +         (partition entry-size
   2.244 +                    (take (* entry-size pkmn-count)
   2.245 +                          (drop 0x383DE
   2.246 +                                rom))))))))
   2.247 +
   2.248 +#+end_src
   2.249 +
   2.250 +
   2.251 +** Pok\eacute{}mon evolutions
   2.252 +#+name: evolution-header
   2.253 +#+begin_src clojure
   2.254 +(defn format-evo
   2.255 +  "Parse a sequence of evolution data, returning a map. First is the
   2.256 +method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the
   2.257 +  method of evolution is by item (only stones will actually make pokemon
   2.258 +  evolve, for some auxillary reason.) Finally, the minimum level for
   2.259 +  evolution to occur (level 1 means no limit, which is used for trade
   2.260 +  and item evolutions), followed by the internal id of the pokemon
   2.261 +  into which to evolve. Hence, level up and trade evolutions are
   2.262 +  described with 3
   2.263 +  bytes; item evolutions with four."
   2.264 +  [coll]
   2.265 +  (let [method (first coll)]
   2.266 +    (cond (empty? coll) []
   2.267 +          (= 0 method) [] ;; just in case
   2.268 +          (= 1 method) ;; level-up evolution
   2.269 +          (conj (format-evo (drop 3 coll))
   2.270 +                            {:method :level-up
   2.271 +                             :min-level (nth coll 1)
   2.272 +                             :into (dec (nth coll 2))})
   2.273 +          
   2.274 +          (= 2 method) ;; item evolution
   2.275 +          (conj (format-evo (drop 4 coll))
   2.276 +                {:method :item
   2.277 +                 :item (dec (nth coll 1))
   2.278 +                 :min-level (nth coll 2)
   2.279 +                 :into (dec (nth coll 3))})
   2.280 +
   2.281 +          (= 3 method) ;; trade evolution
   2.282 +          (conj (format-evo (drop 3 coll))
   2.283 +                {:method :trade
   2.284 +                 :min-level (nth coll 1) ;; always 1 for trade.
   2.285 +                 :into (dec (nth coll 2))}))))
   2.286 +
   2.287 +
   2.288 +(defn hxc-ptrs-evolve
   2.289 +  "A hardcoded collection of 190 pointers to alternating evolution/learnset data,
   2.290 +in internal order."
   2.291 +  ([]
   2.292 +     (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))
   2.293 +  ([rom]
   2.294 +     (let [
   2.295 +           pkmn-count (count (hxc-pokenames-raw)) ;; 190
   2.296 +           ptrs
   2.297 +           (map (fn [[a b]] (low-high a b))
   2.298 +                (partition 2
   2.299 +                           (take (* 2 pkmn-count)
   2.300 +                                 (drop 0x3b1e5 rom))))]
   2.301 +       (map (partial + 0x34000) ptrs)
   2.302 +
   2.303 +       )))
   2.304 +#+end_src
   2.305 +
   2.306 +#+name:evolution
   2.307 +#+begin_src clojure
   2.308 +
   2.309 +(defn hxc-evolution
   2.310 +  "Hardcoded evolution data in memory. The data exists at ROM@34000,
   2.311 +  sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."
   2.312 +  ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
   2.313 +  ([rom]
   2.314 +       (apply assoc {}
   2.315 +               (interleave
   2.316 +                (hxc-pokenames rom)
   2.317 +                (map
   2.318 +                 (comp
   2.319 +                  format-evo
   2.320 +                  (partial take-while (comp not zero?))
   2.321 +                  #(drop % rom))
   2.322 +                 (hxc-ptrs-evolve rom)
   2.323 +                 )))))
   2.324 +
   2.325 +(defn hxc-evolution-pretty
   2.326 +  "Like hxc-evolution, except it uses the names of items and pokemon
   2.327 +--- grabbed from ROM --- rather than their numerical identifiers."
   2.328 +  ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))
   2.329 +  ([rom]
   2.330 +     (let
   2.331 +         [poke-names (vec (hxc-pokenames rom))
   2.332 +          item-names (vec (hxc-items rom))
   2.333 +          use-names
   2.334 +          (fn [m]
   2.335 +            (loop [ks (keys m) new-map m]
   2.336 +              (let [k (first ks)]
   2.337 +                (cond (nil? ks) new-map
   2.338 +                      (= k :into)
   2.339 +                      (recur
   2.340 +                       (next ks)
   2.341 +                       (assoc new-map
   2.342 +                         :into
   2.343 +                         (poke-names
   2.344 +                          (:into
   2.345 +                           new-map))))
   2.346 +                      (= k :item)
   2.347 +                      (recur
   2.348 +                       (next ks)
   2.349 +                       (assoc new-map
   2.350 +                         :item
   2.351 +                         (item-names
   2.352 +                          (:item new-map))))
   2.353 +                      :else
   2.354 +                      (recur
   2.355 +                       (next ks)
   2.356 +                       new-map)
   2.357 +                      ))))]
   2.358 +
   2.359 +       (into {}
   2.360 +             (map (fn [[pkmn evo-coll]]
   2.361 +                    [pkmn (map use-names evo-coll)])
   2.362 +                  (hxc-evolution rom))))))
   2.363 +
   2.364 +
   2.365 +#+end_src
   2.366 +
   2.367 +
   2.368 +** Level-up moves (learnsets)
   2.369 +#+name: learnsets
   2.370 +#+begin_src clojure
   2.371 +
   2.372 +
   2.373 +(defn hxc-learnsets
   2.374 +  "Hardcoded map associating pokemon names to lists of pairs [lvl
   2.375 +  move] of abilities they learn as they level up. The data
   2.376 +exists at ROM@34000, sorted by internal order. Pointers to the data
   2.377 +  exist at ROM@3B1E5; see also, hxc-ptrs-evolve"
   2.378 +  ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))
   2.379 +  ([rom]
   2.380 +     (apply assoc
   2.381 +            {}
   2.382 +            (interleave
   2.383 +             (hxc-pokenames rom)
   2.384 +             (map (comp
   2.385 +                   (partial map
   2.386 +                            (fn [[lvl mv]] [lvl (dec mv)]))
   2.387 +                   (partial partition 2)
   2.388 +                   ;; keep the learnset data
   2.389 +                   (partial take-while (comp not zero?))
   2.390 +                   ;; skip the evolution data
   2.391 +                   rest
   2.392 +                   (partial drop-while (comp not zero?)))
   2.393 +                  (map #(drop % rom) 
   2.394 +                       (hxc-ptrs-evolve rom)))))))
   2.395 +
   2.396 +(defn hxc-learnsets-pretty
   2.397 +  "Live hxc-learnsets except it reports the name of each move --- as
   2.398 +it appears in rom --- rather than the move index."
   2.399 +  ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))
   2.400 +  ([rom]
   2.401 +     (let [moves (vec(map format-name (hxc-move-names)))]
   2.402 +       (into {}
   2.403 +             (map (fn [[pkmn learnset]]
   2.404 +                    [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])
   2.405 +                               learnset)])
   2.406 +                  (hxc-learnsets rom))))))
   2.407 +             
   2.408 +                                  
   2.409 +
   2.410 +#+end_src
   2.411 +
   2.412 +
   2.413 +
   2.414 +* Pok\eacute{}mon II : the Pok\eacute{}dex
   2.415 +** Species vital stats
   2.416 +#+name: dex-stats
   2.417 +#+begin_src clojure
   2.418 +(defn hxc-pokedex-stats
   2.419 +  "The hardcoded pokedex stats (species height weight) in memory. List
   2.420 +begins at ROM@40687"
   2.421 +  ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))
   2.422 +  ([rom]
   2.423 +     (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom))
   2.424 +           pkmn-count (count pokedex-names)
   2.425 +           ]
   2.426 +     ((fn capture-stats
   2.427 +        [n stats data]
   2.428 +        (if (zero? n) stats
   2.429 +            (let [[species
   2.430 +                   [_
   2.431 +                    height-ft
   2.432 +                    height-in
   2.433 +                    weight-1
   2.434 +                    weight-2
   2.435 +                    _
   2.436 +                    dex-ptr-1
   2.437 +                    dex-ptr-2
   2.438 +                    dex-bank
   2.439 +                    _
   2.440 +                    & data]]
   2.441 +                  (split-with (partial not= 0x50) data)]
   2.442 +              (recur (dec n)
   2.443 +                     (assoc stats
   2.444 +                       (pokedex-names (- pkmn-count (dec n)))
   2.445 +                       {:species
   2.446 +                        (format-name (character-codes->str species))
   2.447 +                        :height-ft
   2.448 +                        height-ft
   2.449 +                        :height-in
   2.450 +                        height-in
   2.451 +                        :weight
   2.452 +                        (/ (low-high weight-1 weight-2) 10.)
   2.453 +                        
   2.454 +                    ;;    :text
   2.455 +                    ;;    (character-codes->str
   2.456 +                    ;;     (take-while
   2.457 +                    ;;      (partial not= 0x50)
   2.458 +                    ;;      (drop
   2.459 +                    ;;       (+ 0xB8000
   2.460 +                    ;;          -0x4000
   2.461 +                    ;;          (low-high dex-ptr-1 dex-ptr-2))
   2.462 +                    ;;       rom)))
   2.463 +                        })
   2.464 +                     
   2.465 +                     data)
   2.466 +              
   2.467 +              
   2.468 +              )))
   2.469 +      
   2.470 +      pkmn-count
   2.471 +      {}
   2.472 +      (drop 0x40687 rom)))       ))
   2.473 +#+end_src
   2.474 +
   2.475 +** Species synopses
   2.476 +
   2.477 +#+name: dex-text
   2.478 +#+begin_src clojure
   2.479 +(def hxc-pokedex-text-raw
   2.480 +  "The hardcoded pokedex entries in memory. List begins at
   2.481 +ROM@B8000, shortly before move names."
   2.482 +  (hxc-thunk-words 0xB8000 14754))
   2.483 +
   2.484 +
   2.485 +
   2.486 +
   2.487 +(defn hxc-pokedex-text
   2.488 +  "The hardcoded pokedex entries in memory, presented as an
   2.489 +associative hash map. List begins at ROM@B8000."
   2.490 +  ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))
   2.491 +  ([rom]
   2.492 +     (zipmap
   2.493 +      (hxc-pokedex-names rom)
   2.494 +      (cons nil ;; for missingno.
   2.495 +            (hxc-pokedex-text-raw rom)))))
   2.496 +#+end_src
   2.497 +
   2.498 +
   2.499 +** Pok\eacute{}mon cries
   2.500 +#+name: pokecry
   2.501 +#+begin_src clojure
   2.502 +(defn hxc-cry
   2.503 +  "The pokemon cry data in internal order. List begins at ROM@39462"
   2.504 +  ([](hxc-cry com.aurellem.gb.gb-driver/original-rom))
   2.505 +  ([rom]
   2.506 +     (zipmap
   2.507 +      (hxc-pokenames rom)
   2.508 +      (map
   2.509 +       (fn [[cry-id pitch length]]
   2.510 +         {:cry-id cry-id
   2.511 +         :pitch pitch
   2.512 +          :length length}
   2.513 +         )
   2.514 +       (partition 3
   2.515 +                  (drop 0x39462 rom))))))
   2.516 +
   2.517 +(defn hxc-cry-groups
   2.518 +  ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom))
   2.519 +  ([rom]
   2.520 +     (map #(mapv first
   2.521 +                (filter
   2.522 +                 (fn [[k v]]
   2.523 +                   (= % (:cry-id v)))
   2.524 +                 (hxc-cry)))
   2.525 +          ((comp
   2.526 +            range
   2.527 +            count
   2.528 +            set
   2.529 +            (partial map :cry-id)
   2.530 +            vals
   2.531 +            hxc-cry)
   2.532 +           rom))))
   2.533 +
   2.534 +
   2.535 +(defn cry-conversion!
   2.536 +  "Convert Porygon's cry in ROM to be the cry of the given pokemon."
   2.537 +  [pkmn]
   2.538 +  (write-rom!
   2.539 +   (rewrite-memory
   2.540 +    (vec(rom))
   2.541 +    0x3965D 
   2.542 +    (map second
   2.543 +         ((hxc-cry) pkmn)))))
   2.544 +
   2.545 +#+end_src
   2.546 +
   2.547 +** COMMENT Names of permanent stats
   2.548 +0DD4D-DD72   
   2.549 +
   2.550 +* Items
   2.551 +** Item names
   2.552 +#+name: item-names
   2.553 +#+begin_src clojure
   2.554 +
   2.555 +(def hxc-items-raw
   2.556 +  "The hardcoded names of the items in memory. List begins at
   2.557 +ROM@045B7"
   2.558 +  (hxc-thunk-words 0x45B7 870))
   2.559 +
   2.560 +(def hxc-items
   2.561 +  "The hardcoded names of the items in memory, presented as
   2.562 +  keywords. List begins at ROM@045B7. See also, hxc-items-raw."
   2.563 +  (comp (partial map format-name) hxc-items-raw))
   2.564 +#+end_src
   2.565 +
   2.566 +** Item prices
   2.567 +#+name: item-prices
   2.568 +#+begin_src clojure
   2.569 +(defn hxc-item-prices
   2.570 +  "The hardcoded list of item prices in memory. List begins at ROM@4495"
   2.571 +  ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))
   2.572 +  ([rom]
   2.573 +     (let [items (hxc-items rom)
   2.574 +           price-size 3]
   2.575 +       (zipmap items
   2.576 +               (map (comp
   2.577 +                     ;; zero-cost items are "priceless"
   2.578 +                     #(if (zero? %) :priceless %)
   2.579 +                     decode-bcd butlast)
   2.580 +                    (partition price-size
   2.581 +                               (take (* price-size (count items))
   2.582 +                                     (drop 0x4495 rom))))))))
   2.583 +#+end_src
   2.584 +** Vendor inventories
   2.585 +
   2.586 +#+name: item-vendors
   2.587 +#+begin_src clojure
   2.588 +(defn hxc-shops
   2.589 +  ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))
   2.590 +  ([rom]
   2.591 +     (let [items (zipmap (range) (hxc-items rom))
   2.592 +
   2.593 +           ;; temporarily softcode the TM items
   2.594 +           items (into
   2.595 +                  items
   2.596 +                  (map (juxt identity
   2.597 +                             (comp keyword
   2.598 +                                   (partial str "tm-")
   2.599 +                                   (partial + 1 -200)
   2.600 +                                   )) 
   2.601 +                       (take 200 (drop 200 (range)))))
   2.602 +                       
   2.603 +           ]
   2.604 +
   2.605 +       ((fn parse-shop [coll [num-items & items-etc]]
   2.606 +          (let [inventory (take-while
   2.607 +                           (partial not= 0xFF)
   2.608 +                           items-etc)
   2.609 +               [separator & items-etc] (drop num-items (rest items-etc))]
   2.610 +           (if (= separator 0x50)
   2.611 +             (map (partial mapv (comp items dec)) (conj coll inventory))
   2.612 +             (recur (conj coll inventory) items-etc)
   2.613 +             )
   2.614 +         ))
   2.615 +
   2.616 +        '()
   2.617 +        (drop 0x233C rom))
   2.618 +
   2.619 +     
   2.620 +     )))
   2.621 +#+end_src
   2.622 +
   2.623 +#+results: item-vendors
   2.624 +: #'com.aurellem.gb.hxc/hxc-shops
   2.625 +
   2.626 +
   2.627 +
   2.628 +* Types
   2.629 +** Names of types
   2.630 +#+name: type-names
   2.631 +#+begin_src clojure
   2.632 +(def hxc-types
   2.633 +  "The hardcoded type names in memory. List begins at ROM@27D99,
   2.634 +  shortly before hxc-titles."
   2.635 +  (hxc-thunk-words 0x27D99 102))
   2.636 +
   2.637 +#+end_src
   2.638 +
   2.639 +** Type effectiveness
   2.640 +#+name type-advantage
   2.641 +#+begin_src clojure
   2.642 +(defn hxc-advantage
   2.643 +  ;; in-game multipliers are stored as 10x their effective value
   2.644 +  ;; to allow for fractional multipliers like 1/2
   2.645 +  
   2.646 +  "The hardcoded type advantages in memory, returned as tuples of
   2.647 +  atk-type def-type multiplier. By default (i.e. if not listed here),
   2.648 +the multiplier is 1. List begins at 0x3E62D."
   2.649 +  ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))
   2.650 +  ([rom]
   2.651 +     (map
   2.652 +      (fn [[atk def mult]] [(get pkmn-types atk (hex atk))
   2.653 +                            (get pkmn-types def (hex def))
   2.654 +                            (/ mult 10)])
   2.655 +      (partition 3
   2.656 +                 (take-while (partial not= 0xFF)
   2.657 +                             (drop 0x3E62D rom))))))
   2.658 +#+end_src
   2.659 +
   2.660 +
   2.661 +
   2.662 +* Moves
   2.663 +** Names of moves
   2.664 +#+name: move-names
   2.665 +#+begin_src clojure
   2.666 +(def hxc-move-names
   2.667 +  "The hardcoded move names in memory. List begins at ROM@BC000"
   2.668 +  (hxc-thunk-words 0xBC000 1551))
   2.669 +#+end_src
   2.670 +   
   2.671 +** Properties of moves 
   2.672 +
   2.673 +#+name: move-data
   2.674 +#+begin_src clojure
   2.675 +(defn hxc-move-data
   2.676 +  "The hardcoded (basic (move effects)) in memory. List begins at
   2.677 +0x38000. Returns a map of {:name :power :accuracy :pp :fx-id
   2.678 +  :fx-txt}. The move descriptions are handwritten, not hardcoded."
   2.679 +  ([]
   2.680 +     (hxc-move-data com.aurellem.gb.gb-driver/original-rom))
   2.681 +  ([rom]
   2.682 +     (let [names (vec (hxc-move-names rom))
   2.683 +           move-count (count names)
   2.684 +           move-size 6
   2.685 +           types pkmn-types ;;; !! hardcoded types
   2.686 +           ]
   2.687 +       (zipmap (map format-name names)
   2.688 +               (map
   2.689 +                (fn [[idx effect power type-id accuracy pp]]
   2.690 +                  {:name (names (dec idx))
   2.691 +                   :power power
   2.692 +                   :accuracy  accuracy
   2.693 +                   :pp pp
   2.694 +                   :type (types type-id)
   2.695 +                   :fx-id effect
   2.696 +                   :fx-txt (get move-effects effect) 
   2.697 +                   }
   2.698 +                  )
   2.699 +                
   2.700 +                (partition move-size
   2.701 +                           (take (* move-size move-count)
   2.702 +                                 (drop 0x38000 rom))))))))
   2.703 +  
   2.704 +
   2.705 +
   2.706 +(defn hxc-move-data*
   2.707 +  "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."
   2.708 +  ([]
   2.709 +     (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))
   2.710 +  ([rom]
   2.711 +     (let [names (vec (hxc-move-names rom))
   2.712 +           move-count (count names)
   2.713 +           move-size 6
   2.714 +           format-name (fn [s]
   2.715 +                         (keyword (.toLowerCase
   2.716 +                                   (apply str
   2.717 +                                          (map #(if (= % \space) "-" %) s)))))
   2.718 +           ]
   2.719 +       (zipmap (map format-name names)
   2.720 +               (map
   2.721 +                (fn [[idx effect power type accuracy pp]]
   2.722 +                  {:name (names (dec idx))
   2.723 +                   :power power
   2.724 +                   :accuracy (hex accuracy)
   2.725 +                   :pp pp
   2.726 +                   :fx-id (hex effect)
   2.727 +                   :fx-txt (get move-effects effect) 
   2.728 +                   }
   2.729 +                  )
   2.730 +                
   2.731 +                (partition move-size
   2.732 +                           (take (* move-size move-count)
   2.733 +                                 (drop 0x38000 rom))))))))
   2.734 +  
   2.735 +#+end_src
   2.736 +
   2.737 +** TM and HM moves
   2.738 +
   2.739 +#+name: machines
   2.740 +#+begin_src clojure
   2.741 +(defn hxc-machines
   2.742 +  "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."
   2.743 +  ([] (hxc-machines
   2.744 +       com.aurellem.gb.gb-driver/original-rom))
   2.745 +  ([rom]
   2.746 +     (let [moves (hxc-move-names rom)]
   2.747 +       (zipmap
   2.748 +        (range)
   2.749 +        (take-while
   2.750 +            (comp not nil?)
   2.751 +            (map (comp
   2.752 +                  format-name
   2.753 +                  (zipmap
   2.754 +                   (range)
   2.755 +                   moves)
   2.756 +              dec)
   2.757 +                 (take 100
   2.758 +                       (drop 0x1232D rom))))))))
   2.759 +
   2.760 +#+end_src
   2.761 +
   2.762 +
   2.763 +
   2.764 +
   2.765 +
   2.766 +** COMMENT Status ailments
   2.767 +
   2.768 +* Places
   2.769 +** Names of places
   2.770 +
   2.771 +#+name: places
   2.772 +#+begin_src clojure
   2.773 +(def hxc-places
   2.774 +  "The hardcoded place names in memory. List begins at
   2.775 +ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."
   2.776 +  (hxc-thunk-words 0x71500 560))
   2.777 +
   2.778 +#+end_src
   2.779 +
   2.780 +** Wild Pok\eacute{}mon demographics
   2.781 +#+name: wilds
   2.782 +#+begin_src clojure
   2.783 +
   2.784 +
   2.785 +
   2.786 +(defn hxc-ptrs-wild
   2.787 +  "A list of the hardcoded wild encounter data in memory. Pointers
   2.788 +  begin at ROM@0CB95; data begins at ROM@0x04D89" 
   2.789 +  ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))
   2.790 +  ([rom]
   2.791 +     (let [ptrs
   2.792 +           (map (fn [[a b]] (+ a (* 0x100 b)))
   2.793 +            (take-while (partial not= (list 0xFF 0xFF))
   2.794 +                            (partition 2 (drop 0xCB95 rom))))]
   2.795 +       ptrs)))
   2.796 +
   2.797 +
   2.798 +
   2.799 +(defn hxc-wilds
   2.800 +  "A list of the hardcoded wild encounter data in memory. Pointers
   2.801 +  begin at ROM@0CB95; data begins at ROM@0x04D89" 
   2.802 +  ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))
   2.803 +  ([rom]
   2.804 +     (let [pokenames (zipmap (range) (hxc-pokenames rom))]
   2.805 +       (map
   2.806 +        (partial map (fn [[a b]] {:species (pokenames (dec b)) :level
   2.807 +                                  a}))
   2.808 +        (partition 10
   2.809 +                     
   2.810 +                      (take-while (comp (partial not= 1)
   2.811 +                                        first) 
   2.812 +                                 (partition 2
   2.813 +                                            (drop 0xCD8C rom))
   2.814 +                   
   2.815 +                   ))))))
   2.816 +
   2.817 +#+end_src
   2.818 +
   2.819 +
   2.820 +
   2.821 +
   2.822 +
   2.823 +* Appendices
   2.824 +
   2.825 +
   2.826 +
   2.827  ** Mapping the ROM
   2.828  
   2.829  | ROM address (hex) | Description     | Format          | Example         |
   2.830 @@ -56,110 +876,6 @@
   2.831  
   2.832  
   2.833  
   2.834 -
   2.835 -** COMMENT Getting linguistic data: names, words, etc.
   2.836 -
   2.837 -Some of the simplest data 
   2.838 -
   2.839 -
   2.840 -One of the simplest data structures in the Pok\eacute{} ROM is an
   2.841 -unbroken list of strings that either (a) all have a specific length,
   2.842 -or (b) are all separated by the same character.
   2.843 -
   2.844 -Because lots of good data has this format, we'll start by writing a
   2.845 -template function to extract it:
   2.846 -
   2.847 -#+name: hxc-thunks
   2.848 -#+begin_src clojure :results silent
   2.849 -(defn hxc-thunk
   2.850 -  "Creates a thunk (nullary fn) that grabs data in a certain region of rom and
   2.851 -splits it into a collection by 0x50. If rom is not supplied, uses the
   2.852 -  original rom data."
   2.853 -  [start length]
   2.854 -  (fn self
   2.855 -    ([rom]
   2.856 -       (take-nth 2
   2.857 -                 (partition-by #(= % 0x50)
   2.858 -                               (take length
   2.859 -                                     (drop start rom)))))
   2.860 -    ([]
   2.861 -      (self com.aurellem.gb.gb-driver/original-rom))))
   2.862 -
   2.863 -(def hxc-thunk-words
   2.864 -  "Same as hxc-thunk, except it interprets the rom data as characters,
   2.865 -  returning a collection of strings."
   2.866 -  (comp
   2.867 -   (partial comp (partial map character-codes->str))
   2.868 -   hxc-thunk))
   2.869 -
   2.870 -#+end_src
   2.871 -
   2.872 -* Pok\eacute{}mon
   2.873 -** Names of each species
   2.874 -The names of the Pok\eacute{}mon species are stored in
   2.875 -ROM@E8000. This name list is interesting, for a number of reasons:
   2.876 -- The names are stored in [[ ][internal order]] rather than in the familiar
   2.877 -  Pok\eacute{}dex order. This seemingly random order probably represents the order in which the authors created or
   2.878 -  programmed in the Pok\eacute{}mon; it's used throughout the game.
   2.879 -- There is enough space allocated for 190 Pok\eacute{}mon. As I
   2.880 -  understand it, there were originally going to be 190 Pok\eacute{}mon
   2.881 -  in Generation I, but the creators decided to defer some to
   2.882 -  Generation II. This explains why many Gen I and Gen II Pok\eacute{}mon
   2.883 -  have the same aesthetic feel.
   2.884 -- The list is pockmarked with random gaps, due to the strange internal
   2.885 -  ordering
   2.886 -  and 39 unused spaces [fn::190 allocated spaces minus 151 true Pok\eacute{}mon]. These missing spaces are filled with the
   2.887 -  placeholder name,  =MISSINGNO.= (\ldquo{}Missing number\rdquo{}).
   2.888 -
   2.889 -Each name is exactly ten letters long (Whenever a name is too short, the extra
   2.890 -space is padded with the character 0x50). 
   2.891 -
   2.892 -
   2.893 -
   2.894 -#+name: pokenames
   2.895 -#+begin_src clojure
   2.896 -
   2.897 -(defn hxc-pokenames-raw
   2.898 -  "The hardcoded names of the 190 species in memory. List begins at
   2.899 -ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters
   2.900 -  long, these names are stripped of padding. See also, hxc-pokedex-names"
   2.901 -  ([]
   2.902 -     (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom))
   2.903 -  ([rom]
   2.904 -     (let [count-species 190
   2.905 -           name-length 10]
   2.906 -       (map character-codes->str
   2.907 -            (partition name-length
   2.908 -                       (map #(if (= 0x50 %) 0x00 %)
   2.909 -                            (take (* count-species name-length)
   2.910 -                                  (drop 0xE8000
   2.911 -                                        rom))))))))
   2.912 -(def hxc-pokenames
   2.913 -  (comp
   2.914 -   (partial map format-name)
   2.915 -   hxc-pokenames-raw))
   2.916 -
   2.917 -
   2.918 -
   2.919 -
   2.920 -(defn hxc-pokedex-names
   2.921 -  "The names of the pokemon in hardcoded pokedex order. List begins at
   2.922 -ROM@410B1. See also, hxc-pokenames."
   2.923 -  ([] (hxc-pokedex-names
   2.924 -       com.aurellem.gb.gb-driver/original-rom))
   2.925 -  ([rom]
   2.926 -     (let [names (hxc-pokenames rom)]
   2.927 -       (#(mapv %
   2.928 -               ((comp range count keys) %))
   2.929 -        (zipmap
   2.930 -         (take (count names)
   2.931 -               (drop 0x410b1 rom))
   2.932 -         
   2.933 -         names)))))
   2.934 -
   2.935 -#+end_src
   2.936 -
   2.937 -* Appendices
   2.938  ** Internal Pok\eacute{}mon IDs
   2.939  ** Type IDs
   2.940  
   2.941 @@ -412,6 +1128,8 @@
   2.942  
   2.943  ** Alphabet code
   2.944  
   2.945 +* Source
   2.946 +
   2.947  #+begin_src clojure :tangle ../clojure/com/aurellem/gb/hxc.clj
   2.948  
   2.949  (ns com.aurellem.gb.hxc
   2.950 @@ -419,9 +1137,6 @@
   2.951                           constants species))
   2.952    (:import [com.aurellem.gb.gb_driver SaveState]))
   2.953  
   2.954 -
   2.955 -
   2.956 -
   2.957  ; ************* HANDWRITTEN CONSTANTS
   2.958  
   2.959  <<type-ids>>
   2.960 @@ -439,62 +1154,16 @@
   2.961  <<hxc-thunks>>
   2.962  ;; --------------------------------------------------
   2.963  
   2.964 -
   2.965  <<pokenames>>
   2.966 +<<type-names>>
   2.967  
   2.968  ;; http://hax.iimarck.us/topic/581/
   2.969 -(defn hxc-cry
   2.970 -  "The pokemon cry data in internal order. List begins at ROM@39462"
   2.971 -  ([](hxc-cry com.aurellem.gb.gb-driver/original-rom))
   2.972 -  ([rom]
   2.973 -     (zipmap
   2.974 -      (hxc-pokenames rom)
   2.975 -      (map
   2.976 -       (fn [[cry-id pitch length]]
   2.977 -         {:cry-id cry-id
   2.978 -         :pitch pitch
   2.979 -          :length length}
   2.980 -         )
   2.981 -       (partition 3
   2.982 -                  (drop 0x39462 rom))))))
   2.983 +<<pokecry>>
   2.984  
   2.985 -(defn hxc-cry-groups
   2.986 -  ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom))
   2.987 -  ([rom]
   2.988 -     (map #(mapv first
   2.989 -                (filter
   2.990 -                 (fn [[k v]]
   2.991 -                   (= % (:cry-id v)))
   2.992 -                 (hxc-cry)))
   2.993 -          ((comp
   2.994 -            range
   2.995 -            count
   2.996 -            set
   2.997 -            (partial map :cry-id)
   2.998 -            vals
   2.999 -            hxc-cry)
  2.1000 -           rom))))
  2.1001  
  2.1002 +<<item-names>>
  2.1003  
  2.1004 -(defn cry-conversion!
  2.1005 -  "Convert Porygon's cry in ROM to be the cry of the given pokemon."
  2.1006 -  [pkmn]
  2.1007 -  (write-rom!
  2.1008 -   (rewrite-memory
  2.1009 -    (vec(rom))
  2.1010 -    0x3965D 
  2.1011 -    (map second
  2.1012 -         ((hxc-cry) pkmn)))))
  2.1013  
  2.1014 -(def hxc-items-raw
  2.1015 -  "The hardcoded names of the items in memory. List begins at
  2.1016 -ROM@045B7"
  2.1017 -  (hxc-thunk-words 0x45B7 870))
  2.1018 -
  2.1019 -(def hxc-types
  2.1020 -  "The hardcoded type names in memory. List begins at ROM@27D99,
  2.1021 -  shortly before hxc-titles."
  2.1022 -  (hxc-thunk-words 0x27D99 102))
  2.1023  
  2.1024  (def hxc-titles
  2.1025    "The hardcoded names of the trainer titles in memory. List begins at
  2.1026 @@ -502,98 +1171,16 @@
  2.1027    (hxc-thunk-words 0x27E77 196))
  2.1028  
  2.1029  
  2.1030 -(def hxc-pokedex-text-raw
  2.1031 -  "The hardcoded pokedex entries in memory. List begins at
  2.1032 -ROM@B8000, shortly before move names."
  2.1033 -  (hxc-thunk-words 0xB8000 14754))
  2.1034 -
  2.1035 -
  2.1036 -
  2.1037 -(def hxc-items
  2.1038 -  "The hardcoded names of the items in memory, presented as
  2.1039 -  keywords. List begins at ROM@045B7. See also, hxc-items-raw."
  2.1040 -  (comp (partial map format-name) hxc-items-raw))
  2.1041 -
  2.1042 -(defn hxc-pokedex-text
  2.1043 -  "The hardcoded pokedex entries in memory, presented as an
  2.1044 -associative hash map. List begins at ROM@B8000."
  2.1045 -  ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))
  2.1046 -  ([rom]
  2.1047 -     (zipmap
  2.1048 -      (hxc-pokedex-names rom)
  2.1049 -      (cons nil ;; for missingno.
  2.1050 -            (hxc-pokedex-text-raw rom)))))
  2.1051 +<<dex-text>>
  2.1052  
  2.1053  ;; In red/blue, pokedex stats are in internal order.
  2.1054  ;; In yellow, pokedex stats are in pokedex order.
  2.1055 +<<dex-stats>>
  2.1056  
  2.1057 -(defn hxc-pokedex-stats
  2.1058 -  "The hardcoded pokedex stats (species height weight) in memory. List
  2.1059 -begins at ROM@40687"
  2.1060 -  ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))
  2.1061 -  ([rom]
  2.1062 -     (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom))
  2.1063 -           pkmn-count (count pokedex-names)
  2.1064 -           ]
  2.1065 -     ((fn capture-stats
  2.1066 -        [n stats data]
  2.1067 -        (if (zero? n) stats
  2.1068 -            (let [[species
  2.1069 -                   [_
  2.1070 -                    height-ft
  2.1071 -                    height-in
  2.1072 -                    weight-1
  2.1073 -                    weight-2
  2.1074 -                    _
  2.1075 -                    dex-ptr-1
  2.1076 -                    dex-ptr-2
  2.1077 -                    dex-bank
  2.1078 -                    _
  2.1079 -                    & data]]
  2.1080 -                  (split-with (partial not= 0x50) data)]
  2.1081 -              (recur (dec n)
  2.1082 -                     (assoc stats
  2.1083 -                       (pokedex-names (- pkmn-count (dec n)))
  2.1084 -                       {:species
  2.1085 -                        (format-name (character-codes->str species))
  2.1086 -                        :height-ft
  2.1087 -                        height-ft
  2.1088 -                        :height-in
  2.1089 -                        height-in
  2.1090 -                        :weight
  2.1091 -                        (/ (low-high weight-1 weight-2) 10.)
  2.1092 -                        
  2.1093 -                    ;;    :text
  2.1094 -                    ;;    (character-codes->str
  2.1095 -                    ;;     (take-while
  2.1096 -                    ;;      (partial not= 0x50)
  2.1097 -                    ;;      (drop
  2.1098 -                    ;;       (+ 0xB8000
  2.1099 -                    ;;          -0x4000
  2.1100 -                    ;;          (low-high dex-ptr-1 dex-ptr-2))
  2.1101 -                    ;;       rom)))
  2.1102 -                        })
  2.1103 -                     
  2.1104 -                     data)
  2.1105 -              
  2.1106 -              
  2.1107 -              )))
  2.1108 -      
  2.1109 -      pkmn-count
  2.1110 -      {}
  2.1111 -      (drop 0x40687 rom)))       ))
  2.1112  
  2.1113  
  2.1114  
  2.1115 -
  2.1116 -
  2.1117 -
  2.1118 -
  2.1119 -(def hxc-places
  2.1120 -  "The hardcoded place names in memory. List begins at
  2.1121 -ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."
  2.1122 -  (hxc-thunk-words 0x71500 560))
  2.1123 -
  2.1124 +<<places>>
  2.1125  
  2.1126  (defn hxc-dialog
  2.1127    "The hardcoded dialogue in memory, including in-game alerts. Dialog
  2.1128 @@ -608,90 +1195,10 @@
  2.1129       (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
  2.1130  
  2.1131  
  2.1132 -(def hxc-move-names
  2.1133 -  "The hardcoded move names in memory. List begins at ROM@BC000"
  2.1134 -  (hxc-thunk-words 0xBC000 1551))
  2.1135 +<<move-names>>
  2.1136 +<<move-data>>
  2.1137  
  2.1138 -
  2.1139 -(defn hxc-move-data
  2.1140 -  "The hardcoded (basic (move effects)) in memory. List begins at
  2.1141 -0x38000. Returns a map of {:name :power :accuracy :pp :fx-id
  2.1142 -  :fx-txt}. The move descriptions are handwritten, not hardcoded."
  2.1143 -  ([]
  2.1144 -     (hxc-move-data com.aurellem.gb.gb-driver/original-rom))
  2.1145 -  ([rom]
  2.1146 -     (let [names (vec (hxc-move-names rom))
  2.1147 -           move-count (count names)
  2.1148 -           move-size 6
  2.1149 -           types pkmn-types ;;; !! hardcoded types
  2.1150 -           ]
  2.1151 -       (zipmap (map format-name names)
  2.1152 -               (map
  2.1153 -                (fn [[idx effect power type-id accuracy pp]]
  2.1154 -                  {:name (names (dec idx))
  2.1155 -                   :power power
  2.1156 -                   :accuracy  accuracy
  2.1157 -                   :pp pp
  2.1158 -                   :type (types type-id)
  2.1159 -                   :fx-id effect
  2.1160 -                   :fx-txt (get move-effects effect) 
  2.1161 -                   }
  2.1162 -                  )
  2.1163 -                
  2.1164 -                (partition move-size
  2.1165 -                           (take (* move-size move-count)
  2.1166 -                                 (drop 0x38000 rom))))))))
  2.1167 -  
  2.1168 -
  2.1169 -
  2.1170 -(defn hxc-move-data*
  2.1171 -  "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."
  2.1172 -  ([]
  2.1173 -     (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))
  2.1174 -  ([rom]
  2.1175 -     (let [names (vec (hxc-move-names rom))
  2.1176 -           move-count (count names)
  2.1177 -           move-size 6
  2.1178 -           format-name (fn [s]
  2.1179 -                         (keyword (.toLowerCase
  2.1180 -                                   (apply str
  2.1181 -                                          (map #(if (= % \space) "-" %) s)))))
  2.1182 -           ]
  2.1183 -       (zipmap (map format-name names)
  2.1184 -               (map
  2.1185 -                (fn [[idx effect power type accuracy pp]]
  2.1186 -                  {:name (names (dec idx))
  2.1187 -                   :power power
  2.1188 -                   :accuracy (hex accuracy)
  2.1189 -                   :pp pp
  2.1190 -                   :fx-id (hex effect)
  2.1191 -                   :fx-txt (get move-effects effect) 
  2.1192 -                   }
  2.1193 -                  )
  2.1194 -                
  2.1195 -                (partition move-size
  2.1196 -                           (take (* move-size move-count)
  2.1197 -                                 (drop 0x38000 rom))))))))
  2.1198 -  
  2.1199 -
  2.1200 -(defn hxc-machines
  2.1201 -  "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."
  2.1202 -  ([] (hxc-machines
  2.1203 -       com.aurellem.gb.gb-driver/original-rom))
  2.1204 -  ([rom]
  2.1205 -     (let [moves (hxc-move-names rom)]
  2.1206 -       (zipmap
  2.1207 -        (range)
  2.1208 -        (take-while
  2.1209 -            (comp not nil?)
  2.1210 -            (map (comp
  2.1211 -                  format-name
  2.1212 -                  (zipmap
  2.1213 -                   (range)
  2.1214 -                   moves)
  2.1215 -              dec)
  2.1216 -                 (take 100
  2.1217 -                       (drop 0x1232D rom))))))))
  2.1218 +<<machines>>
  2.1219  
  2.1220  
  2.1221  
  2.1222 @@ -724,271 +1231,13 @@
  2.1223  
  2.1224  
  2.1225  
  2.1226 +<<type-advantage>>
  2.1227  
  2.1228 -(defn hxc-advantage
  2.1229 -  ;; in-game multipliers are stored as 10x their effective value
  2.1230 -  ;; to allow for fractional multipliers like 1/2
  2.1231 -  
  2.1232 -  "The hardcoded type advantages in memory, returned as tuples of
  2.1233 -  atk-type def-type multiplier. By default (i.e. if not listed here),
  2.1234 -the multiplier is 1. List begins at 0x3E62D."
  2.1235 -  ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))
  2.1236 -  ([rom]
  2.1237 -     (map
  2.1238 -      (fn [[atk def mult]] [(get pkmn-types atk (hex atk))
  2.1239 -                            (get pkmn-types def (hex def))
  2.1240 -                            (/ mult 10)])
  2.1241 -      (partition 3
  2.1242 -                 (take-while (partial not= 0xFF)
  2.1243 -                             (drop 0x3E62D rom))))))
  2.1244  
  2.1245  
  2.1246 -
  2.1247 -(defn format-evo
  2.1248 -  "Parse a sequence of evolution data, returning a map. First is the
  2.1249 -method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the
  2.1250 -  method of evolution is by item (only stones will actually make pokemon
  2.1251 -  evolve, for some auxillary reason.) Finally, the minimum level for
  2.1252 -  evolution to occur (level 1 means no limit, which is used for trade
  2.1253 -  and item evolutions), followed by the internal id of the pokemon
  2.1254 -  into which to evolve. Hence, level up and trade evolutions are
  2.1255 -  described with 3
  2.1256 -  bytes; item evolutions with four."
  2.1257 -  [coll]
  2.1258 -  (let [method (first coll)]
  2.1259 -    (cond (empty? coll) []
  2.1260 -          (= 0 method) [] ;; just in case
  2.1261 -          (= 1 method) ;; level-up evolution
  2.1262 -          (conj (format-evo (drop 3 coll))
  2.1263 -                            {:method :level-up
  2.1264 -                             :min-level (nth coll 1)
  2.1265 -                             :into (dec (nth coll 2))})
  2.1266 -          
  2.1267 -          (= 2 method) ;; item evolution
  2.1268 -          (conj (format-evo (drop 4 coll))
  2.1269 -                {:method :item
  2.1270 -                 :item (dec (nth coll 1))
  2.1271 -                 :min-level (nth coll 2)
  2.1272 -                 :into (dec (nth coll 3))})
  2.1273 -
  2.1274 -          (= 3 method) ;; trade evolution
  2.1275 -          (conj (format-evo (drop 3 coll))
  2.1276 -                {:method :trade
  2.1277 -                 :min-level (nth coll 1) ;; always 1 for trade.
  2.1278 -                 :into (dec (nth coll 2))}))))
  2.1279 -
  2.1280 -
  2.1281 -(defn hxc-ptrs-evolve
  2.1282 -  "A hardcoded collection of 190 pointers to alternating evolution/learnset data,
  2.1283 -in internal order."
  2.1284 -  ([]
  2.1285 -     (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))
  2.1286 -  ([rom]
  2.1287 -     (let [
  2.1288 -           pkmn-count (count (hxc-pokenames-raw)) ;; 190
  2.1289 -           ptrs
  2.1290 -           (map (fn [[a b]] (low-high a b))
  2.1291 -                (partition 2
  2.1292 -                           (take (* 2 pkmn-count)
  2.1293 -                                 (drop 0x3b1e5 rom))))]
  2.1294 -       (map (partial + 0x34000) ptrs)
  2.1295 -
  2.1296 -       )))
  2.1297 -
  2.1298 -
  2.1299 -(defn hxc-learnsets
  2.1300 -  "Hardcoded map associating pokemon names to lists of pairs [lvl
  2.1301 -  move] of abilities they learn as they level up. The data
  2.1302 -exists at ROM@34000, sorted by internal order. Pointers to the data
  2.1303 -  exist at ROM@3B1E5; see also, hxc-ptrs-evolve"
  2.1304 -  ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))
  2.1305 -  ([rom]
  2.1306 -     (apply assoc
  2.1307 -            {}
  2.1308 -            (interleave
  2.1309 -             (hxc-pokenames rom)
  2.1310 -             (map (comp
  2.1311 -                   (partial map
  2.1312 -                            (fn [[lvl mv]] [lvl (dec mv)]))
  2.1313 -                   (partial partition 2)
  2.1314 -                   ;; keep the learnset data
  2.1315 -                   (partial take-while (comp not zero?))
  2.1316 -                   ;; skip the evolution data
  2.1317 -                   rest
  2.1318 -                   (partial drop-while (comp not zero?)))
  2.1319 -                  (map #(drop % rom) 
  2.1320 -                       (hxc-ptrs-evolve rom)))))))
  2.1321 -
  2.1322 -(defn hxc-learnsets-pretty
  2.1323 -  "Live hxc-learnsets except it reports the name of each move --- as
  2.1324 -it appears in rom --- rather than the move index."
  2.1325 -  ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))
  2.1326 -  ([rom]
  2.1327 -     (let [moves (vec(map format-name (hxc-move-names)))]
  2.1328 -       (into {}
  2.1329 -             (map (fn [[pkmn learnset]]
  2.1330 -                    [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])
  2.1331 -                               learnset)])
  2.1332 -                  (hxc-learnsets rom))))))
  2.1333 -             
  2.1334 -                                  
  2.1335 -
  2.1336 -
  2.1337 -(defn hxc-evolution
  2.1338 -  "Hardcoded evolution data in memory. The data exists at ROM@34000,
  2.1339 -  sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."
  2.1340 -  ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
  2.1341 -  ([rom]
  2.1342 -       (apply assoc {}
  2.1343 -               (interleave
  2.1344 -                (hxc-pokenames rom)
  2.1345 -                (map
  2.1346 -                 (comp
  2.1347 -                  format-evo
  2.1348 -                  (partial take-while (comp not zero?))
  2.1349 -                  #(drop % rom))
  2.1350 -                 (hxc-ptrs-evolve rom)
  2.1351 -                 )))))
  2.1352 -
  2.1353 -(defn hxc-evolution-pretty
  2.1354 -  "Like hxc-evolution, except it uses the names of items and pokemon
  2.1355 ---- grabbed from ROM --- rather than their numerical identifiers."
  2.1356 -  ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))
  2.1357 -  ([rom]
  2.1358 -     (let
  2.1359 -         [poke-names (vec (hxc-pokenames rom))
  2.1360 -          item-names (vec (hxc-items rom))
  2.1361 -          use-names
  2.1362 -          (fn [m]
  2.1363 -            (loop [ks (keys m) new-map m]
  2.1364 -              (let [k (first ks)]
  2.1365 -                (cond (nil? ks) new-map
  2.1366 -                      (= k :into)
  2.1367 -                      (recur
  2.1368 -                       (next ks)
  2.1369 -                       (assoc new-map
  2.1370 -                         :into
  2.1371 -                         (poke-names
  2.1372 -                          (:into
  2.1373 -                           new-map))))
  2.1374 -                      (= k :item)
  2.1375 -                      (recur
  2.1376 -                       (next ks)
  2.1377 -                       (assoc new-map
  2.1378 -                         :item
  2.1379 -                         (item-names
  2.1380 -                          (:item new-map))))
  2.1381 -                      :else
  2.1382 -                      (recur
  2.1383 -                       (next ks)
  2.1384 -                       new-map)
  2.1385 -                      ))))]
  2.1386 -
  2.1387 -       (into {}
  2.1388 -             (map (fn [[pkmn evo-coll]]
  2.1389 -                    [pkmn (map use-names evo-coll)])
  2.1390 -                  (hxc-evolution rom))))))
  2.1391 -
  2.1392 -
  2.1393 -(defn hxc-pokemon-base
  2.1394 -  ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))
  2.1395 -  ([rom]
  2.1396 -     (let [entry-size 28
  2.1397 -           pkmn-count (count (hxc-pokedex-text rom))
  2.1398 -           pokemon (rest (hxc-pokedex-names))
  2.1399 -           types (apply assoc {}
  2.1400 -                        (interleave
  2.1401 -                         (range)
  2.1402 -                         pkmn-types)) ;;!! softcoded
  2.1403 -           moves (apply assoc {}
  2.1404 -                        (interleave
  2.1405 -                         (range)
  2.1406 -                         (map format-name
  2.1407 -                              (hxc-move-names rom))))
  2.1408 -           machines (hxc-machines)
  2.1409 -           ]
  2.1410 -       (zipmap
  2.1411 -        pokemon
  2.1412 -        (map
  2.1413 -         (fn [[n
  2.1414 -               rating-hp
  2.1415 -               rating-atk
  2.1416 -               rating-def
  2.1417 -               rating-speed
  2.1418 -               rating-special
  2.1419 -               type-1
  2.1420 -               type-2
  2.1421 -               rarity
  2.1422 -               rating-xp
  2.1423 -               pic-dimensions ;; tile_width|tile_height (8px/tile)
  2.1424 -               ptr-pic-obverse-1
  2.1425 -               ptr-pic-obverse-2
  2.1426 -               ptr-pic-reverse-1
  2.1427 -               ptr-pic-reverse-2
  2.1428 -               move-1
  2.1429 -               move-2
  2.1430 -               move-3
  2.1431 -               move-4
  2.1432 -               growth-rate
  2.1433 -               &
  2.1434 -               TMs|HMs]]
  2.1435 -           (let
  2.1436 -               [base-moves
  2.1437 -                (mapv moves
  2.1438 -                      ((comp
  2.1439 -                        ;; since the game uses zero as a delimiter,
  2.1440 -                        ;; it must also increment all move indices by 1.
  2.1441 -                        ;; heren we decrement to correct this.
  2.1442 -                        (partial map dec)
  2.1443 -                        (partial take-while (comp not zero?)))
  2.1444 -                       [move-1 move-2 move-3 move-4]))
  2.1445 -                
  2.1446 -                types
  2.1447 -                (set (list (types type-1)
  2.1448 -                           (types type-2)))
  2.1449 -                TMs|HMs
  2.1450 -                (map
  2.1451 -                 (comp
  2.1452 -                  (partial map first)
  2.1453 -                  (partial remove (comp zero? second)))
  2.1454 -                 (split-at
  2.1455 -                  50
  2.1456 -                  (map vector
  2.1457 -                       (rest(range))
  2.1458 -                       (reduce concat
  2.1459 -                               (map
  2.1460 -                                #(take 8
  2.1461 -                                       (concat (bit-list %)
  2.1462 -                                               (repeat 0)))
  2.1463 -                                
  2.1464 -                                TMs|HMs)))))
  2.1465 -                
  2.1466 -                TMs  (vec (first TMs|HMs))
  2.1467 -                HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))
  2.1468 -                
  2.1469 -                
  2.1470 -                ]
  2.1471 -             
  2.1472 -             
  2.1473 -             {:dex# n
  2.1474 -              :base-moves base-moves
  2.1475 -              :types types
  2.1476 -              :TMs TMs
  2.1477 -              :HMs HMs
  2.1478 -              :base-hp rating-hp
  2.1479 -              :base-atk rating-atk
  2.1480 -              :base-def rating-def
  2.1481 -              :base-speed rating-speed
  2.1482 -              :base-special rating-special
  2.1483 -              :o0 pic-dimensions
  2.1484 -              :o1 ptr-pic-obverse-1
  2.1485 -              :o2 ptr-pic-obverse-2
  2.1486 -              }))
  2.1487 -         
  2.1488 -         (partition entry-size
  2.1489 -                    (take (* entry-size pkmn-count)
  2.1490 -                          (drop 0x383DE
  2.1491 -                                rom))))))))
  2.1492 +<<evolution-header>>
  2.1493 +<<learnsets>>
  2.1494 +<<pokebase>>
  2.1495    
  2.1496    
  2.1497  (defn hxc-intro-pkmn
  2.1498 @@ -1012,101 +1261,11 @@
  2.1499                     pokemon))])))
  2.1500    
  2.1501  
  2.1502 -(defn hxc-item-prices
  2.1503 -  "The hardcoded list of item prices in memory. List begins at ROM@4495"
  2.1504 -  ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))
  2.1505 -  ([rom]
  2.1506 -     (let [items (hxc-items rom)
  2.1507 -           price-size 3]
  2.1508 -       (zipmap items
  2.1509 -               (map (comp
  2.1510 -                     ;; zero-cost items are "priceless"
  2.1511 -                     #(if (zero? %) :priceless %)
  2.1512 -                     decode-bcd butlast)
  2.1513 -                    (partition price-size
  2.1514 -                               (take (* price-size (count items))
  2.1515 -                                     (drop 0x4495 rom))))))))
  2.1516 +<<item-prices>>
  2.1517  
  2.1518 -(defn hxc-shops
  2.1519 -  ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))
  2.1520 -  ([rom]
  2.1521 -     (let [items (zipmap (range) (hxc-items rom))
  2.1522 +<<item-vendors>>
  2.1523  
  2.1524 -           ;; temporarily softcode the TM items
  2.1525 -           items (into
  2.1526 -                  items
  2.1527 -                  (map (juxt identity
  2.1528 -                             (comp keyword
  2.1529 -                                   (partial str "tm-")
  2.1530 -                                   (partial + 1 -200)
  2.1531 -                                   )) 
  2.1532 -                       (take 200 (drop 200 (range)))))
  2.1533 -                       
  2.1534 -           ]
  2.1535 -
  2.1536 -       ((fn parse-shop [coll [num-items & items-etc]]
  2.1537 -          (let [inventory (take-while
  2.1538 -                           (partial not= 0xFF)
  2.1539 -                           items-etc)
  2.1540 -               [separator & items-etc] (drop num-items (rest items-etc))]
  2.1541 -           (if (= separator 0x50)
  2.1542 -             (map (partial mapv (comp items dec)) (conj coll inventory))
  2.1543 -             (recur (conj coll inventory) items-etc)
  2.1544 -             )
  2.1545 -         ))
  2.1546 -
  2.1547 -        '()
  2.1548 -        (drop 0x233C rom))
  2.1549 -
  2.1550 -     
  2.1551 -     )))
  2.1552 -
  2.1553 -
  2.1554 -
  2.1555 -
  2.1556 -
  2.1557 -(defn hxc-ptrs-wild
  2.1558 -  "A list of the hardcoded wild encounter data in memory. Pointers
  2.1559 -  begin at ROM@0CB95; data begins at ROM@0x04D89" 
  2.1560 -  ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))
  2.1561 -  ([rom]
  2.1562 -     (let [ptrs
  2.1563 -           (map (fn [[a b]] (+ a (* 0x100 b)))
  2.1564 -            (take-while (partial not= (list 0xFF 0xFF))
  2.1565 -                            (partition 2 (drop 0xCB95 rom))))]
  2.1566 -       ptrs)))
  2.1567 -
  2.1568 -
  2.1569 -
  2.1570 -(defn hxc-wilds
  2.1571 -  "A list of the hardcoded wild encounter data in memory. Pointers
  2.1572 -  begin at ROM@0CB95; data begins at ROM@0x04D89" 
  2.1573 -  ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))
  2.1574 -  ([rom]
  2.1575 -     (let [pokenames (zipmap (range) (hxc-pokenames rom))]
  2.1576 -       (map
  2.1577 -        (partial map (fn [[a b]] {:species (pokenames (dec b)) :level
  2.1578 -                                  a}))
  2.1579 -        (partition 10
  2.1580 -                     
  2.1581 -                      (take-while (comp (partial not= 1)
  2.1582 -                                        first) 
  2.1583 -                                 (partition 2
  2.1584 -                                            (drop 0xCD8C rom))
  2.1585 -                   
  2.1586 -                   ))))))
  2.1587 -
  2.1588 -
  2.1589 -
  2.1590 -
  2.1591 -
  2.1592 -
  2.1593 -
  2.1594 -
  2.1595 -
  2.1596 -
  2.1597 -
  2.1598 -
  2.1599 +<<wilds>>
  2.1600  
  2.1601  
  2.1602  ;; ********************** MANIPULATION FNS
  2.1603 @@ -1202,3 +1361,6 @@
  2.1604  
  2.1605  #+end_src
  2.1606  
  2.1607 +#+results:
  2.1608 +: nil
  2.1609 +