Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_0.clj @ 321:af86b5ba622b
created function to determine total item-offset
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 04 Apr 2012 00:16:49 -0500 |
parents | 9637a0f52e7b |
children | d604bd3c122c |
line wrap: on
line source
1 (ns com.aurellem.run.bootstrap-02 (:use (com.aurellem.gb saves gb-driver util3 items vbm characters money))4 (:use (com.aurellem.run util title save-corruption))5 (:use (com.aurellem.exp item-bridge))6 (:import [com.aurellem.gb.gb_driver SaveState]))8 (defn-memo boot-root []9 [ [] (root)])11 (defn-memo to-rival-name12 ([] (to-rival-name (boot-root)))13 ([script]14 (->> script15 title16 oak17 name-entry-rlm18 (scroll-text 5))))20 (defn-memo name-rival-bootstrap21 ([] (name-rival-bootstrap (to-rival-name)))22 ([script]23 (->> script24 (first-difference [] [:a] AF)25 (first-difference [] [:r] DE)26 (play-moves27 [[]28 [] [] [:r] [] [:d] [:a] ;; L29 [:r] [] [:r] [] [:r] [] [:r] []30 [:r] [] [:d] [] [:d] [:a] ;; [PK]31 [:u] [] [:l] [] [:l] []32 [:l] [] [:l] [] [:l] [:a] ;; U33 [:r] [] [:r] [] [:r] []34 [:r] [] [:r] [] [:d] [:a] ;; [PK]35 [] [:a] ;; [PK]36 [] [:a] ;; [PK]37 [:r] [] [:d] [:a] ;; END38 ]))))40 (defn-memo leave-house41 ([] (leave-house (name-rival-bootstrap)))42 ([script]43 (->> script44 finish-title45 walk-to-stairs46 walk-to-door47 (walk [↓ ↓]))))49 (defn-memo to-pallet-town-edge50 ([] (to-pallet-town-edge (leave-house)))51 ([script]52 (->> script53 (walk [→ → → → →54 ↑ ↑ ↑ ↑ ↑ ↑]))))56 (defn-memo start-pikachu-battle57 ([] (start-pikachu-battle58 (to-pallet-town-edge)))59 ([script]60 (->> script61 (first-difference [:b] [:b :a] DE)62 scroll-text63 (do-nothing 200)64 (play-moves [[:b]]))))66 (defn-memo capture-pikachu67 ([] (capture-pikachu (start-pikachu-battle)))68 ([script]69 (->> script70 (scroll-text 3))))72 (defn-memo go-to-lab73 ([] (go-to-lab (capture-pikachu)))74 ([script]75 (->> script76 end-text77 (scroll-text 5)78 end-text79 ;; oak walks you to his lab; no input required.80 (do-nothing 400))))82 (defn-memo talk-to-oak-in-lab83 ([] (talk-to-oak-in-lab (go-to-lab)))84 ([script]85 (->> script86 (scroll-text 14)87 end-text)))89 (defn-memo try-to-get-eevee90 ([] (try-to-get-eevee (talk-to-oak-in-lab)))91 ([script]92 (->> script93 ;; walk to pokeball94 (walk [↓ → →])95 ;; and try to grab it96 (play-moves97 (concat [↑ ↑ [:a]]98 (repeat 100 [])))99 (scroll-text 10)100 (end-text))))102 (defn-memo obtain-pikachu103 ([] (obtain-pikachu (try-to-get-eevee)))104 ([script]105 (->> script106 (scroll-text 6)107 (end-text))))110 (defn-memo begin-battle-with-rival111 ([] (begin-battle-with-rival112 (obtain-pikachu)))113 ([script]114 (->> script115 (walk [↓ ↓ ↓])116 (scroll-text 3)117 (end-text)118 (scroll-text))))120 (defn-memo defeat-eevee121 ([] (defeat-eevee122 (begin-battle-with-rival)))123 ([script]124 (->> script125 (do-nothing 400)126 (play-moves [[:a]])127 (critical-hit)128 (do-nothing 200)129 (scroll-text 2) ;; for eevee's tail-whip130 (do-nothing 10)131 (play-moves [[:a]])132 (critical-hit)133 (do-nothing 200)134 (scroll-text 2) ;; tail whip again135 (do-nothing 10)136 (play-moves [[:a]])137 (critical-hit)138 (do-nothing 200))))140 (defn-memo finish-rival-text141 ([] (finish-rival-text142 (defeat-eevee)))143 ([script]144 (->> script145 (scroll-text 12)146 (end-text))))148 (defn-memo pikachu-comes-out149 ([] (pikachu-comes-out150 (finish-rival-text)))151 ([script]152 (->> script153 (scroll-text 8)154 (end-text))))156 (defn-memo leave-oaks-lab157 ([] (leave-oaks-lab158 (pikachu-comes-out)))159 ([script]160 (->> script161 (walk [↓ ↓ ↓ ↓ ↓ ↓]))))163 (defn-memo oaks-lab->pallet-town-edge164 ([] (oaks-lab->pallet-town-edge165 (leave-oaks-lab)))166 ([script]167 (->> script168 (walk [← ← ←169 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ →]))))171 (defn-memo pallet-edge->viridian-mart172 ([] (pallet-edge->viridian-mart true173 (oaks-lab->pallet-town-edge)))174 ([dodge-stupid-guy? script]175 (let [dodge-1 (if dodge-stupid-guy?176 [→ →]177 [→])178 dodge-2 (if dodge-stupid-guy?179 [↑ ↑ ←]180 [↑ ↑])]182 (->> script183 ;; leave straight grass184 (walk-thru-grass185 [↑ ↑ ↑ ↑ ↑])187 (walk [↑ ↑ ↑ ↑])189 (walk-thru-grass190 [← ← ↑])192 (walk [↑ ↑ ↑ ↑ → → → ])194 (walk-thru-grass195 [→ ↑ ↑ ←])197 (walk198 [← ←199 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑200 → → → → ])202 ;; this part is dependent on that203 ;; stupid NPC in the grass patch204 (walk-thru-grass205 (concat dodge-1206 [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ]))208 (walk209 (concat210 dodge-2211 [← ← ←212 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑213 ← ←214 ↑ ↑ ↑ ↑215 → → → → → → → → → →216 ↑ ↑ ↑ ↑ ↑ ↑ ↑]))))))218 (defn-memo get-oaks-parcel219 ([] (get-oaks-parcel220 (pallet-edge->viridian-mart)))221 ([script]222 (->> script223 (do-nothing 50)224 (end-text)225 (scroll-text 3)226 (do-nothing 197)227 (play-moves [[:a] []])228 (walk [↓ ↓ → ↓]))))230 (defn-memo viridian-store->oaks-lab231 ([] (viridian-store->oaks-lab232 (get-oaks-parcel)))233 ([script]234 (->> script235 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓236 ← ← ← ← ← ← ← ← ←237 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓238 ← ←239 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓240 ↓ ↓ ↓ ↓ ↓ ↓ ↓241 → → → → → → → →242 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓243 ← ← ← ← ←244 ↓ ↓ ↓ ↓245 ])246 (walk-thru-grass247 [↓ ↓ ↓ ↓ ↓ ↓ ↓])248 (walk [↓ ↓ ← ↓ ↓ ↓ ←249 ↓ ↓ ↓ ↓ ↓ ↓250 → → → ↑])252 (do-nothing 1))))255 (defn-memo viridian-store->oaks-lab-like-a-boss256 ([] (viridian-store->oaks-lab-like-a-boss257 (get-oaks-parcel)))258 ([script]259 (->> script260 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓261 ← ← ← ← ← ← ← ← ←262 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓])264 (walk-thru-grass265 [↓ ↓ ↓ ↓ ↓])267 (walk268 [↓ ↓ ← ↓269 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓270 → → → ↓])272 (walk-thru-grass273 [↓ ↓ ↓])275 (walk [↓ ← ← ↓ ↓ ↓ ↓ ↓ ↓])277 (walk-thru-grass278 [↓ ↓ ↓ ↓ ↓ ↓])280 (walk [↓ ↓ ↓ ← ↓ ↓ ↓281 ↓ ↓ ↓ ↓ ↓282 → → → ↑]))))284 (defn-memo deliver-oaks-parcel285 ([] (deliver-oaks-parcel286 (viridian-store->oaks-lab-like-a-boss)))287 ([script]288 (->> script289 (walk [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])290 (play-moves [[] [:a]])291 (scroll-text 13)292 (end-text)293 (do-nothing 200)294 (scroll-text 2)295 (end-text)296 (scroll-text 2)297 (end-text)298 (scroll-text 8)299 (end-text)300 (scroll-text 9)301 (end-text)302 (scroll-text 7)303 (end-text)304 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓]))))306 (defn-memo return-to-viridian-mart307 ([] (return-to-viridian-mart308 (deliver-oaks-parcel)))309 ([script]310 (->> script311 oaks-lab->pallet-town-edge312 (pallet-edge->viridian-mart false))))314 (defn-memo walk-to-counter315 ([] (walk-to-counter316 (return-to-viridian-mart)))317 ([script]318 (->> script319 (walk [↑ ↑ ←]))))323 ;; useful addresses324 52262 ;; --- current-cursor-offset325 52278 ;; --- current screen-offset328 (defn exp-item-list []329 (clojure.pprint/pprint330 (apply harmonic-compare331 (map read-state332 ["up-1" "down-1"333 "up-2" "down-2"334 "up-3" "down-3"335 "up-4" "down-4"336 "up-5" "down-5"337 "up-6"]))))339 (def item-cursor-offset-address 52262)340 (def item-screen-offset-address 52278)342 (defn item-offset343 ([^SaveState state]344 (let [mem (memory state)]345 (+ (aget mem item-screen-offset-address)346 (aget mem item-cursor-offset-address))))347 ([] (item-offset @current-state)))350 (defn buy-item351 "Assumes that the main item-screen is up, and buys352 quantity of the nth item in the list, assuming that you353 have enough money."354 [n quantity script]355 (if (= 0 quantity)356 script357 (let [after-initial-pause358 (do-nothing 20 script)359 move-to-item360 (reduce (fn [script _]361 (->> script362 (play-moves [[:d]])363 (do-nothing 3)))364 after-initial-pause365 (range n))366 select-item367 (play-moves [[:a]] move-to-item)368 request-items369 (reduce (fn [script _]370 (->> script371 (play-moves [[:u]])372 (do-nothing 1)))373 select-item374 (range (dec quantity)))375 buy-items376 (->> request-items377 (do-nothing 10)378 (play-moves [[:a]])379 (scroll-text)380 (scroll-text)381 (do-nothing 10)382 (play-moves [[:a]])383 (scroll-text))]384 buy-items)))387 (defn buy-items388 "Given a list of [item-no quantity], buys the quantity389 from the shop's list. Assumes that the item list is390 already up."391 [item-pairs script]392 (let [item-lookup (into {0 0 1 0 2 0 3 0 4 0} item-pairs)393 initial-purchase394 (->> script395 (buy-item 0 (item-lookup 0))396 (buy-item 1 (item-lookup 1))397 (buy-item 2 (item-lookup 2)))]398 (cond399 (and400 (not= 0 (item-lookup 3))401 (not= 0 (item-lookup 4)))402 (->> initial-purchase403 (do-nothing 20)404 (play-moves [[:d]])405 (do-nothing 3)406 (play-moves [[:d]])407 (do-nothing 3)408 (play-moves [[:d]])409 (do-nothing 10)410 (buy-item 0 (item-lookup 3))411 (do-nothing 20)412 (play-moves [[:d]])413 (do-nothing 3)414 (play-moves [[:d]])415 (do-nothing 3)416 (play-moves [[:d]])417 (do-nothing 10)418 (buy-item 0 (item-lookup 4)))419 (and (= 0 (item-lookup 3))420 (not= 0 (item-lookup 4)))421 (->> initial-purchase422 (do-nothing 20)423 (play-moves [[:d]])424 (do-nothing 3)425 (play-moves [[:d]])426 (do-nothing 3)427 (play-moves [[:d]])428 (do-nothing 10)429 (play-moves [[:d]])430 (do-nothing 10)431 (buy-item 0 (item-lookup 4)))432 (and (not= 0 (item-lookup 3))433 (= 0 (item-lookup 4)))434 (->> initial-purchase435 (do-nothing 20)436 (play-moves [[:d]])437 (do-nothing 3)438 (play-moves [[:d]])439 (do-nothing 3)440 (play-moves [[:d]])441 (do-nothing 10)442 (buy-item 0 (item-lookup 3)))443 (and (= 0 (item-lookup 3))444 (= 0 (item-lookup 4)))445 initial-purchase)))448 (defn test-buy-items449 ([] (test-buy-items450 (walk-to-counter)))451 ([script]452 (->> [(first script) (set-money (second script)453 999999)]454 (play-moves455 [[] [:a] []])456 (scroll-text)457 (do-nothing 100)458 (play-moves [[:a]])459 (do-nothing 100)460 (buy-items461 [[0 1]462 [1 15]463 [2 1]464 [3 20]465 [4 95]466 ]))))468 (defn-memo buy-initial-items469 ([] (buy-initial-items470 (walk-to-counter)))471 ([script]472 (->> script473 (play-moves474 [[] [:a] []])475 (scroll-text)476 (do-nothing 100)477 (play-moves [[:a]])478 (do-nothing 100)479 (buy-items480 [[0 1]481 [1 1]482 [2 1]483 [3 1]484 [4 1]])485 (do-nothing 100)486 (play-moves [[:b]])487 (do-nothing 100)488 (play-moves [[:b]])489 (do-nothing 100)490 (play-moves [[:b] []])491 (first-difference [:b] [:b :start] AF))))494 (defn-memo do-save-corruption495 ([] (do-save-corruption496 (buy-initial-items)))497 ([script]498 (->> script499 (first-difference [] [:d] AF)500 (play-moves [[] [] [] [:d]501 [] [] [] [:d]502 [] [] [] [:d]503 [] [] [:a]])504 scroll-text505 (play-moves506 ;; this section is copied from speedrun-2942 and corrupts507 ;; the save so that the total number of pokemon is set to508 ;; 0xFF, allowing manipulation of non-pokemon data in RAM509 ;; via the pokemon interface.510 [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []511 [] [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])512 (title)513 (first-difference [] [:start] AF)514 (first-difference [] [:a] AF)515 (first-difference [:a] [:a :start] AF))))517 (def menu do-nothing )519 (defn-memo corrupt-item-list520 ([] (corrupt-item-list521 (do-save-corruption)))522 ([script]523 (->> script524 (do-nothing 200)525 (menu [↓ [:a]]) ; select "POKEMON" from526 ; from main menu527 (menu [↓ ↓ ↓ ↓ ↓ ↓ ; go to 6th pokemon528 [:a] ↓ [:a] ; select "switch"529 ↓ ↓ ↓ [:a]]) ; switch with 9th "pokemon"531 (do-nothing 1))))533 (defn-memo get-burn-heals534 ([] (get-burn-heals535 (corrupt-item-list)))536 ([script]537 (->> script538 (menu [[:b] [:b]])539 (menu [[:a]])540 (do-nothing 100)541 (menu [↓ [:a]])542 (do-nothing 100)543 (menu [[:a] ↓ [:a]])544 (scroll-text)545 (menu [[:b][:b]])546 (menu [[:a]])548 (do-nothing 50)549 (buy-items [[0 1]])550 (do-nothing 60)551 (menu [[:a]])552 (scroll-text)554 (do-nothing 50)555 (buy-items [[0 1]])556 (do-nothing 60)557 ;;(menu [[:a]])558 ;;(scroll-text)560 ;;(do-nothing 300)561 ;;(menu [[:b] [:b]])562 ;;(do-nothing 300)564 (buy-items [[0 1]565 [1 1]566 [1 1]567 [2 1]568 [3 1]569 [4 97]])571 (do-nothing 10))))573 (defn-memo corrupt-item-list-again574 ([] (corrupt-item-list-again (get-burn-heals)))575 ([script]576 (->> script577 (do-nothing 10)578 (play-moves [[:b]])579 (do-nothing 100)580 (play-moves [[:b]])581 (do-nothing 40)582 (play-moves [[:b]])583 (first-difference [:b] [:start :b] AF)584 (menu [[:a] ↑ ↑ ↑ ↑ ↑ ; get fifth pokemon585 [:a] ↓ [:a] ; and corrupt the586 ↓ ↓ ↓ ↓ ↓ [:a]]) ; item list again by587 ; switching it to588 ))) ; tenth place.590 (defn-memo viridian-store->viridian-poke-center591 ([] (viridian-store->viridian-poke-center592 (corrupt-item-list-again)))593 ([script]594 (->> script595 (do-nothing 100)596 (play-moves [[:b]])597 (do-nothing 100)598 (play-moves [[:b]])599 (do-nothing 40)600 ;; leave store601 (walk [↓ ↓602 → ↓ ↓])603 (walk [← ← ← ←604 ↓ ↓ ↓ ↓ ↓ ↓605 ← ← ← ↑]))))607 (defn-memo to-poke-center-computer608 ([] (to-poke-center-computer609 (viridian-store->viridian-poke-center)))610 ([script]611 (->> script612 (walk [→ →613 ↑ ↑ ↑614 → → → → → → → → → ↑])615 (do-nothing 1))))617 (defn-memo begin-deposits618 ([] (begin-deposits619 (to-poke-center-computer)))620 ([script]621 (->> script622 ;; access PC623 (scroll-text 2)625 ;; access item storage626 (menu [[:a] [:d] [:a]])627 (scroll-text 2)629 ;; begin deposit630 (menu [[:d] [:a]])631 (do-nothing 40))))633 (defn deposit-n-items634 [n script]635 (->> script636 (do-nothing 100)637 (play-moves [[:a]])638 (do-nothing 80)639 (multiple-times640 (dec n)641 (fn [script]642 (->> script643 (play-moves [[:u]])644 (do-nothing 1))))645 (play-moves [[:a]])646 (scroll-text)))648 (defn deposit-one-item649 [script]650 (->> script651 (do-nothing 100)652 (play-moves [[:a]])653 (do-nothing 80)654 (play-moves [[:a]])655 (scroll-text)))657 (defn-memo create-header658 ([] (create-header (begin-deposits)))659 ([script]660 (->> script661 (multiple-times 33 deposit-one-item)662 (do-nothing 1))))664 (defn bootstrap-init []665 [(read-moves "bootstrap-init")666 (read-state "bootstrap-init")])668 (defn create-bootstrap-program669 ([] (create-bootstrap-program670 (create-header)))671 ([script]672 (->> script673 (do-nothing 120)674 (menu [↓ ↓ ↓ ↓ ↓ ↓ ↓])675 ;;(deposit-n-items 33)677 (menu (repeat 17 ↓))681 (do-nothing 1))))684 (defn test-pc-item-program []685 (-> (read-state "bootstrap-init")686 (set-memory pc-item-list-start 50)687 (set-memory-range688 map-function-address-start [0x8B 0xD5])689 (set-memory-range690 (inc pc-item-list-start)691 (flatten692 [(repeat693 28694 [0xFF 0x01])695 [;; second part of item manipulation program696 0x00 ;; this starts at address 0xD56C697 0x2A ;; save (HL)=(target) to A, increment HL699 0x00700 0x47 ;; save A to B702 0x00703 0x3A ;; save (target+1) to A, decrement HL705 0x00706 0x22 ;; A -> target, increment HL [(target+1) -> target]708 0x00709 0x70 ;; load B into target+1 [(target) -> target+1]711 0x00712 0xC3 ;; first part of absolute jump714 0x0C ;; return control to pokemon kernel715 0x5F]716 (repeat717 5718 [0xFF 0x01])720 [;; first part of item manipulation program721 0x00722 0x21 ;; load target into HL724 0x94 ;; this is the target address725 0xD5727 0x00 ;; relative jump back to first part728 0x18730 0xE1 ;; of program731 0x01733 0xFF ;; spacer734 0x01736 0x04 ;; target ID (pokeball)737 0x3E ;; target Quantity (lemonade)738 ]]))))