diff 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
line wrap: on
line diff
     1.1 --- a/org/rom.org	Sat Apr 14 05:20:28 2012 -0500
     1.2 +++ b/org/rom.org	Sat Apr 14 09:27:49 2012 -0500
     1.3 @@ -1094,7 +1094,7 @@
     1.4  #+begin_src clojure
     1.5  (def hxc-places
     1.6    "The hardcoded place names in memory. List begins at
     1.7 -ROM@71500. [Cinnabar/Cerulean] Mansion seems to be dynamically calculated."
     1.8 +ROM@71500. [Cinnabar/Celadon] Mansion seems to be dynamically calculated."
     1.9    (hxc-thunk-words 0x71500 560))
    1.10  #+end_src
    1.11  
    1.12 @@ -1148,9 +1148,111 @@
    1.13  
    1.14  
    1.15  
    1.16 +** Map data
    1.17 +
    1.18 +# http://www.pokecommunity.com/showthread.php?t=235311
    1.19 +# http://datacrystal.romhacking.net/wiki/Pokemon_Red/Blue:Notes
    1.20 +
    1.21 +#+name map
    1.22 +#+begin_src clojure :exports both :results output 
    1.23 +(ns com.aurellem.gb.hxc
    1.24 +  (:use (com.aurellem.gb assembly characters gb-driver util mem-util
    1.25 +                         constants))
    1.26 +  (:import [com.aurellem.gb.gb_driver SaveState]))
    1.27 +
    1.28 +
    1.29 +(defn parse-header-tileset
    1.30 +  [[bank#     ;; memory bank for blocks & tileset 
    1.31 +    
    1.32 +    blocks-lo ;; structure
    1.33 +    blocks-hi
    1.34 +    
    1.35 +    tileset-lo ;; style
    1.36 +    tileset-hi
    1.37 +    
    1.38 +      collision-lo ;; collision info
    1.39 +    collision-hi
    1.40 +    
    1.41 +    talk-here-1 ;; positions of up to three
    1.42 +    talk-here-2 ;; talk-over-countertop tiles
    1.43 +    talk-here-3 ;; --- 0xFF if unused.
    1.44 +    
    1.45 +    grass ;; grass tile --- 0xFF if unused
    1.46 +    
    1.47 +    animation-flags ;; settings for animation
    1.48 +    & _]]
    1.49 +  
    1.50 +  [bank#
    1.51 +   
    1.52 +   blocks-lo ;; structure
    1.53 +   blocks-hi
    1.54 +   
    1.55 +   tileset-lo ;; style
    1.56 +   tileset-hi
    1.57 +   
    1.58 +   collision-lo ;; collision info
    1.59 +   collision-hi
    1.60 +   
    1.61 +   talk-here-1 ;; positions of up to three
    1.62 +   talk-here-2 ;; talk-over-countertop tiles
    1.63 +   talk-here-3 ;; --- 0xFF if unused.
    1.64 +   
    1.65 +   grass ;; grass tile --- 0xFF if unused
    1.66 +   
    1.67 +   animation-flags ;; settings for animation
    1.68 +   ])
    1.69 +
    1.70 +
    1.71 +
    1.72 +(defn parse-header-map
    1.73 +  [start]
    1.74 +
    1.75 +  (let [connection-size 11
    1.76 +
    1.77 +        [tileset-index
    1.78 +         map-height
    1.79 +         map-width
    1.80 +         layout-lo
    1.81 +         layout-hi
    1.82 +         text-lo
    1.83 +         text-hi
    1.84 +         script-lo
    1.85 +         script-hi
    1.86 +         adjacency-flags ;; x x x x N S W E
    1.87 +         & etc]
    1.88 +        (drop start (rom))
    1.89 +
    1.90 +        [east? west? south? north?]
    1.91 +        (bit-list adjacency-flags)
    1.92 +
    1.93 +        [connections object-data]
    1.94 +        (split-at
    1.95 +         (* connection-size (+ east? west? south? north?))
    1.96 +         etc)
    1.97 +
    1.98 +        connections
    1.99 +        (partition connection-size connections)
   1.100 +        
   1.101 +
   1.102 +
   1.103 +
   1.104 +        ]
   1.105 +    (ptr->offset
   1.106 +     3
   1.107 +     (low-high layout-lo layout-hi))
   1.108 +    
   1.109 +
   1.110 +    ))
   1.111 +#+end_src
   1.112 +
   1.113 +#+results:
   1.114 +: 
   1.115 +
   1.116 +
   1.117  
   1.118  * Appendices
   1.119  ** Mapping the ROM
   1.120 +# D3AD: Script:Use Pokeball?
   1.121  
   1.122  | ROM address (hex)     | Description     | Format          | Example         |
   1.123  |-----------------------+-----------------+-----------------+-----------------|
   1.124 @@ -1174,11 +1276,19 @@
   1.125  | 0822E-082F?           | Pointers to background music, part I. |                 |                 |
   1.126  | 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). |
   1.127  |-----------------------+-----------------+-----------------+-----------------|
   1.128 -| 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             |
   1.129 +| 0DACB.                | Amount of HP restored by Soda Pop | The HP consists of a single numerical byte. | 60              |
   1.130 +| 0DACF.                | Amount of HP restored by Lemonade | "               | 80              |
   1.131 +| 0DAD5.                | Amount of HP restored by Fresh Water | "               | 50              |
   1.132 +| 0DADB.                | Amount of HP restored by Hyper Potion. | "               | 200             |
   1.133  | 0DAE0.                | Amount of HP restored by Super Potion. | "               | 50              |
   1.134  | 0DAE3.                | Amount of HP restored by Potion. | "               | 20              |
   1.135  |-----------------------+-----------------+-----------------+-----------------|
   1.136  | 0DD4D-DD72            | Names of permanent stats. | Variable-length strings separated by 0x50. | #HEALTH#ATTACK#DEFENSE#SPEED#SPECIAL# |
   1.137 +|-----------------------+-----------------+-----------------+-----------------|
   1.138 +| 0DE2F.                | Duration of Repel. | A single byte, representing the number of steps you can take before Super Repel wears off. | 100             |
   1.139 +| 0DF39.                | Duration of Super Repel. | "               | 200             |
   1.140 +| 0DF3E.                | Duration of Max Repel. | "               | 250             |
   1.141 +|-----------------------+-----------------+-----------------+-----------------|
   1.142  | 1164B-                | Terminology for the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | TYPE1[newline]TYPE2[newline] *№*,[newline]OT,[newline][0x50]STATUS,[0x50]OK |
   1.143  | 116DE-                | Terminology for permanent stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | ATTACK[newline]DEFENSE[newline]SPEED[newline]SPECIAL[0x50] |
   1.144  | 11852-                | Terminology for current stats in the Pok\eacute{}mon menu. | Contiguous, variable-length strings. | EXP POINTS[newline]LEVEL UP[0x50] |
   1.145 @@ -1214,6 +1324,9 @@
   1.146  | 41072-                | Pok\eacute{} placeholder species, "???" |                 |                 |
   1.147  |-----------------------+-----------------+-----------------+-----------------|
   1.148  | 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. |
   1.149 +|-----------------------+-----------------+-----------------+-----------------|
   1.150 +| 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) |
   1.151 +|-----------------------+-----------------+-----------------+-----------------|
   1.152  | 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 |
   1.153  | 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]... |
   1.154  |-----------------------+-----------------+-----------------+-----------------|
   1.155 @@ -1770,6 +1883,22 @@
   1.156  
   1.157  ;; note: 0x251A (in indexable mem): image decompression routine seems to begin here.
   1.158  
   1.159 +;; note: 0x4845 (index): vending inventory is loaded here. possibly
   1.160 +   ;; other things, too.
   1.161 +(comment
   1.162 +  ;; temporarily intercept/adjust what pops out of the vending
   1.163 +  ;; machine.
   1.164 +  ;; (and how much it costs)
   1.165 +
   1.166 +  ;; located at 0x4845
   1.167 +  ;; not to be confused with shop inventory, 0xCF7B
   1.168 +  (do 
   1.169 +    (step (read-state "vend-menu"))
   1.170 +    (write-memory! (rewrite-memory (vec(memory)) 0x4845 [2 0 1 0]))
   1.171 +    (step @current-state [:a])
   1.172 +    (step @current-state [])
   1.173 +    (nstep @current-state 200) ))
   1.174 +
   1.175  
   1.176  ;; Note: There are two tile tables, one from 8000-8FFF, the other from
   1.177  ;; 8800-97FF. The latter contains symbols, possibly map tiles(?), with some japanese chars and stuff at the end. 
   1.178 @@ -1870,8 +1999,218 @@
   1.179         index-next
   1.180         codes
   1.181         matches))))
   1.182 -      
   1.183 -      
   1.184 +
   1.185 +
   1.186 +(def script-use-ball
   1.187 +  [0xFA ;; ld A, nn
   1.188 +   \_
   1.189 +   \_
   1.190 +   0xA7 ;; and A
   1.191 +   0xCA ;; JP Z
   1.192 +   \_
   1.193 +   \_
   1.194 +   0x3D ;; dec A
   1.195 +   0xC2 ;; JP NZ
   1.196 +   \_
   1.197 +   \_
   1.198 +   0xFA ;; LD A
   1.199 +   \_
   1.200 +   \_
   1.201 +   ])
   1.202 +
   1.203 +
   1.204 +
   1.205 +(defn search-pattern [ptn coll]
   1.206 +  (loop
   1.207 +      [index 0
   1.208 +       to-match ptn
   1.209 +       binds {}
   1.210 +
   1.211 +       next-index 1
   1.212 +       match-start 0
   1.213 +       matches []]
   1.214 +
   1.215 +    (cond
   1.216 +        (>= index (count coll)) matches
   1.217 +        (empty? to-match)
   1.218 +        (recur
   1.219 +         next-index
   1.220 +         ptn
   1.221 +         {}
   1.222 +         (inc next-index)
   1.223 +         next-index
   1.224 +         (conj match-start
   1.225 +               [(hex match-start) binds]))
   1.226 +
   1.227 +        :else
   1.228 +        (let [k (first to-match)
   1.229 +              v (nth coll index)]
   1.230 +        (cond
   1.231 +          (= k \_) ;; wildcard
   1.232 +          (recur
   1.233 +           (inc index)
   1.234 +           (rest to-match)
   1.235 +           binds
   1.236 +
   1.237 +           next-index
   1.238 +           match-start
   1.239 +           matches)
   1.240 +
   1.241 +          (keyword? k)
   1.242 +          (if (binds k)
   1.243 +            (if (= (binds k) v)
   1.244 +              (recur
   1.245 +               (inc index)
   1.246 +               (rest to-match)
   1.247 +               binds
   1.248 +               next-index
   1.249 +               match-start
   1.250 +               matches)
   1.251 +
   1.252 +              (recur
   1.253 +               next-index
   1.254 +               ptn
   1.255 +               {}
   1.256 +               (inc next-index)
   1.257 +               next-index
   1.258 +               matches))
   1.259 +              
   1.260 +              ;; ;; consistent bindings
   1.261 +              ;; (recur
   1.262 +              ;;  (inc index)
   1.263 +              ;;  (rest to-match)
   1.264 +              ;;  binds
   1.265 +
   1.266 +              ;;  next-index
   1.267 +              ;;  match-start
   1.268 +              ;;  matches)
   1.269 +
   1.270 +              ;; ;; inconsistent bindings
   1.271 +              ;; (recur
   1.272 +              ;;  next-index
   1.273 +              ;;  ptn
   1.274 +              ;;  {}
   1.275 +              ;;  (inc next-index)
   1.276 +              ;;  next-index
   1.277 +              ;;  matches))
   1.278 +              
   1.279 +            (if ((set (vals binds)) v)
   1.280 +              ;; bindings are not unique
   1.281 +              (recur
   1.282 +               next-index
   1.283 +               ptn
   1.284 +               {}
   1.285 +               (inc next-index)
   1.286 +               next-index
   1.287 +               matches)
   1.288 +
   1.289 +              ;; bindings are unique
   1.290 +              (recur
   1.291 +               (inc index)
   1.292 +               (rest to-match)
   1.293 +               (assoc binds k v)
   1.294 +
   1.295 +               next-index
   1.296 +               match-start
   1.297 +               matches)))
   1.298 +
   1.299 +          :else ;; k is just a number
   1.300 +          (if (= k v)
   1.301 +            (recur
   1.302 +             (inc index)
   1.303 +             (rest to-match)
   1.304 +             binds
   1.305 +
   1.306 +             next-index
   1.307 +             match-start
   1.308 +             matches)
   1.309 +
   1.310 +            (recur
   1.311 +             next-index
   1.312 +             ptn
   1.313 +             {}
   1.314 +             (inc next-index)
   1.315 +             next-index
   1.316 +             matches)))))))
   1.317 +
   1.318 +            
   1.319 +            
   1.320 +
   1.321 +              
   1.322 +
   1.323 +
   1.324 +
   1.325 +
   1.326 +(defn search-pattern* [ptn coll]
   1.327 +  (loop
   1.328 +      [
   1.329 +       binds {}
   1.330 +       index 0
   1.331 +       index-next 1
   1.332 +       start-match 0
   1.333 +       to-match ptn
   1.334 +       matches []]
   1.335 +
   1.336 +    (cond
   1.337 +        (>= index (count coll)) matches
   1.338 +        (empty? to-match)
   1.339 +        (recur
   1.340 +         {}
   1.341 +         index-next
   1.342 +         (inc index-next)
   1.343 +         index-next
   1.344 +         ptn
   1.345 +         (conj matches
   1.346 +               [(hex start-match) binds]))
   1.347 +
   1.348 +        :else
   1.349 +        (let [k (first to-match)
   1.350 +              v (nth coll index)]
   1.351 +        (cond
   1.352 +          (= k \_) ;; wildcard
   1.353 +          (recur
   1.354 +           binds
   1.355 +           (inc index)
   1.356 +           index-next
   1.357 +           start-match
   1.358 +           (rest to-match)
   1.359 +           matches)
   1.360 +
   1.361 +          (keyword? k)
   1.362 +          (if (binds k)
   1.363 +            (if (= (binds k) v)
   1.364 +              (recur
   1.365 +               binds
   1.366 +               (inc index)
   1.367 +               index-next
   1.368 +               start-match
   1.369 +               (rest to-match)
   1.370 +               matches)
   1.371 +              (recur
   1.372 +               {}
   1.373 +               index-next
   1.374 +               (inc index-next)
   1.375 +               index-next
   1.376 +               ptn
   1.377 +               matches))
   1.378 +            (if
   1.379 +                ;; every symbol must be bound to a different thing.
   1.380 +              ((set (vals binds)) v)
   1.381 +              (recur
   1.382 +               {}
   1.383 +               index-next
   1.384 +               (inc index-next)
   1.385 +               index-next
   1.386 +               ptn
   1.387 +               matches)
   1.388 +              (recur
   1.389 +               (assoc binds k v)
   1.390 +               (inc index)
   1.391 +               index-next
   1.392 +               start-match
   1.393 +               (rest to-match)
   1.394 +               matches))))))))
   1.395 +             
   1.396  
   1.397  
   1.398