annotate clojure/com/aurellem/gb/species.clj @ 215:aba78e52faba

merge
author Robert McIntyre <rlm@mit.edu>
date Fri, 23 Mar 2012 19:26:04 -0500
parents 62969eb07e04 57258c269bcb
children ca9d2897435b
rev   line source
rlm@165 1 (ns com.aurellem.gb.species
ocsenave@213 2 (:use (com.aurellem.gb assembly characters gb-driver util
ocsenave@213 3 constants))
ocsenave@213 4 (:use (com.aurellem.world practice))
rlm@165 5 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@165 6
ocsenave@207 7
ocsenave@207 8 (def hxc-pokenames
ocsenave@207 9 "The hardcoded names of the 190 species in memory. List begins at ROM@E8000."
ocsenave@207 10 (let [count-species 190
ocsenave@207 11 name-length 10]
ocsenave@207 12 (map character-codes->str
ocsenave@207 13 (partition name-length
ocsenave@207 14 (take (* count-species name-length)
ocsenave@207 15 (drop 0xE8000
ocsenave@213 16 (rom(root))))))))
rlm@212 17
ocsenave@207 18 (def hxc-items
ocsenave@207 19 "The hardcoded names of the items in memory. List begins at ROM@45B7 "
ocsenave@207 20 (map character-codes->str
ocsenave@207 21 (take-nth 2
ocsenave@207 22 (partition-by #(= % 0x50)
ocsenave@207 23 (take 1200
ocsenave@207 24 (drop 0x45B7 (rom (root))))))))
ocsenave@207 25 (def hxc-titles
ocsenave@207 26 "The hardcoded names of the trainer titles in memory. List begins at
ocsenave@207 27 ROM@27E77"
ocsenave@207 28 (map character-codes->str
ocsenave@207 29 (take-nth 2
ocsenave@207 30 (partition-by #(= 0x50 %)
ocsenave@207 31 (take 196
ocsenave@207 32 (drop 0x27E77
ocsenave@207 33 (rom (root))))))))
ocsenave@207 34
ocsenave@207 35
ocsenave@207 36 (def hxc-pokedex
ocsenave@207 37 "The hardcoded pokedex entries in memory. List begins at
ocsenave@207 38 ROM@B8000, shortly before move names."
ocsenave@207 39 (map character-codes->str
ocsenave@207 40 (take-nth 2
ocsenave@207 41 (partition-by #(= % 0x50)
ocsenave@207 42 (take 14754
ocsenave@207 43 (drop 0xB8000
ocsenave@207 44 (rom (root))))))))
ocsenave@207 45 (def hxc-moves
ocsenave@207 46 "The hardcoded move names in memory. List begins at ROM@BC000"
ocsenave@207 47 (map character-codes->str
ocsenave@207 48 (take-nth 2
ocsenave@207 49 (partition-by #(= % 0x50)
ocsenave@207 50 (take 1551
ocsenave@207 51 (drop 0xBC000
ocsenave@207 52 (rom (root))))))))
ocsenave@207 53
ocsenave@207 54
ocsenave@207 55
ocsenave@207 56 (def hxc-places
ocsenave@207 57 "The hardcoded place names in memory. List begins at
ocsenave@207 58 ROM@71500. Cinnabar Mansion is dynamically calculated."
ocsenave@207 59 (map character-codes->str
ocsenave@207 60 (take-nth 2
ocsenave@207 61 (partition-by #(= % 0x50)
ocsenave@207 62 (take 560
ocsenave@207 63 (drop 0x71500
ocsenave@207 64 (rom (root))))))))
ocsenave@207 65
ocsenave@213 66
ocsenave@213 67 (def hxc-dialog
ocsenave@213 68 "The hardcoded dialogue in memory, including in-game alerts. List begins at ROM@98000."
ocsenave@213 69 (character-codes->str(take 0x0F728
ocsenave@213 70 (drop (+ 0x98000)
ocsenave@213 71 (rom (root)))))
ocsenave@213 72
ocsenave@207 73 (def hxc-later
ocsenave@207 74 "Running this code produces, e.g. hardcoded names NPCs give
ocsenave@213 75 their pokemon. Will sort through it later."
ocsenave@207 76 (print (character-codes->str(take 10000
ocsenave@207 77 (drop 0x71597
ocsenave@207 78 (rom (root)))))))
ocsenave@207 79
ocsenave@207 80
ocsenave@207 81
ocsenave@207 82
ocsenave@213 83
ocsenave@213 84
ocsenave@213 85
ocsenave@207 86 (let [dex
ocsenave@207 87 (partition-by #(= 0x50 %)
ocsenave@207 88 (take 2540
ocsenave@207 89 (drop 0x40687
ocsenave@207 90 (rom (root)))))]
ocsenave@207 91 (def dex dex)
ocsenave@207 92 (def hxc-species
ocsenave@207 93 (map character-codes->str
ocsenave@207 94 (take-nth 4 dex))))
ocsenave@207 95
ocsenave@207 96
ocsenave@207 97
rlm@165 98 (def species-code->species-name
rlm@165 99 {0x01 :rhydon
rlm@165 100 0x02 :kangaskhan
rlm@165 101 0x03 :nidoran-male
rlm@165 102 0x04 :clefairy
rlm@165 103 0x05 :spearow
rlm@165 104 0x06 :voltorb
rlm@165 105 0x07 :nidoking
rlm@165 106 0x08 :slowbro
rlm@165 107 0x09 :ivysaur
rlm@165 108 0x0A :exeggutor
rlm@165 109 0x0B :lickitung
rlm@165 110 0x0C :exeggcute
rlm@165 111 0x0D :grimer
rlm@165 112 0x0E :gengar
rlm@165 113 0x0F :nidoran-female
rlm@165 114 0x10 :nidoqueen
rlm@165 115 0x11 :cubone
rlm@165 116 0x12 :rhyhorn
rlm@165 117 0x13 :lapras
rlm@165 118 0x14 :arcanine
rlm@165 119 0x15 :mew
rlm@165 120 0x16 :gyarados
rlm@165 121 0x17 :shellder
rlm@165 122 0x18 :tentacool
rlm@165 123 0x19 :gastly
rlm@165 124 0x1A :scyther
rlm@165 125 0x1B :staryu
rlm@165 126 0x1C :blastoise
rlm@165 127 0x1D :pinsir
rlm@165 128 0x1E :tangela
rlm@165 129 0x21 :growlithe
rlm@165 130 0x22 :onix
rlm@165 131 0x23 :fearow
rlm@165 132 0x24 :pidgey
rlm@165 133 0x25 :slowpoke
rlm@165 134 0x26 :kadabra
rlm@165 135 0x27 :graveler
rlm@165 136 0x28 :chansey
rlm@165 137 0x29 :machoke
rlm@165 138 0x2A :mr-mime
rlm@165 139 0x2B :hitmonlee
rlm@165 140 0x2C :hitmonchan
rlm@165 141 0x2D :arbok
rlm@165 142 0x2E :parasect
rlm@165 143 0x2F :psyduck
rlm@165 144 0x30 :drowzee
rlm@165 145 0x31 :golem
rlm@165 146 0x33 :magmar
rlm@165 147 0x35 :electabuzz
rlm@165 148 0x36 :magneton
rlm@165 149 0x37 :koffing
rlm@165 150 0x39 :mankey
rlm@165 151 0x3A :seel
rlm@165 152 0x3B :diglett
rlm@165 153 0x3C :tauros
rlm@214 154 0x40 :farfetch
rlm@165 155 0x41 :venonat
rlm@165 156 0x42 :dragonite
rlm@165 157 0x46 :doduo
rlm@165 158 0x47 :poliwag
rlm@165 159 0x48 :jynx
rlm@165 160 0x49 :moltres
rlm@165 161 0x4A :articuno
rlm@165 162 0x4B :zapdos
rlm@165 163 0x4C :ditto
rlm@165 164 0x4D :meowth
rlm@165 165 0x4E :krabby
rlm@165 166 0x52 :vulpix
rlm@165 167 0x53 :ninetails
rlm@165 168 0x54 :pikachu
ocsenave@213 169 0x55 :riachu
rlm@165 170 0x58 :dratini
rlm@165 171 0x59 :dragonair
rlm@165 172 0x5A :kabuto
rlm@165 173 0x5B :kabutops
rlm@165 174 0x5C :horsea
rlm@165 175 0x5D :sedra
rlm@165 176 0x60 :sandshrew
rlm@165 177 0x61 :sandslash
rlm@165 178 0x62 :omanyte
rlm@165 179 0x63 :omastar
rlm@165 180 0x64 :jigglypuff
rlm@165 181 0x65 :wigglytuff
rlm@165 182 0x66 :eevee
rlm@165 183 0x67 :flareon
rlm@165 184 0x68 :jolteon
rlm@165 185 0x69 :vaporeon
rlm@165 186 0x6A :machop
rlm@165 187 0x6B :zubat
rlm@165 188 0x6C :ekans
rlm@165 189 0x6D :paras
rlm@165 190 0x6E :poliwhirl
rlm@165 191 0x6F :poliwrath
rlm@165 192 0x70 :weedle
rlm@165 193 0x71 :kakuna
rlm@165 194 0x72 :beedrill
rlm@165 195 0x74 :dodrio
rlm@165 196 0x75 :primeape
rlm@165 197 0x76 :dugtrio
rlm@165 198 0x77 :venomoth
rlm@165 199 0x78 :dewgong
rlm@165 200 0x7B :caterpie
rlm@165 201 0x7C :metapod
rlm@165 202 0x7D :butterfree
rlm@165 203 0x7E :machamp
rlm@165 204 0x80 :golduck
rlm@165 205 0x81 :hypno
rlm@165 206 0x82 :golbat
rlm@165 207 0x83 :mewtwo
rlm@165 208 0x84 :snorlax
rlm@165 209 0x85 :magikarp
rlm@165 210 0x88 :muk
rlm@165 211 0x8A :kingler
rlm@165 212 0x8B :cloyster
rlm@165 213 0x8D :electrode
rlm@165 214 0x8E :clefable
rlm@165 215 0x8F :wheezing
rlm@165 216 0x90 :persian
rlm@165 217 0x91 :marowak
rlm@165 218 0x93 :haunter
rlm@165 219 0x94 :abra
rlm@165 220 0x95 :alakazam
rlm@165 221 0x96 :pidgeotto
rlm@165 222 0x97 :pidgeot
rlm@165 223 0x98 :starmie
rlm@165 224 0x99 :bulbasaur
rlm@165 225 0x9A :venusaur
rlm@165 226 0x9B :tentacruel
rlm@165 227 0x9D :goldeen
rlm@165 228 0x9E :seaking
rlm@165 229 0xA3 :ponyta
rlm@165 230 0xA4 :rapidash
rlm@165 231 0xA5 :rattata
rlm@165 232 0xA6 :raticate
rlm@165 233 0xA7 :nidorino
rlm@165 234 0xA8 :nidorina
rlm@165 235 0xA9 :geodude
rlm@165 236 0xAA :porygon
rlm@165 237 0xAB :aerodactyl
rlm@165 238 0xAD :magnemite
rlm@165 239 0xB0 :charmander
rlm@165 240 0xB1 :squirtle
rlm@165 241 0xB2 :charmeleon
rlm@165 242 0xB3 :wartortle
rlm@165 243 0xB4 :charizard
rlm@165 244 0xB9 :oddish
rlm@165 245 0xBA :gloom
rlm@165 246 0xBB :vileplume
rlm@165 247 0xBC :bellsprout
rlm@165 248 0xBD :weepenbell
rlm@165 249 0xBE :victreebel})
rlm@165 250
rlm@165 251 (def species-ID-1 0xD163)
rlm@165 252
rlm@165 253 (def species-name->species-code
rlm@165 254 (zipmap (vals species-code->species-name)
rlm@165 255 (keys species-code->species-name)))
rlm@165 256
rlm@190 257 (defn pokemon-species-data-address [poke-num]
rlm@190 258 (+ species-ID-1 poke-num))
rlm@190 259
rlm@190 260 (defn read-species
rlm@190 261 ([^SaveState state poke-num]
rlm@190 262 (assert (<= 0 poke-num 5))
rlm@190 263 (species-code->species-name
rlm@190 264 (aget (memory state)
rlm@190 265 (pokemon-species-data-address poke-num))))
rlm@190 266 ([poke-num]
rlm@190 267 (read-species @current-state poke-num)))
rlm@190 268
rlm@165 269 (defn set-species
rlm@190 270 ([^SaveState state poke-num species-name]
rlm@190 271 (assert (<= 0 poke-num 5))
rlm@165 272 (let [species-code (species-name->species-code
rlm@165 273 species-name
rlm@165 274 species-name)]
rlm@165 275
rlm@190 276 (set-memory state (pokemon-species-data-address poke-num)
rlm@165 277 species-code)))
rlm@190 278 ([poke-num species-name]
rlm@190 279 (set-species @current-state poke-num species-name)))
rlm@166 280
rlm@166 281
rlm@191 282 (def pokemon-1-species2-address 0xD16A)
rlm@191 283
rlm@191 284 (defn pokemon-species2-address [poke-num]
rlm@191 285 (+ pokemon-1-species2-address
rlm@191 286 (* pokemon-record-width poke-num)))
rlm@191 287
rlm@191 288 (defn read-species2
rlm@191 289 ([^SaveState state poke-num]
rlm@191 290 (species-code->species-name
rlm@191 291 (aget (memory state)
rlm@191 292 (pokemon-species2-address poke-num))))
rlm@191 293 ([poke-num]
rlm@191 294 (read-species2 @current-state poke-num)))
rlm@191 295
rlm@191 296 (defn set-species2
rlm@191 297 ([^SaveState state poke-num new-species]
rlm@191 298 (let [species-code (species-name->species-code
rlm@191 299 new-species
rlm@191 300 new-species)]
rlm@191 301
rlm@191 302 (set-memory state (pokemon-species2-address poke-num)
rlm@191 303 species-code)))
rlm@191 304 ([poke-num new-species]
rlm@191 305 (set-species2 @current-state poke-num new-species)))
rlm@191 306
ocsenave@213 307