comparison clojure/com/aurellem/gb/hxc.clj @ 261:1b5c33614b0d

merge
author Robert McIntyre <rlm@mit.edu>
date Mon, 26 Mar 2012 19:57:25 -0500
parents b2f9a0cb13e3
children a44a2c459aeb
comparison
equal deleted inserted replaced
260:11cfe6dcb803 261:1b5c33614b0d
6 6
7 7
8 8
9 9
10 ; ************* HANDWRITTEN CONSTANTS 10 ; ************* HANDWRITTEN CONSTANTS
11
12
13
14 (defn low-high
15 [low high]
16 (+ low (* 256 high)))
17
18
19 (defn format-name
20 "Convert the string of alphabetic/space characters into a keyword by
21 replacing spaces with hyphens and converting to lowercase."
22 [s]
23 (keyword (.toLowerCase
24 (apply str
25 (map #(if (= % \space) "-" %) s)))))
26
27
11 28
12 (def pkmn-types 29 (def pkmn-types
13 [:normal 30 [:normal
14 :fighting 31 :fighting
15 :flying 32 :flying
51 "0x4C chance of poison" 68 "0x4C chance of poison"
52 "leech half of inflicted damage" 69 "leech half of inflicted damage"
53 "0x19 chance of burn" 70 "0x19 chance of burn"
54 "0x19 chance of freeze" 71 "0x19 chance of freeze"
55 "0x19 chance of paralyze" 72 "0x19 chance of paralyze"
56 "user faints; opponent defense halved." 73 "user faints; opponent defense halved during attack."
57 "leech half of inflicted damage ONLY if sleeping opponent." 74 "leech half of inflicted damage ONLY if sleeping opponent."
58 "imitate last attack" 75 "imitate last attack"
59 "user atk +1" 76 "user atk +1"
60 "user def +1" 77 "user def +1"
61 "user spd +1" 78 "user spd +1"
139 156
140 157
141 ;; ************** HARDCODED DATA 158 ;; ************** HARDCODED DATA
142 159
143 (defn hxc-thunk 160 (defn hxc-thunk
144 "Creates a thunk (unary fn) that grabs data in a certain region of rom and 161 "Creates a thunk (nullary fn) that grabs data in a certain region of rom and
145 splits it into a collection by 0x50. If rom is not supplied, uses the 162 splits it into a collection by 0x50. If rom is not supplied, uses the
146 original rom data." 163 original rom data."
147 [start length] 164 [start length]
148 (fn self 165 (fn self
149 ([rom] 166 ([rom]
177 (def hxc-titles 194 (def hxc-titles
178 "The hardcoded names of the trainer titles in memory. List begins at 195 "The hardcoded names of the trainer titles in memory. List begins at
179 ROM@27E77" 196 ROM@27E77"
180 (hxc-thunk-words 0x27E77 196)) 197 (hxc-thunk-words 0x27E77 196))
181 198
199
200 (def hxc-pokedex-text
201 "The hardcoded pokedex entries in memory. List begins at
202 ROM@B8000, shortly before move names."
203 (hxc-thunk-words 0xB8000 14754))
204
205
206 ;; In red/blue, pokemon are in internal order.
207 ;; In yellow, pokemon are in pokedex order.
208
209 (defn hxc-pokedex-stats
210 ;; uses hxc-pokedex-text to count pokemon
211 ;; since hxc-pokenames includes several missingno"
212 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))
213 ([rom]
214 (let [poketext (hxc-pokedex-text)
215 pkmn-count (count poketext)
216 ]
217 ((fn capture-stats
218 [n stats data]
219 (if (zero? n) stats
220 (let [[species
221 [_
222 height-ft
223 height-in
224 weight-1
225 weight-2
226 _
227 dex-ptr-1
228 dex-ptr-2
229 dex-bank
230 _
231 & data]]
232 (split-with (partial not= 0x50) data)]
233 (recur (dec n)
234 (assoc stats
235 (- pkmn-count n)
236 {:species
237 (character-codes->str species)
238 :height-ft
239 height-ft
240 :height-in
241 height-in
242 :weight
243 (/ (low-high weight-1 weight-2) 10.)
244
245 ;; :text
246 ;; (character-codes->str
247 ;; (take-while
248 ;; (partial not= 0x50)
249 ;; (drop
250 ;; (+ 0xB8000
251 ;; -0x4000
252 ;; (low-high dex-ptr-1 dex-ptr-2))
253 ;; rom)))
254 })
255
256 data)
257
258
259 )))
260
261 pkmn-count
262 {}
263 (drop 0x40687 rom))) ))
264
265
266
267
268
269
270
182 (def hxc-places 271 (def hxc-places
183 "The hardcoded place names in memory. List begins at 272 "The hardcoded place names in memory. List begins at
184 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated." 273 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."
185 (hxc-thunk-words 0x71500 560)) 274 (hxc-thunk-words 0x71500 560))
186 275
196 (drop 0x98000 rom)))))) 285 (drop 0x98000 rom))))))
197 ([] 286 ([]
198 (hxc-dialog com.aurellem.gb.gb-driver/original-rom))) 287 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
199 288
200 289
201 (def hxc-pokedex 290
202 "The hardcoded pokedex entries in memory. List begins at
203 ROM@B8000, shortly before move names."
204 (hxc-thunk-words 0xB8000 14754))
205 291
206 (def hxc-move-names 292 (def hxc-move-names
207 "The hardcoded move names in memory. List begins at ROM@BC000" 293 "The hardcoded move names in memory. List begins at ROM@BC000"
208 (hxc-thunk-words 0xBC000 1551)) 294 (hxc-thunk-words 0xBC000 1551))
209 295
215 ([] 301 ([]
216 (hxc-move-data com.aurellem.gb.gb-driver/original-rom)) 302 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))
217 ([rom] 303 ([rom]
218 (let [names (vec (hxc-move-names rom)) 304 (let [names (vec (hxc-move-names rom))
219 move-count (count names) 305 move-count (count names)
220 move-size 6 306 move-size 6]
221 format-name (fn [s]
222 (keyword (.toLowerCase
223 (apply str
224 (map #(if (= % \space) "-" %) s)))))]
225 (zipmap (map format-name names) 307 (zipmap (map format-name names)
226 (map 308 (map
227 (fn [[idx effect power type accuracy pp]] 309 (fn [[idx effect power type accuracy pp]]
228 {:name (names (dec idx)) 310 {:name (names (dec idx))
229 :power power 311 :power power
285 (map #(if (= 0x50 %) 0x00 %) 367 (map #(if (= 0x50 %) 0x00 %)
286 (take (* count-species name-length) 368 (take (* count-species name-length)
287 (drop 0xE8000 369 (drop 0xE8000
288 rom)))))))) 370 rom))))))))
289 371
372
373
374
375 (defn internal-id
376 ([rom]
377 (zipmap
378 (map format-name (hxc-pokenames rom))
379 (range)))
380 ([]
381 (internal-id com.aurellem.gb.gb-driver/original-rom)))
382
383
384
385
386
387
290 (defn hxc-advantage 388 (defn hxc-advantage
291 "The hardcoded type advantages in memory, returned as tuples of atk-type def-type multiplier. By default (i.e. if not listed here), 389 "The hardcoded type advantages in memory, returned as tuples of atk-type def-type multiplier. By default (i.e. if not listed here),
292 the multiplier is 1." 390 the multiplier is 1."
293 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom)) 391 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))
294 ([rom] 392 ([rom]
301 (drop 0x3E62D rom)))))) 399 (drop 0x3E62D rom))))))
302 400
303 401
304 402
305 403
306 404 (defn format-evo
405 [[method x y z & _]]
406 (cond (= 0 method)
407 {:method :none}
408 (= 1 method)
409 {:method :level-up
410 :min-level x
411 :into y}
412 (= 2 method)
413 {:method :item
414 :item-id x
415 :min-level y
416 :into z}
417 (= 3 method)
418 {:method :trade
419 :min-level x
420 :into y}))
421
422 (defn format-evo*
423 [[method x y z & _]]
424 (cond (= 0 method)
425 {:method :none}
426 (= 1 method)
427 {:method :level-up
428 :min-level x
429 :into (format-name (nth (hxc-pokenames) (dec y)))}
430 (= 2 method)
431 {:method :item
432 :item (format-name (nth (hxc-items) (dec x)))
433 :min-level y
434 :into (format-name (nth (hxc-pokenames) (dec z)))}
435 (= 3 method)
436 {:method :trade
437 :min-level x
438 :into (format-name (nth (hxc-pokenames) (dec y)))}))
439
440 (defn hxc-evolution
441 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
442 ([rom]
443 (let [names (hxc-pokenames rom)
444 pkmn-count (count names)
445 evo-data (drop 0x33fef rom)
446 ptrs
447 (map (fn [[a b]](low-high a b))
448 (partition 2
449 (take (* 2 pkmn-count)
450 (drop 0x3b1e5 rom))))
451 ]
452 (apply assoc {}
453 (interleave
454 (map format-name (hxc-pokenames))
455 (map
456 (comp
457 format-evo
458 (partial take 5)
459 #(drop % rom)
460 (partial + 0x34000))
461 ptrs)))
462
463 )))
464
465
466 (defn hxc-evolution*
467 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
468 ([rom]
469 (let [names (hxc-pokenames rom)
470 pkmn-count (count names)
471 evo-data (drop 0x33fef rom)
472 ptrs
473 (map (fn [[a b]](low-high a b))
474 (partition 2
475 (take (* 2 pkmn-count)
476 (drop 0x3b1e5 rom))))
477 ]
478 (apply assoc {}
479 (interleave
480 (map format-name (hxc-pokenames))
481 (map
482 (comp
483 format-evo*
484 (partial take 5)
485 #(drop % rom)
486 (partial + 0x34000))
487 ptrs)))
488
489 )))
307 490
308 491
309 492
310 493
311 494
383 (def dex dex) 566 (def dex dex)
384 (def hxc-species 567 (def hxc-species
385 (map character-codes->str 568 (map character-codes->str
386 (take-nth 4 dex)))) 569 (take-nth 4 dex))))
387 ) 570 )
571
572
573
574