view org/rom.org @ 417:0b6624c1291c

made basic tone player.
author Robert McIntyre <rlm@mit.edu>
date Mon, 16 Apr 2012 14:08:56 -0500
parents 543a78679971
children 4901ba2d3860
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 | 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. |
1081 | 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. |
1082 | 04524-04527 | (unconfirmed) possibly the bike price in Cerulean. | | |
1083 | 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#... |
1084 | 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). |
1085 |-----------------------+-----------------+-----------------+-----------------|
1086 | 05DD2-05DF2 | Menu text for player info. | | PLAYER [newline] BADGES [nelwine] POK\Eacute{}DEX [newline] TIME [0x50] |
1087 | 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. |
1088 | 06698- | ? Background music. | | |
1089 | 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] |
1090 | 7570-757D | Menu options for trading Pok\eacute{}mon | | TRADE [newline] CANCEL [0x50] |
1091 | 757D-758A | Menu options for healing Pok\eacute{}mon | | HEAL [newline] CANCEL [0x50] |
1092 | 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] |
1093 | 7AF0-8000 | (empty space) | | 0 0 0 0 0 ... |
1094 | 0822E-082F? | Pointers to background music, part I. | | |
1095 | 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). |
1096 |-----------------------+-----------------+-----------------+-----------------|
1097 | 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 |
1098 | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 |
1099 | 0DAE3. | Amount of HP restored by Potion. | " | 20 |
1100 |-----------------------+-----------------+-----------------+-----------------|
1101 | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# |
1102 | 1164B- | Terminology for the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | TYPE1[newline]TYPE2[newline] *№*,[newline]OT,[newline][0x50]STATUS,[0x50]OK |
1103 | 116DE- | Terminology for permanent stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | ATTACK[newline]DEFENSE[newline]SPEED[newline]SPECIAL[0x50] |
1104 | 11852- | Terminology for current stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | EXP POINTS[newline]LEVEL UP[0x50] |
1105 | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1106 | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1107 | 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), ... |
1108 |-----------------------+-----------------+-----------------+-----------------|
1109 | 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. |
1110 | 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"). |
1111 | 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#... |
1112 | 27DFF-27E77 | ? | 120 bytes of unknown data. | |
1113 | 27E77- | Trainer title names. | Variable-length names separated by 0x50. | YOUNGSTER#BUG CATCHER#LASS#... |
1114 | 34000- | | | |
1115 | 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. |
1116 | 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. | | |
1117 | 39462- | The Pok\eacute{}mon cry data. | Fixed-length (3 byte) descriptions of cries. | |
1118 |-----------------------+-----------------+-----------------+-----------------|
1119 | 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*.] | | |
1120 | 39B05-39DD0. | unknown | | |
1121 | 39DD1- | (?) Pointers to trainer Pok\eacute{}mon | | |
1122 | 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.].) |
1123 | 3B1E5-3B361 | Pointers to evolution/learnset data. | One high-low byte pair for each of the 190 Pok\eacute{}mon in internal order. | |
1124 |-----------------------+-----------------+-----------------+-----------------|
1125 | 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. | |
1126 | 3BBAA-3C000 | (empty) | | 0 0 0 0 ... |
1127 |-----------------------+-----------------+-----------------+-----------------|
1128 | 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.]. |
1129 | 3D6C7-3D6D6 | Two miscellaneous strings. | Variable length, separated by 0x50 | Disabled!#TYPE |
1130 |-----------------------+-----------------+-----------------+-----------------|
1131 | 40252-4027B | Pok\eacute{}dex menu text | Variable-length strings separated by 0x50. | SEEN#OWN#CONTENTS#... |
1132 | 40370-40386 | Important constants for Pok\eacute{}dex entries | | HT _ _ *?′??″* [newline] WT _ _ _ *???* lb [0x50] *POK\Eacute{}* [0x50] |
1133 | 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). |
1134 | 41072- | Pok\eacute{} placeholder species, "???" | | |
1135 |-----------------------+-----------------+-----------------+-----------------|
1136 | 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. |
1137 | 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 |
1138 | 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]... |
1139 |-----------------------+-----------------+-----------------+-----------------|
1140 | 70295- | Hall of fame | The text "HALL OF FAME" | |
1141 | 70442- | Play time/money | The text "PLAY TIME [0x50] MONEY" | |
1142 | 71500-7174B | Names of places. | Variable-length place names (strings), separated by 0x50. | PALLET TOWN#VIRIDIAN CITY#PEWTER CITY#CERULEAN CITY#... |
1143 | 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". |
1144 | 7C249-7C2?? | Pointers to background music, pt II. | | |
1145 |-----------------------+-----------------+-----------------+-----------------|
1146 | 98000-B8000 | Dialogue and other messsages. | Variable-length strings. | |
1147 | 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]." |
1148 | BC000-BC60E | Move names. | Variable-length move names, separated by 0x50. The moves are in internal order. | POUND#KARATE CHOP#DOUBLESLAP#COMET PUNCH#... |
1149 | 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♂#... |
1150 |-----------------------+-----------------+-----------------+-----------------|
1151 | E9BD5- | The text PLAY TIME (see above, 70442) | | |
1152 #+TBLFM:
1156 ** Internal Pok\eacute{}mon IDs
1157 ** Type IDs
1159 #+name: type-ids
1160 #+begin_src clojure
1161 (def pkmn-types
1162 [:normal ;;0
1163 :fighting ;;1
1164 :flying ;;2
1165 :poison ;;3
1166 :ground ;;4
1167 :rock ;;5
1168 :bird ;;6
1169 :bug ;;7
1170 :ghost ;;8
1171 :A
1172 :B
1173 :C
1174 :D
1175 :E
1176 :F
1177 :G
1178 :H
1179 :I
1180 :J
1181 :K
1182 :fire ;;20 (0x14)
1183 :water ;;21 (0x15)
1184 :grass ;;22 (0x16)
1185 :electric ;;23 (0x17)
1186 :psychic ;;24 (0x18)
1187 :ice ;;25 (0x19)
1188 :dragon ;;26 (0x1A)
1189 ])
1190 #+end_src
1192 ** Basic effects of moves
1194 *** Table of basic effects
1196 The possible effects of moves in Pok\eacute{}mon \mdash{} for example, dealing
1197 damage, leeching health, or potentially poisoning the opponent
1198 \mdash{} are stored in a table. Each move has exactly one effect, and
1199 different moves might have the same effect.
1201 For example, Leech Life, Mega Drain, and Absorb all have effect ID #3, which is \ldquo{}Leech half of the inflicted damage.\rdquo{}
1203 All the legitimate move effects are listed in the table
1204 below. Here are some notes for reading it:
1206 - Whenever an effect has a chance of doing something (like a chance of
1207 poisoning the opponent), I list the chance as a hexadecimal amount
1208 out of 256; this is to avoid rounding errors. To convert the hex amount into a percentage, divide by 256.
1209 - For some effects, the description is too cumbersome to
1210 write. Instead, I just write a move name
1211 in parentheses, like: (leech seed). That move gives a characteristic example
1212 of the effect.
1213 - I use the abbreviations =atk=, =def=, =spd=, =spc=, =acr=, =evd= for
1214 attack, defense, speed, special, accuracy, and evasiveness.
1219 | ID (hex) | Description | Notes |
1220 |----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------|
1221 | 0 | normal damage | |
1222 | 1 | no damage, just sleep | TODO: find out how many turns |
1223 | 2 | 0x4C chance of poison | |
1224 | 3 | leech half of inflicted damage | |
1225 | 4 | 0x19 chance of burn | |
1226 | 5 | 0x19 chance of freeze | |
1227 | 6 | 0x19 chance of paralysis | |
1228 | 7 | user faints; opponent's defense is halved during attack. | |
1229 | 8 | leech half of inflicted damage ONLY if the opponent is asleep | |
1230 | 9 | imitate last attack | |
1231 | A | user atk +1 | |
1232 | B | user def +1 | |
1233 | C | user spd +1 | |
1234 | D | user spc +1 | |
1235 | E | user acr +1 | This effect is unused. |
1236 | F | user evd +1 | |
1237 | 10 | get post-battle money = 2 * level * uses | |
1238 | 11 | move has 0xFE acr, regardless of battle stat modifications. | |
1239 | 12 | opponent atk -1 | |
1240 | 13 | opponent def -1 | |
1241 | 14 | opponent spd -1 | |
1242 | 15 | opponent spc -1 | |
1243 | 16 | opponent acr -1 | |
1244 | 17 | opponent evd -1 | |
1245 | 18 | converts user's type to opponent's. | |
1246 | 19 | (haze) | |
1247 | 1A | (bide) | |
1248 | 1B | (thrash) | |
1249 | 1C | (teleport) | |
1250 | 1D | (fury swipes) | |
1251 | 1E | attacks 2-5 turns | Unused. TODO: find out what it does. |
1252 | 1F | 0x19 chance of flinching | |
1253 | 20 | opponent sleep for 1-7 turns | |
1254 | 21 | 0x66 chance of poison | |
1255 | 22 | 0x4D chance of burn | |
1256 | 23 | 0x4D chance of freeze | |
1257 | 24 | 0x4D chance of paralysis | |
1258 | 25 | 0x4D chance of flinching | |
1259 | 26 | one-hit KO | |
1260 | 27 | charge one turn, atk next. | |
1261 | 28 | fixed damage, leaves 1HP. | Is the fixed damage the power of the move? |
1262 | 29 | fixed damage. | Like seismic toss, dragon rage, psywave. |
1263 | 2A | atk 2-5 turns; opponent can't attack | The odds of attacking for /n/ turns are: (0 0x60 0x60 0x20 0x20) |
1264 | 2B | charge one turn, atk next. (can't be hit when charging) | |
1265 | 2C | atk hits twice. | |
1266 | 2D | user takes 1 damage if misses. | |
1267 | 2E | evade status-lowering effects | Caused by you or also your opponent? |
1268 | 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. |
1269 | 30 | atk causes recoil dmg = 1/4 dmg dealt | |
1270 | 31 | confuses opponent | |
1271 | 32 | user atk +2 | |
1272 | 33 | user def +2 | |
1273 | 34 | user spd +2 | |
1274 | 35 | user spc +2 | |
1275 | 36 | user acr +2 | This effect is unused. |
1276 | 37 | user evd +2 | This effect is unused. |
1277 | 38 | restores up to half of user's max hp. | |
1278 | 39 | (transform) | |
1279 | 3A | opponent atk -2 | |
1280 | 3B | opponent def -2 | |
1281 | 3C | opponent spd -2 | |
1282 | 3D | opponent spc -2 | |
1283 | 3E | opponent acr -2 | |
1284 | 3F | opponent evd -2 | |
1285 | 40 | doubles user spc when attacked | |
1286 | 41 | doubles user def when attacked | |
1287 | 42 | just poisons opponent | |
1288 | 43 | just paralyzes opponent | |
1289 | 44 | 0x19 chance opponent atk -1 | |
1290 | 45 | 0x19 chance opponent def -1 | |
1291 | 46 | 0x19 chance opponent spd -1 | |
1292 | 47 | 0x4C chance opponent spc -1 | |
1293 | 48 | 0x19 chance opponent acr -1 | |
1294 | 49 | 0x19 chance opponent evd -1 | |
1295 | 4A | ??? | ;; unused? no effect? |
1296 | 4B | ??? | ;; unused? no effect? |
1297 | 4C | 0x19 chance of confusing the opponent | |
1298 | 4D | atk hits twice. 0x33 chance opponent poisioned. | |
1299 | 4E | broken. crash the game after attack. | |
1300 | 4F | (substitute) | |
1301 | 50 | unless opponent faints, user must recharge after atk. some exceptions apply | |
1302 | 51 | (rage) | |
1303 | 52 | (mimic) | |
1304 | 53 | (metronome) | |
1305 | 54 | (leech seed) | |
1306 | 55 | does nothing (splash) | |
1307 | 56 | (disable) | |
1308 #+end_src
1310 *** Source
1311 #+name: move-effects
1312 #+begin_src clojure
1313 (def move-effects
1314 ["normal damage"
1315 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?
1316 "0x4C chance of poison"
1317 "leech half of inflicted damage"
1318 "0x19 chance of burn"
1319 "0x19 chance of freeze"
1320 "0x19 chance of paralyze"
1321 "user faints; opponent defense halved during attack."
1322 "leech half of inflicted damage ONLY if sleeping opponent."
1323 "imitate last attack"
1324 "user atk +1"
1325 "user def +1"
1326 "user spd +1"
1327 "user spc +1"
1328 "user acr +1" ;; unused?!
1329 "user evd +1"
1330 "get post-battle $ = 2*level*uses"
1331 "0xFE acr, no matter what."
1332 "opponent atk -1" ;; acr taken from move acr?
1333 "opponent def -1" ;;
1334 "opponent spd -1" ;;
1335 "opponent spc -1" ;;
1336 "opponent acr -1";;
1337 "opponent evd -1"
1338 "converts user's type to opponent's."
1339 "(haze)"
1340 "(bide)"
1341 "(thrash)"
1342 "(teleport)"
1343 "(fury swipes)"
1344 "attacks 2-5 turns" ;; unused? like rollout?
1345 "0x19 chance of flinch"
1346 "opponent sleep for 1-7 turns"
1347 "0x66 chance of poison"
1348 "0x4D chance of burn"
1349 "0x4D chance of freeze"
1350 "0x4D chance of paralyze"
1351 "0x4D chance of flinch"
1352 "one-hit KO"
1353 "charge one turn, atk next."
1354 "fixed damage, leaves 1HP." ;; how is dmg determined?
1355 "fixed damage." ;; cf seismic toss, dragon rage, psywave.
1356 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)
1357 "charge one turn, atk next. (can't be hit when charging)"
1358 "atk hits twice."
1359 "user takes 1 damage if misses."
1360 "evade status-lowering effects" ;;caused by you or also your opponent?
1361 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"
1362 "atk causes recoil dmg = 1/4 dmg dealt"
1363 "confuses opponent" ;; acr taken from move acr
1364 "user atk +2"
1365 "user def +2"
1366 "user spd +2"
1367 "user spc +2"
1368 "user acr +2" ;; unused!
1369 "user evd +2" ;; unused!
1370 "restores up to half of user's max hp." ;; broken: fails if the difference
1371 ;; b/w max and current hp is one less than a multiple of 256.
1372 "(transform)"
1373 "opponent atk -2"
1374 "opponent def -2"
1375 "opponent spd -2"
1376 "opponent spc -2"
1377 "opponent acr -2"
1378 "opponent evd -2"
1379 "doubles user spc when attacked"
1380 "doubles user def when attacked"
1381 "just poisons opponent" ;;acr taken from move acr
1382 "just paralyzes opponent" ;;
1383 "0x19 chance opponent atk -1"
1384 "0x19 chance opponent def -1"
1385 "0x19 chance opponent spd -1"
1386 "0x4C chance opponent spc -1" ;; context suggest chance is 0x19
1387 "0x19 chance opponent acr -1"
1388 "0x19 chance opponent evd -1"
1389 "???" ;; unused? no effect?
1390 "???" ;; unused? no effect?
1391 "0x19 chance opponent confused"
1392 "atk hits twice. 0x33 chance opponent poisioned."
1393 "broken. crash the game after attack."
1394 "(substitute)"
1395 "unless opponent faints, user must recharge after atk. some
1396 exceptions apply."
1397 "(rage)"
1398 "(mimic)"
1399 "(metronome)"
1400 "(leech seed)"
1401 "does nothing (splash)"
1402 "(disable)"
1403 ])
1404 #+end_src
1407 ** Alphabet code
1409 * Source
1411 #+begin_src clojure :tangle ../clojure/com/aurellem/gb/hxc.clj
1413 (ns com.aurellem.gb.hxc
1414 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1415 constants species))
1416 (:import [com.aurellem.gb.gb_driver SaveState]))
1418 ; ************* HANDWRITTEN CONSTANTS
1420 <<type-ids>>
1423 ;; question: when status effects claim to take
1424 ;; their accuracy from the move accuracy, does
1425 ;; this mean that the move always "hits" but the
1426 ;; status effect may not?
1428 <<move-effects>>
1430 ;; ************** HARDCODED DATA
1432 <<hxc-thunks>>
1433 ;; --------------------------------------------------
1435 <<pokenames>>
1436 <<type-names>>
1438 ;; http://hax.iimarck.us/topic/581/
1439 <<pokecry>>
1442 <<item-names>>
1446 (def hxc-titles
1447 "The hardcoded names of the trainer titles in memory. List begins at
1448 ROM@27E77"
1449 (hxc-thunk-words 0x27E77 196))
1452 <<dex-text>>
1454 ;; In red/blue, pokedex stats are in internal order.
1455 ;; In yellow, pokedex stats are in pokedex order.
1456 <<dex-stats>>
1461 <<places>>
1463 (defn hxc-dialog
1464 "The hardcoded dialogue in memory, including in-game alerts. Dialog
1465 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."
1466 ([rom]
1467 (map character-codes->str
1468 (take-nth 2
1469 (partition-by #(= % 0x57)
1470 (take 0x0F728
1471 (drop 0x98000 rom))))))
1472 ([]
1473 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
1476 <<move-names>>
1477 <<move-data>>
1479 <<machines>>
1483 (defn internal-id
1484 ([rom]
1485 (zipmap
1486 (hxc-pokenames rom)
1487 (range)))
1488 ([]
1489 (internal-id com.aurellem.gb.gb-driver/original-rom)))
1495 ;; nidoran gender change upon levelup
1496 ;; (->
1497 ;; @current-state
1498 ;; rom
1499 ;; vec
1500 ;; (rewrite-memory
1501 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))
1502 ;; [1 1 15])
1503 ;; (rewrite-memory
1504 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))
1505 ;; [1 1 3])
1506 ;; (write-rom!)
1508 ;; )
1512 <<type-advantage>>
1516 <<evolution-header>>
1517 <<evolution>>
1518 <<learnsets>>
1519 <<pokebase>>
1522 (defn hxc-intro-pkmn
1523 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's
1524 internal id is stored at ROM@5EDB."
1525 ([] (hxc-intro-pkmn
1526 com.aurellem.gb.gb-driver/original-rom))
1527 ([rom]
1528 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))
1530 (defn sxc-intro-pkmn!
1531 "Set the hardcoded pokemon to display in Prof. Oak's introduction."
1532 [pokemon]
1533 (write-rom!
1534 (rewrite-rom 0x5EDB
1536 (inc
1537 ((zipmap
1538 (hxc-pokenames)
1539 (range))
1540 pokemon))])))
1543 <<item-prices>>
1545 <<item-vendors>>
1547 <<wilds>>
1550 ;; ********************** MANIPULATION FNS
1553 (defn same-type
1554 ([pkmn move]
1555 (same-type
1556 com.aurellem.gb.gb-driver/original-rom pkmn move))
1557 ([rom pkmn move]
1558 (((comp :types (hxc-pokemon-base rom)) pkmn)
1559 ((comp :type (hxc-move-data rom)) move))))
1564 (defn submap?
1565 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."
1566 [map-small map-big]
1567 (cond (empty? map-small) true
1568 (and
1569 (contains? map-big (ffirst map-small))
1570 (= (get map-big (ffirst map-small))
1571 (second (first map-small))))
1572 (recur (next map-small) map-big)
1574 :else false))
1577 (defn search-map [proto-map maps]
1578 "Returns all the maps that make the same associations as proto-map."
1579 (some (partial submap? proto-map) maps))
1581 (defn filter-vals
1582 "Returns a map consisting of all the pairs [key val] for
1583 which (pred key) returns true."
1584 [pred map]
1585 (reduce (partial apply assoc) {}
1586 (filter (fn [[k v]] (pred v)) map)))
1589 (defn search-moves
1590 "Returns a subcollection of all hardcoded moves with the
1591 given attributes. Attributes consist of :name :power
1592 :accuracy :pp :fx-id
1593 (and also :fx-txt, but it contains the same information
1594 as :fx-id)"
1595 ([attribute-map]
1596 (search-moves
1597 com.aurellem.gb.gb-driver/original-rom attribute-map))
1598 ([rom attribute-map]
1599 (filter-vals (partial submap? attribute-map)
1600 (hxc-move-data rom))))
1606 ;; note: 0x2f31 contains the names "TM" "HM"?
1608 ;; note for later: credits start at F1290
1610 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??
1612 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)
1614 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.
1615 ;; The first instance is for Machines; the second, for stones.
1617 ;; note: according to
1618 ;; http://www.upokecenter.com/games/rby/guides/rgbtrainers.php
1619 ;; the amount of money given by a trainer is equal to the
1620 ;; base money times the level of the last Pokemon on that trainer's
1621 ;; list. Other sources say it's the the level of the last pokemon
1622 ;; /defeated/.
1624 ;; todo: find base money.
1627 ;; note: 0xDFEA (in indexable mem) is the dex# of the currently-viewed Pokemon in
1628 ;; in the pokedex. It's used for other purposes if there is none.
1630 ;; note: 0x9D35 (index.) switches from 0xFF to 0x00 temporarily when
1631 ;; you walk between areas.
1633 ;; note: 0xD059 (index.) is the special battle type of your next battle:
1634 ;; - 00 is a usual battle
1635 ;; - 01 is a pre-scripted OLD MAN battle which always fails to catch the
1636 ;; target Pokemon.
1637 ;; - 02 is a safari zone battle
1638 ;; - 03 obligates you to run away. (unused)
1639 ;; - 04 is a pre-scripted OAK battle, which (temporarily) causes the
1640 ;; enemy Pokemon to cry PIKAAA, and which always catches the target
1641 ;; Pokemon. The target Pokemon is erased after the battle.
1642 ;; - 05+ are glitch states in which you are sort of the Pokemon.
1645 ;; note: 0x251A (in indexable mem): image decompression routine seems to begin here.
1648 ;; Note: There are two tile tables, one from 8000-8FFF, the other from
1649 ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end.
1650 (defn print-pixel-letters!
1651 "The pixel tiles representing letters. Neat!"
1652 ([] (print-pixel-letters! (read-state "oak-speaks")))
1653 ([state]
1654 (map
1655 (comp
1656 println
1657 (partial map #(if (zero? %) \space 0))
1658 #(if (< (count %) 8)
1659 (recur (cons 0 %))
1660 %)
1661 reverse bit-list)
1663 (take 0xFFF (drop 0x8800 (memory state))))))
1666 (defn test-2 []
1667 (loop [n 0
1668 pc-1 (pc-trail (-> state-defend (tick) (step [:a]) (step [:a]) (step []) (nstep 100)) 100000)
1669 pc-2 (pc-trail (-> state-speed (tick) (step [:a]) (step [:a])
1670 (step []) (nstep 100)) 100000)]
1671 (cond (empty? (drop n pc-1)) [pc-1 n]
1672 (not= (take 10 (drop n pc-1)) (take 10 pc-2))
1673 (recur pc-1 pc-2 (inc n))
1674 :else
1675 [(take 1000 pc-2) n])))
1680 (defn test-3
1681 "Explore trainer data"
1682 []
1683 (let [pokenames (vec(hxc-pokenames-raw))]
1684 (println
1685 (reduce
1686 str
1687 (map
1688 (fn [[lvl pkmn]]
1689 (str (format "%-11s %4d %02X %02X"
1690 (cond
1691 (zero? lvl) "+"
1692 (nil? (get pokenames (dec pkmn)))
1693 "-"
1694 :else
1695 (get pokenames (dec pkmn)))
1696 lvl
1697 pkmn
1698 lvl
1699 ) "\n"))
1701 (partition 2
1702 (take 100;;703
1703 (drop
1704 0x3A281
1705 ;; 0x3A75D
1706 (rom)))))))))
1708 (defn search-memory* [mem codes k]
1709 (loop [index 0
1710 index-next 1
1711 start-match 0
1712 to-match codes
1713 matches []]
1714 (cond
1715 (>= index (count mem)) matches
1717 (empty? to-match)
1718 (recur
1719 index-next
1720 (inc index-next)
1721 index-next
1722 codes
1723 (conj matches
1724 [(hex start-match) (take k (drop start-match mem))])
1727 (or (= (first to-match) \_) ;; wildcard
1728 (= (first to-match) (nth mem index)))
1729 (recur
1730 (inc index)
1731 index-next
1732 start-match
1733 (rest to-match)
1734 matches)
1736 :else
1737 (recur
1738 index-next
1739 (inc index-next)
1740 index-next
1741 codes
1742 matches))))
1748 ;; look for the rainbow badge in memory
1749 (println (reduce str (map #(str (first %) "\t" (vec(second %)) "\n") (search-memory (rom) [221] 10))))
1752 (comment
1754 (def hxc-later
1755 "Running this code produces, e.g. hardcoded names NPCs give
1756 their pokemon. Will sort through it later."
1757 (print (character-codes->str(take 10000
1758 (drop 0x71597
1759 (rom (root)))))))
1761 (let [dex
1762 (partition-by #(= 0x50 %)
1763 (take 2540
1764 (drop 0x40687
1765 (rom (root)))))]
1766 (def dex dex)
1767 (def hxc-species
1768 (map character-codes->str
1769 (take-nth 4 dex))))
1773 #+end_src
1775 #+results:
1776 : nil