view org/rom.org @ 420:acc3d1ad24e8

Found HP restored by SODA POP, FRESH WATER, LEMONADE; also found number of steps for REPEL, SUPER REPEL, MAX REPEL.
author Dylan Holmes <ocsenave@gmail.com>
date Sat, 14 Apr 2012 09:27:49 -0500
parents 4901ba2d3860
children 13165fb5852b
line wrap: on
line source
1 #+title: Notes on Deconstructing Pokemon Yellow
2 #+author: Dylan Holmes
3 #+email: rlm@mit.edu
4 #+description: A detailed explication of Pok\eacute{}mon Yellow, helped by Clojure.
5 #+keywords: pokemon, pokemon yellow, rom, gameboy, assembly, hex, pointers, clojure
6 #+SETUPFILE: ../../aurellem/org/setup.org
7 #+INCLUDE: ../../aurellem/org/level-0.org
8 #+BABEL: :exports both :noweb yes :cache no :mkdirp yes
10 # about map headers http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes
11 # map headers Yellow http://www.pokecommunity.com/archive/index.php/t-235311.html
12 # pokedollar: U+20B1
13 * Introduction
15 ** COMMENT Getting linguistic data: names, words, etc.
17 Some of the simplest data
20 One of the simplest data structures in the Pok\eacute{} ROM is an
21 unbroken list of strings that either (a) all have a specific length,
22 or (b) are all separated by the same character.
24 Because lots of good data has this format, we'll start by writing a
25 template function to extract it:
27 #+name: hxc-thunks
28 #+begin_src clojure :results silent
29 (defn hxc-thunk
30 "Creates a thunk (nullary fn) that grabs data in a certain region of rom and
31 splits it into a collection by 0x50. If rom is not supplied, uses the
32 original rom data."
33 [start length]
34 (fn self
35 ([rom]
36 (take-nth 2
37 (partition-by #(= % 0x50)
38 (take length
39 (drop start rom)))))
40 ([]
41 (self com.aurellem.gb.gb-driver/original-rom))))
43 (def hxc-thunk-words
44 "Same as hxc-thunk, except it interprets the rom data as characters,
45 returning a collection of strings."
46 (comp
47 (partial comp (partial map character-codes->str))
48 hxc-thunk))
50 #+end_src
53 * Pok\eacute{}mon I
54 ** Names of each species
55 The names of the Pok\eacute{}mon species are stored in
56 ROM@E8000. This name list is interesting, for a number of reasons:
57 - The names are stored in [[ ][internal order]] rather than in the familiar
58 Pok\eacute{}dex order. This seemingly random order probably represents the order in which the authors created or
59 programmed in the Pok\eacute{}mon; it's used throughout the game.
60 - There is enough space allocated for 190 Pok\eacute{}mon. As I
61 understand it, there were originally going to be 190 Pok\eacute{}mon
62 in Generation I, but the creators decided to defer some to
63 Generation II. This explains why many Gen I and Gen II Pok\eacute{}mon
64 have the same aesthetic feel.
65 - The list is pockmarked with random gaps, due to the strange internal
66 ordering
67 and the 39 unused spaces [fn::190 allocated spaces minus 151 true Pok\eacute{}mon]. These missing spaces are filled with the
68 placeholder name =MISSINGNO.= (\ldquo{}Missing number\rdquo{}).
70 Each name is exactly ten letters long; whenever a name would be too short, the extra
71 space is padded with the character 0x50.
73 *** See the data
75 Here you can see the raw data in three stages: in the first stage, we
76 just grab the first few bytes starting from position 0xE8000. In the
77 second stage, we partition the bytes into ten-letter chunks to show you
78 where the names begin and end. In the final stage, we convert each
79 byte into the letter it represents using the =character-codes->str=
80 function. (0x50 is rendered as the symbol \ldquo{} =#= \rdquo{} for
81 ease of reading).
83 #+begin_src clojure :exports both :cache no :results output
84 (ns com.aurellem.gb.hxc
85 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
86 constants))
87 (:import [com.aurellem.gb.gb_driver SaveState]))
90 (println (take 100 (drop 0xE8000 (rom))))
92 (println (partition 10 (take 100 (drop 0xE8000 (rom)))))
94 (println (character-codes->str (take 100 (drop 0xE8000 (rom)))))
97 #+end_src
99 #+results:
100 : (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)
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 : RHYDON####KANGASKHANNIDORAN♂##CLEFAIRY##SPEAROW###VOLTORB###NIDOKING##SLOWBRO###IVYSAUR###EXEGGUTOR#
105 *** Automatically grab the data.
107 #+name: pokenames
108 #+begin_src clojure
110 (defn hxc-pokenames-raw
111 "The hardcoded names of the 190 species in memory. List begins at
112 ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters
113 long, these names are stripped of padding. See also, hxc-pokedex-names"
114 ([]
115 (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom))
116 ([rom]
117 (let [count-species 190
118 name-length 10]
119 (map character-codes->str
120 (partition name-length
121 (map #(if (= 0x50 %) 0x00 %)
122 (take (* count-species name-length)
123 (drop 0xE8000
124 rom))))))))
125 (def hxc-pokenames
126 (comp
127 (partial map format-name)
128 hxc-pokenames-raw))
133 (defn hxc-pokedex-names
134 "The names of the pokemon in hardcoded pokedex order. List of the
135 pokedex numbers of each pokemon (in internal order) begins at
136 ROM@410B1. See also, hxc-pokenames."
137 ([] (hxc-pokedex-names
138 com.aurellem.gb.gb-driver/original-rom))
139 ([rom]
140 (let [names (hxc-pokenames rom)]
141 (#(mapv %
142 ((comp range count keys) %))
143 (zipmap
144 (take (count names)
145 (drop 0x410b1 rom))
147 names)))))
149 #+end_src
153 ** Generic species information
155 #+name: pokebase
156 #+begin_src clojure
157 (defn hxc-pokemon-base
158 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))
159 ([rom]
160 (let [entry-size 28
162 pokemon (rest (hxc-pokedex-names))
163 pkmn-count (inc(count pokemon))
164 types (apply assoc {}
165 (interleave
166 (range)
167 pkmn-types)) ;;!! softcoded
168 moves (apply assoc {}
169 (interleave
170 (range)
171 (map format-name
172 (hxc-move-names rom))))
173 machines (hxc-machines)
174 ]
175 (zipmap
176 pokemon
177 (map
178 (fn [[n
179 rating-hp
180 rating-atk
181 rating-def
182 rating-speed
183 rating-special
184 type-1
185 type-2
186 rarity
187 rating-xp
188 pic-dimensions ;; tile_width|tile_height (8px/tile)
189 ptr-pic-obverse-1
190 ptr-pic-obverse-2
191 ptr-pic-reverse-1
192 ptr-pic-reverse-2
193 move-1
194 move-2
195 move-3
196 move-4
197 growth-rate
198 &
199 TMs|HMs]]
200 (let
201 [base-moves
202 (mapv moves
203 ((comp
204 ;; 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 types
212 (set (list (types type-1)
213 (types type-2)))
214 TMs|HMs
215 (map
216 (comp
217 (partial map first)
218 (partial remove (comp zero? second)))
219 (split-at
220 50
221 (map vector
222 (rest(range))
223 (reduce concat
224 (map
225 #(take 8
226 (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# n
239 :base-moves base-moves
240 :types types
241 :TMs TMs
242 :HMs HMs
243 :base-hp rating-hp
244 :base-atk rating-atk
245 :base-def rating-def
246 :base-speed rating-speed
247 :base-special rating-special
248 :o0 pic-dimensions
249 :o1 ptr-pic-obverse-1
250 :o2 ptr-pic-obverse-2
251 }))
253 (partition entry-size
254 (take (* entry-size pkmn-count)
255 (drop 0x383DE
256 rom))))))))
258 #+end_src
261 ** Pok\eacute{}mon evolutions
262 #+name: evolution-header
263 #+begin_src clojure
264 (defn format-evo
265 "Parse a sequence of evolution data, returning a map. First is the
266 method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the
267 method of evolution is by item (only stones will actually make pokemon
268 evolve, for some auxillary reason.) Finally, the minimum level for
269 evolution to occur (level 1 means no limit, which is used for trade
270 and item evolutions), followed by the internal id of the pokemon
271 into which to evolve. Hence, level up and trade evolutions are
272 described with 3
273 bytes; item evolutions with four."
274 [coll]
275 (let [method (first coll)]
276 (cond (empty? coll) []
277 (= 0 method) [] ;; just in case
278 (= 1 method) ;; level-up evolution
279 (conj (format-evo (drop 3 coll))
280 {:method :level-up
281 :min-level (nth coll 1)
282 :into (dec (nth coll 2))})
284 (= 2 method) ;; item evolution
285 (conj (format-evo (drop 4 coll))
286 {:method :item
287 :item (dec (nth coll 1))
288 :min-level (nth coll 2)
289 :into (dec (nth coll 3))})
291 (= 3 method) ;; trade evolution
292 (conj (format-evo (drop 3 coll))
293 {:method :trade
294 :min-level (nth coll 1) ;; always 1 for trade.
295 :into (dec (nth coll 2))}))))
298 (defn hxc-ptrs-evolve
299 "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)) ;; 190
306 ptrs
307 (map (fn [[a b]] (low-high a b))
308 (partition 2
309 (take (* 2 pkmn-count)
310 (drop 0x3b1e5 rom))))]
311 (map (partial + 0x34000) ptrs)
313 )))
314 #+end_src
316 #+name:evolution
317 #+begin_src clojure
319 (defn hxc-evolution
320 "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 (interleave
326 (hxc-pokenames rom)
327 (map
328 (comp
329 format-evo
330 (partial take-while (comp not zero?))
331 #(drop % rom))
332 (hxc-ptrs-evolve rom)
333 )))))
335 (defn hxc-evolution-pretty
336 "Like hxc-evolution, except it uses the names of items and pokemon
337 --- grabbed from ROM --- rather than their numerical identifiers."
338 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))
339 ([rom]
340 (let
341 [poke-names (vec (hxc-pokenames rom))
342 item-names (vec (hxc-items rom))
343 use-names
344 (fn [m]
345 (loop [ks (keys m) new-map m]
346 (let [k (first ks)]
347 (cond (nil? ks) new-map
348 (= k :into)
349 (recur
350 (next ks)
351 (assoc new-map
352 :into
353 (poke-names
354 (:into
355 new-map))))
356 (= k :item)
357 (recur
358 (next ks)
359 (assoc new-map
360 :item
361 (item-names
362 (:item new-map))))
363 :else
364 (recur
365 (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_src
378 ** Level-up moves (learnsets)
379 #+name: learnsets
380 #+begin_src clojure
383 (defn hxc-learnsets
384 "Hardcoded map associating pokemon names to lists of pairs [lvl
385 move] of abilities they learn as they level up. The data
386 exists at ROM@34000, sorted by internal order. Pointers to the data
387 exist at ROM@3B1E5; see also, hxc-ptrs-evolve"
388 ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))
389 ([rom]
390 (apply assoc
391 {}
392 (interleave
393 (hxc-pokenames rom)
394 (map (comp
395 (partial map
396 (fn [[lvl mv]] [lvl (dec mv)]))
397 (partial partition 2)
398 ;; keep the learnset data
399 (partial take-while (comp not zero?))
400 ;; skip the evolution data
401 rest
402 (partial drop-while (comp not zero?)))
403 (map #(drop % rom)
404 (hxc-ptrs-evolve rom)))))))
406 (defn hxc-learnsets-pretty
407 "Live hxc-learnsets except it reports the name of each move --- as
408 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_src
424 * Pok\eacute{}mon II : the Pok\eacute{}dex
425 ** Species vital stats
426 #+name: dex-stats
427 #+begin_src clojure
428 (defn hxc-pokedex-stats
429 "The hardcoded pokedex stats (species height weight) in memory. List
430 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-stats
437 [n stats data]
438 (if (zero? n) stats
439 (let [[species
440 [_
441 height-ft
442 height-in
443 weight-1
444 weight-2
445 _
446 dex-ptr-1
447 dex-ptr-2
448 dex-bank
449 _
450 & data]]
451 (split-with (partial not= 0x50) data)]
452 (recur (dec n)
453 (assoc stats
454 (pokedex-names (- pkmn-count (dec n)))
455 {:species
456 (format-name (character-codes->str species))
457 :height-ft
458 height-ft
459 :height-in
460 height-in
461 :weight
462 (/ (low-high weight-1 weight-2) 10.)
464 ;; :text
465 ;; (character-codes->str
466 ;; (take-while
467 ;; (partial not= 0x50)
468 ;; (drop
469 ;; (+ 0xB8000
470 ;; -0x4000
471 ;; (low-high dex-ptr-1 dex-ptr-2))
472 ;; rom)))
473 })
475 data)
478 )))
480 pkmn-count
481 {}
482 (drop 0x40687 rom))) ))
483 #+end_src
485 #+results: dex-stats
486 : #'com.aurellem.gb.hxc/hxc-pokedex-stats
488 ** Species synopses
490 #+name: dex-text
491 #+begin_src clojure
492 (def hxc-pokedex-text-raw
493 "The hardcoded pokedex entries in memory. List begins at
494 ROM@B8000, shortly before move names."
495 (hxc-thunk-words 0xB8000 14754))
500 (defn hxc-pokedex-text
501 "The hardcoded pokedex entries in memory, presented as an
502 associative hash map. List begins at ROM@B8000."
503 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))
504 ([rom]
505 (zipmap
506 (hxc-pokedex-names rom)
507 (cons nil ;; for missingno.
508 (hxc-pokedex-text-raw rom)))))
509 #+end_src
512 ** Pok\eacute{}mon cries
513 #+name: pokecry
514 #+begin_src clojure
515 (defn hxc-cry
516 "The pokemon cry data in internal order. List begins at ROM@39462"
517 ([](hxc-cry com.aurellem.gb.gb-driver/original-rom))
518 ([rom]
519 (zipmap
520 (hxc-pokenames rom)
521 (map
522 (fn [[cry-id pitch length]]
523 {:cry-id cry-id
524 :pitch pitch
525 :length length}
526 )
527 (partition 3
528 (drop 0x39462 rom))))))
530 (defn hxc-cry-groups
531 ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom))
532 ([rom]
533 (map #(mapv first
534 (filter
535 (fn [[k v]]
536 (= % (:cry-id v)))
537 (hxc-cry)))
538 ((comp
539 range
540 count
541 set
542 (partial map :cry-id)
543 vals
544 hxc-cry)
545 rom))))
548 (defn cry-conversion!
549 "Convert Porygon's cry in ROM to be the cry of the given pokemon."
550 [pkmn]
551 (write-rom!
552 (rewrite-memory
553 (vec(rom))
554 0x3965D
555 (map second
556 ((hxc-cry) pkmn)))))
558 #+end_src
560 ** COMMENT Names of permanent stats
561 0DD4D-DD72
563 * Items
564 ** Item names
566 *** See the data
567 #+begin_src clojure :exports both :results output
568 (ns com.aurellem.gb.hxc
569 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
570 constants))
571 (:import [com.aurellem.gb.gb_driver SaveState]))
573 (println (take 100 (drop 0x045B7 (rom))))
575 (println
576 (partition-by
577 (partial = 0x50)
578 (take 100 (drop 0x045B7 (rom)))))
580 (println
581 (map character-codes->str
582 (partition-by
583 (partial = 0x50)
584 (take 100 (drop 0x045B7 (rom))))))
587 #+end_src
589 #+results:
590 : (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)
591 : ((140 128 146 147 132 145 127 129 128 139 139) (80) (148 139 147 145 128 127 129 128 139 139) (80) (134 145 132 128 147 127 129 128 139 139) (80) (143 142 138 186 127 129 128 139 139) (80) (147 142 150 141 127 140 128 143) (80) (129 136 130 152 130 139 132) (80) (230 230 230 230 230) (80) (146 128 133 128 145 136 127 129 128 139 139) (80) (143 142 138 186 131 132 151) (80) (140 142 142 141 127 146 147 142 141 132) (80) (128 141))
592 : (MASTER BALL # ULTRA BALL # GREAT BALL # POKé BALL # TOWN MAP # BICYCLE # ????? # SAFARI BALL # POKéDEX # MOON STONE # AN)
594 *** Automatically grab the data
595 #+name: item-names
596 #+begin_src clojure
598 (def hxc-items-raw
599 "The hardcoded names of the items in memory. List begins at
600 ROM@045B7"
601 (hxc-thunk-words 0x45B7 870))
603 (def hxc-items
604 "The hardcoded names of the items in memory, presented as
605 keywords. List begins at ROM@045B7. See also, hxc-items-raw."
606 (comp (partial map format-name) hxc-items-raw))
607 #+end_src
609 ** Item prices
611 ***
612 #+begin_src clojure :exports both :results output
613 (ns com.aurellem.gb.hxc
614 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
615 constants))
616 (:import [com.aurellem.gb.gb_driver SaveState]))
618 (println (take 90 (drop 0x4495 (rom))))
620 (println
621 (partition 3
622 (take 90 (drop 0x4495 (rom)))))
624 (println
625 (partition 3
626 (map hex
627 (take 90 (drop 0x4495 (rom))))))
629 (println
630 (map decode-bcd
631 (map butlast
632 (partition 3
633 (take 90 (drop 0x4495 (rom)))))))
635 (println
636 (map
637 vector
638 (hxc-items (rom))
639 (map decode-bcd
640 (map butlast
641 (partition 3
642 (take 90 (drop 0x4495 (rom))))))))
648 #+end_src
650 #+results:
651 : (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)
652 : ((0 0 0) (18 0 0) (6 0 0) (2 0 0) (0 0 0) (0 0 0) (0 0 0) (16 0 0) (0 0 0) (0 0 0) (1 0 0) (2 80 0) (2 80 0) (2 0 0) (2 0 0) (48 0 0) (37 0 0) (21 0 0) (7 0 0) (3 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (5 80 0) (3 80 0))
653 : ((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))
654 : (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)
655 : ([: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])
658 ***
659 #+name: item-prices
660 #+begin_src clojure
661 (defn hxc-item-prices
662 "The hardcoded list of item prices in memory. List begins at ROM@4495"
663 ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))
664 ([rom]
665 (let [items (hxc-items rom)
666 price-size 3]
667 (zipmap items
668 (map (comp
669 ;; zero-cost items are "priceless"
670 #(if (zero? %) :priceless %)
671 decode-bcd butlast)
672 (partition price-size
673 (take (* price-size (count items))
674 (drop 0x4495 rom))))))))
675 #+end_src
676 ** Vendor inventories
678 #+name: item-vendors
679 #+begin_src clojure
680 (defn hxc-shops
681 ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))
682 ([rom]
683 (let [items (zipmap (range) (hxc-items rom))
685 ;; temporarily softcode the TM items
686 items (into
687 items
688 (map (juxt identity
689 (comp keyword
690 (partial str "tm-")
691 (partial + 1 -200)
692 ))
693 (take 200 (drop 200 (range)))))
695 ]
697 ((fn parse-shop [coll [num-items & items-etc]]
698 (let [inventory (take-while
699 (partial not= 0xFF)
700 items-etc)
701 [separator & items-etc] (drop num-items (rest items-etc))]
702 (if (= separator 0x50)
703 (map (partial mapv (comp items dec)) (conj coll inventory))
704 (recur (conj coll inventory) items-etc)
705 )
706 ))
708 '()
709 (drop 0x233C rom))
712 )))
713 #+end_src
715 #+results: item-vendors
716 : #'com.aurellem.gb.hxc/hxc-shops
720 * Types
721 ** Names of types
723 *** COMMENT Pointers to type names
724 #+begin_src clojure :exports both :results output
725 (map (comp character-codes->str #(take-while (partial not= 80) (drop % (rom))) (partial + 0x20000) (partial apply low-high)) (partition 2 (take 54 (drop 0x27D63 (rom)))))
726 #+end_src
729 ***
730 #+begin_src clojure :exports both :results output
731 (ns com.aurellem.gb.hxc
732 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
733 constants))
734 (:import [com.aurellem.gb.gb_driver SaveState]))
736 (println (take 90 (drop 0x27D99 (rom))))
738 (println
739 (partition-by (partial = 0x50)
740 (take 90 (drop 0x27D99 (rom)))))
742 (println
743 (map character-codes->str
744 (partition-by (partial = 0x50)
745 (take 90 (drop 0x27D99 (rom))))))
747 #+end_src
749 #+results:
750 : (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)
751 : ((141 142 145 140 128 139) (80) (133 136 134 135 147 136 141 134) (80) (133 139 152 136 141 134) (80) (143 142 136 146 142 141) (80) (133 136 145 132) (80) (150 128 147 132 145) (80) (134 145 128 146 146) (80) (132 139 132 130 147 145 136 130) (80) (143 146 152 130 135 136 130) (80) (136 130 132) (80) (134 145 142 148 141 131) (80) (145 142 130 138) (80) (129 136 145 131) (80) (129 148 134) (80) (134))
752 : (NORMAL # FIGHTING # FLYING # POISON # FIRE # WATER # GRASS # ELECTRIC # PSYCHIC # ICE # GROUND # ROCK # BIRD # BUG # G)
755 ***
756 #+name: type-names
757 #+begin_src clojure
758 (def hxc-types
759 "The hardcoded type names in memory. List begins at ROM@27D99,
760 shortly before hxc-titles."
761 (hxc-thunk-words 0x27D99 102))
763 #+end_src
765 ** Type effectiveness
766 ***
767 #+begin_src clojure :exports both :results output
768 (ns com.aurellem.gb.hxc
769 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
770 constants))
771 (:import [com.aurellem.gb.gb_driver SaveState]))
774 ;; POKEMON TYPES
776 (println pkmn-types) ;; these are the pokemon types
777 (println (map vector (range) pkmn-types)) ;; each type has an id number.
779 (newline)
784 ;;; TYPE EFFECTIVENESS
786 (println (take 15 (drop 0x3E62D (rom))))
787 (println (partition 3 (take 15 (drop 0x3E62D (rom)))))
789 (println
790 (map
791 (fn [[atk-type def-type multiplier]]
792 (list atk-type def-type (/ multiplier 10.)))
794 (partition 3
795 (take 15 (drop 0x3E62D (rom))))))
798 (println
799 (map
800 (fn [[atk-type def-type multiplier]]
801 [
802 (get pkmn-types atk-type)
803 (get pkmn-types def-type)
804 (/ multiplier 10.)
805 ])
807 (partition 3
808 (take 15 (drop 0x3E62D (rom))))))
810 #+end_src
812 #+results:
813 : [: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]
814 : ([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])
815 :
816 : (0 5 5 0 8 0 8 8 20 20 7 20 20 5 5)
817 : ((0 5 5) (0 8 0) (8 8 20) (20 7 20) (20 5 5))
818 : ((0 5 0.5) (0 8 0.0) (8 8 2.0) (20 7 2.0) (20 5 0.5))
819 : ([:normal :rock 0.5] [:normal :ghost 0.0] [:ghost :ghost 2.0] [:fire :bug 2.0] [:fire :rock 0.5])
822 ***
824 #+name: type-advantage
825 #+begin_src clojure
826 (defn hxc-advantage
827 ;; in-game multipliers are stored as 10x their effective value
828 ;; to allow for fractional multipliers like 1/2
830 "The hardcoded type advantages in memory, returned as tuples of
831 atk-type def-type multiplier. By default (i.e. if not listed here),
832 the multiplier is 1. List begins at 0x3E62D."
833 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))
834 ([rom]
835 (map
836 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))
837 (get pkmn-types def (hex def))
838 (/ mult 10)])
839 (partition 3
840 (take-while (partial not= 0xFF)
841 (drop 0x3E62D rom))))))
842 #+end_src
846 * Moves
847 ** Names of moves
848 *** See the data
849 #+begin_src clojure :exports both :results output
850 (ns com.aurellem.gb.hxc
851 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
852 constants))
853 (:import [com.aurellem.gb.gb_driver SaveState]))
855 (println (take 100 (drop 0xBC000 (rom))))
857 (println
858 (partition-by
859 (partial = 0x50)
860 (take 100 (drop 0xBC000 (rom)))))
862 (println
863 (map character-codes->str
864 (partition-by
865 (partial = 0x50)
866 (take 100 (drop 0xBC000 (rom))))))
869 #+end_src
871 #+results:
872 : (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)
873 : ((143 142 148 141 131) (80) (138 128 145 128 147 132 127 130 135 142 143) (80) (131 142 148 129 139 132 146 139 128 143) (80) (130 142 140 132 147 127 143 148 141 130 135) (80) (140 132 134 128 127 143 148 141 130 135) (80) (143 128 152 127 131 128 152) (80) (133 136 145 132 127 143 148 141 130 135) (80) (136 130 132 127 143 148 141 130 135) (80) (147 135 148 141 131 132 145 143 148 141 130 135) (80) (146 130 145 128 147 130))
874 : (POUND # KARATE CHOP # DOUBLESLAP # COMET PUNCH # MEGA PUNCH # PAY DAY # FIRE PUNCH # ICE PUNCH # THUNDERPUNCH # SCRATC)
876 *** Automatically grab the data
878 #+name: move-names
879 #+begin_src clojure
880 (def hxc-move-names
881 "The hardcoded move names in memory. List begins at ROM@BC000"
882 (hxc-thunk-words 0xBC000 1551))
883 #+end_src
885 ** Properties of moves
887 #+name: move-data
888 #+begin_src clojure
889 (defn hxc-move-data
890 "The hardcoded (basic (move effects)) in memory. List begins at
891 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id
892 :fx-txt}. The move descriptions are handwritten, not hardcoded."
893 ([]
894 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))
895 ([rom]
896 (let [names (vec (hxc-move-names rom))
897 move-count (count names)
898 move-size 6
899 types pkmn-types ;;; !! hardcoded types
900 ]
901 (zipmap (map format-name names)
902 (map
903 (fn [[idx effect power type-id accuracy pp]]
904 {:name (names (dec idx))
905 :power power
906 :accuracy accuracy
907 :pp pp
908 :type (types type-id)
909 :fx-id effect
910 :fx-txt (get move-effects effect)
911 }
912 )
914 (partition move-size
915 (take (* move-size move-count)
916 (drop 0x38000 rom))))))))
920 (defn hxc-move-data*
921 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."
922 ([]
923 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))
924 ([rom]
925 (let [names (vec (hxc-move-names rom))
926 move-count (count names)
927 move-size 6
928 format-name (fn [s]
929 (keyword (.toLowerCase
930 (apply str
931 (map #(if (= % \space) "-" %) s)))))
932 ]
933 (zipmap (map format-name names)
934 (map
935 (fn [[idx effect power type accuracy pp]]
936 {:name (names (dec idx))
937 :power power
938 :accuracy (hex accuracy)
939 :pp pp
940 :fx-id (hex effect)
941 :fx-txt (get move-effects effect)
942 }
943 )
945 (partition move-size
946 (take (* move-size move-count)
947 (drop 0x38000 rom))))))))
949 #+end_src
951 ** TM and HM moves
952 ***
953 #+begin_src clojure :exports both :results output
954 (ns com.aurellem.gb.hxc
955 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
956 constants))
957 (:import [com.aurellem.gb.gb_driver SaveState]))
960 (println (hxc-move-names))
961 (println (map vector (rest(range)) (hxc-move-names)))
963 (newline)
965 (println (take 55 (drop 0x1232D (rom))))
967 (println
968 (interpose "."
969 (map
970 (zipmap (rest (range)) (hxc-move-names))
971 (take 55 (drop 0x1232D (rom))))))
973 #+end_src
975 #+results:
976 : (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)
977 : ([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])
978 :
979 : (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)
980 : (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)
983 ***
984 #+name: machines
985 #+begin_src clojure
986 (defn hxc-machines
987 "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."
988 ([] (hxc-machines
989 com.aurellem.gb.gb-driver/original-rom))
990 ([rom]
991 (let [moves (hxc-move-names rom)]
992 (zipmap
993 (range)
994 (take-while
995 (comp not nil?)
996 (map (comp
997 format-name
998 (zipmap
999 (range)
1000 moves)
1001 dec)
1002 (take 100
1003 (drop 0x1232D rom))))))))
1005 #+end_src
1011 ** COMMENT Status ailments
1014 * NPC Trainers
1016 ** Trainer Pok\eacute{}mon
1017 # http://hax.iimarck.us/topic/103/
1018 There are two formats for specifying lists of NPC PPok\eacute{}mon:
1019 - If all the Pok\eacute{}mon will have the same level, the format is
1020 - Level (used for all the Pok\eacute{}mon)
1021 - Any number of Pok\eacute{}mon internal ids.
1022 - 0x00, to indicate end-of-list.
1023 - Otherwise, all the Pok\eacute{}mon will have their level
1024 specified. The format is
1025 - 0xFF, to indicate that we will be specifying the levels individually[fn::Because 0xFF is a
1026 forbidden level within the usual gameplay discipline, the game
1027 makers could safely use 0xFF as a mode indicator.].
1028 - Any number of alternating Level/Pokemon pairs
1029 - 0x00, to indicate end-of-list.
1031 *** Get the pointers
1032 *** See the data
1033 #+begin_src clojure :exports both :results output
1034 (ns com.aurellem.gb.hxc
1035 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1036 constants))
1037 (:import [com.aurellem.gb.gb_driver SaveState]))
1039 (->>
1040 (rom)
1041 (drop 0x39E2F)
1042 (take 21)
1043 (println))
1046 (->>
1047 (rom)
1048 (drop 0x39E2F)
1049 (take 21)
1050 (partition-by zero?)
1051 (take-nth 2)
1052 (println))
1056 (let
1057 [pokenames
1058 (zipmap
1059 (rest (range))
1060 (hxc-pokenames-raw))]
1062 (->>
1063 (rom)
1064 (drop 0x39E2F)
1065 (take 21) ;; (1922 in all)
1066 (partition-by zero?)
1067 (take-nth 2)
1068 (map
1069 (fn parse-team [[mode & team]]
1070 (if (not= 0xFF mode)
1071 (mapv
1072 #(hash-map :level mode :species (pokenames %))
1073 team)
1075 (mapv
1076 (fn [[lvl id]] (hash-map :level lvl :species (pokenames id)))
1077 (partition 2 team)))))
1079 (println)))
1083 #+end_src
1085 #+results:
1086 : (11 165 108 0 14 5 0 10 165 165 107 0 14 165 108 107 0 15 165 5 0)
1087 : ((11 165 108) (14 5) (10 165 165 107) (14 165 108 107) (15 165 5))
1088 : ([{:species RATTATA, :level 11} {:species EKANS, :level 11}] [{:species SPEAROW, :level 14}] [{:species RATTATA, :level 10} {:species RATTATA, :level 10} {:species ZUBAT, :level 10}] [{:species RATTATA, :level 14} {:species EKANS, :level 14} {:species ZUBAT, :level 14}] [{:species RATTATA, :level 15} {:species SPEAROW, :level 15}])
1090 * Places
1091 ** Names of places
1093 #+name: places
1094 #+begin_src clojure
1095 (def hxc-places
1096 "The hardcoded place names in memory. List begins at
1097 ROM@71500. [Cinnabar/Celadon] Mansion seems to be dynamically calculated."
1098 (hxc-thunk-words 0x71500 560))
1099 #+end_src
1101 *** See it work
1102 #+begin_src clojure :exports both :results output
1103 (println (hxc-places))
1104 #+end_src
1106 #+results:
1107 : (PALLET TOWN VIRIDIAN CITY PEWTER CITY CERULEAN CITY LAVENDER TOWN VERMILION CITY CELADON CITY FUCHSIA CITY CINNABAR ISLAND INDIGO PLATEAU SAFFRON CITY ROUTE 1 ROUTE 2 ROUTE 3 ROUTE 4 ROUTE 5 ROUTE 6 ROUTE 7 ROUTE 8 ROUTE 9 ROUTE 10 ROUTE 11 ROUTE 12 ROUTE 13 ROUTE 14 ROUTE 15 ROUTE 16 ROUTE 17 ROUTE 18 SEA ROUTE 19 SEA ROUTE 20 SEA ROUTE 21 ROUTE 22 ROUTE 23 ROUTE 24 ROUTE 25 VIRIDIAN FOREST MT.MOON ROCK TUNNEL SEA COTTAGE S.S.ANNE [POKE]MON LEAGUE UNDERGROUND PATH [POKE]MON TOWER SEAFOAM ISLANDS VICTORY ROAD DIGLETT's CAVE ROCKET HQ SILPH CO. [0x4A] MANSION SAFARI ZONE)
1109 ** Wild Pok\eacute{}mon demographics
1110 #+name: wilds
1111 #+begin_src clojure
1115 (defn hxc-ptrs-wild
1116 "A list of the hardcoded wild encounter data in memory. Pointers
1117 begin at ROM@0CB95; data begins at ROM@0x04D89"
1118 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))
1119 ([rom]
1120 (let [ptrs
1121 (map (fn [[a b]] (+ a (* 0x100 b)))
1122 (take-while (partial not= (list 0xFF 0xFF))
1123 (partition 2 (drop 0xCB95 rom))))]
1124 ptrs)))
1128 (defn hxc-wilds
1129 "A list of the hardcoded wild encounter data in memory. Pointers
1130 begin at ROM@0CB95; data begins at ROM@0x04D89"
1131 ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))
1132 ([rom]
1133 (let [pokenames (zipmap (range) (hxc-pokenames rom))]
1134 (map
1135 (partial map (fn [[a b]] {:species (pokenames (dec b)) :level
1136 a}))
1137 (partition 10
1139 (take-while (comp (partial not= 1)
1140 first)
1141 (partition 2
1142 (drop 0xCD8C rom))
1144 ))))))
1146 #+end_src
1151 ** Map data
1153 # http://www.pokecommunity.com/showthread.php?t=235311
1154 # http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes
1156 #+name map
1157 #+begin_src clojure :exports both :results output
1158 (ns com.aurellem.gb.hxc
1159 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1160 constants))
1161 (:import [com.aurellem.gb.gb_driver SaveState]))
1164 (defn parse-header-tileset
1165 [[bank# ;; memory bank for blocks & tileset
1167 blocks-lo ;; structure
1168 blocks-hi
1170 tileset-lo ;; style
1171 tileset-hi
1173 collision-lo ;; collision info
1174 collision-hi
1176 talk-here-1 ;; positions of up to three
1177 talk-here-2 ;; talk-over-countertop tiles
1178 talk-here-3 ;; --- 0xFF if unused.
1180 grass ;; grass tile --- 0xFF if unused
1182 animation-flags ;; settings for animation
1183 & _]]
1185 [bank#
1187 blocks-lo ;; structure
1188 blocks-hi
1190 tileset-lo ;; style
1191 tileset-hi
1193 collision-lo ;; collision info
1194 collision-hi
1196 talk-here-1 ;; positions of up to three
1197 talk-here-2 ;; talk-over-countertop tiles
1198 talk-here-3 ;; --- 0xFF if unused.
1200 grass ;; grass tile --- 0xFF if unused
1202 animation-flags ;; settings for animation
1203 ])
1207 (defn parse-header-map
1208 [start]
1210 (let [connection-size 11
1212 [tileset-index
1213 map-height
1214 map-width
1215 layout-lo
1216 layout-hi
1217 text-lo
1218 text-hi
1219 script-lo
1220 script-hi
1221 adjacency-flags ;; x x x x N S W E
1222 & etc]
1223 (drop start (rom))
1225 [east? west? south? north?]
1226 (bit-list adjacency-flags)
1228 [connections object-data]
1229 (split-at
1230 (* connection-size (+ east? west? south? north?))
1231 etc)
1233 connections
1234 (partition connection-size connections)
1240 (ptr->offset
1242 (low-high layout-lo layout-hi))
1245 ))
1246 #+end_src
1248 #+results:
1253 * Appendices
1254 ** Mapping the ROM
1255 # D3AD: Script:Use Pokeball?
1257 | ROM address (hex) | Description | Format | Example |
1258 |-----------------------+-----------------+-----------------+-----------------|
1259 | | <15> | <15> | <15> |
1260 | 01823-0184A | Important prefix strings. | Variable-length strings, separated by 0x50. | TM#TRAINER#PC#ROCKET#POK\eacute{}#... |
1261 | 0233C- | Shop inventories. | | |
1262 | 02F47- | (?) Move ids of some HM moves. | One byte per move id | 0x0F 0x13 0x39 0x46 0x94 0xFF, the move ids of CUT, FLY, SURF, STRENGTH, FLASH, then cancel. |
1263 | 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. |
1264 | 04524-04527 | (unconfirmed) possibly the bike price in Cerulean. | | |
1265 | 045B7-0491E | Names of the items in memory. | Variable-length item names (strings of character codes). Names are separated by a single 0x50 character. | MASTER BALL#ULTRA BALL#... |
1266 | 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). |
1267 |-----------------------+-----------------+-----------------+-----------------|
1268 | 05DD2-05DF2 | Menu text for player info. | | PLAYER [newline] BADGES [nelwine] POK\Eacute{}DEX [newline] TIME [0x50] |
1269 | 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. |
1270 | 06698- | ? Background music. | | |
1271 | 7550-7570 | Menu options for map directions[fn:unused:According to [[http://tcrf.net/Pok%C3%A9mon_Red_and_Blue#NORTH.2FWEST.2FSOUTH.2FEAST][The Cutting Room Floor]], this data is unused. ]. | Variable-length strings. | NORTH [newline] WEST [0x50] SOUTH [newline] EAST [0x50] NORTH [newline] EAST[0x50] |
1272 | 7570-757D | Menu options for trading Pok\eacute{}mon | | TRADE [newline] CANCEL [0x50] |
1273 | 757D-758A | Menu options for healing Pok\eacute{}mon | | HEAL [newline] CANCEL [0x50] |
1274 | 7635- | Menu options for selected Pok\eacute{}mon (Includes names of out-of-battle moves). | Variable-length strings separated by 0x50. | CUT [0x50] FLY [0x50] SURF [0x50] STRENGTH [0x50] FLASH [0x50] DIG [0x50] TELEPORT [0x50] SOFTBOILED [0x50] STATS [newline] SWITCH [newline] CANCEL [0x50] |
1275 | 7AF0-8000 | (empty space) | | 0 0 0 0 0 ... |
1276 | 0822E-082F? | Pointers to background music, part I. | | |
1277 | 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). |
1278 |-----------------------+-----------------+-----------------+-----------------|
1279 | 0DACB. | Amount of HP restored by Soda Pop | The HP consists of a single numerical byte. | 60 |
1280 | 0DACF. | Amount of HP restored by Lemonade | " | 80 |
1281 | 0DAD5. | Amount of HP restored by Fresh Water | " | 50 |
1282 | 0DADB. | Amount of HP restored by Hyper Potion. | " | 200 |
1283 | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 |
1284 | 0DAE3. | Amount of HP restored by Potion. | " | 20 |
1285 |-----------------------+-----------------+-----------------+-----------------|
1286 | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# |
1287 |-----------------------+-----------------+-----------------+-----------------|
1288 | 0DE2F. | Duration of Repel. | A single byte, representing the number of steps you can take before Super Repel wears off. | 100 |
1289 | 0DF39. | Duration of Super Repel. | " | 200 |
1290 | 0DF3E. | Duration of Max Repel. | " | 250 |
1291 |-----------------------+-----------------+-----------------+-----------------|
1292 | 1164B- | Terminology for the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | TYPE1[newline]TYPE2[newline] *№*,[newline]OT,[newline][0x50]STATUS,[0x50]OK |
1293 | 116DE- | Terminology for permanent stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | ATTACK[newline]DEFENSE[newline]SPEED[newline]SPECIAL[0x50] |
1294 | 11852- | Terminology for current stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | EXP POINTS[newline]LEVEL UP[0x50] |
1295 | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1296 | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1297 | 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), ... |
1298 |-----------------------+-----------------+-----------------+-----------------|
1299 | 27D56 & 27D57. | Pointer to the pointers to type names. | A single low-byte, high-byte pair. | 0x63 0x7D, corresponding to location 27D63\mdash{} the start of the next entry. |
1300 | 27D63-27D99 | Pointers to type names. | Each point is a low-byte, high-byte pair. The type names follows immediately after this section; see below. | The first pointer is [0x99 0x7D], corresponding to the location 27D99 ("NORMAL"). |
1301 | 27D99-27DFF | Names of the Pok\eacute{}mon types. | Variable-length type names (strings of character codes). Names are separated by a single 0x50 character. | NORMAL#FIGHTING#... |
1302 | 27DFF-27E77 | ? | 120 bytes of unknown data. | |
1303 | 27E77- | Trainer title names. | Variable-length names separated by 0x50. | YOUNGSTER#BUG CATCHER#LASS#... |
1304 | 34000- | | | |
1305 | 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. |
1306 | 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. | | |
1307 | 39462- | The Pok\eacute{}mon cry data. | Fixed-length (3 byte) descriptions of cries. | |
1308 |-----------------------+-----------------+-----------------+-----------------|
1309 | 3997D-39B05 | Trainer titles (extended; see 27E77). This list includes strictly more trainers, seemingly at random inserted into the list from 27E77.[fn::The names added are in bold: YOUNGSTER, BUG CATCHER, LASS, *SAILOR*, JR TRAINER(m), JR TRAINER(f), POK\eacute{}MANIAC, SUPER NERD, *HIKER*, *BIKER*, BURGLAR, ENGINEER, JUGGLER, *FISHERMAN*, SWIMMER, *CUE BALL*, *GAMBLER*, BEAUTY, *PSYCHIC*, ROCKER, JUGGLER (again), *TAMER*, *BIRDKEEPER*, BLACKBELT, *RIVAL1*, PROF OAK, CHIEF, SCIENTIST, *GIOVANNI*, ROCKET, COOLTRAINER(m), COOLTRAINER(f), *BRUNO*, *BROCK*, *MISTY*, *LT. SURGE*, *ERIKA*, *KOGA*, *BLAINE*, *SABRINA*, *GENTLEMAN*, *RIVAL2*, *RIVAL3*, *LORELEI*, *CHANNELER*, *AGATHA*, *LANCE*.] | | |
1310 | 39B05-39DD0. | unknown | | |
1311 | 39DD1-39E2E | Pointers to trainer Pok\eacute{}mon | Pairs of low-high bits. | The first pair is 0x2F 0x5E, which corresponds to memory location 5E2F relative to this 38000-3C000 bank, i.e.[fn::For details about how relative bank pointers work, see the relevant Appendix.] position 39E2F overall. |
1312 | 39E2F-3A5B2 | Trainer Pok\eacute{}mon | Specially-formatted lists of various length, separated by 0x00. If the list starts with 0xFF, the rest of the list will alternate between levels and internal-ids. Otherwise, start of the list is the level of the whole team, and the rest of the list is internal-ids. | The first entry is (11 165 108 0), which means a level 11 team consisting of Rattata and Ekans. The entry for MISTY is (255 18 27 21 152 0), which means a team of various levels consisting of level 18 Staryu and level 21 Starmie. [fn::Incidentally, if you want to change your rival's starter Pok\eacute{}mon, it's enough just to change its species in all of your battles with him.].) |
1313 | 3B1E5-3B361 | Pointers to evolution/learnset data. | One high-low byte pair for each of the 190 Pok\eacute{}mon in internal order. | |
1314 |-----------------------+-----------------+-----------------+-----------------|
1315 | 3B361-3BBAA | Evolution and learnset data. [fn::Evolution data consists of how to make Pok\eacute{}mon evolve, and what they evolve into. Learnset data consists of the moves that Pok\eacute{}mon learn as they level up.] | Variable-length evolution information (see below), followed by a list of level/move-id learnset pairs. | |
1316 | 3BBAA-3C000 | (empty) | | 0 0 0 0 ... |
1317 |-----------------------+-----------------+-----------------+-----------------|
1318 | 3D131-3D133 | The inventory of both OLD MAN and PROF. OAK when they battle for you. | Pairs of [item-id quantity], terminated by 0xFF. | (0x04 0x01 0xFF) They only have one Pok\eacute{}ball [fn::If you give them any ball, OAK will catch the enemy Pok\eacute{}mon and OLD MAN will miss. (OLD MAN misses even if he throws a MASTER BALL, which is a sight to see!) If you give them some other item first in the list, you'll be able to use that item normally but then you'll trigger the Safari Zone message: Pa will claim you're out of SAFARI BALLs and the battle will end. If you engage in either an OLD MAN or OAK battle with a Gym Leader, you will [1] get reprimanded if you try to throw a ball [2] incur the Safari Zone message [3] automatically win no matter which item you use [4] earn whichever reward they give you as usual [5] permanently retain the name OLD MAN / PROF. OAK.]. |
1319 | 3D6C7-3D6D6 | Two miscellaneous strings. | Variable length, separated by 0x50 | Disabled!#TYPE |
1320 |-----------------------+-----------------+-----------------+-----------------|
1321 | 40252-4027B | Pok\eacute{}dex menu text | Variable-length strings separated by 0x50. | SEEN#OWN#CONTENTS#... |
1322 | 40370-40386 | Important constants for Pok\eacute{}dex entries | | HT _ _ *?′??″* [newline] WT _ _ _ *???* lb [0x50] *POK\Eacute{}* [0x50] |
1323 | 40687-41072 | Species data from the Pok\eacute{}dex: species name, height, weight, etc. | Variable-length species names, followed by 0x50, followed by fixed-length height/weight/etc. data. | The first entry is (*146 132 132 131*, 80, *2 4*, *150 0*, 23, 0 64 46, 80), which are the the stats of Bulbasaur: the first entry spells "SEED", then 0x80, then the height (2' 4"), then the weight (formatted as a low-high byte pair), then various Pokédex pointer data (see elsewhere). |
1324 | 41072- | Pok\eacute{} placeholder species, "???" | | |
1325 |-----------------------+-----------------+-----------------+-----------------|
1326 | 410B1-4116F | A conversion table between internal order and Pokedex order. | 190 bytes, corresponding to the Pok\eacute{}dex numbers of the 190 Pok\eacute{}mon listed in internal order. All =MISSINGNO.= are assigned a Pok\eacute{}dex number of 0. | The first few entries are (112 115 32 35 21 100 34 80 2 ...), which are the Pok\eacute{}dex numbers of Rhydon, Kangaskhan, Nidoran(m), Clefairy, Spearow, Voltorb, Nidoking, Slobrow, and Ivysaur. |
1327 |-----------------------+-----------------+-----------------+-----------------|
1328 | 509B4-509E0 | Saffron City's adjacency info. | Four adjacency lists, each 11 bytes long. (For more info on adjacency lists a.k.a. connection data, see [[http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes][here]]) | The first adjacency list is (0x10 0x70 0x46 0xF0 0xC6 0x0A 0x0A 0x23 0xF6 0x09 0xC8) |
1329 |-----------------------+-----------------+-----------------+-----------------|
1330 | 527BA-527DB | The costs and kinds of prizes from Celadon Game Corner. | The following pattern repeats three times, once per window[fn::For the first two prize lists, ids are interpreted as Pok\eacute{}mon ids. For the last prize list, ids are (somehow) interpreted as item ids.]: Internal ids / 0x50 / Prices (two bytes of BCD)/ 0x50. | (0x94 0x52 0x65 0x50) Abra Vulpix Wigglytuff (0x02 0x30 0x10 0x00 0x26 0x80) 230C, 1000C, 2680C |
1331 | 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]... |
1332 |-----------------------+-----------------+-----------------+-----------------|
1333 | 70295- | Hall of fame | The text "HALL OF FAME" | |
1334 | 70442- | Play time/money | The text "PLAY TIME [0x50] MONEY" | |
1335 | 71500-7174B | Names of places. | Variable-length place names (strings), separated by 0x50. | PALLET TOWN#VIRIDIAN CITY#PEWTER CITY#CERULEAN CITY#... |
1336 | 71C1E-71CAA (approx.) | Tradeable NPC Pok\eacute{}mon. | Internal ID, followed by nickname (11 chars; extra space padded by 0x50). Some of the Pokemon have unknown extra data around the id. | The first entry is [0x76] "GURIO######", corresponding to a Dugtrio named "GURIO". |
1337 | 7C249-7C2?? | Pointers to background music, pt II. | | |
1338 |-----------------------+-----------------+-----------------+-----------------|
1339 | 98000-B7190 | Dialogue and other messsages. | Variable-length strings. | |
1340 | B7190-B8000 | (empty space) | | 0 0 0 0 0 ... |
1341 | B8000-BC000 | The text of each Pok\eacute{}mon's Pok\eacute{}dex entry. | Variable-length descriptions (strings) in Pok\eacute{}dex order, separated by 0x50. These entries use the special characters *0x49* (new page), *0x4E* (new line), and *0x5F* (end entry). | The first entry (Bulbasaur's) is: "It can go for days [0x4E] without eating a [0x4E] single morsel. [0x49] In the bulb on [0x4E] its back, it [0x4E] stores energy [0x5F] [0x50]." |
1342 | BC000-BC60F | Move names. | Variable-length move names, separated by 0x50. The moves are in internal order. | POUND#KARATE CHOP#DOUBLESLAP#COMET PUNCH#... |
1343 | BC610-BD000 | (empty space) | | 0 0 0 0 0 ... |
1344 | E8000-E876C | Names of the \ldquo{}190\rdquo{} species of Pok\eacute{}mon in memory. | Fixed length (10-letter) Pok\eacute{}mon names. Any extra space is padded with the character 0x50. The names are in \ldquo{}internal order\rdquo{}. | RHYDON####KANGASKHANNIDORAN♂#... |
1345 |-----------------------+-----------------+-----------------+-----------------|
1346 | E9BD5- | The text PLAY TIME (see above, 70442) | | |
1347 #+TBLFM:
1350 ** Understanding memory banks and pointers
1351 #+begin_src clojure
1353 (defn endian-flip
1354 "Flip the bytes of the two-byte number."
1355 [n]
1356 (assert (< n 0xFFFF))
1357 (+ (* 0x100 (rem n 0x100))
1358 (int (/ n 0x100))))
1361 (defn offset->ptr
1362 "Convert an offset into a little-endian pointer."
1363 [n]
1364 (->
1366 (rem 0x10000) ;; take last four bytes
1367 (rem 0x4000) ;; get relative offset from the start of the bank
1368 (+ 0x4000)
1369 endian-flip))
1371 (defn offset->bank
1372 "Get the bank of the offset."
1373 [n]
1374 (int (/ n 0x4000)))
1376 (defn ptr->offset
1377 "Convert a two-byte little-endian pointer into an offset."
1378 [bank ptr]
1379 (->
1380 ptr
1381 endian-flip
1382 (- 0x4000)
1383 (+ (* 0x4000 bank))
1384 ))
1386 (defn same-bank-offset
1387 "Convert a ptr into an absolute offset by using the bank of the reference."
1388 [reference ptr]
1389 (ptr->offset
1390 (offset->bank reference)
1391 ptr))
1392 #+end_src
1395 ** Internal Pok\eacute{}mon IDs
1396 ** Type IDs
1398 #+name: type-ids
1399 #+begin_src clojure
1400 (def pkmn-types
1401 [:normal ;;0
1402 :fighting ;;1
1403 :flying ;;2
1404 :poison ;;3
1405 :ground ;;4
1406 :rock ;;5
1407 :bird ;;6
1408 :bug ;;7
1409 :ghost ;;8
1410 :A
1411 :B
1412 :C
1413 :D
1414 :E
1415 :F
1416 :G
1417 :H
1418 :I
1419 :J
1420 :K
1421 :fire ;;20 (0x14)
1422 :water ;;21 (0x15)
1423 :grass ;;22 (0x16)
1424 :electric ;;23 (0x17)
1425 :psychic ;;24 (0x18)
1426 :ice ;;25 (0x19)
1427 :dragon ;;26 (0x1A)
1428 ])
1429 #+end_src
1431 ** Basic effects of moves
1433 *** Table of basic effects
1435 The possible effects of moves in Pok\eacute{}mon \mdash{} for example, dealing
1436 damage, leeching health, or potentially poisoning the opponent
1437 \mdash{} are stored in a table. Each move has exactly one effect, and
1438 different moves might have the same effect.
1440 For example, Leech Life, Mega Drain, and Absorb all have effect ID #3, which is \ldquo{}Leech half of the inflicted damage.\rdquo{}
1442 All the legitimate move effects are listed in the table
1443 below. Here are some notes for reading it:
1445 - Whenever an effect has a chance of doing something (like a chance of
1446 poisoning the opponent), I list the chance as a hexadecimal amount
1447 out of 256; this is to avoid rounding errors. To convert the hex amount into a percentage, divide by 256.
1448 - For some effects, the description is too cumbersome to
1449 write. Instead, I just write a move name
1450 in parentheses, like: (leech seed). That move gives a characteristic example
1451 of the effect.
1452 - I use the abbreviations =atk=, =def=, =spd=, =spc=, =acr=, =evd= for
1453 attack, defense, speed, special, accuracy, and evasiveness.
1458 | ID (hex) | Description | Notes |
1459 |----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------|
1460 | 0 | normal damage | |
1461 | 1 | no damage, just sleep | TODO: find out how many turns |
1462 | 2 | 0x4C chance of poison | |
1463 | 3 | leech half of inflicted damage | |
1464 | 4 | 0x19 chance of burn | |
1465 | 5 | 0x19 chance of freeze | |
1466 | 6 | 0x19 chance of paralysis | |
1467 | 7 | user faints; opponent's defense is halved during attack. | |
1468 | 8 | leech half of inflicted damage ONLY if the opponent is asleep | |
1469 | 9 | imitate last attack | |
1470 | A | user atk +1 | |
1471 | B | user def +1 | |
1472 | C | user spd +1 | |
1473 | D | user spc +1 | |
1474 | E | user acr +1 | This effect is unused. |
1475 | F | user evd +1 | |
1476 | 10 | get post-battle money = 2 * level * uses | |
1477 | 11 | move has 0xFE acr, regardless of battle stat modifications. | |
1478 | 12 | opponent atk -1 | |
1479 | 13 | opponent def -1 | |
1480 | 14 | opponent spd -1 | |
1481 | 15 | opponent spc -1 | |
1482 | 16 | opponent acr -1 | |
1483 | 17 | opponent evd -1 | |
1484 | 18 | converts user's type to opponent's. | |
1485 | 19 | (haze) | |
1486 | 1A | (bide) | |
1487 | 1B | (thrash) | |
1488 | 1C | (teleport) | |
1489 | 1D | (fury swipes) | |
1490 | 1E | attacks 2-5 turns | Unused. TODO: find out what it does. |
1491 | 1F | 0x19 chance of flinching | |
1492 | 20 | opponent sleep for 1-7 turns | |
1493 | 21 | 0x66 chance of poison | |
1494 | 22 | 0x4D chance of burn | |
1495 | 23 | 0x4D chance of freeze | |
1496 | 24 | 0x4D chance of paralysis | |
1497 | 25 | 0x4D chance of flinching | |
1498 | 26 | one-hit KO | |
1499 | 27 | charge one turn, atk next. | |
1500 | 28 | fixed damage, leaves 1HP. | Is the fixed damage the power of the move? |
1501 | 29 | fixed damage. | Like seismic toss, dragon rage, psywave. |
1502 | 2A | atk 2-5 turns; opponent can't attack | The odds of attacking for /n/ turns are: (0 0x60 0x60 0x20 0x20) |
1503 | 2B | charge one turn, atk next. (can't be hit when charging) | |
1504 | 2C | atk hits twice. | |
1505 | 2D | user takes 1 damage if misses. | |
1506 | 2E | evade status-lowering effects | Caused by you or also your opponent? |
1507 | 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. |
1508 | 30 | atk causes recoil dmg = 1/4 dmg dealt | |
1509 | 31 | confuses opponent | |
1510 | 32 | user atk +2 | |
1511 | 33 | user def +2 | |
1512 | 34 | user spd +2 | |
1513 | 35 | user spc +2 | |
1514 | 36 | user acr +2 | This effect is unused. |
1515 | 37 | user evd +2 | This effect is unused. |
1516 | 38 | restores up to half of user's max hp. | |
1517 | 39 | (transform) | |
1518 | 3A | opponent atk -2 | |
1519 | 3B | opponent def -2 | |
1520 | 3C | opponent spd -2 | |
1521 | 3D | opponent spc -2 | |
1522 | 3E | opponent acr -2 | |
1523 | 3F | opponent evd -2 | |
1524 | 40 | doubles user spc when attacked | |
1525 | 41 | doubles user def when attacked | |
1526 | 42 | just poisons opponent | |
1527 | 43 | just paralyzes opponent | |
1528 | 44 | 0x19 chance opponent atk -1 | |
1529 | 45 | 0x19 chance opponent def -1 | |
1530 | 46 | 0x19 chance opponent spd -1 | |
1531 | 47 | 0x4C chance opponent spc -1 | |
1532 | 48 | 0x19 chance opponent acr -1 | |
1533 | 49 | 0x19 chance opponent evd -1 | |
1534 | 4A | ??? | ;; unused? no effect? |
1535 | 4B | ??? | ;; unused? no effect? |
1536 | 4C | 0x19 chance of confusing the opponent | |
1537 | 4D | atk hits twice. 0x33 chance opponent poisioned. | |
1538 | 4E | broken. crash the game after attack. | |
1539 | 4F | (substitute) | |
1540 | 50 | unless opponent faints, user must recharge after atk. some exceptions apply | |
1541 | 51 | (rage) | |
1542 | 52 | (mimic) | |
1543 | 53 | (metronome) | |
1544 | 54 | (leech seed) | |
1545 | 55 | does nothing (splash) | |
1546 | 56 | (disable) | |
1547 #+end_src
1549 *** Source
1550 #+name: move-effects
1551 #+begin_src clojure
1552 (def move-effects
1553 ["normal damage"
1554 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?
1555 "0x4C chance of poison"
1556 "leech half of inflicted damage"
1557 "0x19 chance of burn"
1558 "0x19 chance of freeze"
1559 "0x19 chance of paralyze"
1560 "user faints; opponent defense halved during attack."
1561 "leech half of inflicted damage ONLY if sleeping opponent."
1562 "imitate last attack"
1563 "user atk +1"
1564 "user def +1"
1565 "user spd +1"
1566 "user spc +1"
1567 "user acr +1" ;; unused?!
1568 "user evd +1"
1569 "get post-battle $ = 2*level*uses"
1570 "0xFE acr, no matter what."
1571 "opponent atk -1" ;; acr taken from move acr?
1572 "opponent def -1" ;;
1573 "opponent spd -1" ;;
1574 "opponent spc -1" ;;
1575 "opponent acr -1";;
1576 "opponent evd -1"
1577 "converts user's type to opponent's."
1578 "(haze)"
1579 "(bide)"
1580 "(thrash)"
1581 "(teleport)"
1582 "(fury swipes)"
1583 "attacks 2-5 turns" ;; unused? like rollout?
1584 "0x19 chance of flinch"
1585 "opponent sleep for 1-7 turns"
1586 "0x66 chance of poison"
1587 "0x4D chance of burn"
1588 "0x4D chance of freeze"
1589 "0x4D chance of paralyze"
1590 "0x4D chance of flinch"
1591 "one-hit KO"
1592 "charge one turn, atk next."
1593 "fixed damage, leaves 1HP." ;; how is dmg determined?
1594 "fixed damage." ;; cf seismic toss, dragon rage, psywave.
1595 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)
1596 "charge one turn, atk next. (can't be hit when charging)"
1597 "atk hits twice."
1598 "user takes 1 damage if misses."
1599 "evade status-lowering effects" ;;caused by you or also your opponent?
1600 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"
1601 "atk causes recoil dmg = 1/4 dmg dealt"
1602 "confuses opponent" ;; acr taken from move acr
1603 "user atk +2"
1604 "user def +2"
1605 "user spd +2"
1606 "user spc +2"
1607 "user acr +2" ;; unused!
1608 "user evd +2" ;; unused!
1609 "restores up to half of user's max hp." ;; broken: fails if the difference
1610 ;; b/w max and current hp is one less than a multiple of 256.
1611 "(transform)"
1612 "opponent atk -2"
1613 "opponent def -2"
1614 "opponent spd -2"
1615 "opponent spc -2"
1616 "opponent acr -2"
1617 "opponent evd -2"
1618 "doubles user spc when attacked"
1619 "doubles user def when attacked"
1620 "just poisons opponent" ;;acr taken from move acr
1621 "just paralyzes opponent" ;;
1622 "0x19 chance opponent atk -1"
1623 "0x19 chance opponent def -1"
1624 "0x19 chance opponent spd -1"
1625 "0x4C chance opponent spc -1" ;; context suggest chance is 0x19
1626 "0x19 chance opponent acr -1"
1627 "0x19 chance opponent evd -1"
1628 "???" ;; unused? no effect?
1629 "???" ;; unused? no effect?
1630 "0x19 chance opponent confused"
1631 "atk hits twice. 0x33 chance opponent poisioned."
1632 "broken. crash the game after attack."
1633 "(substitute)"
1634 "unless opponent faints, user must recharge after atk. some
1635 exceptions apply."
1636 "(rage)"
1637 "(mimic)"
1638 "(metronome)"
1639 "(leech seed)"
1640 "does nothing (splash)"
1641 "(disable)"
1642 ])
1643 #+end_src
1646 ** Alphabet code
1648 * Source
1650 #+begin_src clojure :tangle ../clojure/com/aurellem/gb/hxc.clj
1652 (ns com.aurellem.gb.hxc
1653 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1654 constants species))
1655 (:import [com.aurellem.gb.gb_driver SaveState]))
1657 ; ************* HANDWRITTEN CONSTANTS
1659 <<type-ids>>
1662 ;; question: when status effects claim to take
1663 ;; their accuracy from the move accuracy, does
1664 ;; this mean that the move always "hits" but the
1665 ;; status effect may not?
1667 <<move-effects>>
1669 ;; ************** HARDCODED DATA
1671 <<hxc-thunks>>
1672 ;; --------------------------------------------------
1674 <<pokenames>>
1675 <<type-names>>
1677 ;; http://hax.iimarck.us/topic/581/
1678 <<pokecry>>
1681 <<item-names>>
1685 (def hxc-titles
1686 "The hardcoded names of the trainer titles in memory. List begins at
1687 ROM@27E77"
1688 (hxc-thunk-words 0x27E77 196))
1691 <<dex-text>>
1693 ;; In red/blue, pokedex stats are in internal order.
1694 ;; In yellow, pokedex stats are in pokedex order.
1695 <<dex-stats>>
1700 <<places>>
1702 (defn hxc-dialog
1703 "The hardcoded dialogue in memory, including in-game alerts. Dialog
1704 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."
1705 ([rom]
1706 (map character-codes->str
1707 (take-nth 2
1708 (partition-by #(= % 0x57)
1709 (take 0x0F728
1710 (drop 0x98000 rom))))))
1711 ([]
1712 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
1715 <<move-names>>
1716 <<move-data>>
1718 <<machines>>
1722 (defn internal-id
1723 ([rom]
1724 (zipmap
1725 (hxc-pokenames rom)
1726 (range)))
1727 ([]
1728 (internal-id com.aurellem.gb.gb-driver/original-rom)))
1734 ;; nidoran gender change upon levelup
1735 ;; (->
1736 ;; @current-state
1737 ;; rom
1738 ;; vec
1739 ;; (rewrite-memory
1740 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))
1741 ;; [1 1 15])
1742 ;; (rewrite-memory
1743 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))
1744 ;; [1 1 3])
1745 ;; (write-rom!)
1747 ;; )
1751 <<type-advantage>>
1755 <<evolution-header>>
1756 <<evolution>>
1757 <<learnsets>>
1758 <<pokebase>>
1761 (defn hxc-intro-pkmn
1762 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's
1763 internal id is stored at ROM@5EDB."
1764 ([] (hxc-intro-pkmn
1765 com.aurellem.gb.gb-driver/original-rom))
1766 ([rom]
1767 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))
1769 (defn sxc-intro-pkmn!
1770 "Set the hardcoded pokemon to display in Prof. Oak's introduction."
1771 [pokemon]
1772 (write-rom!
1773 (rewrite-rom 0x5EDB
1775 (inc
1776 ((zipmap
1777 (hxc-pokenames)
1778 (range))
1779 pokemon))])))
1782 <<item-prices>>
1784 <<item-vendors>>
1786 <<wilds>>
1789 ;; ********************** MANIPULATION FNS
1792 (defn same-type
1793 ([pkmn move]
1794 (same-type
1795 com.aurellem.gb.gb-driver/original-rom pkmn move))
1796 ([rom pkmn move]
1797 (((comp :types (hxc-pokemon-base rom)) pkmn)
1798 ((comp :type (hxc-move-data rom)) move))))
1803 (defn submap?
1804 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."
1805 [map-small map-big]
1806 (cond (empty? map-small) true
1807 (and
1808 (contains? map-big (ffirst map-small))
1809 (= (get map-big (ffirst map-small))
1810 (second (first map-small))))
1811 (recur (next map-small) map-big)
1813 :else false))
1816 (defn search-map [proto-map maps]
1817 "Returns all the maps that make the same associations as proto-map."
1818 (some (partial submap? proto-map) maps))
1820 (defn filter-vals
1821 "Returns a map consisting of all the pairs [key val] for
1822 which (pred key) returns true."
1823 [pred map]
1824 (reduce (partial apply assoc) {}
1825 (filter (fn [[k v]] (pred v)) map)))
1828 (defn search-moves
1829 "Returns a subcollection of all hardcoded moves with the
1830 given attributes. Attributes consist of :name :power
1831 :accuracy :pp :fx-id
1832 (and also :fx-txt, but it contains the same information
1833 as :fx-id)"
1834 ([attribute-map]
1835 (search-moves
1836 com.aurellem.gb.gb-driver/original-rom attribute-map))
1837 ([rom attribute-map]
1838 (filter-vals (partial submap? attribute-map)
1839 (hxc-move-data rom))))
1845 ;; note: 0x2f31 contains the names "TM" "HM"?
1847 ;; note for later: credits start at F1290
1849 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??
1851 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)
1853 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.
1854 ;; The first instance is for Machines; the second, for stones.
1856 ;; note: according to
1857 ;; http://www.upokecenter.com/games/rby/guides/rgbtrainers.php
1858 ;; the amount of money given by a trainer is equal to the
1859 ;; base money times the level of the last Pokemon on that trainer's
1860 ;; list. Other sources say it's the the level of the last pokemon
1861 ;; /defeated/.
1863 ;; todo: find base money.
1866 ;; note: 0xDFEA (in indexable mem) is the dex# of the currently-viewed Pokemon in
1867 ;; in the pokedex. It's used for other purposes if there is none.
1869 ;; note: 0x9D35 (index.) switches from 0xFF to 0x00 temporarily when
1870 ;; you walk between areas.
1872 ;; note: 0xD059 (index.) is the special battle type of your next battle:
1873 ;; - 00 is a usual battle
1874 ;; - 01 is a pre-scripted OLD MAN battle which always fails to catch the
1875 ;; target Pokemon.
1876 ;; - 02 is a safari zone battle
1877 ;; - 03 obligates you to run away. (unused)
1878 ;; - 04 is a pre-scripted OAK battle, which (temporarily) causes the
1879 ;; enemy Pokemon to cry PIKAAA, and which always catches the target
1880 ;; Pokemon. The target Pokemon is erased after the battle.
1881 ;; - 05+ are glitch states in which you are sort of the Pokemon.
1884 ;; note: 0x251A (in indexable mem): image decompression routine seems to begin here.
1886 ;; note: 0x4845 (index): vending inventory is loaded here. possibly
1887 ;; other things, too.
1888 (comment
1889 ;; temporarily intercept/adjust what pops out of the vending
1890 ;; machine.
1891 ;; (and how much it costs)
1893 ;; located at 0x4845
1894 ;; not to be confused with shop inventory, 0xCF7B
1895 (do
1896 (step (read-state "vend-menu"))
1897 (write-memory! (rewrite-memory (vec(memory)) 0x4845 [2 0 1 0]))
1898 (step @current-state [:a])
1899 (step @current-state [])
1900 (nstep @current-state 200) ))
1903 ;; Note: There are two tile tables, one from 8000-8FFF, the other from
1904 ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end.
1905 (defn print-pixel-letters!
1906 "The pixel tiles representing letters. Neat!"
1907 ([] (print-pixel-letters! (read-state "oak-speaks")))
1908 ([state]
1909 (map
1910 (comp
1911 println
1912 (partial map #(if (zero? %) \space 0))
1913 #(if (< (count %) 8)
1914 (recur (cons 0 %))
1915 %)
1916 reverse bit-list)
1918 (take 0xFFF (drop 0x8800 (memory state))))))
1921 ;; (defn test-2 []
1922 ;; (loop [n 0
1923 ;; pc-1 (pc-trail (-> state-defend (tick) (step [:a]) (step [:a]) (step []) (nstep 100)) 100000)
1924 ;; pc-2 (pc-trail (-> state-speed (tick) (step [:a]) (step [:a])
1925 ;; (step []) (nstep 100)) 100000)]
1926 ;; (cond (empty? (drop n pc-1)) [pc-1 n]
1927 ;; (not= (take 10 (drop n pc-1)) (take 10 pc-2))
1928 ;; (recur pc-1 pc-2 (inc n))
1929 ;; :else
1930 ;; [(take 1000 pc-2) n])))
1935 (defn test-3
1936 "Explore trainer data"
1937 ([] (test-3 0x3A289))
1938 ([start]
1939 (let [pokenames (vec(hxc-pokenames-raw))]
1940 (println
1941 (reduce
1942 str
1943 (map
1944 (fn [[adr lvl pkmn]]
1945 (str (format "%-11s %4d %02X %02X \t %05X\n"
1947 (cond
1948 (zero? lvl) "+"
1949 (nil? (get pokenames (dec pkmn)))
1950 "-"
1951 :else
1952 (get pokenames (dec pkmn)))
1953 lvl
1954 pkmn
1955 lvl
1956 adr
1957 )))
1958 (map cons
1959 (take-nth 2 (drop start (range)))
1960 (partition 2
1961 (take 400;;703
1962 (drop
1963 start
1964 ;; 0x3A75D
1965 (rom)))))))))))
1967 (defn search-memory* [mem codes k]
1968 (loop [index 0
1969 index-next 1
1970 start-match 0
1971 to-match codes
1972 matches []]
1973 (cond
1974 (>= index (count mem)) matches
1976 (empty? to-match)
1977 (recur
1978 index-next
1979 (inc index-next)
1980 index-next
1981 codes
1982 (conj matches
1983 [(hex start-match) (take k (drop start-match mem))])
1986 (or (= (first to-match) \_) ;; wildcard
1987 (= (first to-match) (nth mem index)))
1988 (recur
1989 (inc index)
1990 index-next
1991 start-match
1992 (rest to-match)
1993 matches)
1995 :else
1996 (recur
1997 index-next
1998 (inc index-next)
1999 index-next
2000 codes
2001 matches))))
2004 (def script-use-ball
2005 [0xFA ;; ld A, nn
2006 \_
2007 \_
2008 0xA7 ;; and A
2009 0xCA ;; JP Z
2010 \_
2011 \_
2012 0x3D ;; dec A
2013 0xC2 ;; JP NZ
2014 \_
2015 \_
2016 0xFA ;; LD A
2017 \_
2018 \_
2019 ])
2023 (defn search-pattern [ptn coll]
2024 (loop
2025 [index 0
2026 to-match ptn
2027 binds {}
2029 next-index 1
2030 match-start 0
2031 matches []]
2033 (cond
2034 (>= index (count coll)) matches
2035 (empty? to-match)
2036 (recur
2037 next-index
2038 ptn
2039 {}
2040 (inc next-index)
2041 next-index
2042 (conj match-start
2043 [(hex match-start) binds]))
2045 :else
2046 (let [k (first to-match)
2047 v (nth coll index)]
2048 (cond
2049 (= k \_) ;; wildcard
2050 (recur
2051 (inc index)
2052 (rest to-match)
2053 binds
2055 next-index
2056 match-start
2057 matches)
2059 (keyword? k)
2060 (if (binds k)
2061 (if (= (binds k) v)
2062 (recur
2063 (inc index)
2064 (rest to-match)
2065 binds
2066 next-index
2067 match-start
2068 matches)
2070 (recur
2071 next-index
2072 ptn
2073 {}
2074 (inc next-index)
2075 next-index
2076 matches))
2078 ;; ;; consistent bindings
2079 ;; (recur
2080 ;; (inc index)
2081 ;; (rest to-match)
2082 ;; binds
2084 ;; next-index
2085 ;; match-start
2086 ;; matches)
2088 ;; ;; inconsistent bindings
2089 ;; (recur
2090 ;; next-index
2091 ;; ptn
2092 ;; {}
2093 ;; (inc next-index)
2094 ;; next-index
2095 ;; matches))
2097 (if ((set (vals binds)) v)
2098 ;; bindings are not unique
2099 (recur
2100 next-index
2101 ptn
2102 {}
2103 (inc next-index)
2104 next-index
2105 matches)
2107 ;; bindings are unique
2108 (recur
2109 (inc index)
2110 (rest to-match)
2111 (assoc binds k v)
2113 next-index
2114 match-start
2115 matches)))
2117 :else ;; k is just a number
2118 (if (= k v)
2119 (recur
2120 (inc index)
2121 (rest to-match)
2122 binds
2124 next-index
2125 match-start
2126 matches)
2128 (recur
2129 next-index
2130 ptn
2131 {}
2132 (inc next-index)
2133 next-index
2134 matches)))))))
2144 (defn search-pattern* [ptn coll]
2145 (loop
2147 binds {}
2148 index 0
2149 index-next 1
2150 start-match 0
2151 to-match ptn
2152 matches []]
2154 (cond
2155 (>= index (count coll)) matches
2156 (empty? to-match)
2157 (recur
2158 {}
2159 index-next
2160 (inc index-next)
2161 index-next
2162 ptn
2163 (conj matches
2164 [(hex start-match) binds]))
2166 :else
2167 (let [k (first to-match)
2168 v (nth coll index)]
2169 (cond
2170 (= k \_) ;; wildcard
2171 (recur
2172 binds
2173 (inc index)
2174 index-next
2175 start-match
2176 (rest to-match)
2177 matches)
2179 (keyword? k)
2180 (if (binds k)
2181 (if (= (binds k) v)
2182 (recur
2183 binds
2184 (inc index)
2185 index-next
2186 start-match
2187 (rest to-match)
2188 matches)
2189 (recur
2190 {}
2191 index-next
2192 (inc index-next)
2193 index-next
2194 ptn
2195 matches))
2196 (if
2197 ;; every symbol must be bound to a different thing.
2198 ((set (vals binds)) v)
2199 (recur
2200 {}
2201 index-next
2202 (inc index-next)
2203 index-next
2204 ptn
2205 matches)
2206 (recur
2207 (assoc binds k v)
2208 (inc index)
2209 index-next
2210 start-match
2211 (rest to-match)
2212 matches))))))))
2217 ;; look for the rainbow badge in memory
2218 (println (reduce str (map #(str (first %) "\t" (vec(second %)) "\n") (search-memory (rom) [221] 10))))
2221 (comment
2223 (def hxc-later
2224 "Running this code produces, e.g. hardcoded names NPCs give
2225 their pokemon. Will sort through it later."
2226 (print (character-codes->str(take 10000
2227 (drop 0x71597
2228 (rom (root)))))))
2230 (let [dex
2231 (partition-by #(= 0x50 %)
2232 (take 2540
2233 (drop 0x40687
2234 (rom (root)))))]
2235 (def dex dex)
2236 (def hxc-species
2237 (map character-codes->str
2238 (take-nth 4 dex))))
2242 #+end_src
2244 #+results:
2245 : nil