Mercurial > vba-clojure
view org/rom.org @ 417:0b6624c1291c
made basic tone player.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 16 Apr 2012 14:08:56 -0500 |
parents | 543a78679971 |
children | 4901ba2d3860 |
line wrap: on
line source
1 #+title: Notes on Deconstructing Pokemon Yellow2 #+author: Dylan Holmes3 #+email: rlm@mit.edu4 #+description:5 #+keywords:6 #+SETUPFILE: ../../aurellem/org/setup.org7 #+INCLUDE: ../../aurellem/org/level-0.org8 #+BABEL: :exports both :noweb yes :cache no :mkdirp yes10 # about map headers http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes11 # map headers Yellow http://www.pokecommunity.com/archive/index.php/t-235311.html12 # pokedollar: U+20B113 * Introduction16 ** COMMENT Getting linguistic data: names, words, etc.18 Some of the simplest data21 One of the simplest data structures in the Pok\eacute{} ROM is an22 unbroken list of strings that either (a) all have a specific length,23 or (b) are all separated by the same character.25 Because lots of good data has this format, we'll start by writing a26 template function to extract it:28 #+name: hxc-thunks29 #+begin_src clojure :results silent30 (defn hxc-thunk31 "Creates a thunk (nullary fn) that grabs data in a certain region of rom and32 splits it into a collection by 0x50. If rom is not supplied, uses the33 original rom data."34 [start length]35 (fn self36 ([rom]37 (take-nth 238 (partition-by #(= % 0x50)39 (take length40 (drop start rom)))))41 ([]42 (self com.aurellem.gb.gb-driver/original-rom))))44 (def hxc-thunk-words45 "Same as hxc-thunk, except it interprets the rom data as characters,46 returning a collection of strings."47 (comp48 (partial comp (partial map character-codes->str))49 hxc-thunk))51 #+end_src54 * Pok\eacute{}mon I55 ** Names of each species56 The names of the Pok\eacute{}mon species are stored in57 ROM@E8000. This name list is interesting, for a number of reasons:58 - The names are stored in [[ ][internal order]] rather than in the familiar59 Pok\eacute{}dex order. This seemingly random order probably represents the order in which the authors created or60 programmed in the Pok\eacute{}mon; it's used throughout the game.61 - There is enough space allocated for 190 Pok\eacute{}mon. As I62 understand it, there were originally going to be 190 Pok\eacute{}mon63 in Generation I, but the creators decided to defer some to64 Generation II. This explains why many Gen I and Gen II Pok\eacute{}mon65 have the same aesthetic feel.66 - The list is pockmarked with random gaps, due to the strange internal67 ordering68 and the 39 unused spaces [fn::190 allocated spaces minus 151 true Pok\eacute{}mon]. These missing spaces are filled with the69 placeholder name =MISSINGNO.= (\ldquo{}Missing number\rdquo{}).71 Each name is exactly ten letters long; whenever a name would be too short, the extra72 space is padded with the character 0x50.74 *** See the data76 Here you can see the raw data in three stages: in the first stage, we77 just grab the first few bytes starting from position 0xE8000. In the78 second stage, we partition the bytes into ten-letter chunks to show you79 where the names begin and end. In the final stage, we convert each80 byte into the letter it represents using the =character-codes->str=81 function. (0x50 is rendered as the symbol \ldquo{} =#= \rdquo{} for82 ease of reading).84 #+begin_src clojure :exports both :cache no :results output85 (ns com.aurellem.gb.hxc86 (:use (com.aurellem.gb assembly characters gb-driver util mem-util87 constants))88 (:import [com.aurellem.gb.gb_driver SaveState]))91 (println (take 100 (drop 0xE8000 (rom))))93 (println (partition 10 (take 100 (drop 0xE8000 (rom)))))95 (println (character-codes->str (take 100 (drop 0xE8000 (rom)))))98 #+end_src100 #+results:101 : (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)102 : ((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))103 : RHYDON####KANGASKHANNIDORAN♂##CLEFAIRY##SPEAROW###VOLTORB###NIDOKING##SLOWBRO###IVYSAUR###EXEGGUTOR#106 *** Automatically grab the data.108 #+name: pokenames109 #+begin_src clojure111 (defn hxc-pokenames-raw112 "The hardcoded names of the 190 species in memory. List begins at113 ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters114 long, these names are stripped of padding. See also, hxc-pokedex-names"115 ([]116 (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom))117 ([rom]118 (let [count-species 190119 name-length 10]120 (map character-codes->str121 (partition name-length122 (map #(if (= 0x50 %) 0x00 %)123 (take (* count-species name-length)124 (drop 0xE8000125 rom))))))))126 (def hxc-pokenames127 (comp128 (partial map format-name)129 hxc-pokenames-raw))134 (defn hxc-pokedex-names135 "The names of the pokemon in hardcoded pokedex order. List of the136 pokedex numbers of each pokemon (in internal order) begins at137 ROM@410B1. See also, hxc-pokenames."138 ([] (hxc-pokedex-names139 com.aurellem.gb.gb-driver/original-rom))140 ([rom]141 (let [names (hxc-pokenames rom)]142 (#(mapv %143 ((comp range count keys) %))144 (zipmap145 (take (count names)146 (drop 0x410b1 rom))148 names)))))150 #+end_src154 ** Generic species information156 #+name: pokebase157 #+begin_src clojure158 (defn hxc-pokemon-base159 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))160 ([rom]161 (let [entry-size 28163 pokemon (rest (hxc-pokedex-names))164 pkmn-count (inc(count pokemon))165 types (apply assoc {}166 (interleave167 (range)168 pkmn-types)) ;;!! softcoded169 moves (apply assoc {}170 (interleave171 (range)172 (map format-name173 (hxc-move-names rom))))174 machines (hxc-machines)175 ]176 (zipmap177 pokemon178 (map179 (fn [[n180 rating-hp181 rating-atk182 rating-def183 rating-speed184 rating-special185 type-1186 type-2187 rarity188 rating-xp189 pic-dimensions ;; tile_width|tile_height (8px/tile)190 ptr-pic-obverse-1191 ptr-pic-obverse-2192 ptr-pic-reverse-1193 ptr-pic-reverse-2194 move-1195 move-2196 move-3197 move-4198 growth-rate199 &200 TMs|HMs]]201 (let202 [base-moves203 (mapv moves204 ((comp205 ;; since the game uses zero as a delimiter,206 ;; it must also increment all move indices by 1.207 ;; heren we decrement to correct this.208 (partial map dec)209 (partial take-while (comp not zero?)))210 [move-1 move-2 move-3 move-4]))212 types213 (set (list (types type-1)214 (types type-2)))215 TMs|HMs216 (map217 (comp218 (partial map first)219 (partial remove (comp zero? second)))220 (split-at221 50222 (map vector223 (rest(range))224 (reduce concat225 (map226 #(take 8227 (concat (bit-list %)228 (repeat 0)))230 TMs|HMs)))))232 TMs (vec (first TMs|HMs))233 HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))236 ]239 {:dex# n240 :base-moves base-moves241 :types types242 :TMs TMs243 :HMs HMs244 :base-hp rating-hp245 :base-atk rating-atk246 :base-def rating-def247 :base-speed rating-speed248 :base-special rating-special249 :o0 pic-dimensions250 :o1 ptr-pic-obverse-1251 :o2 ptr-pic-obverse-2252 }))254 (partition entry-size255 (take (* entry-size pkmn-count)256 (drop 0x383DE257 rom))))))))259 #+end_src262 ** Pok\eacute{}mon evolutions263 #+name: evolution-header264 #+begin_src clojure265 (defn format-evo266 "Parse a sequence of evolution data, returning a map. First is the267 method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the268 method of evolution is by item (only stones will actually make pokemon269 evolve, for some auxillary reason.) Finally, the minimum level for270 evolution to occur (level 1 means no limit, which is used for trade271 and item evolutions), followed by the internal id of the pokemon272 into which to evolve. Hence, level up and trade evolutions are273 described with 3274 bytes; item evolutions with four."275 [coll]276 (let [method (first coll)]277 (cond (empty? coll) []278 (= 0 method) [] ;; just in case279 (= 1 method) ;; level-up evolution280 (conj (format-evo (drop 3 coll))281 {:method :level-up282 :min-level (nth coll 1)283 :into (dec (nth coll 2))})285 (= 2 method) ;; item evolution286 (conj (format-evo (drop 4 coll))287 {:method :item288 :item (dec (nth coll 1))289 :min-level (nth coll 2)290 :into (dec (nth coll 3))})292 (= 3 method) ;; trade evolution293 (conj (format-evo (drop 3 coll))294 {:method :trade295 :min-level (nth coll 1) ;; always 1 for trade.296 :into (dec (nth coll 2))}))))299 (defn hxc-ptrs-evolve300 "A hardcoded collection of 190 pointers to alternating evolution/learnset data,301 in internal order."302 ([]303 (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))304 ([rom]305 (let [306 pkmn-count (count (hxc-pokenames-raw)) ;; 190307 ptrs308 (map (fn [[a b]] (low-high a b))309 (partition 2310 (take (* 2 pkmn-count)311 (drop 0x3b1e5 rom))))]312 (map (partial + 0x34000) ptrs)314 )))315 #+end_src317 #+name:evolution318 #+begin_src clojure320 (defn hxc-evolution321 "Hardcoded evolution data in memory. The data exists at ROM@34000,322 sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."323 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))324 ([rom]325 (apply assoc {}326 (interleave327 (hxc-pokenames rom)328 (map329 (comp330 format-evo331 (partial take-while (comp not zero?))332 #(drop % rom))333 (hxc-ptrs-evolve rom)334 )))))336 (defn hxc-evolution-pretty337 "Like hxc-evolution, except it uses the names of items and pokemon338 --- grabbed from ROM --- rather than their numerical identifiers."339 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))340 ([rom]341 (let342 [poke-names (vec (hxc-pokenames rom))343 item-names (vec (hxc-items rom))344 use-names345 (fn [m]346 (loop [ks (keys m) new-map m]347 (let [k (first ks)]348 (cond (nil? ks) new-map349 (= k :into)350 (recur351 (next ks)352 (assoc new-map353 :into354 (poke-names355 (:into356 new-map))))357 (= k :item)358 (recur359 (next ks)360 (assoc new-map361 :item362 (item-names363 (:item new-map))))364 :else365 (recur366 (next ks)367 new-map)368 ))))]370 (into {}371 (map (fn [[pkmn evo-coll]]372 [pkmn (map use-names evo-coll)])373 (hxc-evolution rom))))))376 #+end_src379 ** Level-up moves (learnsets)380 #+name: learnsets381 #+begin_src clojure384 (defn hxc-learnsets385 "Hardcoded map associating pokemon names to lists of pairs [lvl386 move] of abilities they learn as they level up. The data387 exists at ROM@34000, sorted by internal order. Pointers to the data388 exist at ROM@3B1E5; see also, hxc-ptrs-evolve"389 ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))390 ([rom]391 (apply assoc392 {}393 (interleave394 (hxc-pokenames rom)395 (map (comp396 (partial map397 (fn [[lvl mv]] [lvl (dec mv)]))398 (partial partition 2)399 ;; keep the learnset data400 (partial take-while (comp not zero?))401 ;; skip the evolution data402 rest403 (partial drop-while (comp not zero?)))404 (map #(drop % rom)405 (hxc-ptrs-evolve rom)))))))407 (defn hxc-learnsets-pretty408 "Live hxc-learnsets except it reports the name of each move --- as409 it appears in rom --- rather than the move index."410 ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))411 ([rom]412 (let [moves (vec(map format-name (hxc-move-names)))]413 (into {}414 (map (fn [[pkmn learnset]]415 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])416 learnset)])417 (hxc-learnsets rom))))))421 #+end_src425 * Pok\eacute{}mon II : the Pok\eacute{}dex426 ** Species vital stats427 #+name: dex-stats428 #+begin_src clojure429 (defn hxc-pokedex-stats430 "The hardcoded pokedex stats (species height weight) in memory. List431 begins at ROM@40687"432 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))433 ([rom]434 (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom))435 pkmn-count (count pokedex-names)436 ]437 ((fn capture-stats438 [n stats data]439 (if (zero? n) stats440 (let [[species441 [_442 height-ft443 height-in444 weight-1445 weight-2446 _447 dex-ptr-1448 dex-ptr-2449 dex-bank450 _451 & data]]452 (split-with (partial not= 0x50) data)]453 (recur (dec n)454 (assoc stats455 (pokedex-names (- pkmn-count (dec n)))456 {:species457 (format-name (character-codes->str species))458 :height-ft459 height-ft460 :height-in461 height-in462 :weight463 (/ (low-high weight-1 weight-2) 10.)465 ;; :text466 ;; (character-codes->str467 ;; (take-while468 ;; (partial not= 0x50)469 ;; (drop470 ;; (+ 0xB8000471 ;; -0x4000472 ;; (low-high dex-ptr-1 dex-ptr-2))473 ;; rom)))474 })476 data)479 )))481 pkmn-count482 {}483 (drop 0x40687 rom))) ))484 #+end_src486 #+results: dex-stats487 : #'com.aurellem.gb.hxc/hxc-pokedex-stats489 ** Species synopses491 #+name: dex-text492 #+begin_src clojure493 (def hxc-pokedex-text-raw494 "The hardcoded pokedex entries in memory. List begins at495 ROM@B8000, shortly before move names."496 (hxc-thunk-words 0xB8000 14754))501 (defn hxc-pokedex-text502 "The hardcoded pokedex entries in memory, presented as an503 associative hash map. List begins at ROM@B8000."504 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))505 ([rom]506 (zipmap507 (hxc-pokedex-names rom)508 (cons nil ;; for missingno.509 (hxc-pokedex-text-raw rom)))))510 #+end_src513 ** Pok\eacute{}mon cries514 #+name: pokecry515 #+begin_src clojure516 (defn hxc-cry517 "The pokemon cry data in internal order. List begins at ROM@39462"518 ([](hxc-cry com.aurellem.gb.gb-driver/original-rom))519 ([rom]520 (zipmap521 (hxc-pokenames rom)522 (map523 (fn [[cry-id pitch length]]524 {:cry-id cry-id525 :pitch pitch526 :length length}527 )528 (partition 3529 (drop 0x39462 rom))))))531 (defn hxc-cry-groups532 ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom))533 ([rom]534 (map #(mapv first535 (filter536 (fn [[k v]]537 (= % (:cry-id v)))538 (hxc-cry)))539 ((comp540 range541 count542 set543 (partial map :cry-id)544 vals545 hxc-cry)546 rom))))549 (defn cry-conversion!550 "Convert Porygon's cry in ROM to be the cry of the given pokemon."551 [pkmn]552 (write-rom!553 (rewrite-memory554 (vec(rom))555 0x3965D556 (map second557 ((hxc-cry) pkmn)))))559 #+end_src561 ** COMMENT Names of permanent stats562 0DD4D-DD72564 * Items565 ** Item names567 *** See the data568 #+begin_src clojure :exports both :results output569 (ns com.aurellem.gb.hxc570 (:use (com.aurellem.gb assembly characters gb-driver util mem-util571 constants))572 (:import [com.aurellem.gb.gb_driver SaveState]))574 (println (take 100 (drop 0x045B7 (rom))))576 (println577 (partition-by578 (partial = 0x50)579 (take 100 (drop 0x045B7 (rom)))))581 (println582 (map character-codes->str583 (partition-by584 (partial = 0x50)585 (take 100 (drop 0x045B7 (rom))))))588 #+end_src590 #+results:591 : (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)592 : ((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))593 : (MASTER BALL # ULTRA BALL # GREAT BALL # POKé BALL # TOWN MAP # BICYCLE # ????? # SAFARI BALL # POKéDEX # MOON STONE # AN)595 *** Automatically grab the data596 #+name: item-names597 #+begin_src clojure599 (def hxc-items-raw600 "The hardcoded names of the items in memory. List begins at601 ROM@045B7"602 (hxc-thunk-words 0x45B7 870))604 (def hxc-items605 "The hardcoded names of the items in memory, presented as606 keywords. List begins at ROM@045B7. See also, hxc-items-raw."607 (comp (partial map format-name) hxc-items-raw))608 #+end_src610 ** Item prices612 ***613 #+begin_src clojure :exports both :results output614 (ns com.aurellem.gb.hxc615 (:use (com.aurellem.gb assembly characters gb-driver util mem-util616 constants))617 (:import [com.aurellem.gb.gb_driver SaveState]))619 (println (take 90 (drop 0x4495 (rom))))621 (println622 (partition 3623 (take 90 (drop 0x4495 (rom)))))625 (println626 (partition 3627 (map hex628 (take 90 (drop 0x4495 (rom))))))630 (println631 (map decode-bcd632 (map butlast633 (partition 3634 (take 90 (drop 0x4495 (rom)))))))636 (println637 (map638 vector639 (hxc-items (rom))640 (map decode-bcd641 (map butlast642 (partition 3643 (take 90 (drop 0x4495 (rom))))))))649 #+end_src651 #+results:652 : (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)653 : ((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))654 : ((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))655 : (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)656 : ([: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])659 ***660 #+name: item-prices661 #+begin_src clojure662 (defn hxc-item-prices663 "The hardcoded list of item prices in memory. List begins at ROM@4495"664 ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))665 ([rom]666 (let [items (hxc-items rom)667 price-size 3]668 (zipmap items669 (map (comp670 ;; zero-cost items are "priceless"671 #(if (zero? %) :priceless %)672 decode-bcd butlast)673 (partition price-size674 (take (* price-size (count items))675 (drop 0x4495 rom))))))))676 #+end_src677 ** Vendor inventories679 #+name: item-vendors680 #+begin_src clojure681 (defn hxc-shops682 ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))683 ([rom]684 (let [items (zipmap (range) (hxc-items rom))686 ;; temporarily softcode the TM items687 items (into688 items689 (map (juxt identity690 (comp keyword691 (partial str "tm-")692 (partial + 1 -200)693 ))694 (take 200 (drop 200 (range)))))696 ]698 ((fn parse-shop [coll [num-items & items-etc]]699 (let [inventory (take-while700 (partial not= 0xFF)701 items-etc)702 [separator & items-etc] (drop num-items (rest items-etc))]703 (if (= separator 0x50)704 (map (partial mapv (comp items dec)) (conj coll inventory))705 (recur (conj coll inventory) items-etc)706 )707 ))709 '()710 (drop 0x233C rom))713 )))714 #+end_src716 #+results: item-vendors717 : #'com.aurellem.gb.hxc/hxc-shops721 * Types722 ** Names of types724 *** COMMENT Pointers to type names725 #+begin_src clojure :exports both :results output726 (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)))))727 #+end_src730 ***731 #+begin_src clojure :exports both :results output732 (ns com.aurellem.gb.hxc733 (:use (com.aurellem.gb assembly characters gb-driver util mem-util734 constants))735 (:import [com.aurellem.gb.gb_driver SaveState]))737 (println (take 90 (drop 0x27D99 (rom))))739 (println740 (partition-by (partial = 0x50)741 (take 90 (drop 0x27D99 (rom)))))743 (println744 (map character-codes->str745 (partition-by (partial = 0x50)746 (take 90 (drop 0x27D99 (rom))))))748 #+end_src750 #+results:751 : (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)752 : ((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))753 : (NORMAL # FIGHTING # FLYING # POISON # FIRE # WATER # GRASS # ELECTRIC # PSYCHIC # ICE # GROUND # ROCK # BIRD # BUG # G)756 ***757 #+name: type-names758 #+begin_src clojure759 (def hxc-types760 "The hardcoded type names in memory. List begins at ROM@27D99,761 shortly before hxc-titles."762 (hxc-thunk-words 0x27D99 102))764 #+end_src766 ** Type effectiveness767 ***768 #+begin_src clojure :exports both :results output769 (ns com.aurellem.gb.hxc770 (:use (com.aurellem.gb assembly characters gb-driver util mem-util771 constants))772 (:import [com.aurellem.gb.gb_driver SaveState]))775 ;; POKEMON TYPES777 (println pkmn-types) ;; these are the pokemon types778 (println (map vector (range) pkmn-types)) ;; each type has an id number.780 (newline)785 ;;; TYPE EFFECTIVENESS787 (println (take 15 (drop 0x3E62D (rom))))788 (println (partition 3 (take 15 (drop 0x3E62D (rom)))))790 (println791 (map792 (fn [[atk-type def-type multiplier]]793 (list atk-type def-type (/ multiplier 10.)))795 (partition 3796 (take 15 (drop 0x3E62D (rom))))))799 (println800 (map801 (fn [[atk-type def-type multiplier]]802 [803 (get pkmn-types atk-type)804 (get pkmn-types def-type)805 (/ multiplier 10.)806 ])808 (partition 3809 (take 15 (drop 0x3E62D (rom))))))811 #+end_src813 #+results:814 : [: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]815 : ([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])816 :817 : (0 5 5 0 8 0 8 8 20 20 7 20 20 5 5)818 : ((0 5 5) (0 8 0) (8 8 20) (20 7 20) (20 5 5))819 : ((0 5 0.5) (0 8 0.0) (8 8 2.0) (20 7 2.0) (20 5 0.5))820 : ([:normal :rock 0.5] [:normal :ghost 0.0] [:ghost :ghost 2.0] [:fire :bug 2.0] [:fire :rock 0.5])823 ***825 #+name: type-advantage826 #+begin_src clojure827 (defn hxc-advantage828 ;; in-game multipliers are stored as 10x their effective value829 ;; to allow for fractional multipliers like 1/2831 "The hardcoded type advantages in memory, returned as tuples of832 atk-type def-type multiplier. By default (i.e. if not listed here),833 the multiplier is 1. List begins at 0x3E62D."834 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))835 ([rom]836 (map837 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))838 (get pkmn-types def (hex def))839 (/ mult 10)])840 (partition 3841 (take-while (partial not= 0xFF)842 (drop 0x3E62D rom))))))843 #+end_src847 * Moves848 ** Names of moves849 *** See the data850 #+begin_src clojure :exports both :results output851 (ns com.aurellem.gb.hxc852 (:use (com.aurellem.gb assembly characters gb-driver util mem-util853 constants))854 (:import [com.aurellem.gb.gb_driver SaveState]))856 (println (take 100 (drop 0xBC000 (rom))))858 (println859 (partition-by860 (partial = 0x50)861 (take 100 (drop 0xBC000 (rom)))))863 (println864 (map character-codes->str865 (partition-by866 (partial = 0x50)867 (take 100 (drop 0xBC000 (rom))))))870 #+end_src872 #+results:873 : (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)874 : ((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))875 : (POUND # KARATE CHOP # DOUBLESLAP # COMET PUNCH # MEGA PUNCH # PAY DAY # FIRE PUNCH # ICE PUNCH # THUNDERPUNCH # SCRATC)877 *** Automatically grab the data879 #+name: move-names880 #+begin_src clojure881 (def hxc-move-names882 "The hardcoded move names in memory. List begins at ROM@BC000"883 (hxc-thunk-words 0xBC000 1551))884 #+end_src886 ** Properties of moves888 #+name: move-data889 #+begin_src clojure890 (defn hxc-move-data891 "The hardcoded (basic (move effects)) in memory. List begins at892 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id893 :fx-txt}. The move descriptions are handwritten, not hardcoded."894 ([]895 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))896 ([rom]897 (let [names (vec (hxc-move-names rom))898 move-count (count names)899 move-size 6900 types pkmn-types ;;; !! hardcoded types901 ]902 (zipmap (map format-name names)903 (map904 (fn [[idx effect power type-id accuracy pp]]905 {:name (names (dec idx))906 :power power907 :accuracy accuracy908 :pp pp909 :type (types type-id)910 :fx-id effect911 :fx-txt (get move-effects effect)912 }913 )915 (partition move-size916 (take (* move-size move-count)917 (drop 0x38000 rom))))))))921 (defn hxc-move-data*922 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."923 ([]924 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))925 ([rom]926 (let [names (vec (hxc-move-names rom))927 move-count (count names)928 move-size 6929 format-name (fn [s]930 (keyword (.toLowerCase931 (apply str932 (map #(if (= % \space) "-" %) s)))))933 ]934 (zipmap (map format-name names)935 (map936 (fn [[idx effect power type accuracy pp]]937 {:name (names (dec idx))938 :power power939 :accuracy (hex accuracy)940 :pp pp941 :fx-id (hex effect)942 :fx-txt (get move-effects effect)943 }944 )946 (partition move-size947 (take (* move-size move-count)948 (drop 0x38000 rom))))))))950 #+end_src952 ** TM and HM moves953 ***954 #+begin_src clojure :exports both :results output955 (ns com.aurellem.gb.hxc956 (:use (com.aurellem.gb assembly characters gb-driver util mem-util957 constants))958 (:import [com.aurellem.gb.gb_driver SaveState]))961 (println (hxc-move-names))962 (println (map vector (rest(range)) (hxc-move-names)))964 (newline)966 (println (take 55 (drop 0x1232D (rom))))968 (println969 (interpose "."970 (map971 (zipmap (rest (range)) (hxc-move-names))972 (take 55 (drop 0x1232D (rom))))))974 #+end_src976 #+results:977 : (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)978 : ([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])979 :980 : (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)981 : (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)984 ***985 #+name: machines986 #+begin_src clojure987 (defn hxc-machines988 "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."989 ([] (hxc-machines990 com.aurellem.gb.gb-driver/original-rom))991 ([rom]992 (let [moves (hxc-move-names rom)]993 (zipmap994 (range)995 (take-while996 (comp not nil?)997 (map (comp998 format-name999 (zipmap1000 (range)1001 moves)1002 dec)1003 (take 1001004 (drop 0x1232D rom))))))))1006 #+end_src1012 ** COMMENT Status ailments1014 * Places1015 ** Names of places1017 #+name: places1018 #+begin_src clojure1019 (def hxc-places1020 "The hardcoded place names in memory. List begins at1021 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."1022 (hxc-thunk-words 0x71500 560))1024 #+end_src1026 ** Wild Pok\eacute{}mon demographics1027 #+name: wilds1028 #+begin_src clojure1032 (defn hxc-ptrs-wild1033 "A list of the hardcoded wild encounter data in memory. Pointers1034 begin at ROM@0CB95; data begins at ROM@0x04D89"1035 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))1036 ([rom]1037 (let [ptrs1038 (map (fn [[a b]] (+ a (* 0x100 b)))1039 (take-while (partial not= (list 0xFF 0xFF))1040 (partition 2 (drop 0xCB95 rom))))]1041 ptrs)))1045 (defn hxc-wilds1046 "A list of the hardcoded wild encounter data in memory. Pointers1047 begin at ROM@0CB95; data begins at ROM@0x04D89"1048 ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))1049 ([rom]1050 (let [pokenames (zipmap (range) (hxc-pokenames rom))]1051 (map1052 (partial map (fn [[a b]] {:species (pokenames (dec b)) :level1053 a}))1054 (partition 101056 (take-while (comp (partial not= 1)1057 first)1058 (partition 21059 (drop 0xCD8C rom))1061 ))))))1063 #+end_src1069 * Appendices1073 ** Mapping the ROM1075 | ROM address (hex) | Description | Format | Example |1076 |-----------------------+-----------------+-----------------+-----------------|1077 | | <15> | <15> | <15> |1078 | 01823-0184A | Important prefix strings. | Variable-length strings, separated by 0x50. | TM#TRAINER#PC#ROCKET#POK\eacute{}#... |1079 | 0233C- | Shop inventories. | | |1080 | 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. |1081 | 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. |1082 | 04524-04527 | (unconfirmed) possibly the bike price in Cerulean. | | |1083 | 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#... |1084 | 04D89- | Lists of wild Pok\eacute{}mon to encounter in each region. | Each list contains ten Pokemon (ids) and their levels; twenty bytes in total. First, the level of the first Pokemon. Then the internal id of the first Pokemon. Next, the level of the second Pokemon, and so on. Since Pokemon cannot have level 0, the lists are separated by a pair 0 /X/, where /X/ is an apparently random Pokemon id. | The first list is (3 36 4 36 2 165 3 165 2 36 3 36 5 36 4 165 6 36 7 36 0 25), i.e. 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, \ldquo{}level 0 gastly\rdquo{} (i.e., end-of-list). |1085 |-----------------------+-----------------+-----------------+-----------------|1086 | 05DD2-05DF2 | Menu text for player info. | | PLAYER [newline] BADGES [nelwine] POK\Eacute{}DEX [newline] TIME [0x50] |1087 | 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. |1088 | 06698- | ? Background music. | | |1089 | 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] |1090 | 7570-757D | Menu options for trading Pok\eacute{}mon | | TRADE [newline] CANCEL [0x50] |1091 | 757D-758A | Menu options for healing Pok\eacute{}mon | | HEAL [newline] CANCEL [0x50] |1092 | 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] |1093 | 7AF0-8000 | (empty space) | | 0 0 0 0 0 ... |1094 | 0822E-082F? | Pointers to background music, part I. | | |1095 | 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, the location of the first list of wild Pok\eacute{}mon (see 04D89, above). |1096 |-----------------------+-----------------+-----------------+-----------------|1097 | 0DADB. | Amount of HP restored by Hyper Potion. | The HP consists of a single byte. TODO: Discover what the surrounding data does, and find the data for the amount of HP restored by other items: Fresh Water (50HP), Soda (60HP), Lemonade(80HP). | 200 |1098 | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 |1099 | 0DAE3. | Amount of HP restored by Potion. | " | 20 |1100 |-----------------------+-----------------+-----------------+-----------------|1101 | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# |1102 | 1164B- | Terminology for the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | TYPE1[newline]TYPE2[newline] *№*,[newline]OT,[newline][0x50]STATUS,[0x50]OK |1103 | 116DE- | Terminology for permanent stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | ATTACK[newline]DEFENSE[newline]SPEED[newline]SPECIAL[0x50] |1104 | 11852- | Terminology for current stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | EXP POINTS[newline]LEVEL UP[0x50] |1105 | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |1106 | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |1107 | 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), ... |1108 |-----------------------+-----------------+-----------------+-----------------|1109 | 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. |1110 | 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"). |1111 | 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#... |1112 | 27DFF-27E77 | ? | 120 bytes of unknown data. | |1113 | 27E77- | Trainer title names. | Variable-length names separated by 0x50. | YOUNGSTER#BUG CATCHER#LASS#... |1114 | 34000- | | | |1115 | 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. |1116 | 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. | | |1117 | 39462- | The Pok\eacute{}mon cry data. | Fixed-length (3 byte) descriptions of cries. | |1118 |-----------------------+-----------------+-----------------+-----------------|1119 | 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*.] | | |1120 | 39B05-39DD0. | unknown | | |1121 | 39DD1- | (?) Pointers to trainer Pok\eacute{}mon | | |1122 | 3A289-3A540 (approx) | Trainer Pok\eacute{}mon | Consecutive level/internal-id pairs (as with wild Pok\eacute{}mon; see 04D89) with irregular spacing \mdash{} the separators seem to have some metadata purpose. | The first entry is 0x05 0x66, representing level 5 Eevee (from your first battle in the game[fn::Incidentally, to change your rival's starter Pok\eacute{}mon, it's enough just to change its species in all of your battles with him.].) |1123 | 3B1E5-3B361 | Pointers to evolution/learnset data. | One high-low byte pair for each of the 190 Pok\eacute{}mon in internal order. | |1124 |-----------------------+-----------------+-----------------+-----------------|1125 | 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. | |1126 | 3BBAA-3C000 | (empty) | | 0 0 0 0 ... |1127 |-----------------------+-----------------+-----------------+-----------------|1128 | 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.]. |1129 | 3D6C7-3D6D6 | Two miscellaneous strings. | Variable length, separated by 0x50 | Disabled!#TYPE |1130 |-----------------------+-----------------+-----------------+-----------------|1131 | 40252-4027B | Pok\eacute{}dex menu text | Variable-length strings separated by 0x50. | SEEN#OWN#CONTENTS#... |1132 | 40370-40386 | Important constants for Pok\eacute{}dex entries | | HT _ _ *?′??″* [newline] WT _ _ _ *???* lb [0x50] *POK\Eacute{}* [0x50] |1133 | 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). |1134 | 41072- | Pok\eacute{} placeholder species, "???" | | |1135 |-----------------------+-----------------+-----------------+-----------------|1136 | 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. |1137 | 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 |1138 | 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]... |1139 |-----------------------+-----------------+-----------------+-----------------|1140 | 70295- | Hall of fame | The text "HALL OF FAME" | |1141 | 70442- | Play time/money | The text "PLAY TIME [0x50] MONEY" | |1142 | 71500-7174B | Names of places. | Variable-length place names (strings), separated by 0x50. | PALLET TOWN#VIRIDIAN CITY#PEWTER CITY#CERULEAN CITY#... |1143 | 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". |1144 | 7C249-7C2?? | Pointers to background music, pt II. | | |1145 |-----------------------+-----------------+-----------------+-----------------|1146 | 98000-B8000 | Dialogue and other messsages. | Variable-length strings. | |1147 | 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]." |1148 | BC000-BC60E | Move names. | Variable-length move names, separated by 0x50. The moves are in internal order. | POUND#KARATE CHOP#DOUBLESLAP#COMET PUNCH#... |1149 | 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♂#... |1150 |-----------------------+-----------------+-----------------+-----------------|1151 | E9BD5- | The text PLAY TIME (see above, 70442) | | |1152 #+TBLFM:1156 ** Internal Pok\eacute{}mon IDs1157 ** Type IDs1159 #+name: type-ids1160 #+begin_src clojure1161 (def pkmn-types1162 [:normal ;;01163 :fighting ;;11164 :flying ;;21165 :poison ;;31166 :ground ;;41167 :rock ;;51168 :bird ;;61169 :bug ;;71170 :ghost ;;81171 :A1172 :B1173 :C1174 :D1175 :E1176 :F1177 :G1178 :H1179 :I1180 :J1181 :K1182 :fire ;;20 (0x14)1183 :water ;;21 (0x15)1184 :grass ;;22 (0x16)1185 :electric ;;23 (0x17)1186 :psychic ;;24 (0x18)1187 :ice ;;25 (0x19)1188 :dragon ;;26 (0x1A)1189 ])1190 #+end_src1192 ** Basic effects of moves1194 *** Table of basic effects1196 The possible effects of moves in Pok\eacute{}mon \mdash{} for example, dealing1197 damage, leeching health, or potentially poisoning the opponent1198 \mdash{} are stored in a table. Each move has exactly one effect, and1199 different moves might have the same effect.1201 For example, Leech Life, Mega Drain, and Absorb all have effect ID #3, which is \ldquo{}Leech half of the inflicted damage.\rdquo{}1203 All the legitimate move effects are listed in the table1204 below. Here are some notes for reading it:1206 - Whenever an effect has a chance of doing something (like a chance of1207 poisoning the opponent), I list the chance as a hexadecimal amount1208 out of 256; this is to avoid rounding errors. To convert the hex amount into a percentage, divide by 256.1209 - For some effects, the description is too cumbersome to1210 write. Instead, I just write a move name1211 in parentheses, like: (leech seed). That move gives a characteristic example1212 of the effect.1213 - I use the abbreviations =atk=, =def=, =spd=, =spc=, =acr=, =evd= for1214 attack, defense, speed, special, accuracy, and evasiveness.1215 .1219 | ID (hex) | Description | Notes |1220 |----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------|1221 | 0 | normal damage | |1222 | 1 | no damage, just sleep | TODO: find out how many turns |1223 | 2 | 0x4C chance of poison | |1224 | 3 | leech half of inflicted damage | |1225 | 4 | 0x19 chance of burn | |1226 | 5 | 0x19 chance of freeze | |1227 | 6 | 0x19 chance of paralysis | |1228 | 7 | user faints; opponent's defense is halved during attack. | |1229 | 8 | leech half of inflicted damage ONLY if the opponent is asleep | |1230 | 9 | imitate last attack | |1231 | A | user atk +1 | |1232 | B | user def +1 | |1233 | C | user spd +1 | |1234 | D | user spc +1 | |1235 | E | user acr +1 | This effect is unused. |1236 | F | user evd +1 | |1237 | 10 | get post-battle money = 2 * level * uses | |1238 | 11 | move has 0xFE acr, regardless of battle stat modifications. | |1239 | 12 | opponent atk -1 | |1240 | 13 | opponent def -1 | |1241 | 14 | opponent spd -1 | |1242 | 15 | opponent spc -1 | |1243 | 16 | opponent acr -1 | |1244 | 17 | opponent evd -1 | |1245 | 18 | converts user's type to opponent's. | |1246 | 19 | (haze) | |1247 | 1A | (bide) | |1248 | 1B | (thrash) | |1249 | 1C | (teleport) | |1250 | 1D | (fury swipes) | |1251 | 1E | attacks 2-5 turns | Unused. TODO: find out what it does. |1252 | 1F | 0x19 chance of flinching | |1253 | 20 | opponent sleep for 1-7 turns | |1254 | 21 | 0x66 chance of poison | |1255 | 22 | 0x4D chance of burn | |1256 | 23 | 0x4D chance of freeze | |1257 | 24 | 0x4D chance of paralysis | |1258 | 25 | 0x4D chance of flinching | |1259 | 26 | one-hit KO | |1260 | 27 | charge one turn, atk next. | |1261 | 28 | fixed damage, leaves 1HP. | Is the fixed damage the power of the move? |1262 | 29 | fixed damage. | Like seismic toss, dragon rage, psywave. |1263 | 2A | atk 2-5 turns; opponent can't attack | The odds of attacking for /n/ turns are: (0 0x60 0x60 0x20 0x20) |1264 | 2B | charge one turn, atk next. (can't be hit when charging) | |1265 | 2C | atk hits twice. | |1266 | 2D | user takes 1 damage if misses. | |1267 | 2E | evade status-lowering effects | Caused by you or also your opponent? |1268 | 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. |1269 | 30 | atk causes recoil dmg = 1/4 dmg dealt | |1270 | 31 | confuses opponent | |1271 | 32 | user atk +2 | |1272 | 33 | user def +2 | |1273 | 34 | user spd +2 | |1274 | 35 | user spc +2 | |1275 | 36 | user acr +2 | This effect is unused. |1276 | 37 | user evd +2 | This effect is unused. |1277 | 38 | restores up to half of user's max hp. | |1278 | 39 | (transform) | |1279 | 3A | opponent atk -2 | |1280 | 3B | opponent def -2 | |1281 | 3C | opponent spd -2 | |1282 | 3D | opponent spc -2 | |1283 | 3E | opponent acr -2 | |1284 | 3F | opponent evd -2 | |1285 | 40 | doubles user spc when attacked | |1286 | 41 | doubles user def when attacked | |1287 | 42 | just poisons opponent | |1288 | 43 | just paralyzes opponent | |1289 | 44 | 0x19 chance opponent atk -1 | |1290 | 45 | 0x19 chance opponent def -1 | |1291 | 46 | 0x19 chance opponent spd -1 | |1292 | 47 | 0x4C chance opponent spc -1 | |1293 | 48 | 0x19 chance opponent acr -1 | |1294 | 49 | 0x19 chance opponent evd -1 | |1295 | 4A | ??? | ;; unused? no effect? |1296 | 4B | ??? | ;; unused? no effect? |1297 | 4C | 0x19 chance of confusing the opponent | |1298 | 4D | atk hits twice. 0x33 chance opponent poisioned. | |1299 | 4E | broken. crash the game after attack. | |1300 | 4F | (substitute) | |1301 | 50 | unless opponent faints, user must recharge after atk. some exceptions apply | |1302 | 51 | (rage) | |1303 | 52 | (mimic) | |1304 | 53 | (metronome) | |1305 | 54 | (leech seed) | |1306 | 55 | does nothing (splash) | |1307 | 56 | (disable) | |1308 #+end_src1310 *** Source1311 #+name: move-effects1312 #+begin_src clojure1313 (def move-effects1314 ["normal damage"1315 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?1316 "0x4C chance of poison"1317 "leech half of inflicted damage"1318 "0x19 chance of burn"1319 "0x19 chance of freeze"1320 "0x19 chance of paralyze"1321 "user faints; opponent defense halved during attack."1322 "leech half of inflicted damage ONLY if sleeping opponent."1323 "imitate last attack"1324 "user atk +1"1325 "user def +1"1326 "user spd +1"1327 "user spc +1"1328 "user acr +1" ;; unused?!1329 "user evd +1"1330 "get post-battle $ = 2*level*uses"1331 "0xFE acr, no matter what."1332 "opponent atk -1" ;; acr taken from move acr?1333 "opponent def -1" ;;1334 "opponent spd -1" ;;1335 "opponent spc -1" ;;1336 "opponent acr -1";;1337 "opponent evd -1"1338 "converts user's type to opponent's."1339 "(haze)"1340 "(bide)"1341 "(thrash)"1342 "(teleport)"1343 "(fury swipes)"1344 "attacks 2-5 turns" ;; unused? like rollout?1345 "0x19 chance of flinch"1346 "opponent sleep for 1-7 turns"1347 "0x66 chance of poison"1348 "0x4D chance of burn"1349 "0x4D chance of freeze"1350 "0x4D chance of paralyze"1351 "0x4D chance of flinch"1352 "one-hit KO"1353 "charge one turn, atk next."1354 "fixed damage, leaves 1HP." ;; how is dmg determined?1355 "fixed damage." ;; cf seismic toss, dragon rage, psywave.1356 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)1357 "charge one turn, atk next. (can't be hit when charging)"1358 "atk hits twice."1359 "user takes 1 damage if misses."1360 "evade status-lowering effects" ;;caused by you or also your opponent?1361 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"1362 "atk causes recoil dmg = 1/4 dmg dealt"1363 "confuses opponent" ;; acr taken from move acr1364 "user atk +2"1365 "user def +2"1366 "user spd +2"1367 "user spc +2"1368 "user acr +2" ;; unused!1369 "user evd +2" ;; unused!1370 "restores up to half of user's max hp." ;; broken: fails if the difference1371 ;; b/w max and current hp is one less than a multiple of 256.1372 "(transform)"1373 "opponent atk -2"1374 "opponent def -2"1375 "opponent spd -2"1376 "opponent spc -2"1377 "opponent acr -2"1378 "opponent evd -2"1379 "doubles user spc when attacked"1380 "doubles user def when attacked"1381 "just poisons opponent" ;;acr taken from move acr1382 "just paralyzes opponent" ;;1383 "0x19 chance opponent atk -1"1384 "0x19 chance opponent def -1"1385 "0x19 chance opponent spd -1"1386 "0x4C chance opponent spc -1" ;; context suggest chance is 0x191387 "0x19 chance opponent acr -1"1388 "0x19 chance opponent evd -1"1389 "???" ;; unused? no effect?1390 "???" ;; unused? no effect?1391 "0x19 chance opponent confused"1392 "atk hits twice. 0x33 chance opponent poisioned."1393 "broken. crash the game after attack."1394 "(substitute)"1395 "unless opponent faints, user must recharge after atk. some1396 exceptions apply."1397 "(rage)"1398 "(mimic)"1399 "(metronome)"1400 "(leech seed)"1401 "does nothing (splash)"1402 "(disable)"1403 ])1404 #+end_src1407 ** Alphabet code1409 * Source1411 #+begin_src clojure :tangle ../clojure/com/aurellem/gb/hxc.clj1413 (ns com.aurellem.gb.hxc1414 (:use (com.aurellem.gb assembly characters gb-driver util mem-util1415 constants species))1416 (:import [com.aurellem.gb.gb_driver SaveState]))1418 ; ************* HANDWRITTEN CONSTANTS1420 <<type-ids>>1423 ;; question: when status effects claim to take1424 ;; their accuracy from the move accuracy, does1425 ;; this mean that the move always "hits" but the1426 ;; status effect may not?1428 <<move-effects>>1430 ;; ************** HARDCODED DATA1432 <<hxc-thunks>>1433 ;; --------------------------------------------------1435 <<pokenames>>1436 <<type-names>>1438 ;; http://hax.iimarck.us/topic/581/1439 <<pokecry>>1442 <<item-names>>1446 (def hxc-titles1447 "The hardcoded names of the trainer titles in memory. List begins at1448 ROM@27E77"1449 (hxc-thunk-words 0x27E77 196))1452 <<dex-text>>1454 ;; In red/blue, pokedex stats are in internal order.1455 ;; In yellow, pokedex stats are in pokedex order.1456 <<dex-stats>>1461 <<places>>1463 (defn hxc-dialog1464 "The hardcoded dialogue in memory, including in-game alerts. Dialog1465 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."1466 ([rom]1467 (map character-codes->str1468 (take-nth 21469 (partition-by #(= % 0x57)1470 (take 0x0F7281471 (drop 0x98000 rom))))))1472 ([]1473 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))1476 <<move-names>>1477 <<move-data>>1479 <<machines>>1483 (defn internal-id1484 ([rom]1485 (zipmap1486 (hxc-pokenames rom)1487 (range)))1488 ([]1489 (internal-id com.aurellem.gb.gb-driver/original-rom)))1495 ;; nidoran gender change upon levelup1496 ;; (->1497 ;; @current-state1498 ;; rom1499 ;; vec1500 ;; (rewrite-memory1501 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))1502 ;; [1 1 15])1503 ;; (rewrite-memory1504 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))1505 ;; [1 1 3])1506 ;; (write-rom!)1508 ;; )1512 <<type-advantage>>1516 <<evolution-header>>1517 <<evolution>>1518 <<learnsets>>1519 <<pokebase>>1522 (defn hxc-intro-pkmn1523 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's1524 internal id is stored at ROM@5EDB."1525 ([] (hxc-intro-pkmn1526 com.aurellem.gb.gb-driver/original-rom))1527 ([rom]1528 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))1530 (defn sxc-intro-pkmn!1531 "Set the hardcoded pokemon to display in Prof. Oak's introduction."1532 [pokemon]1533 (write-rom!1534 (rewrite-rom 0x5EDB1535 [1536 (inc1537 ((zipmap1538 (hxc-pokenames)1539 (range))1540 pokemon))])))1543 <<item-prices>>1545 <<item-vendors>>1547 <<wilds>>1550 ;; ********************** MANIPULATION FNS1553 (defn same-type1554 ([pkmn move]1555 (same-type1556 com.aurellem.gb.gb-driver/original-rom pkmn move))1557 ([rom pkmn move]1558 (((comp :types (hxc-pokemon-base rom)) pkmn)1559 ((comp :type (hxc-move-data rom)) move))))1564 (defn submap?1565 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."1566 [map-small map-big]1567 (cond (empty? map-small) true1568 (and1569 (contains? map-big (ffirst map-small))1570 (= (get map-big (ffirst map-small))1571 (second (first map-small))))1572 (recur (next map-small) map-big)1574 :else false))1577 (defn search-map [proto-map maps]1578 "Returns all the maps that make the same associations as proto-map."1579 (some (partial submap? proto-map) maps))1581 (defn filter-vals1582 "Returns a map consisting of all the pairs [key val] for1583 which (pred key) returns true."1584 [pred map]1585 (reduce (partial apply assoc) {}1586 (filter (fn [[k v]] (pred v)) map)))1589 (defn search-moves1590 "Returns a subcollection of all hardcoded moves with the1591 given attributes. Attributes consist of :name :power1592 :accuracy :pp :fx-id1593 (and also :fx-txt, but it contains the same information1594 as :fx-id)"1595 ([attribute-map]1596 (search-moves1597 com.aurellem.gb.gb-driver/original-rom attribute-map))1598 ([rom attribute-map]1599 (filter-vals (partial submap? attribute-map)1600 (hxc-move-data rom))))1606 ;; note: 0x2f31 contains the names "TM" "HM"?1608 ;; note for later: credits start at F12901610 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??1612 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)1614 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.1615 ;; The first instance is for Machines; the second, for stones.1617 ;; note: according to1618 ;; http://www.upokecenter.com/games/rby/guides/rgbtrainers.php1619 ;; the amount of money given by a trainer is equal to the1620 ;; base money times the level of the last Pokemon on that trainer's1621 ;; list. Other sources say it's the the level of the last pokemon1622 ;; /defeated/.1624 ;; todo: find base money.1627 ;; note: 0xDFEA (in indexable mem) is the dex# of the currently-viewed Pokemon in1628 ;; in the pokedex. It's used for other purposes if there is none.1630 ;; note: 0x9D35 (index.) switches from 0xFF to 0x00 temporarily when1631 ;; you walk between areas.1633 ;; note: 0xD059 (index.) is the special battle type of your next battle:1634 ;; - 00 is a usual battle1635 ;; - 01 is a pre-scripted OLD MAN battle which always fails to catch the1636 ;; target Pokemon.1637 ;; - 02 is a safari zone battle1638 ;; - 03 obligates you to run away. (unused)1639 ;; - 04 is a pre-scripted OAK battle, which (temporarily) causes the1640 ;; enemy Pokemon to cry PIKAAA, and which always catches the target1641 ;; Pokemon. The target Pokemon is erased after the battle.1642 ;; - 05+ are glitch states in which you are sort of the Pokemon.1645 ;; note: 0x251A (in indexable mem): image decompression routine seems to begin here.1648 ;; Note: There are two tile tables, one from 8000-8FFF, the other from1649 ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end.1650 (defn print-pixel-letters!1651 "The pixel tiles representing letters. Neat!"1652 ([] (print-pixel-letters! (read-state "oak-speaks")))1653 ([state]1654 (map1655 (comp1656 println1657 (partial map #(if (zero? %) \space 0))1658 #(if (< (count %) 8)1659 (recur (cons 0 %))1660 %)1661 reverse bit-list)1663 (take 0xFFF (drop 0x8800 (memory state))))))1666 (defn test-2 []1667 (loop [n 01668 pc-1 (pc-trail (-> state-defend (tick) (step [:a]) (step [:a]) (step []) (nstep 100)) 100000)1669 pc-2 (pc-trail (-> state-speed (tick) (step [:a]) (step [:a])1670 (step []) (nstep 100)) 100000)]1671 (cond (empty? (drop n pc-1)) [pc-1 n]1672 (not= (take 10 (drop n pc-1)) (take 10 pc-2))1673 (recur pc-1 pc-2 (inc n))1674 :else1675 [(take 1000 pc-2) n])))1680 (defn test-31681 "Explore trainer data"1682 []1683 (let [pokenames (vec(hxc-pokenames-raw))]1684 (println1685 (reduce1686 str1687 (map1688 (fn [[lvl pkmn]]1689 (str (format "%-11s %4d %02X %02X"1690 (cond1691 (zero? lvl) "+"1692 (nil? (get pokenames (dec pkmn)))1693 "-"1694 :else1695 (get pokenames (dec pkmn)))1696 lvl1697 pkmn1698 lvl1699 ) "\n"))1701 (partition 21702 (take 100;;7031703 (drop1704 0x3A2811705 ;; 0x3A75D1706 (rom)))))))))1708 (defn search-memory* [mem codes k]1709 (loop [index 01710 index-next 11711 start-match 01712 to-match codes1713 matches []]1714 (cond1715 (>= index (count mem)) matches1717 (empty? to-match)1718 (recur1719 index-next1720 (inc index-next)1721 index-next1722 codes1723 (conj matches1724 [(hex start-match) (take k (drop start-match mem))])1725 )1727 (or (= (first to-match) \_) ;; wildcard1728 (= (first to-match) (nth mem index)))1729 (recur1730 (inc index)1731 index-next1732 start-match1733 (rest to-match)1734 matches)1736 :else1737 (recur1738 index-next1739 (inc index-next)1740 index-next1741 codes1742 matches))))1748 ;; look for the rainbow badge in memory1749 (println (reduce str (map #(str (first %) "\t" (vec(second %)) "\n") (search-memory (rom) [221] 10))))1752 (comment1754 (def hxc-later1755 "Running this code produces, e.g. hardcoded names NPCs give1756 their pokemon. Will sort through it later."1757 (print (character-codes->str(take 100001758 (drop 0x715971759 (rom (root)))))))1761 (let [dex1762 (partition-by #(= 0x50 %)1763 (take 25401764 (drop 0x406871765 (rom (root)))))]1766 (def dex dex)1767 (def hxc-species1768 (map character-codes->str1769 (take-nth 4 dex))))1770 )1773 #+end_src1775 #+results:1776 : nil