Mercurial > vba-clojure
view org/rom.org @ 396:c7a43f4ffd9d
fixed bug where A was always 0 when the self-modigying code was executed.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 13 Apr 2012 04:50:58 -0500 |
parents | a6f212ae29a3 |
children | 8eb674700f15 |
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 begins at136 ROM@410B1. See also, hxc-pokenames."137 ([] (hxc-pokedex-names138 com.aurellem.gb.gb-driver/original-rom))139 ([rom]140 (let [names (hxc-pokenames rom)]141 (#(mapv %142 ((comp range count keys) %))143 (zipmap144 (take (count names)145 (drop 0x410b1 rom))147 names)))))149 #+end_src153 ** Generic species information155 #+name: pokebase156 #+begin_src clojure157 (defn hxc-pokemon-base158 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))159 ([rom]160 (let [entry-size 28162 pokemon (rest (hxc-pokedex-names))163 pkmn-count (inc(count pokemon))164 types (apply assoc {}165 (interleave166 (range)167 pkmn-types)) ;;!! softcoded168 moves (apply assoc {}169 (interleave170 (range)171 (map format-name172 (hxc-move-names rom))))173 machines (hxc-machines)174 ]175 (zipmap176 pokemon177 (map178 (fn [[n179 rating-hp180 rating-atk181 rating-def182 rating-speed183 rating-special184 type-1185 type-2186 rarity187 rating-xp188 pic-dimensions ;; tile_width|tile_height (8px/tile)189 ptr-pic-obverse-1190 ptr-pic-obverse-2191 ptr-pic-reverse-1192 ptr-pic-reverse-2193 move-1194 move-2195 move-3196 move-4197 growth-rate198 &199 TMs|HMs]]200 (let201 [base-moves202 (mapv moves203 ((comp204 ;; since the game uses zero as a delimiter,205 ;; it must also increment all move indices by 1.206 ;; heren we decrement to correct this.207 (partial map dec)208 (partial take-while (comp not zero?)))209 [move-1 move-2 move-3 move-4]))211 types212 (set (list (types type-1)213 (types type-2)))214 TMs|HMs215 (map216 (comp217 (partial map first)218 (partial remove (comp zero? second)))219 (split-at220 50221 (map vector222 (rest(range))223 (reduce concat224 (map225 #(take 8226 (concat (bit-list %)227 (repeat 0)))229 TMs|HMs)))))231 TMs (vec (first TMs|HMs))232 HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))235 ]238 {:dex# n239 :base-moves base-moves240 :types types241 :TMs TMs242 :HMs HMs243 :base-hp rating-hp244 :base-atk rating-atk245 :base-def rating-def246 :base-speed rating-speed247 :base-special rating-special248 :o0 pic-dimensions249 :o1 ptr-pic-obverse-1250 :o2 ptr-pic-obverse-2251 }))253 (partition entry-size254 (take (* entry-size pkmn-count)255 (drop 0x383DE256 rom))))))))258 #+end_src261 ** Pok\eacute{}mon evolutions262 #+name: evolution-header263 #+begin_src clojure264 (defn format-evo265 "Parse a sequence of evolution data, returning a map. First is the266 method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the267 method of evolution is by item (only stones will actually make pokemon268 evolve, for some auxillary reason.) Finally, the minimum level for269 evolution to occur (level 1 means no limit, which is used for trade270 and item evolutions), followed by the internal id of the pokemon271 into which to evolve. Hence, level up and trade evolutions are272 described with 3273 bytes; item evolutions with four."274 [coll]275 (let [method (first coll)]276 (cond (empty? coll) []277 (= 0 method) [] ;; just in case278 (= 1 method) ;; level-up evolution279 (conj (format-evo (drop 3 coll))280 {:method :level-up281 :min-level (nth coll 1)282 :into (dec (nth coll 2))})284 (= 2 method) ;; item evolution285 (conj (format-evo (drop 4 coll))286 {:method :item287 :item (dec (nth coll 1))288 :min-level (nth coll 2)289 :into (dec (nth coll 3))})291 (= 3 method) ;; trade evolution292 (conj (format-evo (drop 3 coll))293 {:method :trade294 :min-level (nth coll 1) ;; always 1 for trade.295 :into (dec (nth coll 2))}))))298 (defn hxc-ptrs-evolve299 "A hardcoded collection of 190 pointers to alternating evolution/learnset data,300 in internal order."301 ([]302 (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))303 ([rom]304 (let [305 pkmn-count (count (hxc-pokenames-raw)) ;; 190306 ptrs307 (map (fn [[a b]] (low-high a b))308 (partition 2309 (take (* 2 pkmn-count)310 (drop 0x3b1e5 rom))))]311 (map (partial + 0x34000) ptrs)313 )))314 #+end_src316 #+name:evolution317 #+begin_src clojure319 (defn hxc-evolution320 "Hardcoded evolution data in memory. The data exists at ROM@34000,321 sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."322 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))323 ([rom]324 (apply assoc {}325 (interleave326 (hxc-pokenames rom)327 (map328 (comp329 format-evo330 (partial take-while (comp not zero?))331 #(drop % rom))332 (hxc-ptrs-evolve rom)333 )))))335 (defn hxc-evolution-pretty336 "Like hxc-evolution, except it uses the names of items and pokemon337 --- grabbed from ROM --- rather than their numerical identifiers."338 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))339 ([rom]340 (let341 [poke-names (vec (hxc-pokenames rom))342 item-names (vec (hxc-items rom))343 use-names344 (fn [m]345 (loop [ks (keys m) new-map m]346 (let [k (first ks)]347 (cond (nil? ks) new-map348 (= k :into)349 (recur350 (next ks)351 (assoc new-map352 :into353 (poke-names354 (:into355 new-map))))356 (= k :item)357 (recur358 (next ks)359 (assoc new-map360 :item361 (item-names362 (:item new-map))))363 :else364 (recur365 (next ks)366 new-map)367 ))))]369 (into {}370 (map (fn [[pkmn evo-coll]]371 [pkmn (map use-names evo-coll)])372 (hxc-evolution rom))))))375 #+end_src378 ** Level-up moves (learnsets)379 #+name: learnsets380 #+begin_src clojure383 (defn hxc-learnsets384 "Hardcoded map associating pokemon names to lists of pairs [lvl385 move] of abilities they learn as they level up. The data386 exists at ROM@34000, sorted by internal order. Pointers to the data387 exist at ROM@3B1E5; see also, hxc-ptrs-evolve"388 ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))389 ([rom]390 (apply assoc391 {}392 (interleave393 (hxc-pokenames rom)394 (map (comp395 (partial map396 (fn [[lvl mv]] [lvl (dec mv)]))397 (partial partition 2)398 ;; keep the learnset data399 (partial take-while (comp not zero?))400 ;; skip the evolution data401 rest402 (partial drop-while (comp not zero?)))403 (map #(drop % rom)404 (hxc-ptrs-evolve rom)))))))406 (defn hxc-learnsets-pretty407 "Live hxc-learnsets except it reports the name of each move --- as408 it appears in rom --- rather than the move index."409 ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))410 ([rom]411 (let [moves (vec(map format-name (hxc-move-names)))]412 (into {}413 (map (fn [[pkmn learnset]]414 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])415 learnset)])416 (hxc-learnsets rom))))))420 #+end_src424 * Pok\eacute{}mon II : the Pok\eacute{}dex425 ** Species vital stats426 #+name: dex-stats427 #+begin_src clojure428 (defn hxc-pokedex-stats429 "The hardcoded pokedex stats (species height weight) in memory. List430 begins at ROM@40687"431 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))432 ([rom]433 (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom))434 pkmn-count (count pokedex-names)435 ]436 ((fn capture-stats437 [n stats data]438 (if (zero? n) stats439 (let [[species440 [_441 height-ft442 height-in443 weight-1444 weight-2445 _446 dex-ptr-1447 dex-ptr-2448 dex-bank449 _450 & data]]451 (split-with (partial not= 0x50) data)]452 (recur (dec n)453 (assoc stats454 (pokedex-names (- pkmn-count (dec n)))455 {:species456 (format-name (character-codes->str species))457 :height-ft458 height-ft459 :height-in460 height-in461 :weight462 (/ (low-high weight-1 weight-2) 10.)464 ;; :text465 ;; (character-codes->str466 ;; (take-while467 ;; (partial not= 0x50)468 ;; (drop469 ;; (+ 0xB8000470 ;; -0x4000471 ;; (low-high dex-ptr-1 dex-ptr-2))472 ;; rom)))473 })475 data)478 )))480 pkmn-count481 {}482 (drop 0x40687 rom))) ))483 #+end_src485 ** Species synopses487 #+name: dex-text488 #+begin_src clojure489 (def hxc-pokedex-text-raw490 "The hardcoded pokedex entries in memory. List begins at491 ROM@B8000, shortly before move names."492 (hxc-thunk-words 0xB8000 14754))497 (defn hxc-pokedex-text498 "The hardcoded pokedex entries in memory, presented as an499 associative hash map. List begins at ROM@B8000."500 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))501 ([rom]502 (zipmap503 (hxc-pokedex-names rom)504 (cons nil ;; for missingno.505 (hxc-pokedex-text-raw rom)))))506 #+end_src509 ** Pok\eacute{}mon cries510 #+name: pokecry511 #+begin_src clojure512 (defn hxc-cry513 "The pokemon cry data in internal order. List begins at ROM@39462"514 ([](hxc-cry com.aurellem.gb.gb-driver/original-rom))515 ([rom]516 (zipmap517 (hxc-pokenames rom)518 (map519 (fn [[cry-id pitch length]]520 {:cry-id cry-id521 :pitch pitch522 :length length}523 )524 (partition 3525 (drop 0x39462 rom))))))527 (defn hxc-cry-groups528 ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom))529 ([rom]530 (map #(mapv first531 (filter532 (fn [[k v]]533 (= % (:cry-id v)))534 (hxc-cry)))535 ((comp536 range537 count538 set539 (partial map :cry-id)540 vals541 hxc-cry)542 rom))))545 (defn cry-conversion!546 "Convert Porygon's cry in ROM to be the cry of the given pokemon."547 [pkmn]548 (write-rom!549 (rewrite-memory550 (vec(rom))551 0x3965D552 (map second553 ((hxc-cry) pkmn)))))555 #+end_src557 ** COMMENT Names of permanent stats558 0DD4D-DD72560 * Items561 ** Item names563 *** See the data564 #+begin_src clojure :exports both :results output565 (ns com.aurellem.gb.hxc566 (:use (com.aurellem.gb assembly characters gb-driver util mem-util567 constants))568 (:import [com.aurellem.gb.gb_driver SaveState]))570 (println (take 100 (drop 0x045B7 (rom))))572 (println573 (partition-by574 (partial = 0x50)575 (take 100 (drop 0x045B7 (rom)))))577 (println578 (map character-codes->str579 (partition-by580 (partial = 0x50)581 (take 100 (drop 0x045B7 (rom))))))584 #+end_src586 #+results:587 : (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)588 : ((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))589 : (MASTER BALL # ULTRA BALL # GREAT BALL # POKé BALL # TOWN MAP # BICYCLE # ????? # SAFARI BALL # POKéDEX # MOON STONE # AN)591 *** Automatically grab the data592 #+name: item-names593 #+begin_src clojure595 (def hxc-items-raw596 "The hardcoded names of the items in memory. List begins at597 ROM@045B7"598 (hxc-thunk-words 0x45B7 870))600 (def hxc-items601 "The hardcoded names of the items in memory, presented as602 keywords. List begins at ROM@045B7. See also, hxc-items-raw."603 (comp (partial map format-name) hxc-items-raw))604 #+end_src606 ** Item prices608 ***609 #+begin_src clojure :exports both :results output610 (ns com.aurellem.gb.hxc611 (:use (com.aurellem.gb assembly characters gb-driver util mem-util612 constants))613 (:import [com.aurellem.gb.gb_driver SaveState]))615 (println (take 90 (drop 0x4495 (rom))))617 (println618 (partition 3619 (take 90 (drop 0x4495 (rom)))))621 (println622 (partition 3623 (map hex624 (take 90 (drop 0x4495 (rom))))))626 (println627 (map decode-bcd628 (map butlast629 (partition 3630 (take 90 (drop 0x4495 (rom)))))))632 (println633 (map634 vector635 (hxc-items (rom))636 (map decode-bcd637 (map butlast638 (partition 3639 (take 90 (drop 0x4495 (rom))))))))645 #+end_src647 #+results:648 : (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)649 : ((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))650 : ((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))651 : (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)652 : ([: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])655 ***656 #+name: item-prices657 #+begin_src clojure658 (defn hxc-item-prices659 "The hardcoded list of item prices in memory. List begins at ROM@4495"660 ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))661 ([rom]662 (let [items (hxc-items rom)663 price-size 3]664 (zipmap items665 (map (comp666 ;; zero-cost items are "priceless"667 #(if (zero? %) :priceless %)668 decode-bcd butlast)669 (partition price-size670 (take (* price-size (count items))671 (drop 0x4495 rom))))))))672 #+end_src673 ** Vendor inventories675 #+name: item-vendors676 #+begin_src clojure677 (defn hxc-shops678 ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))679 ([rom]680 (let [items (zipmap (range) (hxc-items rom))682 ;; temporarily softcode the TM items683 items (into684 items685 (map (juxt identity686 (comp keyword687 (partial str "tm-")688 (partial + 1 -200)689 ))690 (take 200 (drop 200 (range)))))692 ]694 ((fn parse-shop [coll [num-items & items-etc]]695 (let [inventory (take-while696 (partial not= 0xFF)697 items-etc)698 [separator & items-etc] (drop num-items (rest items-etc))]699 (if (= separator 0x50)700 (map (partial mapv (comp items dec)) (conj coll inventory))701 (recur (conj coll inventory) items-etc)702 )703 ))705 '()706 (drop 0x233C rom))709 )))710 #+end_src712 #+results: item-vendors713 : #'com.aurellem.gb.hxc/hxc-shops717 * Types718 ** Names of types719 ***720 #+begin_src clojure :exports both :results output721 (ns com.aurellem.gb.hxc722 (:use (com.aurellem.gb assembly characters gb-driver util mem-util723 constants))724 (:import [com.aurellem.gb.gb_driver SaveState]))726 (println (take 90 (drop 0x27D99 (rom))))728 (println729 (partition-by (partial = 0x50)730 (take 90 (drop 0x27D99 (rom)))))732 (println733 (map character-codes->str734 (partition-by (partial = 0x50)735 (take 90 (drop 0x27D99 (rom))))))737 #+end_src739 #+results:740 : (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)741 : ((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))742 : (NORMAL # FIGHTING # FLYING # POISON # FIRE # WATER # GRASS # ELECTRIC # PSYCHIC # ICE # GROUND # ROCK # BIRD # BUG # G)745 ***746 #+name: type-names747 #+begin_src clojure748 (def hxc-types749 "The hardcoded type names in memory. List begins at ROM@27D99,750 shortly before hxc-titles."751 (hxc-thunk-words 0x27D99 102))753 #+end_src755 ** Type effectiveness756 ***757 #+begin_src clojure :exports both :results output758 (ns com.aurellem.gb.hxc759 (:use (com.aurellem.gb assembly characters gb-driver util mem-util760 constants))761 (:import [com.aurellem.gb.gb_driver SaveState]))764 ;; POKEMON TYPES766 (println pkmn-types) ;; these are the pokemon types767 (println (map vector (range) pkmn-types)) ;; each type has an id number.769 (newline)774 ;;; TYPE EFFECTIVENESS776 (println (take 15 (drop 0x3E62D (rom))))777 (println (partition 3 (take 15 (drop 0x3E62D (rom)))))779 (println780 (map781 (fn [[atk-type def-type multiplier]]782 (list atk-type def-type (/ multiplier 10.)))784 (partition 3785 (take 15 (drop 0x3E62D (rom))))))788 (println789 (map790 (fn [[atk-type def-type multiplier]]791 [792 (get pkmn-types atk-type)793 (get pkmn-types def-type)794 (/ multiplier 10.)795 ])797 (partition 3798 (take 15 (drop 0x3E62D (rom))))))800 #+end_src802 #+results:803 : [: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]804 : ([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])805 :806 : (0 5 5 0 8 0 8 8 20 20 7 20 20 5 5)807 : ((0 5 5) (0 8 0) (8 8 20) (20 7 20) (20 5 5))808 : ((0 5 0.5) (0 8 0.0) (8 8 2.0) (20 7 2.0) (20 5 0.5))809 : ([:normal :rock 0.5] [:normal :ghost 0.0] [:ghost :ghost 2.0] [:fire :bug 2.0] [:fire :rock 0.5])812 ***814 #+name: type-advantage815 #+begin_src clojure816 (defn hxc-advantage817 ;; in-game multipliers are stored as 10x their effective value818 ;; to allow for fractional multipliers like 1/2820 "The hardcoded type advantages in memory, returned as tuples of821 atk-type def-type multiplier. By default (i.e. if not listed here),822 the multiplier is 1. List begins at 0x3E62D."823 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))824 ([rom]825 (map826 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))827 (get pkmn-types def (hex def))828 (/ mult 10)])829 (partition 3830 (take-while (partial not= 0xFF)831 (drop 0x3E62D rom))))))832 #+end_src836 * Moves837 ** Names of moves838 *** See the data839 #+begin_src clojure :exports both :results output840 (ns com.aurellem.gb.hxc841 (:use (com.aurellem.gb assembly characters gb-driver util mem-util842 constants))843 (:import [com.aurellem.gb.gb_driver SaveState]))845 (println (take 100 (drop 0xBC000 (rom))))847 (println848 (partition-by849 (partial = 0x50)850 (take 100 (drop 0xBC000 (rom)))))852 (println853 (map character-codes->str854 (partition-by855 (partial = 0x50)856 (take 100 (drop 0xBC000 (rom))))))859 #+end_src861 #+results:862 : (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)863 : ((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))864 : (POUND # KARATE CHOP # DOUBLESLAP # COMET PUNCH # MEGA PUNCH # PAY DAY # FIRE PUNCH # ICE PUNCH # THUNDERPUNCH # SCRATC)866 *** Automatically grab the data868 #+name: move-names869 #+begin_src clojure870 (def hxc-move-names871 "The hardcoded move names in memory. List begins at ROM@BC000"872 (hxc-thunk-words 0xBC000 1551))873 #+end_src875 ** Properties of moves877 #+name: move-data878 #+begin_src clojure879 (defn hxc-move-data880 "The hardcoded (basic (move effects)) in memory. List begins at881 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id882 :fx-txt}. The move descriptions are handwritten, not hardcoded."883 ([]884 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))885 ([rom]886 (let [names (vec (hxc-move-names rom))887 move-count (count names)888 move-size 6889 types pkmn-types ;;; !! hardcoded types890 ]891 (zipmap (map format-name names)892 (map893 (fn [[idx effect power type-id accuracy pp]]894 {:name (names (dec idx))895 :power power896 :accuracy accuracy897 :pp pp898 :type (types type-id)899 :fx-id effect900 :fx-txt (get move-effects effect)901 }902 )904 (partition move-size905 (take (* move-size move-count)906 (drop 0x38000 rom))))))))910 (defn hxc-move-data*911 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."912 ([]913 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))914 ([rom]915 (let [names (vec (hxc-move-names rom))916 move-count (count names)917 move-size 6918 format-name (fn [s]919 (keyword (.toLowerCase920 (apply str921 (map #(if (= % \space) "-" %) s)))))922 ]923 (zipmap (map format-name names)924 (map925 (fn [[idx effect power type accuracy pp]]926 {:name (names (dec idx))927 :power power928 :accuracy (hex accuracy)929 :pp pp930 :fx-id (hex effect)931 :fx-txt (get move-effects effect)932 }933 )935 (partition move-size936 (take (* move-size move-count)937 (drop 0x38000 rom))))))))939 #+end_src941 ** TM and HM moves942 ***943 #+begin_src clojure :exports both :results output944 (ns com.aurellem.gb.hxc945 (:use (com.aurellem.gb assembly characters gb-driver util mem-util946 constants))947 (:import [com.aurellem.gb.gb_driver SaveState]))950 (println (hxc-move-names))951 (println (map vector (rest(range)) (hxc-move-names)))953 (newline)955 (println (take 55 (drop 0x1232D (rom))))957 (println958 (interpose "."959 (map960 (zipmap (rest (range)) (hxc-move-names))961 (take 55 (drop 0x1232D (rom))))))963 #+end_src965 #+results:966 : (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)967 : ([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])968 :969 : (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)970 : (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)973 ***974 #+name: machines975 #+begin_src clojure976 (defn hxc-machines977 "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."978 ([] (hxc-machines979 com.aurellem.gb.gb-driver/original-rom))980 ([rom]981 (let [moves (hxc-move-names rom)]982 (zipmap983 (range)984 (take-while985 (comp not nil?)986 (map (comp987 format-name988 (zipmap989 (range)990 moves)991 dec)992 (take 100993 (drop 0x1232D rom))))))))995 #+end_src1001 ** COMMENT Status ailments1003 * Places1004 ** Names of places1006 #+name: places1007 #+begin_src clojure1008 (def hxc-places1009 "The hardcoded place names in memory. List begins at1010 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."1011 (hxc-thunk-words 0x71500 560))1013 #+end_src1015 ** Wild Pok\eacute{}mon demographics1016 #+name: wilds1017 #+begin_src clojure1021 (defn hxc-ptrs-wild1022 "A list of the hardcoded wild encounter data in memory. Pointers1023 begin at ROM@0CB95; data begins at ROM@0x04D89"1024 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))1025 ([rom]1026 (let [ptrs1027 (map (fn [[a b]] (+ a (* 0x100 b)))1028 (take-while (partial not= (list 0xFF 0xFF))1029 (partition 2 (drop 0xCB95 rom))))]1030 ptrs)))1034 (defn hxc-wilds1035 "A list of the hardcoded wild encounter data in memory. Pointers1036 begin at ROM@0CB95; data begins at ROM@0x04D89"1037 ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))1038 ([rom]1039 (let [pokenames (zipmap (range) (hxc-pokenames rom))]1040 (map1041 (partial map (fn [[a b]] {:species (pokenames (dec b)) :level1042 a}))1043 (partition 101045 (take-while (comp (partial not= 1)1046 first)1047 (partition 21048 (drop 0xCD8C rom))1050 ))))))1052 #+end_src1058 * Appendices1062 ** Mapping the ROM1064 | ROM address (hex) | Description | Format | Example |1065 |-------------------+-----------------+-----------------+-----------------|1066 | | <15> | <15> | <15> |1067 | 0233C- | Shop inventories. | | |1068 | 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. |1069 | 045B7-0491E | Names of the items in memory. | Variable-length item names (strings of character codes). Names are separated by a single 0x80 character. | MASTER BALL#ULTRA BALL#... |1070 | 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). |1071 | 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. |1072 | 06698- | ? Background music. | | |1073 | 0822E-082F? | Pointers to background music, part I. | | |1074 | 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). |1075 |-------------------+-----------------+-----------------+-----------------|1076 | 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 |1077 | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 |1078 | 0DAE3. | Amount of HP restored by Potion. | " | 20 |1079 |-------------------+-----------------+-----------------+-----------------|1080 | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# |1081 | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |1082 | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |1083 | 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), ... |1084 | 27D99-27DFF | Names of the Pok\eacute{}mon types. | Variable-length type names (strings of character codes). Names are separated by a single 0x80 character. | NORMAL#FIGHTING#... |1085 | 27E77- | Trainer title names. | Variable-length names separated by 0x80. | YOUNGSTER#BUG CATCHER#LASS#... |1086 | 34000- | | | |1087 | 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. |1088 | 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. | | |1089 | 39462- | The Pok\eacute{}mon cry data. | Fixed-length (3 byte) descriptions of cries. | |1090 | 3B1E5- | Pointers to evolution/learnset data. | | |1091 | 3B361- | 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. | |1092 | 40687- | Species data from the Pok\eacute{}dex: species name, height, weight, etc. | Fixed-length sequences of bytes. See below for specifics. | |1093 | 410B1- | A conversion table between internal order and Pokedex order. | | |1094 | 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]... |1095 | 71500- | Names of places. | | |1096 | 7C249-7C2?? | Pointers to background music, pt II. | | |1097 | 98000- | Dialogue | | |1098 | B8000- | The text of each Pokemon's Pok\eacute{}dex entry. | | |1099 | BC000-BC60E | Move names. | Variable-length move names, separated by 0x80. The moves are in internal order. | POUND#KARATE CHOP#DOUBLESLAP#COMET PUNCH#... |1100 | 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 0x80. The names are in \ldquo{}internal order\rdquo{}. | RHYDON####KANGASKHANNIDORAN♂#... |1101 | | | | |1102 | | | | |1106 ** Internal Pok\eacute{}mon IDs1107 ** Type IDs1109 #+name: type-ids1110 #+begin_src clojure1111 (def pkmn-types1112 [:normal ;;01113 :fighting ;;11114 :flying ;;21115 :poison ;;31116 :ground ;;41117 :rock ;;51118 :bird ;;61119 :bug ;;71120 :ghost ;;81121 :A1122 :B1123 :C1124 :D1125 :E1126 :F1127 :G1128 :H1129 :I1130 :J1131 :K1132 :fire ;;20 (0x14)1133 :water ;;21 (0x15)1134 :grass ;;22 (0x16)1135 :electric ;;23 (0x17)1136 :psychic ;;24 (0x18)1137 :ice ;;25 (0x19)1138 :dragon ;;26 (0x1A)1139 ])1140 #+end_src1142 ** Basic effects of moves1144 *** Table of basic effects1146 The possible effects of moves in Pok\eacute{}mon \mdash{} for example, dealing1147 damage, leeching health, or potentially poisoning the opponent1148 \mdash{} are stored in a table. Each move has exactly one effect, and1149 different moves might have the same effect.1151 For example, Leech Life, Mega Drain, and Absorb all have effect ID #3, which is \ldquo{}Leech half of the inflicted damage.\rdquo{}1153 All the legitimate move effects are listed in the table1154 below. Here are some notes for reading it:1156 - Whenever an effect has a chance of doing something (like a chance of1157 poisoning the opponent), I list the chance as a hexadecimal amount1158 out of 256; this is to avoid rounding errors. To convert the hex amount into a percentage, divide by 256.1159 - For some effects, the description is too cumbersome to1160 write. Instead, I just write a move name1161 in parentheses, like: (leech seed). That move gives a characteristic example1162 of the effect.1163 - I use the abbreviations =atk=, =def=, =spd=, =spc=, =acr=, =evd= for1164 attack, defense, speed, special, accuracy, and evasiveness.1165 .1169 | ID (hex) | Description | Notes |1170 |----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------|1171 | 0 | normal damage | |1172 | 1 | no damage, just sleep | TODO: find out how many turns |1173 | 2 | 0x4C chance of poison | |1174 | 3 | leech half of inflicted damage | |1175 | 4 | 0x19 chance of burn | |1176 | 5 | 0x19 chance of freeze | |1177 | 6 | 0x19 chance of paralysis | |1178 | 7 | user faints; opponent's defense is halved during attack. | |1179 | 8 | leech half of inflicted damage ONLY if the opponent is asleep | |1180 | 9 | imitate last attack | |1181 | A | user atk +1 | |1182 | B | user def +1 | |1183 | C | user spd +1 | |1184 | D | user spc +1 | |1185 | E | user acr +1 | This effect is unused. |1186 | F | user evd +1 | |1187 | 10 | get post-battle money = 2 * level * uses | |1188 | 11 | move has 0xFE acr, regardless of battle stat modifications. | |1189 | 12 | opponent atk -1 | |1190 | 13 | opponent def -1 | |1191 | 14 | opponent spd -1 | |1192 | 15 | opponent spc -1 | |1193 | 16 | opponent acr -1 | |1194 | 17 | opponent evd -1 | |1195 | 18 | converts user's type to opponent's. | |1196 | 19 | (haze) | |1197 | 1A | (bide) | |1198 | 1B | (thrash) | |1199 | 1C | (teleport) | |1200 | 1D | (fury swipes) | |1201 | 1E | attacks 2-5 turns | Unused. TODO: find out what it does. |1202 | 1F | 0x19 chance of flinching | |1203 | 20 | opponent sleep for 1-7 turns | |1204 | 21 | 0x66 chance of poison | |1205 | 22 | 0x4D chance of burn | |1206 | 23 | 0x4D chance of freeze | |1207 | 24 | 0x4D chance of paralysis | |1208 | 25 | 0x4D chance of flinching | |1209 | 26 | one-hit KO | |1210 | 27 | charge one turn, atk next. | |1211 | 28 | fixed damage, leaves 1HP. | Is the fixed damage the power of the move? |1212 | 29 | fixed damage. | Like seismic toss, dragon rage, psywave. |1213 | 2A | atk 2-5 turns; opponent can't attack | The odds of attacking for /n/ turns are: (0 0x60 0x60 0x20 0x20) |1214 | 2B | charge one turn, atk next. (can't be hit when charging) | |1215 | 2C | atk hits twice. | |1216 | 2D | user takes 1 damage if misses. | |1217 | 2E | evade status-lowering effects | Caused by you or also your opponent? |1218 | 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. |1219 | 30 | atk causes recoil dmg = 1/4 dmg dealt | |1220 | 31 | confuses opponent | |1221 | 32 | user atk +2 | |1222 | 33 | user def +2 | |1223 | 34 | user spd +2 | |1224 | 35 | user spc +2 | |1225 | 36 | user acr +2 | This effect is unused. |1226 | 37 | user evd +2 | This effect is unused. |1227 | 38 | restores up to half of user's max hp. | |1228 | 39 | (transform) | |1229 | 3A | opponent atk -2 | |1230 | 3B | opponent def -2 | |1231 | 3C | opponent spd -2 | |1232 | 3D | opponent spc -2 | |1233 | 3E | opponent acr -2 | |1234 | 3F | opponent evd -2 | |1235 | 40 | doubles user spc when attacked | |1236 | 41 | doubles user def when attacked | |1237 | 42 | just poisons opponent | |1238 | 43 | just paralyzes opponent | |1239 | 44 | 0x19 chance opponent atk -1 | |1240 | 45 | 0x19 chance opponent def -1 | |1241 | 46 | 0x19 chance opponent spd -1 | |1242 | 47 | 0x4C chance opponent spc -1 | |1243 | 48 | 0x19 chance opponent acr -1 | |1244 | 49 | 0x19 chance opponent evd -1 | |1245 | 4A | ??? | ;; unused? no effect? |1246 | 4B | ??? | ;; unused? no effect? |1247 | 4C | 0x19 chance of confusing the opponent | |1248 | 4D | atk hits twice. 0x33 chance opponent poisioned. | |1249 | 4E | broken. crash the game after attack. | |1250 | 4F | (substitute) | |1251 | 50 | unless opponent faints, user must recharge after atk. some exceptions apply | |1252 | 51 | (rage) | |1253 | 52 | (mimic) | |1254 | 53 | (metronome) | |1255 | 54 | (leech seed) | |1256 | 55 | does nothing (splash) | |1257 | 56 | (disable) | |1258 #+end_src1260 *** Source1261 #+name: move-effects1262 #+begin_src clojure1263 (def move-effects1264 ["normal damage"1265 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?1266 "0x4C chance of poison"1267 "leech half of inflicted damage"1268 "0x19 chance of burn"1269 "0x19 chance of freeze"1270 "0x19 chance of paralyze"1271 "user faints; opponent defense halved during attack."1272 "leech half of inflicted damage ONLY if sleeping opponent."1273 "imitate last attack"1274 "user atk +1"1275 "user def +1"1276 "user spd +1"1277 "user spc +1"1278 "user acr +1" ;; unused?!1279 "user evd +1"1280 "get post-battle $ = 2*level*uses"1281 "0xFE acr, no matter what."1282 "opponent atk -1" ;; acr taken from move acr?1283 "opponent def -1" ;;1284 "opponent spd -1" ;;1285 "opponent spc -1" ;;1286 "opponent acr -1";;1287 "opponent evd -1"1288 "converts user's type to opponent's."1289 "(haze)"1290 "(bide)"1291 "(thrash)"1292 "(teleport)"1293 "(fury swipes)"1294 "attacks 2-5 turns" ;; unused? like rollout?1295 "0x19 chance of flinch"1296 "opponent sleep for 1-7 turns"1297 "0x66 chance of poison"1298 "0x4D chance of burn"1299 "0x4D chance of freeze"1300 "0x4D chance of paralyze"1301 "0x4D chance of flinch"1302 "one-hit KO"1303 "charge one turn, atk next."1304 "fixed damage, leaves 1HP." ;; how is dmg determined?1305 "fixed damage." ;; cf seismic toss, dragon rage, psywave.1306 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)1307 "charge one turn, atk next. (can't be hit when charging)"1308 "atk hits twice."1309 "user takes 1 damage if misses."1310 "evade status-lowering effects" ;;caused by you or also your opponent?1311 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"1312 "atk causes recoil dmg = 1/4 dmg dealt"1313 "confuses opponent" ;; acr taken from move acr1314 "user atk +2"1315 "user def +2"1316 "user spd +2"1317 "user spc +2"1318 "user acr +2" ;; unused!1319 "user evd +2" ;; unused!1320 "restores up to half of user's max hp." ;; broken: fails if the difference1321 ;; b/w max and current hp is one less than a multiple of 256.1322 "(transform)"1323 "opponent atk -2"1324 "opponent def -2"1325 "opponent spd -2"1326 "opponent spc -2"1327 "opponent acr -2"1328 "opponent evd -2"1329 "doubles user spc when attacked"1330 "doubles user def when attacked"1331 "just poisons opponent" ;;acr taken from move acr1332 "just paralyzes opponent" ;;1333 "0x19 chance opponent atk -1"1334 "0x19 chance opponent def -1"1335 "0x19 chance opponent spd -1"1336 "0x4C chance opponent spc -1" ;; context suggest chance is 0x191337 "0x19 chance opponent acr -1"1338 "0x19 chance opponent evd -1"1339 "???" ;; unused? no effect?1340 "???" ;; unused? no effect?1341 "0x19 chance opponent confused"1342 "atk hits twice. 0x33 chance opponent poisioned."1343 "broken. crash the game after attack."1344 "(substitute)"1345 "unless opponent faints, user must recharge after atk. some1346 exceptions apply."1347 "(rage)"1348 "(mimic)"1349 "(metronome)"1350 "(leech seed)"1351 "does nothing (splash)"1352 "(disable)"1353 ])1354 #+end_src1357 ** Alphabet code1359 * Source1361 #+begin_src clojure :tangle ../clojure/com/aurellem/gb/hxc.clj1363 (ns com.aurellem.gb.hxc1364 (:use (com.aurellem.gb assembly characters gb-driver util mem-util1365 constants species))1366 (:import [com.aurellem.gb.gb_driver SaveState]))1368 ; ************* HANDWRITTEN CONSTANTS1370 <<type-ids>>1373 ;; question: when status effects claim to take1374 ;; their accuracy from the move accuracy, does1375 ;; this mean that the move always "hits" but the1376 ;; status effect may not?1378 <<move-effects>>1380 ;; ************** HARDCODED DATA1382 <<hxc-thunks>>1383 ;; --------------------------------------------------1385 <<pokenames>>1386 <<type-names>>1388 ;; http://hax.iimarck.us/topic/581/1389 <<pokecry>>1392 <<item-names>>1396 (def hxc-titles1397 "The hardcoded names of the trainer titles in memory. List begins at1398 ROM@27E77"1399 (hxc-thunk-words 0x27E77 196))1402 <<dex-text>>1404 ;; In red/blue, pokedex stats are in internal order.1405 ;; In yellow, pokedex stats are in pokedex order.1406 <<dex-stats>>1411 <<places>>1413 (defn hxc-dialog1414 "The hardcoded dialogue in memory, including in-game alerts. Dialog1415 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."1416 ([rom]1417 (map character-codes->str1418 (take-nth 21419 (partition-by #(= % 0x57)1420 (take 0x0F7281421 (drop 0x98000 rom))))))1422 ([]1423 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))1426 <<move-names>>1427 <<move-data>>1429 <<machines>>1433 (defn internal-id1434 ([rom]1435 (zipmap1436 (hxc-pokenames rom)1437 (range)))1438 ([]1439 (internal-id com.aurellem.gb.gb-driver/original-rom)))1445 ;; nidoran gender change upon levelup1446 ;; (->1447 ;; @current-state1448 ;; rom1449 ;; vec1450 ;; (rewrite-memory1451 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))1452 ;; [1 1 15])1453 ;; (rewrite-memory1454 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))1455 ;; [1 1 3])1456 ;; (write-rom!)1458 ;; )1462 <<type-advantage>>1466 <<evolution-header>>1467 <<evolution>>1468 <<learnsets>>1469 <<pokebase>>1472 (defn hxc-intro-pkmn1473 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's1474 internal id is stored at ROM@5EDB."1475 ([] (hxc-intro-pkmn1476 com.aurellem.gb.gb-driver/original-rom))1477 ([rom]1478 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))1480 (defn sxc-intro-pkmn!1481 "Set the hardcoded pokemon to display in Prof. Oak's introduction."1482 [pokemon]1483 (write-rom!1484 (rewrite-rom 0x5EDB1485 [1486 (inc1487 ((zipmap1488 (hxc-pokenames)1489 (range))1490 pokemon))])))1493 <<item-prices>>1495 <<item-vendors>>1497 <<wilds>>1500 ;; ********************** MANIPULATION FNS1503 (defn same-type1504 ([pkmn move]1505 (same-type1506 com.aurellem.gb.gb-driver/original-rom pkmn move))1507 ([rom pkmn move]1508 (((comp :types (hxc-pokemon-base rom)) pkmn)1509 ((comp :type (hxc-move-data rom)) move))))1514 (defn submap?1515 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."1516 [map-small map-big]1517 (cond (empty? map-small) true1518 (and1519 (contains? map-big (ffirst map-small))1520 (= (get map-big (ffirst map-small))1521 (second (first map-small))))1522 (recur (next map-small) map-big)1524 :else false))1527 (defn search-map [proto-map maps]1528 "Returns all the maps that make the same associations as proto-map."1529 (some (partial submap? proto-map) maps))1531 (defn filter-vals1532 "Returns a map consisting of all the pairs [key val] for1533 which (pred key) returns true."1534 [pred map]1535 (reduce (partial apply assoc) {}1536 (filter (fn [[k v]] (pred v)) map)))1539 (defn search-moves1540 "Returns a subcollection of all hardcoded moves with the1541 given attributes. Attributes consist of :name :power1542 :accuracy :pp :fx-id1543 (and also :fx-txt, but it contains the same information1544 as :fx-id)"1545 ([attribute-map]1546 (search-moves1547 com.aurellem.gb.gb-driver/original-rom attribute-map))1548 ([rom attribute-map]1549 (filter-vals (partial submap? attribute-map)1550 (hxc-move-data rom))))1556 ;; note: 0x2f31 contains the names "TM" "HM"?1558 ;; note for later: credits start at F12901560 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??1562 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)1564 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.1565 ;; The first instance is for Machines; the second, for stones.1567 ;; 0x251A (in indexable mem): image decompression routine seems to begin here.1570 ;; Note: There are two tile tables, one from 8000-8FFF, the other from1571 ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end.1572 (defn print-pixel-letters!1573 "The pixel tiles representing letters. Neat!"1574 ([] (print-pixel-letters! (read-state "oak-speaks")))1575 ([state]1576 (map1577 (comp1578 println1579 (partial map #(if (zero? %) \space 0))1580 #(if (< (count %) 8)1581 (recur (cons 0 %))1582 %)1583 reverse bit-list)1585 (take 0xFFF (drop 0x8800 (memory state))))))1588 (comment1590 (def hxc-later1591 "Running this code produces, e.g. hardcoded names NPCs give1592 their pokemon. Will sort through it later."1593 (print (character-codes->str(take 100001594 (drop 0x715971595 (rom (root)))))))1597 (let [dex1598 (partition-by #(= 0x50 %)1599 (take 25401600 (drop 0x406871601 (rom (root)))))]1602 (def dex dex)1603 (def hxc-species1604 (map character-codes->str1605 (take-nth 4 dex))))1606 )1609 #+end_src1611 #+results:1612 : nil