changeset 372:998702f021e3

merged changes
author Dylan Holmes <ocsenave@gmail.com>
date Mon, 09 Apr 2012 01:44:19 -0500
parents b477970d0b7a (current diff) 8d8023057b3c (diff)
children a6f212ae29a3
files org/rom.org
diffstat 30 files changed, 962 insertions(+), 191 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/exp/cartography	Mon Apr 09 01:40:26 2012 -0500
     1.2 +++ b/clojure/com/aurellem/exp/cartography	Mon Apr 09 01:44:19 2012 -0500
     1.3 @@ -505,14 +505,14 @@
     1.4  D35A                                               Q
     1.5  D35B                                               T
     1.6  D35C                                               Q
     1.7 -D35D                   BEGIN MAP DATA              T
     1.8 +D35D                  BEGIN MAP DATA (current-map) T
     1.9  D35E                                               Q
    1.10  D35F                                               T
    1.11  D360                                               Q
    1.12  D361                   Player Offset X             T
    1.13  D362                   Player Offset Y             Q
    1.14  D363                                               T
    1.15 -D364                                               Q
    1.16 +D364                   FLOOR MAT WARP DESTINATION  Q
    1.17  D365                                               T
    1.18  D366                                               Q
    1.19  D367                                               T
     2.1 --- a/clojure/com/aurellem/exp/item_bridge.clj	Mon Apr 09 01:40:26 2012 -0500
     2.2 +++ b/clojure/com/aurellem/exp/item_bridge.clj	Mon Apr 09 01:44:19 2012 -0500
     2.3 @@ -220,11 +220,6 @@
     2.4      0x55
     2.5      ]))
     2.6  
     2.7 -
     2.8 -
     2.9 -(def pc-item-list-start 0xD539)
    2.10 -(def pc-item-list-width 101)
    2.11 -
    2.12  (def corrupted-items-width 512)
    2.13  
    2.14  (defn items-record
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/clojure/com/aurellem/exp/warp.clj	Mon Apr 09 01:44:19 2012 -0500
     3.3 @@ -0,0 +1,289 @@
     3.4 +(ns com.aurellem.exp.warp
     3.5 +  (:use (com.aurellem.gb gb-driver vbm items util saves))
     3.6 +  (:use (com.aurellem.run util))
     3.7 +  (:import [com.aurellem.gb.gb_driver SaveState]))
     3.8 +
     3.9 +
    3.10 +;; special thanks to http://tasvideos.org/2913S.html for revealing
    3.11 +;; 0xD364 as the floor-map warp location
    3.12 +
    3.13 +
    3.14 +(def mat-warp-address 0xD364)
    3.15 +
    3.16 +(defn view-warp-id [warp-id]
    3.17 +  (->> 
    3.18 +   [[] (set-memory (at-mat) mat-warp-address warp-id)]
    3.19 +   (do-nothing 20)
    3.20 +   (play-moves [↓])
    3.21 +   (do-nothing 100)))
    3.22 +
    3.23 +(defn iterate-locations [start]
    3.24 +  (dorun
    3.25 +   (map 
    3.26 +    #(do
    3.27 +       (printf "0x%02X\n" %)
    3.28 +       (view-warp-id %)
    3.29 +       (Thread/sleep 10000))
    3.30 +    (range start (inc 0xFF)))))
    3.31 +        
    3.32 +
    3.33 +(comment
    3.34 +0x00    pallet-town-home
    3.35 +0x01    viridian-poke-center
    3.36 +0x02    pewter-science-meuseum
    3.37 +0x03    cereluan-dig-house
    3.38 +0x04    lavender-town-poke-center
    3.39 +0x05    vermillion-poke-center
    3.40 +0x06    celedon-department-store            !!!!!!!!!!!
    3.41 +0x07    fuchia-mart
    3.42 +0x08    cinnibar-mansion
    3.43 +0x09    elite-four-HQ
    3.44 +0x0A    saffron-mimic-house
    3.45 +0x0B    CRASHING GLITCH
    3.46 +0x0C    route-1-inside-junk
    3.47 +0x0D    diglett-cave-vermillion-side
    3.48 +0x0E    GLITCH
    3.49 +0x0F    poke-center-outside-mt-moon
    3.50 +0x10    cereullean->saffron
    3.51 +0x11    GLITCH
    3.52 +0x12    saffron->celadon
    3.53 +0x13    saffron->lavendar
    3.54 +0x14    GLITCH 
    3.55 +0x15    poke-center-by-rock-tunnel
    3.56 +0x16    vermillion->lavender
    3.57 +0x17    lavender->fuchia
    3.58 +0x18    GLITCH
    3.59 +0x19    GLITCH
    3.60 +0x1A    unknown
    3.61 +0x1B    cycling-road->celadon
    3.62 +0x1C    GLITCH
    3.63 +0x1D    cycling-road->fuschia
    3.64 +0x1E    surfing-house
    3.65 +0x1F    seafom-island-cinnabar-side
    3.66 +0x20    GLITCH
    3.67 +0x21    indigo-plateu-gate
    3.68 +0x22    plateau-path-start
    3.69 +0x23    GLITCH
    3.70 +0x24    bills-house
    3.71 +0x25    house-again
    3.72 +0x26    stairs-to-house
    3.73 +0x27    gary's-house
    3.74 +0x28    oak's-lab
    3.75 +0x29    poke-center-unknown
    3.76 +0x2A    inside-viridian-mart
    3.77 +0x2B    viridian-school-house
    3.78 +0x2C    unknown
    3.79 +0x2D    viridian-gym
    3.80 +0x2E    diglett's-cave-unknown-side
    3.81 +0x2F    glitched-viridian-forest-entrance
    3.82 +0x30    unknown
    3.83 +0x31    unknown
    3.84 +0x32    unknown
    3.85 +0x33    viridian-forest-pewter-side
    3.86 +0x34    pewter-meuseum-first-floor
    3.87 +0x35    pweter-meuseum-second-floor
    3.88 +0x36    pewter-gym
    3.89 +0x37    unknown-house
    3.90 +0x38    unknown-mart
    3.91 +0x39    unknown-house
    3.92 +0x3A    inside-pewter-poke-center
    3.93 +0x3B    inside-mt-moon-entrance
    3.94 +0x3C    mt-moon-unknown
    3.95 +0x3D    mt-moon-unknown
    3.96 +0x3E    inside-dig-house-cereulan?
    3.97 +0x3F    inside-bulbasaur-house-cerulean
    3.98 +0x40    unknown-poke-center
    3.99 +0x41    cereulan-gym
   3.100 +0x42    inside-bike-shop
   3.101 +0x43    unknown-mart
   3.102 +0x44    unknown-poke-center
   3.103 +0x45    inside-dig-house-cereulan?
   3.104 +0x46    unknown-guard-path
   3.105 +0x47    unknown-undeground-path-entrance
   3.106 +0x48    unknown-house
   3.107 +0x49    unknown-undeground-path-entrance
   3.108 +0x4A    unknown-undeground-path-entrance
   3.109 +0x4B    unknown-undeground-path-entrance
   3.110 +0x4C    unknown-guard-path
   3.111 +0x4D    unknown-undeground-path-entrance
   3.112 +0x4E    unknown-undeground-path-entrance
   3.113 +0x4F    unknown-guard-path
   3.114 +0x50    unknown-undeground-path-entrance
   3.115 +0x51    unknown-poke-center
   3.116 +0x52    mt-moon-unknown
   3.117 +0x53    inside-power-plant-start
   3.118 +0x54    unknown-guard-path
   3.119 +0x55    diglet's-cave-vermillion-entrange
   3.120 +0x56    unknown-2nd-floor-guard-path
   3.121 +0x57    unknown-guard-path
   3.122 +0x58    inside-bill's-house
   3.123 +0x59    unknown-poke-center
   3.124 +0x5A    inside-pokemon-fan-club
   3.125 +0x5B    unknown-mart
   3.126 +0x5C    unknown-gym?
   3.127 +0x5D    unknown-house
   3.128 +0x5E    s.s.anne-catwalk
   3.129 +0x5F    s.s.anne-entrance
   3.130 +0x60    unknown-ss-anne-door
   3.131 +0x61    unknown-ss-anne
   3.132 +0x62    unknown-ss-anne
   3.133 +0x63    ss-anne-bow
   3.134 +0x64    ss-anne-cafeteria
   3.135 +0x65    ss-anne-inside-captian's-room
   3.136 +0x66    ss-anne-inside-room
   3.137 +0x67    ss-anne-inside-room
   3.138 +0x68    ss-anne-inside-room
   3.139 +0x69    CRASHING GLITCH
   3.140 +0x6A    CRASHING GLITCH
   3.141 +0x6B    CRASHING GLITCH
   3.142 +0x6C    moltres-cave-entrance
   3.143 +0x6D    CRASHING GLITCH
   3.144 +0x6E    CRASHING GLITCH
   3.145 +0x6F    CRASHING GLITCH
   3.146 +0x70    CRASHING GLITCH
   3.147 +0x71    unknown-ss-anne
   3.148 +0x72    CRASHING GLITCH
   3.149 +0x73    CRASHING GLITCH
   3.150 +0x74    CRASHING GLITCH
   3.151 +0x75    CRASHING GLITCH
   3.152 +0x76    elite-four-hall-of-fame
   3.153 +0x77    unknown-inside-underground-tunnel
   3.154 +0x78    unknown
   3.155 +0x79    unknown-inside-underground-tunnel
   3.156 +0x7A    unknown
   3.157 +0x7B    unknown-celadon-dept-store-floor                    !
   3.158 +0x7C    unknown-celadon-dept-store-floor                    !
   3.159 +0x7D    unknown-celadon-dept-store-floor                    !
   3.160 +0x7E    celedon-dept-roof                                   !
   3.161 +0x7F    celadon-dept-elevator
   3.162 +0x80    celadon-pokemon-mansion-first-floor
   3.163 +0x81    celadon-pokemon-mansion-second-floor
   3.164 +0x82    celadon-pokemon-mansion-third-floor(computers)
   3.165 +0x83    celadon-pokemon-mansion-boring-roof
   3.166 +0x84    celadon-pokemon-mansion-eevee-room
   3.167 +0x85    unknown-poke-center
   3.168 +0x86    inside-celadon-gym
   3.169 +0x87    inside-celadon-game-corner
   3.170 +0x88    unknown-celadon-dept-store-floor                    !
   3.171 +0x89    celadon-game-corner-prize-claim
   3.172 +0x8A    celadon-cafeteria
   3.173 +0x8B    celadon-rocket-house
   3.174 +0x8C    unknown-poke-center (maybe celadon?)
   3.175 +0x8D    unknown-poke-venter (maybe celadon hotel?)
   3.176 +0x8E    unknown-pokemon-tower
   3.177 +0x8F    unknown-pokemon-tower
   3.178 +0x90    unknown-pokemon-tower
   3.179 +0x91    unknown-pokemon-tower
   3.180 +0x92    unknown-pokemon-tower
   3.181 +0x93    unknown-pokemon-tower
   3.182 +0x94    unknown-pokemon-tower
   3.183 +0x95    inside-fiji's-house
   3.184 +0x96    unknown-mart
   3.185 +0x97    unknown-house
   3.186 +0x98    unknown-mart
   3.187 +0x99    unknown-house
   3.188 +0x9A    unknown-poke-center
   3.189 +0x9B    inside-game-warden's-house
   3.190 +0x9C    inside-safari-zone-gate
   3.191 +0x9D    vermillion-gym
   3.192 +0x9E    unknown-fuscia
   3.193 +0x9F    unknown-cave
   3.194 +0xA0    unknown-cave
   3.195 +0xA1    unknown-moltres-cave
   3.196 +0xA2    unknown-seafoam-cave
   3.197 +0xA3    unknown-fishing-guru-house
   3.198 +0xA4    cereulan-house
   3.199 +0xA5    cinibar-mansion-first-floor
   3.200 +0xA6    saffron-gym
   3.201 +0xA7    cinibar-fossil-regen-lab-entrance
   3.202 +0xA8    unknown-house
   3.203 +0xA9    cinibar-fossil-regen-room
   3.204 +0xAA    cinibar-fossil-regen-regen-room
   3.205 +0xAB    unknown-poke-center
   3.206 +0xAC    unknown-mart
   3.207 +0xAD    unknown-mart
   3.208 +0xAE    eilte-four-poke-center
   3.209 +0xAF    glitched-house
   3.210 +0xB0    mimic's-room
   3.211 +0xB1    inside-fighting-dojo
   3.212 +0xB2    saffron-gym
   3.213 +0xB3    unknown-house (lavender?)
   3.214 +0xB4    unknown-mart
   3.215 +0xB5    sliph-co-first-floor
   3.216 +0xB6    unknown-poke-center
   3.217 +0xB7    unknown-house
   3.218 +0xB8    unknown-guard-path
   3.219 +0xB9    unknown-guard-path-2nd-floor
   3.220 +0xBA    unknown-guard-path
   3.221 +0xBB    unknown-guard-path-2nd-floor
   3.222 +0xBC    unknown-house
   3.223 +0xBD    unknown-house (fishing guru?)
   3.224 +0xBE    unknown-guard-path
   3.225 +0xBF    unknown-guard-path-2nd-floor
   3.226 +0xC0    unknown-cave
   3.227 +0xC1    elite-four-gate-entrance
   3.228 +0xC2    unknown-moltres-cave
   3.229 +0xC3    unknown-guard-path-2nd-floor
   3.230 +0xC4    unknown-house
   3.231 +0xC5    unknown-cave
   3.232 +0xC6    unknown-moltres-cave
   3.233 +0xC7    unknown-game-corner
   3.234 +0xC8    unknown-game-corner
   3.235 +0xC9    unknown-game-corner
   3.236 +0xCA    unknown-game-corner
   3.237 +0xCB    game-corner-elevator
   3.238 +0xCC    GLITCH
   3.239 +0xCD    GLITCH
   3.240 +0xCE    GLITCH
   3.241 +0xCF    unknown-silph-co
   3.242 +0xD0    unknown-silph-co
   3.243 +0xD1    unknown-silph-co
   3.244 +0xD2    unknown-silph-co
   3.245 +0xD3    unknown-silph-co
   3.246 +0xD4    unknown-silph-co
   3.247 +0xD5    unknown-silph-co
   3.248 +0xD6    unknown-cinnibar-mansion
   3.249 +0xD7    unknown-cinnibar-mansion
   3.250 +0xD8    unknown-cinnibar-mansion
   3.251 +0xD9    unknown-safari-zone
   3.252 +0xDA    unknown-safari-zone
   3.253 +0xDB    unknown-safari-zone
   3.254 +0xDC    unknown-safari-zone
   3.255 +0xDD    unknown-safari-zone-rest-room
   3.256 +0xDE    safari-zone-surf-room
   3.257 +0xDF    unknown-safari-zone-rest-room
   3.258 +0xE0    unknown-safari-zone-rest-room
   3.259 +0xE1    unknown-safari-zone-rest-room
   3.260 +0xE2    unknown-mewtwo-cave
   3.261 +0xE3    unknown-mewtwo-cave
   3.262 +0xE4    mewtwo-cave-entrance
   3.263 +0xE5    unknown-house
   3.264 +0xE6    cereulan-badge-description-room
   3.265 +0xE7    CRASHING GLITCH
   3.266 +0xE8    unknown-cave
   3.267 +0xE9    unknown-silph-co
   3.268 +0xEA    unknown-silph-co
   3.269 +0xEB    silph-co-boring-top-floor
   3.270 +0xEC    silph-co-elevator
   3.271 +0xED    GLITCH
   3.272 +0xEE    GLITCH
   3.273 +0xEF    GLITCH
   3.274 +0xF0    GLITCH
   3.275 +0xF1    GLITCH
   3.276 +0xF2    GLITCH
   3.277 +0xF3    GLITCH
   3.278 +0xF4    GLITCH
   3.279 +0xF5    loreli-room
   3.280 +0xF6    bruno-room
   3.281 +0xF7    agatha-room
   3.282 +0xF8    inside-surfing-room
   3.283 +0xF9    GLITCH (dark)
   3.284 +0xFA    GLITCH (dark)
   3.285 +0xFB    CRASHING GLITCH
   3.286 +0xFC    GLITCH (dark)
   3.287 +0xFD    CRASHING GLITCH 
   3.288 +0xFE    CRASHING GLITCH
   3.289 +0xFF    CRASHING GLITCH    
   3.290 +   
   3.291 +
   3.292 +)
   3.293 \ No newline at end of file
     4.1 --- a/clojure/com/aurellem/gb/items.clj	Mon Apr 09 01:40:26 2012 -0500
     4.2 +++ b/clojure/com/aurellem/gb/items.clj	Mon Apr 09 01:44:19 2012 -0500
     4.3 @@ -8,6 +8,9 @@
     4.4    (map char (subvec (vec (memory)) 0x134 0x142)))
     4.5  
     4.6  (def item-list-start 0xD31C)
     4.7 +(def pc-item-list-start 0xD539)
     4.8 +(def pc-item-list-width 101)
     4.9 +
    4.10  
    4.11  (defn item-list
    4.12    ([^SaveState state]
    4.13 @@ -16,7 +19,23 @@
    4.14        item-list-start
    4.15        (+ item-list-start 255)))
    4.16    ([] (item-list @current-state)))
    4.17 -  
    4.18 +
    4.19 +(defn nth-item
    4.20 +  ([^SaveState state n]
    4.21 +     (let [mem (memory state)]
    4.22 +       [(aget mem (+ item-list-start 1 (* 2 n)))
    4.23 +        (aget mem (+ item-list-start 2 (* 2 n)))]))
    4.24 +  ([n] (nth-item @current-state n)))
    4.25 +
    4.26 +
    4.27 +(defn nth-pc-item
    4.28 +  ([^SaveState state n]
    4.29 +     (let [mem (memory state)]
    4.30 +       [(aget mem (+ pc-item-list-start 1 (* 2 n)))
    4.31 +        (aget mem (+ pc-item-list-start 2 (* 2 n)))]))
    4.32 +  ([n] (nth-pc-item @current-state n)))
    4.33 +
    4.34 +
    4.35  (def item-code->item-name
    4.36    (hash-map
    4.37     0x01 :master-ball       
     5.1 --- a/clojure/com/aurellem/gb/saves.clj	Mon Apr 09 01:40:26 2012 -0500
     5.2 +++ b/clojure/com/aurellem/gb/saves.clj	Mon Apr 09 01:44:19 2012 -0500
     5.3 @@ -41,4 +41,6 @@
     5.4  (gen-save cursor-item-3)
     5.5  (gen-save cursor-item-4)
     5.6  (gen-save cursor-item-5)
     5.7 -(gen-save cursor-item-6)
     5.8 \ No newline at end of file
     5.9 +(gen-save cursor-item-6)
    5.10 +
    5.11 +(gen-save at-mat)
    5.12 \ No newline at end of file
     6.1 --- a/clojure/com/aurellem/run/bootstrap_0.clj	Mon Apr 09 01:40:26 2012 -0500
     6.2 +++ b/clojure/com/aurellem/run/bootstrap_0.clj	Mon Apr 09 01:44:19 2012 -0500
     6.3 @@ -397,22 +397,30 @@
     6.4    "Set the quantity of an item to buy or sell to the desired value
     6.5    using the fewest possible button presses."
     6.6    ([total-quantity desired-quantity [moves state :as script]]
     6.7 -     (let [current-quantity (item-quantity-selected state)
     6.8 -           loop-point (if (> total-quantity 99) 0xFF 99)
     6.9 -           distance (- desired-quantity current-quantity)
    6.10 -           loop-distance (int(* -1 (Math/signum (float distance))
    6.11 -                                (- loop-point (Math/abs distance))))
    6.12 -           best-path (first (sort-by #(Math/abs %)
    6.13 -                                     [distance loop-distance]))
    6.14 -           direction (if (< 0 best-path) ↑ ↓)]
    6.15 -       (println "best-path" best-path)
    6.16 -       (reduce
    6.17 -        (fn [script _]
    6.18 -          (delayed-difference [] direction 5 item-quantity-selected
    6.19 -                              script))
    6.20 -        
    6.21 -        script
    6.22 -        (range (Math/abs best-path)))))
    6.23 +     (cond (= desired-quantity 1) (do (println "1 of 1") script)
    6.24 +           (= total-quantity desired-quantity)
    6.25 +           (do (println "get everything!")
    6.26 +               (delayed-difference [] ↓ 5 item-quantity-selected
    6.27 +                                   script))
    6.28 +           true
    6.29 +           (let [current-quantity (item-quantity-selected state)
    6.30 +                 loop-point (if (= 0 total-quantity) 0x100 total-quantity)
    6.31 +                 distance (- desired-quantity current-quantity)
    6.32 +                 loop-distance (int(* -1 (Math/signum (float distance))
    6.33 +                                      (- loop-point (Math/abs distance))))
    6.34 +                 best-path (first (sort-by #(Math/abs %)
    6.35 +                                           [distance loop-distance]))
    6.36 +                 direction (if (< 0 best-path) ↑ ↓)]
    6.37 +             (println "best-path" best-path)
    6.38 +             (println "current-quantity" current-quantity)
    6.39 +             (println "desired-quantity" desired-quantity)
    6.40 +             (println "options" [distance loop-distance])
    6.41 +             (reduce
    6.42 +              (fn [script _]
    6.43 +                (delayed-difference [] direction 5 item-quantity-selected
    6.44 +                                    script))
    6.45 +              script
    6.46 +              (range (Math/abs best-path))))))
    6.47    ([desired-quantity [moves state :as script]]
    6.48       (set-quantity 99 desired-quantity script)))
    6.49  
    6.50 @@ -426,11 +434,15 @@
    6.51      (println "wait-time" wait-time)
    6.52      (do-nothing wait-time script)))
    6.53  
    6.54 -(defn select-menu-entry [script]
    6.55 -  (->> script
    6.56 -       (wait-until (partial set-cursor-relative 1))
    6.57 -       (play-moves [[:a] []])))
    6.58 -
    6.59 +(defn select-menu-entry
    6.60 +  ([test-direction [moves state :as script]]
    6.61 +     (->> script
    6.62 +          (wait-until (partial set-cursor-relative test-direction))
    6.63 +          (play-moves [[] [:a] []])))
    6.64 +  ([[moves state :as script]]
    6.65 +     (select-menu-entry
    6.66 +      1 script)))
    6.67 +         
    6.68  (defn restart
    6.69    "The two button presses after a restart event are converted to
    6.70     blanks. Due to weirdness with the VBM format. To compensate, ensure
    6.71 @@ -441,10 +453,11 @@
    6.72  (defn-memo do-save-corruption
    6.73    ([] (do-save-corruption
    6.74         (walk-to-counter)))
    6.75 -  ([script]
    6.76 +  ([script] (do-save-corruption 4 script))
    6.77 +  ([n script]
    6.78       (->> script
    6.79            activate-start-menu
    6.80 -          (set-cursor 4)
    6.81 +          (set-cursor n)
    6.82            select-menu-entry
    6.83            select-menu-entry
    6.84            (play-moves
    6.85 @@ -470,8 +483,45 @@
    6.86  
    6.87  (def menu do-nothing )
    6.88  
    6.89 +
    6.90 +(defn investivate-close-menu []
    6.91 +  (clojure.pprint/pprint
    6.92 +   (apply harmonic-compare
    6.93 +          (map read-state
    6.94 +               ["start-up-1"
    6.95 +                "start-down-1"
    6.96 +                ;;"start-up-2"
    6.97 +                ;;"start-down-2"
    6.98 +                ;;"start-up-3"
    6.99 +                ;;"start-down-3"
   6.100 +                ;;"computer-up-1"
   6.101 +                ;;"computer-down-2"
   6.102 +                "computer-up-2"
   6.103 +                "computer-down-2"
   6.104 +                "pokemon-up-1"
   6.105 +                "pokemon-down-1"
   6.106 +                "pokemon-up-2"
   6.107 +                "pokemon-down-2"
   6.108 +                "item-up-1"
   6.109 +                "item-down-1"
   6.110 +                "save-up-1"
   6.111 +                "save-down-1"
   6.112 +                "item-nest-up-1"
   6.113 +                "item-nest-down-1"]))))
   6.114 +
   6.115 +(def list-nesting-depth-address 50339)
   6.116 +
   6.117 +(defn current-depth
   6.118 +  ([^SaveState state] (aget (memory state) list-nesting-depth-address))
   6.119 +  ([] (current-depth @current-state)))
   6.120 +  
   6.121 +
   6.122  (defn close-menu [script]
   6.123 -  (first-difference [] [:b] AF script))
   6.124 +  (delayed-difference
   6.125 +   [] [:b] 50
   6.126 +   current-depth
   6.127 +   script))
   6.128 +                                        
   6.129  
   6.130  (defn purchase-item
   6.131    "Assumes that the cursor is over the desired item, and purchases
   6.132 @@ -492,10 +542,11 @@
   6.133         ;;(corrupted-checkpoint)
   6.134         (do-save-corruption)
   6.135         ))
   6.136 -  ([script]
   6.137 +  ([script] (corrupt-item-list 1))
   6.138 +  ([n script]
   6.139       (->> script
   6.140            activate-start-menu
   6.141 -          (set-cursor 1)        ; select "POKEMON" from
   6.142 +          (set-cursor n)        ; select "POKEMON"
   6.143            select-menu-entry     ; from main menu.
   6.144            (set-cursor 5)        ; select 6th pokemon
   6.145            select-menu-entry
   6.146 @@ -1042,159 +1093,3 @@
   6.147      ((fn [_] (println "===========") _))
   6.148      (print-listing 0xD162 (+ 0xD162 20)))))
   6.149  
   6.150 -(defn pc-item-writer-program
   6.151 -  []
   6.152 -  (let [limit 201
   6.153 -        [target-high target-low] (disect-bytes-2 0xD162)]
   6.154 -    (flatten
   6.155 -     [[0x00  ;; (item-hack) set increment stack pointer no-op
   6.156 -       0x1E  ;; load limit into E
   6.157 -       limit
   6.158 -       0x3F  ;; (item-hack) set carry flag no-op
   6.159 -
   6.160 -       ;; load 2 into C.
   6.161 -       0x0E   ;; C == 1 means input-first nybble
   6.162 -       0x04   ;; C == 0 means input-second nybble
   6.163 -
   6.164 -       0x21 ;; load target into HL
   6.165 -       target-low
   6.166 -       target-high
   6.167 -       0x37 ;; (item-hack) set carry flag no-op
   6.168 -
   6.169 -       0x00 ;; (item-hack) no-op
   6.170 -       0x37 ;; (item-hack) set carry flag no-op
   6.171 -       
   6.172 -       0x00 ;; (item-hack) no-op
   6.173 -       0xF3 ;; disable interrupts
   6.174 -       ;; Input Section
   6.175 -
   6.176 -       0x3E ;; load 0x20 into A, to measure buttons
   6.177 -       0x10 
   6.178 -
   6.179 -       0x00 ;; (item-hack) no-op
   6.180 -       0xE0 ;; load A into [FF00]
   6.181 -       0x00
   6.182 -
   6.183 -       0xF0 ;; load 0xFF00 into A to get
   6.184 -       0x00 ;; button presses
   6.185 -       
   6.186 -       0xE6
   6.187 -       0x0F ;; select bottom four bits of A
   6.188 -       0x37 ;; (item-hack) set carry flag no-op
   6.189 -
   6.190 -       0x00 ;; (item-hack) no-op
   6.191 -       0xB8 ;; see if input is different (CP A B)
   6.192 -
   6.193 -       0x00 ;; (item-hack) (INC SP)
   6.194 -       0x28 ;; repeat above steps if input is not different
   6.195 -       ;; (jump relative backwards if B != A)
   6.196 -       0xED ;; (literal -19) (item-hack) -19 == egg bomb (TM37)
   6.197 -
   6.198 -       0x47 ;; load A into B
   6.199 -       
   6.200 -       0x0D ;; dec C
   6.201 -       0x37 ;; (item-hack) set-carry flag
   6.202 -       ;; branch based on C:
   6.203 -       0x20 ;; JR NZ
   6.204 -       23 ;; skip "input second nybble" and "jump to target" below
   6.205 -       
   6.206 -       ;; input second nybble
   6.207 -
   6.208 -       0x0C ;; inc C
   6.209 -       0x0C ;; inc C
   6.210 -
   6.211 -       0x00 ;; (item-hack) no-op
   6.212 -       0xE6 ;; select bottom bits
   6.213 -       0x0F
   6.214 -       0x37 ;; (item-hack) set-carry flag no-op
   6.215 -
   6.216 -       0x00 ;; (item-hack) no-op
   6.217 -       0xB2 ;; (OR A D) -> A
   6.218 -
   6.219 -       0x22 ;; (do (A -> (HL)) (INC HL))
   6.220 -
   6.221 -       0x1D ;; (DEC E)
   6.222 -
   6.223 -       0x00 ;; (item-hack) 
   6.224 -       0x20 ;; jump back to input section if not done
   6.225 -       0xDA ;; literal -36 == TM 18 (counter)
   6.226 -       0x01 ;; (item-hack) set BC to literal (no-op)
   6.227 -
   6.228 -       ;; jump to target
   6.229 -       0x00  ;; (item-hack) these two bytes can be anything.
   6.230 -       0x01 
   6.231 -
   6.232 -       0x00   ;; (item-hack) no-op
   6.233 -       0xBF   ;; (CP A A) ensures Z
   6.234 -       
   6.235 -       0xCA   ;; (item-hack) jump if Z
   6.236 -       target-low
   6.237 -       target-high
   6.238 -       0x01   ;; (item-hack) will never be reached.
   6.239 -       
   6.240 -       ;; input first nybble
   6.241 -       0x00
   6.242 -       0xCB
   6.243 -       0x37  ;; swap nybbles on A
   6.244 -
   6.245 -       0x57  ;; A -> D
   6.246 -
   6.247 -       0x37  ;; (item-hack) set carry flag no-op
   6.248 -       0x18  ;; relative jump backwards
   6.249 -       0xCD  ;; literal -51 == TM05; go back to input section
   6.250 -       0x01  ;; (item-hack) will never reach this instruction
   6.251 -
   6.252 -       ]
   6.253 -      (repeat 8 [0xFF 0x01])
   6.254 -
   6.255 -      [;; jump to actual program
   6.256 -       0x00
   6.257 -       0x37  ;; (item-hack) set carry flag no-op
   6.258 -
   6.259 -       0x2E  ;; 0x3A -> L
   6.260 -       0x3A
   6.261 -
   6.262 -
   6.263 -       0x00  ;; (item-hack) no-op
   6.264 -       0x26  ;; 0xD5 -> L
   6.265 -       0xD5  
   6.266 -       0x01  ;; (item-hack) set-carry BC
   6.267 -
   6.268 -       0x00  ;; (item-hack) these can be anything
   6.269 -       0x00  
   6.270 -
   6.271 -       ;; 0x00
   6.272 -       ;; 0x44 ;; H -> B
   6.273 -
   6.274 -       ;; 0x00
   6.275 -       ;; 0x7D ;; L -> A
   6.276 -       
   6.277 -       ;; 0x00
   6.278 -       ;; 0x7C ;; A -> H
   6.279 -
   6.280 -       ;; 0x00
   6.281 -       ;; 0x68 ;; B -> L
   6.282 -       
   6.283 -       0x00
   6.284 -       0xE9 ;; jump to (HL)
   6.285 -       ]])))
   6.286 -
   6.287 -
   6.288 -(defn test-pc-item-writer []
   6.289 -    (-> (read-state "bootstrap-init")
   6.290 -      (set-memory pc-item-list-start 50)
   6.291 -      (set-memory-range
   6.292 -       map-function-address-start
   6.293 -       [0x8B 0xD5])
   6.294 -      (set-memory-range
   6.295 -       (inc pc-item-list-start)
   6.296 -       (pc-item-writer-program))))
   6.297 -
   6.298 -(defn test-pc-item-writer-2 []
   6.299 -  (let [orig (read-state "pc-item-writer")]
   6.300 -    (-> orig
   6.301 -    (print-listing 0xD162 (+ 0xD162 20))
   6.302 -    (run-moves (reduce concat
   6.303 -                (repeat 10 [[:a :b :start :select] []])))
   6.304 -    ((fn [_] (println "===========") _))
   6.305 -    (print-listing 0xD162 (+ 0xD162 20)))))
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/clojure/com/aurellem/run/bootstrap_1.clj	Mon Apr 09 01:44:19 2012 -0500
     7.3 @@ -0,0 +1,570 @@
     7.4 +(ns com.aurellem.run.bootstrap-1
     7.5 +  (:use (com.aurellem.gb saves gb-driver util
     7.6 +                         items vbm characters money))
     7.7 +  (:use (com.aurellem.run util title save-corruption bootstrap-0))
     7.8 +  (:use (com.aurellem.exp item-bridge))
     7.9 +  (:import [com.aurellem.gb.gb_driver SaveState]))
    7.10 +
    7.11 +(defn pc-item-writer-program
    7.12 +  []
    7.13 +  (let [limit 201
    7.14 +        [target-high target-low] (disect-bytes-2 0xD162)]
    7.15 +    (flatten
    7.16 +     [[0x00  ;; (item-hack) set increment stack pointer no-op
    7.17 +       0x1E  ;; load limit into E
    7.18 +       limit
    7.19 +       0x3F  ;; (item-hack) set carry flag no-op
    7.20 +
    7.21 +       ;; load 2 into C.
    7.22 +       0x0E   ;; C == 1 means input-first nybble
    7.23 +       0x04   ;; C == 0 means input-second nybble
    7.24 +
    7.25 +       0x21 ;; load target into HL
    7.26 +       target-low
    7.27 +       target-high
    7.28 +       0x37 ;; (item-hack) set carry flag no-op
    7.29 +
    7.30 +       0x00 ;; (item-hack) no-op
    7.31 +       0x37 ;; (item-hack) set carry flag no-op
    7.32 +       
    7.33 +       0x00 ;; (item-hack) no-op
    7.34 +       0xF3 ;; disable interrupts
    7.35 +       ;; Input Section
    7.36 +
    7.37 +       0x3E ;; load 0x20 into A, to measure buttons
    7.38 +       0x10 
    7.39 +
    7.40 +       0x00 ;; (item-hack) no-op
    7.41 +       0xE0 ;; load A into [FF00]
    7.42 +       0x00
    7.43 +
    7.44 +       0xF0 ;; load 0xFF00 into A to get
    7.45 +       0x00 ;; button presses
    7.46 +       
    7.47 +       0xE6
    7.48 +       0x0F ;; select bottom four bits of A
    7.49 +       0x37 ;; (item-hack) set carry flag no-op
    7.50 +
    7.51 +       0x00 ;; (item-hack) no-op
    7.52 +       0xB8 ;; see if input is different (CP A B)
    7.53 +
    7.54 +       0x00 ;; (item-hack) (INC SP)
    7.55 +       0x28 ;; repeat above steps if input is not different
    7.56 +       ;; (jump relative backwards if B != A)
    7.57 +       0xED ;; (literal -19) (item-hack) -19 == egg bomb (TM37)
    7.58 +
    7.59 +       0x47 ;; load A into B
    7.60 +       
    7.61 +       0x0D ;; dec C
    7.62 +       0x37 ;; (item-hack) set-carry flag
    7.63 +       ;; branch based on C:
    7.64 +       0x20 ;; JR NZ
    7.65 +       23 ;; skip "input second nybble" and "jump to target" below
    7.66 +       
    7.67 +       ;; input second nybble
    7.68 +
    7.69 +       0x0C ;; inc C
    7.70 +       0x0C ;; inc C
    7.71 +
    7.72 +       0x00 ;; (item-hack) no-op
    7.73 +       0xE6 ;; select bottom bits
    7.74 +       0x0F
    7.75 +       0x37 ;; (item-hack) set-carry flag no-op
    7.76 +
    7.77 +       0x00 ;; (item-hack) no-op
    7.78 +       0xB2 ;; (OR A D) -> A
    7.79 +
    7.80 +       0x22 ;; (do (A -> (HL)) (INC HL))
    7.81 +
    7.82 +       0x1D ;; (DEC E)
    7.83 +
    7.84 +       0x00 ;; (item-hack) 
    7.85 +       0x20 ;; jump back to input section if not done
    7.86 +       0xDA ;; literal -36 == TM 18 (counter)
    7.87 +       0x01 ;; (item-hack) set BC to literal (no-op)
    7.88 +
    7.89 +       ;; jump to target
    7.90 +       0x00  ;; (item-hack) these two bytes can be anything.
    7.91 +       0x01 
    7.92 +
    7.93 +       0x00   ;; (item-hack) no-op
    7.94 +       0xBF   ;; (CP A A) ensures Z
    7.95 +       
    7.96 +       0xCA   ;; (item-hack) jump if Z
    7.97 +       target-low
    7.98 +       target-high
    7.99 +       0x01   ;; (item-hack) will never be reached.
   7.100 +       
   7.101 +       ;; input first nybble
   7.102 +       0x00
   7.103 +       0xCB
   7.104 +       0x37  ;; swap nybbles on A
   7.105 +
   7.106 +       0x57  ;; A -> D
   7.107 +
   7.108 +       0x37  ;; (item-hack) set carry flag no-op
   7.109 +       0x18  ;; relative jump backwards
   7.110 +       0xCD  ;; literal -51 == TM05; go back to input section
   7.111 +       0x01  ;; (item-hack) will never reach this instruction
   7.112 +
   7.113 +       ]
   7.114 +      (repeat 8 [0x00 0x01])
   7.115 +
   7.116 +      [;; jump to actual program
   7.117 +       0x00
   7.118 +       0x37  ;; (item-hack) set carry flag no-op
   7.119 +
   7.120 +       0x2E  ;; 0x3A -> L
   7.121 +       0x3A
   7.122 +
   7.123 +
   7.124 +       0x00  ;; (item-hack) no-op
   7.125 +       0x26  ;; 0xD5 -> L
   7.126 +       0xD5  
   7.127 +       0x01  ;; (item-hack) set-carry BC
   7.128 +
   7.129 +       0x00  ;; (item-hack) these can be anything
   7.130 +       0x01  
   7.131 +
   7.132 +       0x00
   7.133 +       0xE9 ;; jump to (HL)
   7.134 +       ]])))
   7.135 +
   7.136 +(defn view-desired-item-layout []
   7.137 +  (clojure.pprint/pprint
   7.138 +   (raw-inventory->inventory (pc-item-writer-program))))
   7.139 +
   7.140 +(defn pc-item-writer-state []
   7.141 +    (-> (read-state "bootstrap-init")
   7.142 +      (set-memory pc-item-list-start 50)
   7.143 +      (set-memory-range
   7.144 +       map-function-address-start
   7.145 +       [0x8B 0xD5])
   7.146 +      (set-memory-range
   7.147 +       (inc pc-item-list-start)
   7.148 +       (pc-item-writer-program))))
   7.149 +
   7.150 +(defn test-pc-item-writer []
   7.151 +  (let [orig (read-state "pc-item-writer")]
   7.152 +    (-> orig
   7.153 +    (print-listing 0xD162 (+ 0xD162 20))
   7.154 +    (run-moves (reduce concat
   7.155 +                (repeat 10 [[:a :b :start :select] []])))
   7.156 +    ((fn [_] (println "===========") _))
   7.157 +    (print-listing 0xD162 (+ 0xD162 20)))))
   7.158 +
   7.159 +(defn close-all-menus [[moves state :as script]]
   7.160 +  (loop [s script]
   7.161 +    (let [depth (current-depth (second (do-nothing 50 s)))]
   7.162 +      (println "depth" depth)
   7.163 +      (if (= depth 1)
   7.164 +        s
   7.165 +        (recur (close-menu s))))))
   7.166 +
   7.167 +(defn-memo name-rival
   7.168 +  ([] (name-rival (to-rival-name)))
   7.169 +  ([script]
   7.170 +     (->> script
   7.171 +          (first-difference [] [:a] AF)
   7.172 +          (first-difference [] [:r] DE)
   7.173 +          (play-moves
   7.174 +           [[]
   7.175 +            [] [] [:r] [] [:d] [:a]           ;; L
   7.176 +            [:r] [] [:r] [] [:r] [] [:r] [] 
   7.177 +            [:r] [] [:d] [] [:d] [:a]         ;; [PK]
   7.178 +            [:d] [] [:r] [:a]
   7.179 +            ]))))
   7.180 +
   7.181 +(defn-memo to-room-pc
   7.182 +  ([] (to-room-pc (name-rival)))
   7.183 +  ([script]
   7.184 +     (->> script
   7.185 +          finish-title
   7.186 +          (walk [← ← ↑ ← ↑ ↑ ↑]))))
   7.187 +
   7.188 +(defn-memo bootstrap-corrupt-save
   7.189 +  ([] (bootstrap-corrupt-save (to-room-pc)))
   7.190 +  ([script]
   7.191 +   (->> script
   7.192 +        (do-save-corruption 2)
   7.193 +        (corrupt-item-list 0)
   7.194 +        close-all-menus)))
   7.195 +
   7.196 +(defn-memo begin-initial-deposits
   7.197 +  ([] (begin-initial-deposits
   7.198 +       (bootstrap-corrupt-save)))
   7.199 +  ([script]
   7.200 +     (->> script
   7.201 +          (first-difference [] [:a] AF)
   7.202 +          (scroll-text)
   7.203 +          (set-cursor 1)
   7.204 +          select-menu-entry)))
   7.205 +
   7.206 +(defn wait-for-quantity
   7.207 +  [[moves state :as script]]
   7.208 +  (if (not= (item-quantity-selected state) 1)
   7.209 +    (repeat-until-different [] item-quantity-selected script)
   7.210 +    script))
   7.211 +
   7.212 +(defn wait-for-cursor
   7.213 +  [[moves state :as script]]
   7.214 +  (if (not= (list-offset state) 0)
   7.215 +    (repeat-until-different [] list-offset script)
   7.216 +    script))
   7.217 +
   7.218 +(defn deposit-held-item [n quantity [moves state :as script]]
   7.219 +  (let [total-quantity (second (nth-item state n))]
   7.220 +    (println "total-quantity" total-quantity)
   7.221 +    (->> script
   7.222 +         (set-cursor n)
   7.223 +         (select-menu-entry 1)
   7.224 +         (wait-for-quantity)
   7.225 +         (set-quantity total-quantity quantity)
   7.226 +         (delayed-difference [] [:a] 100 #(search-string % "stored"))
   7.227 +         (scroll-text))))
   7.228 +
   7.229 +(defn sell-held-item [n quantity [moves state :as script]]
   7.230 +  (let [total-quantity (second (nth-item state n))]
   7.231 +    (->> script
   7.232 +         (wait-for-cursor)  ;; when selling, the cursor always
   7.233 +         (set-cursor n)     ;; returns to the top of the list.
   7.234 +         (select-menu-entry 1)
   7.235 +         (wait-for-quantity)
   7.236 +         (set-quantity total-quantity quantity)
   7.237 +         (delayed-difference [] [:a] 100 current-depth)
   7.238 +         (play-moves (repeat 20 [:b]))
   7.239 +         (delayed-difference [] [:a] 100 #(search-string % "What"))
   7.240 +         )))
   7.241 +
   7.242 +(defn widthdraw-pc-item [n quantity [moves state :as script]]
   7.243 +  (let [total-quantity (second (nth-pc-item state n))]
   7.244 +    (->> script
   7.245 +         (set-cursor n)
   7.246 +         (select-menu-entry 1)
   7.247 +         (wait-for-quantity)
   7.248 +         (set-quantity total-quantity quantity)
   7.249 +         (delayed-difference [] [:a] 100 #(search-string % "Withdrew"))
   7.250 +         (scroll-text))))
   7.251 +
   7.252 +(defn toss-held-item [n quantity [moves state :as script]]
   7.253 +  (let [total-quantity (second (nth-item state n))]
   7.254 +    (->> script
   7.255 +         (set-cursor n)
   7.256 +         (select-menu-entry 1)
   7.257 +         (set-cursor-relative 1)
   7.258 +         (select-menu-entry -1)
   7.259 +         (wait-for-quantity)
   7.260 +         (set-quantity total-quantity quantity)
   7.261 +         (play-moves [[:a]])
   7.262 +         (scroll-text)
   7.263 +         (delayed-difference [] [:a] 100 #(search-string % "Threw"))
   7.264 +         (scroll-text)
   7.265 +         )))
   7.266 +
   7.267 +(defn buy-item [n quantity [moves state :as script]]
   7.268 +  (->> script
   7.269 +       (set-cursor n)
   7.270 +       (purchase-item quantity)))
   7.271 +
   7.272 +
   7.273 +(def desired-zero-quantities
   7.274 +  (map second (filter (comp (partial = 0) first)
   7.275 +                      (partition 2 (pc-item-writer-program)))))
   7.276 +  
   7.277 +(defn-memo initial-deposits
   7.278 +  ([] (initial-deposits (begin-initial-deposits)))
   7.279 +  ([script]
   7.280 +     (->> script
   7.281 +          (deposit-held-item 0 0x1)
   7.282 +          ((fn [script]
   7.283 +             (reduce 
   7.284 +              (fn [script item] (deposit-held-item item 0xFF script))
   7.285 +              script
   7.286 +              (range 3 (+ 13 3)))))
   7.287 +          close-all-menus)))
   7.288 +
   7.289 +
   7.290 +(defn-memo prepare-celadon-warp
   7.291 +  ([] (prepare-celadon-warp (initial-deposits)))
   7.292 +  ([script]
   7.293 +     (->> script
   7.294 +          (activate-start-menu)
   7.295 +          (set-cursor-relative 1)
   7.296 +          (select-menu-entry)
   7.297 +          (toss-held-item 35 0xFA)
   7.298 +          (close-all-menus))))
   7.299 +
   7.300 +
   7.301 +;;0 -- 256
   7.302 +;;1 -- 254
   7.303 +;;2 -- 254
   7.304 +;;3 -- 255
   7.305 +
   7.306 +(defn-memo restore-items
   7.307 +  ([] (restore-items (prepare-celadon-warp)))
   7.308 +  ([script]
   7.309 +     (->> script
   7.310 +          (first-difference [] [:a] AF)
   7.311 +          (scroll-text)
   7.312 +          (select-menu-entry)
   7.313 +          (widthdraw-pc-item 0 1)
   7.314 +          ;;(widthdraw-pc-item 0 99)
   7.315 +          ;;(widthdraw-pc-item 1 1)
   7.316 +          (widthdraw-pc-item 13 255)
   7.317 +          (close-all-menus))))
   7.318 +
   7.319 +(defn-memo to-celadon
   7.320 +  ([] (to-celadon (restore-items)))
   7.321 +  ([script]
   7.322 +     (->> script
   7.323 +          (walk [→ → → → → → → ↑
   7.324 +                 ↓ ↓ ↓ ↓ ↓ ← ← ← ←
   7.325 +                 ↓ ↓]))))
   7.326 +
   7.327 +
   7.328 +;; celadon store inventory
   7.329 +
   7.330 +;; Floor 2
   7.331 +;;=====================================
   7.332 +;; Great Ball        TM32 (double-team)
   7.333 +;; Super Potion      TM33 (reflect)
   7.334 +;; Revive            TM02 (razor-wind)
   7.335 +;; Super Repel       TM07 (horn-drill)
   7.336 +;; Antidote          TM37 (egg-bomb)
   7.337 +;; Burn Heal         TM01 (mega-punch)
   7.338 +;; Ice Heal          TM05 (mega-kick)
   7.339 +;; Awakening         TM09 (take-down)
   7.340 +;; Parlyz Heal       TM17 (submission)
   7.341 +
   7.342 +
   7.343 +;; Floor 3
   7.344 +;;=====================================       
   7.345 +;; TM18 (counter)
   7.346 +
   7.347 +
   7.348 +;; Floor 4
   7.349 +;;=====================================
   7.350 +;; Poke Doll
   7.351 +;; Fire Stone
   7.352 +;; Thunder Stone
   7.353 +;; Water Stone
   7.354 +;; Leaf Stone
   7.355 +
   7.356 +;; Floor 5
   7.357 +;;=====================================
   7.358 +;; X Accuracy         HP UP
   7.359 +;; Guard Spec.        Protein
   7.360 +;; Dire Hit           Iron
   7.361 +;; X Attack           Carbos
   7.362 +;; X Defend           Calcium
   7.363 +;; X Speed            
   7.364 +;; X Special
   7.365 +
   7.366 +;; Roof
   7.367 +;;=====================================
   7.368 +;; Fresh Water        TM13 (ice-beam)
   7.369 +;; Soda Pop           TM48 (rock-slide)
   7.370 +;; Lemonade :)        TM49 (tri-attack)
   7.371 +
   7.372 +
   7.373 +(defn-memo go-to-floor-two
   7.374 +  ([] (go-to-floor-two (to-celadon)))
   7.375 +  ([script]
   7.376 +     (->> script
   7.377 +          (walk [↑ → → → → → → → → → → →
   7.378 +                 ↑ ↑ ↑ ↑ ↑ ↑
   7.379 +                 ← ← ← ← 
   7.380 +                 ↓ ↓ ↓
   7.381 +                 ← ←])
   7.382 +          (first-difference [] ↑ AF))))
   7.383 +
   7.384 +(defn talk
   7.385 +  "Assumes that you are facing something that initiates text and
   7.386 +   causes it to do so."
   7.387 +  [script]
   7.388 +  (->> script
   7.389 +       (delayed-difference [] [:a] 100
   7.390 +                           #(aget (memory %) text-address))))
   7.391 +
   7.392 +(defn-memo get-money-floor-two
   7.393 +  ([] (get-money-floor-two (go-to-floor-two)))
   7.394 +  ([script]
   7.395 +     (->> script
   7.396 +          talk
   7.397 +          (set-cursor 1)
   7.398 +          (select-menu-entry)
   7.399 +          (sell-held-item 0 1)
   7.400 +          (sell-held-item 0 1)
   7.401 +          (close-menu))))
   7.402 +
   7.403 +(defn-memo floor-two-TMs
   7.404 +  ([] (floor-two-TMs (get-money-floor-two)))
   7.405 +  ([script]
   7.406 +     (->> script
   7.407 +          (wait-for-cursor)
   7.408 +          (select-menu-entry)
   7.409 +          (buy-item 2 98)  ;; TM02 (razor-wind)
   7.410 +          (buy-item 4 71)  ;; TM37 (doubleteam)
   7.411 +          (buy-item 5 63)  ;; TM01 (mega-punch)
   7.412 +          (buy-item 6 1)   ;; TM05 (mega-kick)
   7.413 +          (buy-item 7 56)  ;; TM09 (take-down)
   7.414 +          (close-menu))))
   7.415 +
   7.416 +(defn end-shop-conversation
   7.417 +  [script]
   7.418 +  (->> script
   7.419 +       (wait-until scroll-text [:b])
   7.420 +       (play-moves [[] [:b]])
   7.421 +       close-menu))
   7.422 +
   7.423 +(defn-memo floor-two-more-money
   7.424 +  ([] (floor-two-more-money (floor-two-TMs)))
   7.425 +  ([script]
   7.426 +     (->> script
   7.427 +          (wait-for-cursor)
   7.428 +          (set-cursor 1)
   7.429 +          (select-menu-entry)
   7.430 +          (sell-held-item 0 1)
   7.431 +          (sell-held-item 0 1)
   7.432 +          close-menu
   7.433 +          end-shop-conversation)))
   7.434 +
   7.435 +(defn turn [direction script]
   7.436 +  (->> script
   7.437 +       (first-difference [] direction AF)))
   7.438 +
   7.439 +(defn-memo floor-two-items
   7.440 +  ([] (floor-two-items (floor-two-more-money)))
   7.441 +  ([script]
   7.442 +     (->> script
   7.443 +          (walk [←])
   7.444 +          (turn ↑)
   7.445 +          talk
   7.446 +          select-menu-entry
   7.447 +          (buy-item 5 12)  ;; burn heal
   7.448 +          (buy-item 6 55)  ;; ice heal
   7.449 +          (buy-item 7 4)   ;; awakening
   7.450 +          (buy-item 8 99)  ;; parlyz heal
   7.451 +          (buy-item 8 55)  ;; parlyz heal
   7.452 +          close-menu
   7.453 +          end-shop-conversation)))
   7.454 +
   7.455 +(defn-memo go-to-floor-three
   7.456 +  ([] (go-to-floor-three (floor-two-items)))
   7.457 +  ([script]
   7.458 +     (->> script
   7.459 +          (walk [→ → → → → → → → → → ↑ ↑ ↑
   7.460 +                   → ↑]))))
   7.461 +(defn-memo get-TM18
   7.462 +  ([] (get-TM18 (go-to-floor-three)))
   7.463 +  ([script]
   7.464 +     (->> script
   7.465 +          (walk [↓ ↓])
   7.466 +          talk
   7.467 +          (scroll-text 3)
   7.468 +          end-text)))
   7.469 +
   7.470 +(defn-memo go-to-floor-four
   7.471 +  ([] (go-to-floor-four (get-TM18)))
   7.472 +  ([script]
   7.473 +     (->> script
   7.474 +          (walk [← ← ← ← ↑ ↑
   7.475 +                 ↓ ← ← ↓ ↓ ↓
   7.476 +                 ← ← ← ← ←])
   7.477 +          (turn ↓))))
   7.478 +
   7.479 +(defn-memo floor-four-items
   7.480 +  ([] (floor-four-items (go-to-floor-four)))
   7.481 +  ([script]
   7.482 +     (->> script
   7.483 +          talk
   7.484 +          select-menu-entry
   7.485 +          (buy-item 1 23)  ;; Fire Stone
   7.486 +          (buy-item 2 98)  ;; Thunder Stone
   7.487 +          (buy-item 3 29)  ;; Water Stone
   7.488 +          close-menu
   7.489 +          end-shop-conversation)))
   7.490 +
   7.491 +(defn-memo go-to-floor-five
   7.492 +  ([] (go-to-floor-five (floor-four-items)))
   7.493 +  ([script]
   7.494 +     (->> script
   7.495 +          (walk [→ → → → → →
   7.496 +                 ↑ ↑ ↑
   7.497 +                 → → → → → ↑ ;; leave floor four
   7.498 +                 ↓ ← ← ← ← ← ← ← ←
   7.499 +                 ↓ ↓ ↓ ← ← ← ]);; go to five's clerk
   7.500 +          (turn ↑))))
   7.501 +                
   7.502 +(defn-memo floor-five-items
   7.503 +  ([] (floor-five-items (go-to-floor-five)))
   7.504 +  ([script]
   7.505 +     (->> script
   7.506 +          talk
   7.507 +          select-menu-entry
   7.508 +          (buy-item 0 58)   ;; X-Accuracy
   7.509 +          (buy-item 1 99)   ;; Guard Spec.
   7.510 +          (buy-item 1 24)   ;; Guard Spec.
   7.511 +          close-menu
   7.512 +          end-shop-conversation)))
   7.513 +
   7.514 +(defn-memo go-to-roof
   7.515 +  ([] (go-to-roof (floor-five-items)))
   7.516 +  ([script]
   7.517 +     (->> script
   7.518 +          (walk [→ → → → ↑ ↑ ↑ → → → ↑ ;; leave floor five
   7.519 +                 ↓ ← ← ←]) ;; walk to vending machine
   7.520 +          (turn ↑))))
   7.521 +
   7.522 +(defn buy-drink
   7.523 +  "Assumes you're in front of the vending machine. Buys the indicated
   7.524 +   drink."
   7.525 +  [n script]
   7.526 +  (->> script
   7.527 +       (do-nothing 20)
   7.528 +       (play-moves [[:a][:a]])
   7.529 +       scroll-text
   7.530 +       (wait-for-cursor)
   7.531 +       (set-cursor n)
   7.532 +       select-menu-entry
   7.533 +       close-menu))
   7.534 +
   7.535 +(defn-memo roof-drinks
   7.536 +  ([] (roof-drinks (go-to-roof)))
   7.537 +  ([script]
   7.538 +     (->> script
   7.539 +          (buy-drink 0) ;; fresh water (for TM13)
   7.540 +          ;; buy 16 lemonades
   7.541 +          ;; LEMONADE is the best item <3  :)
   7.542 +          (multiple-times 16 (partial buy-drink 2)))))
   7.543 +
   7.544 +(defn-memo get-TM13
   7.545 +  ([] (get-TM13 (roof-drinks)))
   7.546 +  ([script]
   7.547 +     (->> script
   7.548 +          (walk [← ← ← ← ← ← ↓])
   7.549 +          (play-moves [[][:a][:a][]])
   7.550 +          (scroll-text 3)
   7.551 +          select-menu-entry
   7.552 +          select-menu-entry
   7.553 +          (scroll-text 6)
   7.554 +          close-menu)))
   7.555 +
   7.556 +(defn to-celadon-poke-center
   7.557 +  ([] (to-celadon-poke-center (get-TM13)))
   7.558 +  ([script]
   7.559 +     (->> script
   7.560 +          (walk [↑ → → → → → → → → → ↑])       ; leave roof
   7.561 +          (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ← 
   7.562 +                 ↑ ↑ ↑ ← ← ↑])                 ; to elevator
   7.563 +                 
   7.564 +          (walk [→ → ↑ ↑])                     ; to controls
   7.565 +          talk
   7.566 +          select-menu-entry                    ; to floor 1
   7.567 +          (walk [↓ ↓ ← ←])
   7.568 +          (walk [↓ → ↓ ↓ ↓ ↓ ↓ ↓])             ; leave store
   7.569 +          (walk [↓ → → → → → → → → → → ↑ ↑])
   7.570 +          (walk (repeat 23 →))
   7.571 +          (walk [↑ ↑ ↑ ↑])                     ; enter poke center
   7.572 +          (walk [↑ ↑ ↑ → → → → → → → → → →])   ; to computer
   7.573 +          (turn ↑))))
     8.1 Binary file moves/temp.vbm has changed
     9.1 --- a/org/rom.org	Mon Apr 09 01:40:26 2012 -0500
     9.2 +++ b/org/rom.org	Mon Apr 09 01:44:19 2012 -0500
     9.3 @@ -810,6 +810,7 @@
     9.4  
     9.5  
     9.6  ***
     9.7 +
     9.8  #+name: type-advantage
     9.9  #+begin_src clojure
    9.10  (defn hxc-advantage
    10.1 Binary file save-states/at-mat.sav has changed
    11.1 Binary file save-states/computer-down-1.sav has changed
    12.1 Binary file save-states/computer-down-2.sav has changed
    13.1 Binary file save-states/computer-up-1.sav has changed
    14.1 Binary file save-states/computer-up-2.sav has changed
    15.1 Binary file save-states/item-down-1.sav has changed
    16.1 Binary file save-states/item-nest-down-1.sav has changed
    17.1 Binary file save-states/item-nest-up-1.sav has changed
    18.1 Binary file save-states/item-up-1.sav has changed
    19.1 Binary file save-states/pokemon-down-1.sav has changed
    20.1 Binary file save-states/pokemon-down-2.sav has changed
    21.1 Binary file save-states/pokemon-up-1.sav has changed
    22.1 Binary file save-states/pokemon-up-2.sav has changed
    23.1 Binary file save-states/save-down-1.sav has changed
    24.1 Binary file save-states/save-up-1.sav has changed
    25.1 Binary file save-states/start-down-1.sav has changed
    26.1 Binary file save-states/start-down-2.sav has changed
    27.1 Binary file save-states/start-down-3.sav has changed
    28.1 Binary file save-states/start-up-1.sav has changed
    29.1 Binary file save-states/start-up-2.sav has changed
    30.1 Binary file save-states/start-up-3.sav has changed