Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_0.clj @ 320:9637a0f52e7b
located item-list related addresses.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 03 Apr 2012 23:17:33 -0500 |
parents | 92c47a9cdaea |
children | af86b5ba622b |
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"]))))341 (defn buy-item342 "Assumes that the main item-screen is up, and buys343 quantity of the nth item in the list, assuming that you344 have enough money."345 [n quantity script]346 (if (= 0 quantity)347 script348 (let [after-initial-pause349 (do-nothing 20 script)350 move-to-item351 (reduce (fn [script _]352 (->> script353 (play-moves [[:d]])354 (do-nothing 3)))355 after-initial-pause356 (range n))357 select-item358 (play-moves [[:a]] move-to-item)359 request-items360 (reduce (fn [script _]361 (->> script362 (play-moves [[:u]])363 (do-nothing 1)))364 select-item365 (range (dec quantity)))366 buy-items367 (->> request-items368 (do-nothing 10)369 (play-moves [[:a]])370 (scroll-text)371 (scroll-text)372 (do-nothing 10)373 (play-moves [[:a]])374 (scroll-text))]375 buy-items)))378 (defn buy-items379 "Given a list of [item-no quantity], buys the quantity380 from the shop's list. Assumes that the item list is381 already up."382 [item-pairs script]383 (let [item-lookup (into {0 0 1 0 2 0 3 0 4 0} item-pairs)384 initial-purchase385 (->> script386 (buy-item 0 (item-lookup 0))387 (buy-item 1 (item-lookup 1))388 (buy-item 2 (item-lookup 2)))]389 (cond390 (and391 (not= 0 (item-lookup 3))392 (not= 0 (item-lookup 4)))393 (->> initial-purchase394 (do-nothing 20)395 (play-moves [[:d]])396 (do-nothing 3)397 (play-moves [[:d]])398 (do-nothing 3)399 (play-moves [[:d]])400 (do-nothing 10)401 (buy-item 0 (item-lookup 3))402 (do-nothing 20)403 (play-moves [[:d]])404 (do-nothing 3)405 (play-moves [[:d]])406 (do-nothing 3)407 (play-moves [[:d]])408 (do-nothing 10)409 (buy-item 0 (item-lookup 4)))410 (and (= 0 (item-lookup 3))411 (not= 0 (item-lookup 4)))412 (->> initial-purchase413 (do-nothing 20)414 (play-moves [[:d]])415 (do-nothing 3)416 (play-moves [[:d]])417 (do-nothing 3)418 (play-moves [[:d]])419 (do-nothing 10)420 (play-moves [[:d]])421 (do-nothing 10)422 (buy-item 0 (item-lookup 4)))423 (and (not= 0 (item-lookup 3))424 (= 0 (item-lookup 4)))425 (->> initial-purchase426 (do-nothing 20)427 (play-moves [[:d]])428 (do-nothing 3)429 (play-moves [[:d]])430 (do-nothing 3)431 (play-moves [[:d]])432 (do-nothing 10)433 (buy-item 0 (item-lookup 3)))434 (and (= 0 (item-lookup 3))435 (= 0 (item-lookup 4)))436 initial-purchase)))439 (defn test-buy-items440 ([] (test-buy-items441 (walk-to-counter)))442 ([script]443 (->> [(first script) (set-money (second script)444 999999)]445 (play-moves446 [[] [:a] []])447 (scroll-text)448 (do-nothing 100)449 (play-moves [[:a]])450 (do-nothing 100)451 (buy-items452 [[0 1]453 [1 15]454 [2 1]455 [3 20]456 [4 95]457 ]))))459 (defn-memo buy-initial-items460 ([] (buy-initial-items461 (walk-to-counter)))462 ([script]463 (->> script464 (play-moves465 [[] [:a] []])466 (scroll-text)467 (do-nothing 100)468 (play-moves [[:a]])469 (do-nothing 100)470 (buy-items471 [[0 1]472 [1 1]473 [2 1]474 [3 1]475 [4 1]])476 (do-nothing 100)477 (play-moves [[:b]])478 (do-nothing 100)479 (play-moves [[:b]])480 (do-nothing 100)481 (play-moves [[:b] []])482 (first-difference [:b] [:b :start] AF))))485 (defn-memo do-save-corruption486 ([] (do-save-corruption487 (buy-initial-items)))488 ([script]489 (->> script490 (first-difference [] [:d] AF)491 (play-moves [[] [] [] [:d]492 [] [] [] [:d]493 [] [] [] [:d]494 [] [] [:a]])495 scroll-text496 (play-moves497 ;; this section is copied from speedrun-2942 and corrupts498 ;; the save so that the total number of pokemon is set to499 ;; 0xFF, allowing manipulation of non-pokemon data in RAM500 ;; via the pokemon interface.501 [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []502 [] [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])503 (title)504 (first-difference [] [:start] AF)505 (first-difference [] [:a] AF)506 (first-difference [:a] [:a :start] AF))))508 (def menu do-nothing )510 (defn-memo corrupt-item-list511 ([] (corrupt-item-list512 (do-save-corruption)))513 ([script]514 (->> script515 (do-nothing 200)516 (menu [↓ [:a]]) ; select "POKEMON" from517 ; from main menu518 (menu [↓ ↓ ↓ ↓ ↓ ↓ ; go to 6th pokemon519 [:a] ↓ [:a] ; select "switch"520 ↓ ↓ ↓ [:a]]) ; switch with 9th "pokemon"522 (do-nothing 1))))524 (defn-memo get-burn-heals525 ([] (get-burn-heals526 (corrupt-item-list)))527 ([script]528 (->> script529 (menu [[:b] [:b]])530 (menu [[:a]])531 (do-nothing 100)532 (menu [↓ [:a]])533 (do-nothing 100)534 (menu [[:a] ↓ [:a]])535 (scroll-text)536 (menu [[:b][:b]])537 (menu [[:a]])539 (do-nothing 50)540 (buy-items [[0 1]])541 (do-nothing 60)542 (menu [[:a]])543 (scroll-text)545 (do-nothing 50)546 (buy-items [[0 1]])547 (do-nothing 60)548 ;;(menu [[:a]])549 ;;(scroll-text)551 ;;(do-nothing 300)552 ;;(menu [[:b] [:b]])553 ;;(do-nothing 300)555 (buy-items [[0 1]556 [1 1]557 [1 1]558 [2 1]559 [3 1]560 [4 97]])562 (do-nothing 10))))564 (defn-memo corrupt-item-list-again565 ([] (corrupt-item-list-again (get-burn-heals)))566 ([script]567 (->> script568 (do-nothing 10)569 (play-moves [[:b]])570 (do-nothing 100)571 (play-moves [[:b]])572 (do-nothing 40)573 (play-moves [[:b]])574 (first-difference [:b] [:start :b] AF)575 (menu [[:a] ↑ ↑ ↑ ↑ ↑ ; get fifth pokemon576 [:a] ↓ [:a] ; and corrupt the577 ↓ ↓ ↓ ↓ ↓ [:a]]) ; item list again by578 ; switching it to579 ))) ; tenth place.581 (defn-memo viridian-store->viridian-poke-center582 ([] (viridian-store->viridian-poke-center583 (corrupt-item-list-again)))584 ([script]585 (->> script586 (do-nothing 100)587 (play-moves [[:b]])588 (do-nothing 100)589 (play-moves [[:b]])590 (do-nothing 40)591 ;; leave store592 (walk [↓ ↓593 → ↓ ↓])594 (walk [← ← ← ←595 ↓ ↓ ↓ ↓ ↓ ↓596 ← ← ← ↑]))))598 (defn-memo to-poke-center-computer599 ([] (to-poke-center-computer600 (viridian-store->viridian-poke-center)))601 ([script]602 (->> script603 (walk [→ →604 ↑ ↑ ↑605 → → → → → → → → → ↑])606 (do-nothing 1))))608 (defn-memo begin-deposits609 ([] (begin-deposits610 (to-poke-center-computer)))611 ([script]612 (->> script613 ;; access PC614 (scroll-text 2)616 ;; access item storage617 (menu [[:a] [:d] [:a]])618 (scroll-text 2)620 ;; begin deposit621 (menu [[:d] [:a]])622 (do-nothing 40))))624 (defn deposit-n-items625 [n script]626 (->> script627 (do-nothing 100)628 (play-moves [[:a]])629 (do-nothing 80)630 (multiple-times631 (dec n)632 (fn [script]633 (->> script634 (play-moves [[:u]])635 (do-nothing 1))))636 (play-moves [[:a]])637 (scroll-text)))639 (defn deposit-one-item640 [script]641 (->> script642 (do-nothing 100)643 (play-moves [[:a]])644 (do-nothing 80)645 (play-moves [[:a]])646 (scroll-text)))648 (defn-memo create-header649 ([] (create-header (begin-deposits)))650 ([script]651 (->> script652 (multiple-times 33 deposit-one-item)653 (do-nothing 1))))655 (defn bootstrap-init []656 [(read-moves "bootstrap-init")657 (read-state "bootstrap-init")])659 (defn create-bootstrap-program660 ([] (create-bootstrap-program661 (create-header)))662 ([script]663 (->> script664 (do-nothing 120)665 (menu [↓ ↓ ↓ ↓ ↓ ↓ ↓])666 ;;(deposit-n-items 33)668 (menu (repeat 17 ↓))672 (do-nothing 1))))675 (defn test-pc-item-program []676 (-> (read-state "bootstrap-init")677 (set-memory pc-item-list-start 50)678 (set-memory-range679 map-function-address-start [0x8B 0xD5])680 (set-memory-range681 (inc pc-item-list-start)682 (flatten683 [(repeat684 28685 [0xFF 0x01])686 [;; second part of item manipulation program687 0x00 ;; this starts at address 0xD56C688 0x2A ;; save (HL)=(target) to A, increment HL690 0x00691 0x47 ;; save A to B693 0x00694 0x3A ;; save (target+1) to A, decrement HL696 0x00697 0x22 ;; A -> target, increment HL [(target+1) -> target]699 0x00700 0x70 ;; load B into target+1 [(target) -> target+1]702 0x00703 0xC3 ;; first part of absolute jump705 0x0C ;; return control to pokemon kernel706 0x5F]707 (repeat708 5709 [0xFF 0x01])711 [;; first part of item manipulation program712 0x00713 0x21 ;; load target into HL715 0x94 ;; this is the target address716 0xD5718 0x00 ;; relative jump back to first part719 0x18721 0xE1 ;; of program722 0x01724 0xFF ;; spacer725 0x01727 0x04 ;; target ID (pokeball)728 0x3E ;; target Quantity (lemonade)729 ]]))))