Mercurial > vba-clojure
view org/rom.org @ 582:393b49a83394
tracked down error to set=HL-from-row-and-column
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 01 Sep 2012 09:43:19 -0500 |
parents | 9a7fae5afd8f |
children |
line wrap: on
line source
1 #+title: Notes on Deconstructing Pokemon Yellow2 #+author: Dylan Holmes3 #+email: rlm@mit.edu4 #+description: A detailed explication of Pok\eacute{}mon Yellow, helped by Clojure.5 #+keywords: pokemon, pokemon yellow, rom, gameboy, assembly, hex, pointers, clojure6 #+SETUPFILE: ../../aurellem/org/setup.org7 #+INCLUDE: ../../aurellem/org/level-0.org8 #+BABEL: :exports both :noweb yes :cache no :mkdirp yes9 #+OPTIONS: num:212 # about map headers http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes13 # map headers Yellow http://www.pokecommunity.com/archive/index.php/t-235311.html14 # pokedollar: U+20B115 * Introduction16 This article contains the results of my investigations with17 Pok\eacute{}mon Yellow as I searched for interesting18 data in the ROM. By using the Clojure language interface19 written by Robert[fn::This Clojure interface will be published to aurellem.org soon.], I20 was able to interact with the game in real-time, sending commands and21 gathering data. The result is a manifestly accurate map of22 Pok\eacute{}mon Yellow; every result23 comes with runnable code that /works/. You can see the code and the output of24 every function and confirm for yourself that they are all correct. I25 hope you like the result!27 To orient yourself, you can look for a specific topic in the table of contents28 above, or browse the [[#sec-9-1][map of the ROM]], below.31 If you have any questions or comments, please e-mail =rlm@mit.edu=.34 ** COMMENT Getting linguistic data: names, words, etc.36 Some of the simplest data39 One of the simplest data structures in the Pok\eacute{} ROM is an40 unbroken list of strings that either (a) all have a specific length,41 or (b) are all separated by the same character.43 Because lots of good data has this format, we'll start by writing a44 template function to extract it:46 #+name: hxc-thunks47 #+begin_src clojure :results silent48 (defn hxc-thunk49 "Creates a thunk (nullary fn) that grabs data in a certain region of rom and50 splits it into a collection by 0x50. If rom is not supplied, uses the51 original rom data."52 [start length]53 (fn self54 ([rom]55 (take-nth 256 (partition-by #(= % 0x50)57 (take length58 (drop start rom)))))59 ([]60 (self com.aurellem.gb.gb-driver/original-rom))))62 (def hxc-thunk-words63 "Same as hxc-thunk, except it interprets the rom data as characters,64 returning a collection of strings."65 (comp66 (partial comp (partial map character-codes->str))67 hxc-thunk))69 #+end_src72 * Pok\eacute{}mon I73 ** Names of each species74 The names of the Pok\eacute{}mon species are stored in75 ROM@E8000. This name list is interesting, for a number of reasons:76 - The names are stored in [[ ][internal order]] rather than in the familiar77 Pok\eacute{}dex order. This seemingly random order probably represents the order in which the authors created or78 programmed in the Pok\eacute{}mon; it's used throughout the game.79 - There is enough space allocated for 190 Pok\eacute{}mon. As I80 understand it, there were originally going to be 190 Pok\eacute{}mon81 in Generation I, but the creators decided to defer some to82 Generation II. This explains why many Gen I and Gen II Pok\eacute{}mon83 have the same aesthetic feel.84 - The list is pockmarked with random gaps, due to the strange internal85 ordering86 and the 39 unused spaces [fn::190 allocated spaces minus 151 true Pok\eacute{}mon]. These missing spaces are filled with the87 placeholder name =MISSINGNO.= (\ldquo{}Missing number\rdquo{}).89 Each name is exactly ten letters long; whenever a name would be too short, the extra90 space is padded with the character 0x50.92 *** See the data94 Here you can see the raw data in three stages: in the first stage, we95 just grab the first few bytes starting from position 0xE8000. In the96 second stage, we partition the bytes into ten-letter chunks to show you97 where the names begin and end. In the final stage, we convert each98 byte into the letter it represents using the =character-codes->str=99 function. (0x50 is rendered as the symbol \ldquo{} =#= \rdquo{} for100 ease of reading).102 #+begin_src clojure :exports both :cache no :results output103 (ns com.aurellem.gb.hxc104 (:use (com.aurellem.gb assembly characters gb-driver util mem-util105 constants))106 (:import [com.aurellem.gb.gb_driver SaveState]))109 (println (take 100 (drop 0xE8000 (rom))))111 (println (partition 10 (take 100 (drop 0xE8000 (rom)))))113 (println (character-codes->str (take 100 (drop 0xE8000 (rom)))))116 #+end_src118 #+results:119 : (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)120 : ((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))121 : RHYDON####KANGASKHANNIDORAN♂##CLEFAIRY##SPEAROW###VOLTORB###NIDOKING##SLOWBRO###IVYSAUR###EXEGGUTOR#124 *** Automatically grab the data.126 #+name: pokenames127 #+begin_src clojure129 (defn hxc-pokenames-raw130 "The hardcoded names of the 190 species in memory. List begins at131 ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters132 long, these names are stripped of padding. See also, hxc-pokedex-names"133 ([]134 (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom))135 ([rom]136 (let [count-species 190137 name-length 10]138 (map character-codes->str139 (partition name-length140 (map #(if (= 0x50 %) 0x00 %)141 (take (* count-species name-length)142 (drop 0xE8000143 rom))))))))144 (def hxc-pokenames145 (comp146 (partial map format-name)147 hxc-pokenames-raw))152 (defn hxc-pokedex-names153 "The names of the pokemon in hardcoded pokedex order. List of the154 pokedex numbers of each pokemon (in internal order) begins at155 ROM@410B1. See also, hxc-pokenames."156 ([] (hxc-pokedex-names157 com.aurellem.gb.gb-driver/original-rom))158 ([rom]159 (let [names (hxc-pokenames rom)]160 (#(mapv %161 ((comp range count keys) %))162 (zipmap163 (take (count names)164 (drop 0x410b1 rom))166 names)))))168 #+end_src172 ** Generic species information174 #+name: pokebase175 #+begin_src clojure176 (defn hxc-pokemon-base177 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))178 ([rom]179 (let [entry-size 28181 pokemon (rest (hxc-pokedex-names))182 pkmn-count (inc(count pokemon))183 types (apply assoc {}184 (interleave185 (range)186 pkmn-types)) ;;!! softcoded187 moves (apply assoc {}188 (interleave189 (range)190 (map format-name191 (hxc-move-names rom))))192 machines (hxc-machines)193 ]194 (zipmap195 pokemon196 (map197 (fn [[n198 rating-hp199 rating-atk200 rating-def201 rating-speed202 rating-special203 type-1204 type-2205 rarity ;; catch rate206 rating-xp ;; base exp yield207 pic-dimensions ;; tile_width|tile_height (8px/tile)208 ptr-pic-obverse-1209 ptr-pic-obverse-2210 ptr-pic-reverse-1211 ptr-pic-reverse-2212 move-1 ;; attacks known at level 0 [i.e. by default]213 move-2 ;; (0 for none)214 move-3215 move-4216 growth-rate217 &218 TMs|HMs]]219 (let220 [base-moves221 (mapv moves222 ((comp223 ;; since the game uses zero as a delimiter,224 ;; it must also increment all move indices by 1.225 ;; heren we decrement to correct this.226 (partial map dec)227 (partial take-while (comp not zero?)))228 [move-1 move-2 move-3 move-4]))230 types231 (set (list (types type-1)232 (types type-2)))233 TMs|HMs234 (map235 (comp236 (partial map first)237 (partial remove (comp zero? second)))238 (split-at239 50240 (map vector241 (rest(range))242 (reduce concat243 (map244 #(take 8245 (concat (bit-list %)246 (repeat 0)))248 TMs|HMs)))))250 TMs (vec (first TMs|HMs))251 HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))254 ]257 {:dex# n258 :base-moves base-moves259 :types types260 :TMs TMs261 :HMs HMs262 :base-hp rating-hp263 :base-atk rating-atk264 :base-def rating-def265 :base-speed rating-speed266 :base-special rating-special267 :o0 pic-dimensions268 :o1 ptr-pic-obverse-1269 :o2 ptr-pic-obverse-2270 }))272 (partition entry-size273 (take (* entry-size pkmn-count)274 (drop 0x383DE275 rom))))))))277 #+end_src280 ** Pok\eacute{}mon evolutions281 #+name: evolution-header282 #+begin_src clojure283 (defn format-evo284 "Parse a sequence of evolution data, returning a map. First is the285 method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the286 method of evolution is by item (only stones will actually make pokemon287 evolve, for some auxillary reason.) Finally, the minimum level for288 evolution to occur (level 1 means no limit, which is used for trade289 and item evolutions), followed by the internal id of the pokemon290 into which to evolve. Hence, level up and trade evolutions are291 described with 3292 bytes; item evolutions with four."293 [coll]294 (let [method (first coll)]295 (cond (empty? coll) []296 (= 0 method) [] ;; just in case297 (= 1 method) ;; level-up evolution298 (conj (format-evo (drop 3 coll))299 {:method :level-up300 :min-level (nth coll 1)301 :into (dec (nth coll 2))})303 (= 2 method) ;; item evolution304 (conj (format-evo (drop 4 coll))305 {:method :item306 :item (dec (nth coll 1))307 :min-level (nth coll 2)308 :into (dec (nth coll 3))})310 (= 3 method) ;; trade evolution311 (conj (format-evo (drop 3 coll))312 {:method :trade313 :min-level (nth coll 1) ;; always 1 for trade.314 :into (dec (nth coll 2))}))))317 (defn hxc-ptrs-evolve318 "A hardcoded collection of 190 pointers to alternating evolution/learnset data,319 in internal order."320 ([]321 (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))322 ([rom]323 (let [324 pkmn-count (count (hxc-pokenames-raw)) ;; 190325 ptrs326 (map (fn [[a b]] (low-high a b))327 (partition 2328 (take (* 2 pkmn-count)329 (drop 0x3b1e5 rom))))]330 (map (partial + 0x34000) ptrs)332 )))333 #+end_src335 #+name:evolution336 #+begin_src clojure338 (defn hxc-evolution339 "Hardcoded evolution data in memory. The data exists at ROM@34000,340 sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."341 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))342 ([rom]343 (apply assoc {}344 (interleave345 (hxc-pokenames rom)346 (map347 (comp348 format-evo349 (partial take-while (comp not zero?))350 #(drop % rom))351 (hxc-ptrs-evolve rom)352 )))))354 (defn hxc-evolution-pretty355 "Like hxc-evolution, except it uses the names of items and pokemon356 --- grabbed from ROM --- rather than their numerical identifiers."357 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))358 ([rom]359 (let360 [poke-names (vec (hxc-pokenames rom))361 item-names (vec (hxc-items rom))362 use-names363 (fn [m]364 (loop [ks (keys m) new-map m]365 (let [k (first ks)]366 (cond (nil? ks) new-map367 (= k :into)368 (recur369 (next ks)370 (assoc new-map371 :into372 (poke-names373 (:into374 new-map))))375 (= k :item)376 (recur377 (next ks)378 (assoc new-map379 :item380 (item-names381 (:item new-map))))382 :else383 (recur384 (next ks)385 new-map)386 ))))]388 (into {}389 (map (fn [[pkmn evo-coll]]390 [pkmn (map use-names evo-coll)])391 (hxc-evolution rom))))))394 #+end_src397 ** Level-up moves (learnsets)398 #+name: learnsets399 #+begin_src clojure402 (defn hxc-learnsets403 "Hardcoded map associating pokemon names to lists of pairs [lvl404 move] of abilities they learn as they level up. The data405 exists at ROM@34000, sorted by internal order. Pointers to the data406 exist at ROM@3B1E5; see also, hxc-ptrs-evolve"407 ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))408 ([rom]409 (apply assoc410 {}411 (interleave412 (hxc-pokenames rom)413 (map (comp414 (partial map415 (fn [[lvl mv]] [lvl (dec mv)]))416 (partial partition 2)417 ;; keep the learnset data418 (partial take-while (comp not zero?))419 ;; skip the evolution data420 rest421 (partial drop-while (comp not zero?)))422 (map #(drop % rom)423 (hxc-ptrs-evolve rom)))))))425 (defn hxc-learnsets-pretty426 "Live hxc-learnsets except it reports the name of each move --- as427 it appears in rom --- rather than the move index."428 ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))429 ([rom]430 (let [moves (vec(map format-name (hxc-move-names)))]431 (into {}432 (map (fn [[pkmn learnset]]433 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])434 learnset)])435 (hxc-learnsets rom))))))439 #+end_src443 * Pok\eacute{}mon II : the Pok\eacute{}dex444 ** Species vital stats445 #+name: dex-stats446 #+begin_src clojure447 (defn hxc-pokedex-stats448 "The hardcoded pokedex stats (species height weight) in memory. List449 begins at ROM@40687"450 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))451 ([rom]452 (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom))453 pkmn-count (count pokedex-names)454 ]455 ((fn capture-stats456 [n stats data]457 (if (zero? n) stats458 (let [[species459 [_460 height-ft461 height-in462 weight-1463 weight-2464 _465 dex-ptr-1466 dex-ptr-2467 dex-bank468 _469 & data]]470 (split-with (partial not= 0x50) data)]471 (recur (dec n)472 (assoc stats473 (pokedex-names (- pkmn-count (dec n)))474 {:species475 (format-name (character-codes->str species))476 :height-ft477 height-ft478 :height-in479 height-in480 :weight481 (/ (low-high weight-1 weight-2) 10.)483 ;; :text484 ;; (character-codes->str485 ;; (take-while486 ;; (partial not= 0x50)487 ;; (drop488 ;; (+ 0xB8000489 ;; -0x4000490 ;; (low-high dex-ptr-1 dex-ptr-2))491 ;; rom)))492 })494 data)497 )))499 pkmn-count500 {}501 (drop 0x40687 rom))) ))502 #+end_src504 #+results: dex-stats505 : #'com.aurellem.gb.hxc/hxc-pokedex-stats507 ** Species synopses509 #+name: dex-text510 #+begin_src clojure511 (def hxc-pokedex-text-raw512 "The hardcoded pokedex entries in memory. List begins at513 ROM@B8000, shortly before move names."514 (hxc-thunk-words 0xB8000 14754))519 (defn hxc-pokedex-text520 "The hardcoded pokedex entries in memory, presented as an521 associative hash map. List begins at ROM@B8000."522 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))523 ([rom]524 (zipmap525 (hxc-pokedex-names rom)526 (cons nil ;; for missingno.527 (hxc-pokedex-text-raw rom)))))528 #+end_src531 ** Pok\eacute{}mon cries532 *** See the data534 Here, you can see that each Pok\eacute{}mon's cry data consists of535 three bytes: the =cry-id=, which is the basic sound byte to use, the536 =pitch=, which determines how high or low to make the sound byte, and537 the =length=, which is the amount of the sound byte to play.539 Even though there are only a few different basic sound bytes (cry540 ids) to build from, by varying the pitch and length,541 you can create a wide variety of different Pok\eacute{}mon cries.543 #+begin_src clojure :exports both :cache no :results output544 (ns com.aurellem.gb.hxc545 (:use (com.aurellem.gb assembly characters gb-driver util mem-util546 constants))547 (:import [com.aurellem.gb.gb_driver SaveState]))549 (->>550 (rom)551 (drop 0x39462)552 (take 12)553 (println))555 (->>556 (rom)557 (drop 0x39462)558 (take 12)559 (partition 3)560 (map vec)561 (println))563 (->>564 (rom)565 (drop 0x39462)566 (take 12)567 (partition 3)568 (map569 (fn [[id pitch length]]570 {:cry-id id :pitch pitch :length length}))571 (println))573 #+end_src575 #+results:576 : (17 0 128 3 0 128 0 0 128 25 204 1)577 : ([17 0 128] [3 0 128] [0 0 128] [25 204 1])578 : ({:cry-id 17, :pitch 0, :length 128} {:cry-id 3, :pitch 0, :length 128} {:cry-id 0, :pitch 0, :length 128} {:cry-id 25, :pitch 204, :length 1})581 It is interesting to note which Pok\eacute{}mon use the same basic582 =cry-id= --- I call these /cry groups/. Here, you can see which583 Pok\eacute{}mon belong to the same cry group.585 #+begin_src clojure :exports both :cache no :results output586 (ns com.aurellem.gb.hxc587 (:use (com.aurellem.gb assembly characters gb-driver util mem-util588 constants))589 (:import [com.aurellem.gb.gb_driver SaveState]))591 (println "POKEMON CRY GROUPS")592 (doall593 (map println594 (let [cry-id595 (->>596 (rom)597 (drop 0x39462) ;; get the cry data598 (partition 3) ;; partition it into groups of three599 (map first) ;; keep only the first item, the cry-id600 (zipmap (hxc-pokenames)) ;; associate each pokemon with its cry-id601 )]603 (->> (hxc-pokenames) ;; start with the list of pokemon604 (remove (partial = :missingno.)) ;; remove missingnos605 (sort-by cry-id)606 (partition-by cry-id)607 (map vec)))))609 #+end_src611 #+results:612 #+begin_example613 POKEMON CRY GROUPS614 [:nidoran♂ :sandshrew :sandslash :nidorino]615 [:nidoran♀ :nidorina]616 [:slowpoke]617 [:kangaskhan]618 [:rhyhorn :magmar :charmander :charmeleon :charizard]619 [:grimer :snorlax]620 [:voltorb :electabuzz :electrode]621 [:gengar :muk]622 [:marowak :oddish :gloom]623 [:nidoking :moltres :articuno :raichu]624 [:nidoqueen :mankey :primeape]625 [:exeggcute :diglett :doduo :dodrio :dugtrio]626 [:lickitung :hitmonchan :seel :dewgong]627 [:exeggutor :drowzee :jynx :hypno]628 [:pidgey :poliwag :ditto :jigglypuff :wigglytuff :poliwhirl :poliwrath]629 [:ivysaur :dragonite :pikachu :dratini :dragonair :bulbasaur :venusaur]630 [:spearow :farfetch'd]631 [:rhydon]632 [:tangela :hitmonlee :golem :koffing :weezing]633 [:blastoise :kakuna :beedrill]634 [:pinsir :chansey :pidgeotto :pidgeot]635 [:arcanine :weedle]636 [:scyther :kabuto :caterpie :butterfree :goldeen :seaking]637 [:gyarados :onix :arbok :ekans :magikarp]638 [:shellder :fearow :zapdos :kabutops :cloyster]639 [:clefairy :cubone :meowth :horsea :seadra :clefable :persian]640 [:tentacool :venonat :eevee :flareon :jolteon :vaporeon :venomoth :tentacruel]641 [:lapras]642 [:gastly :kadabra :magneton :metapod :haunter :abra :alakazam :magnemite]643 [:tauros :zubat :golbat :squirtle :wartortle]644 [:mew :staryu :parasect :paras :mewtwo :starmie]645 [:slowbro :growlithe :machoke :omanyte :omastar :machop :machamp]646 [:mr.mime :krabby :kingler]647 [:psyduck :golduck :bellsprout]648 [:rattata :raticate]649 [:aerodactyl :vileplume]650 [:graveler :vulpix :ninetales :geodude]651 [:ponyta :rapidash :porygon :weepinbell :victreebel]652 #+end_example659 *** Automatically grab the data660 #+name: pokecry661 #+begin_src clojure662 (defn hxc-cry663 "The pokemon cry data in internal order. List begins at ROM@39462"664 ([](hxc-cry com.aurellem.gb.gb-driver/original-rom))665 ([rom]666 (zipmap667 (hxc-pokenames rom)668 (map669 (fn [[cry-id pitch length]]670 {:cry-id cry-id671 :pitch pitch672 :length length}673 )674 (partition 3675 (drop 0x39462 rom))))))677 (defn hxc-cry-groups678 ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom))679 ([rom]680 (map #(mapv first681 (filter682 (fn [[k v]]683 (= % (:cry-id v)))684 (hxc-cry)))685 ((comp686 range687 count688 set689 (partial map :cry-id)690 vals691 hxc-cry)692 rom))))695 (defn cry-conversion!696 "Convert Porygon's cry in ROM to be the cry of the given pokemon."697 [pkmn]698 (write-rom!699 (rewrite-memory700 (vec(rom))701 0x3965D702 (map second703 ((hxc-cry) pkmn)))))705 #+end_src707 ** COMMENT Names of permanent stats708 0DD4D-DD72710 * Items711 ** Item names713 *** See the data714 #+begin_src clojure :exports both :results output715 (ns com.aurellem.gb.hxc716 (:use (com.aurellem.gb assembly characters gb-driver util mem-util717 constants))718 (:import [com.aurellem.gb.gb_driver SaveState]))720 (println (take 100 (drop 0x045B7 (rom))))722 (println723 (partition-by724 (partial = 0x50)725 (take 100 (drop 0x045B7 (rom)))))727 (println728 (map character-codes->str729 (partition-by730 (partial = 0x50)731 (take 100 (drop 0x045B7 (rom))))))734 #+end_src736 #+results:737 : (140 128 146 147 132 145 127 129 128 139 139 80 148 139 147 145 128 127 129 128 139 139 80 134 145 132 128 147 127 129 128 139 139 80 143 142 138 186 127 129 128 139 139 80 147 142 150 141 127 140 128 143 80 129 136 130 152 130 139 132 80 230 230 230 230 230 80 146 128 133 128 145 136 127 129 128 139 139 80 143 142 138 186 131 132 151 80 140 142 142 141 127 146 147 142 141 132 80 128 141)738 : ((140 128 146 147 132 145 127 129 128 139 139) (80) (148 139 147 145 128 127 129 128 139 139) (80) (134 145 132 128 147 127 129 128 139 139) (80) (143 142 138 186 127 129 128 139 139) (80) (147 142 150 141 127 140 128 143) (80) (129 136 130 152 130 139 132) (80) (230 230 230 230 230) (80) (146 128 133 128 145 136 127 129 128 139 139) (80) (143 142 138 186 131 132 151) (80) (140 142 142 141 127 146 147 142 141 132) (80) (128 141))739 : (MASTER BALL # ULTRA BALL # GREAT BALL # POKé BALL # TOWN MAP # BICYCLE # ????? # SAFARI BALL # POKéDEX # MOON STONE # AN)741 *** Automatically grab the data742 #+name: item-names743 #+begin_src clojure745 (def hxc-items-raw746 "The hardcoded names of the items in memory. List begins at747 ROM@045B7"748 (hxc-thunk-words 0x45B7 870))750 (def hxc-items751 "The hardcoded names of the items in memory, presented as752 keywords. List begins at ROM@045B7. See also, hxc-items-raw."753 (comp (partial map format-name) hxc-items-raw))754 #+end_src756 ** Item prices758 ***759 #+begin_src clojure :exports both :results output760 (ns com.aurellem.gb.hxc761 (:use (com.aurellem.gb assembly characters gb-driver util mem-util762 constants))763 (:import [com.aurellem.gb.gb_driver SaveState]))765 (println (take 90 (drop 0x4495 (rom))))767 (println768 (partition 3769 (take 90 (drop 0x4495 (rom)))))771 (println772 (partition 3773 (map hex774 (take 90 (drop 0x4495 (rom))))))776 (println777 (map decode-bcd778 (map butlast779 (partition 3780 (take 90 (drop 0x4495 (rom)))))))782 (println783 (map784 vector785 (hxc-items (rom))786 (map decode-bcd787 (map butlast788 (partition 3789 (take 90 (drop 0x4495 (rom))))))))795 #+end_src797 #+results:798 : (0 0 0 18 0 0 6 0 0 2 0 0 0 0 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 1 0 0 2 80 0 2 80 0 2 0 0 2 0 0 48 0 0 37 0 0 21 0 0 7 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 80 0 3 80 0)799 : ((0 0 0) (18 0 0) (6 0 0) (2 0 0) (0 0 0) (0 0 0) (0 0 0) (16 0 0) (0 0 0) (0 0 0) (1 0 0) (2 80 0) (2 80 0) (2 0 0) (2 0 0) (48 0 0) (37 0 0) (21 0 0) (7 0 0) (3 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (5 80 0) (3 80 0))800 : ((0x0 0x0 0x0) (0x12 0x0 0x0) (0x6 0x0 0x0) (0x2 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x10 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x1 0x0 0x0) (0x2 0x50 0x0) (0x2 0x50 0x0) (0x2 0x0 0x0) (0x2 0x0 0x0) (0x30 0x0 0x0) (0x25 0x0 0x0) (0x15 0x0 0x0) (0x7 0x0 0x0) (0x3 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x5 0x50 0x0) (0x3 0x50 0x0))801 : (0 1200 600 200 0 0 0 1000 0 0 100 250 250 200 200 3000 2500 1500 700 300 0 0 0 0 0 0 0 0 550 350)802 : ([:master-ball 0] [:ultra-ball 1200] [:great-ball 600] [:poké-ball 200] [:town-map 0] [:bicycle 0] [:????? 0] [:safari-ball 1000] [:pokédex 0] [:moon-stone 0] [:antidote 100] [:burn-heal 250] [:ice-heal 250] [:awakening 200] [:parlyz-heal 200] [:full-restore 3000] [:max-potion 2500] [:hyper-potion 1500] [:super-potion 700] [:potion 300] [:boulderbadge 0] [:cascadebadge 0] [:thunderbadge 0] [:rainbowbadge 0] [:soulbadge 0] [:marshbadge 0] [:volcanobadge 0] [:earthbadge 0] [:escape-rope 550] [:repel 350])805 ***806 #+name: item-prices807 #+begin_src clojure808 (defn hxc-item-prices809 "The hardcoded list of item prices in memory. List begins at ROM@4495"810 ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))811 ([rom]812 (let [items (hxc-items rom)813 price-size 3]814 (zipmap items815 (map (comp816 ;; zero-cost items are "priceless"817 #(if (zero? %) :priceless %)818 decode-bcd butlast)819 (partition price-size820 (take (* price-size (count items))821 (drop 0x4495 rom))))))))822 #+end_src823 ** Vendor inventories825 #+name: item-vendors826 #+begin_src clojure827 (defn hxc-shops828 ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))829 ([rom]830 (let [items (zipmap (range) (hxc-items rom))832 ;; temporarily softcode the TM items833 items (into834 items835 (map (juxt identity836 (comp keyword837 (partial str "tm-")838 (partial + 1 -200)839 ))840 (take 200 (drop 200 (range)))))842 ]844 ((fn parse-shop [coll [num-items & items-etc]]845 (let [inventory (take-while846 (partial not= 0xFF)847 items-etc)848 [separator & items-etc] (drop num-items (rest items-etc))]849 (if (= separator 0x50)850 (map (partial mapv (comp items dec)) (conj coll inventory))851 (recur (conj coll inventory) items-etc)852 )853 ))855 '()856 (drop 0x233C rom))859 )))860 #+end_src862 #+results: item-vendors863 : #'com.aurellem.gb.hxc/hxc-shops867 * Types868 ** Names of types870 *** COMMENT Pointers to type names871 #+begin_src clojure :exports both :results output872 (map (comp character-codes->str #(take-while (partial not= 80) (drop % (rom))) (partial + 0x20000) (partial apply low-high)) (partition 2 (take 54 (drop 0x27D63 (rom)))))873 #+end_src876 ***877 #+begin_src clojure :exports both :results output878 (ns com.aurellem.gb.hxc879 (:use (com.aurellem.gb assembly characters gb-driver util mem-util880 constants))881 (:import [com.aurellem.gb.gb_driver SaveState]))883 (println (take 90 (drop 0x27D99 (rom))))885 (println886 (partition-by (partial = 0x50)887 (take 90 (drop 0x27D99 (rom)))))889 (println890 (map character-codes->str891 (partition-by (partial = 0x50)892 (take 90 (drop 0x27D99 (rom))))))894 #+end_src896 #+results:897 : (141 142 145 140 128 139 80 133 136 134 135 147 136 141 134 80 133 139 152 136 141 134 80 143 142 136 146 142 141 80 133 136 145 132 80 150 128 147 132 145 80 134 145 128 146 146 80 132 139 132 130 147 145 136 130 80 143 146 152 130 135 136 130 80 136 130 132 80 134 145 142 148 141 131 80 145 142 130 138 80 129 136 145 131 80 129 148 134 80 134)898 : ((141 142 145 140 128 139) (80) (133 136 134 135 147 136 141 134) (80) (133 139 152 136 141 134) (80) (143 142 136 146 142 141) (80) (133 136 145 132) (80) (150 128 147 132 145) (80) (134 145 128 146 146) (80) (132 139 132 130 147 145 136 130) (80) (143 146 152 130 135 136 130) (80) (136 130 132) (80) (134 145 142 148 141 131) (80) (145 142 130 138) (80) (129 136 145 131) (80) (129 148 134) (80) (134))899 : (NORMAL # FIGHTING # FLYING # POISON # FIRE # WATER # GRASS # ELECTRIC # PSYCHIC # ICE # GROUND # ROCK # BIRD # BUG # G)902 ***903 #+name: type-names904 #+begin_src clojure905 (def hxc-types906 "The hardcoded type names in memory. List begins at ROM@27D99,907 shortly before hxc-titles."908 (hxc-thunk-words 0x27D99 102))910 #+end_src912 ** Type effectiveness913 ***914 #+begin_src clojure :exports both :results output915 (ns com.aurellem.gb.hxc916 (:use (com.aurellem.gb assembly characters gb-driver util mem-util917 constants))918 (:import [com.aurellem.gb.gb_driver SaveState]))921 ;; POKEMON TYPES923 (println pkmn-types) ;; these are the pokemon types924 (println (map vector (range) pkmn-types)) ;; each type has an id number.926 (newline)931 ;;; TYPE EFFECTIVENESS933 (println (take 15 (drop 0x3E5FA (rom))))934 (println (partition 3 (take 15 (drop 0x3E5FA (rom)))))936 (println937 (map938 (fn [[atk-type def-type multiplier]]939 (list atk-type def-type (/ multiplier 10.)))941 (partition 3942 (take 15 (drop 0x3E5FA (rom))))))945 (println946 (map947 (fn [[atk-type def-type multiplier]]948 [949 (get pkmn-types atk-type)950 (get pkmn-types def-type)951 (/ multiplier 10.)952 ])954 (partition 3955 (take 15 (drop 0x3E5FA (rom))))))957 #+end_src959 #+results:960 : [:normal :fighting :flying :poison :ground :rock :bird :bug :ghost :A :B :C :D :E :F :G :H :I :J :K :fire :water :grass :electric :psychic :ice :dragon]961 : ([0 :normal] [1 :fighting] [2 :flying] [3 :poison] [4 :ground] [5 :rock] [6 :bird] [7 :bug] [8 :ghost] [9 :A] [10 :B] [11 :C] [12 :D] [13 :E] [14 :F] [15 :G] [16 :H] [17 :I] [18 :J] [19 :K] [20 :fire] [21 :water] [22 :grass] [23 :electric] [24 :psychic] [25 :ice] [26 :dragon])962 :963 : (21 20 20 20 22 20 20 25 20 22 21 20 23 21 20)964 : ((21 20 20) (20 22 20) (20 25 20) (22 21 20) (23 21 20))965 : ((21 20 2.0) (20 22 2.0) (20 25 2.0) (22 21 2.0) (23 21 2.0))966 : ([:water :fire 2.0] [:fire :grass 2.0] [:fire :ice 2.0] [:grass :water 2.0] [:electric :water 2.0])969 ***971 #+name: type-advantage972 #+begin_src clojure973 (defn hxc-advantage974 ;; in-game multipliers are stored as 10x their effective value975 ;; to allow for fractional multipliers like 1/2977 "The hardcoded type advantages in memory, returned as tuples of978 atk-type def-type multiplier. By default (i.e. if not listed here),979 the multiplier is 1. List begins at 0x3E62D."980 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))981 ([rom]982 (map983 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))984 (get pkmn-types def (hex def))985 (/ mult 10)])986 (partition 3987 (take-while (partial not= 0xFF)988 (drop 0x3E5FA rom))))))989 #+end_src994 * Moves995 ** Names of moves996 *** See the data997 #+begin_src clojure :exports both :results output998 (ns com.aurellem.gb.hxc999 (:use (com.aurellem.gb assembly characters gb-driver util mem-util1000 constants))1001 (:import [com.aurellem.gb.gb_driver SaveState]))1003 (println (take 100 (drop 0xBC000 (rom))))1005 (println1006 (partition-by1007 (partial = 0x50)1008 (take 100 (drop 0xBC000 (rom)))))1010 (println1011 (map character-codes->str1012 (partition-by1013 (partial = 0x50)1014 (take 100 (drop 0xBC000 (rom))))))1017 #+end_src1019 #+results:1020 : (143 142 148 141 131 80 138 128 145 128 147 132 127 130 135 142 143 80 131 142 148 129 139 132 146 139 128 143 80 130 142 140 132 147 127 143 148 141 130 135 80 140 132 134 128 127 143 148 141 130 135 80 143 128 152 127 131 128 152 80 133 136 145 132 127 143 148 141 130 135 80 136 130 132 127 143 148 141 130 135 80 147 135 148 141 131 132 145 143 148 141 130 135 80 146 130 145 128 147 130)1021 : ((143 142 148 141 131) (80) (138 128 145 128 147 132 127 130 135 142 143) (80) (131 142 148 129 139 132 146 139 128 143) (80) (130 142 140 132 147 127 143 148 141 130 135) (80) (140 132 134 128 127 143 148 141 130 135) (80) (143 128 152 127 131 128 152) (80) (133 136 145 132 127 143 148 141 130 135) (80) (136 130 132 127 143 148 141 130 135) (80) (147 135 148 141 131 132 145 143 148 141 130 135) (80) (146 130 145 128 147 130))1022 : (POUND # KARATE CHOP # DOUBLESLAP # COMET PUNCH # MEGA PUNCH # PAY DAY # FIRE PUNCH # ICE PUNCH # THUNDERPUNCH # SCRATC)1024 *** Automatically grab the data1026 #+name: move-names1027 #+begin_src clojure1028 (def hxc-move-names1029 "The hardcoded move names in memory. List begins at ROM@BC000"1030 (hxc-thunk-words 0xBC000 1551))1031 #+end_src1033 ** Properties of moves1035 #+name: move-data1036 #+begin_src clojure1037 (defn hxc-move-data1038 "The hardcoded (basic (move effects)) in memory. List begins at1039 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id1040 :fx-txt}. The move descriptions are handwritten, not hardcoded."1041 ([]1042 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))1043 ([rom]1044 (let [names (vec (hxc-move-names rom))1045 move-count (count names)1046 move-size 61047 types pkmn-types ;;; !! hardcoded types1048 ]1049 (zipmap (map format-name names)1050 (map1051 (fn [[idx effect power type-id accuracy pp]]1052 {:name (names (dec idx))1053 :power power1054 :accuracy accuracy1055 :pp pp1056 :type (types type-id)1057 :fx-id effect1058 :fx-txt (get move-effects effect)1059 }1060 )1062 (partition move-size1063 (take (* move-size move-count)1064 (drop 0x38000 rom))))))))1068 (defn hxc-move-data*1069 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."1070 ([]1071 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))1072 ([rom]1073 (let [names (vec (hxc-move-names rom))1074 move-count (count names)1075 move-size 61076 format-name (fn [s]1077 (keyword (.toLowerCase1078 (apply str1079 (map #(if (= % \space) "-" %) s)))))1080 ]1081 (zipmap (map format-name names)1082 (map1083 (fn [[idx effect power type accuracy pp]]1084 {:name (names (dec idx))1085 :power power1086 :accuracy (hex accuracy)1087 :pp pp1088 :fx-id (hex effect)1089 :fx-txt (get move-effects effect)1090 }1091 )1093 (partition move-size1094 (take (* move-size move-count)1095 (drop 0x38000 rom))))))))1097 #+end_src1099 ** TM and HM moves1100 ***1101 #+begin_src clojure :exports both :results output1102 (ns com.aurellem.gb.hxc1103 (:use (com.aurellem.gb assembly characters gb-driver util mem-util1104 constants))1105 (:import [com.aurellem.gb.gb_driver SaveState]))1108 (println (hxc-move-names))1109 (println (map vector (rest(range)) (hxc-move-names)))1111 (newline)1113 (println (take 55 (drop 0x1232D (rom))))1115 (println1116 (interpose "."1117 (map1118 (zipmap (rest (range)) (hxc-move-names))1119 (take 55 (drop 0x1232D (rom))))))1121 #+end_src1123 #+results:1124 : (POUND KARATE CHOP DOUBLESLAP COMET PUNCH MEGA PUNCH PAY DAY FIRE PUNCH ICE PUNCH THUNDERPUNCH SCRATCH VICEGRIP GUILLOTINE RAZOR WIND SWORDS DANCE CUT GUST WING ATTACK WHIRLWIND FLY BIND SLAM VINE WHIP STOMP DOUBLE KICK MEGA KICK JUMP KICK ROLLING KICK SAND-ATTACK HEADBUTT HORN ATTACK FURY ATTACK HORN DRILL TACKLE BODY SLAM WRAP TAKE DOWN THRASH DOUBLE-EDGE TAIL WHIP POISON STING TWINEEDLE PIN MISSILE LEER BITE GROWL ROAR SING SUPERSONIC SONICBOOM DISABLE ACID EMBER FLAMETHROWER MIST WATER GUN HYDRO PUMP SURF ICE BEAM BLIZZARD PSYBEAM BUBBLEBEAM AURORA BEAM HYPER BEAM PECK DRILL PECK SUBMISSION LOW KICK COUNTER SEISMIC TOSS STRENGTH ABSORB MEGA DRAIN LEECH SEED GROWTH RAZOR LEAF SOLARBEAM POISONPOWDER STUN SPORE SLEEP POWDER PETAL DANCE STRING SHOT DRAGON RAGE FIRE SPIN THUNDERSHOCK THUNDERBOLT THUNDER WAVE THUNDER ROCK THROW EARTHQUAKE FISSURE DIG TOXIC CONFUSION PSYCHIC HYPNOSIS MEDITATE AGILITY QUICK ATTACK RAGE TELEPORT NIGHT SHADE MIMIC SCREECH DOUBLE TEAM RECOVER HARDEN MINIMIZE SMOKESCREEN CONFUSE RAY WITHDRAW DEFENSE CURL BARRIER LIGHT SCREEN HAZE REFLECT FOCUS ENERGY BIDE METRONOME MIRROR MOVE SELFDESTRUCT EGG BOMB LICK SMOG SLUDGE BONE CLUB FIRE BLAST WATERFALL CLAMP SWIFT SKULL BASH SPIKE CANNON CONSTRICT AMNESIA KINESIS SOFTBOILED HI JUMP KICK GLARE DREAM EATER POISON GAS BARRAGE LEECH LIFE LOVELY KISS SKY ATTACK TRANSFORM BUBBLE DIZZY PUNCH SPORE FLASH PSYWAVE SPLASH ACID ARMOR CRABHAMMER EXPLOSION FURY SWIPES BONEMERANG REST ROCK SLIDE HYPER FANG SHARPEN CONVERSION TRI ATTACK SUPER FANG SLASH SUBSTITUTE STRUGGLE)1125 : ([1 POUND] [2 KARATE CHOP] [3 DOUBLESLAP] [4 COMET PUNCH] [5 MEGA PUNCH] [6 PAY DAY] [7 FIRE PUNCH] [8 ICE PUNCH] [9 THUNDERPUNCH] [10 SCRATCH] [11 VICEGRIP] [12 GUILLOTINE] [13 RAZOR WIND] [14 SWORDS DANCE] [15 CUT] [16 GUST] [17 WING ATTACK] [18 WHIRLWIND] [19 FLY] [20 BIND] [21 SLAM] [22 VINE WHIP] [23 STOMP] [24 DOUBLE KICK] [25 MEGA KICK] [26 JUMP KICK] [27 ROLLING KICK] [28 SAND-ATTACK] [29 HEADBUTT] [30 HORN ATTACK] [31 FURY ATTACK] [32 HORN DRILL] [33 TACKLE] [34 BODY SLAM] [35 WRAP] [36 TAKE DOWN] [37 THRASH] [38 DOUBLE-EDGE] [39 TAIL WHIP] [40 POISON STING] [41 TWINEEDLE] [42 PIN MISSILE] [43 LEER] [44 BITE] [45 GROWL] [46 ROAR] [47 SING] [48 SUPERSONIC] [49 SONICBOOM] [50 DISABLE] [51 ACID] [52 EMBER] [53 FLAMETHROWER] [54 MIST] [55 WATER GUN] [56 HYDRO PUMP] [57 SURF] [58 ICE BEAM] [59 BLIZZARD] [60 PSYBEAM] [61 BUBBLEBEAM] [62 AURORA BEAM] [63 HYPER BEAM] [64 PECK] [65 DRILL PECK] [66 SUBMISSION] [67 LOW KICK] [68 COUNTER] [69 SEISMIC TOSS] [70 STRENGTH] [71 ABSORB] [72 MEGA DRAIN] [73 LEECH SEED] [74 GROWTH] [75 RAZOR LEAF] [76 SOLARBEAM] [77 POISONPOWDER] [78 STUN SPORE] [79 SLEEP POWDER] [80 PETAL DANCE] [81 STRING SHOT] [82 DRAGON RAGE] [83 FIRE SPIN] [84 THUNDERSHOCK] [85 THUNDERBOLT] [86 THUNDER WAVE] [87 THUNDER] [88 ROCK THROW] [89 EARTHQUAKE] [90 FISSURE] [91 DIG] [92 TOXIC] [93 CONFUSION] [94 PSYCHIC] [95 HYPNOSIS] [96 MEDITATE] [97 AGILITY] [98 QUICK ATTACK] [99 RAGE] [100 TELEPORT] [101 NIGHT SHADE] [102 MIMIC] [103 SCREECH] [104 DOUBLE TEAM] [105 RECOVER] [106 HARDEN] [107 MINIMIZE] [108 SMOKESCREEN] [109 CONFUSE RAY] [110 WITHDRAW] [111 DEFENSE CURL] [112 BARRIER] [113 LIGHT SCREEN] [114 HAZE] [115 REFLECT] [116 FOCUS ENERGY] [117 BIDE] [118 METRONOME] [119 MIRROR MOVE] [120 SELFDESTRUCT] [121 EGG BOMB] [122 LICK] [123 SMOG] [124 SLUDGE] [125 BONE CLUB] [126 FIRE BLAST] [127 WATERFALL] [128 CLAMP] [129 SWIFT] [130 SKULL BASH] [131 SPIKE CANNON] [132 CONSTRICT] [133 AMNESIA] [134 KINESIS] [135 SOFTBOILED] [136 HI JUMP KICK] [137 GLARE] [138 DREAM EATER] [139 POISON GAS] [140 BARRAGE] [141 LEECH LIFE] [142 LOVELY KISS] [143 SKY ATTACK] [144 TRANSFORM] [145 BUBBLE] [146 DIZZY PUNCH] [147 SPORE] [148 FLASH] [149 PSYWAVE] [150 SPLASH] [151 ACID ARMOR] [152 CRABHAMMER] [153 EXPLOSION] [154 FURY SWIPES] [155 BONEMERANG] [156 REST] [157 ROCK SLIDE] [158 HYPER FANG] [159 SHARPEN] [160 CONVERSION] [161 TRI ATTACK] [162 SUPER FANG] [163 SLASH] [164 SUBSTITUTE] [165 STRUGGLE])1126 :1127 : (5 13 14 18 25 92 32 34 36 38 61 55 58 59 63 6 66 68 69 99 72 76 82 85 87 89 90 91 94 100 102 104 115 117 118 120 121 126 129 130 135 138 143 156 86 149 153 157 161 164 15 19 57 70 148)1128 : (MEGA PUNCH . RAZOR WIND . SWORDS DANCE . WHIRLWIND . MEGA KICK . TOXIC . HORN DRILL . BODY SLAM . TAKE DOWN . DOUBLE-EDGE . BUBBLEBEAM . WATER GUN . ICE BEAM . BLIZZARD . HYPER BEAM . PAY DAY . SUBMISSION . COUNTER . SEISMIC TOSS . RAGE . MEGA DRAIN . SOLARBEAM . DRAGON RAGE . THUNDERBOLT . THUNDER . EARTHQUAKE . FISSURE . DIG . PSYCHIC . TELEPORT . MIMIC . DOUBLE TEAM . REFLECT . BIDE . METRONOME . SELFDESTRUCT . EGG BOMB . FIRE BLAST . SWIFT . SKULL BASH . SOFTBOILED . DREAM EATER . SKY ATTACK . REST . THUNDER WAVE . PSYWAVE . EXPLOSION . ROCK SLIDE . TRI ATTACK . SUBSTITUTE . CUT . FLY . SURF . STRENGTH . FLASH)1131 ***1132 #+name: machines1133 #+begin_src clojure1134 (defn hxc-machines1135 "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."1136 ([] (hxc-machines1137 com.aurellem.gb.gb-driver/original-rom))1138 ([rom]1139 (let [moves (hxc-move-names rom)]1140 (zipmap1141 (range)1142 (take-while1143 (comp not nil?)1144 (map (comp1145 format-name1146 (zipmap1147 (range)1148 moves)1149 dec)1150 (take 1001151 (drop 0x1232D rom))))))))1153 #+end_src1159 ** COMMENT Status ailments1162 * NPC Trainers1164 ** Trainer Pok\eacute{}mon1165 # http://hax.iimarck.us/topic/103/1166 There are two formats for specifying lists of NPC PPok\eacute{}mon:1167 - If all the Pok\eacute{}mon will have the same level, the format is1168 - Level (used for all the Pok\eacute{}mon)1169 - Any number of Pok\eacute{}mon internal ids.1170 - 0x00, to indicate end-of-list.1171 - Otherwise, all the Pok\eacute{}mon will have their level1172 specified. The format is1173 - 0xFF, to indicate that we will be specifying the levels individually[fn::Because 0xFF is a1174 forbidden level within the usual gameplay discipline, the game1175 makers could safely use 0xFF as a mode indicator.].1176 - Any number of alternating Level/Pokemon pairs1177 - 0x00, to indicate end-of-list.1179 *** Get the pointers1180 *** See the data1181 #+begin_src clojure :exports both :results output1182 (ns com.aurellem.gb.hxc1183 (:use (com.aurellem.gb assembly characters gb-driver util mem-util1184 constants))1185 (:import [com.aurellem.gb.gb_driver SaveState]))1187 (->>1188 (rom)1189 (drop 0x39E2F)1190 (take 21)1191 (println))1194 (->>1195 (rom)1196 (drop 0x39E2F)1197 (take 21)1198 (partition-by zero?)1199 (take-nth 2)1200 (println))1204 (let1205 [pokenames1206 (zipmap1207 (rest (range))1208 (hxc-pokenames-raw))]1210 (->>1211 (rom)1212 (drop 0x39E2F)1213 (take 21) ;; (1922 in all)1214 (partition-by zero?)1215 (take-nth 2)1216 (map1217 (fn parse-team [[mode & team]]1218 (if (not= 0xFF mode)1219 (mapv1220 #(hash-map :level mode :species (pokenames %))1221 team)1223 (mapv1224 (fn [[lvl id]] (hash-map :level lvl :species (pokenames id)))1225 (partition 2 team)))))1227 (println)))1231 #+end_src1233 #+results:1234 : (11 165 108 0 14 5 0 10 165 165 107 0 14 165 108 107 0 15 165 5 0)1235 : ((11 165 108) (14 5) (10 165 165 107) (14 165 108 107) (15 165 5))1236 : ([{:species RATTATA, :level 11} {:species EKANS, :level 11}] [{:species SPEAROW, :level 14}] [{:species RATTATA, :level 10} {:species RATTATA, :level 10} {:species ZUBAT, :level 10}] [{:species RATTATA, :level 14} {:species EKANS, :level 14} {:species ZUBAT, :level 14}] [{:species RATTATA, :level 15} {:species SPEAROW, :level 15}])1238 * Places1239 ** Names of places1241 #+name: places1242 #+begin_src clojure1243 (def hxc-places1244 "The hardcoded place names in memory. List begins at1245 ROM@71500. [Cinnabar/Celadon] Mansion seems to be dynamically calculated."1246 (hxc-thunk-words 0x71500 560))1247 #+end_src1249 *** See it work1250 #+begin_src clojure :exports both :results output1251 (println (hxc-places))1252 #+end_src1254 #+results:1255 : (PALLET TOWN VIRIDIAN CITY PEWTER CITY CERULEAN CITY LAVENDER TOWN VERMILION CITY CELADON CITY FUCHSIA CITY CINNABAR ISLAND INDIGO PLATEAU SAFFRON CITY ROUTE 1 ROUTE 2 ROUTE 3 ROUTE 4 ROUTE 5 ROUTE 6 ROUTE 7 ROUTE 8 ROUTE 9 ROUTE 10 ROUTE 11 ROUTE 12 ROUTE 13 ROUTE 14 ROUTE 15 ROUTE 16 ROUTE 17 ROUTE 18 SEA ROUTE 19 SEA ROUTE 20 SEA ROUTE 21 ROUTE 22 ROUTE 23 ROUTE 24 ROUTE 25 VIRIDIAN FOREST MT.MOON ROCK TUNNEL SEA COTTAGE S.S.ANNE [POKE]MON LEAGUE UNDERGROUND PATH [POKE]MON TOWER SEAFOAM ISLANDS VICTORY ROAD DIGLETT's CAVE ROCKET HQ SILPH CO. [0x4A] MANSION SAFARI ZONE)1257 ** Wild Pok\eacute{}mon demographics1258 #+name: wilds1259 #+begin_src clojure1261 ;; 0x0489, relative to 0xCB95, points to 0xCD89.1262 (defn hxc-ptrs-wild1263 "A list of the hardcoded wild encounter data in memory. Pointers1264 begin at ROM@0CB95; data begins at ROM@0x0CD89"1265 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))1266 ([rom]1267 (let [ptrs1268 (map (fn [[a b]] (+ a (* 0x100 b)))1269 (take-while (partial not= (list 0xFF 0xFF))1270 (partition 2 (drop 0xCB95 rom))))]1271 ptrs)))1275 (defn hxc-wilds1276 "A list of the hardcoded wild encounter data in memory. Pointers1277 begin at ROM@0CB95; data begins at ROM@0x0CD89"1278 ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))1279 ([rom]1280 (let [pokenames (zipmap (range) (hxc-pokenames rom))]1281 (map1282 (partial map1283 (fn [[a b]]1284 {:species (pokenames (dec b))1285 :level a}))1286 (partition 101287 (take-while1288 (comp (partial not= 1) first)1289 (partition 21290 (drop 0xCD8C rom))1292 ))))))1294 #+end_src1299 ** Map data1301 # http://www.pokecommunity.com/showthread.php?t=2353111302 # http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes1304 #+name map1305 #+begin_src clojure :exports both :results output1306 (ns com.aurellem.gb.hxc1307 (:use (com.aurellem.gb assembly characters gb-driver util mem-util1308 constants))1309 (:import [com.aurellem.gb.gb_driver SaveState]))1312 (defn parse-header-tileset1313 [[bank# ;; memory bank for blocks & tileset1315 blocks-lo ;; structure1316 blocks-hi1318 tileset-lo ;; style1319 tileset-hi1321 collision-lo ;; collision info1322 collision-hi1324 talk-here-1 ;; positions of up to three1325 talk-here-2 ;; talk-over-countertop tiles1326 talk-here-3 ;; --- 0xFF if unused.1328 grass ;; grass tile --- 0xFF if unused1330 animation-flags ;; settings for animation1331 & _]]1333 [bank#1335 blocks-lo ;; structure1336 blocks-hi1338 tileset-lo ;; style1339 tileset-hi1341 collision-lo ;; collision info1342 collision-hi1344 talk-here-1 ;; positions of up to three1345 talk-here-2 ;; talk-over-countertop tiles1346 talk-here-3 ;; --- 0xFF if unused.1348 grass ;; grass tile --- 0xFF if unused1350 animation-flags ;; settings for animation1351 ])1355 (defn parse-header-map1356 [start]1358 (let [connection-size 111360 [tileset-index1361 map-height1362 map-width1363 layout-lo1364 layout-hi1365 text-lo1366 text-hi1367 script-lo1368 script-hi1369 adjacency-flags ;; x x x x N S W E1370 & etc]1371 (drop start (rom))1373 [east? west? south? north?]1374 (bit-list adjacency-flags)1376 [connections object-data]1377 (split-at1378 (* connection-size (+ east? west? south? north?))1379 etc)1381 connections1382 (partition connection-size connections)1387 ]1388 (ptr->offset1389 31390 (low-high layout-lo layout-hi))1393 ))1394 #+end_src1396 #+results:1397 :1401 * Appendices1402 ** Mapping the ROM1403 # D3AD: Script:Use Pokeball?1405 | ROM address (hex) | Description | Format | Example |1406 |-----------------------+-----------------+-----------------+-----------------|1407 | | <15> | <15> | <15> |1408 | 01823-0184A | Important prefix strings. | Variable-length strings, separated by 0x50. | TM#TRAINER#PC#ROCKET#POK\eacute{}#... |1409 | 0233C- | Shop inventories. | | |1410 | 02F47- | (?) Move ids of some HM moves. | One byte per move id | 0x0F 0x13 0x39 0x46 0x94 0xFF, the move ids of CUT, FLY, SURF, STRENGTH, FLASH, then cancel. |1411 | 03E59- | Start of the Give-Pok\eacute{}mon script. | Assembly. When called, converts the contents of register BC into a Pok\eacute{}mon: (B) is the level; (C) is the species. | |1412 | 03E3F- | Start of the give-item script. | Assembly. When called, converts the contents of register BC into an item: (B) is the item type; (C) is the quantity. | |1413 | 04495- | Prices of items. | Each price is two bytes of binary-coded decimal. Prices are separated by zeroes. Priceless items[fn::Like the Pok\eacute{}dex and other unsellable items.] are given a price of zero. | The cost of lemonade is 0x03 0x50, which translates to a price of ₱350. |1414 | 04524-04527 | (unconfirmed) possibly the bike price in Cerulean. | | |1415 | 045B7-0491E | Names of the items in memory. | Variable-length item names (strings of character codes). Names are separated by a single 0x50 character. | MASTER BALL#ULTRA BALL#... |1416 |-----------------------+-----------------+-----------------+-----------------|1417 | 05DD2-05DF2 | Menu text for player info. | | PLAYER [newline] BADGES [nelwine] POK\Eacute{}DEX [newline] TIME [0x50] |1418 | 05EDB. | Which Pok\eacute{}mon to show during Prof. Oak's introduction. | A single byte, the Pok\eacute{}mon's internal id. | In Pok\eacute{}mon Yellow, it shows Pikachu during the introduction; Pikachu's internal id is 0x54. |1419 | 06698- | ? Background music. | | |1420 |-----------------------+-----------------+-----------------+-----------------|1421 | 7550-7570 | Menu options for map directions[fn:unused:According to [[http://tcrf.net/Pok%C3%A9mon_Red_and_Blue#NORTH.2FWEST.2FSOUTH.2FEAST][The Cutting Room Floor]], this data is unused. ]. | Variable-length strings. | NORTH [newline] WEST [0x50] SOUTH [newline] EAST [0x50] NORTH [newline] EAST[0x50] |1422 | 7570-757D | Menu options for trading Pok\eacute{}mon | | TRADE [newline] CANCEL [0x50] |1423 | 757D-758A | Menu options for healing Pok\eacute{}mon | | HEAL [newline] CANCEL [0x50] |1424 | 7635- | Menu options for selected Pok\eacute{}mon (Includes names of out-of-battle moves). | Variable-length strings separated by 0x50. | CUT [0x50] FLY [0x50] SURF [0x50] STRENGTH [0x50] FLASH [0x50] DIG [0x50] TELEPORT [0x50] SOFTBOILED [0x50] STATS [newline] SWITCH [newline] CANCEL [0x50] |1425 | 7AF0-8000 | (empty space) | | 0 0 0 0 0 ... |1426 | 0822E-082F? | Pointers to background music, part I. | | |1427 | 0CB95- | Pointers to lists of wild pokemon to encounter in each region. These lists begin at 04D89, see above. | Each pointer is a low-byte, high-byte pair. | The first entry is 0x89 0x4D, corresponding to the address 0x4D89 relative to this memory bank, i.e. absolute address 0xCD89, the location of the first list of wild Pok\eacute{}mon. (For details on pointer addresses, see the relevant appendix.) |1428 | 0CD89- | Lists of wild Pok\eacute{}mon to encounter in each region. | Lists of 12 bytes. First, an encounter rate[fn::I suspect this is an amount out of 256.]. Next, ten alternating Pok\eacute{}mon/level pairs. Each list ends with 0x00. If the encounter rate is zero, the list ends immediately. | The first nonempty list (located at ROM@0CD8B) is (25; 3 36 4 36 2 165 3 165 2 36 3 36 5 36 4 165 6 36 7 36; 0), i.e. 25 encounter rate; level 3 pidgey, level 4 pidgey, level 2 rattata, level 3 rattata, level 2 pidgey, level 3 pidgey, level 5 pidgey, level 4 rattata, level 6 pidgey, level 7 pidgey, 0 (i.e., end-of-list). |1429 |-----------------------+-----------------+-----------------+-----------------|1430 | 0DACB. | Amount of HP restored by Soda Pop | The HP consists of a single numerical byte. | 60 |1431 | 0DACF. | Amount of HP restored by Lemonade | " | 80 |1432 | 0DAD5. | Amount of HP restored by Fresh Water | " | 50 |1433 | 0DADB. | Amount of HP restored by Hyper Potion. | " | 200 |1434 | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 |1435 | 0DAE3. | Amount of HP restored by Potion. | " | 20 |1436 |-----------------------+-----------------+-----------------+-----------------|1437 | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# |1438 |-----------------------+-----------------+-----------------+-----------------|1439 | 0DE2F. | Duration of Repel. | A single byte, representing the number of steps you can take before the effect wears off. | 100 |1440 | 0DF39. | Duration of Super Repel. | " | 200 |1441 | 0DF3E. | Duration of Max Repel. | " | 250 |1442 |-----------------------+-----------------+-----------------+-----------------|1443 | 1164B- | Terminology for the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | TYPE1[newline]TYPE2[newline] *№*,[newline]OT,[newline][0x50]STATUS,[0x50]OK |1444 | 116DE- | Terminology for permanent stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | ATTACK[newline]DEFENSE[newline]SPEED[newline]SPECIAL[0x50] |1445 | 11852- | Terminology for current stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | EXP POINTS[newline]LEVEL UP[0x50] |1446 | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |1447 | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |1448 |-----------------------+-----------------+-----------------+-----------------|1449 | 11D53. | Which badge is a prerequisite for CUT? | op code: which bit of A to test? | When this script is called, the bits of A contain your badges, and this op code will check a certain bit of A. The op codes for the badges are, in order, [0x47 0x4F 0x57 0x5F 0x67 0x6F 0x77 0x7F]. |1450 | 11D67. | Which badge is a prerequisite for SURF? | " | 0x67 (test for Soul Badge) |1451 | 11DAC. | Which badge is a prerequisite for STRENGTH? | " | 0x5F (test for Rainbow Badge) |1452 |-----------------------+-----------------+-----------------+-----------------|1453 | 1232D-12364 | Which moves are taught by the TMs and HMs | A list of 55 move ids (50 TMs, plus 5 HMs). First, the move that will be taught by TM01; second, the move that will be taught by TM02; and so on. The last five entries are the moves taught by HMs 1-5. (See also, BC000 below) | The first few entries are (5 13 14 18 ...) corresponding to Mega Punch (TM01), Razor Wind (TM02), Swords Dance (TM03), Whirlwind (TM04), ... |1454 |-----------------------+-----------------+-----------------+-----------------|1455 | 1CF8B-1CF8C | Which Pok\eacute{}mon does Melanie give you in Cerulean City? | A level/internal-id pair. | (10 153), corresponding to a level 10 Bulbasaur. |1456 | 1D651-1D652 | Which Pok\eacute{}mon do you find at the top of Celadon Mansion? | A level/internal-id pair. | (25 102), corresponding to a level 25 Eevee. |1457 |-----------------------+-----------------+-----------------+-----------------|1458 | 27D56 & 27D57. | Pointer to the pointers to type names. | A single low-byte, high-byte pair. | 0x63 0x7D, corresponding to location 27D63\mdash{} the start of the next entry. |1459 | 27D63-27D99 | Pointers to type names. | Each point is a low-byte, high-byte pair. The type names follows immediately after this section; see below. | The first pointer is [0x99 0x7D], corresponding to the location 27D99 ("NORMAL"). |1460 | 27D99-27DFF | Names of the Pok\eacute{}mon types. | Variable-length type names (strings of character codes). Names are separated by a single 0x50 character. | NORMAL#FIGHTING#... |1461 | 27DFF-27E77 | ? | 120 bytes of unknown data. | |1462 | 27E77- | Trainer title names. | Variable-length names separated by 0x50. | YOUNGSTER#BUG CATCHER#LASS#... |1463 | 34000- | | | |1464 | 38000-383DE | The basic properties and effects of moves. (165 moves total) | Fixed-length (6 byte) continguous descriptions (no separating character): move-index, move-effect, power, move-type, accuracy, pp. | The entry for Pound, the first attack in the list, is (1 0 40 0 255 35). See below for more explanation. |1465 | 383DE- | Species data for the Pokemon, listed in Pokedex order: Pokedex number; base moves; types; learnable TMs and HMs; base HP, attack, defense, speed, special; sprite data. | | |1466 | 39462- | The Pok\eacute{}mon cry data. | Fixed-length (3 byte) descriptions of cries. | |1467 |-----------------------+-----------------+-----------------+-----------------|1468 | 3997D-39B05 | Trainer titles (extended; see 27E77). This list includes strictly more trainers, seemingly at random inserted into the list from 27E77.[fn::The names added are in bold: YOUNGSTER, BUG CATCHER, LASS, *SAILOR*, JR TRAINER(m), JR TRAINER(f), POK\eacute{}MANIAC, SUPER NERD, *HIKER*, *BIKER*, BURGLAR, ENGINEER, JUGGLER, *FISHERMAN*, SWIMMER, *CUE BALL*, *GAMBLER*, BEAUTY, *PSYCHIC*, ROCKER, JUGGLER (again), *TAMER*, *BIRDKEEPER*, BLACKBELT, *RIVAL1*, PROF OAK, CHIEF, SCIENTIST, *GIOVANNI*, ROCKET, COOLTRAINER(m), COOLTRAINER(f), *BRUNO*, *BROCK*, *MISTY*, *LT. SURGE*, *ERIKA*, *KOGA*, *BLAINE*, *SABRINA*, *GENTLEMAN*, *RIVAL2*, *RIVAL3*, *LORELEI*, *CHANNELER*, *AGATHA*, *LANCE*.] | | |1469 | 39B05-39DD0. | unknown | | |1470 | 39DD1-39E2E | Pointers to trainer Pok\eacute{}mon | Pairs of low-high bits. | The first pair is 0x2F 0x5E, which corresponds to memory location 5E2F relative to this 38000-3C000 bank, i.e.[fn::For details about how relative bank pointers work, see the relevant Appendix.] position 39E2F overall. |1471 | 39E2F-3A5B2 | Trainer Pok\eacute{}mon | Specially-formatted lists of various length, separated by 0x00. If the list starts with 0xFF, the rest of the list will alternate between levels and internal-ids. Otherwise, start of the list is the level of the whole team, and the rest of the list is internal-ids. | The first entry is (11 165 108 0), which means a level 11 team consisting of Rattata and Ekans. The entry for MISTY is (255 18 27 21 152 0), which means a team of various levels consisting of level 18 Staryu and level 21 Starmie. [fn::Incidentally, if you want to change your rival's starter Pok\eacute{}mon, it's enough just to change its species in all of your battles with him.].) |1472 | 3B1E5-3B361 | Pointers to evolution/learnset data. | One high-low byte pair for each of the 190 Pok\eacute{}mon in internal order. | |1473 |-----------------------+-----------------+-----------------+-----------------|1474 | 3B361-3BBAA | *Evolution and learnset data*. [fn::Evolution data consists of how to make Pok\eacute{}mon evolve, and what they evolve into. Learnset data consists of the moves that Pok\eacute{}mon learn as they level up.] | Variable-length evolution information (see below), followed by a list of level/move-id learnset pairs. | |1475 | 3BBAA-3C000 | (empty) | | 0 0 0 0 ... |1476 |-----------------------+-----------------+-----------------+-----------------|1477 | 3D131-3D133 | The inventory of both OLD MAN and PROF. OAK when they battle for you. | Pairs of [item-id quantity], terminated by 0xFF. | (0x04 0x01 0xFF) They only have one Pok\eacute{}ball [fn::If you give them any ball, OAK will catch the enemy Pok\eacute{}mon and OLD MAN will miss. (OLD MAN misses even if he throws a MASTER BALL, which is a sight to see!) If you give them some other item first in the list, you'll be able to use that item normally but then you'll trigger the Safari Zone message: Pa will claim you're out of SAFARI BALLs and the battle will end. If you engage in either an OLD MAN or OAK battle with a Gym Leader, you will [1] get reprimanded if you try to throw a ball [2] incur the Safari Zone message [3] automatically win no matter which item you use [4] earn whichever reward they give you as usual [5] permanently retain the name OLD MAN / PROF. OAK.]. |1478 | 3D6C7-3D6D6 | Two miscellaneous strings. | Variable length, separated by 0x50 | Disabled!#TYPE |1479 | 3E190-3E194 | Which moves have an increased critical-hit ratio? | List of move ids, terminated by 0xFF. | (0x02 0x4B 0x98 0xA3 0xFF) corresponding to karate-chop, razor-leaf, crabhammer, slash, end-of-list. |1480 | 3E200-3E204 | " (???) | " | " |1481 | 3E231. | Besides normal-type, which type of move can COUNTER counter? | A single byte representing a type id. | This is set to 1, the id of the FIGHTING type. |1482 | 3E5FA-3E6F0. | *Type effectiveness* | Triples of bytes: =atk-type=, =def-type=, =multiplier=. The multiplier is stored as 10x its actual value to allow for fractions; so, 20 means 2.0x effective, 5 means 0.5x effective. Unlisted type combinations have 1.0x effectiveness by default. | The first few entries are (21 20 20) (20 22 20) (20 25 20) (22 21 20) (23 21 20), corresponding to [:water :fire 2.0] [:fire :grass 2.0] [:fire :ice 2.0] |1483 |-----------------------+-----------------+-----------------+-----------------|1484 | 40252-4027B | Pok\eacute{}dex menu text | Variable-length strings separated by 0x50. | SEEN#OWN#CONTENTS#... |1485 | 40370-40386 | Important constants for Pok\eacute{}dex entries | | HT _ _ *?′??″* [newline] WT _ _ _ *???* lb [0x50] *POK\Eacute{}* [0x50] |1486 | 40687-41072 | Species data from the Pok\eacute{}dex: species name, height, weight, etc. | Variable-length species names, followed by 0x50, followed by fixed-length height/weight/etc. data. | The first entry is (*146 132 132 131*, 80, *2 4*, *150 0*, 23, 0 64 46, 80), which are the the stats of Bulbasaur: the first entry spells "SEED", then 0x80, then the height (2' 4"), then the weight (formatted as a low-high byte pair), then various Pokédex pointer data (see elsewhere). |1487 | 41072- | Pok\eacute{} placeholder species, "???" | | |1488 |-----------------------+-----------------+-----------------+-----------------|1489 | 410B1-4116F | A conversion table between internal order and Pokedex order. | 190 bytes, corresponding to the Pok\eacute{}dex numbers of the 190 Pok\eacute{}mon listed in internal order. All =MISSINGNO.= are assigned a Pok\eacute{}dex number of 0. | The first few entries are (112 115 32 35 21 100 34 80 2 ...), which are the Pok\eacute{}dex numbers of Rhydon, Kangaskhan, Nidoran(m), Clefairy, Spearow, Voltorb, Nidoking, Slobrow, and Ivysaur. |1490 |-----------------------+-----------------+-----------------+-----------------|1491 | 509B4-509E0 | Saffron City's adjacency info. | Four adjacency lists, each 11 bytes long. (For more info on adjacency lists a.k.a. connection data, see [[http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes][here]]) | The first adjacency list is (0x10 0x70 0x46 0xF0 0xC6 0x0A 0x0A 0x23 0xF6 0x09 0xC8) |1492 |-----------------------+-----------------+-----------------+-----------------|1493 | 515AE-515AF | Which Pok\eacute{}mon does the trainer near Route 25 give you? | A level/internal-id pair. | (10 176) corresponding to a level 10 Charmander. |1494 | 51DD5-51DD6 | Which Pok\eacute{}mon does the Silph Co. trainer give you? | A level/internal-id pair. | (15 19) corresponding to a level 15 Lapras. |1495 |-----------------------+-----------------+-----------------+-----------------|1496 | 527BA-527DB | The costs and kinds of prizes from Celadon Game Corner. | The following pattern repeats three times, once per window[fn::For the first two prize lists, ids are interpreted as Pok\eacute{}mon ids. For the last prize list, ids are (somehow) interpreted as item ids.]: Internal ids / 0x50 / Prices (two bytes of BCD)/ 0x50. | (0x94 0x52 0x65 0x50) Abra Vulpix Wigglytuff (0x02 0x30 0x10 0x00 0x26 0x80) 230C, 1000C, 2680C |1497 | 5DE10-5DE30 | Abbreviations for status ailments. | Fixed-length strings, probably[fn::Here's something strange: all of the status messages start with 0x7F and end with 0x4F \mdash{}except PAR, which ends with 0x50.]. The last entry is QUIT##. | [0x7F] *SLP* [0x4E][0x7F] *PSN* [0x4E][0x7F] *PAR* [0x50][0x7F]... |1498 |-----------------------+-----------------+-----------------+-----------------|1499 | 70295- | Hall of fame | The text "HALL OF FAME" | |1500 | 70442- | Play time/money | The text "PLAY TIME [0x50] MONEY" | |1501 | 71500-7174B | Names of places. | Variable-length place names (strings), separated by 0x50. | PALLET TOWN#VIRIDIAN CITY#PEWTER CITY#CERULEAN CITY#... |1502 | 71C1E-71CAA (approx.) | Tradeable NPC Pok\eacute{}mon. | Internal ID, followed by nickname (11 chars; extra space padded by 0x50). Some of the Pokemon have unknown extra data around the id. | The first entry is [0x76] "GURIO######", corresponding to a Dugtrio named "GURIO". |1503 | 7C249-7C2?? | Pointers to background music, pt II. | | |1504 |-----------------------+-----------------+-----------------+-----------------|1505 | 98000-B7190 | Dialogue and other messsages. | Variable-length strings. | |1506 | B7190-B8000 | (empty space) | | 0 0 0 0 0 ... |1507 | B8000-BC000 | The text of each Pok\eacute{}mon's Pok\eacute{}dex entry. | Variable-length descriptions (strings) in Pok\eacute{}dex order, separated by 0x50. These entries use the special characters *0x49* (new page), *0x4E* (new line), and *0x5F* (end entry). | The first entry (Bulbasaur's) is: "It can go for days [0x4E] without eating a [0x4E] single morsel. [0x49] In the bulb on [0x4E] its back, it [0x4E] stores energy [0x5F] [0x50]." |1508 | BC000-BC60F | Move names. | Variable-length move names, separated by 0x50. The moves are in internal order. | POUND#KARATE CHOP#DOUBLESLAP#COMET PUNCH#... |1509 | BC610-BD000 | (empty space) | | 0 0 0 0 0 ... |1510 | E8000-E876C | Names of the \ldquo{}190\rdquo{} species of Pok\eacute{}mon in memory. | Fixed length (10-letter) Pok\eacute{}mon names. Any extra space is padded with the character 0x50. The names are in \ldquo{}internal order\rdquo{}. | RHYDON####KANGASKHANNIDORAN♂#... |1511 |-----------------------+-----------------+-----------------+-----------------|1512 | E9BD5- | The text PLAY TIME (see above, 70442) | | |1513 | F1A44-F1A45 | Which Pok\eacute{}mon does Officer Jenny give you? | A level/internal-id pair. | (10 177), corresponding to a level 10 Squirtle. |1514 | F21BF-F21C0 | Which Pok\eacute{}mon does the salesman at the Mt. Moon Pok\eacute{}mon center give you? | A level/internal-id pair | (5 133), corresponding to a level 5 Magikarp. |1515 | | | | |1516 #+TBLFM:1518 ** COMMENT1519 Locations where Give Pokemon is used in a nonstraightforward way1520 0x5287C1521 0x5CE231522 0x5C36B1523 0x7562E1525 Find GivePokemon1526 (search-memory* (vec(rom)) [120 234 \_ \_ 121 234 \_ \_ 175 234 \_ \_ 6] 10)1528 F4011 : ASM script for asking if it's oak battle1531 ** Understanding memory banks and pointers1532 #+begin_src clojure1534 (defn endian-flip1535 "Flip the bytes of the two-byte number."1536 [n]1537 (assert (< n 0xFFFF))1538 (+ (* 0x100 (rem n 0x100))1539 (int (/ n 0x100))))1542 (defn offset->ptr1543 "Convert an offset into a little-endian pointer."1544 [n]1545 (->1546 n1547 (rem 0x10000) ;; take last four bytes1548 (rem 0x4000) ;; get relative offset from the start of the bank1549 (+ 0x4000)1550 endian-flip))1552 (defn offset->bank1553 "Get the bank of the offset."1554 [n]1555 (int (/ n 0x4000)))1557 (defn ptr->offset1558 "Convert a two-byte little-endian pointer into an offset."1559 [bank ptr]1560 (->1561 ptr1562 endian-flip1563 (- 0x4000)1564 (+ (* 0x4000 bank))1565 ))1567 (defn same-bank-offset1568 "Convert a ptr into an absolute offset by using the bank of the reference."1569 [reference ptr]1570 (ptr->offset1571 (offset->bank reference)1572 ptr))1573 #+end_src1576 ** Internal Pok\eacute{}mon IDs1577 ** Type IDs1579 #+name: type-ids1580 #+begin_src clojure1581 (def pkmn-types1582 [:normal ;;01583 :fighting ;;11584 :flying ;;21585 :poison ;;31586 :ground ;;41587 :rock ;;51588 :bird ;;61589 :bug ;;71590 :ghost ;;81591 :A1592 :B1593 :C1594 :D1595 :E1596 :F1597 :G1598 :H1599 :I1600 :J1601 :K1602 :fire ;;20 (0x14)1603 :water ;;21 (0x15)1604 :grass ;;22 (0x16)1605 :electric ;;23 (0x17)1606 :psychic ;;24 (0x18)1607 :ice ;;25 (0x19)1608 :dragon ;;26 (0x1A)1609 ])1610 #+end_src1612 ** Basic effects of moves1614 *** Table of basic effects1616 The possible effects of moves in Pok\eacute{}mon \mdash{} for example, dealing1617 damage, leeching health, or potentially poisoning the opponent1618 \mdash{} are stored in a table. Each move has exactly one effect, and1619 different moves might have the same effect.1621 For example, Leech Life, Mega Drain, and Absorb all have effect ID #3, which is \ldquo{}Leech half of the inflicted damage.\rdquo{}1623 All the legitimate move effects are listed in the table1624 below. Here are some notes for reading it:1626 - Whenever an effect has a chance of doing something (like a chance of1627 poisoning the opponent), I list the chance as a hexadecimal amount1628 out of 256; this is to avoid rounding errors. To convert the hex amount into a percentage, divide by 256.1629 - For some effects, the description is too cumbersome to1630 write. Instead, I just write a move name1631 in parentheses, like: (leech seed). That move gives a characteristic example1632 of the effect.1633 - I use the abbreviations =atk=, =def=, =spd=, =spc=, =acr=, =evd= for1634 attack, defense, speed, special, accuracy, and evasiveness.1635 .1639 | ID (hex) | Description | Notes |1640 |----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------|1641 | 0 | normal damage | |1642 | 1 | no damage, just sleep | TODO: find out how many turns |1643 | 2 | 0x4C chance of poison | |1644 | 3 | leech half of inflicted damage | |1645 | 4 | 0x19 chance of burn | |1646 | 5 | 0x19 chance of freeze | |1647 | 6 | 0x19 chance of paralysis | |1648 | 7 | user faints; opponent's defense is halved during attack. | |1649 | 8 | leech half of inflicted damage ONLY if the opponent is asleep | |1650 | 9 | imitate last attack | |1651 | A | user atk +1 | |1652 | B | user def +1 | |1653 | C | user spd +1 | |1654 | D | user spc +1 | |1655 | E | user acr +1 | This effect is unused. |1656 | F | user evd +1 | |1657 | 10 | get post-battle money = 2 * level * uses | |1658 | 11 | move has 0xFE acr, regardless of battle stat modifications. | |1659 | 12 | opponent atk -1 | |1660 | 13 | opponent def -1 | |1661 | 14 | opponent spd -1 | |1662 | 15 | opponent spc -1 | |1663 | 16 | opponent acr -1 | |1664 | 17 | opponent evd -1 | |1665 | 18 | converts user's type to opponent's. | |1666 | 19 | (haze) | |1667 | 1A | (bide) | |1668 | 1B | (thrash) | |1669 | 1C | (teleport) | |1670 | 1D | (fury swipes) | |1671 | 1E | attacks 2-5 turns | Unused. TODO: find out what it does. |1672 | 1F | 0x19 chance of flinching | |1673 | 20 | opponent sleep for 1-7 turns | |1674 | 21 | 0x66 chance of poison | |1675 | 22 | 0x4D chance of burn | |1676 | 23 | 0x4D chance of freeze | |1677 | 24 | 0x4D chance of paralysis | |1678 | 25 | 0x4D chance of flinching | |1679 | 26 | one-hit KO | |1680 | 27 | charge one turn, atk next. | |1681 | 28 | fixed damage, leaves 1HP. | Is the fixed damage the power of the move? |1682 | 29 | fixed damage. | Like seismic toss, dragon rage, psywave. |1683 | 2A | atk 2-5 turns; opponent can't attack | The odds of attacking for /n/ turns are: (0 0x60 0x60 0x20 0x20) |1684 | 2B | charge one turn, atk next. (can't be hit when charging) | |1685 | 2C | atk hits twice. | |1686 | 2D | user takes 1 damage if misses. | |1687 | 2E | evade status-lowering effects | Caused by you or also your opponent? |1688 | 2F | broken: if user is slower than opponent, makes critical hit impossible, otherwise has no effect | This is the effect of Focus Energy. It's (very) broken. |1689 | 30 | atk causes recoil dmg = 1/4 dmg dealt | |1690 | 31 | confuses opponent | |1691 | 32 | user atk +2 | |1692 | 33 | user def +2 | |1693 | 34 | user spd +2 | |1694 | 35 | user spc +2 | |1695 | 36 | user acr +2 | This effect is unused. |1696 | 37 | user evd +2 | This effect is unused. |1697 | 38 | restores up to half of user's max hp. | |1698 | 39 | (transform) | |1699 | 3A | opponent atk -2 | |1700 | 3B | opponent def -2 | |1701 | 3C | opponent spd -2 | |1702 | 3D | opponent spc -2 | |1703 | 3E | opponent acr -2 | |1704 | 3F | opponent evd -2 | |1705 | 40 | doubles user spc when attacked | |1706 | 41 | doubles user def when attacked | |1707 | 42 | just poisons opponent | |1708 | 43 | just paralyzes opponent | |1709 | 44 | 0x19 chance opponent atk -1 | |1710 | 45 | 0x19 chance opponent def -1 | |1711 | 46 | 0x19 chance opponent spd -1 | |1712 | 47 | 0x4C chance opponent spc -1 | |1713 | 48 | 0x19 chance opponent acr -1 | |1714 | 49 | 0x19 chance opponent evd -1 | |1715 | 4A | ??? | ;; unused? no effect? |1716 | 4B | ??? | ;; unused? no effect? |1717 | 4C | 0x19 chance of confusing the opponent | |1718 | 4D | atk hits twice. 0x33 chance opponent poisioned. | |1719 | 4E | broken. crash the game after attack. | |1720 | 4F | (substitute) | |1721 | 50 | unless opponent faints, user must recharge after atk. some exceptions apply | |1722 | 51 | (rage) | |1723 | 52 | (mimic) | |1724 | 53 | (metronome) | |1725 | 54 | (leech seed) | |1726 | 55 | does nothing (splash) | |1727 | 56 | (disable) | |1728 #+end_src1730 *** Source1731 #+name: move-effects1732 #+begin_src clojure1733 (def move-effects1734 ["normal damage"1735 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?1736 "0x4C chance of poison"1737 "leech half of inflicted damage"1738 "0x19 chance of burn"1739 "0x19 chance of freeze"1740 "0x19 chance of paralyze"1741 "user faints; opponent defense halved during attack."1742 "leech half of inflicted damage ONLY if sleeping opponent."1743 "imitate last attack"1744 "user atk +1"1745 "user def +1"1746 "user spd +1"1747 "user spc +1"1748 "user acr +1" ;; unused?!1749 "user evd +1"1750 "get post-battle $ = 2*level*uses"1751 "0xFE acr, no matter what."1752 "opponent atk -1" ;; acr taken from move acr?1753 "opponent def -1" ;;1754 "opponent spd -1" ;;1755 "opponent spc -1" ;;1756 "opponent acr -1";;1757 "opponent evd -1"1758 "converts user's type to opponent's."1759 "(haze)"1760 "(bide)"1761 "(thrash)"1762 "(teleport)"1763 "(fury swipes)"1764 "attacks 2-5 turns" ;; unused? like rollout?1765 "0x19 chance of flinch"1766 "opponent sleep for 1-7 turns"1767 "0x66 chance of poison"1768 "0x4D chance of burn"1769 "0x4D chance of freeze"1770 "0x4D chance of paralyze"1771 "0x4D chance of flinch"1772 "one-hit KO"1773 "charge one turn, atk next."1774 "fixed damage, leaves 1HP." ;; how is dmg determined?1775 "fixed damage." ;; cf seismic toss, dragon rage, psywave.1776 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)1777 "charge one turn, atk next. (can't be hit when charging)"1778 "atk hits twice."1779 "user takes 1 damage if misses."1780 "evade status-lowering effects" ;;caused by you or also your opponent?1781 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"1782 "atk causes recoil dmg = 1/4 dmg dealt"1783 "confuses opponent" ;; acr taken from move acr1784 "user atk +2"1785 "user def +2"1786 "user spd +2"1787 "user spc +2"1788 "user acr +2" ;; unused!1789 "user evd +2" ;; unused!1790 "restores up to half of user's max hp." ;; broken: fails if the difference1791 ;; b/w max and current hp is one less than a multiple of 256.1792 "(transform)"1793 "opponent atk -2"1794 "opponent def -2"1795 "opponent spd -2"1796 "opponent spc -2"1797 "opponent acr -2"1798 "opponent evd -2"1799 "doubles user spc when attacked"1800 "doubles user def when attacked"1801 "just poisons opponent" ;;acr taken from move acr1802 "just paralyzes opponent" ;;1803 "0x19 chance opponent atk -1"1804 "0x19 chance opponent def -1"1805 "0x19 chance opponent spd -1"1806 "0x4C chance opponent spc -1" ;; context suggest chance is 0x191807 "0x19 chance opponent acr -1"1808 "0x19 chance opponent evd -1"1809 "???" ;; unused? no effect?1810 "???" ;; unused? no effect?1811 "0x19 chance opponent confused"1812 "atk hits twice. 0x33 chance opponent poisioned."1813 "broken. crash the game after attack."1814 "(substitute)"1815 "unless opponent faints, user must recharge after atk. some1816 exceptions apply."1817 "(rage)"1818 "(mimic)"1819 "(metronome)"1820 "(leech seed)"1821 "does nothing (splash)"1822 "(disable)"1823 ])1824 #+end_src1827 ** Alphabet code1829 * Source1831 #+begin_src clojure :tangle ../clojure/com/aurellem/gb/hxc.clj1833 (ns com.aurellem.gb.hxc1834 (:use (com.aurellem.gb assembly characters gb-driver util mem-util1835 constants species))1836 (:import [com.aurellem.gb.gb_driver SaveState]))1838 ; ************* HANDWRITTEN CONSTANTS1840 <<type-ids>>1843 ;; question: when status effects claim to take1844 ;; their accuracy from the move accuracy, does1845 ;; this mean that the move always "hits" but the1846 ;; status effect may not?1848 <<move-effects>>1850 ;; ************** HARDCODED DATA1852 <<hxc-thunks>>1853 ;; --------------------------------------------------1855 <<pokenames>>1856 <<type-names>>1858 ;; http://hax.iimarck.us/topic/581/1859 <<pokecry>>1862 <<item-names>>1866 (def hxc-titles1867 "The hardcoded names of the trainer titles in memory. List begins at1868 ROM@27E77"1869 (hxc-thunk-words 0x27E77 196))1872 <<dex-text>>1874 ;; In red/blue, pokedex stats are in internal order.1875 ;; In yellow, pokedex stats are in pokedex order.1876 <<dex-stats>>1881 <<places>>1883 (defn hxc-dialog1884 "The hardcoded dialogue in memory, including in-game alerts. Dialog1885 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."1886 ([rom]1887 (map character-codes->str1888 (take-nth 21889 (partition-by #(= % 0x57)1890 (take 0x0F7281891 (drop 0x98000 rom))))))1892 ([]1893 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))1896 <<move-names>>1897 <<move-data>>1899 <<machines>>1903 (defn internal-id1904 ([rom]1905 (zipmap1906 (hxc-pokenames rom)1907 (range)))1908 ([]1909 (internal-id com.aurellem.gb.gb-driver/original-rom)))1915 ;; nidoran gender change upon levelup1916 ;; (->1917 ;; @current-state1918 ;; rom1919 ;; vec1920 ;; (rewrite-memory1921 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))1922 ;; [1 1 15])1923 ;; (rewrite-memory1924 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))1925 ;; [1 1 3])1926 ;; (write-rom!)1928 ;; )1932 <<type-advantage>>1936 <<evolution-header>>1937 <<evolution>>1938 <<learnsets>>1939 <<pokebase>>1942 (defn hxc-intro-pkmn1943 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's1944 internal id is stored at ROM@5EDB."1945 ([] (hxc-intro-pkmn1946 com.aurellem.gb.gb-driver/original-rom))1947 ([rom]1948 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))1950 (defn sxc-intro-pkmn!1951 "Set the hardcoded pokemon to display in Prof. Oak's introduction."1952 [pokemon]1953 (write-rom!1954 (rewrite-rom 0x5EDB1955 [1956 (inc1957 ((zipmap1958 (hxc-pokenames)1959 (range))1960 pokemon))])))1963 <<item-prices>>1965 <<item-vendors>>1967 <<wilds>>1970 ;; ********************** MANIPULATION FNS1973 (defn same-type1974 ([pkmn move]1975 (same-type1976 com.aurellem.gb.gb-driver/original-rom pkmn move))1977 ([rom pkmn move]1978 (((comp :types (hxc-pokemon-base rom)) pkmn)1979 ((comp :type (hxc-move-data rom)) move))))1984 (defn submap?1985 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."1986 [map-small map-big]1987 (cond (empty? map-small) true1988 (and1989 (contains? map-big (ffirst map-small))1990 (= (get map-big (ffirst map-small))1991 (second (first map-small))))1992 (recur (next map-small) map-big)1994 :else false))1997 (defn search-map [proto-map maps]1998 "Returns all the maps that make the same associations as proto-map."1999 (some (partial submap? proto-map) maps))2001 (defn filter-vals2002 "Returns a map consisting of all the pairs [key val] for2003 which (pred key) returns true."2004 [pred map]2005 (reduce (partial apply assoc) {}2006 (filter (fn [[k v]] (pred v)) map)))2009 (defn search-moves2010 "Returns a subcollection of all hardcoded moves with the2011 given attributes. Attributes consist of :name :power2012 :accuracy :pp :fx-id2013 (and also :fx-txt, but it contains the same information2014 as :fx-id)"2015 ([attribute-map]2016 (search-moves2017 com.aurellem.gb.gb-driver/original-rom attribute-map))2018 ([rom attribute-map]2019 (filter-vals (partial submap? attribute-map)2020 (hxc-move-data rom))))2026 ;; note: 0x2f31 contains the names "TM" "HM"?2028 ;; note for later: credits start at F12902030 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??2032 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)2034 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.2035 ;; The first instance is for Machines; the second, for stones.2037 ;; note: according to2038 ;; http://www.upokecenter.com/games/rby/guides/rgbtrainers.php2039 ;; the amount of money given by a trainer is equal to the2040 ;; base money times the level of the last Pokemon on that trainer's2041 ;; list. Other sources say it's the the level of the last pokemon2042 ;; /defeated/.2044 ;; todo: find base money.2047 ;; note: 0xDFEA (in indexable mem) is the dex# of the currently-viewed Pokemon in2048 ;; in the pokedex. It's used for other purposes if there is none.2050 ;; note: 0x9D35 (index.) switches from 0xFF to 0x00 temporarily when2051 ;; you walk between areas.2053 ;; note: 0xD059 (index.) is the special battle type of your next battle:2054 ;; - 00 is a usual battle2055 ;; - 01 is a pre-scripted OLD MAN battle which always fails to catch the2056 ;; target Pokemon.2057 ;; - 02 is a safari zone battle2058 ;; - 03 obligates you to run away. (unused)2059 ;; - 04 is a pre-scripted OAK battle, which (temporarily) causes the2060 ;; enemy Pokemon to cry PIKAAA, and which always catches the target2061 ;; Pokemon. The target Pokemon is erased after the battle.2062 ;; - 05+ are glitch states in which you are sort of the Pokemon.2065 ;; note: 0x251A (in indexable mem): image decompression routine seems to begin here.2067 ;; note: 0x4845 (index): vending inventory is loaded here. possibly2068 ;; other things, too.2069 (comment2070 ;; temporarily intercept/adjust what pops out of the vending2071 ;; machine.2072 ;; (and how much it costs)2074 ;; located at 0x48452075 ;; not to be confused with shop inventory, 0xCF7B2076 (do2077 (step (read-state "vend-menu"))2078 (write-memory! (rewrite-memory (vec(memory)) 0x4845 [2 0 1 0]))2079 (step @current-state [:a])2080 (step @current-state [])2081 (nstep @current-state 200) ))2084 ;; Note: There are two tile tables, one from 8000-8FFF, the other from2085 ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end.2086 (defn print-pixel-letters!2087 "The pixel tiles representing letters. Neat!"2088 ([] (print-pixel-letters! (read-state "oak-speaks")))2089 ([state]2090 (map2091 (comp2092 println2093 (partial map #(if (zero? %) \space 0))2094 #(if (< (count %) 8)2095 (recur (cons 0 %))2096 %)2097 reverse bit-list)2099 (take 0xFFF (drop 0x8800 (memory state))))))2102 ;; (defn test-2 []2103 ;; (loop [n 02104 ;; pc-1 (pc-trail (-> state-defend (tick) (step [:a]) (step [:a]) (step []) (nstep 100)) 100000)2105 ;; pc-2 (pc-trail (-> state-speed (tick) (step [:a]) (step [:a])2106 ;; (step []) (nstep 100)) 100000)]2107 ;; (cond (empty? (drop n pc-1)) [pc-1 n]2108 ;; (not= (take 10 (drop n pc-1)) (take 10 pc-2))2109 ;; (recur pc-1 pc-2 (inc n))2110 ;; :else2111 ;; [(take 1000 pc-2) n])))2116 (defn test-32117 "Explore trainer data"2118 ([] (test-3 0x3A289))2119 ([start]2120 (let [pokenames (vec(hxc-pokenames-raw))]2121 (println2122 (reduce2123 str2124 (map2125 (fn [[adr lvl pkmn]]2126 (str (format "%-11s %4d %02X %02X \t %05X\n"2128 (cond2129 (zero? lvl) "+"2130 (nil? (get pokenames (dec pkmn)))2131 "-"2132 :else2133 (get pokenames (dec pkmn)))2134 lvl2135 pkmn2136 lvl2137 adr2138 )))2139 (map cons2140 (take-nth 2 (drop start (range)))2141 (partition 22142 (take 400;;7032143 (drop2144 start2145 ;; 0x3A75D2146 (rom)))))))))))2148 (defn search-memory* [mem codes k]2149 (loop [index 02150 index-next 12151 start-match 02152 to-match codes2153 matches []]2154 (cond2155 (>= index (count mem)) matches2157 (empty? to-match)2158 (recur2159 index-next2160 (inc index-next)2161 index-next2162 codes2163 (conj matches2164 [(hex start-match) (take k (drop start-match mem))])2165 )2167 (or (= (first to-match) \_) ;; wildcard2168 (= (first to-match) (nth mem index)))2169 (recur2170 (inc index)2171 index-next2172 start-match2173 (rest to-match)2174 matches)2176 :else2177 (recur2178 index-next2179 (inc index-next)2180 index-next2181 codes2182 matches))))2185 (def script-use-ball2186 [0xFA ;; ld A, nn2187 \_2188 \_2189 0xA7 ;; and A2190 0xCA ;; JP Z2191 \_2192 \_2193 0x3D ;; dec A2194 0xC2 ;; JP NZ2195 \_2196 \_2197 0xFA ;; LD A2198 \_2199 \_2200 ])2204 (defn search-pattern [ptn coll]2205 (loop2206 [index 02207 to-match ptn2208 binds {}2210 next-index 12211 match-start 02212 matches []]2214 (cond2215 (>= index (count coll)) matches2216 (empty? to-match)2217 (recur2218 next-index2219 ptn2220 {}2221 (inc next-index)2222 next-index2223 (conj match-start2224 [(hex match-start) binds]))2226 :else2227 (let [k (first to-match)2228 v (nth coll index)]2229 (cond2230 (= k \_) ;; wildcard2231 (recur2232 (inc index)2233 (rest to-match)2234 binds2236 next-index2237 match-start2238 matches)2240 (keyword? k)2241 (if (binds k)2242 (if (= (binds k) v)2243 (recur2244 (inc index)2245 (rest to-match)2246 binds2247 next-index2248 match-start2249 matches)2251 (recur2252 next-index2253 ptn2254 {}2255 (inc next-index)2256 next-index2257 matches))2259 ;; ;; consistent bindings2260 ;; (recur2261 ;; (inc index)2262 ;; (rest to-match)2263 ;; binds2265 ;; next-index2266 ;; match-start2267 ;; matches)2269 ;; ;; inconsistent bindings2270 ;; (recur2271 ;; next-index2272 ;; ptn2273 ;; {}2274 ;; (inc next-index)2275 ;; next-index2276 ;; matches))2278 (if ((set (vals binds)) v)2279 ;; bindings are not unique2280 (recur2281 next-index2282 ptn2283 {}2284 (inc next-index)2285 next-index2286 matches)2288 ;; bindings are unique2289 (recur2290 (inc index)2291 (rest to-match)2292 (assoc binds k v)2294 next-index2295 match-start2296 matches)))2298 :else ;; k is just a number2299 (if (= k v)2300 (recur2301 (inc index)2302 (rest to-match)2303 binds2305 next-index2306 match-start2307 matches)2309 (recur2310 next-index2311 ptn2312 {}2313 (inc next-index)2314 next-index2315 matches)))))))2325 (defn search-pattern* [ptn coll]2326 (loop2327 [2328 binds {}2329 index 02330 index-next 12331 start-match 02332 to-match ptn2333 matches []]2335 (cond2336 (>= index (count coll)) matches2337 (empty? to-match)2338 (recur2339 {}2340 index-next2341 (inc index-next)2342 index-next2343 ptn2344 (conj matches2345 [(hex start-match) binds]))2347 :else2348 (let [k (first to-match)2349 v (nth coll index)]2350 (cond2351 (= k \_) ;; wildcard2352 (recur2353 binds2354 (inc index)2355 index-next2356 start-match2357 (rest to-match)2358 matches)2360 (keyword? k)2361 (if (binds k)2362 (if (= (binds k) v)2363 (recur2364 binds2365 (inc index)2366 index-next2367 start-match2368 (rest to-match)2369 matches)2370 (recur2371 {}2372 index-next2373 (inc index-next)2374 index-next2375 ptn2376 matches))2377 (if2378 ;; every symbol must be bound to a different thing.2379 ((set (vals binds)) v)2380 (recur2381 {}2382 index-next2383 (inc index-next)2384 index-next2385 ptn2386 matches)2387 (recur2388 (assoc binds k v)2389 (inc index)2390 index-next2391 start-match2392 (rest to-match)2393 matches)))2395 :else2396 (if (= k v)2397 (recur2398 binds2399 (inc index)2400 index-next2401 start-match2402 (rest to-match)2403 matches)2404 (recur2405 {}2406 index-next2407 (inc index-next)2408 index-next2409 ptn2410 matches))2414 )))))2419 ;; look for the rainbow badge in memory2420 (println (reduce str (map #(str (first %) "\t" (vec(second %)) "\n") (search-memory (rom) [221] 10))))2423 (comment2425 (def hxc-later2426 "Running this code produces, e.g. hardcoded names NPCs give2427 their pokemon. Will sort through it later."2428 (print (character-codes->str(take 100002429 (drop 0x715972430 (rom (root)))))))2432 (let [dex2433 (partition-by #(= 0x50 %)2434 (take 25402435 (drop 0x406872436 (rom (root)))))]2437 (def dex dex)2438 (def hxc-species2439 (map character-codes->str2440 (take-nth 4 dex))))2441 )2444 #+end_src2446 #+results:2447 : nil