Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_1.clj @ 620:1b52b14868d3 tip
merge.
author | rlm <rlm@aurellem.org> |
---|---|
date | Sun, 07 Feb 2016 23:16:04 -0800 |
parents | 54644b08da1a |
children |
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-memo 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 close-celadon-computer-menu521 [script]522 ;; this part was determined via manual binary search523 ;; because for some reason the current-depth RAM value524 ;; is the same for both the final menu being either on525 ;; or off.526 (->> script527 (play-moves528 (concat (repeat 4 []) [[:b]]))))530 (defn to-held-items531 [script]532 (->> script533 close-menu534 close-menu535 close-celadon-computer-menu536 activate-start-menu537 open-held-items))539 (defn toss-pc-item [n quantity [moves state :as script]]540 (let [total-quantity (second (nth-pc-item state n))]541 (->> script542 (set-cursor n)543 (select-menu-entry 1)544 (set-quantity total-quantity quantity)545 (delayed-difference [] [:a] 100 #(search-string % "Is"))546 (scroll-text)547 select-menu-entry548 (scroll-text))))550 (defn-memo hacking-1551 ([] (hacking-1 (to-celadon-poke-center)))552 ([script]553 (->> script554 activate-rlm-pc555 begin-deposit556 (deposit-held-item-named 0x00 30)557 (deposit-held-item-named :TM01 63)558 (deposit-held-item-named :awakening 4)559 (deposit-held-item-named :thunderstone 98)560 (deposit-held-item-named :TM09 55)561 (deposit-held-item-named 0x00 55))))563 (defn-memo hacking-2564 ([] (hacking-2 (hacking-1)))565 ([script]566 (->> script567 (to-held-items)568 (toss-held-item 0 166) ;; discard cruft569 close-menu570 close-menu)))572 (defn-memo hacking-3573 ([] (hacking-3 (hacking-2)))574 ([script]575 (->> script576 activate-rlm-pc577 begin-withdraw578 (widthdraw-pc-item 0 99)579 (widthdraw-pc-item 0 1)580 (widthdraw-pc-item 2 0xFE)581 (widthdraw-pc-item 3 0xFE)582 close-menu)))584 (defn-memo hacking-4585 ([] (hacking-4 (hacking-3)))586 ([script]587 (->> script588 begin-deposit589 (deposit-held-item 19 243)590 (deposit-held-item-named :lemonade 16)591 (deposit-held-item 18 224))))593 (defn-memo hacking-5594 "clean out the held-item list again"595 ([] (hacking-5 (hacking-4)))596 ([script]597 (->> script598 (to-held-items)599 (toss-held-item 18 30)600 (toss-held-item 17 1)601 close-menu602 close-menu)))604 (defn-memo hacking-6605 ([] (hacking-6 (hacking-5)))606 ([script]607 (->> script608 activate-rlm-pc609 begin-withdraw610 (widthdraw-pc-item 4 0xFE)611 (widthdraw-pc-item 5 0xFE)612 (widthdraw-pc-item 6 0xFE)613 close-menu)))615 (defn-memo hacking-7616 ([] (hacking-7 (hacking-6)))617 ([script]618 (->> script619 begin-deposit620 (deposit-held-item 19 240)621 (deposit-held-item 18 230)622 (deposit-held-item-named :parlyz-heal 55)623 (deposit-held-item 17 184)624 (deposit-held-item 17 40)625 (deposit-held-item-named :TM37 71)626 (deposit-held-item-named :ice-heal 55)627 (deposit-held-item-named :fire-stone 23)628 (deposit-held-item-named :burn-heal 12)629 ;; as a special case, /don't/ close the menu.630 )))632 (defn-memo hacking-8633 "Clear cruft away from held item list."634 ([] (hacking-8 (hacking-7)))635 ([script]636 (->> script637 to-held-items638 (toss-held-item 15 1)639 (toss-held-item 14 1)640 (toss-held-item 13 1)641 close-menu642 close-menu)))644 (defn-memo hacking-9645 ([] (hacking-9 (hacking-8)))646 ([script]647 (->> script648 activate-rlm-pc649 begin-withdraw650 (widthdraw-pc-item 7 0xFE)651 (widthdraw-pc-item 8 0xFC)652 (widthdraw-pc-item 8 1)653 (widthdraw-pc-item 8 1)654 (widthdraw-pc-item 9 0xFE)655 (multiple-times656 7657 (partial combine-pc-items 2))658 close-menu)))660 (defn-memo hacking-10661 ([] (hacking-10 (hacking-9)))662 ([script]663 (->> script664 begin-deposit665 (deposit-held-item 17 230)666 (deposit-held-item-named :parlyz-heal 55)667 (deposit-held-item 14 178)668 (deposit-held-item-named :water-stone 29)669 (deposit-held-item 14 32)670 (deposit-held-item-named :TM18 1)671 (deposit-held-item 13 1)672 (deposit-held-item 13 191)673 (deposit-held-item-named :TM02 98)674 (deposit-held-item-named :TM09 1)675 close-menu)))677 (defn-memo hacking-11678 ([] (hacking-11 (hacking-10)))679 ([script]680 (->> script681 begin-withdraw682 (widthdraw-pc-item 3 0xFE)683 (widthdraw-pc-item 4 0xFE)684 (widthdraw-pc-item 5 1)685 (widthdraw-pc-item 5 1)686 (widthdraw-pc-item 5 1)687 (widthdraw-pc-item 5 0xFB)688 (multiple-times689 3690 (partial combine-pc-items 2))691 close-menu)))693 (defn-memo hacking-12694 ([] (hacking-12 (hacking-11)))695 ([script]696 (->> script697 begin-deposit698 (deposit-held-item 18 203)699 (deposit-held-item-named :guard-spec 87)700 (deposit-held-item-named :guard-spec 24)701 (deposit-held-item-named :TM05 1)702 (multiple-times703 8704 (partial deposit-held-item 14 1))705 (deposit-held-item 14 55)706 (deposit-held-item-named :x-accuracy 58)707 (deposit-held-item 14 38)708 (deposit-held-item-named :TM13 1)709 (deposit-held-item 13 1)710 (deposit-held-item 13 233)711 close-menu)))713 (defn-memo hacking-13714 ([] (hacking-13 (hacking-12)))715 ([script]716 (->> script717 (set-cursor-relative 1)718 (select-menu-entry)719 (toss-pc-item 1 1)720 (toss-pc-item 0 156)721 (toss-pc-item 0 11))))723 (defn confirm-pattern []724 (let [start-address (inc pc-item-list-start)725 target-pattern (pc-item-writer-program)726 actual-pattern727 (subvec (vec (memory (second (hacking-13))))728 start-address729 (+ start-address (count target-pattern)))]730 (println target-pattern)731 (println actual-pattern)732 (= target-pattern actual-pattern)))734 (defn-memo go-to-mansion-for-the-lulz735 ([] (go-to-mansion-for-the-lulz (hacking-13)))736 ([script]737 (let [lulz-delay 70]738 (->> script739 close-menu740 close-menu741 close-celadon-computer-menu742 (walk [← ← ← ← ← ← ← ← ← ↓ ↓ ↓ ↓])743 (walk (repeat 17 ←))744 (walk [↑ → → → → ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])745 (walk [↓ ← ↑])746 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓747 ← ← ← ← ↑ ↑ ↑ ← ↑])748 (talk)749 (do-nothing lulz-delay)750 (play-moves [[:a]])751 (do-nothing lulz-delay)752 (play-moves [[:a]])753 (do-nothing lulz-delay)754 close-menu))))756 (defn-memo launch-bootstrap-program757 ([] (launch-bootstrap-program758 (go-to-mansion-for-the-lulz)))759 ([script]760 (->> script761 ;; must corrupt item list again by switching pokemon762 activate-start-menu ;; \763 (set-cursor 0) ;; |764 select-menu-entry ;; |765 select-menu-entry ;; |766 (set-cursor 1) ;; | -- switch 9th pokemon767 select-menu-entry ;; | with 4th pokemon768 (set-cursor 3) ;; |769 select-menu-entry ;; |770 close-menu ;; /771 ;; now, open items and set map-function to772 ;; the program inside the item-computer.773 (set-cursor 1)774 (select-menu-entry)775 (toss-held-item 22 12)776 (switch-held-items 22 40)777 close-all-menus)))779 (defn regen-control-checkpoint!780 [] (write-script! (launch-bootstrap-program) "control-checkpoint"))782 (defn control-checkpoint []783 (read-script "control-checkpoint"))785 (def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF])787 (defn test-pattern-writing788 ([] (test-pattern-writing increasing-pattern))789 ([pattern]790 (let [moves (bootstrap-pattern pattern)791 pattern-insertion792 (->> (launch-bootstrap-program)793 (play-moves794 (take 100 moves)))]795 (println "Input Pattern:")796 (apply println (map #(format "0x%02X" %) pattern))797 (println "\nMemory Listing:")798 (print-listing (second pattern-insertion)799 0xD162 (+ 0xD162 (count pattern)))800 (= (subvec (vec (memory (second pattern-insertion)))801 0xD162 (+ 0xD162 (count pattern)))802 pattern))))805 (defn item-writer-test-script []806 [[]807 (-> (second (control-checkpoint))808 (set-memory-range809 (inc pc-item-list-start)810 (pc-item-writer-program)))])813 (defn-memo launch-main-bootstrap-program814 ([] (launch-main-bootstrap-program815 ;;(control-checkpoint)816 (launch-bootstrap-program)817 ;;(item-writer-test-script)818 ))819 ([script]820 (->> script821 (play-moves822 (bootstrap-pattern (main-bootstrap-program)))823 ;; I'd like to just press b here, but I can't824 ;; because the smallest item with item id >= 75 is825 ;; TM01, which has value 201.826 ;; (* 2 (- 201 75)) == 252, which plus 1 is 253 here :(827 ;;(play-moves [[:b]])828 (play-moves829 (take 253 (interleave (repeat 1000 [:b])830 (repeat 1000 [])))))))832 (def bootstrap-start pokemon-list-start)834 (defn test-main-bootstrap-integrety835 []836 (assert837 (= (main-bootstrap-program)838 (subvec839 (vec (memory (second (launch-main-bootstrap-program))))840 pokemon-list-start841 (+ pokemon-list-start (count (main-bootstrap-program)))))))843 (defn set-target-address844 "Assumes that the game is under control of the main-bootstrap845 program in MODE-SELECT mode, and sets the target address to which846 jumps/writes will occur."847 [target-address script]848 (let [[target-high target-low] (disect-bytes-2 target-address)]849 (->> script850 (play-moves851 (map buttons852 [set-H-mode target-high 0x00853 set-L-mode target-low 0x00])))))855 (defn write-RAM-segment856 "Assumes that the game is under control of the main-bootstrap857 program in MODE-SELECT mode and that target-address has been858 appropriately set, and writes 255 bytes or less to RAM."859 [segment script]860 (->> script861 (play-moves862 (map buttons863 [write-mode (count segment)]))864 (play-moves (map buttons segment))865 (play-moves [[]])))867 (defn write-RAM868 "Assumes that the game is under control of the main-bootstrap869 program in MODE-SELECT mode, and rewrites RAM starting at870 'start-address with 'new-ram."871 [start-address new-ram script]872 (loop [s (set-target-address start-address script)873 to-write new-ram]874 (if (< (count to-write) 0x100)875 (write-RAM-segment to-write s)876 (recur877 (write-RAM-segment (take 0xFF to-write) s)878 (drop 0xFF to-write)))))880 (defn transfer-control881 "Assumes that the game is under control of the main-bootstrap882 program in MODE-SELECT mode, and jumps to the target-address."883 [target-address script]884 (->> script885 (set-target-address target-address)886 (play-moves [(buttons jump-mode)])))889 (def relocated-bootstrap-start890 (+ 90 pokemon-box-1-address))892 (defn-memo relocate-main-bootstrap893 ([] (relocate-main-bootstrap (launch-main-bootstrap-program)))894 ([script]895 (->> script896 (do-nothing 2)897 (write-RAM898 relocated-bootstrap-start899 (main-bootstrap-program900 relocated-bootstrap-start))901 (do-nothing 1)902 (transfer-control relocated-bootstrap-start)903 (do-nothing 1))))905 (defn gen-new-kernel-checkpoint! []906 (write-script! (do-nothing 10 (relocate-main-bootstrap))907 "new-kernel"))909 (defn new-kernel [] (read-script "new-kernel"))911 (def mid-game-data912 (subvec (vec (memory (mid-game)))913 pokemon-list-start914 (+ pokemon-list-start 697)))916 (def mid-game-map-address 0x46BC)918 (defn-memo set-mid-game-data919 ([] (set-mid-game-data (relocate-main-bootstrap)))920 ([script]921 (->> script922 (do-nothing 10)923 (write-RAM pokemon-list-start924 mid-game-data))))925 (defn test-set-data926 ([] (test-set-data (relocate-main-bootstrap)))927 ([script]928 (->> script929 (do-nothing 10)930 (write-RAM pokemon-list-start931 (repeat 500 0xCC)))))933 (defn test-mid-game-transfer []934 (= (subvec (vec (memory (second (set-mid-game-data))))935 pokemon-list-start936 (+ pokemon-list-start 500))937 (subvec (vec (memory (mid-game)))938 pokemon-list-start939 (+ pokemon-list-start 500))))941 (defn-memo return-to-pokemon-kernel942 ([] (return-to-pokemon-kernel (set-mid-game-data)))943 ([script]944 (let [scratch (+ 200 pokemon-box-1-address)945 return-program946 (flatten947 [0xFB948 0xC3949 (reverse (disect-bytes-2 mid-game-map-address))])]950 (->> script951 (write-RAM scratch return-program)952 (transfer-control scratch)953 (do-nothing 1)))))