Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_1.clj @ 593:daa3497bbe12
increased speed to travel to floor two of celadon dept. store.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 01 Sep 2012 12:38:26 -0500 |
parents | cd557c922cec |
children | ea448eecb615 |
line wrap: on
line source
1 (ns com.aurellem.run.bootstrap-12 (:use (com.aurellem.gb saves gb-driver util constants3 items vbm characters money4 rlm-assembly))5 (:use (com.aurellem.run util title save-corruption bootstrap-0))6 (:use (com.aurellem.exp item-bridge))7 (:import [com.aurellem.gb.gb_driver SaveState]))9 (def hex #(printf "0x%02X\n" %))11 (defn print-desired-item-layout []12 (clojure.pprint/pprint13 (raw-inventory->inventory (pc-item-writer-program))))15 (defn pc-item-writer-state []16 (-> (read-state "bootstrap-init")17 (set-memory pc-item-list-start 50)18 (set-memory-range19 map-function-address-start20 [0x8B 0xD5])21 (set-memory-range22 (inc pc-item-list-start)23 (pc-item-writer-program))))25 (defn test-pc-item-writer []26 (let [orig (read-state "pc-item-writer")]27 (-> orig28 (print-listing 0xD162 (+ 0xD162 20))29 (run-moves (reduce concat30 (repeat 10 [[:a :b :start :select] []])))31 ((fn [_] (println "===========") _))32 (print-listing 0xD162 (+ 0xD162 20)))))34 (defn close-all-menus [[moves state :as script]]35 (loop [s script]36 (let [depth (current-depth (second (do-nothing 50 s)))]37 (println "depth" depth)38 (if (= depth 1)39 s40 (recur (close-menu s))))))42 (defn-memo name-rival43 ([] (name-rival (to-rival-name)))44 ([script]45 (->> script46 (first-difference [] [:a] AF)47 (first-difference [] [:r] DE)48 (play-moves49 [[]50 [] [] [:r] [] [:d] [:a] ;; L51 [:r] [] [:r] [] [:r] [] [:r] []52 [:r] [] [:d] [] [:d] [:a] ;; [PK]53 [:d] [] [:r] [:a]54 ]))))56 (defn-memo to-room-pc57 ([] (to-room-pc (name-rival)))58 ([script]59 (->> script60 finish-title61 (walk [← ← ↑ ← ↑ ↑ ↑]))))63 ;; (defn wait-for-quantity64 ;; [[moves state :as script]]65 ;; (if (not= (item-quantity-selected state) 1)66 ;; (repeat-until-different [] item-quantity-selected script)67 ;; script))69 ;; TODO use this:70 ;;(wait-until (partial set-cursor-relative 1))72 ;; (defn wait-for-cursor73 ;; [[moves state :as script]]74 ;; (if (not= (list-offset state) 0)75 ;; (repeat-until-different [] list-offset script)76 ;; script))78 (defn deposit-held-item [n quantity [moves state :as script]]79 (let [total-quantity (second (nth-item state n))]80 (println "total-quantity" total-quantity)81 (->> script82 (set-cursor n)83 (select-menu-entry 1)84 ;;(wait-for-quantity)85 (set-quantity total-quantity quantity)86 (delayed-difference [] [:a] 100 #(search-string % "stored"))87 (scroll-text))))89 (defn sell-held-item [n quantity [moves state :as script]]90 (let [total-quantity (second (nth-item state n))]91 (->> script92 ;;(wait-for-cursor) ;; when selling, the cursor always93 (set-cursor n) ;; returns to the top of the list.94 (select-menu-entry 1)95 ;;(wait-for-quantity)96 (set-quantity total-quantity quantity)97 (delayed-difference [] [:a] 100 current-depth)98 (play-moves (repeat 20 [:b]))99 (delayed-difference [] [:a] 100 #(search-string % "What"))100 )))102 (defn widthdraw-pc-item [n quantity [moves state :as script]]103 (let [total-quantity (second (nth-pc-item state n))]104 (->> script105 (set-cursor n)106 (select-menu-entry 1)107 ;;(wait-for-quantity)108 (set-quantity total-quantity quantity)109 (delayed-difference [] [:a] 100 #(search-string % "Withdrew"))110 (scroll-text))))112 (defn toss-held-item [n quantity [moves state :as script]]113 (let [total-quantity (second (nth-item state n))]114 (->> script115 (set-cursor n)116 (select-menu-entry 1)117 (set-cursor-relative 1)118 (select-menu-entry -1)119 ;;(wait-for-quantity)120 (set-quantity total-quantity quantity)121 (play-moves [[:a]])122 (scroll-text)123 (delayed-difference [] [:a] 100 #(search-string % "Threw"))124 (scroll-text)125 )))127 (defn buy-item [n quantity [moves state :as script]]128 (->> script129 (set-cursor n)130 (purchase-item quantity)))132 (defn switch-items [item-fn idx-1 idx-2 script]133 (->> script134 (wait-until select-menu-entry)135 (set-cursor idx-1)136 (wait-until select-menu-entry)137 (play-moves [[][:select][]])138 (set-cursor idx-2)139 (delayed-difference [] [:select] 100140 #(item-fn % (list-offset %)))))142 (def switch-pc-items (partial switch-items nth-pc-item))143 (def switch-held-items (partial switch-items nth-item))145 (defn combine-pc-items [idx-1 script]146 (->> script147 (switch-pc-items idx-1 (inc idx-1))))149 (def desired-zero-quantities150 (map second (filter (comp (partial = 0) first)151 (partition 2 (pc-item-writer-program)))))153 (defn bootstrap-corrupt-save154 ([] (bootstrap-corrupt-save (to-room-pc)))155 ([script]156 (->> script157 (do-save-corruption 3)158 (corrupt-item-list 0)159 close-all-menus)))161 (defn-memo prepare-celadon-warp162 ([] (prepare-celadon-warp (bootstrap-corrupt-save)))163 ([script]164 (->> script165 (activate-start-menu)166 (set-cursor-relative 1)167 (select-menu-entry)168 ;; vastly increase text speed while we're here.169 (switch-held-items 21 27)170 (toss-held-item 35 0xFA)171 (close-all-menus))))173 (defn-memo begin-initial-deposits174 ([] (begin-initial-deposits175 (prepare-celadon-warp)))176 ([script]177 (->> script178 (first-difference [] [:a] AF)179 (scroll-text)180 (set-cursor 1)181 select-menu-entry)))183 (defn-memo initial-deposits184 ([] (initial-deposits (begin-initial-deposits)))185 ([script]186 (->> script187 (deposit-held-item 0 0x1)188 ((fn [script]189 (reduce190 (fn [script item] (deposit-held-item item 0xFF script))191 script192 (range 3 (+ 13 3)))))193 close-all-menus)))196 ;;0 -- 256197 ;;1 -- 254198 ;;2 -- 254199 ;;3 -- 255201 (defn activate-home-pc202 [script]203 (->> script204 (delayed-difference [] [:a]205 200 first-character)206 (scroll-text)))208 (defn-memo restore-items209 ([] (restore-items (initial-deposits)))210 ([script]211 (->> script212 activate-home-pc213 (select-menu-entry)214 (widthdraw-pc-item 0 1)215 ;;(widthdraw-pc-item 0 99)216 ;;(widthdraw-pc-item 1 1)217 (widthdraw-pc-item 13 255)218 (close-all-menus))))220 (defn-memo to-celadon221 ([] (to-celadon (restore-items)))222 ([script]223 (->> script224 (walk [→ → → → → → → ↑225 ↓ ↓ ↓ ↓ ↓ ← ← ← ←226 ↓ ↓]))))229 ;; celadon store inventory231 ;; Floor 2232 ;;=====================================233 ;; Great Ball TM32 (double-team)234 ;; Super Potion TM33 (reflect)235 ;; Revive TM02 (razor-wind)236 ;; Super Repel TM07 (horn-drill)237 ;; Antidote TM37 (egg-bomb)238 ;; Burn Heal TM01 (mega-punch)239 ;; Ice Heal TM05 (mega-kick)240 ;; Awakening TM09 (take-down)241 ;; Parlyz Heal TM17 (submission)244 ;; Floor 3245 ;;=====================================246 ;; TM18 (counter)249 ;; Floor 4250 ;;=====================================251 ;; Poke Doll252 ;; Fire Stone253 ;; Thunder Stone254 ;; Water Stone255 ;; Leaf Stone257 ;; Floor 5258 ;;=====================================259 ;; X Accuracy HP UP260 ;; Guard Spec. Protein261 ;; Dire Hit Iron262 ;; X Attack Carbos263 ;; X Defend Calcium264 ;; X Speed265 ;; X Special267 ;; Roof268 ;;=====================================269 ;; Fresh Water TM13 (ice-beam)270 ;; Soda Pop TM48 (rock-slide)271 ;; Lemonade :) TM49 (tri-attack)274 (defn-memo go-to-floor-two275 ([] (go-to-floor-two (to-celadon)))276 ([script]277 (->> script278 (walk [→ → ↑279 ↑ ↑ ↑ ↑280 ← ← ← ←281 ↑ ↑282 ← ← ← ←283 ↓ ↓ ↓284 ← ←])285 (first-difference [] ↑ AF))))287 (defn talk288 "Assumes that you are facing something that initiates text and289 causes it to do so."290 [script]291 (->> script292 (delayed-difference [] [:a] 100293 first-character)))295 (defn-memo get-money-floor-two296 ([] (get-money-floor-two (go-to-floor-two)))297 ([script]298 (->> script299 talk300 (set-cursor 1)301 (select-menu-entry)302 (sell-held-item 0 1)303 (sell-held-item 0 1)304 (close-menu))))306 (defn-memo floor-two-TMs307 ([] (floor-two-TMs (get-money-floor-two)))308 ([script]309 (->> script310 (set-cursor 0)311 (select-menu-entry)312 (buy-item 2 98) ;; TM02 (razor-wind)313 (buy-item 4 71) ;; TM37 (doubleteam)314 (buy-item 5 63) ;; TM01 (mega-punch)315 (buy-item 6 1) ;; TM05 (mega-kick)316 (buy-item 7 56) ;; TM09 (take-down)317 (close-menu))))319 (defn end-shop-conversation320 [script]321 (->> script322 (wait-until scroll-text [:b])323 (play-moves [[] [:b]])324 close-menu))326 (defn-memo floor-two-more-money327 ([] (floor-two-more-money (floor-two-TMs)))328 ([script]329 (->> script330 (set-cursor 1)331 (select-menu-entry)332 (sell-held-item 0 1)333 (sell-held-item 0 1)334 close-menu335 end-shop-conversation)))337 (defn turn [direction script]338 (->> script339 (first-difference [] direction AF)))341 (defn-memo floor-two-items342 ([] (floor-two-items (floor-two-more-money)))343 ([script]344 (->> script345 (walk [←])346 (turn ↑)347 talk348 select-menu-entry349 (buy-item 5 12) ;; burn heal350 (buy-item 6 55) ;; ice heal351 (buy-item 7 4) ;; awakening352 (buy-item 8 99) ;; parlyz heal353 (buy-item 8 55) ;; parlyz heal354 close-menu355 end-shop-conversation)))357 (defn-memo go-to-floor-three358 ([] (go-to-floor-three (floor-two-items)))359 ([script]360 (->> script361 (walk [→ → → → → → → → → → ↑ ↑ ↑362 → ↑]))))363 (defn-memo get-TM18364 ([] (get-TM18 (go-to-floor-three)))365 ([script]366 (->> script367 (walk [↓ ↓])368 talk369 (scroll-text 3)370 end-text)))372 (defn-memo go-to-floor-four373 ([] (go-to-floor-four (get-TM18)))374 ([script]375 (->> script376 (walk [← ← ← ← ↑ ↑377 ↓ ← ← ↓ ↓ ↓378 ← ← ← ← ←])379 (turn ↓))))381 (defn-memo floor-four-items382 ([] (floor-four-items (go-to-floor-four)))383 ([script]384 (->> script385 talk386 select-menu-entry387 (buy-item 1 23) ;; Fire Stone388 (buy-item 2 98) ;; Thunder Stone389 (buy-item 3 29) ;; Water Stone390 close-menu391 end-shop-conversation)))393 (defn-memo go-to-floor-five394 ([] (go-to-floor-five (floor-four-items)))395 ([script]396 (->> script397 (walk [→ → → → → →398 ↑ ↑ ↑399 → → → → → ↑ ;; leave floor four400 ↓ ← ← ← ← ← ← ← ←401 ↓ ↓ ↓ ← ← ← ]);; go to five's clerk402 (turn ↑))))404 (defn-memo floor-five-items405 ([] (floor-five-items (go-to-floor-five)))406 ([script]407 (->> script408 talk409 select-menu-entry410 (buy-item 0 58) ;; X-Accuracy411 (buy-item 1 99) ;; Guard Spec.412 (buy-item 1 24) ;; Guard Spec.413 close-menu414 end-shop-conversation)))416 (defn-memo go-to-roof417 ([] (go-to-roof (floor-five-items)))418 ([script]419 (->> script420 (walk [→ → → → ↑ ↑ ↑ → → → ↑ ;; leave floor five421 ↓ ← ← ←]) ;; walk to vending machine422 (turn ↑))))424 (defn buy-drink425 "Assumes you're in front of the vending machine. Buys the indicated426 drink."427 [n script]428 (->> script429 (do-nothing 20)430 (play-moves [[:a][:a]])431 scroll-text432 (set-cursor n)433 select-menu-entry434 close-menu))436 (defn-memo roof-drinks437 ([] (roof-drinks (go-to-roof)))438 ([script]439 (->> script440 (buy-drink 0) ;; fresh water (for TM13)441 ;; buy 16 lemonades442 ;; LEMONADE is the best item <3 :)443 (multiple-times 16 (partial buy-drink 2)))))445 (defn-memo get-TM13446 ([] (get-TM13 (roof-drinks)))447 ([script]448 (->> script449 ;;(walk [← ← ← ← ← ← ↓])450 (walk [↓ ↓ ↓ ← ← ← ← ← ←])451 (play-moves [[][][][][:a][:a][]])452 (scroll-text 3)453 select-menu-entry454 select-menu-entry455 (scroll-text 6)456 close-menu)))458 (defn-memo to-celadon-poke-center459 ([] (to-celadon-poke-center (get-TM13)))460 ([script]461 (->> script462 ;;(walk [↑ → → → → → → → → → ↑]) ; leave roof463 (walk [→ → → → → → → → → ↑ ↑ ↑ ↑])464 (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ←465 ↑ ↑ ↑ ← ← ↑]) ; to elevator467 (walk [→ → ↑ ↑]) ; to controls468 talk469 select-menu-entry ; to floor 1470 (walk [↓ ↓ ← ←])471 (walk [↓ → ↓ ↓ ↓ ↓ ↓ ↓]) ; leave store472 (walk [↓ → → → → → → → → → → ↑ ↑])473 (walk (repeat 23 →))474 (walk [↑ ↑ ↑ ↑]) ; enter poke center475 (walk [↑ ↑ ↑ → → → → → → → → → →]) ; to computer476 (turn ↑))))478 (defn activate-rlm-pc [script]479 (->> script480 talk481 scroll-text482 ;;wait-for-cursor483 (set-cursor 1)484 select-menu-entry485 (scroll-text 2)))487 (defn begin-deposit [script]488 (->> script489 (set-cursor 1)490 select-menu-entry))492 (defn begin-withdraw [script]493 (->> script494 (set-cursor 0)495 (select-menu-entry)))497 (defn deposit-held-item-named498 [item-name quantity [moves state :as script]]499 (let [index (count500 (take-while501 (fn [[name quant]]502 (or (not= name item-name)503 (< quant quantity)))504 (inventory state)))]505 (println "index" index)506 (deposit-held-item index quantity script)))508 (defn open-held-items509 [script]510 (->> script511 select-menu-entry))513 (defn to-held-items514 [script]515 (->> script516 close-menu517 close-menu518 end-text;;; grr520 activate-start-menu521 open-held-items))523 (defn toss-pc-item [n quantity [moves state :as script]]524 (let [total-quantity (second (nth-pc-item state n))]525 (->> script526 (set-cursor n)527 (select-menu-entry 1)528 (set-quantity total-quantity quantity)529 (delayed-difference [] [:a] 100 #(search-string % "Is"))530 (scroll-text)531 select-menu-entry532 (scroll-text))))534 (defn-memo hacking-1535 ([] (hacking-1 (to-celadon-poke-center)))536 ([script]537 (->> script538 activate-rlm-pc539 begin-deposit540 (deposit-held-item-named 0x00 30)541 (deposit-held-item-named :TM01 63)542 (deposit-held-item-named :awakening 4)543 (deposit-held-item-named :thunderstone 98)544 (deposit-held-item-named :TM09 55)545 (deposit-held-item-named 0x00 55))))547 (defn-memo hacking-2548 ([] (hacking-2 (hacking-1)))549 ([script]550 (->> script551 (to-held-items)552 (toss-held-item 0 166) ;; discard cruft553 close-menu554 close-menu)))556 (defn-memo hacking-3557 ([] (hacking-3 (hacking-2)))558 ([script]559 (->> script560 activate-rlm-pc561 begin-withdraw562 (widthdraw-pc-item 0 99)563 (widthdraw-pc-item 0 1)564 (widthdraw-pc-item 2 0xFE)565 (widthdraw-pc-item 3 0xFE)566 close-menu)))568 (defn-memo hacking-4569 ([] (hacking-4 (hacking-3)))570 ([script]571 (->> script572 begin-deposit573 (deposit-held-item 19 243)574 (deposit-held-item-named :lemonade 16)575 (deposit-held-item 18 224))))577 (defn-memo hacking-5578 "clean out the held-item list again"579 ([] (hacking-5 (hacking-4)))580 ([script]581 (->> script582 (to-held-items)583 (toss-held-item 18 30)584 (toss-held-item 17 1)585 close-menu586 close-menu)))588 (defn-memo hacking-6589 ([] (hacking-6 (hacking-5)))590 ([script]591 (->> script592 activate-rlm-pc593 begin-withdraw594 (widthdraw-pc-item 4 0xFE)595 (widthdraw-pc-item 5 0xFE)596 (widthdraw-pc-item 6 0xFE)597 close-menu)))599 (defn-memo hacking-7600 ([] (hacking-7 (hacking-6)))601 ([script]602 (->> script603 begin-deposit604 (deposit-held-item 19 240)605 (deposit-held-item 18 230)606 (deposit-held-item-named :parlyz-heal 55)607 (deposit-held-item 17 184)608 (deposit-held-item 17 40)609 (deposit-held-item-named :TM37 71)610 (deposit-held-item-named :ice-heal 55)611 (deposit-held-item-named :fire-stone 23)612 (deposit-held-item-named :burn-heal 12)613 ;; as a special case, /don't/ close the menu.614 )))616 (defn-memo hacking-8617 "Clear cruft away from held item list."618 ([] (hacking-8 (hacking-7)))619 ([script]620 (->> script621 to-held-items622 (toss-held-item 15 1)623 (toss-held-item 14 1)624 (toss-held-item 13 1)625 close-menu626 close-menu)))628 (defn-memo hacking-9629 ([] (hacking-9 (hacking-8)))630 ([script]631 (->> script632 activate-rlm-pc633 begin-withdraw634 (widthdraw-pc-item 7 0xFE)635 (widthdraw-pc-item 8 0xFC)636 (widthdraw-pc-item 8 1)637 (widthdraw-pc-item 8 1)638 (widthdraw-pc-item 9 0xFE)639 (multiple-times640 7641 (partial combine-pc-items 2))642 close-menu)))644 (defn-memo hacking-10645 ([] (hacking-10 (hacking-9)))646 ([script]647 (->> script648 begin-deposit649 (deposit-held-item 17 230)650 (deposit-held-item-named :parlyz-heal 55)651 (deposit-held-item 14 178)652 (deposit-held-item-named :water-stone 29)653 (deposit-held-item 14 32)654 (deposit-held-item-named :TM18 1)655 (deposit-held-item 13 1)656 (deposit-held-item 13 191)657 (deposit-held-item-named :TM02 98)658 (deposit-held-item-named :TM09 1)659 close-menu)))661 (defn-memo hacking-11662 ([] (hacking-11 (hacking-10)))663 ([script]664 (->> script665 begin-withdraw666 (widthdraw-pc-item 3 0xFE)667 (widthdraw-pc-item 4 0xFE)668 (widthdraw-pc-item 5 1)669 (widthdraw-pc-item 5 1)670 (widthdraw-pc-item 5 1)671 (widthdraw-pc-item 5 0xFB)672 (multiple-times673 3674 (partial combine-pc-items 2))675 close-menu)))677 (defn-memo hacking-12678 ([] (hacking-12 (hacking-11)))679 ([script]680 (->> script681 begin-deposit682 (deposit-held-item 18 203)683 (deposit-held-item-named :guard-spec 87)684 (deposit-held-item-named :guard-spec 24)685 (deposit-held-item-named :TM05 1)686 (multiple-times687 8688 (partial deposit-held-item 14 1))689 (deposit-held-item 14 55)690 (deposit-held-item-named :x-accuracy 58)691 (deposit-held-item 14 38)692 (deposit-held-item-named :TM13 1)693 (deposit-held-item 13 1)694 (deposit-held-item 13 233)695 close-menu)))697 (defn-memo hacking-13698 ([] (hacking-13 (hacking-12)))699 ([script]700 (->> script701 (set-cursor-relative 1)702 (select-menu-entry)703 (toss-pc-item 1 1)704 (toss-pc-item 0 156)705 (toss-pc-item 0 11))))707 (defn confirm-pattern []708 (let [start-address (inc pc-item-list-start)709 target-pattern (pc-item-writer-program)710 actual-pattern711 (subvec (vec (memory (second (hacking-13))))712 start-address713 (+ start-address (count target-pattern)))]714 (println target-pattern)715 (println actual-pattern)716 (= target-pattern actual-pattern)))718 (defn-memo go-to-mansion-for-the-lulz719 ([] (go-to-mansion-for-the-lulz (hacking-13)))720 ([script]721 (->> script722 close-menu723 close-menu724 end-text ;;grr725 (walk [↓ ← ← ← ← ← ← ← ← ← ↓ ↓ ↓])726 (walk (repeat 17 ←))727 (walk [↑ → → → → ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])728 (walk [↓ ← ↑])729 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓730 ← ← ← ← ↑ ↑ ↑ ← ↑])731 (talk)732 (scroll-text 2)733 (do-nothing 100)734 close-menu)))736 (defn-memo launch-bootstrap-program737 ([] (launch-bootstrap-program738 (go-to-mansion-for-the-lulz)))739 ([script]740 (->> script741 ;; must corrupt item list again by switching pokemon742 activate-start-menu ;; \743 (set-cursor 0) ;; |744 select-menu-entry ;; |745 select-menu-entry ;; |746 (set-cursor 1) ;; | -- switch 9th pokemon747 select-menu-entry ;; | with 4th pokemon748 (set-cursor 3) ;; |749 select-menu-entry ;; |750 close-menu ;; /751 ;; now, open items and set map-function to752 ;; the program inside the item-computer.753 (set-cursor 1)754 (select-menu-entry)755 (toss-held-item 22 12)756 (switch-held-items 22 40)757 close-all-menus)))759 (defn regen-control-checkpoint!760 [] (write-script! (launch-bootstrap-program) "control-checkpoint"))762 (defn control-checkpoint []763 (read-script "control-checkpoint"))765 (def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF])767 (defn test-pattern-writing768 ([] (test-pattern-writing increasing-pattern))769 ([pattern]770 (let [moves (bootstrap-pattern pattern)771 pattern-insertion772 (->> (launch-bootstrap-program)773 (play-moves774 (take 100 moves)))]775 (println "Input Pattern:")776 (apply println (map #(format "0x%02X" %) pattern))777 (println "\nMemory Listing:")778 (print-listing (second pattern-insertion)779 0xD162 (+ 0xD162 (count pattern)))780 (= (subvec (vec (memory (second pattern-insertion)))781 0xD162 (+ 0xD162 (count pattern)))782 pattern))))784 (defn-memo launch-main-bootstrap-program785 ([] (launch-main-bootstrap-program786 (control-checkpoint)787 ;;(launch-bootstrap-program)788 ))789 ([script]790 (->> script791 (play-moves792 (bootstrap-pattern (main-bootstrap-program)))793 (play-moves794 (take 253 (interleave (repeat 1000 [:b])795 (repeat 1000 [])))))))796 (def bootstrap-start pokemon-list-start)798 (defn test-main-bootstrap-integrety799 []800 (assert801 (= (main-bootstrap-program)802 (subvec803 (vec (memory (second (launch-main-bootstrap-program))))804 pokemon-list-start805 (+ pokemon-list-start (count (main-bootstrap-program)))))))807 (defn set-target-address808 "Assumes that the game is under control of the main-bootstrap809 program in MODE-SELECT mode, and sets the target address to which810 jumps/writes will occur."811 [target-address script]812 (let [[target-high target-low] (disect-bytes-2 target-address)]813 (->> script814 (play-moves815 (map buttons816 [set-H-mode target-high 0x00817 set-L-mode target-low 0x00])))))819 (defn write-RAM-segment820 "Assumes that the game is under control of the main-bootstrap821 program in MODE-SELECT mode and that target-address has been822 appropriately set, and writes 255 bytes or less to RAM."823 [segment script]824 (->> script825 (play-moves826 (map buttons827 [write-mode (count segment)]))828 (play-moves (map buttons segment))829 (play-moves [[]])))831 (defn write-RAM832 "Assumes that the game is under control of the main-bootstrap833 program in MODE-SELECT mode, and rewrites RAM starting at834 'start-address with 'new-ram."835 [start-address new-ram script]836 (loop [s (set-target-address start-address script)837 to-write new-ram]838 (if (< (count to-write) 0x100)839 (write-RAM-segment to-write s)840 (recur841 (write-RAM-segment (take 0xFF to-write) s)842 (drop 0xFF to-write)))))844 (defn transfer-control845 "Assumes that the game is under control of the main-bootstrap846 program in MODE-SELECT mode, and jumps to the target-address."847 [target-address script]848 (->> script849 (set-target-address target-address)850 (play-moves [(buttons jump-mode)])))853 (def relocated-bootstrap-start854 (+ 90 pokemon-box-1-address))856 (defn-memo relocate-main-bootstrap857 ([] (relocate-main-bootstrap (launch-main-bootstrap-program)))858 ([script]859 (->> script860 (do-nothing 2)861 (write-RAM862 relocated-bootstrap-start863 (main-bootstrap-program864 relocated-bootstrap-start))865 (do-nothing 1)866 (transfer-control relocated-bootstrap-start)867 (do-nothing 1))))869 (defn gen-new-kernel-checkpoint! []870 (write-script! (do-nothing 10 (relocate-main-bootstrap))871 "new-kernel"))873 (defn new-kernel [] (read-script "new-kernel"))875 (def mid-game-data876 (subvec (vec (memory (mid-game)))877 pokemon-list-start878 (+ pokemon-list-start 697)))880 (def mid-game-map-address 0x46BC)882 (defn-memo set-mid-game-data883 ([] (set-mid-game-data (relocate-main-bootstrap)))884 ([script]885 (->> script886 (do-nothing 10)887 (write-RAM pokemon-list-start888 mid-game-data))))889 (defn test-set-data890 ([] (test-set-data (relocate-main-bootstrap)))891 ([script]892 (->> script893 (do-nothing 10)894 (write-RAM pokemon-list-start895 (repeat 500 0xCC)))))897 (defn test-mid-game-transfer []898 (= (subvec (vec (memory (second (set-mid-game-data))))899 pokemon-list-start900 (+ pokemon-list-start 500))901 (subvec (vec (memory (mid-game)))902 pokemon-list-start903 (+ pokemon-list-start 500))))905 (defn-memo return-to-pokemon-kernel906 ([] (return-to-pokemon-kernel (set-mid-game-data)))907 ([script]908 (let [scratch (+ 200 pokemon-box-1-address)909 return-program910 (flatten911 [0xFB912 0xC3913 (reverse (disect-bytes-2 mid-game-map-address))])]914 (->> script915 (write-RAM scratch return-program)916 (transfer-control scratch)917 (do-nothing 1)))))