Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_1.clj @ 353:a9e7507379e9
adjusting run to use 0x00 items for money since they are worth a half million each.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 09 Apr 2012 05:36:56 -0500 |
parents | 82e3ba144773 |
children | 4141489d1406 |
line wrap: on
line source
1 (ns com.aurellem.run.bootstrap-12 (:use (com.aurellem.gb saves gb-driver util3 items vbm characters money))4 (:use (com.aurellem.run util title save-corruption bootstrap-0))5 (:use (com.aurellem.exp item-bridge))6 (:import [com.aurellem.gb.gb_driver SaveState]))8 (defn pc-item-writer-program9 []10 (let [limit 20111 [target-high target-low] (disect-bytes-2 0xD162)]12 (flatten13 [[0x00 ;; (item-hack) set increment stack pointer no-op14 0x1E ;; load limit into E15 limit16 0x3F ;; (item-hack) set carry flag no-op18 ;; load 2 into C.19 0x0E ;; C == 1 means input-first nybble20 0x04 ;; C == 0 means input-second nybble22 0x21 ;; load target into HL23 target-low24 target-high25 0x37 ;; (item-hack) set carry flag no-op27 0x00 ;; (item-hack) no-op28 0x37 ;; (item-hack) set carry flag no-op30 0x00 ;; (item-hack) no-op31 0xF3 ;; disable interrupts32 ;; Input Section34 0x3E ;; load 0x20 into A, to measure buttons35 0x1037 0x00 ;; (item-hack) no-op38 0xE0 ;; load A into [FF00]39 0x0041 0xF0 ;; load 0xFF00 into A to get42 0x00 ;; button presses44 0xE645 0x0F ;; select bottom four bits of A46 0x37 ;; (item-hack) set carry flag no-op48 0x00 ;; (item-hack) no-op49 0xB8 ;; see if input is different (CP A B)51 0x00 ;; (item-hack) (INC SP)52 0x28 ;; repeat above steps if input is not different53 ;; (jump relative backwards if B != A)54 0xED ;; (literal -19) (item-hack) -19 == egg bomb (TM37)56 0x47 ;; load A into B58 0x0D ;; dec C59 0x37 ;; (item-hack) set-carry flag60 ;; branch based on C:61 0x20 ;; JR NZ62 23 ;; skip "input second nybble" and "jump to target" below64 ;; input second nybble66 0x0C ;; inc C67 0x0C ;; inc C69 0x00 ;; (item-hack) no-op70 0xE6 ;; select bottom bits71 0x0F72 0x37 ;; (item-hack) set-carry flag no-op74 0x00 ;; (item-hack) no-op75 0xB2 ;; (OR A D) -> A77 0x22 ;; (do (A -> (HL)) (INC HL))79 0x1D ;; (DEC E)81 0x00 ;; (item-hack)82 0x20 ;; jump back to input section if not done83 0xDA ;; literal -36 == TM 18 (counter)84 0x01 ;; (item-hack) set BC to literal (no-op)86 ;; jump to target87 0x00 ;; (item-hack) these two bytes can be anything.88 0x0190 0x00 ;; (item-hack) no-op91 0xBF ;; (CP A A) ensures Z93 0xCA ;; (item-hack) jump if Z94 target-low95 target-high96 0x01 ;; (item-hack) will never be reached.98 ;; input first nybble99 0x00100 0xCB101 0x37 ;; swap nybbles on A103 0x57 ;; A -> D105 0x37 ;; (item-hack) set carry flag no-op106 0x18 ;; relative jump backwards107 0xCD ;; literal -51 == TM05; go back to input section108 0x01 ;; (item-hack) will never reach this instruction110 ]111 (repeat 8 [0xFF 0x01])113 [;; jump to actual program114 0x00115 0x37 ;; (item-hack) set carry flag no-op117 0x2E ;; 0x3A -> L118 0x3A121 0x00 ;; (item-hack) no-op122 0x26 ;; 0xD5 -> L123 0xD5124 0x01 ;; (item-hack) set-carry BC126 0x00 ;; (item-hack) these can be anything127 0x01129 0x00130 0xE9 ;; jump to (HL)131 ]])))133 (defn view-desired-item-layout []134 (clojure.pprint/pprint135 (raw-inventory->inventory (pc-item-writer-program))))137 (defn pc-item-writer-state []138 (-> (read-state "bootstrap-init")139 (set-memory pc-item-list-start 50)140 (set-memory-range141 map-function-address-start142 [0x8B 0xD5])143 (set-memory-range144 (inc pc-item-list-start)145 (pc-item-writer-program))))147 (defn test-pc-item-writer []148 (let [orig (read-state "pc-item-writer")]149 (-> orig150 (print-listing 0xD162 (+ 0xD162 20))151 (run-moves (reduce concat152 (repeat 10 [[:a :b :start :select] []])))153 ((fn [_] (println "===========") _))154 (print-listing 0xD162 (+ 0xD162 20)))))156 (defn close-all-menus [[moves state :as script]]157 (loop [s script]158 (let [depth (current-depth (second (do-nothing 50 s)))]159 (println "depth" depth)160 (if (= depth 1)161 s162 (recur (close-menu s))))))164 (defn-memo name-rival165 ([] (name-rival (to-rival-name)))166 ([script]167 (->> script168 (first-difference [] [:a] AF)169 (first-difference [] [:r] DE)170 (play-moves171 [[]172 [] [] [:r] [] [:d] [:a] ;; L173 [:r] [] [:r] [] [:r] [] [:r] []174 [:r] [] [:d] [] [:d] [:a] ;; [PK]175 [:d] [] [:r] [:a]176 ]))))178 (defn-memo to-room-pc179 ([] (to-room-pc (name-rival)))180 ([script]181 (->> script182 finish-title183 (walk [← ← ↑ ← ↑ ↑ ↑]))))185 (defn-memo bootstrap-corrupt-save186 ([] (bootstrap-corrupt-save (to-room-pc)))187 ([script]188 (->> script189 (do-save-corruption 2)190 (corrupt-item-list 0)191 close-all-menus)))193 (defn-memo begin-initial-deposits194 ([] (begin-initial-deposits195 (bootstrap-corrupt-save)))196 ([script]197 (->> script198 (first-difference [] [:a] AF)199 (scroll-text)200 (set-cursor 1)201 select-menu-entry)))203 (defn wait-for-quantity204 [[moves state :as script]]205 (if (not= (item-quantity-selected state) 1)206 (repeat-until-different [] item-quantity-selected script)207 script))209 (defn wait-for-cursor210 [[moves state :as script]]211 (if (not= (list-offset state) 0)212 (repeat-until-different [] list-offset script)213 script))215 (defn deposit-held-item [n quantity [moves state :as script]]216 (let [total-quantity (second (nth-item state n))]217 (println "total-quantity" total-quantity)218 (->> script219 (set-cursor n)220 (select-menu-entry 1)221 (wait-for-quantity)222 (set-quantity total-quantity quantity)223 (delayed-difference [] [:a] 100 #(search-string % "stored"))224 (scroll-text))))226 (defn sell-held-item [n quantity [moves state :as script]]227 (let [total-quantity (second (nth-item state n))]228 (->> script229 (wait-for-cursor) ;; when selling, the cursor always230 (set-cursor n) ;; returns to the top of the list.231 (select-menu-entry 1)232 (wait-for-quantity)233 (set-quantity total-quantity quantity)234 (delayed-difference [] [:a] 100 current-depth)235 (play-moves (repeat 20 [:b]))236 (delayed-difference [] [:a] 100 #(search-string % "What"))237 )))239 (defn widthdraw-pc-item [n quantity [moves state :as script]]240 (let [total-quantity (second (nth-pc-item state n))]241 (->> script242 (set-cursor n)243 (select-menu-entry 1)244 (wait-for-quantity)245 (set-quantity total-quantity quantity)246 (delayed-difference [] [:a] 100 #(search-string % "Withdrew"))247 (scroll-text))))249 (defn toss-held-item [n quantity [moves state :as script]]250 (let [total-quantity (second (nth-item state n))]251 (->> script252 (set-cursor n)253 (select-menu-entry 1)254 (set-cursor-relative 1)255 (select-menu-entry -1)256 (wait-for-quantity)257 (set-quantity total-quantity quantity)258 (play-moves [[:a]])259 (scroll-text)260 (delayed-difference [] [:a] 100 #(search-string % "Threw"))261 (scroll-text)262 )))265 (def desired-zero-quantities266 (map second (filter (comp (partial = 0) first)267 (partition 2 (pc-item-writer-program)))))269 (defn-memo initial-deposits270 ([] (initial-deposits (begin-initial-deposits)))271 ([script]272 (->> script273 (deposit-held-item 1 0x2)274 ((fn [script]275 (reduce276 (fn [script item] (deposit-held-item item 0xFF script))277 script278 (range 3 (+ 12 3)))))279 close-all-menus)))282 (defn-memo prepare-celadon-warp283 ([] (prepare-celadon-warp (initial-deposits)))284 ([script]285 (->> script286 (activate-start-menu)287 (set-cursor-relative 1)288 (select-menu-entry)289 (toss-held-item 35 0xFA)290 (close-all-menus))))293 ;;0 -- 256294 ;;1 -- 254295 ;;2 -- 254296 ;;3 -- 255298 (defn-memo restore-items299 ([] (restore-items (prepare-celadon-warp)))300 ([script]301 (->> script302 (first-difference [] [:a] AF)303 (scroll-text)304 (select-menu-entry)305 (widthdraw-pc-item 0 1)306 (widthdraw-pc-item 0 99)307 (widthdraw-pc-item 1 1)308 (widthdraw-pc-item 2 5)309 ;; (widthdraw-pc-item 3 99)310 ;; (widthdraw-pc-item 3 99)311 ;; (widthdraw-pc-item 3 57) ;; take all312 ;; (widthdraw-pc-item 2 99)313 ;; (widthdraw-pc-item 2 99)314 ;; (widthdraw-pc-item 2 56) ;; take all315 ;; (widthdraw-pc-item 1 99)316 ;; (widthdraw-pc-item 1 99)317 ;; (widthdraw-pc-item 1 55) ;; leave one318 ;; (widthdraw-pc-item 0 99)319 ;; (widthdraw-pc-item 0 99)320 ;; (widthdraw-pc-item 0 57) ;; leave one321 (close-all-menus))))323 (defn-memo to-celadon324 ([] (to-celadon (restore-items)))325 ([script]326 (->> script327 (walk [→ → → → → → → ↑328 ↓ ↓ ↓ ↓ ↓ ← ← ← ←329 ↓ ↓]))))332 ;; celadon store inventory334 ;; Floor 2335 ;;=====================================336 ;; Great Ball TM32 (double-team)337 ;; Super Potion TM33 (reflect)338 ;; Revive TM02 (razor-wind)339 ;; Super Repel TM07 (horn-drill)340 ;; Antidote TM37 (egg-bomb)341 ;; Burn Heal TM01 (mega-punch)342 ;; Ice Heal TM05 (mega-kick)343 ;; Awakening TM09 (take-down)344 ;; Parlyz Heal TM17 (submission)347 ;; Floor 3348 ;;=====================================349 ;; TM18 (counter)352 ;; Floor 4353 ;;=====================================354 ;; Poke Doll355 ;; Fire Stone356 ;; Thunder Stone357 ;; Water Stone358 ;; Leaf Stone360 ;; Floor 5361 ;;=====================================362 ;; X Accuracy HP UP363 ;; Guard Spec. Protein364 ;; Dire Hit Iron365 ;; X Attack Carbos366 ;; X Defend Calcium367 ;; X Speed368 ;; X Special370 ;; Roof371 ;;=====================================372 ;; Fresh Water TM13 (ice-beam)373 ;; Soda Pop TM48 (rock-slide)374 ;; Lemonade :) TM49 (tri-attack)377 (defn-memo go-to-floor-two378 ([] (go-to-floor-two (to-celadon)))379 ([script]380 (->> script381 (walk [↑ → → → → → → → → → → →382 ↑ ↑ ↑ ↑ ↑ ↑383 ← ← ← ←384 ↓ ↓ ↓385 ← ←])386 (first-difference [] ↑ AF))))388 (defn talk389 "Assumes that you are facing a person and engages in conversation"390 [[moves state :as script]]391 (delayed-difference [] [:a] 100392 #(aget (memory %) text-address)393 script))396 (defn get-money-floor-two397 ([] (get-money-floor-two (go-to-floor-two)))398 ([script]399 (->> script400 talk401 (set-cursor 1)402 (select-menu-entry)403 (sell-held-item 2 1)404 (sell-held-item 2 1)406 ;; (sell-held-item 11)407 ;; (sell-held-item 10)408 ;; (sell-held-item 9)409 ;; (sell-held-item 8)410 ;; (sell-held-item 7)411 ;; (sell-held-item 6)412 (do-nothing 40))))417 (defn floor-two-TMs418 [])420 (defn floor-two-items421 [])423 (defn go-to-floor-three424 [])426 (defn get-TM18427 [])429 (defn go-to-floor-four430 [])432 (defn floor-four-items433 [])435 (defn go-to-floor-five436 [])438 (defn floor-five-items439 [])441 (defn go-to-roof442 [])444 (defn roof-drinks445 [])447 (defn get-TM13448 [])