view org/rom.org @ 499:8b8053ccb33c

generated graphical representation of the gb color map.
author Robert McIntyre <rlm@mit.edu>
date Tue, 12 Jun 2012 03:36:47 -0500
parents 9a7fae5afd8f
children
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
9 #+OPTIONS: num:2
12 # about map headers http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes
13 # map headers Yellow http://www.pokecommunity.com/archive/index.php/t-235311.html
14 # pokedollar: U+20B1
15 * Introduction
16 This article contains the results of my investigations with
17 Pok\eacute{}mon Yellow as I searched for interesting
18 data in the ROM. By using the Clojure language interface
19 written by Robert[fn::This Clojure interface will be published to aurellem.org soon.], I
20 was able to interact with the game in real-time, sending commands and
21 gathering data. The result is a manifestly accurate map of
22 Pok\eacute{}mon Yellow; every result
23 comes with runnable code that /works/. You can see the code and the output of
24 every function and confirm for yourself that they are all correct. I
25 hope you like the result!
27 To orient yourself, you can look for a specific topic in the table of contents
28 above, or browse the [[#sec-9-1][map of the ROM]], below.
31 If you have any questions or comments, please e-mail =rlm@mit.edu=.
34 ** COMMENT Getting linguistic data: names, words, etc.
36 Some of the simplest data
39 One of the simplest data structures in the Pok\eacute{} ROM is an
40 unbroken list of strings that either (a) all have a specific length,
41 or (b) are all separated by the same character.
43 Because lots of good data has this format, we'll start by writing a
44 template function to extract it:
46 #+name: hxc-thunks
47 #+begin_src clojure :results silent
48 (defn hxc-thunk
49 "Creates a thunk (nullary fn) that grabs data in a certain region of rom and
50 splits it into a collection by 0x50. If rom is not supplied, uses the
51 original rom data."
52 [start length]
53 (fn self
54 ([rom]
55 (take-nth 2
56 (partition-by #(= % 0x50)
57 (take length
58 (drop start rom)))))
59 ([]
60 (self com.aurellem.gb.gb-driver/original-rom))))
62 (def hxc-thunk-words
63 "Same as hxc-thunk, except it interprets the rom data as characters,
64 returning a collection of strings."
65 (comp
66 (partial comp (partial map character-codes->str))
67 hxc-thunk))
69 #+end_src
72 * Pok\eacute{}mon I
73 ** Names of each species
74 The names of the Pok\eacute{}mon species are stored in
75 ROM@E8000. This name list is interesting, for a number of reasons:
76 - The names are stored in [[ ][internal order]] rather than in the familiar
77 Pok\eacute{}dex order. This seemingly random order probably represents the order in which the authors created or
78 programmed in the Pok\eacute{}mon; it's used throughout the game.
79 - There is enough space allocated for 190 Pok\eacute{}mon. As I
80 understand it, there were originally going to be 190 Pok\eacute{}mon
81 in Generation I, but the creators decided to defer some to
82 Generation II. This explains why many Gen I and Gen II Pok\eacute{}mon
83 have the same aesthetic feel.
84 - The list is pockmarked with random gaps, due to the strange internal
85 ordering
86 and the 39 unused spaces [fn::190 allocated spaces minus 151 true Pok\eacute{}mon]. These missing spaces are filled with the
87 placeholder name =MISSINGNO.= (\ldquo{}Missing number\rdquo{}).
89 Each name is exactly ten letters long; whenever a name would be too short, the extra
90 space is padded with the character 0x50.
92 *** See the data
94 Here you can see the raw data in three stages: in the first stage, we
95 just grab the first few bytes starting from position 0xE8000. In the
96 second stage, we partition the bytes into ten-letter chunks to show you
97 where the names begin and end. In the final stage, we convert each
98 byte into the letter it represents using the =character-codes->str=
99 function. (0x50 is rendered as the symbol \ldquo{} =#= \rdquo{} for
100 ease of reading).
102 #+begin_src clojure :exports both :cache no :results output
103 (ns com.aurellem.gb.hxc
104 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
105 constants))
106 (:import [com.aurellem.gb.gb_driver SaveState]))
109 (println (take 100 (drop 0xE8000 (rom))))
111 (println (partition 10 (take 100 (drop 0xE8000 (rom)))))
113 (println (character-codes->str (take 100 (drop 0xE8000 (rom)))))
116 #+end_src
118 #+results:
119 : (145 135 152 131 142 141 80 80 80 80 138 128 141 134 128 146 138 135 128 141 141 136 131 142 145 128 141 239 80 80 130 139 132 133 128 136 145 152 80 80 146 143 132 128 145 142 150 80 80 80 149 142 139 147 142 145 129 80 80 80 141 136 131 142 138 136 141 134 80 80 146 139 142 150 129 145 142 80 80 80 136 149 152 146 128 148 145 80 80 80 132 151 132 134 134 148 147 142 145 80)
120 : ((145 135 152 131 142 141 80 80 80 80) (138 128 141 134 128 146 138 135 128 141) (141 136 131 142 145 128 141 239 80 80) (130 139 132 133 128 136 145 152 80 80) (146 143 132 128 145 142 150 80 80 80) (149 142 139 147 142 145 129 80 80 80) (141 136 131 142 138 136 141 134 80 80) (146 139 142 150 129 145 142 80 80 80) (136 149 152 146 128 148 145 80 80 80) (132 151 132 134 134 148 147 142 145 80))
121 : RHYDON####KANGASKHANNIDORAN♂##CLEFAIRY##SPEAROW###VOLTORB###NIDOKING##SLOWBRO###IVYSAUR###EXEGGUTOR#
124 *** Automatically grab the data.
126 #+name: pokenames
127 #+begin_src clojure
129 (defn hxc-pokenames-raw
130 "The hardcoded names of the 190 species in memory. List begins at
131 ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters
132 long, these names are stripped of padding. See also, hxc-pokedex-names"
133 ([]
134 (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom))
135 ([rom]
136 (let [count-species 190
137 name-length 10]
138 (map character-codes->str
139 (partition name-length
140 (map #(if (= 0x50 %) 0x00 %)
141 (take (* count-species name-length)
142 (drop 0xE8000
143 rom))))))))
144 (def hxc-pokenames
145 (comp
146 (partial map format-name)
147 hxc-pokenames-raw))
152 (defn hxc-pokedex-names
153 "The names of the pokemon in hardcoded pokedex order. List of the
154 pokedex numbers of each pokemon (in internal order) begins at
155 ROM@410B1. See also, hxc-pokenames."
156 ([] (hxc-pokedex-names
157 com.aurellem.gb.gb-driver/original-rom))
158 ([rom]
159 (let [names (hxc-pokenames rom)]
160 (#(mapv %
161 ((comp range count keys) %))
162 (zipmap
163 (take (count names)
164 (drop 0x410b1 rom))
166 names)))))
168 #+end_src
172 ** Generic species information
174 #+name: pokebase
175 #+begin_src clojure
176 (defn hxc-pokemon-base
177 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))
178 ([rom]
179 (let [entry-size 28
181 pokemon (rest (hxc-pokedex-names))
182 pkmn-count (inc(count pokemon))
183 types (apply assoc {}
184 (interleave
185 (range)
186 pkmn-types)) ;;!! softcoded
187 moves (apply assoc {}
188 (interleave
189 (range)
190 (map format-name
191 (hxc-move-names rom))))
192 machines (hxc-machines)
193 ]
194 (zipmap
195 pokemon
196 (map
197 (fn [[n
198 rating-hp
199 rating-atk
200 rating-def
201 rating-speed
202 rating-special
203 type-1
204 type-2
205 rarity ;; catch rate
206 rating-xp ;; base exp yield
207 pic-dimensions ;; tile_width|tile_height (8px/tile)
208 ptr-pic-obverse-1
209 ptr-pic-obverse-2
210 ptr-pic-reverse-1
211 ptr-pic-reverse-2
212 move-1 ;; attacks known at level 0 [i.e. by default]
213 move-2 ;; (0 for none)
214 move-3
215 move-4
216 growth-rate
217 &
218 TMs|HMs]]
219 (let
220 [base-moves
221 (mapv moves
222 ((comp
223 ;; since the game uses zero as a delimiter,
224 ;; it must also increment all move indices by 1.
225 ;; heren we decrement to correct this.
226 (partial map dec)
227 (partial take-while (comp not zero?)))
228 [move-1 move-2 move-3 move-4]))
230 types
231 (set (list (types type-1)
232 (types type-2)))
233 TMs|HMs
234 (map
235 (comp
236 (partial map first)
237 (partial remove (comp zero? second)))
238 (split-at
239 50
240 (map vector
241 (rest(range))
242 (reduce concat
243 (map
244 #(take 8
245 (concat (bit-list %)
246 (repeat 0)))
248 TMs|HMs)))))
250 TMs (vec (first TMs|HMs))
251 HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))
254 ]
257 {:dex# n
258 :base-moves base-moves
259 :types types
260 :TMs TMs
261 :HMs HMs
262 :base-hp rating-hp
263 :base-atk rating-atk
264 :base-def rating-def
265 :base-speed rating-speed
266 :base-special rating-special
267 :o0 pic-dimensions
268 :o1 ptr-pic-obverse-1
269 :o2 ptr-pic-obverse-2
270 }))
272 (partition entry-size
273 (take (* entry-size pkmn-count)
274 (drop 0x383DE
275 rom))))))))
277 #+end_src
280 ** Pok\eacute{}mon evolutions
281 #+name: evolution-header
282 #+begin_src clojure
283 (defn format-evo
284 "Parse a sequence of evolution data, returning a map. First is the
285 method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the
286 method of evolution is by item (only stones will actually make pokemon
287 evolve, for some auxillary reason.) Finally, the minimum level for
288 evolution to occur (level 1 means no limit, which is used for trade
289 and item evolutions), followed by the internal id of the pokemon
290 into which to evolve. Hence, level up and trade evolutions are
291 described with 3
292 bytes; item evolutions with four."
293 [coll]
294 (let [method (first coll)]
295 (cond (empty? coll) []
296 (= 0 method) [] ;; just in case
297 (= 1 method) ;; level-up evolution
298 (conj (format-evo (drop 3 coll))
299 {:method :level-up
300 :min-level (nth coll 1)
301 :into (dec (nth coll 2))})
303 (= 2 method) ;; item evolution
304 (conj (format-evo (drop 4 coll))
305 {:method :item
306 :item (dec (nth coll 1))
307 :min-level (nth coll 2)
308 :into (dec (nth coll 3))})
310 (= 3 method) ;; trade evolution
311 (conj (format-evo (drop 3 coll))
312 {:method :trade
313 :min-level (nth coll 1) ;; always 1 for trade.
314 :into (dec (nth coll 2))}))))
317 (defn hxc-ptrs-evolve
318 "A hardcoded collection of 190 pointers to alternating evolution/learnset data,
319 in internal order."
320 ([]
321 (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))
322 ([rom]
323 (let [
324 pkmn-count (count (hxc-pokenames-raw)) ;; 190
325 ptrs
326 (map (fn [[a b]] (low-high a b))
327 (partition 2
328 (take (* 2 pkmn-count)
329 (drop 0x3b1e5 rom))))]
330 (map (partial + 0x34000) ptrs)
332 )))
333 #+end_src
335 #+name:evolution
336 #+begin_src clojure
338 (defn hxc-evolution
339 "Hardcoded evolution data in memory. The data exists at ROM@34000,
340 sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."
341 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
342 ([rom]
343 (apply assoc {}
344 (interleave
345 (hxc-pokenames rom)
346 (map
347 (comp
348 format-evo
349 (partial take-while (comp not zero?))
350 #(drop % rom))
351 (hxc-ptrs-evolve rom)
352 )))))
354 (defn hxc-evolution-pretty
355 "Like hxc-evolution, except it uses the names of items and pokemon
356 --- grabbed from ROM --- rather than their numerical identifiers."
357 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))
358 ([rom]
359 (let
360 [poke-names (vec (hxc-pokenames rom))
361 item-names (vec (hxc-items rom))
362 use-names
363 (fn [m]
364 (loop [ks (keys m) new-map m]
365 (let [k (first ks)]
366 (cond (nil? ks) new-map
367 (= k :into)
368 (recur
369 (next ks)
370 (assoc new-map
371 :into
372 (poke-names
373 (:into
374 new-map))))
375 (= k :item)
376 (recur
377 (next ks)
378 (assoc new-map
379 :item
380 (item-names
381 (:item new-map))))
382 :else
383 (recur
384 (next ks)
385 new-map)
386 ))))]
388 (into {}
389 (map (fn [[pkmn evo-coll]]
390 [pkmn (map use-names evo-coll)])
391 (hxc-evolution rom))))))
394 #+end_src
397 ** Level-up moves (learnsets)
398 #+name: learnsets
399 #+begin_src clojure
402 (defn hxc-learnsets
403 "Hardcoded map associating pokemon names to lists of pairs [lvl
404 move] of abilities they learn as they level up. The data
405 exists at ROM@34000, sorted by internal order. Pointers to the data
406 exist at ROM@3B1E5; see also, hxc-ptrs-evolve"
407 ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))
408 ([rom]
409 (apply assoc
410 {}
411 (interleave
412 (hxc-pokenames rom)
413 (map (comp
414 (partial map
415 (fn [[lvl mv]] [lvl (dec mv)]))
416 (partial partition 2)
417 ;; keep the learnset data
418 (partial take-while (comp not zero?))
419 ;; skip the evolution data
420 rest
421 (partial drop-while (comp not zero?)))
422 (map #(drop % rom)
423 (hxc-ptrs-evolve rom)))))))
425 (defn hxc-learnsets-pretty
426 "Live hxc-learnsets except it reports the name of each move --- as
427 it appears in rom --- rather than the move index."
428 ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))
429 ([rom]
430 (let [moves (vec(map format-name (hxc-move-names)))]
431 (into {}
432 (map (fn [[pkmn learnset]]
433 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])
434 learnset)])
435 (hxc-learnsets rom))))))
439 #+end_src
443 * Pok\eacute{}mon II : the Pok\eacute{}dex
444 ** Species vital stats
445 #+name: dex-stats
446 #+begin_src clojure
447 (defn hxc-pokedex-stats
448 "The hardcoded pokedex stats (species height weight) in memory. List
449 begins at ROM@40687"
450 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))
451 ([rom]
452 (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom))
453 pkmn-count (count pokedex-names)
454 ]
455 ((fn capture-stats
456 [n stats data]
457 (if (zero? n) stats
458 (let [[species
459 [_
460 height-ft
461 height-in
462 weight-1
463 weight-2
464 _
465 dex-ptr-1
466 dex-ptr-2
467 dex-bank
468 _
469 & data]]
470 (split-with (partial not= 0x50) data)]
471 (recur (dec n)
472 (assoc stats
473 (pokedex-names (- pkmn-count (dec n)))
474 {:species
475 (format-name (character-codes->str species))
476 :height-ft
477 height-ft
478 :height-in
479 height-in
480 :weight
481 (/ (low-high weight-1 weight-2) 10.)
483 ;; :text
484 ;; (character-codes->str
485 ;; (take-while
486 ;; (partial not= 0x50)
487 ;; (drop
488 ;; (+ 0xB8000
489 ;; -0x4000
490 ;; (low-high dex-ptr-1 dex-ptr-2))
491 ;; rom)))
492 })
494 data)
497 )))
499 pkmn-count
500 {}
501 (drop 0x40687 rom))) ))
502 #+end_src
504 #+results: dex-stats
505 : #'com.aurellem.gb.hxc/hxc-pokedex-stats
507 ** Species synopses
509 #+name: dex-text
510 #+begin_src clojure
511 (def hxc-pokedex-text-raw
512 "The hardcoded pokedex entries in memory. List begins at
513 ROM@B8000, shortly before move names."
514 (hxc-thunk-words 0xB8000 14754))
519 (defn hxc-pokedex-text
520 "The hardcoded pokedex entries in memory, presented as an
521 associative hash map. List begins at ROM@B8000."
522 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))
523 ([rom]
524 (zipmap
525 (hxc-pokedex-names rom)
526 (cons nil ;; for missingno.
527 (hxc-pokedex-text-raw rom)))))
528 #+end_src
531 ** Pok\eacute{}mon cries
532 *** See the data
534 Here, you can see that each Pok\eacute{}mon's cry data consists of
535 three bytes: the =cry-id=, which is the basic sound byte to use, the
536 =pitch=, which determines how high or low to make the sound byte, and
537 the =length=, which is the amount of the sound byte to play.
539 Even though there are only a few different basic sound bytes (cry
540 ids) to build from, by varying the pitch and length,
541 you can create a wide variety of different Pok\eacute{}mon cries.
543 #+begin_src clojure :exports both :cache no :results output
544 (ns com.aurellem.gb.hxc
545 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
546 constants))
547 (:import [com.aurellem.gb.gb_driver SaveState]))
549 (->>
550 (rom)
551 (drop 0x39462)
552 (take 12)
553 (println))
555 (->>
556 (rom)
557 (drop 0x39462)
558 (take 12)
559 (partition 3)
560 (map vec)
561 (println))
563 (->>
564 (rom)
565 (drop 0x39462)
566 (take 12)
567 (partition 3)
568 (map
569 (fn [[id pitch length]]
570 {:cry-id id :pitch pitch :length length}))
571 (println))
573 #+end_src
575 #+results:
576 : (17 0 128 3 0 128 0 0 128 25 204 1)
577 : ([17 0 128] [3 0 128] [0 0 128] [25 204 1])
578 : ({:cry-id 17, :pitch 0, :length 128} {:cry-id 3, :pitch 0, :length 128} {:cry-id 0, :pitch 0, :length 128} {:cry-id 25, :pitch 204, :length 1})
581 It is interesting to note which Pok\eacute{}mon use the same basic
582 =cry-id= --- I call these /cry groups/. Here, you can see which
583 Pok\eacute{}mon belong to the same cry group.
585 #+begin_src clojure :exports both :cache no :results output
586 (ns com.aurellem.gb.hxc
587 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
588 constants))
589 (:import [com.aurellem.gb.gb_driver SaveState]))
591 (println "POKEMON CRY GROUPS")
592 (doall
593 (map println
594 (let [cry-id
595 (->>
596 (rom)
597 (drop 0x39462) ;; get the cry data
598 (partition 3) ;; partition it into groups of three
599 (map first) ;; keep only the first item, the cry-id
600 (zipmap (hxc-pokenames)) ;; associate each pokemon with its cry-id
601 )]
603 (->> (hxc-pokenames) ;; start with the list of pokemon
604 (remove (partial = :missingno.)) ;; remove missingnos
605 (sort-by cry-id)
606 (partition-by cry-id)
607 (map vec)))))
609 #+end_src
611 #+results:
612 #+begin_example
613 POKEMON CRY GROUPS
614 [:nidoran♂ :sandshrew :sandslash :nidorino]
615 [:nidoran♀ :nidorina]
616 [:slowpoke]
617 [:kangaskhan]
618 [:rhyhorn :magmar :charmander :charmeleon :charizard]
619 [:grimer :snorlax]
620 [:voltorb :electabuzz :electrode]
621 [:gengar :muk]
622 [:marowak :oddish :gloom]
623 [:nidoking :moltres :articuno :raichu]
624 [:nidoqueen :mankey :primeape]
625 [:exeggcute :diglett :doduo :dodrio :dugtrio]
626 [:lickitung :hitmonchan :seel :dewgong]
627 [:exeggutor :drowzee :jynx :hypno]
628 [:pidgey :poliwag :ditto :jigglypuff :wigglytuff :poliwhirl :poliwrath]
629 [:ivysaur :dragonite :pikachu :dratini :dragonair :bulbasaur :venusaur]
630 [:spearow :farfetch'd]
631 [:rhydon]
632 [:tangela :hitmonlee :golem :koffing :weezing]
633 [:blastoise :kakuna :beedrill]
634 [:pinsir :chansey :pidgeotto :pidgeot]
635 [:arcanine :weedle]
636 [:scyther :kabuto :caterpie :butterfree :goldeen :seaking]
637 [:gyarados :onix :arbok :ekans :magikarp]
638 [:shellder :fearow :zapdos :kabutops :cloyster]
639 [:clefairy :cubone :meowth :horsea :seadra :clefable :persian]
640 [:tentacool :venonat :eevee :flareon :jolteon :vaporeon :venomoth :tentacruel]
641 [:lapras]
642 [:gastly :kadabra :magneton :metapod :haunter :abra :alakazam :magnemite]
643 [:tauros :zubat :golbat :squirtle :wartortle]
644 [:mew :staryu :parasect :paras :mewtwo :starmie]
645 [:slowbro :growlithe :machoke :omanyte :omastar :machop :machamp]
646 [:mr.mime :krabby :kingler]
647 [:psyduck :golduck :bellsprout]
648 [:rattata :raticate]
649 [:aerodactyl :vileplume]
650 [:graveler :vulpix :ninetales :geodude]
651 [:ponyta :rapidash :porygon :weepinbell :victreebel]
652 #+end_example
659 *** Automatically grab the data
660 #+name: pokecry
661 #+begin_src clojure
662 (defn hxc-cry
663 "The pokemon cry data in internal order. List begins at ROM@39462"
664 ([](hxc-cry com.aurellem.gb.gb-driver/original-rom))
665 ([rom]
666 (zipmap
667 (hxc-pokenames rom)
668 (map
669 (fn [[cry-id pitch length]]
670 {:cry-id cry-id
671 :pitch pitch
672 :length length}
673 )
674 (partition 3
675 (drop 0x39462 rom))))))
677 (defn hxc-cry-groups
678 ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom))
679 ([rom]
680 (map #(mapv first
681 (filter
682 (fn [[k v]]
683 (= % (:cry-id v)))
684 (hxc-cry)))
685 ((comp
686 range
687 count
688 set
689 (partial map :cry-id)
690 vals
691 hxc-cry)
692 rom))))
695 (defn cry-conversion!
696 "Convert Porygon's cry in ROM to be the cry of the given pokemon."
697 [pkmn]
698 (write-rom!
699 (rewrite-memory
700 (vec(rom))
701 0x3965D
702 (map second
703 ((hxc-cry) pkmn)))))
705 #+end_src
707 ** COMMENT Names of permanent stats
708 0DD4D-DD72
710 * Items
711 ** Item names
713 *** See the data
714 #+begin_src clojure :exports both :results output
715 (ns com.aurellem.gb.hxc
716 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
717 constants))
718 (:import [com.aurellem.gb.gb_driver SaveState]))
720 (println (take 100 (drop 0x045B7 (rom))))
722 (println
723 (partition-by
724 (partial = 0x50)
725 (take 100 (drop 0x045B7 (rom)))))
727 (println
728 (map character-codes->str
729 (partition-by
730 (partial = 0x50)
731 (take 100 (drop 0x045B7 (rom))))))
734 #+end_src
736 #+results:
737 : (140 128 146 147 132 145 127 129 128 139 139 80 148 139 147 145 128 127 129 128 139 139 80 134 145 132 128 147 127 129 128 139 139 80 143 142 138 186 127 129 128 139 139 80 147 142 150 141 127 140 128 143 80 129 136 130 152 130 139 132 80 230 230 230 230 230 80 146 128 133 128 145 136 127 129 128 139 139 80 143 142 138 186 131 132 151 80 140 142 142 141 127 146 147 142 141 132 80 128 141)
738 : ((140 128 146 147 132 145 127 129 128 139 139) (80) (148 139 147 145 128 127 129 128 139 139) (80) (134 145 132 128 147 127 129 128 139 139) (80) (143 142 138 186 127 129 128 139 139) (80) (147 142 150 141 127 140 128 143) (80) (129 136 130 152 130 139 132) (80) (230 230 230 230 230) (80) (146 128 133 128 145 136 127 129 128 139 139) (80) (143 142 138 186 131 132 151) (80) (140 142 142 141 127 146 147 142 141 132) (80) (128 141))
739 : (MASTER BALL # ULTRA BALL # GREAT BALL # POKé BALL # TOWN MAP # BICYCLE # ????? # SAFARI BALL # POKéDEX # MOON STONE # AN)
741 *** Automatically grab the data
742 #+name: item-names
743 #+begin_src clojure
745 (def hxc-items-raw
746 "The hardcoded names of the items in memory. List begins at
747 ROM@045B7"
748 (hxc-thunk-words 0x45B7 870))
750 (def hxc-items
751 "The hardcoded names of the items in memory, presented as
752 keywords. List begins at ROM@045B7. See also, hxc-items-raw."
753 (comp (partial map format-name) hxc-items-raw))
754 #+end_src
756 ** Item prices
758 ***
759 #+begin_src clojure :exports both :results output
760 (ns com.aurellem.gb.hxc
761 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
762 constants))
763 (:import [com.aurellem.gb.gb_driver SaveState]))
765 (println (take 90 (drop 0x4495 (rom))))
767 (println
768 (partition 3
769 (take 90 (drop 0x4495 (rom)))))
771 (println
772 (partition 3
773 (map hex
774 (take 90 (drop 0x4495 (rom))))))
776 (println
777 (map decode-bcd
778 (map butlast
779 (partition 3
780 (take 90 (drop 0x4495 (rom)))))))
782 (println
783 (map
784 vector
785 (hxc-items (rom))
786 (map decode-bcd
787 (map butlast
788 (partition 3
789 (take 90 (drop 0x4495 (rom))))))))
795 #+end_src
797 #+results:
798 : (0 0 0 18 0 0 6 0 0 2 0 0 0 0 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 1 0 0 2 80 0 2 80 0 2 0 0 2 0 0 48 0 0 37 0 0 21 0 0 7 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 80 0 3 80 0)
799 : ((0 0 0) (18 0 0) (6 0 0) (2 0 0) (0 0 0) (0 0 0) (0 0 0) (16 0 0) (0 0 0) (0 0 0) (1 0 0) (2 80 0) (2 80 0) (2 0 0) (2 0 0) (48 0 0) (37 0 0) (21 0 0) (7 0 0) (3 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (5 80 0) (3 80 0))
800 : ((0x0 0x0 0x0) (0x12 0x0 0x0) (0x6 0x0 0x0) (0x2 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x10 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x1 0x0 0x0) (0x2 0x50 0x0) (0x2 0x50 0x0) (0x2 0x0 0x0) (0x2 0x0 0x0) (0x30 0x0 0x0) (0x25 0x0 0x0) (0x15 0x0 0x0) (0x7 0x0 0x0) (0x3 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x0 0x0 0x0) (0x5 0x50 0x0) (0x3 0x50 0x0))
801 : (0 1200 600 200 0 0 0 1000 0 0 100 250 250 200 200 3000 2500 1500 700 300 0 0 0 0 0 0 0 0 550 350)
802 : ([:master-ball 0] [:ultra-ball 1200] [:great-ball 600] [:poké-ball 200] [:town-map 0] [:bicycle 0] [:????? 0] [:safari-ball 1000] [:pokédex 0] [:moon-stone 0] [:antidote 100] [:burn-heal 250] [:ice-heal 250] [:awakening 200] [:parlyz-heal 200] [:full-restore 3000] [:max-potion 2500] [:hyper-potion 1500] [:super-potion 700] [:potion 300] [:boulderbadge 0] [:cascadebadge 0] [:thunderbadge 0] [:rainbowbadge 0] [:soulbadge 0] [:marshbadge 0] [:volcanobadge 0] [:earthbadge 0] [:escape-rope 550] [:repel 350])
805 ***
806 #+name: item-prices
807 #+begin_src clojure
808 (defn hxc-item-prices
809 "The hardcoded list of item prices in memory. List begins at ROM@4495"
810 ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))
811 ([rom]
812 (let [items (hxc-items rom)
813 price-size 3]
814 (zipmap items
815 (map (comp
816 ;; zero-cost items are "priceless"
817 #(if (zero? %) :priceless %)
818 decode-bcd butlast)
819 (partition price-size
820 (take (* price-size (count items))
821 (drop 0x4495 rom))))))))
822 #+end_src
823 ** Vendor inventories
825 #+name: item-vendors
826 #+begin_src clojure
827 (defn hxc-shops
828 ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))
829 ([rom]
830 (let [items (zipmap (range) (hxc-items rom))
832 ;; temporarily softcode the TM items
833 items (into
834 items
835 (map (juxt identity
836 (comp keyword
837 (partial str "tm-")
838 (partial + 1 -200)
839 ))
840 (take 200 (drop 200 (range)))))
842 ]
844 ((fn parse-shop [coll [num-items & items-etc]]
845 (let [inventory (take-while
846 (partial not= 0xFF)
847 items-etc)
848 [separator & items-etc] (drop num-items (rest items-etc))]
849 (if (= separator 0x50)
850 (map (partial mapv (comp items dec)) (conj coll inventory))
851 (recur (conj coll inventory) items-etc)
852 )
853 ))
855 '()
856 (drop 0x233C rom))
859 )))
860 #+end_src
862 #+results: item-vendors
863 : #'com.aurellem.gb.hxc/hxc-shops
867 * Types
868 ** Names of types
870 *** COMMENT Pointers to type names
871 #+begin_src clojure :exports both :results output
872 (map (comp character-codes->str #(take-while (partial not= 80) (drop % (rom))) (partial + 0x20000) (partial apply low-high)) (partition 2 (take 54 (drop 0x27D63 (rom)))))
873 #+end_src
876 ***
877 #+begin_src clojure :exports both :results output
878 (ns com.aurellem.gb.hxc
879 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
880 constants))
881 (:import [com.aurellem.gb.gb_driver SaveState]))
883 (println (take 90 (drop 0x27D99 (rom))))
885 (println
886 (partition-by (partial = 0x50)
887 (take 90 (drop 0x27D99 (rom)))))
889 (println
890 (map character-codes->str
891 (partition-by (partial = 0x50)
892 (take 90 (drop 0x27D99 (rom))))))
894 #+end_src
896 #+results:
897 : (141 142 145 140 128 139 80 133 136 134 135 147 136 141 134 80 133 139 152 136 141 134 80 143 142 136 146 142 141 80 133 136 145 132 80 150 128 147 132 145 80 134 145 128 146 146 80 132 139 132 130 147 145 136 130 80 143 146 152 130 135 136 130 80 136 130 132 80 134 145 142 148 141 131 80 145 142 130 138 80 129 136 145 131 80 129 148 134 80 134)
898 : ((141 142 145 140 128 139) (80) (133 136 134 135 147 136 141 134) (80) (133 139 152 136 141 134) (80) (143 142 136 146 142 141) (80) (133 136 145 132) (80) (150 128 147 132 145) (80) (134 145 128 146 146) (80) (132 139 132 130 147 145 136 130) (80) (143 146 152 130 135 136 130) (80) (136 130 132) (80) (134 145 142 148 141 131) (80) (145 142 130 138) (80) (129 136 145 131) (80) (129 148 134) (80) (134))
899 : (NORMAL # FIGHTING # FLYING # POISON # FIRE # WATER # GRASS # ELECTRIC # PSYCHIC # ICE # GROUND # ROCK # BIRD # BUG # G)
902 ***
903 #+name: type-names
904 #+begin_src clojure
905 (def hxc-types
906 "The hardcoded type names in memory. List begins at ROM@27D99,
907 shortly before hxc-titles."
908 (hxc-thunk-words 0x27D99 102))
910 #+end_src
912 ** Type effectiveness
913 ***
914 #+begin_src clojure :exports both :results output
915 (ns com.aurellem.gb.hxc
916 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
917 constants))
918 (:import [com.aurellem.gb.gb_driver SaveState]))
921 ;; POKEMON TYPES
923 (println pkmn-types) ;; these are the pokemon types
924 (println (map vector (range) pkmn-types)) ;; each type has an id number.
926 (newline)
931 ;;; TYPE EFFECTIVENESS
933 (println (take 15 (drop 0x3E5FA (rom))))
934 (println (partition 3 (take 15 (drop 0x3E5FA (rom)))))
936 (println
937 (map
938 (fn [[atk-type def-type multiplier]]
939 (list atk-type def-type (/ multiplier 10.)))
941 (partition 3
942 (take 15 (drop 0x3E5FA (rom))))))
945 (println
946 (map
947 (fn [[atk-type def-type multiplier]]
948 [
949 (get pkmn-types atk-type)
950 (get pkmn-types def-type)
951 (/ multiplier 10.)
952 ])
954 (partition 3
955 (take 15 (drop 0x3E5FA (rom))))))
957 #+end_src
959 #+results:
960 : [:normal :fighting :flying :poison :ground :rock :bird :bug :ghost :A :B :C :D :E :F :G :H :I :J :K :fire :water :grass :electric :psychic :ice :dragon]
961 : ([0 :normal] [1 :fighting] [2 :flying] [3 :poison] [4 :ground] [5 :rock] [6 :bird] [7 :bug] [8 :ghost] [9 :A] [10 :B] [11 :C] [12 :D] [13 :E] [14 :F] [15 :G] [16 :H] [17 :I] [18 :J] [19 :K] [20 :fire] [21 :water] [22 :grass] [23 :electric] [24 :psychic] [25 :ice] [26 :dragon])
962 :
963 : (21 20 20 20 22 20 20 25 20 22 21 20 23 21 20)
964 : ((21 20 20) (20 22 20) (20 25 20) (22 21 20) (23 21 20))
965 : ((21 20 2.0) (20 22 2.0) (20 25 2.0) (22 21 2.0) (23 21 2.0))
966 : ([:water :fire 2.0] [:fire :grass 2.0] [:fire :ice 2.0] [:grass :water 2.0] [:electric :water 2.0])
969 ***
971 #+name: type-advantage
972 #+begin_src clojure
973 (defn hxc-advantage
974 ;; in-game multipliers are stored as 10x their effective value
975 ;; to allow for fractional multipliers like 1/2
977 "The hardcoded type advantages in memory, returned as tuples of
978 atk-type def-type multiplier. By default (i.e. if not listed here),
979 the multiplier is 1. List begins at 0x3E62D."
980 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))
981 ([rom]
982 (map
983 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))
984 (get pkmn-types def (hex def))
985 (/ mult 10)])
986 (partition 3
987 (take-while (partial not= 0xFF)
988 (drop 0x3E5FA rom))))))
989 #+end_src
994 * Moves
995 ** Names of moves
996 *** See the data
997 #+begin_src clojure :exports both :results output
998 (ns com.aurellem.gb.hxc
999 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1000 constants))
1001 (:import [com.aurellem.gb.gb_driver SaveState]))
1003 (println (take 100 (drop 0xBC000 (rom))))
1005 (println
1006 (partition-by
1007 (partial = 0x50)
1008 (take 100 (drop 0xBC000 (rom)))))
1010 (println
1011 (map character-codes->str
1012 (partition-by
1013 (partial = 0x50)
1014 (take 100 (drop 0xBC000 (rom))))))
1017 #+end_src
1019 #+results:
1020 : (143 142 148 141 131 80 138 128 145 128 147 132 127 130 135 142 143 80 131 142 148 129 139 132 146 139 128 143 80 130 142 140 132 147 127 143 148 141 130 135 80 140 132 134 128 127 143 148 141 130 135 80 143 128 152 127 131 128 152 80 133 136 145 132 127 143 148 141 130 135 80 136 130 132 127 143 148 141 130 135 80 147 135 148 141 131 132 145 143 148 141 130 135 80 146 130 145 128 147 130)
1021 : ((143 142 148 141 131) (80) (138 128 145 128 147 132 127 130 135 142 143) (80) (131 142 148 129 139 132 146 139 128 143) (80) (130 142 140 132 147 127 143 148 141 130 135) (80) (140 132 134 128 127 143 148 141 130 135) (80) (143 128 152 127 131 128 152) (80) (133 136 145 132 127 143 148 141 130 135) (80) (136 130 132 127 143 148 141 130 135) (80) (147 135 148 141 131 132 145 143 148 141 130 135) (80) (146 130 145 128 147 130))
1022 : (POUND # KARATE CHOP # DOUBLESLAP # COMET PUNCH # MEGA PUNCH # PAY DAY # FIRE PUNCH # ICE PUNCH # THUNDERPUNCH # SCRATC)
1024 *** Automatically grab the data
1026 #+name: move-names
1027 #+begin_src clojure
1028 (def hxc-move-names
1029 "The hardcoded move names in memory. List begins at ROM@BC000"
1030 (hxc-thunk-words 0xBC000 1551))
1031 #+end_src
1033 ** Properties of moves
1035 #+name: move-data
1036 #+begin_src clojure
1037 (defn hxc-move-data
1038 "The hardcoded (basic (move effects)) in memory. List begins at
1039 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id
1040 :fx-txt}. The move descriptions are handwritten, not hardcoded."
1041 ([]
1042 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))
1043 ([rom]
1044 (let [names (vec (hxc-move-names rom))
1045 move-count (count names)
1046 move-size 6
1047 types pkmn-types ;;; !! hardcoded types
1049 (zipmap (map format-name names)
1050 (map
1051 (fn [[idx effect power type-id accuracy pp]]
1052 {:name (names (dec idx))
1053 :power power
1054 :accuracy accuracy
1055 :pp pp
1056 :type (types type-id)
1057 :fx-id effect
1058 :fx-txt (get move-effects effect)
1062 (partition move-size
1063 (take (* move-size move-count)
1064 (drop 0x38000 rom))))))))
1068 (defn hxc-move-data*
1069 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."
1070 ([]
1071 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))
1072 ([rom]
1073 (let [names (vec (hxc-move-names rom))
1074 move-count (count names)
1075 move-size 6
1076 format-name (fn [s]
1077 (keyword (.toLowerCase
1078 (apply str
1079 (map #(if (= % \space) "-" %) s)))))
1081 (zipmap (map format-name names)
1082 (map
1083 (fn [[idx effect power type accuracy pp]]
1084 {:name (names (dec idx))
1085 :power power
1086 :accuracy (hex accuracy)
1087 :pp pp
1088 :fx-id (hex effect)
1089 :fx-txt (get move-effects effect)
1093 (partition move-size
1094 (take (* move-size move-count)
1095 (drop 0x38000 rom))))))))
1097 #+end_src
1099 ** TM and HM moves
1100 ***
1101 #+begin_src clojure :exports both :results output
1102 (ns com.aurellem.gb.hxc
1103 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1104 constants))
1105 (:import [com.aurellem.gb.gb_driver SaveState]))
1108 (println (hxc-move-names))
1109 (println (map vector (rest(range)) (hxc-move-names)))
1111 (newline)
1113 (println (take 55 (drop 0x1232D (rom))))
1115 (println
1116 (interpose "."
1117 (map
1118 (zipmap (rest (range)) (hxc-move-names))
1119 (take 55 (drop 0x1232D (rom))))))
1121 #+end_src
1123 #+results:
1124 : (POUND KARATE CHOP DOUBLESLAP COMET PUNCH MEGA PUNCH PAY DAY FIRE PUNCH ICE PUNCH THUNDERPUNCH SCRATCH VICEGRIP GUILLOTINE RAZOR WIND SWORDS DANCE CUT GUST WING ATTACK WHIRLWIND FLY BIND SLAM VINE WHIP STOMP DOUBLE KICK MEGA KICK JUMP KICK ROLLING KICK SAND-ATTACK HEADBUTT HORN ATTACK FURY ATTACK HORN DRILL TACKLE BODY SLAM WRAP TAKE DOWN THRASH DOUBLE-EDGE TAIL WHIP POISON STING TWINEEDLE PIN MISSILE LEER BITE GROWL ROAR SING SUPERSONIC SONICBOOM DISABLE ACID EMBER FLAMETHROWER MIST WATER GUN HYDRO PUMP SURF ICE BEAM BLIZZARD PSYBEAM BUBBLEBEAM AURORA BEAM HYPER BEAM PECK DRILL PECK SUBMISSION LOW KICK COUNTER SEISMIC TOSS STRENGTH ABSORB MEGA DRAIN LEECH SEED GROWTH RAZOR LEAF SOLARBEAM POISONPOWDER STUN SPORE SLEEP POWDER PETAL DANCE STRING SHOT DRAGON RAGE FIRE SPIN THUNDERSHOCK THUNDERBOLT THUNDER WAVE THUNDER ROCK THROW EARTHQUAKE FISSURE DIG TOXIC CONFUSION PSYCHIC HYPNOSIS MEDITATE AGILITY QUICK ATTACK RAGE TELEPORT NIGHT SHADE MIMIC SCREECH DOUBLE TEAM RECOVER HARDEN MINIMIZE SMOKESCREEN CONFUSE RAY WITHDRAW DEFENSE CURL BARRIER LIGHT SCREEN HAZE REFLECT FOCUS ENERGY BIDE METRONOME MIRROR MOVE SELFDESTRUCT EGG BOMB LICK SMOG SLUDGE BONE CLUB FIRE BLAST WATERFALL CLAMP SWIFT SKULL BASH SPIKE CANNON CONSTRICT AMNESIA KINESIS SOFTBOILED HI JUMP KICK GLARE DREAM EATER POISON GAS BARRAGE LEECH LIFE LOVELY KISS SKY ATTACK TRANSFORM BUBBLE DIZZY PUNCH SPORE FLASH PSYWAVE SPLASH ACID ARMOR CRABHAMMER EXPLOSION FURY SWIPES BONEMERANG REST ROCK SLIDE HYPER FANG SHARPEN CONVERSION TRI ATTACK SUPER FANG SLASH SUBSTITUTE STRUGGLE)
1125 : ([1 POUND] [2 KARATE CHOP] [3 DOUBLESLAP] [4 COMET PUNCH] [5 MEGA PUNCH] [6 PAY DAY] [7 FIRE PUNCH] [8 ICE PUNCH] [9 THUNDERPUNCH] [10 SCRATCH] [11 VICEGRIP] [12 GUILLOTINE] [13 RAZOR WIND] [14 SWORDS DANCE] [15 CUT] [16 GUST] [17 WING ATTACK] [18 WHIRLWIND] [19 FLY] [20 BIND] [21 SLAM] [22 VINE WHIP] [23 STOMP] [24 DOUBLE KICK] [25 MEGA KICK] [26 JUMP KICK] [27 ROLLING KICK] [28 SAND-ATTACK] [29 HEADBUTT] [30 HORN ATTACK] [31 FURY ATTACK] [32 HORN DRILL] [33 TACKLE] [34 BODY SLAM] [35 WRAP] [36 TAKE DOWN] [37 THRASH] [38 DOUBLE-EDGE] [39 TAIL WHIP] [40 POISON STING] [41 TWINEEDLE] [42 PIN MISSILE] [43 LEER] [44 BITE] [45 GROWL] [46 ROAR] [47 SING] [48 SUPERSONIC] [49 SONICBOOM] [50 DISABLE] [51 ACID] [52 EMBER] [53 FLAMETHROWER] [54 MIST] [55 WATER GUN] [56 HYDRO PUMP] [57 SURF] [58 ICE BEAM] [59 BLIZZARD] [60 PSYBEAM] [61 BUBBLEBEAM] [62 AURORA BEAM] [63 HYPER BEAM] [64 PECK] [65 DRILL PECK] [66 SUBMISSION] [67 LOW KICK] [68 COUNTER] [69 SEISMIC TOSS] [70 STRENGTH] [71 ABSORB] [72 MEGA DRAIN] [73 LEECH SEED] [74 GROWTH] [75 RAZOR LEAF] [76 SOLARBEAM] [77 POISONPOWDER] [78 STUN SPORE] [79 SLEEP POWDER] [80 PETAL DANCE] [81 STRING SHOT] [82 DRAGON RAGE] [83 FIRE SPIN] [84 THUNDERSHOCK] [85 THUNDERBOLT] [86 THUNDER WAVE] [87 THUNDER] [88 ROCK THROW] [89 EARTHQUAKE] [90 FISSURE] [91 DIG] [92 TOXIC] [93 CONFUSION] [94 PSYCHIC] [95 HYPNOSIS] [96 MEDITATE] [97 AGILITY] [98 QUICK ATTACK] [99 RAGE] [100 TELEPORT] [101 NIGHT SHADE] [102 MIMIC] [103 SCREECH] [104 DOUBLE TEAM] [105 RECOVER] [106 HARDEN] [107 MINIMIZE] [108 SMOKESCREEN] [109 CONFUSE RAY] [110 WITHDRAW] [111 DEFENSE CURL] [112 BARRIER] [113 LIGHT SCREEN] [114 HAZE] [115 REFLECT] [116 FOCUS ENERGY] [117 BIDE] [118 METRONOME] [119 MIRROR MOVE] [120 SELFDESTRUCT] [121 EGG BOMB] [122 LICK] [123 SMOG] [124 SLUDGE] [125 BONE CLUB] [126 FIRE BLAST] [127 WATERFALL] [128 CLAMP] [129 SWIFT] [130 SKULL BASH] [131 SPIKE CANNON] [132 CONSTRICT] [133 AMNESIA] [134 KINESIS] [135 SOFTBOILED] [136 HI JUMP KICK] [137 GLARE] [138 DREAM EATER] [139 POISON GAS] [140 BARRAGE] [141 LEECH LIFE] [142 LOVELY KISS] [143 SKY ATTACK] [144 TRANSFORM] [145 BUBBLE] [146 DIZZY PUNCH] [147 SPORE] [148 FLASH] [149 PSYWAVE] [150 SPLASH] [151 ACID ARMOR] [152 CRABHAMMER] [153 EXPLOSION] [154 FURY SWIPES] [155 BONEMERANG] [156 REST] [157 ROCK SLIDE] [158 HYPER FANG] [159 SHARPEN] [160 CONVERSION] [161 TRI ATTACK] [162 SUPER FANG] [163 SLASH] [164 SUBSTITUTE] [165 STRUGGLE])
1127 : (5 13 14 18 25 92 32 34 36 38 61 55 58 59 63 6 66 68 69 99 72 76 82 85 87 89 90 91 94 100 102 104 115 117 118 120 121 126 129 130 135 138 143 156 86 149 153 157 161 164 15 19 57 70 148)
1128 : (MEGA PUNCH . RAZOR WIND . SWORDS DANCE . WHIRLWIND . MEGA KICK . TOXIC . HORN DRILL . BODY SLAM . TAKE DOWN . DOUBLE-EDGE . BUBBLEBEAM . WATER GUN . ICE BEAM . BLIZZARD . HYPER BEAM . PAY DAY . SUBMISSION . COUNTER . SEISMIC TOSS . RAGE . MEGA DRAIN . SOLARBEAM . DRAGON RAGE . THUNDERBOLT . THUNDER . EARTHQUAKE . FISSURE . DIG . PSYCHIC . TELEPORT . MIMIC . DOUBLE TEAM . REFLECT . BIDE . METRONOME . SELFDESTRUCT . EGG BOMB . FIRE BLAST . SWIFT . SKULL BASH . SOFTBOILED . DREAM EATER . SKY ATTACK . REST . THUNDER WAVE . PSYWAVE . EXPLOSION . ROCK SLIDE . TRI ATTACK . SUBSTITUTE . CUT . FLY . SURF . STRENGTH . FLASH)
1131 ***
1132 #+name: machines
1133 #+begin_src clojure
1134 (defn hxc-machines
1135 "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."
1136 ([] (hxc-machines
1137 com.aurellem.gb.gb-driver/original-rom))
1138 ([rom]
1139 (let [moves (hxc-move-names rom)]
1140 (zipmap
1141 (range)
1142 (take-while
1143 (comp not nil?)
1144 (map (comp
1145 format-name
1146 (zipmap
1147 (range)
1148 moves)
1149 dec)
1150 (take 100
1151 (drop 0x1232D rom))))))))
1153 #+end_src
1159 ** COMMENT Status ailments
1162 * NPC Trainers
1164 ** Trainer Pok\eacute{}mon
1165 # http://hax.iimarck.us/topic/103/
1166 There are two formats for specifying lists of NPC PPok\eacute{}mon:
1167 - If all the Pok\eacute{}mon will have the same level, the format is
1168 - Level (used for all the Pok\eacute{}mon)
1169 - Any number of Pok\eacute{}mon internal ids.
1170 - 0x00, to indicate end-of-list.
1171 - Otherwise, all the Pok\eacute{}mon will have their level
1172 specified. The format is
1173 - 0xFF, to indicate that we will be specifying the levels individually[fn::Because 0xFF is a
1174 forbidden level within the usual gameplay discipline, the game
1175 makers could safely use 0xFF as a mode indicator.].
1176 - Any number of alternating Level/Pokemon pairs
1177 - 0x00, to indicate end-of-list.
1179 *** Get the pointers
1180 *** See the data
1181 #+begin_src clojure :exports both :results output
1182 (ns com.aurellem.gb.hxc
1183 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1184 constants))
1185 (:import [com.aurellem.gb.gb_driver SaveState]))
1187 (->>
1188 (rom)
1189 (drop 0x39E2F)
1190 (take 21)
1191 (println))
1194 (->>
1195 (rom)
1196 (drop 0x39E2F)
1197 (take 21)
1198 (partition-by zero?)
1199 (take-nth 2)
1200 (println))
1204 (let
1205 [pokenames
1206 (zipmap
1207 (rest (range))
1208 (hxc-pokenames-raw))]
1210 (->>
1211 (rom)
1212 (drop 0x39E2F)
1213 (take 21) ;; (1922 in all)
1214 (partition-by zero?)
1215 (take-nth 2)
1216 (map
1217 (fn parse-team [[mode & team]]
1218 (if (not= 0xFF mode)
1219 (mapv
1220 #(hash-map :level mode :species (pokenames %))
1221 team)
1223 (mapv
1224 (fn [[lvl id]] (hash-map :level lvl :species (pokenames id)))
1225 (partition 2 team)))))
1227 (println)))
1231 #+end_src
1233 #+results:
1234 : (11 165 108 0 14 5 0 10 165 165 107 0 14 165 108 107 0 15 165 5 0)
1235 : ((11 165 108) (14 5) (10 165 165 107) (14 165 108 107) (15 165 5))
1236 : ([{:species RATTATA, :level 11} {:species EKANS, :level 11}] [{:species SPEAROW, :level 14}] [{:species RATTATA, :level 10} {:species RATTATA, :level 10} {:species ZUBAT, :level 10}] [{:species RATTATA, :level 14} {:species EKANS, :level 14} {:species ZUBAT, :level 14}] [{:species RATTATA, :level 15} {:species SPEAROW, :level 15}])
1238 * Places
1239 ** Names of places
1241 #+name: places
1242 #+begin_src clojure
1243 (def hxc-places
1244 "The hardcoded place names in memory. List begins at
1245 ROM@71500. [Cinnabar/Celadon] Mansion seems to be dynamically calculated."
1246 (hxc-thunk-words 0x71500 560))
1247 #+end_src
1249 *** See it work
1250 #+begin_src clojure :exports both :results output
1251 (println (hxc-places))
1252 #+end_src
1254 #+results:
1255 : (PALLET TOWN VIRIDIAN CITY PEWTER CITY CERULEAN CITY LAVENDER TOWN VERMILION CITY CELADON CITY FUCHSIA CITY CINNABAR ISLAND INDIGO PLATEAU SAFFRON CITY ROUTE 1 ROUTE 2 ROUTE 3 ROUTE 4 ROUTE 5 ROUTE 6 ROUTE 7 ROUTE 8 ROUTE 9 ROUTE 10 ROUTE 11 ROUTE 12 ROUTE 13 ROUTE 14 ROUTE 15 ROUTE 16 ROUTE 17 ROUTE 18 SEA ROUTE 19 SEA ROUTE 20 SEA ROUTE 21 ROUTE 22 ROUTE 23 ROUTE 24 ROUTE 25 VIRIDIAN FOREST MT.MOON ROCK TUNNEL SEA COTTAGE S.S.ANNE [POKE]MON LEAGUE UNDERGROUND PATH [POKE]MON TOWER SEAFOAM ISLANDS VICTORY ROAD DIGLETT's CAVE ROCKET HQ SILPH CO. [0x4A] MANSION SAFARI ZONE)
1257 ** Wild Pok\eacute{}mon demographics
1258 #+name: wilds
1259 #+begin_src clojure
1261 ;; 0x0489, relative to 0xCB95, points to 0xCD89.
1262 (defn hxc-ptrs-wild
1263 "A list of the hardcoded wild encounter data in memory. Pointers
1264 begin at ROM@0CB95; data begins at ROM@0x0CD89"
1265 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))
1266 ([rom]
1267 (let [ptrs
1268 (map (fn [[a b]] (+ a (* 0x100 b)))
1269 (take-while (partial not= (list 0xFF 0xFF))
1270 (partition 2 (drop 0xCB95 rom))))]
1271 ptrs)))
1275 (defn hxc-wilds
1276 "A list of the hardcoded wild encounter data in memory. Pointers
1277 begin at ROM@0CB95; data begins at ROM@0x0CD89"
1278 ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))
1279 ([rom]
1280 (let [pokenames (zipmap (range) (hxc-pokenames rom))]
1281 (map
1282 (partial map
1283 (fn [[a b]]
1284 {:species (pokenames (dec b))
1285 :level a}))
1286 (partition 10
1287 (take-while
1288 (comp (partial not= 1) first)
1289 (partition 2
1290 (drop 0xCD8C rom))
1292 ))))))
1294 #+end_src
1299 ** Map data
1301 # http://www.pokecommunity.com/showthread.php?t=235311
1302 # http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes
1304 #+name map
1305 #+begin_src clojure :exports both :results output
1306 (ns com.aurellem.gb.hxc
1307 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1308 constants))
1309 (:import [com.aurellem.gb.gb_driver SaveState]))
1312 (defn parse-header-tileset
1313 [[bank# ;; memory bank for blocks & tileset
1315 blocks-lo ;; structure
1316 blocks-hi
1318 tileset-lo ;; style
1319 tileset-hi
1321 collision-lo ;; collision info
1322 collision-hi
1324 talk-here-1 ;; positions of up to three
1325 talk-here-2 ;; talk-over-countertop tiles
1326 talk-here-3 ;; --- 0xFF if unused.
1328 grass ;; grass tile --- 0xFF if unused
1330 animation-flags ;; settings for animation
1331 & _]]
1333 [bank#
1335 blocks-lo ;; structure
1336 blocks-hi
1338 tileset-lo ;; style
1339 tileset-hi
1341 collision-lo ;; collision info
1342 collision-hi
1344 talk-here-1 ;; positions of up to three
1345 talk-here-2 ;; talk-over-countertop tiles
1346 talk-here-3 ;; --- 0xFF if unused.
1348 grass ;; grass tile --- 0xFF if unused
1350 animation-flags ;; settings for animation
1351 ])
1355 (defn parse-header-map
1356 [start]
1358 (let [connection-size 11
1360 [tileset-index
1361 map-height
1362 map-width
1363 layout-lo
1364 layout-hi
1365 text-lo
1366 text-hi
1367 script-lo
1368 script-hi
1369 adjacency-flags ;; x x x x N S W E
1370 & etc]
1371 (drop start (rom))
1373 [east? west? south? north?]
1374 (bit-list adjacency-flags)
1376 [connections object-data]
1377 (split-at
1378 (* connection-size (+ east? west? south? north?))
1379 etc)
1381 connections
1382 (partition connection-size connections)
1388 (ptr->offset
1390 (low-high layout-lo layout-hi))
1393 ))
1394 #+end_src
1396 #+results:
1401 * Appendices
1402 ** Mapping the ROM
1403 # D3AD: Script:Use Pokeball?
1405 | ROM address (hex) | Description | Format | Example |
1406 |-----------------------+-----------------+-----------------+-----------------|
1407 | | <15> | <15> | <15> |
1408 | 01823-0184A | Important prefix strings. | Variable-length strings, separated by 0x50. | TM#TRAINER#PC#ROCKET#POK\eacute{}#... |
1409 | 0233C- | Shop inventories. | | |
1410 | 02F47- | (?) Move ids of some HM moves. | One byte per move id | 0x0F 0x13 0x39 0x46 0x94 0xFF, the move ids of CUT, FLY, SURF, STRENGTH, FLASH, then cancel. |
1411 | 03E59- | Start of the Give-Pok\eacute{}mon script. | Assembly. When called, converts the contents of register BC into a Pok\eacute{}mon: (B) is the level; (C) is the species. | |
1412 | 03E3F- | Start of the give-item script. | Assembly. When called, converts the contents of register BC into an item: (B) is the item type; (C) is the quantity. | |
1413 | 04495- | Prices of items. | Each price is two bytes of binary-coded decimal. Prices are separated by zeroes. Priceless items[fn::Like the Pok\eacute{}dex and other unsellable items.] are given a price of zero. | The cost of lemonade is 0x03 0x50, which translates to a price of ₱350. |
1414 | 04524-04527 | (unconfirmed) possibly the bike price in Cerulean. | | |
1415 | 045B7-0491E | Names of the items in memory. | Variable-length item names (strings of character codes). Names are separated by a single 0x50 character. | MASTER BALL#ULTRA BALL#... |
1416 |-----------------------+-----------------+-----------------+-----------------|
1417 | 05DD2-05DF2 | Menu text for player info. | | PLAYER [newline] BADGES [nelwine] POK\Eacute{}DEX [newline] TIME [0x50] |
1418 | 05EDB. | Which Pok\eacute{}mon to show during Prof. Oak's introduction. | A single byte, the Pok\eacute{}mon's internal id. | In Pok\eacute{}mon Yellow, it shows Pikachu during the introduction; Pikachu's internal id is 0x54. |
1419 | 06698- | ? Background music. | | |
1420 |-----------------------+-----------------+-----------------+-----------------|
1421 | 7550-7570 | Menu options for map directions[fn:unused:According to [[http://tcrf.net/Pok%C3%A9mon_Red_and_Blue#NORTH.2FWEST.2FSOUTH.2FEAST][The Cutting Room Floor]], this data is unused. ]. | Variable-length strings. | NORTH [newline] WEST [0x50] SOUTH [newline] EAST [0x50] NORTH [newline] EAST[0x50] |
1422 | 7570-757D | Menu options for trading Pok\eacute{}mon | | TRADE [newline] CANCEL [0x50] |
1423 | 757D-758A | Menu options for healing Pok\eacute{}mon | | HEAL [newline] CANCEL [0x50] |
1424 | 7635- | Menu options for selected Pok\eacute{}mon (Includes names of out-of-battle moves). | Variable-length strings separated by 0x50. | CUT [0x50] FLY [0x50] SURF [0x50] STRENGTH [0x50] FLASH [0x50] DIG [0x50] TELEPORT [0x50] SOFTBOILED [0x50] STATS [newline] SWITCH [newline] CANCEL [0x50] |
1425 | 7AF0-8000 | (empty space) | | 0 0 0 0 0 ... |
1426 | 0822E-082F? | Pointers to background music, part I. | | |
1427 | 0CB95- | Pointers to lists of wild pokemon to encounter in each region. These lists begin at 04D89, see above. | Each pointer is a low-byte, high-byte pair. | The first entry is 0x89 0x4D, corresponding to the address 0x4D89 relative to this memory bank, i.e. absolute address 0xCD89, the location of the first list of wild Pok\eacute{}mon. (For details on pointer addresses, see the relevant appendix.) |
1428 | 0CD89- | Lists of wild Pok\eacute{}mon to encounter in each region. | Lists of 12 bytes. First, an encounter rate[fn::I suspect this is an amount out of 256.]. Next, ten alternating Pok\eacute{}mon/level pairs. Each list ends with 0x00. If the encounter rate is zero, the list ends immediately. | The first nonempty list (located at ROM@0CD8B) is (25; 3 36 4 36 2 165 3 165 2 36 3 36 5 36 4 165 6 36 7 36; 0), i.e. 25 encounter rate; level 3 pidgey, level 4 pidgey, level 2 rattata, level 3 rattata, level 2 pidgey, level 3 pidgey, level 5 pidgey, level 4 rattata, level 6 pidgey, level 7 pidgey, 0 (i.e., end-of-list). |
1429 |-----------------------+-----------------+-----------------+-----------------|
1430 | 0DACB. | Amount of HP restored by Soda Pop | The HP consists of a single numerical byte. | 60 |
1431 | 0DACF. | Amount of HP restored by Lemonade | " | 80 |
1432 | 0DAD5. | Amount of HP restored by Fresh Water | " | 50 |
1433 | 0DADB. | Amount of HP restored by Hyper Potion. | " | 200 |
1434 | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 |
1435 | 0DAE3. | Amount of HP restored by Potion. | " | 20 |
1436 |-----------------------+-----------------+-----------------+-----------------|
1437 | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# |
1438 |-----------------------+-----------------+-----------------+-----------------|
1439 | 0DE2F. | Duration of Repel. | A single byte, representing the number of steps you can take before the effect wears off. | 100 |
1440 | 0DF39. | Duration of Super Repel. | " | 200 |
1441 | 0DF3E. | Duration of Max Repel. | " | 250 |
1442 |-----------------------+-----------------+-----------------+-----------------|
1443 | 1164B- | Terminology for the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | TYPE1[newline]TYPE2[newline] *№*,[newline]OT,[newline][0x50]STATUS,[0x50]OK |
1444 | 116DE- | Terminology for permanent stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | ATTACK[newline]DEFENSE[newline]SPEED[newline]SPECIAL[0x50] |
1445 | 11852- | Terminology for current stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | EXP POINTS[newline]LEVEL UP[0x50] |
1446 | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1447 | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1448 |-----------------------+-----------------+-----------------+-----------------|
1449 | 11D53. | Which badge is a prerequisite for CUT? | op code: which bit of A to test? | When this script is called, the bits of A contain your badges, and this op code will check a certain bit of A. The op codes for the badges are, in order, [0x47 0x4F 0x57 0x5F 0x67 0x6F 0x77 0x7F]. |
1450 | 11D67. | Which badge is a prerequisite for SURF? | " | 0x67 (test for Soul Badge) |
1451 | 11DAC. | Which badge is a prerequisite for STRENGTH? | " | 0x5F (test for Rainbow Badge) |
1452 |-----------------------+-----------------+-----------------+-----------------|
1453 | 1232D-12364 | Which moves are taught by the TMs and HMs | A list of 55 move ids (50 TMs, plus 5 HMs). First, the move that will be taught by TM01; second, the move that will be taught by TM02; and so on. The last five entries are the moves taught by HMs 1-5. (See also, BC000 below) | The first few entries are (5 13 14 18 ...) corresponding to Mega Punch (TM01), Razor Wind (TM02), Swords Dance (TM03), Whirlwind (TM04), ... |
1454 |-----------------------+-----------------+-----------------+-----------------|
1455 | 1CF8B-1CF8C | Which Pok\eacute{}mon does Melanie give you in Cerulean City? | A level/internal-id pair. | (10 153), corresponding to a level 10 Bulbasaur. |
1456 | 1D651-1D652 | Which Pok\eacute{}mon do you find at the top of Celadon Mansion? | A level/internal-id pair. | (25 102), corresponding to a level 25 Eevee. |
1457 |-----------------------+-----------------+-----------------+-----------------|
1458 | 27D56 & 27D57. | Pointer to the pointers to type names. | A single low-byte, high-byte pair. | 0x63 0x7D, corresponding to location 27D63\mdash{} the start of the next entry. |
1459 | 27D63-27D99 | Pointers to type names. | Each point is a low-byte, high-byte pair. The type names follows immediately after this section; see below. | The first pointer is [0x99 0x7D], corresponding to the location 27D99 ("NORMAL"). |
1460 | 27D99-27DFF | Names of the Pok\eacute{}mon types. | Variable-length type names (strings of character codes). Names are separated by a single 0x50 character. | NORMAL#FIGHTING#... |
1461 | 27DFF-27E77 | ? | 120 bytes of unknown data. | |
1462 | 27E77- | Trainer title names. | Variable-length names separated by 0x50. | YOUNGSTER#BUG CATCHER#LASS#... |
1463 | 34000- | | | |
1464 | 38000-383DE | The basic properties and effects of moves. (165 moves total) | Fixed-length (6 byte) continguous descriptions (no separating character): move-index, move-effect, power, move-type, accuracy, pp. | The entry for Pound, the first attack in the list, is (1 0 40 0 255 35). See below for more explanation. |
1465 | 383DE- | Species data for the Pokemon, listed in Pokedex order: Pokedex number; base moves; types; learnable TMs and HMs; base HP, attack, defense, speed, special; sprite data. | | |
1466 | 39462- | The Pok\eacute{}mon cry data. | Fixed-length (3 byte) descriptions of cries. | |
1467 |-----------------------+-----------------+-----------------+-----------------|
1468 | 3997D-39B05 | Trainer titles (extended; see 27E77). This list includes strictly more trainers, seemingly at random inserted into the list from 27E77.[fn::The names added are in bold: YOUNGSTER, BUG CATCHER, LASS, *SAILOR*, JR TRAINER(m), JR TRAINER(f), POK\eacute{}MANIAC, SUPER NERD, *HIKER*, *BIKER*, BURGLAR, ENGINEER, JUGGLER, *FISHERMAN*, SWIMMER, *CUE BALL*, *GAMBLER*, BEAUTY, *PSYCHIC*, ROCKER, JUGGLER (again), *TAMER*, *BIRDKEEPER*, BLACKBELT, *RIVAL1*, PROF OAK, CHIEF, SCIENTIST, *GIOVANNI*, ROCKET, COOLTRAINER(m), COOLTRAINER(f), *BRUNO*, *BROCK*, *MISTY*, *LT. SURGE*, *ERIKA*, *KOGA*, *BLAINE*, *SABRINA*, *GENTLEMAN*, *RIVAL2*, *RIVAL3*, *LORELEI*, *CHANNELER*, *AGATHA*, *LANCE*.] | | |
1469 | 39B05-39DD0. | unknown | | |
1470 | 39DD1-39E2E | Pointers to trainer Pok\eacute{}mon | Pairs of low-high bits. | The first pair is 0x2F 0x5E, which corresponds to memory location 5E2F relative to this 38000-3C000 bank, i.e.[fn::For details about how relative bank pointers work, see the relevant Appendix.] position 39E2F overall. |
1471 | 39E2F-3A5B2 | Trainer Pok\eacute{}mon | Specially-formatted lists of various length, separated by 0x00. If the list starts with 0xFF, the rest of the list will alternate between levels and internal-ids. Otherwise, start of the list is the level of the whole team, and the rest of the list is internal-ids. | The first entry is (11 165 108 0), which means a level 11 team consisting of Rattata and Ekans. The entry for MISTY is (255 18 27 21 152 0), which means a team of various levels consisting of level 18 Staryu and level 21 Starmie. [fn::Incidentally, if you want to change your rival's starter Pok\eacute{}mon, it's enough just to change its species in all of your battles with him.].) |
1472 | 3B1E5-3B361 | Pointers to evolution/learnset data. | One high-low byte pair for each of the 190 Pok\eacute{}mon in internal order. | |
1473 |-----------------------+-----------------+-----------------+-----------------|
1474 | 3B361-3BBAA | *Evolution and learnset data*. [fn::Evolution data consists of how to make Pok\eacute{}mon evolve, and what they evolve into. Learnset data consists of the moves that Pok\eacute{}mon learn as they level up.] | Variable-length evolution information (see below), followed by a list of level/move-id learnset pairs. | |
1475 | 3BBAA-3C000 | (empty) | | 0 0 0 0 ... |
1476 |-----------------------+-----------------+-----------------+-----------------|
1477 | 3D131-3D133 | The inventory of both OLD MAN and PROF. OAK when they battle for you. | Pairs of [item-id quantity], terminated by 0xFF. | (0x04 0x01 0xFF) They only have one Pok\eacute{}ball [fn::If you give them any ball, OAK will catch the enemy Pok\eacute{}mon and OLD MAN will miss. (OLD MAN misses even if he throws a MASTER BALL, which is a sight to see!) If you give them some other item first in the list, you'll be able to use that item normally but then you'll trigger the Safari Zone message: Pa will claim you're out of SAFARI BALLs and the battle will end. If you engage in either an OLD MAN or OAK battle with a Gym Leader, you will [1] get reprimanded if you try to throw a ball [2] incur the Safari Zone message [3] automatically win no matter which item you use [4] earn whichever reward they give you as usual [5] permanently retain the name OLD MAN / PROF. OAK.]. |
1478 | 3D6C7-3D6D6 | Two miscellaneous strings. | Variable length, separated by 0x50 | Disabled!#TYPE |
1479 | 3E190-3E194 | Which moves have an increased critical-hit ratio? | List of move ids, terminated by 0xFF. | (0x02 0x4B 0x98 0xA3 0xFF) corresponding to karate-chop, razor-leaf, crabhammer, slash, end-of-list. |
1480 | 3E200-3E204 | " (???) | " | " |
1481 | 3E231. | Besides normal-type, which type of move can COUNTER counter? | A single byte representing a type id. | This is set to 1, the id of the FIGHTING type. |
1482 | 3E5FA-3E6F0. | *Type effectiveness* | Triples of bytes: =atk-type=, =def-type=, =multiplier=. The multiplier is stored as 10x its actual value to allow for fractions; so, 20 means 2.0x effective, 5 means 0.5x effective. Unlisted type combinations have 1.0x effectiveness by default. | The first few entries are (21 20 20) (20 22 20) (20 25 20) (22 21 20) (23 21 20), corresponding to [:water :fire 2.0] [:fire :grass 2.0] [:fire :ice 2.0] |
1483 |-----------------------+-----------------+-----------------+-----------------|
1484 | 40252-4027B | Pok\eacute{}dex menu text | Variable-length strings separated by 0x50. | SEEN#OWN#CONTENTS#... |
1485 | 40370-40386 | Important constants for Pok\eacute{}dex entries | | HT _ _ *?′??″* [newline] WT _ _ _ *???* lb [0x50] *POK\Eacute{}* [0x50] |
1486 | 40687-41072 | Species data from the Pok\eacute{}dex: species name, height, weight, etc. | Variable-length species names, followed by 0x50, followed by fixed-length height/weight/etc. data. | The first entry is (*146 132 132 131*, 80, *2 4*, *150 0*, 23, 0 64 46, 80), which are the the stats of Bulbasaur: the first entry spells "SEED", then 0x80, then the height (2' 4"), then the weight (formatted as a low-high byte pair), then various Pokédex pointer data (see elsewhere). |
1487 | 41072- | Pok\eacute{} placeholder species, "???" | | |
1488 |-----------------------+-----------------+-----------------+-----------------|
1489 | 410B1-4116F | A conversion table between internal order and Pokedex order. | 190 bytes, corresponding to the Pok\eacute{}dex numbers of the 190 Pok\eacute{}mon listed in internal order. All =MISSINGNO.= are assigned a Pok\eacute{}dex number of 0. | The first few entries are (112 115 32 35 21 100 34 80 2 ...), which are the Pok\eacute{}dex numbers of Rhydon, Kangaskhan, Nidoran(m), Clefairy, Spearow, Voltorb, Nidoking, Slobrow, and Ivysaur. |
1490 |-----------------------+-----------------+-----------------+-----------------|
1491 | 509B4-509E0 | Saffron City's adjacency info. | Four adjacency lists, each 11 bytes long. (For more info on adjacency lists a.k.a. connection data, see [[http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes][here]]) | The first adjacency list is (0x10 0x70 0x46 0xF0 0xC6 0x0A 0x0A 0x23 0xF6 0x09 0xC8) |
1492 |-----------------------+-----------------+-----------------+-----------------|
1493 | 515AE-515AF | Which Pok\eacute{}mon does the trainer near Route 25 give you? | A level/internal-id pair. | (10 176) corresponding to a level 10 Charmander. |
1494 | 51DD5-51DD6 | Which Pok\eacute{}mon does the Silph Co. trainer give you? | A level/internal-id pair. | (15 19) corresponding to a level 15 Lapras. |
1495 |-----------------------+-----------------+-----------------+-----------------|
1496 | 527BA-527DB | The costs and kinds of prizes from Celadon Game Corner. | The following pattern repeats three times, once per window[fn::For the first two prize lists, ids are interpreted as Pok\eacute{}mon ids. For the last prize list, ids are (somehow) interpreted as item ids.]: Internal ids / 0x50 / Prices (two bytes of BCD)/ 0x50. | (0x94 0x52 0x65 0x50) Abra Vulpix Wigglytuff (0x02 0x30 0x10 0x00 0x26 0x80) 230C, 1000C, 2680C |
1497 | 5DE10-5DE30 | Abbreviations for status ailments. | Fixed-length strings, probably[fn::Here's something strange: all of the status messages start with 0x7F and end with 0x4F \mdash{}except PAR, which ends with 0x50.]. The last entry is QUIT##. | [0x7F] *SLP* [0x4E][0x7F] *PSN* [0x4E][0x7F] *PAR* [0x50][0x7F]... |
1498 |-----------------------+-----------------+-----------------+-----------------|
1499 | 70295- | Hall of fame | The text "HALL OF FAME" | |
1500 | 70442- | Play time/money | The text "PLAY TIME [0x50] MONEY" | |
1501 | 71500-7174B | Names of places. | Variable-length place names (strings), separated by 0x50. | PALLET TOWN#VIRIDIAN CITY#PEWTER CITY#CERULEAN CITY#... |
1502 | 71C1E-71CAA (approx.) | Tradeable NPC Pok\eacute{}mon. | Internal ID, followed by nickname (11 chars; extra space padded by 0x50). Some of the Pokemon have unknown extra data around the id. | The first entry is [0x76] "GURIO######", corresponding to a Dugtrio named "GURIO". |
1503 | 7C249-7C2?? | Pointers to background music, pt II. | | |
1504 |-----------------------+-----------------+-----------------+-----------------|
1505 | 98000-B7190 | Dialogue and other messsages. | Variable-length strings. | |
1506 | B7190-B8000 | (empty space) | | 0 0 0 0 0 ... |
1507 | B8000-BC000 | The text of each Pok\eacute{}mon's Pok\eacute{}dex entry. | Variable-length descriptions (strings) in Pok\eacute{}dex order, separated by 0x50. These entries use the special characters *0x49* (new page), *0x4E* (new line), and *0x5F* (end entry). | The first entry (Bulbasaur's) is: "It can go for days [0x4E] without eating a [0x4E] single morsel. [0x49] In the bulb on [0x4E] its back, it [0x4E] stores energy [0x5F] [0x50]." |
1508 | BC000-BC60F | Move names. | Variable-length move names, separated by 0x50. The moves are in internal order. | POUND#KARATE CHOP#DOUBLESLAP#COMET PUNCH#... |
1509 | BC610-BD000 | (empty space) | | 0 0 0 0 0 ... |
1510 | E8000-E876C | Names of the \ldquo{}190\rdquo{} species of Pok\eacute{}mon in memory. | Fixed length (10-letter) Pok\eacute{}mon names. Any extra space is padded with the character 0x50. The names are in \ldquo{}internal order\rdquo{}. | RHYDON####KANGASKHANNIDORAN♂#... |
1511 |-----------------------+-----------------+-----------------+-----------------|
1512 | E9BD5- | The text PLAY TIME (see above, 70442) | | |
1513 | F1A44-F1A45 | Which Pok\eacute{}mon does Officer Jenny give you? | A level/internal-id pair. | (10 177), corresponding to a level 10 Squirtle. |
1514 | F21BF-F21C0 | Which Pok\eacute{}mon does the salesman at the Mt. Moon Pok\eacute{}mon center give you? | A level/internal-id pair | (5 133), corresponding to a level 5 Magikarp. |
1515 | | | | |
1516 #+TBLFM:
1518 ** COMMENT
1519 Locations where Give Pokemon is used in a nonstraightforward way
1520 0x5287C
1521 0x5CE23
1522 0x5C36B
1523 0x7562E
1525 Find GivePokemon
1526 (search-memory* (vec(rom)) [120 234 \_ \_ 121 234 \_ \_ 175 234 \_ \_ 6] 10)
1528 F4011 : ASM script for asking if it's oak battle
1531 ** Understanding memory banks and pointers
1532 #+begin_src clojure
1534 (defn endian-flip
1535 "Flip the bytes of the two-byte number."
1536 [n]
1537 (assert (< n 0xFFFF))
1538 (+ (* 0x100 (rem n 0x100))
1539 (int (/ n 0x100))))
1542 (defn offset->ptr
1543 "Convert an offset into a little-endian pointer."
1544 [n]
1545 (->
1547 (rem 0x10000) ;; take last four bytes
1548 (rem 0x4000) ;; get relative offset from the start of the bank
1549 (+ 0x4000)
1550 endian-flip))
1552 (defn offset->bank
1553 "Get the bank of the offset."
1554 [n]
1555 (int (/ n 0x4000)))
1557 (defn ptr->offset
1558 "Convert a two-byte little-endian pointer into an offset."
1559 [bank ptr]
1560 (->
1561 ptr
1562 endian-flip
1563 (- 0x4000)
1564 (+ (* 0x4000 bank))
1565 ))
1567 (defn same-bank-offset
1568 "Convert a ptr into an absolute offset by using the bank of the reference."
1569 [reference ptr]
1570 (ptr->offset
1571 (offset->bank reference)
1572 ptr))
1573 #+end_src
1576 ** Internal Pok\eacute{}mon IDs
1577 ** Type IDs
1579 #+name: type-ids
1580 #+begin_src clojure
1581 (def pkmn-types
1582 [:normal ;;0
1583 :fighting ;;1
1584 :flying ;;2
1585 :poison ;;3
1586 :ground ;;4
1587 :rock ;;5
1588 :bird ;;6
1589 :bug ;;7
1590 :ghost ;;8
1591 :A
1592 :B
1593 :C
1594 :D
1595 :E
1596 :F
1597 :G
1598 :H
1599 :I
1600 :J
1601 :K
1602 :fire ;;20 (0x14)
1603 :water ;;21 (0x15)
1604 :grass ;;22 (0x16)
1605 :electric ;;23 (0x17)
1606 :psychic ;;24 (0x18)
1607 :ice ;;25 (0x19)
1608 :dragon ;;26 (0x1A)
1609 ])
1610 #+end_src
1612 ** Basic effects of moves
1614 *** Table of basic effects
1616 The possible effects of moves in Pok\eacute{}mon \mdash{} for example, dealing
1617 damage, leeching health, or potentially poisoning the opponent
1618 \mdash{} are stored in a table. Each move has exactly one effect, and
1619 different moves might have the same effect.
1621 For example, Leech Life, Mega Drain, and Absorb all have effect ID #3, which is \ldquo{}Leech half of the inflicted damage.\rdquo{}
1623 All the legitimate move effects are listed in the table
1624 below. Here are some notes for reading it:
1626 - Whenever an effect has a chance of doing something (like a chance of
1627 poisoning the opponent), I list the chance as a hexadecimal amount
1628 out of 256; this is to avoid rounding errors. To convert the hex amount into a percentage, divide by 256.
1629 - For some effects, the description is too cumbersome to
1630 write. Instead, I just write a move name
1631 in parentheses, like: (leech seed). That move gives a characteristic example
1632 of the effect.
1633 - I use the abbreviations =atk=, =def=, =spd=, =spc=, =acr=, =evd= for
1634 attack, defense, speed, special, accuracy, and evasiveness.
1639 | ID (hex) | Description | Notes |
1640 |----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------|
1641 | 0 | normal damage | |
1642 | 1 | no damage, just sleep | TODO: find out how many turns |
1643 | 2 | 0x4C chance of poison | |
1644 | 3 | leech half of inflicted damage | |
1645 | 4 | 0x19 chance of burn | |
1646 | 5 | 0x19 chance of freeze | |
1647 | 6 | 0x19 chance of paralysis | |
1648 | 7 | user faints; opponent's defense is halved during attack. | |
1649 | 8 | leech half of inflicted damage ONLY if the opponent is asleep | |
1650 | 9 | imitate last attack | |
1651 | A | user atk +1 | |
1652 | B | user def +1 | |
1653 | C | user spd +1 | |
1654 | D | user spc +1 | |
1655 | E | user acr +1 | This effect is unused. |
1656 | F | user evd +1 | |
1657 | 10 | get post-battle money = 2 * level * uses | |
1658 | 11 | move has 0xFE acr, regardless of battle stat modifications. | |
1659 | 12 | opponent atk -1 | |
1660 | 13 | opponent def -1 | |
1661 | 14 | opponent spd -1 | |
1662 | 15 | opponent spc -1 | |
1663 | 16 | opponent acr -1 | |
1664 | 17 | opponent evd -1 | |
1665 | 18 | converts user's type to opponent's. | |
1666 | 19 | (haze) | |
1667 | 1A | (bide) | |
1668 | 1B | (thrash) | |
1669 | 1C | (teleport) | |
1670 | 1D | (fury swipes) | |
1671 | 1E | attacks 2-5 turns | Unused. TODO: find out what it does. |
1672 | 1F | 0x19 chance of flinching | |
1673 | 20 | opponent sleep for 1-7 turns | |
1674 | 21 | 0x66 chance of poison | |
1675 | 22 | 0x4D chance of burn | |
1676 | 23 | 0x4D chance of freeze | |
1677 | 24 | 0x4D chance of paralysis | |
1678 | 25 | 0x4D chance of flinching | |
1679 | 26 | one-hit KO | |
1680 | 27 | charge one turn, atk next. | |
1681 | 28 | fixed damage, leaves 1HP. | Is the fixed damage the power of the move? |
1682 | 29 | fixed damage. | Like seismic toss, dragon rage, psywave. |
1683 | 2A | atk 2-5 turns; opponent can't attack | The odds of attacking for /n/ turns are: (0 0x60 0x60 0x20 0x20) |
1684 | 2B | charge one turn, atk next. (can't be hit when charging) | |
1685 | 2C | atk hits twice. | |
1686 | 2D | user takes 1 damage if misses. | |
1687 | 2E | evade status-lowering effects | Caused by you or also your opponent? |
1688 | 2F | broken: if user is slower than opponent, makes critical hit impossible, otherwise has no effect | This is the effect of Focus Energy. It's (very) broken. |
1689 | 30 | atk causes recoil dmg = 1/4 dmg dealt | |
1690 | 31 | confuses opponent | |
1691 | 32 | user atk +2 | |
1692 | 33 | user def +2 | |
1693 | 34 | user spd +2 | |
1694 | 35 | user spc +2 | |
1695 | 36 | user acr +2 | This effect is unused. |
1696 | 37 | user evd +2 | This effect is unused. |
1697 | 38 | restores up to half of user's max hp. | |
1698 | 39 | (transform) | |
1699 | 3A | opponent atk -2 | |
1700 | 3B | opponent def -2 | |
1701 | 3C | opponent spd -2 | |
1702 | 3D | opponent spc -2 | |
1703 | 3E | opponent acr -2 | |
1704 | 3F | opponent evd -2 | |
1705 | 40 | doubles user spc when attacked | |
1706 | 41 | doubles user def when attacked | |
1707 | 42 | just poisons opponent | |
1708 | 43 | just paralyzes opponent | |
1709 | 44 | 0x19 chance opponent atk -1 | |
1710 | 45 | 0x19 chance opponent def -1 | |
1711 | 46 | 0x19 chance opponent spd -1 | |
1712 | 47 | 0x4C chance opponent spc -1 | |
1713 | 48 | 0x19 chance opponent acr -1 | |
1714 | 49 | 0x19 chance opponent evd -1 | |
1715 | 4A | ??? | ;; unused? no effect? |
1716 | 4B | ??? | ;; unused? no effect? |
1717 | 4C | 0x19 chance of confusing the opponent | |
1718 | 4D | atk hits twice. 0x33 chance opponent poisioned. | |
1719 | 4E | broken. crash the game after attack. | |
1720 | 4F | (substitute) | |
1721 | 50 | unless opponent faints, user must recharge after atk. some exceptions apply | |
1722 | 51 | (rage) | |
1723 | 52 | (mimic) | |
1724 | 53 | (metronome) | |
1725 | 54 | (leech seed) | |
1726 | 55 | does nothing (splash) | |
1727 | 56 | (disable) | |
1728 #+end_src
1730 *** Source
1731 #+name: move-effects
1732 #+begin_src clojure
1733 (def move-effects
1734 ["normal damage"
1735 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?
1736 "0x4C chance of poison"
1737 "leech half of inflicted damage"
1738 "0x19 chance of burn"
1739 "0x19 chance of freeze"
1740 "0x19 chance of paralyze"
1741 "user faints; opponent defense halved during attack."
1742 "leech half of inflicted damage ONLY if sleeping opponent."
1743 "imitate last attack"
1744 "user atk +1"
1745 "user def +1"
1746 "user spd +1"
1747 "user spc +1"
1748 "user acr +1" ;; unused?!
1749 "user evd +1"
1750 "get post-battle $ = 2*level*uses"
1751 "0xFE acr, no matter what."
1752 "opponent atk -1" ;; acr taken from move acr?
1753 "opponent def -1" ;;
1754 "opponent spd -1" ;;
1755 "opponent spc -1" ;;
1756 "opponent acr -1";;
1757 "opponent evd -1"
1758 "converts user's type to opponent's."
1759 "(haze)"
1760 "(bide)"
1761 "(thrash)"
1762 "(teleport)"
1763 "(fury swipes)"
1764 "attacks 2-5 turns" ;; unused? like rollout?
1765 "0x19 chance of flinch"
1766 "opponent sleep for 1-7 turns"
1767 "0x66 chance of poison"
1768 "0x4D chance of burn"
1769 "0x4D chance of freeze"
1770 "0x4D chance of paralyze"
1771 "0x4D chance of flinch"
1772 "one-hit KO"
1773 "charge one turn, atk next."
1774 "fixed damage, leaves 1HP." ;; how is dmg determined?
1775 "fixed damage." ;; cf seismic toss, dragon rage, psywave.
1776 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)
1777 "charge one turn, atk next. (can't be hit when charging)"
1778 "atk hits twice."
1779 "user takes 1 damage if misses."
1780 "evade status-lowering effects" ;;caused by you or also your opponent?
1781 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"
1782 "atk causes recoil dmg = 1/4 dmg dealt"
1783 "confuses opponent" ;; acr taken from move acr
1784 "user atk +2"
1785 "user def +2"
1786 "user spd +2"
1787 "user spc +2"
1788 "user acr +2" ;; unused!
1789 "user evd +2" ;; unused!
1790 "restores up to half of user's max hp." ;; broken: fails if the difference
1791 ;; b/w max and current hp is one less than a multiple of 256.
1792 "(transform)"
1793 "opponent atk -2"
1794 "opponent def -2"
1795 "opponent spd -2"
1796 "opponent spc -2"
1797 "opponent acr -2"
1798 "opponent evd -2"
1799 "doubles user spc when attacked"
1800 "doubles user def when attacked"
1801 "just poisons opponent" ;;acr taken from move acr
1802 "just paralyzes opponent" ;;
1803 "0x19 chance opponent atk -1"
1804 "0x19 chance opponent def -1"
1805 "0x19 chance opponent spd -1"
1806 "0x4C chance opponent spc -1" ;; context suggest chance is 0x19
1807 "0x19 chance opponent acr -1"
1808 "0x19 chance opponent evd -1"
1809 "???" ;; unused? no effect?
1810 "???" ;; unused? no effect?
1811 "0x19 chance opponent confused"
1812 "atk hits twice. 0x33 chance opponent poisioned."
1813 "broken. crash the game after attack."
1814 "(substitute)"
1815 "unless opponent faints, user must recharge after atk. some
1816 exceptions apply."
1817 "(rage)"
1818 "(mimic)"
1819 "(metronome)"
1820 "(leech seed)"
1821 "does nothing (splash)"
1822 "(disable)"
1823 ])
1824 #+end_src
1827 ** Alphabet code
1829 * Source
1831 #+begin_src clojure :tangle ../clojure/com/aurellem/gb/hxc.clj
1833 (ns com.aurellem.gb.hxc
1834 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1835 constants species))
1836 (:import [com.aurellem.gb.gb_driver SaveState]))
1838 ; ************* HANDWRITTEN CONSTANTS
1840 <<type-ids>>
1843 ;; question: when status effects claim to take
1844 ;; their accuracy from the move accuracy, does
1845 ;; this mean that the move always "hits" but the
1846 ;; status effect may not?
1848 <<move-effects>>
1850 ;; ************** HARDCODED DATA
1852 <<hxc-thunks>>
1853 ;; --------------------------------------------------
1855 <<pokenames>>
1856 <<type-names>>
1858 ;; http://hax.iimarck.us/topic/581/
1859 <<pokecry>>
1862 <<item-names>>
1866 (def hxc-titles
1867 "The hardcoded names of the trainer titles in memory. List begins at
1868 ROM@27E77"
1869 (hxc-thunk-words 0x27E77 196))
1872 <<dex-text>>
1874 ;; In red/blue, pokedex stats are in internal order.
1875 ;; In yellow, pokedex stats are in pokedex order.
1876 <<dex-stats>>
1881 <<places>>
1883 (defn hxc-dialog
1884 "The hardcoded dialogue in memory, including in-game alerts. Dialog
1885 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."
1886 ([rom]
1887 (map character-codes->str
1888 (take-nth 2
1889 (partition-by #(= % 0x57)
1890 (take 0x0F728
1891 (drop 0x98000 rom))))))
1892 ([]
1893 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
1896 <<move-names>>
1897 <<move-data>>
1899 <<machines>>
1903 (defn internal-id
1904 ([rom]
1905 (zipmap
1906 (hxc-pokenames rom)
1907 (range)))
1908 ([]
1909 (internal-id com.aurellem.gb.gb-driver/original-rom)))
1915 ;; nidoran gender change upon levelup
1916 ;; (->
1917 ;; @current-state
1918 ;; rom
1919 ;; vec
1920 ;; (rewrite-memory
1921 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))
1922 ;; [1 1 15])
1923 ;; (rewrite-memory
1924 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))
1925 ;; [1 1 3])
1926 ;; (write-rom!)
1928 ;; )
1932 <<type-advantage>>
1936 <<evolution-header>>
1937 <<evolution>>
1938 <<learnsets>>
1939 <<pokebase>>
1942 (defn hxc-intro-pkmn
1943 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's
1944 internal id is stored at ROM@5EDB."
1945 ([] (hxc-intro-pkmn
1946 com.aurellem.gb.gb-driver/original-rom))
1947 ([rom]
1948 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))
1950 (defn sxc-intro-pkmn!
1951 "Set the hardcoded pokemon to display in Prof. Oak's introduction."
1952 [pokemon]
1953 (write-rom!
1954 (rewrite-rom 0x5EDB
1956 (inc
1957 ((zipmap
1958 (hxc-pokenames)
1959 (range))
1960 pokemon))])))
1963 <<item-prices>>
1965 <<item-vendors>>
1967 <<wilds>>
1970 ;; ********************** MANIPULATION FNS
1973 (defn same-type
1974 ([pkmn move]
1975 (same-type
1976 com.aurellem.gb.gb-driver/original-rom pkmn move))
1977 ([rom pkmn move]
1978 (((comp :types (hxc-pokemon-base rom)) pkmn)
1979 ((comp :type (hxc-move-data rom)) move))))
1984 (defn submap?
1985 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."
1986 [map-small map-big]
1987 (cond (empty? map-small) true
1988 (and
1989 (contains? map-big (ffirst map-small))
1990 (= (get map-big (ffirst map-small))
1991 (second (first map-small))))
1992 (recur (next map-small) map-big)
1994 :else false))
1997 (defn search-map [proto-map maps]
1998 "Returns all the maps that make the same associations as proto-map."
1999 (some (partial submap? proto-map) maps))
2001 (defn filter-vals
2002 "Returns a map consisting of all the pairs [key val] for
2003 which (pred key) returns true."
2004 [pred map]
2005 (reduce (partial apply assoc) {}
2006 (filter (fn [[k v]] (pred v)) map)))
2009 (defn search-moves
2010 "Returns a subcollection of all hardcoded moves with the
2011 given attributes. Attributes consist of :name :power
2012 :accuracy :pp :fx-id
2013 (and also :fx-txt, but it contains the same information
2014 as :fx-id)"
2015 ([attribute-map]
2016 (search-moves
2017 com.aurellem.gb.gb-driver/original-rom attribute-map))
2018 ([rom attribute-map]
2019 (filter-vals (partial submap? attribute-map)
2020 (hxc-move-data rom))))
2026 ;; note: 0x2f31 contains the names "TM" "HM"?
2028 ;; note for later: credits start at F1290
2030 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??
2032 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)
2034 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.
2035 ;; The first instance is for Machines; the second, for stones.
2037 ;; note: according to
2038 ;; http://www.upokecenter.com/games/rby/guides/rgbtrainers.php
2039 ;; the amount of money given by a trainer is equal to the
2040 ;; base money times the level of the last Pokemon on that trainer's
2041 ;; list. Other sources say it's the the level of the last pokemon
2042 ;; /defeated/.
2044 ;; todo: find base money.
2047 ;; note: 0xDFEA (in indexable mem) is the dex# of the currently-viewed Pokemon in
2048 ;; in the pokedex. It's used for other purposes if there is none.
2050 ;; note: 0x9D35 (index.) switches from 0xFF to 0x00 temporarily when
2051 ;; you walk between areas.
2053 ;; note: 0xD059 (index.) is the special battle type of your next battle:
2054 ;; - 00 is a usual battle
2055 ;; - 01 is a pre-scripted OLD MAN battle which always fails to catch the
2056 ;; target Pokemon.
2057 ;; - 02 is a safari zone battle
2058 ;; - 03 obligates you to run away. (unused)
2059 ;; - 04 is a pre-scripted OAK battle, which (temporarily) causes the
2060 ;; enemy Pokemon to cry PIKAAA, and which always catches the target
2061 ;; Pokemon. The target Pokemon is erased after the battle.
2062 ;; - 05+ are glitch states in which you are sort of the Pokemon.
2065 ;; note: 0x251A (in indexable mem): image decompression routine seems to begin here.
2067 ;; note: 0x4845 (index): vending inventory is loaded here. possibly
2068 ;; other things, too.
2069 (comment
2070 ;; temporarily intercept/adjust what pops out of the vending
2071 ;; machine.
2072 ;; (and how much it costs)
2074 ;; located at 0x4845
2075 ;; not to be confused with shop inventory, 0xCF7B
2076 (do
2077 (step (read-state "vend-menu"))
2078 (write-memory! (rewrite-memory (vec(memory)) 0x4845 [2 0 1 0]))
2079 (step @current-state [:a])
2080 (step @current-state [])
2081 (nstep @current-state 200) ))
2084 ;; Note: There are two tile tables, one from 8000-8FFF, the other from
2085 ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end.
2086 (defn print-pixel-letters!
2087 "The pixel tiles representing letters. Neat!"
2088 ([] (print-pixel-letters! (read-state "oak-speaks")))
2089 ([state]
2090 (map
2091 (comp
2092 println
2093 (partial map #(if (zero? %) \space 0))
2094 #(if (< (count %) 8)
2095 (recur (cons 0 %))
2096 %)
2097 reverse bit-list)
2099 (take 0xFFF (drop 0x8800 (memory state))))))
2102 ;; (defn test-2 []
2103 ;; (loop [n 0
2104 ;; pc-1 (pc-trail (-> state-defend (tick) (step [:a]) (step [:a]) (step []) (nstep 100)) 100000)
2105 ;; pc-2 (pc-trail (-> state-speed (tick) (step [:a]) (step [:a])
2106 ;; (step []) (nstep 100)) 100000)]
2107 ;; (cond (empty? (drop n pc-1)) [pc-1 n]
2108 ;; (not= (take 10 (drop n pc-1)) (take 10 pc-2))
2109 ;; (recur pc-1 pc-2 (inc n))
2110 ;; :else
2111 ;; [(take 1000 pc-2) n])))
2116 (defn test-3
2117 "Explore trainer data"
2118 ([] (test-3 0x3A289))
2119 ([start]
2120 (let [pokenames (vec(hxc-pokenames-raw))]
2121 (println
2122 (reduce
2123 str
2124 (map
2125 (fn [[adr lvl pkmn]]
2126 (str (format "%-11s %4d %02X %02X \t %05X\n"
2128 (cond
2129 (zero? lvl) "+"
2130 (nil? (get pokenames (dec pkmn)))
2131 "-"
2132 :else
2133 (get pokenames (dec pkmn)))
2134 lvl
2135 pkmn
2136 lvl
2137 adr
2138 )))
2139 (map cons
2140 (take-nth 2 (drop start (range)))
2141 (partition 2
2142 (take 400;;703
2143 (drop
2144 start
2145 ;; 0x3A75D
2146 (rom)))))))))))
2148 (defn search-memory* [mem codes k]
2149 (loop [index 0
2150 index-next 1
2151 start-match 0
2152 to-match codes
2153 matches []]
2154 (cond
2155 (>= index (count mem)) matches
2157 (empty? to-match)
2158 (recur
2159 index-next
2160 (inc index-next)
2161 index-next
2162 codes
2163 (conj matches
2164 [(hex start-match) (take k (drop start-match mem))])
2167 (or (= (first to-match) \_) ;; wildcard
2168 (= (first to-match) (nth mem index)))
2169 (recur
2170 (inc index)
2171 index-next
2172 start-match
2173 (rest to-match)
2174 matches)
2176 :else
2177 (recur
2178 index-next
2179 (inc index-next)
2180 index-next
2181 codes
2182 matches))))
2185 (def script-use-ball
2186 [0xFA ;; ld A, nn
2187 \_
2188 \_
2189 0xA7 ;; and A
2190 0xCA ;; JP Z
2191 \_
2192 \_
2193 0x3D ;; dec A
2194 0xC2 ;; JP NZ
2195 \_
2196 \_
2197 0xFA ;; LD A
2198 \_
2199 \_
2200 ])
2204 (defn search-pattern [ptn coll]
2205 (loop
2206 [index 0
2207 to-match ptn
2208 binds {}
2210 next-index 1
2211 match-start 0
2212 matches []]
2214 (cond
2215 (>= index (count coll)) matches
2216 (empty? to-match)
2217 (recur
2218 next-index
2219 ptn
2220 {}
2221 (inc next-index)
2222 next-index
2223 (conj match-start
2224 [(hex match-start) binds]))
2226 :else
2227 (let [k (first to-match)
2228 v (nth coll index)]
2229 (cond
2230 (= k \_) ;; wildcard
2231 (recur
2232 (inc index)
2233 (rest to-match)
2234 binds
2236 next-index
2237 match-start
2238 matches)
2240 (keyword? k)
2241 (if (binds k)
2242 (if (= (binds k) v)
2243 (recur
2244 (inc index)
2245 (rest to-match)
2246 binds
2247 next-index
2248 match-start
2249 matches)
2251 (recur
2252 next-index
2253 ptn
2254 {}
2255 (inc next-index)
2256 next-index
2257 matches))
2259 ;; ;; consistent bindings
2260 ;; (recur
2261 ;; (inc index)
2262 ;; (rest to-match)
2263 ;; binds
2265 ;; next-index
2266 ;; match-start
2267 ;; matches)
2269 ;; ;; inconsistent bindings
2270 ;; (recur
2271 ;; next-index
2272 ;; ptn
2273 ;; {}
2274 ;; (inc next-index)
2275 ;; next-index
2276 ;; matches))
2278 (if ((set (vals binds)) v)
2279 ;; bindings are not unique
2280 (recur
2281 next-index
2282 ptn
2283 {}
2284 (inc next-index)
2285 next-index
2286 matches)
2288 ;; bindings are unique
2289 (recur
2290 (inc index)
2291 (rest to-match)
2292 (assoc binds k v)
2294 next-index
2295 match-start
2296 matches)))
2298 :else ;; k is just a number
2299 (if (= k v)
2300 (recur
2301 (inc index)
2302 (rest to-match)
2303 binds
2305 next-index
2306 match-start
2307 matches)
2309 (recur
2310 next-index
2311 ptn
2312 {}
2313 (inc next-index)
2314 next-index
2315 matches)))))))
2325 (defn search-pattern* [ptn coll]
2326 (loop
2328 binds {}
2329 index 0
2330 index-next 1
2331 start-match 0
2332 to-match ptn
2333 matches []]
2335 (cond
2336 (>= index (count coll)) matches
2337 (empty? to-match)
2338 (recur
2339 {}
2340 index-next
2341 (inc index-next)
2342 index-next
2343 ptn
2344 (conj matches
2345 [(hex start-match) binds]))
2347 :else
2348 (let [k (first to-match)
2349 v (nth coll index)]
2350 (cond
2351 (= k \_) ;; wildcard
2352 (recur
2353 binds
2354 (inc index)
2355 index-next
2356 start-match
2357 (rest to-match)
2358 matches)
2360 (keyword? k)
2361 (if (binds k)
2362 (if (= (binds k) v)
2363 (recur
2364 binds
2365 (inc index)
2366 index-next
2367 start-match
2368 (rest to-match)
2369 matches)
2370 (recur
2371 {}
2372 index-next
2373 (inc index-next)
2374 index-next
2375 ptn
2376 matches))
2377 (if
2378 ;; every symbol must be bound to a different thing.
2379 ((set (vals binds)) v)
2380 (recur
2381 {}
2382 index-next
2383 (inc index-next)
2384 index-next
2385 ptn
2386 matches)
2387 (recur
2388 (assoc binds k v)
2389 (inc index)
2390 index-next
2391 start-match
2392 (rest to-match)
2393 matches)))
2395 :else
2396 (if (= k v)
2397 (recur
2398 binds
2399 (inc index)
2400 index-next
2401 start-match
2402 (rest to-match)
2403 matches)
2404 (recur
2405 {}
2406 index-next
2407 (inc index-next)
2408 index-next
2409 ptn
2410 matches))
2414 )))))
2419 ;; look for the rainbow badge in memory
2420 (println (reduce str (map #(str (first %) "\t" (vec(second %)) "\n") (search-memory (rom) [221] 10))))
2423 (comment
2425 (def hxc-later
2426 "Running this code produces, e.g. hardcoded names NPCs give
2427 their pokemon. Will sort through it later."
2428 (print (character-codes->str(take 10000
2429 (drop 0x71597
2430 (rom (root)))))))
2432 (let [dex
2433 (partition-by #(= 0x50 %)
2434 (take 2540
2435 (drop 0x40687
2436 (rom (root)))))]
2437 (def dex dex)
2438 (def hxc-species
2439 (map character-codes->str
2440 (take-nth 4 dex))))
2444 #+end_src
2446 #+results:
2447 : nil