Mercurial > vba-clojure
view clojure/com/aurellem/gb/hxc.clj @ 347:ff65ee0944fe
more progess: now rom.org tangles into hxc.clj; i'll be subdividing the code blocks as I write more.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Sun, 08 Apr 2012 06:13:39 -0500 |
parents | 5639312a393f |
children | 497ca041f5af |
line wrap: on
line source
2 (ns com.aurellem.gb.hxc3 (:use (com.aurellem.gb assembly characters gb-driver util mem-util4 constants species))5 (:import [com.aurellem.gb.gb_driver SaveState]))10 ; ************* HANDWRITTEN CONSTANTS12 (def pkmn-types13 [:normal ;;014 :fighting ;;115 :flying ;;216 :poison ;;317 :ground ;;418 :rock ;;519 :bird ;;620 :bug ;;721 :ghost ;;822 :A23 :B24 :C25 :D26 :E27 :F28 :G29 :H30 :I31 :J32 :K33 :fire ;;20 (0x14)34 :water ;;21 (0x15)35 :grass ;;22 (0x16)36 :electric ;;23 (0x17)37 :psychic ;;24 (0x18)38 :ice ;;25 (0x19)39 :dragon ;;26 (0x1A)40 ])43 ;; question: when status effects claim to take44 ;; their accuracy from the move accuracy, does45 ;; this mean that the move always "hits" but the46 ;; status effect may not?48 (def move-effects49 ["normal damage"50 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?51 "0x4C chance of poison"52 "leech half of inflicted damage"53 "0x19 chance of burn"54 "0x19 chance of freeze"55 "0x19 chance of paralyze"56 "user faints; opponent defense halved during attack."57 "leech half of inflicted damage ONLY if sleeping opponent."58 "imitate last attack"59 "user atk +1"60 "user def +1"61 "user spd +1"62 "user spc +1"63 "user acr +1" ;; unused?!64 "user evd +1"65 "get post-battle $ = 2*level*uses"66 "0xFE acr, no matter what."67 "opponent atk -1" ;; acr taken from move acr?68 "opponent def -1" ;;69 "opponent spd -1" ;;70 "opponent spc -1" ;;71 "opponent acr -1";;72 "opponent evd -1"73 "converts user's type to opponent's."74 "(haze)"75 "(bide)"76 "(thrash)"77 "(teleport)"78 "(fury swipes)"79 "attacks 2-5 turns" ;; unused? like rollout?80 "0x19 chance of flinch"81 "opponent sleep for 1-7 turns"82 "0x66 chance of poison"83 "0x4D chance of burn"84 "0x4D chance of freeze"85 "0x4D chance of paralyze"86 "0x4D chance of flinch"87 "one-hit KO"88 "charge one turn, atk next."89 "fixed damage, leaves 1HP." ;; how is dmg determined?90 "fixed damage." ;; cf seismic toss, dragon rage, psywave.91 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)92 "charge one turn, atk next. (can't be hit when charging)"93 "atk hits twice."94 "user takes 1 damage if misses."95 "evade status-lowering effects" ;;caused by you or also your opponent?96 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"97 "atk causes recoil dmg = 1/4 dmg dealt"98 "confuses opponent" ;; acr taken from move acr99 "user atk +2"100 "user def +2"101 "user spd +2"102 "user spc +2"103 "user acr +2" ;; unused!104 "user evd +2" ;; unused!105 "restores up to half of user's max hp." ;; broken: fails if the difference106 ;; b/w max and current hp is one less than a multiple of 256.107 "(transform)"108 "opponent atk -2"109 "opponent def -2"110 "opponent spd -2"111 "opponent spc -2"112 "opponent acr -2"113 "opponent evd -2"114 "doubles user spc when attacked"115 "doubles user def when attacked"116 "just poisons opponent" ;;acr taken from move acr117 "just paralyzes opponent" ;;118 "0x19 chance opponent atk -1"119 "0x19 chance opponent def -1"120 "0x19 chance opponent spd -1"121 "0x4C chance opponent spc -1" ;; context suggest chance is 0x19122 "0x19 chance opponent acr -1"123 "0x19 chance opponent evd -1"124 "???" ;; unused? no effect?125 "???" ;; unused? no effect?126 "0x19 chance opponent confused"127 "atk hits twice. 0x33 chance opponent poisioned."128 "broken. crash the game after attack."129 "(substitute)"130 "unless opponent faints, user must recharge after atk. some131 exceptions apply."132 "(rage)"133 "(mimic)"134 "(metronome)"135 "(leech seed)"136 "does nothing (splash)"137 "(disable)"138 ])140 ;; ************** HARDCODED DATA142 (defn hxc-thunk143 "Creates a thunk (nullary fn) that grabs data in a certain region of rom and144 splits it into a collection by 0x50. If rom is not supplied, uses the145 original rom data."146 [start length]147 (fn self148 ([rom]149 (take-nth 2150 (partition-by #(= % 0x50)151 (take length152 (drop start rom)))))153 ([]154 (self com.aurellem.gb.gb-driver/original-rom))))156 (def hxc-thunk-words157 "Same as hxc-thunk, except it interprets the rom data as characters,158 returning a collection of strings."159 (comp160 (partial comp (partial map character-codes->str))161 hxc-thunk))163 ;; --------------------------------------------------167 (defn hxc-pokenames-raw168 "The hardcoded names of the 190 species in memory. List begins at169 ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters170 long, these names are stripped of padding. See also, hxc-pokedex-names"171 ([]172 (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom))173 ([rom]174 (let [count-species 190175 name-length 10]176 (map character-codes->str177 (partition name-length178 (map #(if (= 0x50 %) 0x00 %)179 (take (* count-species name-length)180 (drop 0xE8000181 rom))))))))182 (def hxc-pokenames183 (comp184 (partial map format-name)185 hxc-pokenames-raw))190 (defn hxc-pokedex-names191 "The names of the pokemon in hardcoded pokedex order. List begins at192 ROM@410B1. See also, hxc-pokenames."193 ([] (hxc-pokedex-names194 com.aurellem.gb.gb-driver/original-rom))195 ([rom]196 (let [names (hxc-pokenames rom)]197 (#(mapv %198 ((comp range count keys) %))199 (zipmap200 (take (count names)201 (drop 0x410b1 rom))203 names)))))207 ;; http://hax.iimarck.us/topic/581/208 (defn hxc-cry209 "The pokemon cry data in internal order. List begins at ROM@39462"210 ([](hxc-cry com.aurellem.gb.gb-driver/original-rom))211 ([rom]212 (zipmap213 (hxc-pokenames rom)214 (map215 (fn [[cry-id pitch length]]216 {:cry-id cry-id217 :pitch pitch218 :length length}219 )220 (partition 3221 (drop 0x39462 rom))))))223 (defn hxc-cry-groups224 ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom))225 ([rom]226 (map #(mapv first227 (filter228 (fn [[k v]]229 (= % (:cry-id v)))230 (hxc-cry)))231 ((comp232 range233 count234 set235 (partial map :cry-id)236 vals237 hxc-cry)238 rom))))241 (defn cry-conversion!242 "Convert Porygon's cry in ROM to be the cry of the given pokemon."243 [pkmn]244 (write-rom!245 (rewrite-memory246 (vec(rom))247 0x3965D248 (map second249 ((hxc-cry) pkmn)))))251 (def hxc-items-raw252 "The hardcoded names of the items in memory. List begins at253 ROM@045B7"254 (hxc-thunk-words 0x45B7 870))256 (def hxc-types257 "The hardcoded type names in memory. List begins at ROM@27D99,258 shortly before hxc-titles."259 (hxc-thunk-words 0x27D99 102))261 (def hxc-titles262 "The hardcoded names of the trainer titles in memory. List begins at263 ROM@27E77"264 (hxc-thunk-words 0x27E77 196))267 (def hxc-pokedex-text-raw268 "The hardcoded pokedex entries in memory. List begins at269 ROM@B8000, shortly before move names."270 (hxc-thunk-words 0xB8000 14754))274 (def hxc-items275 "The hardcoded names of the items in memory, presented as276 keywords. List begins at ROM@045B7. See also, hxc-items-raw."277 (comp (partial map format-name) hxc-items-raw))279 (defn hxc-pokedex-text280 "The hardcoded pokedex entries in memory, presented as an281 associative hash map. List begins at ROM@B8000."282 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))283 ([rom]284 (zipmap285 (hxc-pokedex-names rom)286 (cons nil ;; for missingno.287 (hxc-pokedex-text-raw rom)))))289 ;; In red/blue, pokedex stats are in internal order.290 ;; In yellow, pokedex stats are in pokedex order.292 (defn hxc-pokedex-stats293 "The hardcoded pokedex stats (species height weight) in memory. List294 begins at ROM@40687"295 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))296 ([rom]297 (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom))298 pkmn-count (count pokedex-names)299 ]300 ((fn capture-stats301 [n stats data]302 (if (zero? n) stats303 (let [[species304 [_305 height-ft306 height-in307 weight-1308 weight-2309 _310 dex-ptr-1311 dex-ptr-2312 dex-bank313 _314 & data]]315 (split-with (partial not= 0x50) data)]316 (recur (dec n)317 (assoc stats318 (pokedex-names (- pkmn-count (dec n)))319 {:species320 (format-name (character-codes->str species))321 :height-ft322 height-ft323 :height-in324 height-in325 :weight326 (/ (low-high weight-1 weight-2) 10.)328 ;; :text329 ;; (character-codes->str330 ;; (take-while331 ;; (partial not= 0x50)332 ;; (drop333 ;; (+ 0xB8000334 ;; -0x4000335 ;; (low-high dex-ptr-1 dex-ptr-2))336 ;; rom)))337 })339 data)342 )))344 pkmn-count345 {}346 (drop 0x40687 rom))) ))354 (def hxc-places355 "The hardcoded place names in memory. List begins at356 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."357 (hxc-thunk-words 0x71500 560))360 (defn hxc-dialog361 "The hardcoded dialogue in memory, including in-game alerts. Dialog362 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."363 ([rom]364 (map character-codes->str365 (take-nth 2366 (partition-by #(= % 0x57)367 (take 0x0F728368 (drop 0x98000 rom))))))369 ([]370 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))373 (def hxc-move-names374 "The hardcoded move names in memory. List begins at ROM@BC000"375 (hxc-thunk-words 0xBC000 1551))378 (defn hxc-move-data379 "The hardcoded (basic (move effects)) in memory. List begins at380 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id381 :fx-txt}. The move descriptions are handwritten, not hardcoded."382 ([]383 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))384 ([rom]385 (let [names (vec (hxc-move-names rom))386 move-count (count names)387 move-size 6388 types pkmn-types ;;; !! hardcoded types389 ]390 (zipmap (map format-name names)391 (map392 (fn [[idx effect power type-id accuracy pp]]393 {:name (names (dec idx))394 :power power395 :accuracy accuracy396 :pp pp397 :type (types type-id)398 :fx-id effect399 :fx-txt (get move-effects effect)400 }401 )403 (partition move-size404 (take (* move-size move-count)405 (drop 0x38000 rom))))))))409 (defn hxc-move-data*410 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."411 ([]412 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))413 ([rom]414 (let [names (vec (hxc-move-names rom))415 move-count (count names)416 move-size 6417 format-name (fn [s]418 (keyword (.toLowerCase419 (apply str420 (map #(if (= % \space) "-" %) s)))))421 ]422 (zipmap (map format-name names)423 (map424 (fn [[idx effect power type accuracy pp]]425 {:name (names (dec idx))426 :power power427 :accuracy (hex accuracy)428 :pp pp429 :fx-id (hex effect)430 :fx-txt (get move-effects effect)431 }432 )434 (partition move-size435 (take (* move-size move-count)436 (drop 0x38000 rom))))))))439 (defn hxc-machines440 "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."441 ([] (hxc-machines442 com.aurellem.gb.gb-driver/original-rom))443 ([rom]444 (let [moves (hxc-move-names rom)]445 (zipmap446 (range)447 (take-while448 (comp not nil?)449 (map (comp450 format-name451 (zipmap452 (range)453 moves)454 dec)455 (take 100456 (drop 0x1232D rom))))))))460 (defn internal-id461 ([rom]462 (zipmap463 (hxc-pokenames rom)464 (range)))465 ([]466 (internal-id com.aurellem.gb.gb-driver/original-rom)))472 ;; nidoran gender change upon levelup473 ;; (->474 ;; @current-state475 ;; rom476 ;; vec477 ;; (rewrite-memory478 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))479 ;; [1 1 15])480 ;; (rewrite-memory481 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))482 ;; [1 1 3])483 ;; (write-rom!)485 ;; )490 (defn hxc-advantage491 ;; in-game multipliers are stored as 10x their effective value492 ;; to allow for fractional multipliers like 1/2494 "The hardcoded type advantages in memory, returned as tuples of495 atk-type def-type multiplier. By default (i.e. if not listed here),496 the multiplier is 1. List begins at 0x3E62D."497 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))498 ([rom]499 (map500 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))501 (get pkmn-types def (hex def))502 (/ mult 10)])503 (partition 3504 (take-while (partial not= 0xFF)505 (drop 0x3E62D rom))))))509 (defn format-evo510 "Parse a sequence of evolution data, returning a map. First is the511 method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the512 method of evolution is by item (only stones will actually make pokemon513 evolve, for some auxillary reason.) Finally, the minimum level for514 evolution to occur (level 1 means no limit, which is used for trade515 and item evolutions), followed by the internal id of the pokemon516 into which to evolve. Hence, level up and trade evolutions are517 described with 3518 bytes; item evolutions with four."519 [coll]520 (let [method (first coll)]521 (cond (empty? coll) []522 (= 0 method) [] ;; just in case523 (= 1 method) ;; level-up evolution524 (conj (format-evo (drop 3 coll))525 {:method :level-up526 :min-level (nth coll 1)527 :into (dec (nth coll 2))})529 (= 2 method) ;; item evolution530 (conj (format-evo (drop 4 coll))531 {:method :item532 :item (dec (nth coll 1))533 :min-level (nth coll 2)534 :into (dec (nth coll 3))})536 (= 3 method) ;; trade evolution537 (conj (format-evo (drop 3 coll))538 {:method :trade539 :min-level (nth coll 1) ;; always 1 for trade.540 :into (dec (nth coll 2))}))))543 (defn hxc-ptrs-evolve544 "A hardcoded collection of 190 pointers to alternating evolution/learnset data,545 in internal order."546 ([]547 (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))548 ([rom]549 (let [550 pkmn-count (count (hxc-pokenames-raw)) ;; 190551 ptrs552 (map (fn [[a b]] (low-high a b))553 (partition 2554 (take (* 2 pkmn-count)555 (drop 0x3b1e5 rom))))]556 (map (partial + 0x34000) ptrs)558 )))561 (defn hxc-learnsets562 "Hardcoded map associating pokemon names to lists of pairs [lvl563 move] of abilities they learn as they level up. The data564 exists at ROM@34000, sorted by internal order. Pointers to the data565 exist at ROM@3B1E5; see also, hxc-ptrs-evolve"566 ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))567 ([rom]568 (apply assoc569 {}570 (interleave571 (hxc-pokenames rom)572 (map (comp573 (partial map574 (fn [[lvl mv]] [lvl (dec mv)]))575 (partial partition 2)576 ;; keep the learnset data577 (partial take-while (comp not zero?))578 ;; skip the evolution data579 rest580 (partial drop-while (comp not zero?)))581 (map #(drop % rom)582 (hxc-ptrs-evolve rom)))))))584 (defn hxc-learnsets-pretty585 "Live hxc-learnsets except it reports the name of each move --- as586 it appears in rom --- rather than the move index."587 ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))588 ([rom]589 (let [moves (vec(map format-name (hxc-move-names)))]590 (into {}591 (map (fn [[pkmn learnset]]592 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])593 learnset)])594 (hxc-learnsets rom))))))599 (defn hxc-evolution600 "Hardcoded evolution data in memory. The data exists at ROM@34000,601 sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."602 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))603 ([rom]604 (apply assoc {}605 (interleave606 (hxc-pokenames rom)607 (map608 (comp609 format-evo610 (partial take-while (comp not zero?))611 #(drop % rom))612 (hxc-ptrs-evolve rom)613 )))))615 (defn hxc-evolution-pretty616 "Like hxc-evolution, except it uses the names of items and pokemon617 --- grabbed from ROM --- rather than their numerical identifiers."618 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))619 ([rom]620 (let621 [poke-names (vec (hxc-pokenames rom))622 item-names (vec (hxc-items rom))623 use-names624 (fn [m]625 (loop [ks (keys m) new-map m]626 (let [k (first ks)]627 (cond (nil? ks) new-map628 (= k :into)629 (recur630 (next ks)631 (assoc new-map632 :into633 (poke-names634 (:into635 new-map))))636 (= k :item)637 (recur638 (next ks)639 (assoc new-map640 :item641 (item-names642 (:item new-map))))643 :else644 (recur645 (next ks)646 new-map)647 ))))]649 (into {}650 (map (fn [[pkmn evo-coll]]651 [pkmn (map use-names evo-coll)])652 (hxc-evolution rom))))))655 (defn hxc-pokemon-base656 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))657 ([rom]658 (let [entry-size 28659 pkmn-count (count (hxc-pokedex-text rom))660 pokemon (rest (hxc-pokedex-names))661 types (apply assoc {}662 (interleave663 (range)664 pkmn-types)) ;;!! softcoded665 moves (apply assoc {}666 (interleave667 (range)668 (map format-name669 (hxc-move-names rom))))670 machines (hxc-machines)671 ]672 (zipmap673 pokemon674 (map675 (fn [[n676 rating-hp677 rating-atk678 rating-def679 rating-speed680 rating-special681 type-1682 type-2683 rarity684 rating-xp685 pic-dimensions ;; tile_width|tile_height (8px/tile)686 ptr-pic-obverse-1687 ptr-pic-obverse-2688 ptr-pic-reverse-1689 ptr-pic-reverse-2690 move-1691 move-2692 move-3693 move-4694 growth-rate695 &696 TMs|HMs]]697 (let698 [base-moves699 (mapv moves700 ((comp701 ;; since the game uses zero as a delimiter,702 ;; it must also increment all move indices by 1.703 ;; heren we decrement to correct this.704 (partial map dec)705 (partial take-while (comp not zero?)))706 [move-1 move-2 move-3 move-4]))708 types709 (set (list (types type-1)710 (types type-2)))711 TMs|HMs712 (map713 (comp714 (partial map first)715 (partial remove (comp zero? second)))716 (split-at717 50718 (map vector719 (rest(range))720 (reduce concat721 (map722 #(take 8723 (concat (bit-list %)724 (repeat 0)))726 TMs|HMs)))))728 TMs (vec (first TMs|HMs))729 HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))732 ]735 {:dex# n736 :base-moves base-moves737 :types types738 :TMs TMs739 :HMs HMs740 :base-hp rating-hp741 :base-atk rating-atk742 :base-def rating-def743 :base-speed rating-speed744 :base-special rating-special745 :o0 pic-dimensions746 :o1 ptr-pic-obverse-1747 :o2 ptr-pic-obverse-2748 }))750 (partition entry-size751 (take (* entry-size pkmn-count)752 (drop 0x383DE753 rom))))))))756 (defn hxc-intro-pkmn757 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's758 internal id is stored at ROM@5EDB."759 ([] (hxc-intro-pkmn760 com.aurellem.gb.gb-driver/original-rom))761 ([rom]762 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))764 (defn sxc-intro-pkmn!765 "Set the hardcoded pokemon to display in Prof. Oak's introduction."766 [pokemon]767 (write-rom!768 (rewrite-rom 0x5EDB769 [770 (inc771 ((zipmap772 (hxc-pokenames)773 (range))774 pokemon))])))777 (defn hxc-item-prices778 "The hardcoded list of item prices in memory. List begins at ROM@4495"779 ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))780 ([rom]781 (let [items (hxc-items rom)782 price-size 3]783 (zipmap items784 (map (comp785 ;; zero-cost items are "priceless"786 #(if (zero? %) :priceless %)787 decode-bcd butlast)788 (partition price-size789 (take (* price-size (count items))790 (drop 0x4495 rom))))))))792 (defn hxc-shops793 ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))794 ([rom]795 (let [items (zipmap (range) (hxc-items rom))797 ;; temporarily softcode the TM items798 items (into799 items800 (map (juxt identity801 (comp keyword802 (partial str "tm-")803 (partial + 1 -200)804 ))805 (take 200 (drop 200 (range)))))807 ]809 ((fn parse-shop [coll [num-items & items-etc]]810 (let [inventory (take-while811 (partial not= 0xFF)812 items-etc)813 [separator & items-etc] (drop num-items (rest items-etc))]814 (if (= separator 0x50)815 (map (partial mapv (comp items dec)) (conj coll inventory))816 (recur (conj coll inventory) items-etc)817 )818 ))820 '()821 (drop 0x233C rom))824 )))830 (defn hxc-ptrs-wild831 "A list of the hardcoded wild encounter data in memory. Pointers832 begin at ROM@0CB95; data begins at ROM@0x04D89"833 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))834 ([rom]835 (let [ptrs836 (map (fn [[a b]] (+ a (* 0x100 b)))837 (take-while (partial not= (list 0xFF 0xFF))838 (partition 2 (drop 0xCB95 rom))))]839 ptrs)))843 (defn hxc-wilds844 "A list of the hardcoded wild encounter data in memory. Pointers845 begin at ROM@0CB95; data begins at ROM@0x04D89"846 ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))847 ([rom]848 (let [pokenames (zipmap (range) (hxc-pokenames rom))]849 (map850 (partial map (fn [[a b]] {:species (pokenames (dec b)) :level851 a}))852 (partition 10854 (take-while (comp (partial not= 1)855 first)856 (partition 2857 (drop 0xCD8C rom))859 ))))))874 ;; ********************** MANIPULATION FNS877 (defn same-type878 ([pkmn move]879 (same-type880 com.aurellem.gb.gb-driver/original-rom pkmn move))881 ([rom pkmn move]882 (((comp :types (hxc-pokemon-base rom)) pkmn)883 ((comp :type (hxc-move-data rom)) move))))888 (defn submap?889 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."890 [map-small map-big]891 (cond (empty? map-small) true892 (and893 (contains? map-big (ffirst map-small))894 (= (get map-big (ffirst map-small))895 (second (first map-small))))896 (recur (next map-small) map-big)898 :else false))901 (defn search-map [proto-map maps]902 "Returns all the maps that make the same associations as proto-map."903 (some (partial submap? proto-map) maps))905 (defn filter-vals906 "Returns a map consisting of all the pairs [key val] for907 which (pred key) returns true."908 [pred map]909 (reduce (partial apply assoc) {}910 (filter (fn [[k v]] (pred v)) map)))913 (defn search-moves914 "Returns a subcollection of all hardcoded moves with the915 given attributes. Attributes consist of :name :power916 :accuracy :pp :fx-id917 (and also :fx-txt, but it contains the same information918 as :fx-id)"919 ([attribute-map]920 (search-moves921 com.aurellem.gb.gb-driver/original-rom attribute-map))922 ([rom attribute-map]923 (filter-vals (partial submap? attribute-map)924 (hxc-move-data rom))))930 ;; note: 0x2f31 contains the names "TM" "HM"?932 ;; note for later: credits start at F1290934 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??936 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)938 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.939 ;; The first instance is for Machines; the second, for stones.941 ;; 0x251A (in indexable mem): image decompression routine seems to begin here.944 (comment946 (def hxc-later947 "Running this code produces, e.g. hardcoded names NPCs give948 their pokemon. Will sort through it later."949 (print (character-codes->str(take 10000950 (drop 0x71597951 (rom (root)))))))953 (let [dex954 (partition-by #(= 0x50 %)955 (take 2540956 (drop 0x40687957 (rom (root)))))]958 (def dex dex)959 (def hxc-species960 (map character-codes->str961 (take-nth 4 dex))))962 )