view org/rom.org @ 411:0406867ead8a

Saving work -- found Pokedex menu text, and other things.
author Dylan Holmes <ocsenave@gmail.com>
date Fri, 13 Apr 2012 05:06:56 -0500
parents a2319e29205b
children 543a78679971
line wrap: on
line source
1 #+title: Notes on Deconstructing Pokemon Yellow
2 #+author: Dylan Holmes
3 #+email: rlm@mit.edu
4 #+description:
5 #+keywords:
6 #+SETUPFILE: ../../aurellem/org/setup.org
7 #+INCLUDE: ../../aurellem/org/level-0.org
8 #+BABEL: :exports both :noweb yes :cache no :mkdirp yes
10 # about map headers http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes
11 # map headers Yellow http://www.pokecommunity.com/archive/index.php/t-235311.html
12 # pokedollar: U+20B1
13 * Introduction
16 ** COMMENT Getting linguistic data: names, words, etc.
18 Some of the simplest data
21 One of the simplest data structures in the Pok\eacute{} ROM is an
22 unbroken list of strings that either (a) all have a specific length,
23 or (b) are all separated by the same character.
25 Because lots of good data has this format, we'll start by writing a
26 template function to extract it:
28 #+name: hxc-thunks
29 #+begin_src clojure :results silent
30 (defn hxc-thunk
31 "Creates a thunk (nullary fn) that grabs data in a certain region of rom and
32 splits it into a collection by 0x50. If rom is not supplied, uses the
33 original rom data."
34 [start length]
35 (fn self
36 ([rom]
37 (take-nth 2
38 (partition-by #(= % 0x50)
39 (take length
40 (drop start rom)))))
41 ([]
42 (self com.aurellem.gb.gb-driver/original-rom))))
44 (def hxc-thunk-words
45 "Same as hxc-thunk, except it interprets the rom data as characters,
46 returning a collection of strings."
47 (comp
48 (partial comp (partial map character-codes->str))
49 hxc-thunk))
51 #+end_src
54 * Pok\eacute{}mon I
55 ** Names of each species
56 The names of the Pok\eacute{}mon species are stored in
57 ROM@E8000. This name list is interesting, for a number of reasons:
58 - The names are stored in [[ ][internal order]] rather than in the familiar
59 Pok\eacute{}dex order. This seemingly random order probably represents the order in which the authors created or
60 programmed in the Pok\eacute{}mon; it's used throughout the game.
61 - There is enough space allocated for 190 Pok\eacute{}mon. As I
62 understand it, there were originally going to be 190 Pok\eacute{}mon
63 in Generation I, but the creators decided to defer some to
64 Generation II. This explains why many Gen I and Gen II Pok\eacute{}mon
65 have the same aesthetic feel.
66 - The list is pockmarked with random gaps, due to the strange internal
67 ordering
68 and the 39 unused spaces [fn::190 allocated spaces minus 151 true Pok\eacute{}mon]. These missing spaces are filled with the
69 placeholder name =MISSINGNO.= (\ldquo{}Missing number\rdquo{}).
71 Each name is exactly ten letters long; whenever a name would be too short, the extra
72 space is padded with the character 0x50.
74 *** See the data
76 Here you can see the raw data in three stages: in the first stage, we
77 just grab the first few bytes starting from position 0xE8000. In the
78 second stage, we partition the bytes into ten-letter chunks to show you
79 where the names begin and end. In the final stage, we convert each
80 byte into the letter it represents using the =character-codes->str=
81 function. (0x50 is rendered as the symbol \ldquo{} =#= \rdquo{} for
82 ease of reading).
84 #+begin_src clojure :exports both :cache no :results output
85 (ns com.aurellem.gb.hxc
86 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
87 constants))
88 (:import [com.aurellem.gb.gb_driver SaveState]))
91 (println (take 100 (drop 0xE8000 (rom))))
93 (println (partition 10 (take 100 (drop 0xE8000 (rom)))))
95 (println (character-codes->str (take 100 (drop 0xE8000 (rom)))))
98 #+end_src
100 #+results:
101 : (145 135 152 131 142 141 80 80 80 80 138 128 141 134 128 146 138 135 128 141 141 136 131 142 145 128 141 239 80 80 130 139 132 133 128 136 145 152 80 80 146 143 132 128 145 142 150 80 80 80 149 142 139 147 142 145 129 80 80 80 141 136 131 142 138 136 141 134 80 80 146 139 142 150 129 145 142 80 80 80 136 149 152 146 128 148 145 80 80 80 132 151 132 134 134 148 147 142 145 80)
102 : ((145 135 152 131 142 141 80 80 80 80) (138 128 141 134 128 146 138 135 128 141) (141 136 131 142 145 128 141 239 80 80) (130 139 132 133 128 136 145 152 80 80) (146 143 132 128 145 142 150 80 80 80) (149 142 139 147 142 145 129 80 80 80) (141 136 131 142 138 136 141 134 80 80) (146 139 142 150 129 145 142 80 80 80) (136 149 152 146 128 148 145 80 80 80) (132 151 132 134 134 148 147 142 145 80))
103 : RHYDON####KANGASKHANNIDORAN♂##CLEFAIRY##SPEAROW###VOLTORB###NIDOKING##SLOWBRO###IVYSAUR###EXEGGUTOR#
106 *** Automatically grab the data.
108 #+name: pokenames
109 #+begin_src clojure
111 (defn hxc-pokenames-raw
112 "The hardcoded names of the 190 species in memory. List begins at
113 ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters
114 long, these names are stripped of padding. See also, hxc-pokedex-names"
115 ([]
116 (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom))
117 ([rom]
118 (let [count-species 190
119 name-length 10]
120 (map character-codes->str
121 (partition name-length
122 (map #(if (= 0x50 %) 0x00 %)
123 (take (* count-species name-length)
124 (drop 0xE8000
125 rom))))))))
126 (def hxc-pokenames
127 (comp
128 (partial map format-name)
129 hxc-pokenames-raw))
134 (defn hxc-pokedex-names
135 "The names of the pokemon in hardcoded pokedex order. List of the
136 pokedex numbers of each pokemon (in internal order) begins at
137 ROM@410B1. See also, hxc-pokenames."
138 ([] (hxc-pokedex-names
139 com.aurellem.gb.gb-driver/original-rom))
140 ([rom]
141 (let [names (hxc-pokenames rom)]
142 (#(mapv %
143 ((comp range count keys) %))
144 (zipmap
145 (take (count names)
146 (drop 0x410b1 rom))
148 names)))))
150 #+end_src
154 ** Generic species information
156 #+name: pokebase
157 #+begin_src clojure
158 (defn hxc-pokemon-base
159 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))
160 ([rom]
161 (let [entry-size 28
163 pokemon (rest (hxc-pokedex-names))
164 pkmn-count (inc(count pokemon))
165 types (apply assoc {}
166 (interleave
167 (range)
168 pkmn-types)) ;;!! softcoded
169 moves (apply assoc {}
170 (interleave
171 (range)
172 (map format-name
173 (hxc-move-names rom))))
174 machines (hxc-machines)
175 ]
176 (zipmap
177 pokemon
178 (map
179 (fn [[n
180 rating-hp
181 rating-atk
182 rating-def
183 rating-speed
184 rating-special
185 type-1
186 type-2
187 rarity
188 rating-xp
189 pic-dimensions ;; tile_width|tile_height (8px/tile)
190 ptr-pic-obverse-1
191 ptr-pic-obverse-2
192 ptr-pic-reverse-1
193 ptr-pic-reverse-2
194 move-1
195 move-2
196 move-3
197 move-4
198 growth-rate
199 &
200 TMs|HMs]]
201 (let
202 [base-moves
203 (mapv moves
204 ((comp
205 ;; since the game uses zero as a delimiter,
206 ;; it must also increment all move indices by 1.
207 ;; heren we decrement to correct this.
208 (partial map dec)
209 (partial take-while (comp not zero?)))
210 [move-1 move-2 move-3 move-4]))
212 types
213 (set (list (types type-1)
214 (types type-2)))
215 TMs|HMs
216 (map
217 (comp
218 (partial map first)
219 (partial remove (comp zero? second)))
220 (split-at
221 50
222 (map vector
223 (rest(range))
224 (reduce concat
225 (map
226 #(take 8
227 (concat (bit-list %)
228 (repeat 0)))
230 TMs|HMs)))))
232 TMs (vec (first TMs|HMs))
233 HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))
236 ]
239 {:dex# n
240 :base-moves base-moves
241 :types types
242 :TMs TMs
243 :HMs HMs
244 :base-hp rating-hp
245 :base-atk rating-atk
246 :base-def rating-def
247 :base-speed rating-speed
248 :base-special rating-special
249 :o0 pic-dimensions
250 :o1 ptr-pic-obverse-1
251 :o2 ptr-pic-obverse-2
252 }))
254 (partition entry-size
255 (take (* entry-size pkmn-count)
256 (drop 0x383DE
257 rom))))))))
259 #+end_src
262 ** Pok\eacute{}mon evolutions
263 #+name: evolution-header
264 #+begin_src clojure
265 (defn format-evo
266 "Parse a sequence of evolution data, returning a map. First is the
267 method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the
268 method of evolution is by item (only stones will actually make pokemon
269 evolve, for some auxillary reason.) Finally, the minimum level for
270 evolution to occur (level 1 means no limit, which is used for trade
271 and item evolutions), followed by the internal id of the pokemon
272 into which to evolve. Hence, level up and trade evolutions are
273 described with 3
274 bytes; item evolutions with four."
275 [coll]
276 (let [method (first coll)]
277 (cond (empty? coll) []
278 (= 0 method) [] ;; just in case
279 (= 1 method) ;; level-up evolution
280 (conj (format-evo (drop 3 coll))
281 {:method :level-up
282 :min-level (nth coll 1)
283 :into (dec (nth coll 2))})
285 (= 2 method) ;; item evolution
286 (conj (format-evo (drop 4 coll))
287 {:method :item
288 :item (dec (nth coll 1))
289 :min-level (nth coll 2)
290 :into (dec (nth coll 3))})
292 (= 3 method) ;; trade evolution
293 (conj (format-evo (drop 3 coll))
294 {:method :trade
295 :min-level (nth coll 1) ;; always 1 for trade.
296 :into (dec (nth coll 2))}))))
299 (defn hxc-ptrs-evolve
300 "A hardcoded collection of 190 pointers to alternating evolution/learnset data,
301 in internal order."
302 ([]
303 (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))
304 ([rom]
305 (let [
306 pkmn-count (count (hxc-pokenames-raw)) ;; 190
307 ptrs
308 (map (fn [[a b]] (low-high a b))
309 (partition 2
310 (take (* 2 pkmn-count)
311 (drop 0x3b1e5 rom))))]
312 (map (partial + 0x34000) ptrs)
314 )))
315 #+end_src
317 #+name:evolution
318 #+begin_src clojure
320 (defn hxc-evolution
321 "Hardcoded evolution data in memory. The data exists at ROM@34000,
322 sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."
323 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
324 ([rom]
325 (apply assoc {}
326 (interleave
327 (hxc-pokenames rom)
328 (map
329 (comp
330 format-evo
331 (partial take-while (comp not zero?))
332 #(drop % rom))
333 (hxc-ptrs-evolve rom)
334 )))))
336 (defn hxc-evolution-pretty
337 "Like hxc-evolution, except it uses the names of items and pokemon
338 --- grabbed from ROM --- rather than their numerical identifiers."
339 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))
340 ([rom]
341 (let
342 [poke-names (vec (hxc-pokenames rom))
343 item-names (vec (hxc-items rom))
344 use-names
345 (fn [m]
346 (loop [ks (keys m) new-map m]
347 (let [k (first ks)]
348 (cond (nil? ks) new-map
349 (= k :into)
350 (recur
351 (next ks)
352 (assoc new-map
353 :into
354 (poke-names
355 (:into
356 new-map))))
357 (= k :item)
358 (recur
359 (next ks)
360 (assoc new-map
361 :item
362 (item-names
363 (:item new-map))))
364 :else
365 (recur
366 (next ks)
367 new-map)
368 ))))]
370 (into {}
371 (map (fn [[pkmn evo-coll]]
372 [pkmn (map use-names evo-coll)])
373 (hxc-evolution rom))))))
376 #+end_src
379 ** Level-up moves (learnsets)
380 #+name: learnsets
381 #+begin_src clojure
384 (defn hxc-learnsets
385 "Hardcoded map associating pokemon names to lists of pairs [lvl
386 move] of abilities they learn as they level up. The data
387 exists at ROM@34000, sorted by internal order. Pointers to the data
388 exist at ROM@3B1E5; see also, hxc-ptrs-evolve"
389 ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))
390 ([rom]
391 (apply assoc
392 {}
393 (interleave
394 (hxc-pokenames rom)
395 (map (comp
396 (partial map
397 (fn [[lvl mv]] [lvl (dec mv)]))
398 (partial partition 2)
399 ;; keep the learnset data
400 (partial take-while (comp not zero?))
401 ;; skip the evolution data
402 rest
403 (partial drop-while (comp not zero?)))
404 (map #(drop % rom)
405 (hxc-ptrs-evolve rom)))))))
407 (defn hxc-learnsets-pretty
408 "Live hxc-learnsets except it reports the name of each move --- as
409 it appears in rom --- rather than the move index."
410 ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))
411 ([rom]
412 (let [moves (vec(map format-name (hxc-move-names)))]
413 (into {}
414 (map (fn [[pkmn learnset]]
415 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])
416 learnset)])
417 (hxc-learnsets rom))))))
421 #+end_src
425 * Pok\eacute{}mon II : the Pok\eacute{}dex
426 ** Species vital stats
427 #+name: dex-stats
428 #+begin_src clojure
429 (defn hxc-pokedex-stats
430 "The hardcoded pokedex stats (species height weight) in memory. List
431 begins at ROM@40687"
432 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))
433 ([rom]
434 (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom))
435 pkmn-count (count pokedex-names)
436 ]
437 ((fn capture-stats
438 [n stats data]
439 (if (zero? n) stats
440 (let [[species
441 [_
442 height-ft
443 height-in
444 weight-1
445 weight-2
446 _
447 dex-ptr-1
448 dex-ptr-2
449 dex-bank
450 _
451 & data]]
452 (split-with (partial not= 0x50) data)]
453 (recur (dec n)
454 (assoc stats
455 (pokedex-names (- pkmn-count (dec n)))
456 {:species
457 (format-name (character-codes->str species))
458 :height-ft
459 height-ft
460 :height-in
461 height-in
462 :weight
463 (/ (low-high weight-1 weight-2) 10.)
465 ;; :text
466 ;; (character-codes->str
467 ;; (take-while
468 ;; (partial not= 0x50)
469 ;; (drop
470 ;; (+ 0xB8000
471 ;; -0x4000
472 ;; (low-high dex-ptr-1 dex-ptr-2))
473 ;; rom)))
474 })
476 data)
479 )))
481 pkmn-count
482 {}
483 (drop 0x40687 rom))) ))
484 #+end_src
486 #+results: dex-stats
487 : #'com.aurellem.gb.hxc/hxc-pokedex-stats
489 ** Species synopses
491 #+name: dex-text
492 #+begin_src clojure
493 (def hxc-pokedex-text-raw
494 "The hardcoded pokedex entries in memory. List begins at
495 ROM@B8000, shortly before move names."
496 (hxc-thunk-words 0xB8000 14754))
501 (defn hxc-pokedex-text
502 "The hardcoded pokedex entries in memory, presented as an
503 associative hash map. List begins at ROM@B8000."
504 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))
505 ([rom]
506 (zipmap
507 (hxc-pokedex-names rom)
508 (cons nil ;; for missingno.
509 (hxc-pokedex-text-raw rom)))))
510 #+end_src
513 ** Pok\eacute{}mon cries
514 #+name: pokecry
515 #+begin_src clojure
516 (defn hxc-cry
517 "The pokemon cry data in internal order. List begins at ROM@39462"
518 ([](hxc-cry com.aurellem.gb.gb-driver/original-rom))
519 ([rom]
520 (zipmap
521 (hxc-pokenames rom)
522 (map
523 (fn [[cry-id pitch length]]
524 {:cry-id cry-id
525 :pitch pitch
526 :length length}
527 )
528 (partition 3
529 (drop 0x39462 rom))))))
531 (defn hxc-cry-groups
532 ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom))
533 ([rom]
534 (map #(mapv first
535 (filter
536 (fn [[k v]]
537 (= % (:cry-id v)))
538 (hxc-cry)))
539 ((comp
540 range
541 count
542 set
543 (partial map :cry-id)
544 vals
545 hxc-cry)
546 rom))))
549 (defn cry-conversion!
550 "Convert Porygon's cry in ROM to be the cry of the given pokemon."
551 [pkmn]
552 (write-rom!
553 (rewrite-memory
554 (vec(rom))
555 0x3965D
556 (map second
557 ((hxc-cry) pkmn)))))
559 #+end_src
561 ** COMMENT Names of permanent stats
562 0DD4D-DD72
564 * Items
565 ** Item names
567 *** See the data
568 #+begin_src clojure :exports both :results output
569 (ns com.aurellem.gb.hxc
570 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
571 constants))
572 (:import [com.aurellem.gb.gb_driver SaveState]))
574 (println (take 100 (drop 0x045B7 (rom))))
576 (println
577 (partition-by
578 (partial = 0x50)
579 (take 100 (drop 0x045B7 (rom)))))
581 (println
582 (map character-codes->str
583 (partition-by
584 (partial = 0x50)
585 (take 100 (drop 0x045B7 (rom))))))
588 #+end_src
590 #+results:
591 : (140 128 146 147 132 145 127 129 128 139 139 80 148 139 147 145 128 127 129 128 139 139 80 134 145 132 128 147 127 129 128 139 139 80 143 142 138 186 127 129 128 139 139 80 147 142 150 141 127 140 128 143 80 129 136 130 152 130 139 132 80 230 230 230 230 230 80 146 128 133 128 145 136 127 129 128 139 139 80 143 142 138 186 131 132 151 80 140 142 142 141 127 146 147 142 141 132 80 128 141)
592 : ((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))
593 : (MASTER BALL # ULTRA BALL # GREAT BALL # POKé BALL # TOWN MAP # BICYCLE # ????? # SAFARI BALL # POKéDEX # MOON STONE # AN)
595 *** Automatically grab the data
596 #+name: item-names
597 #+begin_src clojure
599 (def hxc-items-raw
600 "The hardcoded names of the items in memory. List begins at
601 ROM@045B7"
602 (hxc-thunk-words 0x45B7 870))
604 (def hxc-items
605 "The hardcoded names of the items in memory, presented as
606 keywords. List begins at ROM@045B7. See also, hxc-items-raw."
607 (comp (partial map format-name) hxc-items-raw))
608 #+end_src
610 ** Item prices
612 ***
613 #+begin_src clojure :exports both :results output
614 (ns com.aurellem.gb.hxc
615 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
616 constants))
617 (:import [com.aurellem.gb.gb_driver SaveState]))
619 (println (take 90 (drop 0x4495 (rom))))
621 (println
622 (partition 3
623 (take 90 (drop 0x4495 (rom)))))
625 (println
626 (partition 3
627 (map hex
628 (take 90 (drop 0x4495 (rom))))))
630 (println
631 (map decode-bcd
632 (map butlast
633 (partition 3
634 (take 90 (drop 0x4495 (rom)))))))
636 (println
637 (map
638 vector
639 (hxc-items (rom))
640 (map decode-bcd
641 (map butlast
642 (partition 3
643 (take 90 (drop 0x4495 (rom))))))))
649 #+end_src
651 #+results:
652 : (0 0 0 18 0 0 6 0 0 2 0 0 0 0 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 1 0 0 2 80 0 2 80 0 2 0 0 2 0 0 48 0 0 37 0 0 21 0 0 7 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 80 0 3 80 0)
653 : ((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))
654 : ((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))
655 : (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)
656 : ([: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])
659 ***
660 #+name: item-prices
661 #+begin_src clojure
662 (defn hxc-item-prices
663 "The hardcoded list of item prices in memory. List begins at ROM@4495"
664 ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))
665 ([rom]
666 (let [items (hxc-items rom)
667 price-size 3]
668 (zipmap items
669 (map (comp
670 ;; zero-cost items are "priceless"
671 #(if (zero? %) :priceless %)
672 decode-bcd butlast)
673 (partition price-size
674 (take (* price-size (count items))
675 (drop 0x4495 rom))))))))
676 #+end_src
677 ** Vendor inventories
679 #+name: item-vendors
680 #+begin_src clojure
681 (defn hxc-shops
682 ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))
683 ([rom]
684 (let [items (zipmap (range) (hxc-items rom))
686 ;; temporarily softcode the TM items
687 items (into
688 items
689 (map (juxt identity
690 (comp keyword
691 (partial str "tm-")
692 (partial + 1 -200)
693 ))
694 (take 200 (drop 200 (range)))))
696 ]
698 ((fn parse-shop [coll [num-items & items-etc]]
699 (let [inventory (take-while
700 (partial not= 0xFF)
701 items-etc)
702 [separator & items-etc] (drop num-items (rest items-etc))]
703 (if (= separator 0x50)
704 (map (partial mapv (comp items dec)) (conj coll inventory))
705 (recur (conj coll inventory) items-etc)
706 )
707 ))
709 '()
710 (drop 0x233C rom))
713 )))
714 #+end_src
716 #+results: item-vendors
717 : #'com.aurellem.gb.hxc/hxc-shops
721 * Types
722 ** Names of types
724 *** COMMENT Pointers to type names
725 #+begin_src clojure :exports both :results output
726 (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)))))
727 #+end_src
730 ***
731 #+begin_src clojure :exports both :results output
732 (ns com.aurellem.gb.hxc
733 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
734 constants))
735 (:import [com.aurellem.gb.gb_driver SaveState]))
737 (println (take 90 (drop 0x27D99 (rom))))
739 (println
740 (partition-by (partial = 0x50)
741 (take 90 (drop 0x27D99 (rom)))))
743 (println
744 (map character-codes->str
745 (partition-by (partial = 0x50)
746 (take 90 (drop 0x27D99 (rom))))))
748 #+end_src
750 #+results:
751 : (141 142 145 140 128 139 80 133 136 134 135 147 136 141 134 80 133 139 152 136 141 134 80 143 142 136 146 142 141 80 133 136 145 132 80 150 128 147 132 145 80 134 145 128 146 146 80 132 139 132 130 147 145 136 130 80 143 146 152 130 135 136 130 80 136 130 132 80 134 145 142 148 141 131 80 145 142 130 138 80 129 136 145 131 80 129 148 134 80 134)
752 : ((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))
753 : (NORMAL # FIGHTING # FLYING # POISON # FIRE # WATER # GRASS # ELECTRIC # PSYCHIC # ICE # GROUND # ROCK # BIRD # BUG # G)
756 ***
757 #+name: type-names
758 #+begin_src clojure
759 (def hxc-types
760 "The hardcoded type names in memory. List begins at ROM@27D99,
761 shortly before hxc-titles."
762 (hxc-thunk-words 0x27D99 102))
764 #+end_src
766 ** Type effectiveness
767 ***
768 #+begin_src clojure :exports both :results output
769 (ns com.aurellem.gb.hxc
770 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
771 constants))
772 (:import [com.aurellem.gb.gb_driver SaveState]))
775 ;; POKEMON TYPES
777 (println pkmn-types) ;; these are the pokemon types
778 (println (map vector (range) pkmn-types)) ;; each type has an id number.
780 (newline)
785 ;;; TYPE EFFECTIVENESS
787 (println (take 15 (drop 0x3E62D (rom))))
788 (println (partition 3 (take 15 (drop 0x3E62D (rom)))))
790 (println
791 (map
792 (fn [[atk-type def-type multiplier]]
793 (list atk-type def-type (/ multiplier 10.)))
795 (partition 3
796 (take 15 (drop 0x3E62D (rom))))))
799 (println
800 (map
801 (fn [[atk-type def-type multiplier]]
802 [
803 (get pkmn-types atk-type)
804 (get pkmn-types def-type)
805 (/ multiplier 10.)
806 ])
808 (partition 3
809 (take 15 (drop 0x3E62D (rom))))))
811 #+end_src
813 #+results:
814 : [: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]
815 : ([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])
816 :
817 : (0 5 5 0 8 0 8 8 20 20 7 20 20 5 5)
818 : ((0 5 5) (0 8 0) (8 8 20) (20 7 20) (20 5 5))
819 : ((0 5 0.5) (0 8 0.0) (8 8 2.0) (20 7 2.0) (20 5 0.5))
820 : ([:normal :rock 0.5] [:normal :ghost 0.0] [:ghost :ghost 2.0] [:fire :bug 2.0] [:fire :rock 0.5])
823 ***
825 #+name: type-advantage
826 #+begin_src clojure
827 (defn hxc-advantage
828 ;; in-game multipliers are stored as 10x their effective value
829 ;; to allow for fractional multipliers like 1/2
831 "The hardcoded type advantages in memory, returned as tuples of
832 atk-type def-type multiplier. By default (i.e. if not listed here),
833 the multiplier is 1. List begins at 0x3E62D."
834 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))
835 ([rom]
836 (map
837 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))
838 (get pkmn-types def (hex def))
839 (/ mult 10)])
840 (partition 3
841 (take-while (partial not= 0xFF)
842 (drop 0x3E62D rom))))))
843 #+end_src
847 * Moves
848 ** Names of moves
849 *** See the data
850 #+begin_src clojure :exports both :results output
851 (ns com.aurellem.gb.hxc
852 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
853 constants))
854 (:import [com.aurellem.gb.gb_driver SaveState]))
856 (println (take 100 (drop 0xBC000 (rom))))
858 (println
859 (partition-by
860 (partial = 0x50)
861 (take 100 (drop 0xBC000 (rom)))))
863 (println
864 (map character-codes->str
865 (partition-by
866 (partial = 0x50)
867 (take 100 (drop 0xBC000 (rom))))))
870 #+end_src
872 #+results:
873 : (143 142 148 141 131 80 138 128 145 128 147 132 127 130 135 142 143 80 131 142 148 129 139 132 146 139 128 143 80 130 142 140 132 147 127 143 148 141 130 135 80 140 132 134 128 127 143 148 141 130 135 80 143 128 152 127 131 128 152 80 133 136 145 132 127 143 148 141 130 135 80 136 130 132 127 143 148 141 130 135 80 147 135 148 141 131 132 145 143 148 141 130 135 80 146 130 145 128 147 130)
874 : ((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))
875 : (POUND # KARATE CHOP # DOUBLESLAP # COMET PUNCH # MEGA PUNCH # PAY DAY # FIRE PUNCH # ICE PUNCH # THUNDERPUNCH # SCRATC)
877 *** Automatically grab the data
879 #+name: move-names
880 #+begin_src clojure
881 (def hxc-move-names
882 "The hardcoded move names in memory. List begins at ROM@BC000"
883 (hxc-thunk-words 0xBC000 1551))
884 #+end_src
886 ** Properties of moves
888 #+name: move-data
889 #+begin_src clojure
890 (defn hxc-move-data
891 "The hardcoded (basic (move effects)) in memory. List begins at
892 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id
893 :fx-txt}. The move descriptions are handwritten, not hardcoded."
894 ([]
895 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))
896 ([rom]
897 (let [names (vec (hxc-move-names rom))
898 move-count (count names)
899 move-size 6
900 types pkmn-types ;;; !! hardcoded types
901 ]
902 (zipmap (map format-name names)
903 (map
904 (fn [[idx effect power type-id accuracy pp]]
905 {:name (names (dec idx))
906 :power power
907 :accuracy accuracy
908 :pp pp
909 :type (types type-id)
910 :fx-id effect
911 :fx-txt (get move-effects effect)
912 }
913 )
915 (partition move-size
916 (take (* move-size move-count)
917 (drop 0x38000 rom))))))))
921 (defn hxc-move-data*
922 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."
923 ([]
924 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))
925 ([rom]
926 (let [names (vec (hxc-move-names rom))
927 move-count (count names)
928 move-size 6
929 format-name (fn [s]
930 (keyword (.toLowerCase
931 (apply str
932 (map #(if (= % \space) "-" %) s)))))
933 ]
934 (zipmap (map format-name names)
935 (map
936 (fn [[idx effect power type accuracy pp]]
937 {:name (names (dec idx))
938 :power power
939 :accuracy (hex accuracy)
940 :pp pp
941 :fx-id (hex effect)
942 :fx-txt (get move-effects effect)
943 }
944 )
946 (partition move-size
947 (take (* move-size move-count)
948 (drop 0x38000 rom))))))))
950 #+end_src
952 ** TM and HM moves
953 ***
954 #+begin_src clojure :exports both :results output
955 (ns com.aurellem.gb.hxc
956 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
957 constants))
958 (:import [com.aurellem.gb.gb_driver SaveState]))
961 (println (hxc-move-names))
962 (println (map vector (rest(range)) (hxc-move-names)))
964 (newline)
966 (println (take 55 (drop 0x1232D (rom))))
968 (println
969 (interpose "."
970 (map
971 (zipmap (rest (range)) (hxc-move-names))
972 (take 55 (drop 0x1232D (rom))))))
974 #+end_src
976 #+results:
977 : (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)
978 : ([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])
979 :
980 : (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)
981 : (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)
984 ***
985 #+name: machines
986 #+begin_src clojure
987 (defn hxc-machines
988 "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."
989 ([] (hxc-machines
990 com.aurellem.gb.gb-driver/original-rom))
991 ([rom]
992 (let [moves (hxc-move-names rom)]
993 (zipmap
994 (range)
995 (take-while
996 (comp not nil?)
997 (map (comp
998 format-name
999 (zipmap
1000 (range)
1001 moves)
1002 dec)
1003 (take 100
1004 (drop 0x1232D rom))))))))
1006 #+end_src
1012 ** COMMENT Status ailments
1014 * Places
1015 ** Names of places
1017 #+name: places
1018 #+begin_src clojure
1019 (def hxc-places
1020 "The hardcoded place names in memory. List begins at
1021 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."
1022 (hxc-thunk-words 0x71500 560))
1024 #+end_src
1026 ** Wild Pok\eacute{}mon demographics
1027 #+name: wilds
1028 #+begin_src clojure
1032 (defn hxc-ptrs-wild
1033 "A list of the hardcoded wild encounter data in memory. Pointers
1034 begin at ROM@0CB95; data begins at ROM@0x04D89"
1035 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))
1036 ([rom]
1037 (let [ptrs
1038 (map (fn [[a b]] (+ a (* 0x100 b)))
1039 (take-while (partial not= (list 0xFF 0xFF))
1040 (partition 2 (drop 0xCB95 rom))))]
1041 ptrs)))
1045 (defn hxc-wilds
1046 "A list of the hardcoded wild encounter data in memory. Pointers
1047 begin at ROM@0CB95; data begins at ROM@0x04D89"
1048 ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))
1049 ([rom]
1050 (let [pokenames (zipmap (range) (hxc-pokenames rom))]
1051 (map
1052 (partial map (fn [[a b]] {:species (pokenames (dec b)) :level
1053 a}))
1054 (partition 10
1056 (take-while (comp (partial not= 1)
1057 first)
1058 (partition 2
1059 (drop 0xCD8C rom))
1061 ))))))
1063 #+end_src
1069 * Appendices
1073 ** Mapping the ROM
1075 | ROM address (hex) | Description | Format | Example |
1076 |-----------------------+-----------------+-----------------+-----------------|
1077 | | <15> | <15> | <15> |
1078 | 01823-0184A | Important prefix strings. | Variable-length strings, separated by 0x50. | TM#TRAINER#PC#ROCKET#POK\eacute{}#... |
1079 | 0233C- | Shop inventories. | | |
1080 | 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. |
1081 | 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#... |
1082 | 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). |
1083 | 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. |
1084 | 06698- | ? Background music. | | |
1085 | 0822E-082F? | Pointers to background music, part I. | | |
1086 | 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). |
1087 |-----------------------+-----------------+-----------------+-----------------|
1088 | 0DADB. | Amount of HP restored by Hyper Potion. | The HP consists of a single byte. TODO: Discover what the surrounding data does, and find the data for the amount of HP restored by other items: Fresh Water (50HP), Soda (60HP), Lemonade(80HP). | 200 |
1089 | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 |
1090 | 0DAE3. | Amount of HP restored by Potion. | " | 20 |
1091 |-----------------------+-----------------+-----------------+-----------------|
1092 | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# |
1093 | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1094 | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1095 | 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), ... |
1096 |-----------------------+-----------------+-----------------+-----------------|
1097 | 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. |
1098 | 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"). |
1099 | 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#... |
1100 | 27DFF-27E77 | ? | 120 bytes of unknown data. | |
1101 | 27E77- | Trainer title names. | Variable-length names separated by 0x50. | YOUNGSTER#BUG CATCHER#LASS#... |
1102 | 34000- | | | |
1103 | 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. |
1104 | 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. | | |
1105 | 39462- | The Pok\eacute{}mon cry data. | Fixed-length (3 byte) descriptions of cries. | |
1106 |-----------------------+-----------------+-----------------+-----------------|
1107 | 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*.] | | |
1108 | 39B05-3A289 (?) | Pointers to trainer Pok\eacute{}mon | | |
1109 | 3A289-3A540 (approx) | Trainer Pok\eacute{}mon | Consecutive level/internal-id pairs (as with wild Pok\eacute{}mon; see 04D89) with irregular spacing \mdash{} the separators seem to have some metadata purpose. | The first entry is 0x05 0x66, representing level 5 Eevee (from your first battle in the game[fn::Incidentally, to change your rival's starter Pok\eacute{}mon, it's enough just to change its species in all of your battles with him.].) |
1110 | 3B1E5-3B361 | Pointers to evolution/learnset data. | One high-low byte pair for each of the 190 Pok\eacute{}mon in internal order. | |
1111 |-----------------------+-----------------+-----------------+-----------------|
1112 | 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. | |
1113 | 3BBAA-3C000 | (empty) | | 0 0 0 0 ... |
1114 |-----------------------+-----------------+-----------------+-----------------|
1115 | 3D6C7-3D6D6 | Two miscellaneous strings. | Variable length, separated by 0x50 | Disabled!#TYPE |
1116 |-----------------------+-----------------+-----------------+-----------------|
1117 | 40252-4027B | Pok\eacute{}dex menu text | Variable-length strings separated by 0x50. | SEEN#OWN#CONTENTS#... |
1118 | 40370-40386 | Important constants for Pok\eacute{}dex entries | | HT _ _ *?′??″* [newline] WT _ _ _ *???* lb [0x50] *POK\Eacute{}* [0x50] |
1119 | 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). |
1120 | 41072- | Pok\eacute{} placeholder species, "???" | | |
1121 |-----------------------+-----------------+-----------------+-----------------|
1122 | 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. |
1123 | 527BA-527DB | The costs and species of prizes from Celadon Game Corner. | The following pattern repeats three times, once per window[fn::For the first two groups, ids are interpreted as Pok\eacute{}mon ids. For the last group, 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 |
1124 | 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]... |
1125 | 71500-7174B | Names of places. | Variable-length place names (strings), separated by 0x50. | PALLET TOWN#VIRIDIAN CITY#PEWTER CITY#CERULEAN CITY#... |
1126 | 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". |
1127 | 7C249-7C2?? | Pointers to background music, pt II. | | |
1128 | 98000-B8000 | Dialogue and other messsages. | Variable-length strings. | |
1129 | 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]." |
1130 | BC000-BC60E | Move names. | Variable-length move names, separated by 0x50. The moves are in internal order. | POUND#KARATE CHOP#DOUBLESLAP#COMET PUNCH#... |
1131 | 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♂#... |
1132 | | | | |
1133 | | | | |
1134 #+TBLFM:
1138 ** Internal Pok\eacute{}mon IDs
1139 ** Type IDs
1141 #+name: type-ids
1142 #+begin_src clojure
1143 (def pkmn-types
1144 [:normal ;;0
1145 :fighting ;;1
1146 :flying ;;2
1147 :poison ;;3
1148 :ground ;;4
1149 :rock ;;5
1150 :bird ;;6
1151 :bug ;;7
1152 :ghost ;;8
1153 :A
1154 :B
1155 :C
1156 :D
1157 :E
1158 :F
1159 :G
1160 :H
1161 :I
1162 :J
1163 :K
1164 :fire ;;20 (0x14)
1165 :water ;;21 (0x15)
1166 :grass ;;22 (0x16)
1167 :electric ;;23 (0x17)
1168 :psychic ;;24 (0x18)
1169 :ice ;;25 (0x19)
1170 :dragon ;;26 (0x1A)
1171 ])
1172 #+end_src
1174 ** Basic effects of moves
1176 *** Table of basic effects
1178 The possible effects of moves in Pok\eacute{}mon \mdash{} for example, dealing
1179 damage, leeching health, or potentially poisoning the opponent
1180 \mdash{} are stored in a table. Each move has exactly one effect, and
1181 different moves might have the same effect.
1183 For example, Leech Life, Mega Drain, and Absorb all have effect ID #3, which is \ldquo{}Leech half of the inflicted damage.\rdquo{}
1185 All the legitimate move effects are listed in the table
1186 below. Here are some notes for reading it:
1188 - Whenever an effect has a chance of doing something (like a chance of
1189 poisoning the opponent), I list the chance as a hexadecimal amount
1190 out of 256; this is to avoid rounding errors. To convert the hex amount into a percentage, divide by 256.
1191 - For some effects, the description is too cumbersome to
1192 write. Instead, I just write a move name
1193 in parentheses, like: (leech seed). That move gives a characteristic example
1194 of the effect.
1195 - I use the abbreviations =atk=, =def=, =spd=, =spc=, =acr=, =evd= for
1196 attack, defense, speed, special, accuracy, and evasiveness.
1201 | ID (hex) | Description | Notes |
1202 |----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------|
1203 | 0 | normal damage | |
1204 | 1 | no damage, just sleep | TODO: find out how many turns |
1205 | 2 | 0x4C chance of poison | |
1206 | 3 | leech half of inflicted damage | |
1207 | 4 | 0x19 chance of burn | |
1208 | 5 | 0x19 chance of freeze | |
1209 | 6 | 0x19 chance of paralysis | |
1210 | 7 | user faints; opponent's defense is halved during attack. | |
1211 | 8 | leech half of inflicted damage ONLY if the opponent is asleep | |
1212 | 9 | imitate last attack | |
1213 | A | user atk +1 | |
1214 | B | user def +1 | |
1215 | C | user spd +1 | |
1216 | D | user spc +1 | |
1217 | E | user acr +1 | This effect is unused. |
1218 | F | user evd +1 | |
1219 | 10 | get post-battle money = 2 * level * uses | |
1220 | 11 | move has 0xFE acr, regardless of battle stat modifications. | |
1221 | 12 | opponent atk -1 | |
1222 | 13 | opponent def -1 | |
1223 | 14 | opponent spd -1 | |
1224 | 15 | opponent spc -1 | |
1225 | 16 | opponent acr -1 | |
1226 | 17 | opponent evd -1 | |
1227 | 18 | converts user's type to opponent's. | |
1228 | 19 | (haze) | |
1229 | 1A | (bide) | |
1230 | 1B | (thrash) | |
1231 | 1C | (teleport) | |
1232 | 1D | (fury swipes) | |
1233 | 1E | attacks 2-5 turns | Unused. TODO: find out what it does. |
1234 | 1F | 0x19 chance of flinching | |
1235 | 20 | opponent sleep for 1-7 turns | |
1236 | 21 | 0x66 chance of poison | |
1237 | 22 | 0x4D chance of burn | |
1238 | 23 | 0x4D chance of freeze | |
1239 | 24 | 0x4D chance of paralysis | |
1240 | 25 | 0x4D chance of flinching | |
1241 | 26 | one-hit KO | |
1242 | 27 | charge one turn, atk next. | |
1243 | 28 | fixed damage, leaves 1HP. | Is the fixed damage the power of the move? |
1244 | 29 | fixed damage. | Like seismic toss, dragon rage, psywave. |
1245 | 2A | atk 2-5 turns; opponent can't attack | The odds of attacking for /n/ turns are: (0 0x60 0x60 0x20 0x20) |
1246 | 2B | charge one turn, atk next. (can't be hit when charging) | |
1247 | 2C | atk hits twice. | |
1248 | 2D | user takes 1 damage if misses. | |
1249 | 2E | evade status-lowering effects | Caused by you or also your opponent? |
1250 | 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. |
1251 | 30 | atk causes recoil dmg = 1/4 dmg dealt | |
1252 | 31 | confuses opponent | |
1253 | 32 | user atk +2 | |
1254 | 33 | user def +2 | |
1255 | 34 | user spd +2 | |
1256 | 35 | user spc +2 | |
1257 | 36 | user acr +2 | This effect is unused. |
1258 | 37 | user evd +2 | This effect is unused. |
1259 | 38 | restores up to half of user's max hp. | |
1260 | 39 | (transform) | |
1261 | 3A | opponent atk -2 | |
1262 | 3B | opponent def -2 | |
1263 | 3C | opponent spd -2 | |
1264 | 3D | opponent spc -2 | |
1265 | 3E | opponent acr -2 | |
1266 | 3F | opponent evd -2 | |
1267 | 40 | doubles user spc when attacked | |
1268 | 41 | doubles user def when attacked | |
1269 | 42 | just poisons opponent | |
1270 | 43 | just paralyzes opponent | |
1271 | 44 | 0x19 chance opponent atk -1 | |
1272 | 45 | 0x19 chance opponent def -1 | |
1273 | 46 | 0x19 chance opponent spd -1 | |
1274 | 47 | 0x4C chance opponent spc -1 | |
1275 | 48 | 0x19 chance opponent acr -1 | |
1276 | 49 | 0x19 chance opponent evd -1 | |
1277 | 4A | ??? | ;; unused? no effect? |
1278 | 4B | ??? | ;; unused? no effect? |
1279 | 4C | 0x19 chance of confusing the opponent | |
1280 | 4D | atk hits twice. 0x33 chance opponent poisioned. | |
1281 | 4E | broken. crash the game after attack. | |
1282 | 4F | (substitute) | |
1283 | 50 | unless opponent faints, user must recharge after atk. some exceptions apply | |
1284 | 51 | (rage) | |
1285 | 52 | (mimic) | |
1286 | 53 | (metronome) | |
1287 | 54 | (leech seed) | |
1288 | 55 | does nothing (splash) | |
1289 | 56 | (disable) | |
1290 #+end_src
1292 *** Source
1293 #+name: move-effects
1294 #+begin_src clojure
1295 (def move-effects
1296 ["normal damage"
1297 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?
1298 "0x4C chance of poison"
1299 "leech half of inflicted damage"
1300 "0x19 chance of burn"
1301 "0x19 chance of freeze"
1302 "0x19 chance of paralyze"
1303 "user faints; opponent defense halved during attack."
1304 "leech half of inflicted damage ONLY if sleeping opponent."
1305 "imitate last attack"
1306 "user atk +1"
1307 "user def +1"
1308 "user spd +1"
1309 "user spc +1"
1310 "user acr +1" ;; unused?!
1311 "user evd +1"
1312 "get post-battle $ = 2*level*uses"
1313 "0xFE acr, no matter what."
1314 "opponent atk -1" ;; acr taken from move acr?
1315 "opponent def -1" ;;
1316 "opponent spd -1" ;;
1317 "opponent spc -1" ;;
1318 "opponent acr -1";;
1319 "opponent evd -1"
1320 "converts user's type to opponent's."
1321 "(haze)"
1322 "(bide)"
1323 "(thrash)"
1324 "(teleport)"
1325 "(fury swipes)"
1326 "attacks 2-5 turns" ;; unused? like rollout?
1327 "0x19 chance of flinch"
1328 "opponent sleep for 1-7 turns"
1329 "0x66 chance of poison"
1330 "0x4D chance of burn"
1331 "0x4D chance of freeze"
1332 "0x4D chance of paralyze"
1333 "0x4D chance of flinch"
1334 "one-hit KO"
1335 "charge one turn, atk next."
1336 "fixed damage, leaves 1HP." ;; how is dmg determined?
1337 "fixed damage." ;; cf seismic toss, dragon rage, psywave.
1338 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)
1339 "charge one turn, atk next. (can't be hit when charging)"
1340 "atk hits twice."
1341 "user takes 1 damage if misses."
1342 "evade status-lowering effects" ;;caused by you or also your opponent?
1343 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"
1344 "atk causes recoil dmg = 1/4 dmg dealt"
1345 "confuses opponent" ;; acr taken from move acr
1346 "user atk +2"
1347 "user def +2"
1348 "user spd +2"
1349 "user spc +2"
1350 "user acr +2" ;; unused!
1351 "user evd +2" ;; unused!
1352 "restores up to half of user's max hp." ;; broken: fails if the difference
1353 ;; b/w max and current hp is one less than a multiple of 256.
1354 "(transform)"
1355 "opponent atk -2"
1356 "opponent def -2"
1357 "opponent spd -2"
1358 "opponent spc -2"
1359 "opponent acr -2"
1360 "opponent evd -2"
1361 "doubles user spc when attacked"
1362 "doubles user def when attacked"
1363 "just poisons opponent" ;;acr taken from move acr
1364 "just paralyzes opponent" ;;
1365 "0x19 chance opponent atk -1"
1366 "0x19 chance opponent def -1"
1367 "0x19 chance opponent spd -1"
1368 "0x4C chance opponent spc -1" ;; context suggest chance is 0x19
1369 "0x19 chance opponent acr -1"
1370 "0x19 chance opponent evd -1"
1371 "???" ;; unused? no effect?
1372 "???" ;; unused? no effect?
1373 "0x19 chance opponent confused"
1374 "atk hits twice. 0x33 chance opponent poisioned."
1375 "broken. crash the game after attack."
1376 "(substitute)"
1377 "unless opponent faints, user must recharge after atk. some
1378 exceptions apply."
1379 "(rage)"
1380 "(mimic)"
1381 "(metronome)"
1382 "(leech seed)"
1383 "does nothing (splash)"
1384 "(disable)"
1385 ])
1386 #+end_src
1389 ** Alphabet code
1391 * Source
1393 #+begin_src clojure :tangle ../clojure/com/aurellem/gb/hxc.clj
1395 (ns com.aurellem.gb.hxc
1396 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1397 constants species))
1398 (:import [com.aurellem.gb.gb_driver SaveState]))
1400 ; ************* HANDWRITTEN CONSTANTS
1402 <<type-ids>>
1405 ;; question: when status effects claim to take
1406 ;; their accuracy from the move accuracy, does
1407 ;; this mean that the move always "hits" but the
1408 ;; status effect may not?
1410 <<move-effects>>
1412 ;; ************** HARDCODED DATA
1414 <<hxc-thunks>>
1415 ;; --------------------------------------------------
1417 <<pokenames>>
1418 <<type-names>>
1420 ;; http://hax.iimarck.us/topic/581/
1421 <<pokecry>>
1424 <<item-names>>
1428 (def hxc-titles
1429 "The hardcoded names of the trainer titles in memory. List begins at
1430 ROM@27E77"
1431 (hxc-thunk-words 0x27E77 196))
1434 <<dex-text>>
1436 ;; In red/blue, pokedex stats are in internal order.
1437 ;; In yellow, pokedex stats are in pokedex order.
1438 <<dex-stats>>
1443 <<places>>
1445 (defn hxc-dialog
1446 "The hardcoded dialogue in memory, including in-game alerts. Dialog
1447 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."
1448 ([rom]
1449 (map character-codes->str
1450 (take-nth 2
1451 (partition-by #(= % 0x57)
1452 (take 0x0F728
1453 (drop 0x98000 rom))))))
1454 ([]
1455 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
1458 <<move-names>>
1459 <<move-data>>
1461 <<machines>>
1465 (defn internal-id
1466 ([rom]
1467 (zipmap
1468 (hxc-pokenames rom)
1469 (range)))
1470 ([]
1471 (internal-id com.aurellem.gb.gb-driver/original-rom)))
1477 ;; nidoran gender change upon levelup
1478 ;; (->
1479 ;; @current-state
1480 ;; rom
1481 ;; vec
1482 ;; (rewrite-memory
1483 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))
1484 ;; [1 1 15])
1485 ;; (rewrite-memory
1486 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))
1487 ;; [1 1 3])
1488 ;; (write-rom!)
1490 ;; )
1494 <<type-advantage>>
1498 <<evolution-header>>
1499 <<evolution>>
1500 <<learnsets>>
1501 <<pokebase>>
1504 (defn hxc-intro-pkmn
1505 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's
1506 internal id is stored at ROM@5EDB."
1507 ([] (hxc-intro-pkmn
1508 com.aurellem.gb.gb-driver/original-rom))
1509 ([rom]
1510 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))
1512 (defn sxc-intro-pkmn!
1513 "Set the hardcoded pokemon to display in Prof. Oak's introduction."
1514 [pokemon]
1515 (write-rom!
1516 (rewrite-rom 0x5EDB
1518 (inc
1519 ((zipmap
1520 (hxc-pokenames)
1521 (range))
1522 pokemon))])))
1525 <<item-prices>>
1527 <<item-vendors>>
1529 <<wilds>>
1532 ;; ********************** MANIPULATION FNS
1535 (defn same-type
1536 ([pkmn move]
1537 (same-type
1538 com.aurellem.gb.gb-driver/original-rom pkmn move))
1539 ([rom pkmn move]
1540 (((comp :types (hxc-pokemon-base rom)) pkmn)
1541 ((comp :type (hxc-move-data rom)) move))))
1546 (defn submap?
1547 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."
1548 [map-small map-big]
1549 (cond (empty? map-small) true
1550 (and
1551 (contains? map-big (ffirst map-small))
1552 (= (get map-big (ffirst map-small))
1553 (second (first map-small))))
1554 (recur (next map-small) map-big)
1556 :else false))
1559 (defn search-map [proto-map maps]
1560 "Returns all the maps that make the same associations as proto-map."
1561 (some (partial submap? proto-map) maps))
1563 (defn filter-vals
1564 "Returns a map consisting of all the pairs [key val] for
1565 which (pred key) returns true."
1566 [pred map]
1567 (reduce (partial apply assoc) {}
1568 (filter (fn [[k v]] (pred v)) map)))
1571 (defn search-moves
1572 "Returns a subcollection of all hardcoded moves with the
1573 given attributes. Attributes consist of :name :power
1574 :accuracy :pp :fx-id
1575 (and also :fx-txt, but it contains the same information
1576 as :fx-id)"
1577 ([attribute-map]
1578 (search-moves
1579 com.aurellem.gb.gb-driver/original-rom attribute-map))
1580 ([rom attribute-map]
1581 (filter-vals (partial submap? attribute-map)
1582 (hxc-move-data rom))))
1588 ;; note: 0x2f31 contains the names "TM" "HM"?
1590 ;; note for later: credits start at F1290
1592 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??
1594 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)
1596 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.
1597 ;; The first instance is for Machines; the second, for stones.
1599 ;; note: according to
1600 ;; http://www.upokecenter.com/games/rby/guides/rgbtrainers.php
1601 ;; the amount of money given by a trainer is equal to the
1602 ;; base money times the level of the last Pokemon on that trainer's
1603 ;; list. Other sources say it's the the level of the last pokemon
1604 ;; /defeated/.
1606 ;; todo: find base money.
1609 ;; note: 0xDFEA (in indexable mem) is the dex# of the currently-viewed Pokemon in
1610 ;; in the pokedex. It's used for other purposes if there is none.
1612 ;; 0x251A (in indexable mem): image decompression routine seems to begin here.
1615 ;; Note: There are two tile tables, one from 8000-8FFF, the other from
1616 ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end.
1617 (defn print-pixel-letters!
1618 "The pixel tiles representing letters. Neat!"
1619 ([] (print-pixel-letters! (read-state "oak-speaks")))
1620 ([state]
1621 (map
1622 (comp
1623 println
1624 (partial map #(if (zero? %) \space 0))
1625 #(if (< (count %) 8)
1626 (recur (cons 0 %))
1627 %)
1628 reverse bit-list)
1630 (take 0xFFF (drop 0x8800 (memory state))))))
1633 (defn test-2 []
1634 (loop [n 0
1635 pc-1 (pc-trail (-> state-defend (tick) (step [:a]) (step [:a]) (step []) (nstep 100)) 100000)
1636 pc-2 (pc-trail (-> state-speed (tick) (step [:a]) (step [:a])
1637 (step []) (nstep 100)) 100000)]
1638 (cond (empty? (drop n pc-1)) [pc-1 n]
1639 (not= (take 10 (drop n pc-1)) (take 10 pc-2))
1640 (recur pc-1 pc-2 (inc n))
1641 :else
1642 [(take 1000 pc-2) n])))
1647 (defn test-3
1648 "Explore trainer data"
1649 []
1650 (let [pokenames (vec(hxc-pokenames-raw))]
1651 (println
1652 (reduce
1653 str
1654 (map
1655 (fn [[lvl pkmn]]
1656 (str (format "%-11s %4d %02X %02X"
1657 (cond
1658 (zero? lvl) "+"
1659 (nil? (get pokenames (dec pkmn)))
1660 "-"
1661 :else
1662 (get pokenames (dec pkmn)))
1663 lvl
1664 pkmn
1665 lvl
1666 ) "\n"))
1668 (partition 2
1669 (take 100;;703
1670 (drop 0x3A281 (rom)))))))))
1674 ;; look for the rainbow badge in memory
1675 (println (reduce str (map #(str (first %) "\t" (vec(second %)) "\n") (search-memory (rom) [221] 10))))
1678 (comment
1680 (def hxc-later
1681 "Running this code produces, e.g. hardcoded names NPCs give
1682 their pokemon. Will sort through it later."
1683 (print (character-codes->str(take 10000
1684 (drop 0x71597
1685 (rom (root)))))))
1687 (let [dex
1688 (partition-by #(= 0x50 %)
1689 (take 2540
1690 (drop 0x40687
1691 (rom (root)))))]
1692 (def dex dex)
1693 (def hxc-species
1694 (map character-codes->str
1695 (take-nth 4 dex))))
1699 #+end_src
1701 #+results:
1702 : nil