annotate clojure/com/aurellem/gb/types.clj @ 458:abcf1c8bb74c

going to work on another song.
author Robert McIntyre <rlm@mit.edu>
date Fri, 04 May 2012 02:26:28 -0500
parents c31cb3043087
children
rev   line source
rlm@180 1 (ns com.aurellem.gb.types
rlm@180 2 (:use (com.aurellem.gb gb-driver util constants))
rlm@180 3 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@180 4
rlm@180 5 (def type-code->type-name
rlm@180 6 {0x00 :normal
rlm@180 7 0x01 :fighting
rlm@180 8 0x02 :flying
ocsenave@292 9 0x03 :poison
rlm@180 10 0x04 :ground
rlm@180 11 0x05 :rock
rlm@180 12 0x07 :bug
rlm@180 13 0x08 :ghost
rlm@180 14 0x14 :fire
rlm@180 15 0x15 :water
rlm@180 16 0x16 :grass
rlm@180 17 0x17 :electric
rlm@180 18 0x18 :psychic
rlm@180 19 0x19 :ice
rlm@204 20 0x1A :dragon })
rlm@180 21
rlm@180 22 (def type-name->type-code
rlm@180 23 (zipmap (vals type-code->type-name)
rlm@180 24 (keys type-code->type-name)))
rlm@180 25
rlm@190 26 (def pokemon-1-type-start-address 0xD16F)
rlm@180 27
rlm@180 28 (defn pokemon-type-start-address [poke-num]
rlm@190 29 (+ pokemon-1-type-start-address
rlm@180 30 (* pokemon-record-width poke-num)))
rlm@180 31
rlm@180 32 (defn give-type
rlm@180 33 ([^SaveState state poke-num types]
rlm@180 34 (assert (<= 0 poke-num 5))
rlm@180 35 (let [types*
rlm@180 36 (if (= (count types) 1)
rlm@180 37 [(first types) (first types)]
rlm@180 38 types)]
rlm@180 39 (set-memory-range
rlm@180 40 state
rlm@180 41 (pokemon-type-start-address poke-num)
rlm@206 42 (map type-name->type-code types*))))
rlm@180 43 ([poke-num types]
rlm@180 44 (give-type @current-state poke-num types)))
rlm@180 45
rlm@190 46 (defn read-type
rlm@180 47 ([^SaveState state poke-num]
rlm@180 48 (assert (<= 0 poke-num 5))
rlm@180 49 (let [types-start (pokemon-type-start-address poke-num)
rlm@180 50 [type-1 type-2]
rlm@180 51 (subvec (vec (memory state))
rlm@180 52 types-start (+ 2 types-start))]
rlm@180 53 (if (= type-1 type-2)
rlm@180 54 [(type-code->type-name type-1)]
rlm@180 55 (mapv type-code->type-name [type-1 type-2]))))
rlm@180 56 ([poke-num]
rlm@190 57 (read-type @current-state poke-num)))
rlm@203 58
rlm@205 59 (def pokemon->type
rlm@205 60 {:abra [:psychic]
rlm@205 61 :aerodactyl [:rock :flying]
rlm@205 62 :alakazam [:psychic]
rlm@205 63 :arbok [:poison]
rlm@205 64 :arcanine [:fire]
rlm@205 65 :articuno [:ice :flying]
rlm@205 66 :beedrill [:bug :poison]
rlm@205 67 :bellsprout [:grass :poison]
rlm@205 68 :blastoise [:water]
rlm@205 69 :bulbasaur [:grass :poison]
rlm@205 70 :butterfree [:bug :flying]
rlm@205 71 :caterpie [:bug]
rlm@205 72 :chansey [:normal]
rlm@205 73 :charizard [:fire :flying]
rlm@205 74 :charmander [:fire]
rlm@205 75 :charmeleon [:fire]
rlm@205 76 :clefable [:normal]
rlm@205 77 :clefairy [:normal]
rlm@205 78 :cloyster [:water :ice]
rlm@205 79 :cubone [:ground]
rlm@205 80 :dewgong [:water :ice]
rlm@205 81 :diglett [:ground]
rlm@205 82 :ditto [:normal]
rlm@205 83 :dodrio [:normal :flying]
rlm@205 84 :doduo [:normal :flying]
rlm@205 85 :dragonair [:dragon]
rlm@205 86 :dragonite [:dragon :flying]
rlm@205 87 :dratini [:dragon]
rlm@205 88 :drowzee [:psychic]
rlm@205 89 :dugtrio [:ground]
rlm@205 90 :eevee [:normal]
rlm@205 91 :ekans [:poison]
rlm@205 92 :electabuzz [:electric]
rlm@205 93 :electrode [:electric]
rlm@205 94 :exeggcute [:grass :psychic]
rlm@205 95 :exeggutor [:grass :psychic]
rlm@205 96 :farfetchd [:normal :flying]
rlm@205 97 :fearow [:normal :flying]
rlm@205 98 :flareon [:fire]
rlm@205 99 :gastly [:ghost :poison]
rlm@205 100 :gengar [:ghost :poison]
rlm@205 101 :geodude [:rock :ground]
rlm@205 102 :gloom [:grass :poison]
rlm@205 103 :golbat [:poison :flying]
rlm@205 104 :goldeen [:water]
rlm@205 105 :golduck [:water]
rlm@205 106 :golem [:rock :ground]
rlm@205 107 :graveler [:rock :ground]
rlm@205 108 :grimer [:poison]
rlm@205 109 :growlithe [:fire]
rlm@205 110 :gyarados [:water :flying]
rlm@205 111 :haunter [:ghost :poison]
rlm@205 112 :hitmonchan [:fighting]
rlm@205 113 :hitmonlee [:fighting]
rlm@205 114 :horsea [:water]
rlm@205 115 :hypno [:psychic]
rlm@205 116 :ivysaur [:grass :poison]
rlm@205 117 :jigglypuff [:normal]
rlm@205 118 :jolteon [:electric]
rlm@205 119 :jynx [:ice :psychic]
rlm@205 120 :kabuto [:rock :water]
rlm@205 121 :kabutops [:rock :water]
rlm@205 122 :kadabra [:psychic]
rlm@205 123 :kakuna [:bug :poison]
rlm@205 124 :kangaskhan [:normal]
rlm@205 125 :kingler [:water]
rlm@205 126 :koffing [:poison]
rlm@205 127 :krabby [:water]
rlm@205 128 :lapras [:water :ice]
rlm@205 129 :lickitung [:normal]
rlm@205 130 :machamp [:fighting]
rlm@205 131 :machoke [:fighting]
rlm@205 132 :machop [:fighting]
rlm@205 133 :magikarp [:water]
rlm@205 134 :magmar [:fire]
rlm@205 135 :magnemite [:electric]
rlm@205 136 :magneton [:electric]
rlm@205 137 :mankey [:fighting]
rlm@205 138 :marowak [:ground]
rlm@205 139 :meowth [:normal]
rlm@205 140 :metapod [:bug]
rlm@205 141 :mew [:psychic]
rlm@205 142 :mewtwo [:psychic]
rlm@205 143 :moltres [:fire :flying]
rlm@205 144 :mr-mime [:psychic]
rlm@205 145 :muk [:poison]
rlm@205 146 :nidoking [:poison :ground]
rlm@205 147 :nidoqueen [:poison :ground]
rlm@205 148 :nidoran-female [:poison]
rlm@205 149 :nidoran-male [:poison]
rlm@205 150 :nidorina [:poison]
rlm@205 151 :nidorino [:poison]
rlm@205 152 :ninetails [:fire]
rlm@205 153 :oddish [:grass :poison]
rlm@205 154 :omanyte [:rock :water]
rlm@205 155 :omastar [:rock :water]
rlm@205 156 :onix [:rock :ground]
rlm@205 157 :paras [:bug :grass]
rlm@205 158 :parasect [:bug :grass]
rlm@205 159 :persian [:normal]
rlm@205 160 :pidgeot [:normal :flying]
rlm@205 161 :pidgeotto [:normal :flying]
rlm@205 162 :pidgey [:normal :flying]
rlm@205 163 :pikachu [:electric]
rlm@205 164 :pinsir [:bug]
rlm@205 165 :poliwag [:water]
rlm@205 166 :poliwhirl [:water]
rlm@205 167 :poliwrath [:water :fighting]
rlm@205 168 :ponyta [:fire]
rlm@205 169 :porygon [:normal]
rlm@205 170 :primeape [:fighting]
rlm@205 171 :psyduck [:water]
rlm@205 172 :raichu [:electric]
rlm@205 173 :rapidash [:fire]
rlm@205 174 :raticate [:normal]
rlm@205 175 :rattata [:normal]
rlm@205 176 :rhydon [:ground :rock]
rlm@205 177 :rhyhorn [:ground :rock]
rlm@205 178 :sandshrew [:ground]
rlm@205 179 :sandslash [:ground]
rlm@205 180 :scyther [:bug :flying]
rlm@205 181 :seaking [:water]
rlm@205 182 :sedra [:water]
rlm@205 183 :seel [:water]
rlm@205 184 :shellder [:water]
rlm@205 185 :slowbro [:water :psychic]
rlm@205 186 :slowpoke [:water :psychic]
rlm@205 187 :snorlax [:normal]
rlm@205 188 :spearow [:normal :flying]
rlm@205 189 :squirtle [:water]
rlm@205 190 :starmie [:water :psychic]
rlm@205 191 :staryu [:water]
rlm@205 192 :tangela [:grass]
rlm@205 193 :tauros [:normal]
rlm@205 194 :tentacool [:water :poison]
rlm@205 195 :tentacruel [:water :poison]
rlm@205 196 :vaporeon [:water]
rlm@205 197 :venomoth [:bug :poison]
rlm@205 198 :venonat [:bug :poison]
rlm@205 199 :venusaur [:grass :poison]
rlm@205 200 :victreebel [:grass :poison]
rlm@205 201 :vileplume [:grass :poison]
rlm@205 202 :voltorb [:electric]
rlm@205 203 :vulpix [:fire]
rlm@205 204 :wartortle [:water]
rlm@205 205 :weedle [:bug :poison]
rlm@205 206 :weepenbell [:grass :poison]
rlm@205 207 :wheezing [:poison]
rlm@205 208 :wigglytuff [:normal]
rlm@205 209 :zapdos [:electric :flying]
rlm@205 210 :zubat [:poison :flying]})
rlm@203 211
rlm@204 212
rlm@204 213
rlm@204 214
rlm@204 215
rlm@205 216
rlm@205 217
rlm@205 218
rlm@205 219
rlm@205 220
rlm@205 221
rlm@205 222
rlm@205 223
rlm@205 224
rlm@205 225
rlm@205 226
rlm@205 227
rlm@205 228
rlm@205 229
rlm@205 230
rlm@205 231
rlm@205 232
rlm@205 233
rlm@205 234
rlm@205 235
rlm@205 236
rlm@205 237
rlm@205 238
rlm@205 239
rlm@205 240
rlm@205 241
rlm@205 242
rlm@205 243
rlm@205 244
rlm@205 245
rlm@205 246
rlm@205 247
rlm@205 248
rlm@205 249
rlm@205 250
rlm@205 251
rlm@205 252
rlm@205 253
rlm@205 254
rlm@205 255
rlm@205 256
rlm@205 257
rlm@205 258
rlm@205 259
rlm@205 260
rlm@205 261
rlm@205 262
rlm@205 263
rlm@205 264
rlm@205 265
rlm@205 266
rlm@205 267
rlm@205 268
rlm@205 269
rlm@205 270
rlm@205 271
rlm@205 272
rlm@205 273
rlm@205 274
rlm@205 275
rlm@205 276
rlm@205 277
rlm@205 278
rlm@205 279
rlm@205 280
rlm@205 281
rlm@205 282
rlm@205 283
rlm@205 284
rlm@205 285
rlm@205 286
rlm@205 287
rlm@205 288
rlm@205 289
rlm@205 290
rlm@205 291
rlm@205 292
rlm@205 293
rlm@205 294
rlm@205 295
rlm@205 296
rlm@205 297
rlm@205 298
rlm@205 299
rlm@205 300
rlm@205 301
rlm@205 302
rlm@205 303
rlm@205 304
rlm@205 305
rlm@205 306
rlm@205 307
rlm@205 308
rlm@205 309
rlm@205 310
rlm@205 311
rlm@205 312
rlm@205 313
rlm@205 314
rlm@205 315
rlm@205 316
rlm@205 317
rlm@205 318
rlm@205 319
rlm@205 320
rlm@205 321
rlm@205 322
rlm@205 323
rlm@205 324
rlm@205 325
rlm@205 326
rlm@205 327
rlm@205 328
rlm@205 329
rlm@205 330
rlm@205 331
rlm@205 332
rlm@205 333
rlm@205 334
rlm@205 335
rlm@205 336
rlm@205 337
rlm@205 338
rlm@205 339
rlm@205 340
rlm@205 341
rlm@205 342
rlm@205 343
rlm@205 344
rlm@205 345
rlm@205 346
rlm@205 347
rlm@205 348
rlm@205 349
rlm@205 350
rlm@205 351
rlm@205 352
rlm@205 353
rlm@205 354
rlm@205 355
rlm@205 356
rlm@205 357
rlm@205 358
rlm@205 359
rlm@205 360
rlm@205 361
rlm@205 362
rlm@205 363
rlm@205 364