comparison org/rom.org @ 420:acc3d1ad24e8

Found HP restored by SODA POP, FRESH WATER, LEMONADE; also found number of steps for REPEL, SUPER REPEL, MAX REPEL.
author Dylan Holmes <ocsenave@gmail.com>
date Sat, 14 Apr 2012 09:27:49 -0500
parents 4901ba2d3860
children 13165fb5852b
comparison
equal deleted inserted replaced
419:4901ba2d3860 420:acc3d1ad24e8
1092 1092
1093 #+name: places 1093 #+name: places
1094 #+begin_src clojure 1094 #+begin_src clojure
1095 (def hxc-places 1095 (def hxc-places
1096 "The hardcoded place names in memory. List begins at 1096 "The hardcoded place names in memory. List begins at
1097 ROM@71500. [Cinnabar/Cerulean] Mansion seems to be dynamically calculated." 1097 ROM@71500. [Cinnabar/Celadon] Mansion seems to be dynamically calculated."
1098 (hxc-thunk-words 0x71500 560)) 1098 (hxc-thunk-words 0x71500 560))
1099 #+end_src 1099 #+end_src
1100 1100
1101 *** See it work 1101 *** See it work
1102 #+begin_src clojure :exports both :results output 1102 #+begin_src clojure :exports both :results output
1146 #+end_src 1146 #+end_src
1147 1147
1148 1148
1149 1149
1150 1150
1151 ** Map data
1152
1153 # http://www.pokecommunity.com/showthread.php?t=235311
1154 # http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes
1155
1156 #+name map
1157 #+begin_src clojure :exports both :results output
1158 (ns com.aurellem.gb.hxc
1159 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
1160 constants))
1161 (:import [com.aurellem.gb.gb_driver SaveState]))
1162
1163
1164 (defn parse-header-tileset
1165 [[bank# ;; memory bank for blocks & tileset
1166
1167 blocks-lo ;; structure
1168 blocks-hi
1169
1170 tileset-lo ;; style
1171 tileset-hi
1172
1173 collision-lo ;; collision info
1174 collision-hi
1175
1176 talk-here-1 ;; positions of up to three
1177 talk-here-2 ;; talk-over-countertop tiles
1178 talk-here-3 ;; --- 0xFF if unused.
1179
1180 grass ;; grass tile --- 0xFF if unused
1181
1182 animation-flags ;; settings for animation
1183 & _]]
1184
1185 [bank#
1186
1187 blocks-lo ;; structure
1188 blocks-hi
1189
1190 tileset-lo ;; style
1191 tileset-hi
1192
1193 collision-lo ;; collision info
1194 collision-hi
1195
1196 talk-here-1 ;; positions of up to three
1197 talk-here-2 ;; talk-over-countertop tiles
1198 talk-here-3 ;; --- 0xFF if unused.
1199
1200 grass ;; grass tile --- 0xFF if unused
1201
1202 animation-flags ;; settings for animation
1203 ])
1204
1205
1206
1207 (defn parse-header-map
1208 [start]
1209
1210 (let [connection-size 11
1211
1212 [tileset-index
1213 map-height
1214 map-width
1215 layout-lo
1216 layout-hi
1217 text-lo
1218 text-hi
1219 script-lo
1220 script-hi
1221 adjacency-flags ;; x x x x N S W E
1222 & etc]
1223 (drop start (rom))
1224
1225 [east? west? south? north?]
1226 (bit-list adjacency-flags)
1227
1228 [connections object-data]
1229 (split-at
1230 (* connection-size (+ east? west? south? north?))
1231 etc)
1232
1233 connections
1234 (partition connection-size connections)
1235
1236
1237
1238
1239 ]
1240 (ptr->offset
1241 3
1242 (low-high layout-lo layout-hi))
1243
1244
1245 ))
1246 #+end_src
1247
1248 #+results:
1249 :
1250
1251
1151 1252
1152 * Appendices 1253 * Appendices
1153 ** Mapping the ROM 1254 ** Mapping the ROM
1255 # D3AD: Script:Use Pokeball?
1154 1256
1155 | ROM address (hex) | Description | Format | Example | 1257 | ROM address (hex) | Description | Format | Example |
1156 |-----------------------+-----------------+-----------------+-----------------| 1258 |-----------------------+-----------------+-----------------+-----------------|
1157 | | <15> | <15> | <15> | 1259 | | <15> | <15> | <15> |
1158 | 01823-0184A | Important prefix strings. | Variable-length strings, separated by 0x50. | TM#TRAINER#PC#ROCKET#POK\eacute{}#... | 1260 | 01823-0184A | Important prefix strings. | Variable-length strings, separated by 0x50. | TM#TRAINER#PC#ROCKET#POK\eacute{}#... |
1172 | 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] | 1274 | 7635- | Menu options for selected Pok\eacute{}mon (Includes names of out-of-battle moves). | Variable-length strings separated by 0x50. | CUT [0x50] FLY [0x50] SURF [0x50] STRENGTH [0x50] FLASH [0x50] DIG [0x50] TELEPORT [0x50] SOFTBOILED [0x50] STATS [newline] SWITCH [newline] CANCEL [0x50] |
1173 | 7AF0-8000 | (empty space) | | 0 0 0 0 0 ... | 1275 | 7AF0-8000 | (empty space) | | 0 0 0 0 0 ... |
1174 | 0822E-082F? | Pointers to background music, part I. | | | 1276 | 0822E-082F? | Pointers to background music, part I. | | |
1175 | 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). | 1277 | 0CB95- | Pointers to lists of wild pokemon to encounter in each region. These lists begin at 04D89, see above. | Each pointer is a low-byte, high-byte pair. | The first entry is 0x89 0x4D, corresponding to the address 0x4D89, the location of the first list of wild Pok\eacute{}mon (see 04D89, above). |
1176 |-----------------------+-----------------+-----------------+-----------------| 1278 |-----------------------+-----------------+-----------------+-----------------|
1177 | 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 | 1279 | 0DACB. | Amount of HP restored by Soda Pop | The HP consists of a single numerical byte. | 60 |
1280 | 0DACF. | Amount of HP restored by Lemonade | " | 80 |
1281 | 0DAD5. | Amount of HP restored by Fresh Water | " | 50 |
1282 | 0DADB. | Amount of HP restored by Hyper Potion. | " | 200 |
1178 | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 | 1283 | 0DAE0. | Amount of HP restored by Super Potion. | " | 50 |
1179 | 0DAE3. | Amount of HP restored by Potion. | " | 20 | 1284 | 0DAE3. | Amount of HP restored by Potion. | " | 20 |
1180 |-----------------------+-----------------+-----------------+-----------------| 1285 |-----------------------+-----------------+-----------------+-----------------|
1181 | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# | 1286 | 0DD4D-DD72 | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# |
1287 |-----------------------+-----------------+-----------------+-----------------|
1288 | 0DE2F. | Duration of Repel. | A single byte, representing the number of steps you can take before Super Repel wears off. | 100 |
1289 | 0DF39. | Duration of Super Repel. | " | 200 |
1290 | 0DF3E. | Duration of Max Repel. | " | 250 |
1291 |-----------------------+-----------------+-----------------+-----------------|
1182 | 1164B- | Terminology for the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | TYPE1[newline]TYPE2[newline] *№*,[newline]OT,[newline][0x50]STATUS,[0x50]OK | 1292 | 1164B- | Terminology for the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | TYPE1[newline]TYPE2[newline] *№*,[newline]OT,[newline][0x50]STATUS,[0x50]OK |
1183 | 116DE- | Terminology for permanent stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | ATTACK[newline]DEFENSE[newline]SPEED[newline]SPECIAL[0x50] | 1293 | 116DE- | Terminology for permanent stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | ATTACK[newline]DEFENSE[newline]SPEED[newline]SPECIAL[0x50] |
1184 | 11852- | Terminology for current stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | EXP POINTS[newline]LEVEL UP[0x50] | 1294 | 11852- | Terminology for current stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | EXP POINTS[newline]LEVEL UP[0x50] |
1185 | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# | 1295 | 1195C-1196A | The two terms for being able/unable to learn a TM/HM. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1186 | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# | 1296 | 119C0-119CE | The two terms for being able/unable to evolve using the current stone. | Variable-length strings separated by 0x50. | ABLE#NOT ABLE# |
1212 | 40370-40386 | Important constants for Pok\eacute{}dex entries | | HT _ _ *?′??″* [newline] WT _ _ _ *???* lb [0x50] *POK\Eacute{}* [0x50] | 1322 | 40370-40386 | Important constants for Pok\eacute{}dex entries | | HT _ _ *?′??″* [newline] WT _ _ _ *???* lb [0x50] *POK\Eacute{}* [0x50] |
1213 | 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). | 1323 | 40687-41072 | Species data from the Pok\eacute{}dex: species name, height, weight, etc. | Variable-length species names, followed by 0x50, followed by fixed-length height/weight/etc. data. | The first entry is (*146 132 132 131*, 80, *2 4*, *150 0*, 23, 0 64 46, 80), which are the the stats of Bulbasaur: the first entry spells "SEED", then 0x80, then the height (2' 4"), then the weight (formatted as a low-high byte pair), then various Pokédex pointer data (see elsewhere). |
1214 | 41072- | Pok\eacute{} placeholder species, "???" | | | 1324 | 41072- | Pok\eacute{} placeholder species, "???" | | |
1215 |-----------------------+-----------------+-----------------+-----------------| 1325 |-----------------------+-----------------+-----------------+-----------------|
1216 | 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. | 1326 | 410B1-4116F | A conversion table between internal order and Pokedex order. | 190 bytes, corresponding to the Pok\eacute{}dex numbers of the 190 Pok\eacute{}mon listed in internal order. All =MISSINGNO.= are assigned a Pok\eacute{}dex number of 0. | The first few entries are (112 115 32 35 21 100 34 80 2 ...), which are the Pok\eacute{}dex numbers of Rhydon, Kangaskhan, Nidoran(m), Clefairy, Spearow, Voltorb, Nidoking, Slobrow, and Ivysaur. |
1327 |-----------------------+-----------------+-----------------+-----------------|
1328 | 509B4-509E0 | Saffron City's adjacency info. | Four adjacency lists, each 11 bytes long. (For more info on adjacency lists a.k.a. connection data, see [[http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes][here]]) | The first adjacency list is (0x10 0x70 0x46 0xF0 0xC6 0x0A 0x0A 0x23 0xF6 0x09 0xC8) |
1329 |-----------------------+-----------------+-----------------+-----------------|
1217 | 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 | 1330 | 527BA-527DB | The costs and kinds of prizes from Celadon Game Corner. | The following pattern repeats three times, once per window[fn::For the first two prize lists, ids are interpreted as Pok\eacute{}mon ids. For the last prize list, ids are (somehow) interpreted as item ids.]: Internal ids / 0x50 / Prices (two bytes of BCD)/ 0x50. | (0x94 0x52 0x65 0x50) Abra Vulpix Wigglytuff (0x02 0x30 0x10 0x00 0x26 0x80) 230C, 1000C, 2680C |
1218 | 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]... | 1331 | 5DE10-5DE30 | Abbreviations for status ailments. | Fixed-length strings, probably[fn::Here's something strange: all of the status messages start with 0x7F and end with 0x4F \mdash{}except PAR, which ends with 0x50.]. The last entry is QUIT##. | [0x7F] *SLP* [0x4E][0x7F] *PSN* [0x4E][0x7F] *PAR* [0x50][0x7F]... |
1219 |-----------------------+-----------------+-----------------+-----------------| 1332 |-----------------------+-----------------+-----------------+-----------------|
1220 | 70295- | Hall of fame | The text "HALL OF FAME" | | 1333 | 70295- | Hall of fame | The text "HALL OF FAME" | |
1221 | 70442- | Play time/money | The text "PLAY TIME [0x50] MONEY" | | 1334 | 70442- | Play time/money | The text "PLAY TIME [0x50] MONEY" | |
1768 ;; - 05+ are glitch states in which you are sort of the Pokemon. 1881 ;; - 05+ are glitch states in which you are sort of the Pokemon.
1769 1882
1770 1883
1771 ;; note: 0x251A (in indexable mem): image decompression routine seems to begin here. 1884 ;; note: 0x251A (in indexable mem): image decompression routine seems to begin here.
1772 1885
1886 ;; note: 0x4845 (index): vending inventory is loaded here. possibly
1887 ;; other things, too.
1888 (comment
1889 ;; temporarily intercept/adjust what pops out of the vending
1890 ;; machine.
1891 ;; (and how much it costs)
1892
1893 ;; located at 0x4845
1894 ;; not to be confused with shop inventory, 0xCF7B
1895 (do
1896 (step (read-state "vend-menu"))
1897 (write-memory! (rewrite-memory (vec(memory)) 0x4845 [2 0 1 0]))
1898 (step @current-state [:a])
1899 (step @current-state [])
1900 (nstep @current-state 200) ))
1901
1773 1902
1774 ;; Note: There are two tile tables, one from 8000-8FFF, the other from 1903 ;; Note: There are two tile tables, one from 8000-8FFF, the other from
1775 ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end. 1904 ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end.
1776 (defn print-pixel-letters! 1905 (defn print-pixel-letters!
1777 "The pixel tiles representing letters. Neat!" 1906 "The pixel tiles representing letters. Neat!"
1868 index-next 1997 index-next
1869 (inc index-next) 1998 (inc index-next)
1870 index-next 1999 index-next
1871 codes 2000 codes
1872 matches)))) 2001 matches))))
1873 2002
1874 2003
2004 (def script-use-ball
2005 [0xFA ;; ld A, nn
2006 \_
2007 \_
2008 0xA7 ;; and A
2009 0xCA ;; JP Z
2010 \_
2011 \_
2012 0x3D ;; dec A
2013 0xC2 ;; JP NZ
2014 \_
2015 \_
2016 0xFA ;; LD A
2017 \_
2018 \_
2019 ])
2020
2021
2022
2023 (defn search-pattern [ptn coll]
2024 (loop
2025 [index 0
2026 to-match ptn
2027 binds {}
2028
2029 next-index 1
2030 match-start 0
2031 matches []]
2032
2033 (cond
2034 (>= index (count coll)) matches
2035 (empty? to-match)
2036 (recur
2037 next-index
2038 ptn
2039 {}
2040 (inc next-index)
2041 next-index
2042 (conj match-start
2043 [(hex match-start) binds]))
2044
2045 :else
2046 (let [k (first to-match)
2047 v (nth coll index)]
2048 (cond
2049 (= k \_) ;; wildcard
2050 (recur
2051 (inc index)
2052 (rest to-match)
2053 binds
2054
2055 next-index
2056 match-start
2057 matches)
2058
2059 (keyword? k)
2060 (if (binds k)
2061 (if (= (binds k) v)
2062 (recur
2063 (inc index)
2064 (rest to-match)
2065 binds
2066 next-index
2067 match-start
2068 matches)
2069
2070 (recur
2071 next-index
2072 ptn
2073 {}
2074 (inc next-index)
2075 next-index
2076 matches))
2077
2078 ;; ;; consistent bindings
2079 ;; (recur
2080 ;; (inc index)
2081 ;; (rest to-match)
2082 ;; binds
2083
2084 ;; next-index
2085 ;; match-start
2086 ;; matches)
2087
2088 ;; ;; inconsistent bindings
2089 ;; (recur
2090 ;; next-index
2091 ;; ptn
2092 ;; {}
2093 ;; (inc next-index)
2094 ;; next-index
2095 ;; matches))
2096
2097 (if ((set (vals binds)) v)
2098 ;; bindings are not unique
2099 (recur
2100 next-index
2101 ptn
2102 {}
2103 (inc next-index)
2104 next-index
2105 matches)
2106
2107 ;; bindings are unique
2108 (recur
2109 (inc index)
2110 (rest to-match)
2111 (assoc binds k v)
2112
2113 next-index
2114 match-start
2115 matches)))
2116
2117 :else ;; k is just a number
2118 (if (= k v)
2119 (recur
2120 (inc index)
2121 (rest to-match)
2122 binds
2123
2124 next-index
2125 match-start
2126 matches)
2127
2128 (recur
2129 next-index
2130 ptn
2131 {}
2132 (inc next-index)
2133 next-index
2134 matches)))))))
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144 (defn search-pattern* [ptn coll]
2145 (loop
2146 [
2147 binds {}
2148 index 0
2149 index-next 1
2150 start-match 0
2151 to-match ptn
2152 matches []]
2153
2154 (cond
2155 (>= index (count coll)) matches
2156 (empty? to-match)
2157 (recur
2158 {}
2159 index-next
2160 (inc index-next)
2161 index-next
2162 ptn
2163 (conj matches
2164 [(hex start-match) binds]))
2165
2166 :else
2167 (let [k (first to-match)
2168 v (nth coll index)]
2169 (cond
2170 (= k \_) ;; wildcard
2171 (recur
2172 binds
2173 (inc index)
2174 index-next
2175 start-match
2176 (rest to-match)
2177 matches)
2178
2179 (keyword? k)
2180 (if (binds k)
2181 (if (= (binds k) v)
2182 (recur
2183 binds
2184 (inc index)
2185 index-next
2186 start-match
2187 (rest to-match)
2188 matches)
2189 (recur
2190 {}
2191 index-next
2192 (inc index-next)
2193 index-next
2194 ptn
2195 matches))
2196 (if
2197 ;; every symbol must be bound to a different thing.
2198 ((set (vals binds)) v)
2199 (recur
2200 {}
2201 index-next
2202 (inc index-next)
2203 index-next
2204 ptn
2205 matches)
2206 (recur
2207 (assoc binds k v)
2208 (inc index)
2209 index-next
2210 start-match
2211 (rest to-match)
2212 matches))))))))
2213
1875 2214
1876 2215
1877 2216
1878 ;; look for the rainbow badge in memory 2217 ;; look for the rainbow badge in memory
1879 (println (reduce str (map #(str (first %) "\t" (vec(second %)) "\n") (search-memory (rom) [221] 10)))) 2218 (println (reduce str (map #(str (first %) "\t" (vec(second %)) "\n") (search-memory (rom) [221] 10))))