view org/rom.org @ 471:5f87c3e46c22

Added interactive Pokemon cries.
author Dylan Holmes <ocsenave@gmail.com>
date Sun, 29 Apr 2012 20:35:58 -0500
parents c02108ddcb35
children 69d1787522c7
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
206 rating-xp
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
213 move-2
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 0x3E62D (rom))))
934 (println (partition 3 (take 15 (drop 0x3E62D (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 0x3E62D (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 0x3E62D (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 : (0 5 5 0 8 0 8 8 20 20 7 20 20 5 5)
964 : ((0 5 5) (0 8 0) (8 8 20) (20 7 20) (20 5 5))
965 : ((0 5 0.5) (0 8 0.0) (8 8 2.0) (20 7 2.0) (20 5 0.5))
966 : ([:normal :rock 0.5] [:normal :ghost 0.0] [:ghost :ghost 2.0] [:fire :bug 2.0] [:fire :rock 0.5])
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 0x3E62D rom))))))
989 #+end_src
993 * Moves
994 ** Names of moves
995 *** See the data
996 #+begin_src clojure :exports both :results output
997 (ns com.aurellem.gb.hxc
998 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
999 constants))
1000 (:import [com.aurellem.gb.gb_driver SaveState]))
1002 (println (take 100 (drop 0xBC000 (rom))))
1004 (println
1005 (partition-by
1006 (partial = 0x50)
1007 (take 100 (drop 0xBC000 (rom)))))
1009 (println
1010 (map character-codes->str
1011 (partition-by
1012 (partial = 0x50)
1013 (take 100 (drop 0xBC000 (rom))))))
1016 #+end_src
1018 #+results:
1019 : (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)
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 : (POUND # KARATE CHOP # DOUBLESLAP # COMET PUNCH # MEGA PUNCH # PAY DAY # FIRE PUNCH # ICE PUNCH # THUNDERPUNCH # SCRATC)
1023 *** Automatically grab the data
1025 #+name: move-names
1026 #+begin_src clojure
1027 (def hxc-move-names
1028 "The hardcoded move names in memory. List begins at ROM@BC000"
1029 (hxc-thunk-words 0xBC000 1551))
1030 #+end_src
1032 ** Properties of moves
1034 #+name: move-data
1035 #+begin_src clojure
1036 (defn hxc-move-data
1037 "The hardcoded (basic (move effects)) in memory. List begins at
1038 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id
1039 :fx-txt}. The move descriptions are handwritten, not hardcoded."
1040 ([]
1041 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))
1042 ([rom]
1043 (let [names (vec (hxc-move-names rom))
1044 move-count (count names)
1045 move-size 6
1046 types pkmn-types ;;; !! hardcoded types
1048 (zipmap (map format-name names)
1049 (map
1050 (fn [[idx effect power type-id accuracy pp]]
1051 {:name (names (dec idx))
1052 :power power
1053 :accuracy accuracy
1054 :pp pp
1055 :type (types type-id)
1056 :fx-id effect
1057 :fx-txt (get move-effects effect)
1061 (partition move-size
1062 (take (* move-size move-count)
1063 (drop 0x38000 rom))))))))
1067 (defn hxc-move-data*
1068 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."
1069 ([]
1070 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))
1071 ([rom]
1072 (let [names (vec (hxc-move-names rom))
1073 move-count (count names)
1074 move-size 6
1075 format-name (fn [s]
1076 (keyword (.toLowerCase
1077 (apply str
1078 (map #(if (= % \space) "-" %) s)))))
1080 (zipmap (map format-name names)
1081 (map
1082 (fn [[idx effect power type accuracy pp]]
1083 {:name (names (dec idx))
1084 :power power
1085 :accuracy (hex accuracy)
1086 :pp pp
1087 :fx-id (hex effect)
1088 :fx-txt (get move-effects effect)
1092 (partition move-size
1093 (take (* move-size move-count)
1094 (drop 0x38000 rom))))))))
1096 #+end_src
1098 ** TM and HM moves
1099 ***
1100 #+begin_src clojure :exports both :results output
1101 (ns com.aurellem.gb.hxc
1102 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1103 constants))
1104 (:import [com.aurellem.gb.gb_driver SaveState]))
1107 (println (hxc-move-names))
1108 (println (map vector (rest(range)) (hxc-move-names)))
1110 (newline)
1112 (println (take 55 (drop 0x1232D (rom))))
1114 (println
1115 (interpose "."
1116 (map
1117 (zipmap (rest (range)) (hxc-move-names))
1118 (take 55 (drop 0x1232D (rom))))))
1120 #+end_src
1122 #+results:
1123 : (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)
1124 : ([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])
1126 : (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)
1127 : (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)
1130 ***
1131 #+name: machines
1132 #+begin_src clojure
1133 (defn hxc-machines
1134 "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."
1135 ([] (hxc-machines
1136 com.aurellem.gb.gb-driver/original-rom))
1137 ([rom]
1138 (let [moves (hxc-move-names rom)]
1139 (zipmap
1140 (range)
1141 (take-while
1142 (comp not nil?)
1143 (map (comp
1144 format-name
1145 (zipmap
1146 (range)
1147 moves)
1148 dec)
1149 (take 100
1150 (drop 0x1232D rom))))))))
1152 #+end_src
1158 ** COMMENT Status ailments
1161 * NPC Trainers
1163 ** Trainer Pok\eacute{}mon
1164 # http://hax.iimarck.us/topic/103/
1165 There are two formats for specifying lists of NPC PPok\eacute{}mon:
1166 - If all the Pok\eacute{}mon will have the same level, the format is
1167 - Level (used for all the Pok\eacute{}mon)
1168 - Any number of Pok\eacute{}mon internal ids.
1169 - 0x00, to indicate end-of-list.
1170 - Otherwise, all the Pok\eacute{}mon will have their level
1171 specified. The format is
1172 - 0xFF, to indicate that we will be specifying the levels individually[fn::Because 0xFF is a
1173 forbidden level within the usual gameplay discipline, the game
1174 makers could safely use 0xFF as a mode indicator.].
1175 - Any number of alternating Level/Pokemon pairs
1176 - 0x00, to indicate end-of-list.
1178 *** Get the pointers
1179 *** See the data
1180 #+begin_src clojure :exports both :results output
1181 (ns com.aurellem.gb.hxc
1182 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1183 constants))
1184 (:import [com.aurellem.gb.gb_driver SaveState]))
1186 (->>
1187 (rom)
1188 (drop 0x39E2F)
1189 (take 21)
1190 (println))
1193 (->>
1194 (rom)
1195 (drop 0x39E2F)
1196 (take 21)
1197 (partition-by zero?)
1198 (take-nth 2)
1199 (println))
1203 (let
1204 [pokenames
1205 (zipmap
1206 (rest (range))
1207 (hxc-pokenames-raw))]
1209 (->>
1210 (rom)
1211 (drop 0x39E2F)
1212 (take 21) ;; (1922 in all)
1213 (partition-by zero?)
1214 (take-nth 2)
1215 (map
1216 (fn parse-team [[mode & team]]
1217 (if (not= 0xFF mode)
1218 (mapv
1219 #(hash-map :level mode :species (pokenames %))
1220 team)
1222 (mapv
1223 (fn [[lvl id]] (hash-map :level lvl :species (pokenames id)))
1224 (partition 2 team)))))
1226 (println)))
1230 #+end_src
1232 #+results:
1233 : (11 165 108 0 14 5 0 10 165 165 107 0 14 165 108 107 0 15 165 5 0)
1234 : ((11 165 108) (14 5) (10 165 165 107) (14 165 108 107) (15 165 5))
1235 : ([{: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}])
1237 * Places
1238 ** Names of places
1240 #+name: places
1241 #+begin_src clojure
1242 (def hxc-places
1243 "The hardcoded place names in memory. List begins at
1244 ROM@71500. [Cinnabar/Celadon] Mansion seems to be dynamically calculated."
1245 (hxc-thunk-words 0x71500 560))
1246 #+end_src
1248 *** See it work
1249 #+begin_src clojure :exports both :results output
1250 (println (hxc-places))
1251 #+end_src
1253 #+results:
1254 : (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)
1256 ** Wild Pok\eacute{}mon demographics
1257 #+name: wilds
1258 #+begin_src clojure
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@0x04D89"
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@0x04D89"
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 (fn [[a b]] {:species (pokenames (dec b)) :level
1283 a}))
1284 (partition 10
1286 (take-while (comp (partial not= 1)
1287 first)
1288 (partition 2
1289 (drop 0xCD8C rom))
1291 ))))))
1293 #+end_src
1298 ** Map data
1300 # http://www.pokecommunity.com/showthread.php?t=235311
1301 # http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes
1303 #+name map
1304 #+begin_src clojure :exports both :results output
1305 (ns com.aurellem.gb.hxc
1306 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1307 constants))
1308 (:import [com.aurellem.gb.gb_driver SaveState]))
1311 (defn parse-header-tileset
1312 [[bank# ;; memory bank for blocks & tileset
1314 blocks-lo ;; structure
1315 blocks-hi
1317 tileset-lo ;; style
1318 tileset-hi
1320 collision-lo ;; collision info
1321 collision-hi
1323 talk-here-1 ;; positions of up to three
1324 talk-here-2 ;; talk-over-countertop tiles
1325 talk-here-3 ;; --- 0xFF if unused.
1327 grass ;; grass tile --- 0xFF if unused
1329 animation-flags ;; settings for animation
1330 & _]]
1332 [bank#
1334 blocks-lo ;; structure
1335 blocks-hi
1337 tileset-lo ;; style
1338 tileset-hi
1340 collision-lo ;; collision info
1341 collision-hi
1343 talk-here-1 ;; positions of up to three
1344 talk-here-2 ;; talk-over-countertop tiles
1345 talk-here-3 ;; --- 0xFF if unused.
1347 grass ;; grass tile --- 0xFF if unused
1349 animation-flags ;; settings for animation
1350 ])
1354 (defn parse-header-map
1355 [start]
1357 (let [connection-size 11
1359 [tileset-index
1360 map-height
1361 map-width
1362 layout-lo
1363 layout-hi
1364 text-lo
1365 text-hi
1366 script-lo
1367 script-hi
1368 adjacency-flags ;; x x x x N S W E
1369 & etc]
1370 (drop start (rom))
1372 [east? west? south? north?]
1373 (bit-list adjacency-flags)
1375 [connections object-data]
1376 (split-at
1377 (* connection-size (+ east? west? south? north?))
1378 etc)
1380 connections
1381 (partition connection-size connections)
1387 (ptr->offset
1389 (low-high layout-lo layout-hi))
1392 ))
1393 #+end_src
1395 #+results:
1400 * Appendices
1401 ** Mapping the ROM
1402 # D3AD: Script:Use Pokeball?
1404 | ROM address (hex) | Description | Format | Example |
1405 |-----------------------+-----------------+-----------------+-----------------|
1406 | | <15> | <15> | <15> |
1407 | 01823-0184A | Important prefix strings. | Variable-length strings, separated by 0x50. | TM#TRAINER#PC#ROCKET#POK\eacute{}#... |
1408 | 0233C- | Shop inventories. | | |
1409 | 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. |
1410 | 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. | |
1411 | 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. | |
1412 | 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. |
1413 | 04524-04527 | (unconfirmed) possibly the bike price in Cerulean. | | |
1414 | 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#... |
1415 | 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). |
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, the location of the first list of wild Pok\eacute{}mon (see 04D89, above). |
1428 |-----------------------+-----------------+-----------------+-----------------|
1429 | 0DACB. | Amount of HP restored by Soda Pop | The HP consists of a single numerical byte. | 60 |
1430 | 0DACF. | Amount of HP restored by Lemonade | " | 80 |
1431 | 0DAD5. | Amount of HP restored by Fresh Water | " | 50 |
1432 | 0DADB. | Amount of HP restored by Hyper Potion. | " | 200 |
1433 | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 |
1434 | 0DAE3. | Amount of HP restored by Potion. | " | 20 |
1435 |-----------------------+-----------------+-----------------+-----------------|
1436 | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# |
1437 |-----------------------+-----------------+-----------------+-----------------|
1438 | 0DE2F. | Duration of Repel. | A single byte, representing the number of steps you can take before the effect wears off. | 100 |
1439 | 0DF39. | Duration of Super Repel. | " | 200 |
1440 | 0DF3E. | Duration of Max Repel. | " | 250 |
1441 |-----------------------+-----------------+-----------------+-----------------|
1442 | 1164B- | Terminology for the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | TYPE1[newline]TYPE2[newline] *№*,[newline]OT,[newline][0x50]STATUS,[0x50]OK |
1443 | 116DE- | Terminology for permanent stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | ATTACK[newline]DEFENSE[newline]SPEED[newline]SPECIAL[0x50] |
1444 | 11852- | Terminology for current stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | EXP POINTS[newline]LEVEL UP[0x50] |
1445 | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1446 | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1447 |-----------------------+-----------------+-----------------+-----------------|
1448 | 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]. |
1449 | 11D67. | Which badge is a prerequisite for SURF? | " | 0x67 (test for Soul Badge) |
1450 | 11DAC. | Which badge is a prerequisite for STRENGTH? | " | 0x5F (test for Rainbow Badge) |
1451 |-----------------------+-----------------+-----------------+-----------------|
1452 | 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), ... |
1453 |-----------------------+-----------------+-----------------+-----------------|
1454 | 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. |
1455 | 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. |
1456 |-----------------------+-----------------+-----------------+-----------------|
1457 | 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. |
1458 | 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"). |
1459 | 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#... |
1460 | 27DFF-27E77 | ? | 120 bytes of unknown data. | |
1461 | 27E77- | Trainer title names. | Variable-length names separated by 0x50. | YOUNGSTER#BUG CATCHER#LASS#... |
1462 | 34000- | | | |
1463 | 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. |
1464 | 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. | | |
1465 | 39462- | The Pok\eacute{}mon cry data. | Fixed-length (3 byte) descriptions of cries. | |
1466 |-----------------------+-----------------+-----------------+-----------------|
1467 | 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*.] | | |
1468 | 39B05-39DD0. | unknown | | |
1469 | 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. |
1470 | 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.].) |
1471 | 3B1E5-3B361 | Pointers to evolution/learnset data. | One high-low byte pair for each of the 190 Pok\eacute{}mon in internal order. | |
1472 |-----------------------+-----------------+-----------------+-----------------|
1473 | 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. | |
1474 | 3BBAA-3C000 | (empty) | | 0 0 0 0 ... |
1475 |-----------------------+-----------------+-----------------+-----------------|
1476 | 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.]. |
1477 | 3D6C7-3D6D6 | Two miscellaneous strings. | Variable length, separated by 0x50 | Disabled!#TYPE |
1478 | 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. |
1479 | 3E200-3E204 | " (???) | " | " |
1480 | 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. |
1481 |-----------------------+-----------------+-----------------+-----------------|
1482 | 40252-4027B | Pok\eacute{}dex menu text | Variable-length strings separated by 0x50. | SEEN#OWN#CONTENTS#... |
1483 | 40370-40386 | Important constants for Pok\eacute{}dex entries | | HT _ _ *?′??″* [newline] WT _ _ _ *???* lb [0x50] *POK\Eacute{}* [0x50] |
1484 | 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). |
1485 | 41072- | Pok\eacute{} placeholder species, "???" | | |
1486 |-----------------------+-----------------+-----------------+-----------------|
1487 | 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. |
1488 |-----------------------+-----------------+-----------------+-----------------|
1489 | 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) |
1490 |-----------------------+-----------------+-----------------+-----------------|
1491 | 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. |
1492 | 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. |
1493 |-----------------------+-----------------+-----------------+-----------------|
1494 | 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 |
1495 | 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]... |
1496 |-----------------------+-----------------+-----------------+-----------------|
1497 | 70295- | Hall of fame | The text "HALL OF FAME" | |
1498 | 70442- | Play time/money | The text "PLAY TIME [0x50] MONEY" | |
1499 | 71500-7174B | Names of places. | Variable-length place names (strings), separated by 0x50. | PALLET TOWN#VIRIDIAN CITY#PEWTER CITY#CERULEAN CITY#... |
1500 | 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". |
1501 | 7C249-7C2?? | Pointers to background music, pt II. | | |
1502 |-----------------------+-----------------+-----------------+-----------------|
1503 | 98000-B7190 | Dialogue and other messsages. | Variable-length strings. | |
1504 | B7190-B8000 | (empty space) | | 0 0 0 0 0 ... |
1505 | 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]." |
1506 | BC000-BC60F | Move names. | Variable-length move names, separated by 0x50. The moves are in internal order. | POUND#KARATE CHOP#DOUBLESLAP#COMET PUNCH#... |
1507 | BC610-BD000 | (empty space) | | 0 0 0 0 0 ... |
1508 | 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♂#... |
1509 |-----------------------+-----------------+-----------------+-----------------|
1510 | E9BD5- | The text PLAY TIME (see above, 70442) | | |
1511 | F1A44-F1A45 | Which Pok\eacute{}mon does Officer Jenny give you? | A level/internal-id pair. | (10 177), corresponding to a level 10 Squirtle. |
1512 | 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. |
1513 | | |
1514 #+TBLFM:
1516 ** COMMENT
1517 Locations where Give Pokemon is used in a nonstraightforward way
1518 0x5287C
1519 0x5CE23
1520 0x5C36B
1521 0x7562E
1523 Find GivePokemon
1524 (search-memory* (vec(rom)) [120 234 \_ \_ 121 234 \_ \_ 175 234 \_ \_ 6] 10)
1526 F4011 : ASM script for asking if it's oak battle
1529 ** Understanding memory banks and pointers
1530 #+begin_src clojure
1532 (defn endian-flip
1533 "Flip the bytes of the two-byte number."
1534 [n]
1535 (assert (< n 0xFFFF))
1536 (+ (* 0x100 (rem n 0x100))
1537 (int (/ n 0x100))))
1540 (defn offset->ptr
1541 "Convert an offset into a little-endian pointer."
1542 [n]
1543 (->
1545 (rem 0x10000) ;; take last four bytes
1546 (rem 0x4000) ;; get relative offset from the start of the bank
1547 (+ 0x4000)
1548 endian-flip))
1550 (defn offset->bank
1551 "Get the bank of the offset."
1552 [n]
1553 (int (/ n 0x4000)))
1555 (defn ptr->offset
1556 "Convert a two-byte little-endian pointer into an offset."
1557 [bank ptr]
1558 (->
1559 ptr
1560 endian-flip
1561 (- 0x4000)
1562 (+ (* 0x4000 bank))
1563 ))
1565 (defn same-bank-offset
1566 "Convert a ptr into an absolute offset by using the bank of the reference."
1567 [reference ptr]
1568 (ptr->offset
1569 (offset->bank reference)
1570 ptr))
1571 #+end_src
1574 ** Internal Pok\eacute{}mon IDs
1575 ** Type IDs
1577 #+name: type-ids
1578 #+begin_src clojure
1579 (def pkmn-types
1580 [:normal ;;0
1581 :fighting ;;1
1582 :flying ;;2
1583 :poison ;;3
1584 :ground ;;4
1585 :rock ;;5
1586 :bird ;;6
1587 :bug ;;7
1588 :ghost ;;8
1589 :A
1590 :B
1591 :C
1592 :D
1593 :E
1594 :F
1595 :G
1596 :H
1597 :I
1598 :J
1599 :K
1600 :fire ;;20 (0x14)
1601 :water ;;21 (0x15)
1602 :grass ;;22 (0x16)
1603 :electric ;;23 (0x17)
1604 :psychic ;;24 (0x18)
1605 :ice ;;25 (0x19)
1606 :dragon ;;26 (0x1A)
1607 ])
1608 #+end_src
1610 ** Basic effects of moves
1612 *** Table of basic effects
1614 The possible effects of moves in Pok\eacute{}mon \mdash{} for example, dealing
1615 damage, leeching health, or potentially poisoning the opponent
1616 \mdash{} are stored in a table. Each move has exactly one effect, and
1617 different moves might have the same effect.
1619 For example, Leech Life, Mega Drain, and Absorb all have effect ID #3, which is \ldquo{}Leech half of the inflicted damage.\rdquo{}
1621 All the legitimate move effects are listed in the table
1622 below. Here are some notes for reading it:
1624 - Whenever an effect has a chance of doing something (like a chance of
1625 poisoning the opponent), I list the chance as a hexadecimal amount
1626 out of 256; this is to avoid rounding errors. To convert the hex amount into a percentage, divide by 256.
1627 - For some effects, the description is too cumbersome to
1628 write. Instead, I just write a move name
1629 in parentheses, like: (leech seed). That move gives a characteristic example
1630 of the effect.
1631 - I use the abbreviations =atk=, =def=, =spd=, =spc=, =acr=, =evd= for
1632 attack, defense, speed, special, accuracy, and evasiveness.
1637 | ID (hex) | Description | Notes |
1638 |----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------|
1639 | 0 | normal damage | |
1640 | 1 | no damage, just sleep | TODO: find out how many turns |
1641 | 2 | 0x4C chance of poison | |
1642 | 3 | leech half of inflicted damage | |
1643 | 4 | 0x19 chance of burn | |
1644 | 5 | 0x19 chance of freeze | |
1645 | 6 | 0x19 chance of paralysis | |
1646 | 7 | user faints; opponent's defense is halved during attack. | |
1647 | 8 | leech half of inflicted damage ONLY if the opponent is asleep | |
1648 | 9 | imitate last attack | |
1649 | A | user atk +1 | |
1650 | B | user def +1 | |
1651 | C | user spd +1 | |
1652 | D | user spc +1 | |
1653 | E | user acr +1 | This effect is unused. |
1654 | F | user evd +1 | |
1655 | 10 | get post-battle money = 2 * level * uses | |
1656 | 11 | move has 0xFE acr, regardless of battle stat modifications. | |
1657 | 12 | opponent atk -1 | |
1658 | 13 | opponent def -1 | |
1659 | 14 | opponent spd -1 | |
1660 | 15 | opponent spc -1 | |
1661 | 16 | opponent acr -1 | |
1662 | 17 | opponent evd -1 | |
1663 | 18 | converts user's type to opponent's. | |
1664 | 19 | (haze) | |
1665 | 1A | (bide) | |
1666 | 1B | (thrash) | |
1667 | 1C | (teleport) | |
1668 | 1D | (fury swipes) | |
1669 | 1E | attacks 2-5 turns | Unused. TODO: find out what it does. |
1670 | 1F | 0x19 chance of flinching | |
1671 | 20 | opponent sleep for 1-7 turns | |
1672 | 21 | 0x66 chance of poison | |
1673 | 22 | 0x4D chance of burn | |
1674 | 23 | 0x4D chance of freeze | |
1675 | 24 | 0x4D chance of paralysis | |
1676 | 25 | 0x4D chance of flinching | |
1677 | 26 | one-hit KO | |
1678 | 27 | charge one turn, atk next. | |
1679 | 28 | fixed damage, leaves 1HP. | Is the fixed damage the power of the move? |
1680 | 29 | fixed damage. | Like seismic toss, dragon rage, psywave. |
1681 | 2A | atk 2-5 turns; opponent can't attack | The odds of attacking for /n/ turns are: (0 0x60 0x60 0x20 0x20) |
1682 | 2B | charge one turn, atk next. (can't be hit when charging) | |
1683 | 2C | atk hits twice. | |
1684 | 2D | user takes 1 damage if misses. | |
1685 | 2E | evade status-lowering effects | Caused by you or also your opponent? |
1686 | 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. |
1687 | 30 | atk causes recoil dmg = 1/4 dmg dealt | |
1688 | 31 | confuses opponent | |
1689 | 32 | user atk +2 | |
1690 | 33 | user def +2 | |
1691 | 34 | user spd +2 | |
1692 | 35 | user spc +2 | |
1693 | 36 | user acr +2 | This effect is unused. |
1694 | 37 | user evd +2 | This effect is unused. |
1695 | 38 | restores up to half of user's max hp. | |
1696 | 39 | (transform) | |
1697 | 3A | opponent atk -2 | |
1698 | 3B | opponent def -2 | |
1699 | 3C | opponent spd -2 | |
1700 | 3D | opponent spc -2 | |
1701 | 3E | opponent acr -2 | |
1702 | 3F | opponent evd -2 | |
1703 | 40 | doubles user spc when attacked | |
1704 | 41 | doubles user def when attacked | |
1705 | 42 | just poisons opponent | |
1706 | 43 | just paralyzes opponent | |
1707 | 44 | 0x19 chance opponent atk -1 | |
1708 | 45 | 0x19 chance opponent def -1 | |
1709 | 46 | 0x19 chance opponent spd -1 | |
1710 | 47 | 0x4C chance opponent spc -1 | |
1711 | 48 | 0x19 chance opponent acr -1 | |
1712 | 49 | 0x19 chance opponent evd -1 | |
1713 | 4A | ??? | ;; unused? no effect? |
1714 | 4B | ??? | ;; unused? no effect? |
1715 | 4C | 0x19 chance of confusing the opponent | |
1716 | 4D | atk hits twice. 0x33 chance opponent poisioned. | |
1717 | 4E | broken. crash the game after attack. | |
1718 | 4F | (substitute) | |
1719 | 50 | unless opponent faints, user must recharge after atk. some exceptions apply | |
1720 | 51 | (rage) | |
1721 | 52 | (mimic) | |
1722 | 53 | (metronome) | |
1723 | 54 | (leech seed) | |
1724 | 55 | does nothing (splash) | |
1725 | 56 | (disable) | |
1726 #+end_src
1728 *** Source
1729 #+name: move-effects
1730 #+begin_src clojure
1731 (def move-effects
1732 ["normal damage"
1733 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?
1734 "0x4C chance of poison"
1735 "leech half of inflicted damage"
1736 "0x19 chance of burn"
1737 "0x19 chance of freeze"
1738 "0x19 chance of paralyze"
1739 "user faints; opponent defense halved during attack."
1740 "leech half of inflicted damage ONLY if sleeping opponent."
1741 "imitate last attack"
1742 "user atk +1"
1743 "user def +1"
1744 "user spd +1"
1745 "user spc +1"
1746 "user acr +1" ;; unused?!
1747 "user evd +1"
1748 "get post-battle $ = 2*level*uses"
1749 "0xFE acr, no matter what."
1750 "opponent atk -1" ;; acr taken from move acr?
1751 "opponent def -1" ;;
1752 "opponent spd -1" ;;
1753 "opponent spc -1" ;;
1754 "opponent acr -1";;
1755 "opponent evd -1"
1756 "converts user's type to opponent's."
1757 "(haze)"
1758 "(bide)"
1759 "(thrash)"
1760 "(teleport)"
1761 "(fury swipes)"
1762 "attacks 2-5 turns" ;; unused? like rollout?
1763 "0x19 chance of flinch"
1764 "opponent sleep for 1-7 turns"
1765 "0x66 chance of poison"
1766 "0x4D chance of burn"
1767 "0x4D chance of freeze"
1768 "0x4D chance of paralyze"
1769 "0x4D chance of flinch"
1770 "one-hit KO"
1771 "charge one turn, atk next."
1772 "fixed damage, leaves 1HP." ;; how is dmg determined?
1773 "fixed damage." ;; cf seismic toss, dragon rage, psywave.
1774 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)
1775 "charge one turn, atk next. (can't be hit when charging)"
1776 "atk hits twice."
1777 "user takes 1 damage if misses."
1778 "evade status-lowering effects" ;;caused by you or also your opponent?
1779 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"
1780 "atk causes recoil dmg = 1/4 dmg dealt"
1781 "confuses opponent" ;; acr taken from move acr
1782 "user atk +2"
1783 "user def +2"
1784 "user spd +2"
1785 "user spc +2"
1786 "user acr +2" ;; unused!
1787 "user evd +2" ;; unused!
1788 "restores up to half of user's max hp." ;; broken: fails if the difference
1789 ;; b/w max and current hp is one less than a multiple of 256.
1790 "(transform)"
1791 "opponent atk -2"
1792 "opponent def -2"
1793 "opponent spd -2"
1794 "opponent spc -2"
1795 "opponent acr -2"
1796 "opponent evd -2"
1797 "doubles user spc when attacked"
1798 "doubles user def when attacked"
1799 "just poisons opponent" ;;acr taken from move acr
1800 "just paralyzes opponent" ;;
1801 "0x19 chance opponent atk -1"
1802 "0x19 chance opponent def -1"
1803 "0x19 chance opponent spd -1"
1804 "0x4C chance opponent spc -1" ;; context suggest chance is 0x19
1805 "0x19 chance opponent acr -1"
1806 "0x19 chance opponent evd -1"
1807 "???" ;; unused? no effect?
1808 "???" ;; unused? no effect?
1809 "0x19 chance opponent confused"
1810 "atk hits twice. 0x33 chance opponent poisioned."
1811 "broken. crash the game after attack."
1812 "(substitute)"
1813 "unless opponent faints, user must recharge after atk. some
1814 exceptions apply."
1815 "(rage)"
1816 "(mimic)"
1817 "(metronome)"
1818 "(leech seed)"
1819 "does nothing (splash)"
1820 "(disable)"
1821 ])
1822 #+end_src
1825 ** Alphabet code
1827 * Source
1829 #+begin_src clojure :tangle ../clojure/com/aurellem/gb/hxc.clj
1831 (ns com.aurellem.gb.hxc
1832 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1833 constants species))
1834 (:import [com.aurellem.gb.gb_driver SaveState]))
1836 ; ************* HANDWRITTEN CONSTANTS
1838 <<type-ids>>
1841 ;; question: when status effects claim to take
1842 ;; their accuracy from the move accuracy, does
1843 ;; this mean that the move always "hits" but the
1844 ;; status effect may not?
1846 <<move-effects>>
1848 ;; ************** HARDCODED DATA
1850 <<hxc-thunks>>
1851 ;; --------------------------------------------------
1853 <<pokenames>>
1854 <<type-names>>
1856 ;; http://hax.iimarck.us/topic/581/
1857 <<pokecry>>
1860 <<item-names>>
1864 (def hxc-titles
1865 "The hardcoded names of the trainer titles in memory. List begins at
1866 ROM@27E77"
1867 (hxc-thunk-words 0x27E77 196))
1870 <<dex-text>>
1872 ;; In red/blue, pokedex stats are in internal order.
1873 ;; In yellow, pokedex stats are in pokedex order.
1874 <<dex-stats>>
1879 <<places>>
1881 (defn hxc-dialog
1882 "The hardcoded dialogue in memory, including in-game alerts. Dialog
1883 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."
1884 ([rom]
1885 (map character-codes->str
1886 (take-nth 2
1887 (partition-by #(= % 0x57)
1888 (take 0x0F728
1889 (drop 0x98000 rom))))))
1890 ([]
1891 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
1894 <<move-names>>
1895 <<move-data>>
1897 <<machines>>
1901 (defn internal-id
1902 ([rom]
1903 (zipmap
1904 (hxc-pokenames rom)
1905 (range)))
1906 ([]
1907 (internal-id com.aurellem.gb.gb-driver/original-rom)))
1913 ;; nidoran gender change upon levelup
1914 ;; (->
1915 ;; @current-state
1916 ;; rom
1917 ;; vec
1918 ;; (rewrite-memory
1919 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))
1920 ;; [1 1 15])
1921 ;; (rewrite-memory
1922 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))
1923 ;; [1 1 3])
1924 ;; (write-rom!)
1926 ;; )
1930 <<type-advantage>>
1934 <<evolution-header>>
1935 <<evolution>>
1936 <<learnsets>>
1937 <<pokebase>>
1940 (defn hxc-intro-pkmn
1941 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's
1942 internal id is stored at ROM@5EDB."
1943 ([] (hxc-intro-pkmn
1944 com.aurellem.gb.gb-driver/original-rom))
1945 ([rom]
1946 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))
1948 (defn sxc-intro-pkmn!
1949 "Set the hardcoded pokemon to display in Prof. Oak's introduction."
1950 [pokemon]
1951 (write-rom!
1952 (rewrite-rom 0x5EDB
1954 (inc
1955 ((zipmap
1956 (hxc-pokenames)
1957 (range))
1958 pokemon))])))
1961 <<item-prices>>
1963 <<item-vendors>>
1965 <<wilds>>
1968 ;; ********************** MANIPULATION FNS
1971 (defn same-type
1972 ([pkmn move]
1973 (same-type
1974 com.aurellem.gb.gb-driver/original-rom pkmn move))
1975 ([rom pkmn move]
1976 (((comp :types (hxc-pokemon-base rom)) pkmn)
1977 ((comp :type (hxc-move-data rom)) move))))
1982 (defn submap?
1983 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."
1984 [map-small map-big]
1985 (cond (empty? map-small) true
1986 (and
1987 (contains? map-big (ffirst map-small))
1988 (= (get map-big (ffirst map-small))
1989 (second (first map-small))))
1990 (recur (next map-small) map-big)
1992 :else false))
1995 (defn search-map [proto-map maps]
1996 "Returns all the maps that make the same associations as proto-map."
1997 (some (partial submap? proto-map) maps))
1999 (defn filter-vals
2000 "Returns a map consisting of all the pairs [key val] for
2001 which (pred key) returns true."
2002 [pred map]
2003 (reduce (partial apply assoc) {}
2004 (filter (fn [[k v]] (pred v)) map)))
2007 (defn search-moves
2008 "Returns a subcollection of all hardcoded moves with the
2009 given attributes. Attributes consist of :name :power
2010 :accuracy :pp :fx-id
2011 (and also :fx-txt, but it contains the same information
2012 as :fx-id)"
2013 ([attribute-map]
2014 (search-moves
2015 com.aurellem.gb.gb-driver/original-rom attribute-map))
2016 ([rom attribute-map]
2017 (filter-vals (partial submap? attribute-map)
2018 (hxc-move-data rom))))
2024 ;; note: 0x2f31 contains the names "TM" "HM"?
2026 ;; note for later: credits start at F1290
2028 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??
2030 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)
2032 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.
2033 ;; The first instance is for Machines; the second, for stones.
2035 ;; note: according to
2036 ;; http://www.upokecenter.com/games/rby/guides/rgbtrainers.php
2037 ;; the amount of money given by a trainer is equal to the
2038 ;; base money times the level of the last Pokemon on that trainer's
2039 ;; list. Other sources say it's the the level of the last pokemon
2040 ;; /defeated/.
2042 ;; todo: find base money.
2045 ;; note: 0xDFEA (in indexable mem) is the dex# of the currently-viewed Pokemon in
2046 ;; in the pokedex. It's used for other purposes if there is none.
2048 ;; note: 0x9D35 (index.) switches from 0xFF to 0x00 temporarily when
2049 ;; you walk between areas.
2051 ;; note: 0xD059 (index.) is the special battle type of your next battle:
2052 ;; - 00 is a usual battle
2053 ;; - 01 is a pre-scripted OLD MAN battle which always fails to catch the
2054 ;; target Pokemon.
2055 ;; - 02 is a safari zone battle
2056 ;; - 03 obligates you to run away. (unused)
2057 ;; - 04 is a pre-scripted OAK battle, which (temporarily) causes the
2058 ;; enemy Pokemon to cry PIKAAA, and which always catches the target
2059 ;; Pokemon. The target Pokemon is erased after the battle.
2060 ;; - 05+ are glitch states in which you are sort of the Pokemon.
2063 ;; note: 0x251A (in indexable mem): image decompression routine seems to begin here.
2065 ;; note: 0x4845 (index): vending inventory is loaded here. possibly
2066 ;; other things, too.
2067 (comment
2068 ;; temporarily intercept/adjust what pops out of the vending
2069 ;; machine.
2070 ;; (and how much it costs)
2072 ;; located at 0x4845
2073 ;; not to be confused with shop inventory, 0xCF7B
2074 (do
2075 (step (read-state "vend-menu"))
2076 (write-memory! (rewrite-memory (vec(memory)) 0x4845 [2 0 1 0]))
2077 (step @current-state [:a])
2078 (step @current-state [])
2079 (nstep @current-state 200) ))
2082 ;; Note: There are two tile tables, one from 8000-8FFF, the other from
2083 ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end.
2084 (defn print-pixel-letters!
2085 "The pixel tiles representing letters. Neat!"
2086 ([] (print-pixel-letters! (read-state "oak-speaks")))
2087 ([state]
2088 (map
2089 (comp
2090 println
2091 (partial map #(if (zero? %) \space 0))
2092 #(if (< (count %) 8)
2093 (recur (cons 0 %))
2094 %)
2095 reverse bit-list)
2097 (take 0xFFF (drop 0x8800 (memory state))))))
2100 ;; (defn test-2 []
2101 ;; (loop [n 0
2102 ;; pc-1 (pc-trail (-> state-defend (tick) (step [:a]) (step [:a]) (step []) (nstep 100)) 100000)
2103 ;; pc-2 (pc-trail (-> state-speed (tick) (step [:a]) (step [:a])
2104 ;; (step []) (nstep 100)) 100000)]
2105 ;; (cond (empty? (drop n pc-1)) [pc-1 n]
2106 ;; (not= (take 10 (drop n pc-1)) (take 10 pc-2))
2107 ;; (recur pc-1 pc-2 (inc n))
2108 ;; :else
2109 ;; [(take 1000 pc-2) n])))
2114 (defn test-3
2115 "Explore trainer data"
2116 ([] (test-3 0x3A289))
2117 ([start]
2118 (let [pokenames (vec(hxc-pokenames-raw))]
2119 (println
2120 (reduce
2121 str
2122 (map
2123 (fn [[adr lvl pkmn]]
2124 (str (format "%-11s %4d %02X %02X \t %05X\n"
2126 (cond
2127 (zero? lvl) "+"
2128 (nil? (get pokenames (dec pkmn)))
2129 "-"
2130 :else
2131 (get pokenames (dec pkmn)))
2132 lvl
2133 pkmn
2134 lvl
2135 adr
2136 )))
2137 (map cons
2138 (take-nth 2 (drop start (range)))
2139 (partition 2
2140 (take 400;;703
2141 (drop
2142 start
2143 ;; 0x3A75D
2144 (rom)))))))))))
2146 (defn search-memory* [mem codes k]
2147 (loop [index 0
2148 index-next 1
2149 start-match 0
2150 to-match codes
2151 matches []]
2152 (cond
2153 (>= index (count mem)) matches
2155 (empty? to-match)
2156 (recur
2157 index-next
2158 (inc index-next)
2159 index-next
2160 codes
2161 (conj matches
2162 [(hex start-match) (take k (drop start-match mem))])
2165 (or (= (first to-match) \_) ;; wildcard
2166 (= (first to-match) (nth mem index)))
2167 (recur
2168 (inc index)
2169 index-next
2170 start-match
2171 (rest to-match)
2172 matches)
2174 :else
2175 (recur
2176 index-next
2177 (inc index-next)
2178 index-next
2179 codes
2180 matches))))
2183 (def script-use-ball
2184 [0xFA ;; ld A, nn
2185 \_
2186 \_
2187 0xA7 ;; and A
2188 0xCA ;; JP Z
2189 \_
2190 \_
2191 0x3D ;; dec A
2192 0xC2 ;; JP NZ
2193 \_
2194 \_
2195 0xFA ;; LD A
2196 \_
2197 \_
2198 ])
2202 (defn search-pattern [ptn coll]
2203 (loop
2204 [index 0
2205 to-match ptn
2206 binds {}
2208 next-index 1
2209 match-start 0
2210 matches []]
2212 (cond
2213 (>= index (count coll)) matches
2214 (empty? to-match)
2215 (recur
2216 next-index
2217 ptn
2218 {}
2219 (inc next-index)
2220 next-index
2221 (conj match-start
2222 [(hex match-start) binds]))
2224 :else
2225 (let [k (first to-match)
2226 v (nth coll index)]
2227 (cond
2228 (= k \_) ;; wildcard
2229 (recur
2230 (inc index)
2231 (rest to-match)
2232 binds
2234 next-index
2235 match-start
2236 matches)
2238 (keyword? k)
2239 (if (binds k)
2240 (if (= (binds k) v)
2241 (recur
2242 (inc index)
2243 (rest to-match)
2244 binds
2245 next-index
2246 match-start
2247 matches)
2249 (recur
2250 next-index
2251 ptn
2252 {}
2253 (inc next-index)
2254 next-index
2255 matches))
2257 ;; ;; consistent bindings
2258 ;; (recur
2259 ;; (inc index)
2260 ;; (rest to-match)
2261 ;; binds
2263 ;; next-index
2264 ;; match-start
2265 ;; matches)
2267 ;; ;; inconsistent bindings
2268 ;; (recur
2269 ;; next-index
2270 ;; ptn
2271 ;; {}
2272 ;; (inc next-index)
2273 ;; next-index
2274 ;; matches))
2276 (if ((set (vals binds)) v)
2277 ;; bindings are not unique
2278 (recur
2279 next-index
2280 ptn
2281 {}
2282 (inc next-index)
2283 next-index
2284 matches)
2286 ;; bindings are unique
2287 (recur
2288 (inc index)
2289 (rest to-match)
2290 (assoc binds k v)
2292 next-index
2293 match-start
2294 matches)))
2296 :else ;; k is just a number
2297 (if (= k v)
2298 (recur
2299 (inc index)
2300 (rest to-match)
2301 binds
2303 next-index
2304 match-start
2305 matches)
2307 (recur
2308 next-index
2309 ptn
2310 {}
2311 (inc next-index)
2312 next-index
2313 matches)))))))
2323 (defn search-pattern* [ptn coll]
2324 (loop
2326 binds {}
2327 index 0
2328 index-next 1
2329 start-match 0
2330 to-match ptn
2331 matches []]
2333 (cond
2334 (>= index (count coll)) matches
2335 (empty? to-match)
2336 (recur
2337 {}
2338 index-next
2339 (inc index-next)
2340 index-next
2341 ptn
2342 (conj matches
2343 [(hex start-match) binds]))
2345 :else
2346 (let [k (first to-match)
2347 v (nth coll index)]
2348 (cond
2349 (= k \_) ;; wildcard
2350 (recur
2351 binds
2352 (inc index)
2353 index-next
2354 start-match
2355 (rest to-match)
2356 matches)
2358 (keyword? k)
2359 (if (binds k)
2360 (if (= (binds k) v)
2361 (recur
2362 binds
2363 (inc index)
2364 index-next
2365 start-match
2366 (rest to-match)
2367 matches)
2368 (recur
2369 {}
2370 index-next
2371 (inc index-next)
2372 index-next
2373 ptn
2374 matches))
2375 (if
2376 ;; every symbol must be bound to a different thing.
2377 ((set (vals binds)) v)
2378 (recur
2379 {}
2380 index-next
2381 (inc index-next)
2382 index-next
2383 ptn
2384 matches)
2385 (recur
2386 (assoc binds k v)
2387 (inc index)
2388 index-next
2389 start-match
2390 (rest to-match)
2391 matches)))
2393 :else
2394 (if (= k v)
2395 (recur
2396 binds
2397 (inc index)
2398 index-next
2399 start-match
2400 (rest to-match)
2401 matches)
2402 (recur
2403 {}
2404 index-next
2405 (inc index-next)
2406 index-next
2407 ptn
2408 matches))
2412 )))))
2417 ;; look for the rainbow badge in memory
2418 (println (reduce str (map #(str (first %) "\t" (vec(second %)) "\n") (search-memory (rom) [221] 10))))
2421 (comment
2423 (def hxc-later
2424 "Running this code produces, e.g. hardcoded names NPCs give
2425 their pokemon. Will sort through it later."
2426 (print (character-codes->str(take 10000
2427 (drop 0x71597
2428 (rom (root)))))))
2430 (let [dex
2431 (partition-by #(= 0x50 %)
2432 (take 2540
2433 (drop 0x40687
2434 (rom (root)))))]
2435 (def dex dex)
2436 (def hxc-species
2437 (map character-codes->str
2438 (take-nth 4 dex))))
2442 #+end_src
2444 #+results:
2445 : nil