Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_1.clj @ 563:a70d9223f6eb
added blank glyph.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 31 Aug 2012 09:37:18 -0500 |
parents | cd557c922cec |
children | daa3497bbe12 |
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-memo 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 (first-difference [] ↑ AF))))285 (defn talk286 "Assumes that you are facing something that initiates text and287 causes it to do so."288 [script]289 (->> script290 (delayed-difference [] [:a] 100291 first-character)))293 (defn-memo get-money-floor-two294 ([] (get-money-floor-two (go-to-floor-two)))295 ([script]296 (->> script297 talk298 (set-cursor 1)299 (select-menu-entry)300 (sell-held-item 0 1)301 (sell-held-item 0 1)302 (close-menu))))304 (defn-memo floor-two-TMs305 ([] (floor-two-TMs (get-money-floor-two)))306 ([script]307 (->> script308 (set-cursor 0)309 (select-menu-entry)310 (buy-item 2 98) ;; TM02 (razor-wind)311 (buy-item 4 71) ;; TM37 (doubleteam)312 (buy-item 5 63) ;; TM01 (mega-punch)313 (buy-item 6 1) ;; TM05 (mega-kick)314 (buy-item 7 56) ;; TM09 (take-down)315 (close-menu))))317 (defn end-shop-conversation318 [script]319 (->> script320 (wait-until scroll-text [:b])321 (play-moves [[] [:b]])322 close-menu))324 (defn-memo floor-two-more-money325 ([] (floor-two-more-money (floor-two-TMs)))326 ([script]327 (->> script328 (set-cursor 1)329 (select-menu-entry)330 (sell-held-item 0 1)331 (sell-held-item 0 1)332 close-menu333 end-shop-conversation)))335 (defn turn [direction script]336 (->> script337 (first-difference [] direction AF)))339 (defn-memo floor-two-items340 ([] (floor-two-items (floor-two-more-money)))341 ([script]342 (->> script343 (walk [←])344 (turn ↑)345 talk346 select-menu-entry347 (buy-item 5 12) ;; burn heal348 (buy-item 6 55) ;; ice heal349 (buy-item 7 4) ;; awakening350 (buy-item 8 99) ;; parlyz heal351 (buy-item 8 55) ;; parlyz heal352 close-menu353 end-shop-conversation)))355 (defn-memo go-to-floor-three356 ([] (go-to-floor-three (floor-two-items)))357 ([script]358 (->> script359 (walk [→ → → → → → → → → → ↑ ↑ ↑360 → ↑]))))361 (defn-memo get-TM18362 ([] (get-TM18 (go-to-floor-three)))363 ([script]364 (->> script365 (walk [↓ ↓])366 talk367 (scroll-text 3)368 end-text)))370 (defn-memo go-to-floor-four371 ([] (go-to-floor-four (get-TM18)))372 ([script]373 (->> script374 (walk [← ← ← ← ↑ ↑375 ↓ ← ← ↓ ↓ ↓376 ← ← ← ← ←])377 (turn ↓))))379 (defn-memo floor-four-items380 ([] (floor-four-items (go-to-floor-four)))381 ([script]382 (->> script383 talk384 select-menu-entry385 (buy-item 1 23) ;; Fire Stone386 (buy-item 2 98) ;; Thunder Stone387 (buy-item 3 29) ;; Water Stone388 close-menu389 end-shop-conversation)))391 (defn-memo go-to-floor-five392 ([] (go-to-floor-five (floor-four-items)))393 ([script]394 (->> script395 (walk [→ → → → → →396 ↑ ↑ ↑397 → → → → → ↑ ;; leave floor four398 ↓ ← ← ← ← ← ← ← ←399 ↓ ↓ ↓ ← ← ← ]);; go to five's clerk400 (turn ↑))))402 (defn-memo floor-five-items403 ([] (floor-five-items (go-to-floor-five)))404 ([script]405 (->> script406 talk407 select-menu-entry408 (buy-item 0 58) ;; X-Accuracy409 (buy-item 1 99) ;; Guard Spec.410 (buy-item 1 24) ;; Guard Spec.411 close-menu412 end-shop-conversation)))414 (defn-memo go-to-roof415 ([] (go-to-roof (floor-five-items)))416 ([script]417 (->> script418 (walk [→ → → → ↑ ↑ ↑ → → → ↑ ;; leave floor five419 ↓ ← ← ←]) ;; walk to vending machine420 (turn ↑))))422 (defn buy-drink423 "Assumes you're in front of the vending machine. Buys the indicated424 drink."425 [n script]426 (->> script427 (do-nothing 20)428 (play-moves [[:a][:a]])429 scroll-text430 (set-cursor n)431 select-menu-entry432 close-menu))434 (defn-memo roof-drinks435 ([] (roof-drinks (go-to-roof)))436 ([script]437 (->> script438 (buy-drink 0) ;; fresh water (for TM13)439 ;; buy 16 lemonades440 ;; LEMONADE is the best item <3 :)441 (multiple-times 16 (partial buy-drink 2)))))443 (defn-memo get-TM13444 ([] (get-TM13 (roof-drinks)))445 ([script]446 (->> script447 ;;(walk [← ← ← ← ← ← ↓])448 (walk [↓ ↓ ↓ ← ← ← ← ← ←])449 (play-moves [[][][][][:a][:a][]])450 (scroll-text 3)451 select-menu-entry452 select-menu-entry453 (scroll-text 6)454 close-menu)))456 (defn-memo to-celadon-poke-center457 ([] (to-celadon-poke-center (get-TM13)))458 ([script]459 (->> script460 ;;(walk [↑ → → → → → → → → → ↑]) ; leave roof461 (walk [→ → → → → → → → → ↑ ↑ ↑ ↑])462 (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ←463 ↑ ↑ ↑ ← ← ↑]) ; to elevator465 (walk [→ → ↑ ↑]) ; to controls466 talk467 select-menu-entry ; to floor 1468 (walk [↓ ↓ ← ←])469 (walk [↓ → ↓ ↓ ↓ ↓ ↓ ↓]) ; leave store470 (walk [↓ → → → → → → → → → → ↑ ↑])471 (walk (repeat 23 →))472 (walk [↑ ↑ ↑ ↑]) ; enter poke center473 (walk [↑ ↑ ↑ → → → → → → → → → →]) ; to computer474 (turn ↑))))476 (defn activate-rlm-pc [script]477 (->> script478 talk479 scroll-text480 ;;wait-for-cursor481 (set-cursor 1)482 select-menu-entry483 (scroll-text 2)))485 (defn begin-deposit [script]486 (->> script487 (set-cursor 1)488 select-menu-entry))490 (defn begin-withdraw [script]491 (->> script492 (set-cursor 0)493 (select-menu-entry)))495 (defn deposit-held-item-named496 [item-name quantity [moves state :as script]]497 (let [index (count498 (take-while499 (fn [[name quant]]500 (or (not= name item-name)501 (< quant quantity)))502 (inventory state)))]503 (println "index" index)504 (deposit-held-item index quantity script)))506 (defn open-held-items507 [script]508 (->> script509 select-menu-entry))511 (defn to-held-items512 [script]513 (->> script514 close-menu515 close-menu516 end-text;;; grr518 activate-start-menu519 open-held-items))521 (defn toss-pc-item [n quantity [moves state :as script]]522 (let [total-quantity (second (nth-pc-item state n))]523 (->> script524 (set-cursor n)525 (select-menu-entry 1)526 (set-quantity total-quantity quantity)527 (delayed-difference [] [:a] 100 #(search-string % "Is"))528 (scroll-text)529 select-menu-entry530 (scroll-text))))532 (defn-memo hacking-1533 ([] (hacking-1 (to-celadon-poke-center)))534 ([script]535 (->> script536 activate-rlm-pc537 begin-deposit538 (deposit-held-item-named 0x00 30)539 (deposit-held-item-named :TM01 63)540 (deposit-held-item-named :awakening 4)541 (deposit-held-item-named :thunderstone 98)542 (deposit-held-item-named :TM09 55)543 (deposit-held-item-named 0x00 55))))545 (defn-memo hacking-2546 ([] (hacking-2 (hacking-1)))547 ([script]548 (->> script549 (to-held-items)550 (toss-held-item 0 166) ;; discard cruft551 close-menu552 close-menu)))554 (defn-memo hacking-3555 ([] (hacking-3 (hacking-2)))556 ([script]557 (->> script558 activate-rlm-pc559 begin-withdraw560 (widthdraw-pc-item 0 99)561 (widthdraw-pc-item 0 1)562 (widthdraw-pc-item 2 0xFE)563 (widthdraw-pc-item 3 0xFE)564 close-menu)))566 (defn-memo hacking-4567 ([] (hacking-4 (hacking-3)))568 ([script]569 (->> script570 begin-deposit571 (deposit-held-item 19 243)572 (deposit-held-item-named :lemonade 16)573 (deposit-held-item 18 224))))575 (defn-memo hacking-5576 "clean out the held-item list again"577 ([] (hacking-5 (hacking-4)))578 ([script]579 (->> script580 (to-held-items)581 (toss-held-item 18 30)582 (toss-held-item 17 1)583 close-menu584 close-menu)))586 (defn-memo hacking-6587 ([] (hacking-6 (hacking-5)))588 ([script]589 (->> script590 activate-rlm-pc591 begin-withdraw592 (widthdraw-pc-item 4 0xFE)593 (widthdraw-pc-item 5 0xFE)594 (widthdraw-pc-item 6 0xFE)595 close-menu)))597 (defn-memo hacking-7598 ([] (hacking-7 (hacking-6)))599 ([script]600 (->> script601 begin-deposit602 (deposit-held-item 19 240)603 (deposit-held-item 18 230)604 (deposit-held-item-named :parlyz-heal 55)605 (deposit-held-item 17 184)606 (deposit-held-item 17 40)607 (deposit-held-item-named :TM37 71)608 (deposit-held-item-named :ice-heal 55)609 (deposit-held-item-named :fire-stone 23)610 (deposit-held-item-named :burn-heal 12)611 ;; as a special case, /don't/ close the menu.612 )))614 (defn-memo hacking-8615 "Clear cruft away from held item list."616 ([] (hacking-8 (hacking-7)))617 ([script]618 (->> script619 to-held-items620 (toss-held-item 15 1)621 (toss-held-item 14 1)622 (toss-held-item 13 1)623 close-menu624 close-menu)))626 (defn-memo hacking-9627 ([] (hacking-9 (hacking-8)))628 ([script]629 (->> script630 activate-rlm-pc631 begin-withdraw632 (widthdraw-pc-item 7 0xFE)633 (widthdraw-pc-item 8 0xFC)634 (widthdraw-pc-item 8 1)635 (widthdraw-pc-item 8 1)636 (widthdraw-pc-item 9 0xFE)637 (multiple-times638 7639 (partial combine-pc-items 2))640 close-menu)))642 (defn-memo hacking-10643 ([] (hacking-10 (hacking-9)))644 ([script]645 (->> script646 begin-deposit647 (deposit-held-item 17 230)648 (deposit-held-item-named :parlyz-heal 55)649 (deposit-held-item 14 178)650 (deposit-held-item-named :water-stone 29)651 (deposit-held-item 14 32)652 (deposit-held-item-named :TM18 1)653 (deposit-held-item 13 1)654 (deposit-held-item 13 191)655 (deposit-held-item-named :TM02 98)656 (deposit-held-item-named :TM09 1)657 close-menu)))659 (defn-memo hacking-11660 ([] (hacking-11 (hacking-10)))661 ([script]662 (->> script663 begin-withdraw664 (widthdraw-pc-item 3 0xFE)665 (widthdraw-pc-item 4 0xFE)666 (widthdraw-pc-item 5 1)667 (widthdraw-pc-item 5 1)668 (widthdraw-pc-item 5 1)669 (widthdraw-pc-item 5 0xFB)670 (multiple-times671 3672 (partial combine-pc-items 2))673 close-menu)))675 (defn-memo hacking-12676 ([] (hacking-12 (hacking-11)))677 ([script]678 (->> script679 begin-deposit680 (deposit-held-item 18 203)681 (deposit-held-item-named :guard-spec 87)682 (deposit-held-item-named :guard-spec 24)683 (deposit-held-item-named :TM05 1)684 (multiple-times685 8686 (partial deposit-held-item 14 1))687 (deposit-held-item 14 55)688 (deposit-held-item-named :x-accuracy 58)689 (deposit-held-item 14 38)690 (deposit-held-item-named :TM13 1)691 (deposit-held-item 13 1)692 (deposit-held-item 13 233)693 close-menu)))695 (defn-memo hacking-13696 ([] (hacking-13 (hacking-12)))697 ([script]698 (->> script699 (set-cursor-relative 1)700 (select-menu-entry)701 (toss-pc-item 1 1)702 (toss-pc-item 0 156)703 (toss-pc-item 0 11))))705 (defn confirm-pattern []706 (let [start-address (inc pc-item-list-start)707 target-pattern (pc-item-writer-program)708 actual-pattern709 (subvec (vec (memory (second (hacking-13))))710 start-address711 (+ start-address (count target-pattern)))]712 (println target-pattern)713 (println actual-pattern)714 (= target-pattern actual-pattern)))716 (defn-memo go-to-mansion-for-the-lulz717 ([] (go-to-mansion-for-the-lulz (hacking-13)))718 ([script]719 (->> script720 close-menu721 close-menu722 end-text ;;grr723 (walk [↓ ← ← ← ← ← ← ← ← ← ↓ ↓ ↓])724 (walk (repeat 17 ←))725 (walk [↑ → → → → ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])726 (walk [↓ ← ↑])727 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓728 ← ← ← ← ↑ ↑ ↑ ← ↑])729 (talk)730 (scroll-text 2)731 (do-nothing 100)732 close-menu)))734 (defn-memo launch-bootstrap-program735 ([] (launch-bootstrap-program736 (go-to-mansion-for-the-lulz)))737 ([script]738 (->> script739 ;; must corrupt item list again by switching pokemon740 activate-start-menu ;; \741 (set-cursor 0) ;; |742 select-menu-entry ;; |743 select-menu-entry ;; |744 (set-cursor 1) ;; | -- switch 9th pokemon745 select-menu-entry ;; | with 4th pokemon746 (set-cursor 3) ;; |747 select-menu-entry ;; |748 close-menu ;; /749 ;; now, open items and set map-function to750 ;; the program inside the item-computer.751 (set-cursor 1)752 (select-menu-entry)753 (toss-held-item 22 12)754 (switch-held-items 22 40)755 close-all-menus)))757 (defn regen-control-checkpoint!758 [] (write-script! (launch-bootstrap-program) "control-checkpoint"))760 (defn control-checkpoint []761 (read-script "control-checkpoint"))763 (def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF])765 (defn test-pattern-writing766 ([] (test-pattern-writing increasing-pattern))767 ([pattern]768 (let [moves (bootstrap-pattern pattern)769 pattern-insertion770 (->> (launch-bootstrap-program)771 (play-moves772 (take 100 moves)))]773 (println "Input Pattern:")774 (apply println (map #(format "0x%02X" %) pattern))775 (println "\nMemory Listing:")776 (print-listing (second pattern-insertion)777 0xD162 (+ 0xD162 (count pattern)))778 (= (subvec (vec (memory (second pattern-insertion)))779 0xD162 (+ 0xD162 (count pattern)))780 pattern))))782 (defn-memo launch-main-bootstrap-program783 ([] (launch-main-bootstrap-program784 (control-checkpoint)785 ;;(launch-bootstrap-program)786 ))787 ([script]788 (->> script789 (play-moves790 (bootstrap-pattern (main-bootstrap-program)))791 (play-moves792 (take 253 (interleave (repeat 1000 [:b])793 (repeat 1000 [])))))))794 (def bootstrap-start pokemon-list-start)796 (defn test-main-bootstrap-integrety797 []798 (assert799 (= (main-bootstrap-program)800 (subvec801 (vec (memory (second (launch-main-bootstrap-program))))802 pokemon-list-start803 (+ pokemon-list-start (count (main-bootstrap-program)))))))805 (defn set-target-address806 "Assumes that the game is under control of the main-bootstrap807 program in MODE-SELECT mode, and sets the target address to which808 jumps/writes will occur."809 [target-address script]810 (let [[target-high target-low] (disect-bytes-2 target-address)]811 (->> script812 (play-moves813 (map buttons814 [set-H-mode target-high 0x00815 set-L-mode target-low 0x00])))))817 (defn write-RAM-segment818 "Assumes that the game is under control of the main-bootstrap819 program in MODE-SELECT mode and that target-address has been820 appropriately set, and writes 255 bytes or less to RAM."821 [segment script]822 (->> script823 (play-moves824 (map buttons825 [write-mode (count segment)]))826 (play-moves (map buttons segment))827 (play-moves [[]])))829 (defn write-RAM830 "Assumes that the game is under control of the main-bootstrap831 program in MODE-SELECT mode, and rewrites RAM starting at832 'start-address with 'new-ram."833 [start-address new-ram script]834 (loop [s (set-target-address start-address script)835 to-write new-ram]836 (if (< (count to-write) 0x100)837 (write-RAM-segment to-write s)838 (recur839 (write-RAM-segment (take 0xFF to-write) s)840 (drop 0xFF to-write)))))842 (defn transfer-control843 "Assumes that the game is under control of the main-bootstrap844 program in MODE-SELECT mode, and jumps to the target-address."845 [target-address script]846 (->> script847 (set-target-address target-address)848 (play-moves [(buttons jump-mode)])))851 (def relocated-bootstrap-start852 (+ 90 pokemon-box-1-address))854 (defn-memo relocate-main-bootstrap855 ([] (relocate-main-bootstrap (launch-main-bootstrap-program)))856 ([script]857 (->> script858 (do-nothing 2)859 (write-RAM860 relocated-bootstrap-start861 (main-bootstrap-program862 relocated-bootstrap-start))863 (do-nothing 1)864 (transfer-control relocated-bootstrap-start)865 (do-nothing 1))))867 (defn gen-new-kernel-checkpoint! []868 (write-script! (do-nothing 10 (relocate-main-bootstrap))869 "new-kernel"))871 (defn new-kernel [] (read-script "new-kernel"))873 (def mid-game-data874 (subvec (vec (memory (mid-game)))875 pokemon-list-start876 (+ pokemon-list-start 697)))878 (def mid-game-map-address 0x46BC)880 (defn-memo set-mid-game-data881 ([] (set-mid-game-data (relocate-main-bootstrap)))882 ([script]883 (->> script884 (do-nothing 10)885 (write-RAM pokemon-list-start886 mid-game-data))))887 (defn test-set-data888 ([] (test-set-data (relocate-main-bootstrap)))889 ([script]890 (->> script891 (do-nothing 10)892 (write-RAM pokemon-list-start893 (repeat 500 0xCC)))))895 (defn test-mid-game-transfer []896 (= (subvec (vec (memory (second (set-mid-game-data))))897 pokemon-list-start898 (+ pokemon-list-start 500))899 (subvec (vec (memory (mid-game)))900 pokemon-list-start901 (+ pokemon-list-start 500))))903 (defn-memo return-to-pokemon-kernel904 ([] (return-to-pokemon-kernel (set-mid-game-data)))905 ([script]906 (let [scratch (+ 200 pokemon-box-1-address)907 return-program908 (flatten909 [0xFB910 0xC3911 (reverse (disect-bytes-2 mid-game-map-address))])]912 (->> script913 (write-RAM scratch return-program)914 (transfer-control scratch)915 (do-nothing 1)))))