ocsenave@311: #+title: Notes on Deconstructing Pokemon Yellow ocsenave@311: #+author: Dylan Holmes ocsenave@311: #+email: rlm@mit.edu ocsenave@311: #+description: ocsenave@312: #+keywords: ocsenave@311: #+SETUPFILE: ../../aurellem/org/setup.org ocsenave@311: #+INCLUDE: ../../aurellem/org/level-0.org ocsenave@311: #+BABEL: :exports both :noweb yes :cache no :mkdirp yes ocsenave@311: ocsenave@346: # about map headers http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes ocsenave@346: # map headers Yellow http://www.pokecommunity.com/archive/index.php/t-235311.html ocsenave@312: # pokedollar: U+20B1 ocsenave@347: * Introduction ocsenave@347: ocsenave@347: ** Mapping the ROM ocsenave@311: ocsenave@311: | ROM address (hex) | Description | Format | Example | ocsenave@311: |-------------------+-----------------+-----------------+-----------------| ocsenave@311: | | <15> | <15> | <15> | ocsenave@312: | 0233C- | Shop inventories. | | | ocsenave@312: | 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. | ocsenave@311: | 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#... | ocsenave@346: | 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). | ocsenave@311: | 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. | ocsenave@312: | 06698- | ? Background music. | | | ocsenave@312: | 0822E-082F? | Pointers to background music, part I. | | | ocsenave@347: | 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). | ocsenave@347: |-------------------+-----------------+-----------------+-----------------| ocsenave@347: | 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 | ocsenave@347: | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 | ocsenave@347: | 0DAE3. | Amount of HP restored by Potion. | " | 20 | ocsenave@347: |-------------------+-----------------+-----------------+-----------------| ocsenave@346: | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# | ocsenave@346: | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# | ocsenave@346: | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# | ocsenave@346: | 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), ... | ocsenave@311: | 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#... | ocsenave@347: | 27E77- | Trainer title names. | Variable-length names separated by 0x80. | YOUNGSTER#BUG CATCHER#LASS#... | ocsenave@347: | 34000- | | | | ocsenave@347: | 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. | ocsenave@312: | 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. | | | ocsenave@311: | 39462- | The Pok\eacute{}mon cry data. | Fixed-length (3 byte) descriptions of cries. | | ocsenave@312: | 3B1E5- | Pointers to evolution/learnset data. | | | ocsenave@347: | 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. | | ocsenave@311: | 40687- | Species data from the Pok\eacute{}dex: species name, height, weight, etc. | Fixed-length sequences of bytes. See below for specifics. | | ocsenave@312: | 410B1- | A conversion table between internal order and Pokedex order. | | | ocsenave@346: | 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]... | ocsenave@312: | 71500- | Names of places. | | | ocsenave@312: | 7C249-7C2?? | Pointers to background music, pt II. | | | ocsenave@312: | 98000- | Dialogue | | | ocsenave@312: | B8000- | The text of each Pokemon's Pok\eacute{}dex entry. | | | ocsenave@347: | BC000-BC60E | Move names. | Variable-length move names, separated by 0x80. The moves are in internal order. | POUND#KARATE CHOP#DOUBLESLAP#COMET PUNCH#... | ocsenave@311: | 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♂#... | ocsenave@311: | | | | | ocsenave@311: | | | | | ocsenave@312: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ** COMMENT Getting linguistic data: names, words, etc. ocsenave@347: ocsenave@347: Some of the simplest data ocsenave@347: ocsenave@347: ocsenave@347: One of the simplest data structures in the Pok\eacute{} ROM is an ocsenave@347: unbroken list of strings that either (a) all have a specific length, ocsenave@347: or (b) are all separated by the same character. ocsenave@347: ocsenave@347: Because lots of good data has this format, we'll start by writing a ocsenave@347: template function to extract it: ocsenave@347: ocsenave@347: #+name: hxc-thunks ocsenave@347: #+begin_src clojure :results silent ocsenave@347: (defn hxc-thunk ocsenave@347: "Creates a thunk (nullary fn) that grabs data in a certain region of rom and ocsenave@347: splits it into a collection by 0x50. If rom is not supplied, uses the ocsenave@347: original rom data." ocsenave@347: [start length] ocsenave@347: (fn self ocsenave@347: ([rom] ocsenave@347: (take-nth 2 ocsenave@347: (partition-by #(= % 0x50) ocsenave@347: (take length ocsenave@347: (drop start rom))))) ocsenave@347: ([] ocsenave@347: (self com.aurellem.gb.gb-driver/original-rom)))) ocsenave@347: ocsenave@347: (def hxc-thunk-words ocsenave@347: "Same as hxc-thunk, except it interprets the rom data as characters, ocsenave@347: returning a collection of strings." ocsenave@347: (comp ocsenave@347: (partial comp (partial map character-codes->str)) ocsenave@347: hxc-thunk)) ocsenave@347: ocsenave@347: #+end_src ocsenave@347: ocsenave@347: * Pok\eacute{}mon ocsenave@347: ** Names of each species ocsenave@347: The names of the Pok\eacute{}mon species are stored in ocsenave@347: ROM@E8000. This name list is interesting, for a number of reasons: ocsenave@347: - The names are stored in [[ ][internal order]] rather than in the familiar ocsenave@347: Pok\eacute{}dex order. This seemingly random order probably represents the order in which the authors created or ocsenave@347: programmed in the Pok\eacute{}mon; it's used throughout the game. ocsenave@347: - There is enough space allocated for 190 Pok\eacute{}mon. As I ocsenave@347: understand it, there were originally going to be 190 Pok\eacute{}mon ocsenave@347: in Generation I, but the creators decided to defer some to ocsenave@347: Generation II. This explains why many Gen I and Gen II Pok\eacute{}mon ocsenave@347: have the same aesthetic feel. ocsenave@347: - The list is pockmarked with random gaps, due to the strange internal ocsenave@347: ordering ocsenave@347: and 39 unused spaces [fn::190 allocated spaces minus 151 true Pok\eacute{}mon]. These missing spaces are filled with the ocsenave@347: placeholder name, =MISSINGNO.= (\ldquo{}Missing number\rdquo{}). ocsenave@347: ocsenave@347: Each name is exactly ten letters long (Whenever a name is too short, the extra ocsenave@347: space is padded with the character 0x50). ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: #+name: pokenames ocsenave@347: #+begin_src clojure ocsenave@347: ocsenave@347: (defn hxc-pokenames-raw ocsenave@347: "The hardcoded names of the 190 species in memory. List begins at ocsenave@347: ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters ocsenave@347: long, these names are stripped of padding. See also, hxc-pokedex-names" ocsenave@347: ([] ocsenave@347: (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [count-species 190 ocsenave@347: name-length 10] ocsenave@347: (map character-codes->str ocsenave@347: (partition name-length ocsenave@347: (map #(if (= 0x50 %) 0x00 %) ocsenave@347: (take (* count-species name-length) ocsenave@347: (drop 0xE8000 ocsenave@347: rom)))))))) ocsenave@347: (def hxc-pokenames ocsenave@347: (comp ocsenave@347: (partial map format-name) ocsenave@347: hxc-pokenames-raw)) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-pokedex-names ocsenave@347: "The names of the pokemon in hardcoded pokedex order. List begins at ocsenave@347: ROM@410B1. See also, hxc-pokenames." ocsenave@347: ([] (hxc-pokedex-names ocsenave@347: com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [names (hxc-pokenames rom)] ocsenave@347: (#(mapv % ocsenave@347: ((comp range count keys) %)) ocsenave@347: (zipmap ocsenave@347: (take (count names) ocsenave@347: (drop 0x410b1 rom)) ocsenave@347: ocsenave@347: names))))) ocsenave@347: ocsenave@347: #+end_src ocsenave@347: ocsenave@312: * Appendices ocsenave@312: ** Internal Pok\eacute{}mon IDs ocsenave@312: ** Type IDs ocsenave@347: ocsenave@347: #+name: type-ids ocsenave@347: #+begin_src clojure ocsenave@347: (def pkmn-types ocsenave@347: [:normal ;;0 ocsenave@347: :fighting ;;1 ocsenave@347: :flying ;;2 ocsenave@347: :poison ;;3 ocsenave@347: :ground ;;4 ocsenave@347: :rock ;;5 ocsenave@347: :bird ;;6 ocsenave@347: :bug ;;7 ocsenave@347: :ghost ;;8 ocsenave@347: :A ocsenave@347: :B ocsenave@347: :C ocsenave@347: :D ocsenave@347: :E ocsenave@347: :F ocsenave@347: :G ocsenave@347: :H ocsenave@347: :I ocsenave@347: :J ocsenave@347: :K ocsenave@347: :fire ;;20 (0x14) ocsenave@347: :water ;;21 (0x15) ocsenave@347: :grass ;;22 (0x16) ocsenave@347: :electric ;;23 (0x17) ocsenave@347: :psychic ;;24 (0x18) ocsenave@347: :ice ;;25 (0x19) ocsenave@347: :dragon ;;26 (0x1A) ocsenave@347: ]) ocsenave@347: #+end_src ocsenave@347: ocsenave@312: ** Basic effects of moves ocsenave@347: ocsenave@347: *** Table of basic effects ocsenave@347: ocsenave@347: The possible effects of moves in Pok\eacute{}mon \mdash{} for example, dealing ocsenave@347: damage, leeching health, or potentially poisoning the opponent ocsenave@347: \mdash{} are stored in a table. Each move has exactly one effect, and ocsenave@347: different moves might have the same effect. ocsenave@347: ocsenave@347: For example, Leech Life, Mega Drain, and Absorb all have effect ID #3, which is \ldquo{}Leech half of the inflicted damage.\rdquo{} ocsenave@347: ocsenave@347: All the legitimate move effects are listed in the table ocsenave@347: below. Here are some notes for reading it: ocsenave@347: ocsenave@347: - Whenever an effect has a chance of doing something (like a chance of ocsenave@347: poisoning the opponent), I list the chance as a hexadecimal amount out of 256 to avoid rounding errors. To convert the hex amount into a percentage, divide by 256. ocsenave@347: - For some effects, the description is too cumbersome to ocsenave@347: write. Instead, I just write a move name ocsenave@347: in parentheses, like: (leech seed). That move gives a characteristic example ocsenave@347: of the effect. ocsenave@347: - I use the abbreviations =atk=, =def=, =spd=, =spc=, =acr=, =evd= for ocsenave@347: attack, defense, speed, special, accuracy, and evasion. ocsenave@347: . ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: | ID (hex) | Description | Notes | ocsenave@347: |----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------| ocsenave@347: | 0 | normal damage | | ocsenave@347: | 1 | no damage, just sleep | TODO: find out how many turns | ocsenave@347: | 2 | 0x4C chance of poison | | ocsenave@347: | 3 | leech half of inflicted damage | | ocsenave@347: | 4 | 0x19 chance of burn | | ocsenave@347: | 5 | 0x19 chance of freeze | | ocsenave@347: | 6 | 0x19 chance of paralysis | | ocsenave@347: | 7 | user faints; opponent's defense is halved during attack. | | ocsenave@347: | 8 | leech half of inflicted damage ONLY if the opponent is asleep | | ocsenave@347: | 9 | imitate last attack | | ocsenave@347: | A | user atk +1 | | ocsenave@347: | B | user def +1 | | ocsenave@347: | C | user spd +1 | | ocsenave@347: | D | user spc +1 | | ocsenave@347: | E | user acr +1 | This effect is unused. | ocsenave@347: | F | user evd +1 | | ocsenave@347: | 10 | get post-battle money = 2 * level * uses | | ocsenave@347: | 11 | move has 0xFE acr, regardless of battle stat modifications. | | ocsenave@347: | 12 | opponent atk -1 | | ocsenave@347: | 13 | opponent def -1 | | ocsenave@347: | 14 | opponent spd -1 | | ocsenave@347: | 15 | opponent spc -1 | | ocsenave@347: | 16 | opponent acr -1 | | ocsenave@347: | 17 | opponent evd -1 | | ocsenave@347: | 18 | converts user's type to opponent's. | | ocsenave@347: | 19 | (haze) | | ocsenave@347: | 1A | (bide) | | ocsenave@347: | 1B | (thrash) | | ocsenave@347: | 1C | (teleport) | | ocsenave@347: | 1D | (fury swipes) | | ocsenave@347: | 1E | attacks 2-5 turns | Unused. TODO: find out what it does. | ocsenave@347: | 1F | 0x19 chance of flinching | | ocsenave@347: | 20 | opponent sleep for 1-7 turns | | ocsenave@347: | 21 | 0x66 chance of poison | | ocsenave@347: | 22 | 0x4D chance of burn | | ocsenave@347: | 23 | 0x4D chance of freeze | | ocsenave@347: | 24 | 0x4D chance of paralysis | | ocsenave@347: | 25 | 0x4D chance of flinching | | ocsenave@347: | 26 | one-hit KO | | ocsenave@347: | 27 | charge one turn, atk next. | | ocsenave@347: | 28 | fixed damage, leaves 1HP. | Is the fixed damage the power of the move? | ocsenave@347: | 29 | fixed damage. | Like seismic toss, dragon rage, psywave. | ocsenave@347: | 2A | atk 2-5 turns; opponent can't attack | The odds of attacking for /n/ turns are: (0 0x60 0x60 0x20 0x20) | ocsenave@347: | 2B | charge one turn, atk next. (can't be hit when charging) | | ocsenave@347: | 2C | atk hits twice. | | ocsenave@347: | 2D | user takes 1 damage if misses. | | ocsenave@347: | 2E | evade status-lowering effects | Caused by you or also your opponent? | ocsenave@347: | 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. | ocsenave@347: | 30 | atk causes recoil dmg = 1/4 dmg dealt | | ocsenave@347: | 31 | confuses opponent | | ocsenave@347: | 32 | user atk +2 | | ocsenave@347: | 33 | user def +2 | | ocsenave@347: | 34 | user spd +2 | | ocsenave@347: | 35 | user spc +2 | | ocsenave@347: | 36 | user acr +2 | This effect is unused. | ocsenave@347: | 37 | user evd +2 | This effect is unused. | ocsenave@347: | 38 | restores up to half of user's max hp. | | ocsenave@347: | 39 | (transform) | | ocsenave@347: | 3A | opponent atk -2 | | ocsenave@347: | 3B | opponent def -2 | | ocsenave@347: | 3C | opponent spd -2 | | ocsenave@347: | 3D | opponent spc -2 | | ocsenave@347: | 3E | opponent acr -2 | | ocsenave@347: | 3F | opponent evd -2 | | ocsenave@347: | 40 | doubles user spc when attacked | | ocsenave@347: | 41 | doubles user def when attacked | | ocsenave@347: | 42 | just poisons opponent | | ocsenave@347: | 43 | just paralyzes opponent | | ocsenave@347: | 44 | 0x19 chance opponent atk -1 | | ocsenave@347: | 45 | 0x19 chance opponent def -1 | | ocsenave@347: | 46 | 0x19 chance opponent spd -1 | | ocsenave@347: | 47 | 0x4C chance opponent spc -1 | | ocsenave@347: | 48 | 0x19 chance opponent acr -1 | | ocsenave@347: | 49 | 0x19 chance opponent evd -1 | | ocsenave@347: | 4A | ??? | ;; unused? no effect? | ocsenave@347: | 4B | ??? | ;; unused? no effect? | ocsenave@347: | 4C | 0x19 chance of confusing the opponent | | ocsenave@347: | 4D | atk hits twice. 0x33 chance opponent poisioned. | | ocsenave@347: | 4E | broken. crash the game after attack. | | ocsenave@347: | 4F | (substitute) | | ocsenave@347: | 50 | unless opponent faints, user must recharge after atk. some exceptions apply | | ocsenave@347: | 51 | (rage) | | ocsenave@347: | 52 | (mimic) | | ocsenave@347: | 53 | (metronome) | | ocsenave@347: | 54 | (leech seed) | | ocsenave@347: | 55 | does nothing (splash) | | ocsenave@347: | 56 | (disable) | | ocsenave@347: #+end_src ocsenave@347: ocsenave@347: *** Source ocsenave@347: #+name: move-effects ocsenave@347: #+begin_src clojure ocsenave@347: (def move-effects ocsenave@347: ["normal damage" ocsenave@347: "no damage, just opponent sleep" ;; how many turns? is atk power ignored? ocsenave@347: "0x4C chance of poison" ocsenave@347: "leech half of inflicted damage" ocsenave@347: "0x19 chance of burn" ocsenave@347: "0x19 chance of freeze" ocsenave@347: "0x19 chance of paralyze" ocsenave@347: "user faints; opponent defense halved during attack." ocsenave@347: "leech half of inflicted damage ONLY if sleeping opponent." ocsenave@347: "imitate last attack" ocsenave@347: "user atk +1" ocsenave@347: "user def +1" ocsenave@347: "user spd +1" ocsenave@347: "user spc +1" ocsenave@347: "user acr +1" ;; unused?! ocsenave@347: "user evd +1" ocsenave@347: "get post-battle $ = 2*level*uses" ocsenave@347: "0xFE acr, no matter what." ocsenave@347: "opponent atk -1" ;; acr taken from move acr? ocsenave@347: "opponent def -1" ;; ocsenave@347: "opponent spd -1" ;; ocsenave@347: "opponent spc -1" ;; ocsenave@347: "opponent acr -1";; ocsenave@347: "opponent evd -1" ocsenave@347: "converts user's type to opponent's." ocsenave@347: "(haze)" ocsenave@347: "(bide)" ocsenave@347: "(thrash)" ocsenave@347: "(teleport)" ocsenave@347: "(fury swipes)" ocsenave@347: "attacks 2-5 turns" ;; unused? like rollout? ocsenave@347: "0x19 chance of flinch" ocsenave@347: "opponent sleep for 1-7 turns" ocsenave@347: "0x66 chance of poison" ocsenave@347: "0x4D chance of burn" ocsenave@347: "0x4D chance of freeze" ocsenave@347: "0x4D chance of paralyze" ocsenave@347: "0x4D chance of flinch" ocsenave@347: "one-hit KO" ocsenave@347: "charge one turn, atk next." ocsenave@347: "fixed damage, leaves 1HP." ;; how is dmg determined? ocsenave@347: "fixed damage." ;; cf seismic toss, dragon rage, psywave. ocsenave@347: "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20) ocsenave@347: "charge one turn, atk next. (can't be hit when charging)" ocsenave@347: "atk hits twice." ocsenave@347: "user takes 1 damage if misses." ocsenave@347: "evade status-lowering effects" ;;caused by you or also your opponent? ocsenave@347: "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect" ocsenave@347: "atk causes recoil dmg = 1/4 dmg dealt" ocsenave@347: "confuses opponent" ;; acr taken from move acr ocsenave@347: "user atk +2" ocsenave@347: "user def +2" ocsenave@347: "user spd +2" ocsenave@347: "user spc +2" ocsenave@347: "user acr +2" ;; unused! ocsenave@347: "user evd +2" ;; unused! ocsenave@347: "restores up to half of user's max hp." ;; broken: fails if the difference ocsenave@347: ;; b/w max and current hp is one less than a multiple of 256. ocsenave@347: "(transform)" ocsenave@347: "opponent atk -2" ocsenave@347: "opponent def -2" ocsenave@347: "opponent spd -2" ocsenave@347: "opponent spc -2" ocsenave@347: "opponent acr -2" ocsenave@347: "opponent evd -2" ocsenave@347: "doubles user spc when attacked" ocsenave@347: "doubles user def when attacked" ocsenave@347: "just poisons opponent" ;;acr taken from move acr ocsenave@347: "just paralyzes opponent" ;; ocsenave@347: "0x19 chance opponent atk -1" ocsenave@347: "0x19 chance opponent def -1" ocsenave@347: "0x19 chance opponent spd -1" ocsenave@347: "0x4C chance opponent spc -1" ;; context suggest chance is 0x19 ocsenave@347: "0x19 chance opponent acr -1" ocsenave@347: "0x19 chance opponent evd -1" ocsenave@347: "???" ;; unused? no effect? ocsenave@347: "???" ;; unused? no effect? ocsenave@347: "0x19 chance opponent confused" ocsenave@347: "atk hits twice. 0x33 chance opponent poisioned." ocsenave@347: "broken. crash the game after attack." ocsenave@347: "(substitute)" ocsenave@347: "unless opponent faints, user must recharge after atk. some ocsenave@347: exceptions apply." ocsenave@347: "(rage)" ocsenave@347: "(mimic)" ocsenave@347: "(metronome)" ocsenave@347: "(leech seed)" ocsenave@347: "does nothing (splash)" ocsenave@347: "(disable)" ocsenave@347: ]) ocsenave@347: #+end_src ocsenave@347: ocsenave@347: ocsenave@312: ** Alphabet code ocsenave@347: ocsenave@347: #+begin_src clojure :tangle ../clojure/com/aurellem/gb/hxc.clj ocsenave@347: ocsenave@347: (ns com.aurellem.gb.hxc ocsenave@347: (:use (com.aurellem.gb assembly characters gb-driver util mem-util ocsenave@347: constants species)) ocsenave@347: (:import [com.aurellem.gb.gb_driver SaveState])) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ; ************* HANDWRITTEN CONSTANTS ocsenave@347: ocsenave@347: <> ocsenave@347: ocsenave@347: ocsenave@347: ;; question: when status effects claim to take ocsenave@347: ;; their accuracy from the move accuracy, does ocsenave@347: ;; this mean that the move always "hits" but the ocsenave@347: ;; status effect may not? ocsenave@347: ocsenave@347: <> ocsenave@347: ocsenave@347: ;; ************** HARDCODED DATA ocsenave@347: ocsenave@347: <> ocsenave@347: ;; -------------------------------------------------- ocsenave@347: ocsenave@347: ocsenave@347: <> ocsenave@347: ocsenave@347: ;; http://hax.iimarck.us/topic/581/ ocsenave@347: (defn hxc-cry ocsenave@347: "The pokemon cry data in internal order. List begins at ROM@39462" ocsenave@347: ([](hxc-cry com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (zipmap ocsenave@347: (hxc-pokenames rom) ocsenave@347: (map ocsenave@347: (fn [[cry-id pitch length]] ocsenave@347: {:cry-id cry-id ocsenave@347: :pitch pitch ocsenave@347: :length length} ocsenave@347: ) ocsenave@347: (partition 3 ocsenave@347: (drop 0x39462 rom)))))) ocsenave@347: ocsenave@347: (defn hxc-cry-groups ocsenave@347: ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (map #(mapv first ocsenave@347: (filter ocsenave@347: (fn [[k v]] ocsenave@347: (= % (:cry-id v))) ocsenave@347: (hxc-cry))) ocsenave@347: ((comp ocsenave@347: range ocsenave@347: count ocsenave@347: set ocsenave@347: (partial map :cry-id) ocsenave@347: vals ocsenave@347: hxc-cry) ocsenave@347: rom)))) ocsenave@347: ocsenave@347: ocsenave@347: (defn cry-conversion! ocsenave@347: "Convert Porygon's cry in ROM to be the cry of the given pokemon." ocsenave@347: [pkmn] ocsenave@347: (write-rom! ocsenave@347: (rewrite-memory ocsenave@347: (vec(rom)) ocsenave@347: 0x3965D ocsenave@347: (map second ocsenave@347: ((hxc-cry) pkmn))))) ocsenave@347: ocsenave@347: (def hxc-items-raw ocsenave@347: "The hardcoded names of the items in memory. List begins at ocsenave@347: ROM@045B7" ocsenave@347: (hxc-thunk-words 0x45B7 870)) ocsenave@347: ocsenave@347: (def hxc-types ocsenave@347: "The hardcoded type names in memory. List begins at ROM@27D99, ocsenave@347: shortly before hxc-titles." ocsenave@347: (hxc-thunk-words 0x27D99 102)) ocsenave@347: ocsenave@347: (def hxc-titles ocsenave@347: "The hardcoded names of the trainer titles in memory. List begins at ocsenave@347: ROM@27E77" ocsenave@347: (hxc-thunk-words 0x27E77 196)) ocsenave@347: ocsenave@347: ocsenave@347: (def hxc-pokedex-text-raw ocsenave@347: "The hardcoded pokedex entries in memory. List begins at ocsenave@347: ROM@B8000, shortly before move names." ocsenave@347: (hxc-thunk-words 0xB8000 14754)) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (def hxc-items ocsenave@347: "The hardcoded names of the items in memory, presented as ocsenave@347: keywords. List begins at ROM@045B7. See also, hxc-items-raw." ocsenave@347: (comp (partial map format-name) hxc-items-raw)) ocsenave@347: ocsenave@347: (defn hxc-pokedex-text ocsenave@347: "The hardcoded pokedex entries in memory, presented as an ocsenave@347: associative hash map. List begins at ROM@B8000." ocsenave@347: ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (zipmap ocsenave@347: (hxc-pokedex-names rom) ocsenave@347: (cons nil ;; for missingno. ocsenave@347: (hxc-pokedex-text-raw rom))))) ocsenave@347: ocsenave@347: ;; In red/blue, pokedex stats are in internal order. ocsenave@347: ;; In yellow, pokedex stats are in pokedex order. ocsenave@347: ocsenave@347: (defn hxc-pokedex-stats ocsenave@347: "The hardcoded pokedex stats (species height weight) in memory. List ocsenave@347: begins at ROM@40687" ocsenave@347: ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom)) ocsenave@347: pkmn-count (count pokedex-names) ocsenave@347: ] ocsenave@347: ((fn capture-stats ocsenave@347: [n stats data] ocsenave@347: (if (zero? n) stats ocsenave@347: (let [[species ocsenave@347: [_ ocsenave@347: height-ft ocsenave@347: height-in ocsenave@347: weight-1 ocsenave@347: weight-2 ocsenave@347: _ ocsenave@347: dex-ptr-1 ocsenave@347: dex-ptr-2 ocsenave@347: dex-bank ocsenave@347: _ ocsenave@347: & data]] ocsenave@347: (split-with (partial not= 0x50) data)] ocsenave@347: (recur (dec n) ocsenave@347: (assoc stats ocsenave@347: (pokedex-names (- pkmn-count (dec n))) ocsenave@347: {:species ocsenave@347: (format-name (character-codes->str species)) ocsenave@347: :height-ft ocsenave@347: height-ft ocsenave@347: :height-in ocsenave@347: height-in ocsenave@347: :weight ocsenave@347: (/ (low-high weight-1 weight-2) 10.) ocsenave@347: ocsenave@347: ;; :text ocsenave@347: ;; (character-codes->str ocsenave@347: ;; (take-while ocsenave@347: ;; (partial not= 0x50) ocsenave@347: ;; (drop ocsenave@347: ;; (+ 0xB8000 ocsenave@347: ;; -0x4000 ocsenave@347: ;; (low-high dex-ptr-1 dex-ptr-2)) ocsenave@347: ;; rom))) ocsenave@347: }) ocsenave@347: ocsenave@347: data) ocsenave@347: ocsenave@347: ocsenave@347: ))) ocsenave@347: ocsenave@347: pkmn-count ocsenave@347: {} ocsenave@347: (drop 0x40687 rom))) )) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (def hxc-places ocsenave@347: "The hardcoded place names in memory. List begins at ocsenave@347: ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated." ocsenave@347: (hxc-thunk-words 0x71500 560)) ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-dialog ocsenave@347: "The hardcoded dialogue in memory, including in-game alerts. Dialog ocsenave@347: seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000." ocsenave@347: ([rom] ocsenave@347: (map character-codes->str ocsenave@347: (take-nth 2 ocsenave@347: (partition-by #(= % 0x57) ocsenave@347: (take 0x0F728 ocsenave@347: (drop 0x98000 rom)))))) ocsenave@347: ([] ocsenave@347: (hxc-dialog com.aurellem.gb.gb-driver/original-rom))) ocsenave@347: ocsenave@347: ocsenave@347: (def hxc-move-names ocsenave@347: "The hardcoded move names in memory. List begins at ROM@BC000" ocsenave@347: (hxc-thunk-words 0xBC000 1551)) ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-move-data ocsenave@347: "The hardcoded (basic (move effects)) in memory. List begins at ocsenave@347: 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id ocsenave@347: :fx-txt}. The move descriptions are handwritten, not hardcoded." ocsenave@347: ([] ocsenave@347: (hxc-move-data com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [names (vec (hxc-move-names rom)) ocsenave@347: move-count (count names) ocsenave@347: move-size 6 ocsenave@347: types pkmn-types ;;; !! hardcoded types ocsenave@347: ] ocsenave@347: (zipmap (map format-name names) ocsenave@347: (map ocsenave@347: (fn [[idx effect power type-id accuracy pp]] ocsenave@347: {:name (names (dec idx)) ocsenave@347: :power power ocsenave@347: :accuracy accuracy ocsenave@347: :pp pp ocsenave@347: :type (types type-id) ocsenave@347: :fx-id effect ocsenave@347: :fx-txt (get move-effects effect) ocsenave@347: } ocsenave@347: ) ocsenave@347: ocsenave@347: (partition move-size ocsenave@347: (take (* move-size move-count) ocsenave@347: (drop 0x38000 rom)))))))) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-move-data* ocsenave@347: "Like hxc-move-data, but reports numbers as hexadecimal symbols instead." ocsenave@347: ([] ocsenave@347: (hxc-move-data* com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [names (vec (hxc-move-names rom)) ocsenave@347: move-count (count names) ocsenave@347: move-size 6 ocsenave@347: format-name (fn [s] ocsenave@347: (keyword (.toLowerCase ocsenave@347: (apply str ocsenave@347: (map #(if (= % \space) "-" %) s))))) ocsenave@347: ] ocsenave@347: (zipmap (map format-name names) ocsenave@347: (map ocsenave@347: (fn [[idx effect power type accuracy pp]] ocsenave@347: {:name (names (dec idx)) ocsenave@347: :power power ocsenave@347: :accuracy (hex accuracy) ocsenave@347: :pp pp ocsenave@347: :fx-id (hex effect) ocsenave@347: :fx-txt (get move-effects effect) ocsenave@347: } ocsenave@347: ) ocsenave@347: ocsenave@347: (partition move-size ocsenave@347: (take (* move-size move-count) ocsenave@347: (drop 0x38000 rom)))))))) ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-machines ocsenave@347: "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D." ocsenave@347: ([] (hxc-machines ocsenave@347: com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [moves (hxc-move-names rom)] ocsenave@347: (zipmap ocsenave@347: (range) ocsenave@347: (take-while ocsenave@347: (comp not nil?) ocsenave@347: (map (comp ocsenave@347: format-name ocsenave@347: (zipmap ocsenave@347: (range) ocsenave@347: moves) ocsenave@347: dec) ocsenave@347: (take 100 ocsenave@347: (drop 0x1232D rom)))))))) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (defn internal-id ocsenave@347: ([rom] ocsenave@347: (zipmap ocsenave@347: (hxc-pokenames rom) ocsenave@347: (range))) ocsenave@347: ([] ocsenave@347: (internal-id com.aurellem.gb.gb-driver/original-rom))) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ;; nidoran gender change upon levelup ocsenave@347: ;; (-> ocsenave@347: ;; @current-state ocsenave@347: ;; rom ocsenave@347: ;; vec ocsenave@347: ;; (rewrite-memory ocsenave@347: ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂)) ocsenave@347: ;; [1 1 15]) ocsenave@347: ;; (rewrite-memory ocsenave@347: ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀)) ocsenave@347: ;; [1 1 3]) ocsenave@347: ;; (write-rom!) ocsenave@347: ocsenave@347: ;; ) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-advantage ocsenave@347: ;; in-game multipliers are stored as 10x their effective value ocsenave@347: ;; to allow for fractional multipliers like 1/2 ocsenave@347: ocsenave@347: "The hardcoded type advantages in memory, returned as tuples of ocsenave@347: atk-type def-type multiplier. By default (i.e. if not listed here), ocsenave@347: the multiplier is 1. List begins at 0x3E62D." ocsenave@347: ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (map ocsenave@347: (fn [[atk def mult]] [(get pkmn-types atk (hex atk)) ocsenave@347: (get pkmn-types def (hex def)) ocsenave@347: (/ mult 10)]) ocsenave@347: (partition 3 ocsenave@347: (take-while (partial not= 0xFF) ocsenave@347: (drop 0x3E62D rom)))))) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (defn format-evo ocsenave@347: "Parse a sequence of evolution data, returning a map. First is the ocsenave@347: method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the ocsenave@347: method of evolution is by item (only stones will actually make pokemon ocsenave@347: evolve, for some auxillary reason.) Finally, the minimum level for ocsenave@347: evolution to occur (level 1 means no limit, which is used for trade ocsenave@347: and item evolutions), followed by the internal id of the pokemon ocsenave@347: into which to evolve. Hence, level up and trade evolutions are ocsenave@347: described with 3 ocsenave@347: bytes; item evolutions with four." ocsenave@347: [coll] ocsenave@347: (let [method (first coll)] ocsenave@347: (cond (empty? coll) [] ocsenave@347: (= 0 method) [] ;; just in case ocsenave@347: (= 1 method) ;; level-up evolution ocsenave@347: (conj (format-evo (drop 3 coll)) ocsenave@347: {:method :level-up ocsenave@347: :min-level (nth coll 1) ocsenave@347: :into (dec (nth coll 2))}) ocsenave@347: ocsenave@347: (= 2 method) ;; item evolution ocsenave@347: (conj (format-evo (drop 4 coll)) ocsenave@347: {:method :item ocsenave@347: :item (dec (nth coll 1)) ocsenave@347: :min-level (nth coll 2) ocsenave@347: :into (dec (nth coll 3))}) ocsenave@347: ocsenave@347: (= 3 method) ;; trade evolution ocsenave@347: (conj (format-evo (drop 3 coll)) ocsenave@347: {:method :trade ocsenave@347: :min-level (nth coll 1) ;; always 1 for trade. ocsenave@347: :into (dec (nth coll 2))})))) ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-ptrs-evolve ocsenave@347: "A hardcoded collection of 190 pointers to alternating evolution/learnset data, ocsenave@347: in internal order." ocsenave@347: ([] ocsenave@347: (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [ ocsenave@347: pkmn-count (count (hxc-pokenames-raw)) ;; 190 ocsenave@347: ptrs ocsenave@347: (map (fn [[a b]] (low-high a b)) ocsenave@347: (partition 2 ocsenave@347: (take (* 2 pkmn-count) ocsenave@347: (drop 0x3b1e5 rom))))] ocsenave@347: (map (partial + 0x34000) ptrs) ocsenave@347: ocsenave@347: ))) ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-learnsets ocsenave@347: "Hardcoded map associating pokemon names to lists of pairs [lvl ocsenave@347: move] of abilities they learn as they level up. The data ocsenave@347: exists at ROM@34000, sorted by internal order. Pointers to the data ocsenave@347: exist at ROM@3B1E5; see also, hxc-ptrs-evolve" ocsenave@347: ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (apply assoc ocsenave@347: {} ocsenave@347: (interleave ocsenave@347: (hxc-pokenames rom) ocsenave@347: (map (comp ocsenave@347: (partial map ocsenave@347: (fn [[lvl mv]] [lvl (dec mv)])) ocsenave@347: (partial partition 2) ocsenave@347: ;; keep the learnset data ocsenave@347: (partial take-while (comp not zero?)) ocsenave@347: ;; skip the evolution data ocsenave@347: rest ocsenave@347: (partial drop-while (comp not zero?))) ocsenave@347: (map #(drop % rom) ocsenave@347: (hxc-ptrs-evolve rom))))))) ocsenave@347: ocsenave@347: (defn hxc-learnsets-pretty ocsenave@347: "Live hxc-learnsets except it reports the name of each move --- as ocsenave@347: it appears in rom --- rather than the move index." ocsenave@347: ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [moves (vec(map format-name (hxc-move-names)))] ocsenave@347: (into {} ocsenave@347: (map (fn [[pkmn learnset]] ocsenave@347: [pkmn (map (fn [[lvl mv]] [lvl (moves mv)]) ocsenave@347: learnset)]) ocsenave@347: (hxc-learnsets rom)))))) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-evolution ocsenave@347: "Hardcoded evolution data in memory. The data exists at ROM@34000, ocsenave@347: sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve." ocsenave@347: ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (apply assoc {} ocsenave@347: (interleave ocsenave@347: (hxc-pokenames rom) ocsenave@347: (map ocsenave@347: (comp ocsenave@347: format-evo ocsenave@347: (partial take-while (comp not zero?)) ocsenave@347: #(drop % rom)) ocsenave@347: (hxc-ptrs-evolve rom) ocsenave@347: ))))) ocsenave@347: ocsenave@347: (defn hxc-evolution-pretty ocsenave@347: "Like hxc-evolution, except it uses the names of items and pokemon ocsenave@347: --- grabbed from ROM --- rather than their numerical identifiers." ocsenave@347: ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let ocsenave@347: [poke-names (vec (hxc-pokenames rom)) ocsenave@347: item-names (vec (hxc-items rom)) ocsenave@347: use-names ocsenave@347: (fn [m] ocsenave@347: (loop [ks (keys m) new-map m] ocsenave@347: (let [k (first ks)] ocsenave@347: (cond (nil? ks) new-map ocsenave@347: (= k :into) ocsenave@347: (recur ocsenave@347: (next ks) ocsenave@347: (assoc new-map ocsenave@347: :into ocsenave@347: (poke-names ocsenave@347: (:into ocsenave@347: new-map)))) ocsenave@347: (= k :item) ocsenave@347: (recur ocsenave@347: (next ks) ocsenave@347: (assoc new-map ocsenave@347: :item ocsenave@347: (item-names ocsenave@347: (:item new-map)))) ocsenave@347: :else ocsenave@347: (recur ocsenave@347: (next ks) ocsenave@347: new-map) ocsenave@347: ))))] ocsenave@347: ocsenave@347: (into {} ocsenave@347: (map (fn [[pkmn evo-coll]] ocsenave@347: [pkmn (map use-names evo-coll)]) ocsenave@347: (hxc-evolution rom)))))) ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-pokemon-base ocsenave@347: ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [entry-size 28 ocsenave@347: pkmn-count (count (hxc-pokedex-text rom)) ocsenave@347: pokemon (rest (hxc-pokedex-names)) ocsenave@347: types (apply assoc {} ocsenave@347: (interleave ocsenave@347: (range) ocsenave@347: pkmn-types)) ;;!! softcoded ocsenave@347: moves (apply assoc {} ocsenave@347: (interleave ocsenave@347: (range) ocsenave@347: (map format-name ocsenave@347: (hxc-move-names rom)))) ocsenave@347: machines (hxc-machines) ocsenave@347: ] ocsenave@347: (zipmap ocsenave@347: pokemon ocsenave@347: (map ocsenave@347: (fn [[n ocsenave@347: rating-hp ocsenave@347: rating-atk ocsenave@347: rating-def ocsenave@347: rating-speed ocsenave@347: rating-special ocsenave@347: type-1 ocsenave@347: type-2 ocsenave@347: rarity ocsenave@347: rating-xp ocsenave@347: pic-dimensions ;; tile_width|tile_height (8px/tile) ocsenave@347: ptr-pic-obverse-1 ocsenave@347: ptr-pic-obverse-2 ocsenave@347: ptr-pic-reverse-1 ocsenave@347: ptr-pic-reverse-2 ocsenave@347: move-1 ocsenave@347: move-2 ocsenave@347: move-3 ocsenave@347: move-4 ocsenave@347: growth-rate ocsenave@347: & ocsenave@347: TMs|HMs]] ocsenave@347: (let ocsenave@347: [base-moves ocsenave@347: (mapv moves ocsenave@347: ((comp ocsenave@347: ;; since the game uses zero as a delimiter, ocsenave@347: ;; it must also increment all move indices by 1. ocsenave@347: ;; heren we decrement to correct this. ocsenave@347: (partial map dec) ocsenave@347: (partial take-while (comp not zero?))) ocsenave@347: [move-1 move-2 move-3 move-4])) ocsenave@347: ocsenave@347: types ocsenave@347: (set (list (types type-1) ocsenave@347: (types type-2))) ocsenave@347: TMs|HMs ocsenave@347: (map ocsenave@347: (comp ocsenave@347: (partial map first) ocsenave@347: (partial remove (comp zero? second))) ocsenave@347: (split-at ocsenave@347: 50 ocsenave@347: (map vector ocsenave@347: (rest(range)) ocsenave@347: (reduce concat ocsenave@347: (map ocsenave@347: #(take 8 ocsenave@347: (concat (bit-list %) ocsenave@347: (repeat 0))) ocsenave@347: ocsenave@347: TMs|HMs))))) ocsenave@347: ocsenave@347: TMs (vec (first TMs|HMs)) ocsenave@347: HMs (take 5 (map (partial + -50) (vec (second TMs|HMs)))) ocsenave@347: ocsenave@347: ocsenave@347: ] ocsenave@347: ocsenave@347: ocsenave@347: {:dex# n ocsenave@347: :base-moves base-moves ocsenave@347: :types types ocsenave@347: :TMs TMs ocsenave@347: :HMs HMs ocsenave@347: :base-hp rating-hp ocsenave@347: :base-atk rating-atk ocsenave@347: :base-def rating-def ocsenave@347: :base-speed rating-speed ocsenave@347: :base-special rating-special ocsenave@347: :o0 pic-dimensions ocsenave@347: :o1 ptr-pic-obverse-1 ocsenave@347: :o2 ptr-pic-obverse-2 ocsenave@347: })) ocsenave@347: ocsenave@347: (partition entry-size ocsenave@347: (take (* entry-size pkmn-count) ocsenave@347: (drop 0x383DE ocsenave@347: rom)))))))) ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-intro-pkmn ocsenave@347: "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's ocsenave@347: internal id is stored at ROM@5EDB." ocsenave@347: ([] (hxc-intro-pkmn ocsenave@347: com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (nth (hxc-pokenames rom) (nth rom 0x5EDB)))) ocsenave@347: ocsenave@347: (defn sxc-intro-pkmn! ocsenave@347: "Set the hardcoded pokemon to display in Prof. Oak's introduction." ocsenave@347: [pokemon] ocsenave@347: (write-rom! ocsenave@347: (rewrite-rom 0x5EDB ocsenave@347: [ ocsenave@347: (inc ocsenave@347: ((zipmap ocsenave@347: (hxc-pokenames) ocsenave@347: (range)) ocsenave@347: pokemon))]))) ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-item-prices ocsenave@347: "The hardcoded list of item prices in memory. List begins at ROM@4495" ocsenave@347: ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [items (hxc-items rom) ocsenave@347: price-size 3] ocsenave@347: (zipmap items ocsenave@347: (map (comp ocsenave@347: ;; zero-cost items are "priceless" ocsenave@347: #(if (zero? %) :priceless %) ocsenave@347: decode-bcd butlast) ocsenave@347: (partition price-size ocsenave@347: (take (* price-size (count items)) ocsenave@347: (drop 0x4495 rom)))))))) ocsenave@347: ocsenave@347: (defn hxc-shops ocsenave@347: ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [items (zipmap (range) (hxc-items rom)) ocsenave@347: ocsenave@347: ;; temporarily softcode the TM items ocsenave@347: items (into ocsenave@347: items ocsenave@347: (map (juxt identity ocsenave@347: (comp keyword ocsenave@347: (partial str "tm-") ocsenave@347: (partial + 1 -200) ocsenave@347: )) ocsenave@347: (take 200 (drop 200 (range))))) ocsenave@347: ocsenave@347: ] ocsenave@347: ocsenave@347: ((fn parse-shop [coll [num-items & items-etc]] ocsenave@347: (let [inventory (take-while ocsenave@347: (partial not= 0xFF) ocsenave@347: items-etc) ocsenave@347: [separator & items-etc] (drop num-items (rest items-etc))] ocsenave@347: (if (= separator 0x50) ocsenave@347: (map (partial mapv (comp items dec)) (conj coll inventory)) ocsenave@347: (recur (conj coll inventory) items-etc) ocsenave@347: ) ocsenave@347: )) ocsenave@347: ocsenave@347: '() ocsenave@347: (drop 0x233C rom)) ocsenave@347: ocsenave@347: ocsenave@347: ))) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-ptrs-wild ocsenave@347: "A list of the hardcoded wild encounter data in memory. Pointers ocsenave@347: begin at ROM@0CB95; data begins at ROM@0x04D89" ocsenave@347: ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [ptrs ocsenave@347: (map (fn [[a b]] (+ a (* 0x100 b))) ocsenave@347: (take-while (partial not= (list 0xFF 0xFF)) ocsenave@347: (partition 2 (drop 0xCB95 rom))))] ocsenave@347: ptrs))) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (defn hxc-wilds ocsenave@347: "A list of the hardcoded wild encounter data in memory. Pointers ocsenave@347: begin at ROM@0CB95; data begins at ROM@0x04D89" ocsenave@347: ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom)) ocsenave@347: ([rom] ocsenave@347: (let [pokenames (zipmap (range) (hxc-pokenames rom))] ocsenave@347: (map ocsenave@347: (partial map (fn [[a b]] {:species (pokenames (dec b)) :level ocsenave@347: a})) ocsenave@347: (partition 10 ocsenave@347: ocsenave@347: (take-while (comp (partial not= 1) ocsenave@347: first) ocsenave@347: (partition 2 ocsenave@347: (drop 0xCD8C rom)) ocsenave@347: ocsenave@347: )))))) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ;; ********************** MANIPULATION FNS ocsenave@347: ocsenave@347: ocsenave@347: (defn same-type ocsenave@347: ([pkmn move] ocsenave@347: (same-type ocsenave@347: com.aurellem.gb.gb-driver/original-rom pkmn move)) ocsenave@347: ([rom pkmn move] ocsenave@347: (((comp :types (hxc-pokemon-base rom)) pkmn) ocsenave@347: ((comp :type (hxc-move-data rom)) move)))) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: (defn submap? ocsenave@347: "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false." ocsenave@347: [map-small map-big] ocsenave@347: (cond (empty? map-small) true ocsenave@347: (and ocsenave@347: (contains? map-big (ffirst map-small)) ocsenave@347: (= (get map-big (ffirst map-small)) ocsenave@347: (second (first map-small)))) ocsenave@347: (recur (next map-small) map-big) ocsenave@347: ocsenave@347: :else false)) ocsenave@347: ocsenave@347: ocsenave@347: (defn search-map [proto-map maps] ocsenave@347: "Returns all the maps that make the same associations as proto-map." ocsenave@347: (some (partial submap? proto-map) maps)) ocsenave@347: ocsenave@347: (defn filter-vals ocsenave@347: "Returns a map consisting of all the pairs [key val] for ocsenave@347: which (pred key) returns true." ocsenave@347: [pred map] ocsenave@347: (reduce (partial apply assoc) {} ocsenave@347: (filter (fn [[k v]] (pred v)) map))) ocsenave@347: ocsenave@347: ocsenave@347: (defn search-moves ocsenave@347: "Returns a subcollection of all hardcoded moves with the ocsenave@347: given attributes. Attributes consist of :name :power ocsenave@347: :accuracy :pp :fx-id ocsenave@347: (and also :fx-txt, but it contains the same information ocsenave@347: as :fx-id)" ocsenave@347: ([attribute-map] ocsenave@347: (search-moves ocsenave@347: com.aurellem.gb.gb-driver/original-rom attribute-map)) ocsenave@347: ([rom attribute-map] ocsenave@347: (filter-vals (partial submap? attribute-map) ocsenave@347: (hxc-move-data rom)))) ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ocsenave@347: ;; note: 0x2f31 contains the names "TM" "HM"? ocsenave@347: ocsenave@347: ;; note for later: credits start at F1290 ocsenave@347: ocsenave@347: ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ?? ocsenave@347: ocsenave@347: ;; note: DD4D spells out pokemon vital stat names ("speed", etc.) ocsenave@347: ocsenave@347: ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE. ocsenave@347: ;; The first instance is for Machines; the second, for stones. ocsenave@347: ocsenave@347: ;; 0x251A (in indexable mem): image decompression routine seems to begin here. ocsenave@347: ocsenave@347: ocsenave@347: (comment ocsenave@347: ocsenave@347: (def hxc-later ocsenave@347: "Running this code produces, e.g. hardcoded names NPCs give ocsenave@347: their pokemon. Will sort through it later." ocsenave@347: (print (character-codes->str(take 10000 ocsenave@347: (drop 0x71597 ocsenave@347: (rom (root))))))) ocsenave@347: ocsenave@347: (let [dex ocsenave@347: (partition-by #(= 0x50 %) ocsenave@347: (take 2540 ocsenave@347: (drop 0x40687 ocsenave@347: (rom (root)))))] ocsenave@347: (def dex dex) ocsenave@347: (def hxc-species ocsenave@347: (map character-codes->str ocsenave@347: (take-nth 4 dex)))) ocsenave@347: ) ocsenave@347: ocsenave@347: ocsenave@347: #+end_src ocsenave@347: