Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_1.clj @ 594:ea448eecb615
improved route from celadon dept. store to celadon pokemon center.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 01 Sep 2012 12:52:46 -0500 |
parents | daa3497bbe12 |
children | 96ee9d72aeb9 |
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)303 ;; These glitch items have to be sold one at a time304 ;; because the game will only award up to 500000 at305 ;; a time for selling them.306 (sell-held-item 0 1)307 (sell-held-item 0 1)309 (close-menu))))311 (defn-memo floor-two-TMs312 ([] (floor-two-TMs (get-money-floor-two)))313 ([script]314 (->> script315 (set-cursor 0)316 (select-menu-entry)317 (buy-item 2 98) ;; TM02 (razor-wind)318 (buy-item 4 71) ;; TM37 (doubleteam)319 (buy-item 5 63) ;; TM01 (mega-punch)320 (buy-item 6 1) ;; TM05 (mega-kick)321 (buy-item 7 56) ;; TM09 (take-down)322 (close-menu))))324 (defn end-shop-conversation325 [script]326 (->> script327 (wait-until scroll-text [:b])328 (play-moves [[] [:b]])329 close-menu))331 (defn-memo floor-two-more-money332 ([] (floor-two-more-money (floor-two-TMs)))333 ([script]334 (->> script335 (set-cursor 1)336 (select-menu-entry)337 (sell-held-item 0 1)338 (sell-held-item 0 1)339 close-menu340 end-shop-conversation)))342 (defn turn [direction script]343 (->> script344 (first-difference [] direction AF)))346 (defn-memo floor-two-items347 ([] (floor-two-items (floor-two-more-money)))348 ([script]349 (->> script350 (walk [←])351 (turn ↑)352 talk353 select-menu-entry354 (buy-item 5 12) ;; burn heal355 (buy-item 6 55) ;; ice heal356 (buy-item 7 4) ;; awakening357 (buy-item 8 99) ;; parlyz heal358 (buy-item 8 55) ;; parlyz heal359 close-menu360 end-shop-conversation)))362 (defn-memo go-to-floor-three363 ([] (go-to-floor-three (floor-two-items)))364 ([script]365 (->> script366 (walk [→ → → → → → → → → → ↑ ↑ ↑367 → ↑]))))368 (defn-memo get-TM18369 ([] (get-TM18 (go-to-floor-three)))370 ([script]371 (->> script372 (walk [↓ ↓])373 talk374 (scroll-text 3)375 end-text)))377 (defn-memo go-to-floor-four378 ([] (go-to-floor-four (get-TM18)))379 ([script]380 (->> script381 (walk [← ← ← ← ↑ ↑382 ↓ ← ← ↓ ↓ ↓383 ← ← ← ← ←])384 (turn ↓))))386 (defn-memo floor-four-items387 ([] (floor-four-items (go-to-floor-four)))388 ([script]389 (->> script390 talk391 select-menu-entry392 (buy-item 1 23) ;; Fire Stone393 (buy-item 2 98) ;; Thunder Stone394 (buy-item 3 29) ;; Water Stone395 close-menu396 end-shop-conversation)))398 (defn-memo go-to-floor-five399 ([] (go-to-floor-five (floor-four-items)))400 ([script]401 (->> script402 (walk [→ → → → → →403 ↑ ↑ ↑404 → → → → → ↑ ;; leave floor four405 ↓ ← ← ← ← ← ← ← ←406 ↓ ↓ ↓ ← ← ← ]);; go to five's clerk407 (turn ↑))))409 (defn-memo floor-five-items410 ([] (floor-five-items (go-to-floor-five)))411 ([script]412 (->> script413 talk414 select-menu-entry415 (buy-item 0 58) ;; X-Accuracy416 (buy-item 1 99) ;; Guard Spec.417 (buy-item 1 24) ;; Guard Spec.418 close-menu419 end-shop-conversation)))421 (defn-memo go-to-roof422 ([] (go-to-roof (floor-five-items)))423 ([script]424 (->> script425 (walk [→ → → → ↑ ↑ ↑ → → → ↑ ;; leave floor five426 ↓ ← ← ←]) ;; walk to vending machine427 (turn ↑))))429 (defn buy-drink430 "Assumes you're in front of the vending machine. Buys the indicated431 drink."432 [n script]433 (->> script434 (do-nothing 20)435 (play-moves [[:a][:a]])436 scroll-text437 (set-cursor n)438 select-menu-entry439 close-menu))441 (defn-memo roof-drinks442 ([] (roof-drinks (go-to-roof)))443 ([script]444 (->> script445 (buy-drink 0) ;; fresh water (for TM13)446 ;; buy 16 lemonades447 ;; LEMONADE is the best item <3 :)448 (multiple-times 16 (partial buy-drink 2)))))450 (defn-memo get-TM13451 ([] (get-TM13 (roof-drinks)))452 ([script]453 (->> script454 ;; alternate route depending on girl's motions455 ;;(walk [← ← ← ← ← ← ↓])456 (walk [↓ ↓ ↓ ← ← ← ← ← ←])457 (play-moves [[][][][][:a][:a][]])458 (scroll-text 3)459 select-menu-entry460 select-menu-entry461 (scroll-text 6)462 close-menu)))464 (defn-memo to-celadon-poke-center465 ([] (to-celadon-poke-center (get-TM13)))466 ([script]467 (->> script468 ;; alternate route depending on girl's motions469 ;;(walk [↑ → → → → → → → → → ↑]) ; leave roof470 (walk [→ → → → → → → → → ↑ ↑ ↑ ↑])471 (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ←472 ↑ ↑ ↑ ← ← ↑]) ; to elevator474 (walk [→ → ↑ ↑]) ; to controls475 talk476 select-menu-entry ; to floor 1477 (walk [↓ ↓ ←])478 (walk [↓ → ↓ ↓ ↓ ↓ ↓ ↓]) ; leave store479 (walk [→ → → → → → → → → → ↑])480 (walk (repeat 23 →))481 (walk [↑ ↑ ↑ ↑]) ; enter poke center482 (walk [↑ ↑ ↑ → → → → → → → → → →]) ; to computer483 (turn ↑))))485 (defn activate-rlm-pc [script]486 (->> script487 talk488 scroll-text489 ;;wait-for-cursor490 (set-cursor 1)491 select-menu-entry492 (scroll-text 2)))494 (defn begin-deposit [script]495 (->> script496 (set-cursor 1)497 select-menu-entry))499 (defn begin-withdraw [script]500 (->> script501 (set-cursor 0)502 (select-menu-entry)))504 (defn deposit-held-item-named505 [item-name quantity [moves state :as script]]506 (let [index (count507 (take-while508 (fn [[name quant]]509 (or (not= name item-name)510 (< quant quantity)))511 (inventory state)))]512 (println "index" index)513 (deposit-held-item index quantity script)))515 (defn open-held-items516 [script]517 (->> script518 select-menu-entry))520 (defn to-held-items521 [script]522 (->> script523 close-menu524 close-menu525 end-text;;; grr527 activate-start-menu528 open-held-items))530 (defn toss-pc-item [n quantity [moves state :as script]]531 (let [total-quantity (second (nth-pc-item state n))]532 (->> script533 (set-cursor n)534 (select-menu-entry 1)535 (set-quantity total-quantity quantity)536 (delayed-difference [] [:a] 100 #(search-string % "Is"))537 (scroll-text)538 select-menu-entry539 (scroll-text))))541 (defn-memo hacking-1542 ([] (hacking-1 (to-celadon-poke-center)))543 ([script]544 (->> script545 activate-rlm-pc546 begin-deposit547 (deposit-held-item-named 0x00 30)548 (deposit-held-item-named :TM01 63)549 (deposit-held-item-named :awakening 4)550 (deposit-held-item-named :thunderstone 98)551 (deposit-held-item-named :TM09 55)552 (deposit-held-item-named 0x00 55))))554 (defn-memo hacking-2555 ([] (hacking-2 (hacking-1)))556 ([script]557 (->> script558 (to-held-items)559 (toss-held-item 0 166) ;; discard cruft560 close-menu561 close-menu)))563 (defn-memo hacking-3564 ([] (hacking-3 (hacking-2)))565 ([script]566 (->> script567 activate-rlm-pc568 begin-withdraw569 (widthdraw-pc-item 0 99)570 (widthdraw-pc-item 0 1)571 (widthdraw-pc-item 2 0xFE)572 (widthdraw-pc-item 3 0xFE)573 close-menu)))575 (defn-memo hacking-4576 ([] (hacking-4 (hacking-3)))577 ([script]578 (->> script579 begin-deposit580 (deposit-held-item 19 243)581 (deposit-held-item-named :lemonade 16)582 (deposit-held-item 18 224))))584 (defn-memo hacking-5585 "clean out the held-item list again"586 ([] (hacking-5 (hacking-4)))587 ([script]588 (->> script589 (to-held-items)590 (toss-held-item 18 30)591 (toss-held-item 17 1)592 close-menu593 close-menu)))595 (defn-memo hacking-6596 ([] (hacking-6 (hacking-5)))597 ([script]598 (->> script599 activate-rlm-pc600 begin-withdraw601 (widthdraw-pc-item 4 0xFE)602 (widthdraw-pc-item 5 0xFE)603 (widthdraw-pc-item 6 0xFE)604 close-menu)))606 (defn-memo hacking-7607 ([] (hacking-7 (hacking-6)))608 ([script]609 (->> script610 begin-deposit611 (deposit-held-item 19 240)612 (deposit-held-item 18 230)613 (deposit-held-item-named :parlyz-heal 55)614 (deposit-held-item 17 184)615 (deposit-held-item 17 40)616 (deposit-held-item-named :TM37 71)617 (deposit-held-item-named :ice-heal 55)618 (deposit-held-item-named :fire-stone 23)619 (deposit-held-item-named :burn-heal 12)620 ;; as a special case, /don't/ close the menu.621 )))623 (defn-memo hacking-8624 "Clear cruft away from held item list."625 ([] (hacking-8 (hacking-7)))626 ([script]627 (->> script628 to-held-items629 (toss-held-item 15 1)630 (toss-held-item 14 1)631 (toss-held-item 13 1)632 close-menu633 close-menu)))635 (defn-memo hacking-9636 ([] (hacking-9 (hacking-8)))637 ([script]638 (->> script639 activate-rlm-pc640 begin-withdraw641 (widthdraw-pc-item 7 0xFE)642 (widthdraw-pc-item 8 0xFC)643 (widthdraw-pc-item 8 1)644 (widthdraw-pc-item 8 1)645 (widthdraw-pc-item 9 0xFE)646 (multiple-times647 7648 (partial combine-pc-items 2))649 close-menu)))651 (defn-memo hacking-10652 ([] (hacking-10 (hacking-9)))653 ([script]654 (->> script655 begin-deposit656 (deposit-held-item 17 230)657 (deposit-held-item-named :parlyz-heal 55)658 (deposit-held-item 14 178)659 (deposit-held-item-named :water-stone 29)660 (deposit-held-item 14 32)661 (deposit-held-item-named :TM18 1)662 (deposit-held-item 13 1)663 (deposit-held-item 13 191)664 (deposit-held-item-named :TM02 98)665 (deposit-held-item-named :TM09 1)666 close-menu)))668 (defn-memo hacking-11669 ([] (hacking-11 (hacking-10)))670 ([script]671 (->> script672 begin-withdraw673 (widthdraw-pc-item 3 0xFE)674 (widthdraw-pc-item 4 0xFE)675 (widthdraw-pc-item 5 1)676 (widthdraw-pc-item 5 1)677 (widthdraw-pc-item 5 1)678 (widthdraw-pc-item 5 0xFB)679 (multiple-times680 3681 (partial combine-pc-items 2))682 close-menu)))684 (defn-memo hacking-12685 ([] (hacking-12 (hacking-11)))686 ([script]687 (->> script688 begin-deposit689 (deposit-held-item 18 203)690 (deposit-held-item-named :guard-spec 87)691 (deposit-held-item-named :guard-spec 24)692 (deposit-held-item-named :TM05 1)693 (multiple-times694 8695 (partial deposit-held-item 14 1))696 (deposit-held-item 14 55)697 (deposit-held-item-named :x-accuracy 58)698 (deposit-held-item 14 38)699 (deposit-held-item-named :TM13 1)700 (deposit-held-item 13 1)701 (deposit-held-item 13 233)702 close-menu)))704 (defn-memo hacking-13705 ([] (hacking-13 (hacking-12)))706 ([script]707 (->> script708 (set-cursor-relative 1)709 (select-menu-entry)710 (toss-pc-item 1 1)711 (toss-pc-item 0 156)712 (toss-pc-item 0 11))))714 (defn confirm-pattern []715 (let [start-address (inc pc-item-list-start)716 target-pattern (pc-item-writer-program)717 actual-pattern718 (subvec (vec (memory (second (hacking-13))))719 start-address720 (+ start-address (count target-pattern)))]721 (println target-pattern)722 (println actual-pattern)723 (= target-pattern actual-pattern)))725 (defn-memo go-to-mansion-for-the-lulz726 ([] (go-to-mansion-for-the-lulz (hacking-13)))727 ([script]728 (->> script729 close-menu730 close-menu731 end-text ;;grr732 (walk [↓ ← ← ← ← ← ← ← ← ← ↓ ↓ ↓])733 (walk (repeat 17 ←))734 (walk [↑ → → → → ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])735 (walk [↓ ← ↑])736 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓737 ← ← ← ← ↑ ↑ ↑ ← ↑])738 (talk)739 (scroll-text 2)740 (do-nothing 100)741 close-menu)))743 (defn-memo launch-bootstrap-program744 ([] (launch-bootstrap-program745 (go-to-mansion-for-the-lulz)))746 ([script]747 (->> script748 ;; must corrupt item list again by switching pokemon749 activate-start-menu ;; \750 (set-cursor 0) ;; |751 select-menu-entry ;; |752 select-menu-entry ;; |753 (set-cursor 1) ;; | -- switch 9th pokemon754 select-menu-entry ;; | with 4th pokemon755 (set-cursor 3) ;; |756 select-menu-entry ;; |757 close-menu ;; /758 ;; now, open items and set map-function to759 ;; the program inside the item-computer.760 (set-cursor 1)761 (select-menu-entry)762 (toss-held-item 22 12)763 (switch-held-items 22 40)764 close-all-menus)))766 (defn regen-control-checkpoint!767 [] (write-script! (launch-bootstrap-program) "control-checkpoint"))769 (defn control-checkpoint []770 (read-script "control-checkpoint"))772 (def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF])774 (defn test-pattern-writing775 ([] (test-pattern-writing increasing-pattern))776 ([pattern]777 (let [moves (bootstrap-pattern pattern)778 pattern-insertion779 (->> (launch-bootstrap-program)780 (play-moves781 (take 100 moves)))]782 (println "Input Pattern:")783 (apply println (map #(format "0x%02X" %) pattern))784 (println "\nMemory Listing:")785 (print-listing (second pattern-insertion)786 0xD162 (+ 0xD162 (count pattern)))787 (= (subvec (vec (memory (second pattern-insertion)))788 0xD162 (+ 0xD162 (count pattern)))789 pattern))))791 (defn-memo launch-main-bootstrap-program792 ([] (launch-main-bootstrap-program793 (control-checkpoint)794 ;;(launch-bootstrap-program)795 ))796 ([script]797 (->> script798 (play-moves799 (bootstrap-pattern (main-bootstrap-program)))800 (play-moves801 (take 253 (interleave (repeat 1000 [:b])802 (repeat 1000 [])))))))803 (def bootstrap-start pokemon-list-start)805 (defn test-main-bootstrap-integrety806 []807 (assert808 (= (main-bootstrap-program)809 (subvec810 (vec (memory (second (launch-main-bootstrap-program))))811 pokemon-list-start812 (+ pokemon-list-start (count (main-bootstrap-program)))))))814 (defn set-target-address815 "Assumes that the game is under control of the main-bootstrap816 program in MODE-SELECT mode, and sets the target address to which817 jumps/writes will occur."818 [target-address script]819 (let [[target-high target-low] (disect-bytes-2 target-address)]820 (->> script821 (play-moves822 (map buttons823 [set-H-mode target-high 0x00824 set-L-mode target-low 0x00])))))826 (defn write-RAM-segment827 "Assumes that the game is under control of the main-bootstrap828 program in MODE-SELECT mode and that target-address has been829 appropriately set, and writes 255 bytes or less to RAM."830 [segment script]831 (->> script832 (play-moves833 (map buttons834 [write-mode (count segment)]))835 (play-moves (map buttons segment))836 (play-moves [[]])))838 (defn write-RAM839 "Assumes that the game is under control of the main-bootstrap840 program in MODE-SELECT mode, and rewrites RAM starting at841 'start-address with 'new-ram."842 [start-address new-ram script]843 (loop [s (set-target-address start-address script)844 to-write new-ram]845 (if (< (count to-write) 0x100)846 (write-RAM-segment to-write s)847 (recur848 (write-RAM-segment (take 0xFF to-write) s)849 (drop 0xFF to-write)))))851 (defn transfer-control852 "Assumes that the game is under control of the main-bootstrap853 program in MODE-SELECT mode, and jumps to the target-address."854 [target-address script]855 (->> script856 (set-target-address target-address)857 (play-moves [(buttons jump-mode)])))860 (def relocated-bootstrap-start861 (+ 90 pokemon-box-1-address))863 (defn-memo relocate-main-bootstrap864 ([] (relocate-main-bootstrap (launch-main-bootstrap-program)))865 ([script]866 (->> script867 (do-nothing 2)868 (write-RAM869 relocated-bootstrap-start870 (main-bootstrap-program871 relocated-bootstrap-start))872 (do-nothing 1)873 (transfer-control relocated-bootstrap-start)874 (do-nothing 1))))876 (defn gen-new-kernel-checkpoint! []877 (write-script! (do-nothing 10 (relocate-main-bootstrap))878 "new-kernel"))880 (defn new-kernel [] (read-script "new-kernel"))882 (def mid-game-data883 (subvec (vec (memory (mid-game)))884 pokemon-list-start885 (+ pokemon-list-start 697)))887 (def mid-game-map-address 0x46BC)889 (defn-memo set-mid-game-data890 ([] (set-mid-game-data (relocate-main-bootstrap)))891 ([script]892 (->> script893 (do-nothing 10)894 (write-RAM pokemon-list-start895 mid-game-data))))896 (defn test-set-data897 ([] (test-set-data (relocate-main-bootstrap)))898 ([script]899 (->> script900 (do-nothing 10)901 (write-RAM pokemon-list-start902 (repeat 500 0xCC)))))904 (defn test-mid-game-transfer []905 (= (subvec (vec (memory (second (set-mid-game-data))))906 pokemon-list-start907 (+ pokemon-list-start 500))908 (subvec (vec (memory (mid-game)))909 pokemon-list-start910 (+ pokemon-list-start 500))))912 (defn-memo return-to-pokemon-kernel913 ([] (return-to-pokemon-kernel (set-mid-game-data)))914 ([script]915 (let [scratch (+ 200 pokemon-box-1-address)916 return-program917 (flatten918 [0xFB919 0xC3920 (reverse (disect-bytes-2 mid-game-map-address))])]921 (->> script922 (write-RAM scratch return-program)923 (transfer-control scratch)924 (do-nothing 1)))))