view clojure/com/aurellem/run/bootstrap_0.clj @ 319:92c47a9cdaea

adapting bootstrap to new util functions.
author Robert McIntyre <rlm@mit.edu>
date Tue, 03 Apr 2012 04:16:20 -0500
parents 8e63b0bb8ea3
children 9637a0f52e7b
line wrap: on
line source
1 (ns com.aurellem.run.bootstrap-0
2 (:use (com.aurellem.gb gb-driver util items vbm characters money))
3 (:use (com.aurellem.run util title save-corruption))
4 (:use (com.aurellem.exp item-bridge))
5 (:import [com.aurellem.gb.gb_driver SaveState]))
7 (defn-memo boot-root []
8 [ [] (root)])
10 (defn-memo to-rival-name
11 ([] (to-rival-name (boot-root)))
12 ([script]
13 (->> script
14 title
15 oak
16 name-entry-rlm
17 (scroll-text 5))))
19 (defn-memo name-rival-bootstrap
20 ([] (name-rival-bootstrap (to-rival-name)))
21 ([script]
22 (->> script
23 (first-difference [] [:a] AF)
24 (first-difference [] [:r] DE)
25 (play-moves
26 [[]
27 [] [] [:r] [] [:d] [:a] ;; L
28 [:r] [] [:r] [] [:r] [] [:r] []
29 [:r] [] [:d] [] [:d] [:a] ;; [PK]
30 [:u] [] [:l] [] [:l] []
31 [:l] [] [:l] [] [:l] [:a] ;; U
32 [:r] [] [:r] [] [:r] []
33 [:r] [] [:r] [] [:d] [:a] ;; [PK]
34 [] [:a] ;; [PK]
35 [] [:a] ;; [PK]
36 [:r] [] [:d] [:a] ;; END
37 ]))))
39 (defn-memo leave-house
40 ([] (leave-house (name-rival-bootstrap)))
41 ([script]
42 (->> script
43 finish-title
44 walk-to-stairs
45 walk-to-door
46 (walk [↓ ↓]))))
48 (defn-memo to-pallet-town-edge
49 ([] (to-pallet-town-edge (leave-house)))
50 ([script]
51 (->> script
52 (walk [→ → → → →
53 ↑ ↑ ↑ ↑ ↑ ↑]))))
55 (defn-memo start-pikachu-battle
56 ([] (start-pikachu-battle
57 (to-pallet-town-edge)))
58 ([script]
59 (->> script
60 (first-difference [:b] [:b :a] DE)
61 scroll-text
62 (do-nothing 200)
63 (play-moves [[:b]]))))
65 (defn-memo capture-pikachu
66 ([] (capture-pikachu (start-pikachu-battle)))
67 ([script]
68 (->> script
69 (scroll-text 3))))
71 (defn-memo go-to-lab
72 ([] (go-to-lab (capture-pikachu)))
73 ([script]
74 (->> script
75 end-text
76 (scroll-text 5)
77 end-text
78 ;; oak walks you to his lab; no input required.
79 (do-nothing 400))))
81 (defn-memo talk-to-oak-in-lab
82 ([] (talk-to-oak-in-lab (go-to-lab)))
83 ([script]
84 (->> script
85 (scroll-text 14)
86 end-text)))
88 (defn-memo try-to-get-eevee
89 ([] (try-to-get-eevee (talk-to-oak-in-lab)))
90 ([script]
91 (->> script
92 ;; walk to pokeball
93 (walk [↓ → →])
94 ;; and try to grab it
95 (play-moves
96 (concat [↑ ↑ [:a]]
97 (repeat 100 [])))
98 (scroll-text 10)
99 (end-text))))
101 (defn-memo obtain-pikachu
102 ([] (obtain-pikachu (try-to-get-eevee)))
103 ([script]
104 (->> script
105 (scroll-text 6)
106 (end-text))))
109 (defn-memo begin-battle-with-rival
110 ([] (begin-battle-with-rival
111 (obtain-pikachu)))
112 ([script]
113 (->> script
114 (walk [↓ ↓ ↓])
115 (scroll-text 3)
116 (end-text)
117 (scroll-text))))
119 (defn-memo defeat-eevee
120 ([] (defeat-eevee
121 (begin-battle-with-rival)))
122 ([script]
123 (->> script
124 (do-nothing 400)
125 (play-moves [[:a]])
126 (critical-hit)
127 (do-nothing 200)
128 (scroll-text 2) ;; for eevee's tail-whip
129 (do-nothing 10)
130 (play-moves [[:a]])
131 (critical-hit)
132 (do-nothing 200)
133 (scroll-text 2) ;; tail whip again
134 (do-nothing 10)
135 (play-moves [[:a]])
136 (critical-hit)
137 (do-nothing 200))))
139 (defn-memo finish-rival-text
140 ([] (finish-rival-text
141 (defeat-eevee)))
142 ([script]
143 (->> script
144 (scroll-text 12)
145 (end-text))))
147 (defn-memo pikachu-comes-out
148 ([] (pikachu-comes-out
149 (finish-rival-text)))
150 ([script]
151 (->> script
152 (scroll-text 8)
153 (end-text))))
155 (defn-memo leave-oaks-lab
156 ([] (leave-oaks-lab
157 (pikachu-comes-out)))
158 ([script]
159 (->> script
160 (walk [↓ ↓ ↓ ↓ ↓ ↓]))))
162 (defn-memo oaks-lab->pallet-town-edge
163 ([] (oaks-lab->pallet-town-edge
164 (leave-oaks-lab)))
165 ([script]
166 (->> script
167 (walk [← ← ←
168 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ →]))))
170 (defn-memo pallet-edge->viridian-mart
171 ([] (pallet-edge->viridian-mart true
172 (oaks-lab->pallet-town-edge)))
173 ([dodge-stupid-guy? script]
174 (let [dodge-1 (if dodge-stupid-guy?
175 [→ →]
176 [→])
177 dodge-2 (if dodge-stupid-guy?
178 [↑ ↑ ←]
179 [↑ ↑])]
181 (->> script
182 ;; leave straight grass
183 (walk-thru-grass
184 [↑ ↑ ↑ ↑ ↑])
186 (walk [↑ ↑ ↑ ↑])
188 (walk-thru-grass
189 [← ← ↑])
191 (walk [↑ ↑ ↑ ↑ → → → ])
193 (walk-thru-grass
194 [→ ↑ ↑ ←])
196 (walk
197 [← ←
198 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
199 → → → → ])
201 ;; this part is dependent on that
202 ;; stupid NPC in the grass patch
203 (walk-thru-grass
204 (concat dodge-1
205 [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ]))
207 (walk
208 (concat
209 dodge-2
210 [← ← ←
211 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
212 ← ←
213 ↑ ↑ ↑ ↑
214 → → → → → → → → → →
215 ↑ ↑ ↑ ↑ ↑ ↑ ↑]))))))
217 (defn-memo get-oaks-parcel
218 ([] (get-oaks-parcel
219 (pallet-edge->viridian-mart)))
220 ([script]
221 (->> script
222 (do-nothing 50)
223 (end-text)
224 (scroll-text 3)
225 (do-nothing 197)
226 (play-moves [[:a] []])
227 (walk [↓ ↓ → ↓]))))
229 (defn-memo viridian-store->oaks-lab
230 ([] (viridian-store->oaks-lab
231 (get-oaks-parcel)))
232 ([script]
233 (->> script
234 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
235 ← ← ← ← ← ← ← ← ←
236 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
237 ← ←
238 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
239 ↓ ↓ ↓ ↓ ↓ ↓ ↓
240 → → → → → → → →
241 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
242 ← ← ← ← ←
243 ↓ ↓ ↓ ↓
244 ])
245 (walk-thru-grass
246 [↓ ↓ ↓ ↓ ↓ ↓ ↓])
247 (walk [↓ ↓ ← ↓ ↓ ↓ ←
248 ↓ ↓ ↓ ↓ ↓ ↓
249 → → → ↑])
251 (do-nothing 1))))
254 (defn-memo viridian-store->oaks-lab-like-a-boss
255 ([] (viridian-store->oaks-lab-like-a-boss
256 (get-oaks-parcel)))
257 ([script]
258 (->> script
259 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
260 ← ← ← ← ← ← ← ← ←
261 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓])
263 (walk-thru-grass
264 [↓ ↓ ↓ ↓ ↓])
266 (walk
267 [↓ ↓ ← ↓
268 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
269 → → → ↓])
271 (walk-thru-grass
272 [↓ ↓ ↓])
274 (walk [↓ ← ← ↓ ↓ ↓ ↓ ↓ ↓])
276 (walk-thru-grass
277 [↓ ↓ ↓ ↓ ↓ ↓])
279 (walk [↓ ↓ ↓ ← ↓ ↓ ↓
280 ↓ ↓ ↓ ↓ ↓
281 → → → ↑]))))
283 (defn-memo deliver-oaks-parcel
284 ([] (deliver-oaks-parcel
285 (viridian-store->oaks-lab-like-a-boss)))
286 ([script]
287 (->> script
288 (walk [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])
289 (play-moves [[] [:a]])
290 (scroll-text 13)
291 (end-text)
292 (do-nothing 200)
293 (scroll-text 2)
294 (end-text)
295 (scroll-text 2)
296 (end-text)
297 (scroll-text 8)
298 (end-text)
299 (scroll-text 9)
300 (end-text)
301 (scroll-text 7)
302 (end-text)
303 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓]))))
305 (defn-memo return-to-viridian-mart
306 ([] (return-to-viridian-mart
307 (deliver-oaks-parcel)))
308 ([script]
309 (->> script
310 oaks-lab->pallet-town-edge
311 (pallet-edge->viridian-mart false))))
313 (defn-memo walk-to-counter
314 ([] (walk-to-counter
315 (return-to-viridian-mart)))
316 ([script]
317 (->> script
318 (walk [↑ ↑ ←]))))
320 (defn buy-item
321 "Assumes that the main item-screen is up, and buys
322 quantity of the nth item in the list, assuming that you
323 have enough money."
324 [n quantity script]
325 (if (= 0 quantity)
326 script
327 (let [after-initial-pause
328 (do-nothing 20 script)
329 move-to-item
330 (reduce (fn [script _]
331 (->> script
332 (play-moves [[:d]])
333 (do-nothing 3)))
334 after-initial-pause
335 (range n))
336 select-item
337 (play-moves [[:a]] move-to-item)
338 request-items
339 (reduce (fn [script _]
340 (->> script
341 (play-moves [[:u]])
342 (do-nothing 1)))
343 select-item
344 (range (dec quantity)))
345 buy-items
346 (->> request-items
347 (do-nothing 10)
348 (play-moves [[:a]])
349 (scroll-text)
350 (scroll-text)
351 (do-nothing 10)
352 (play-moves [[:a]])
353 (scroll-text))]
354 buy-items)))
357 (defn buy-items
358 "Given a list of [item-no quantity], buys the quantity
359 from the shop's list. Assumes that the item list is
360 already up."
361 [item-pairs script]
362 (let [item-lookup (into {0 0 1 0 2 0 3 0 4 0} item-pairs)
363 initial-purchase
364 (->> script
365 (buy-item 0 (item-lookup 0))
366 (buy-item 1 (item-lookup 1))
367 (buy-item 2 (item-lookup 2)))]
368 (cond
369 (and
370 (not= 0 (item-lookup 3))
371 (not= 0 (item-lookup 4)))
372 (->> initial-purchase
373 (do-nothing 20)
374 (play-moves [[:d]])
375 (do-nothing 3)
376 (play-moves [[:d]])
377 (do-nothing 3)
378 (play-moves [[:d]])
379 (do-nothing 10)
380 (buy-item 0 (item-lookup 3))
381 (do-nothing 20)
382 (play-moves [[:d]])
383 (do-nothing 3)
384 (play-moves [[:d]])
385 (do-nothing 3)
386 (play-moves [[:d]])
387 (do-nothing 10)
388 (buy-item 0 (item-lookup 4)))
389 (and (= 0 (item-lookup 3))
390 (not= 0 (item-lookup 4)))
391 (->> initial-purchase
392 (do-nothing 20)
393 (play-moves [[:d]])
394 (do-nothing 3)
395 (play-moves [[:d]])
396 (do-nothing 3)
397 (play-moves [[:d]])
398 (do-nothing 10)
399 (play-moves [[:d]])
400 (do-nothing 10)
401 (buy-item 0 (item-lookup 4)))
402 (and (not= 0 (item-lookup 3))
403 (= 0 (item-lookup 4)))
404 (->> initial-purchase
405 (do-nothing 20)
406 (play-moves [[:d]])
407 (do-nothing 3)
408 (play-moves [[:d]])
409 (do-nothing 3)
410 (play-moves [[:d]])
411 (do-nothing 10)
412 (buy-item 0 (item-lookup 3)))
413 (and (= 0 (item-lookup 3))
414 (= 0 (item-lookup 4)))
415 initial-purchase)))
418 (defn test-buy-items
419 ([] (test-buy-items
420 (walk-to-counter)))
421 ([script]
422 (->> [(first script) (set-money (second script)
423 999999)]
424 (play-moves
425 [[] [:a] []])
426 (scroll-text)
427 (do-nothing 100)
428 (play-moves [[:a]])
429 (do-nothing 100)
430 (buy-items
431 [[0 1]
432 [1 15]
433 [2 1]
434 [3 20]
435 [4 95]
436 ]))))
438 (defn-memo buy-initial-items
439 ([] (buy-initial-items
440 (walk-to-counter)))
441 ([script]
442 (->> script
443 (play-moves
444 [[] [:a] []])
445 (scroll-text)
446 (do-nothing 100)
447 (play-moves [[:a]])
448 (do-nothing 100)
449 (buy-items
450 [[0 1]
451 [1 1]
452 [2 1]
453 [3 1]
454 [4 1]])
455 (do-nothing 100)
456 (play-moves [[:b]])
457 (do-nothing 100)
458 (play-moves [[:b]])
459 (do-nothing 100)
460 (play-moves [[:b] []])
461 (first-difference [:b] [:b :start] AF))))
464 (defn-memo do-save-corruption
465 ([] (do-save-corruption
466 (buy-initial-items)))
467 ([script]
468 (->> script
469 (first-difference [] [:d] AF)
470 (play-moves [[] [] [] [:d]
471 [] [] [] [:d]
472 [] [] [] [:d]
473 [] [] [:a]])
474 scroll-text
475 (play-moves
476 ;; this section is copied from speedrun-2942 and corrupts
477 ;; the save so that the total number of pokemon is set to
478 ;; 0xFF, allowing manipulation of non-pokemon data in RAM
479 ;; via the pokemon interface.
480 [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
481 [] [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])
482 (title)
483 (first-difference [] [:start] AF)
484 (first-difference [] [:a] AF)
485 (first-difference [:a] [:a :start] AF))))
487 (def menu do-nothing )
489 (defn-memo corrupt-item-list
490 ([] (corrupt-item-list
491 (do-save-corruption)))
492 ([script]
493 (->> script
494 (do-nothing 200)
495 (menu [↓ [:a]]) ; select "POKEMON" from
496 ; from main menu
497 (menu [↓ ↓ ↓ ↓ ↓ ↓ ; go to 6th pokemon
498 [:a] ↓ [:a] ; select "switch"
499 ↓ ↓ ↓ [:a]]) ; switch with 9th "pokemon"
501 (do-nothing 1))))
503 (defn-memo get-burn-heals
504 ([] (get-burn-heals
505 (corrupt-item-list)))
506 ([script]
507 (->> script
508 (menu [[:b] [:b]])
509 (menu [[:a]])
510 (do-nothing 100)
511 (menu [↓ [:a]])
512 (do-nothing 100)
513 (menu [[:a] ↓ [:a]])
514 (scroll-text)
515 (menu [[:b][:b]])
516 (menu [[:a]])
518 (do-nothing 50)
519 (buy-items [[0 1]])
520 (do-nothing 60)
521 (menu [[:a]])
522 (scroll-text)
524 (do-nothing 50)
525 (buy-items [[0 1]])
526 (do-nothing 60)
527 ;;(menu [[:a]])
528 ;;(scroll-text)
530 ;;(do-nothing 300)
531 ;;(menu [[:b] [:b]])
532 ;;(do-nothing 300)
534 (buy-items [[0 1]
535 [1 1]
536 [1 1]
537 [2 1]
538 [3 1]
539 [4 97]])
541 (do-nothing 10))))
543 (defn-memo corrupt-item-list-again
544 ([] (corrupt-item-list-again (get-burn-heals)))
545 ([script]
546 (->> script
547 (do-nothing 10)
548 (play-moves [[:b]])
549 (do-nothing 100)
550 (play-moves [[:b]])
551 (do-nothing 40)
552 (play-moves [[:b]])
553 (first-difference [:b] [:start :b] AF)
554 (menu [[:a] ↑ ↑ ↑ ↑ ↑ ; get fifth pokemon
555 [:a] ↓ [:a] ; and corrupt the
556 ↓ ↓ ↓ ↓ ↓ [:a]]) ; item list again by
557 ; switching it to
558 ))) ; tenth place.
560 (defn-memo viridian-store->viridian-poke-center
561 ([] (viridian-store->viridian-poke-center
562 (corrupt-item-list-again)))
563 ([script]
564 (->> script
565 (do-nothing 100)
566 (play-moves [[:b]])
567 (do-nothing 100)
568 (play-moves [[:b]])
569 (do-nothing 40)
570 ;; leave store
571 (walk [↓ ↓
572 → ↓ ↓])
573 (walk [← ← ← ←
574 ↓ ↓ ↓ ↓ ↓ ↓
575 ← ← ← ↑]))))
577 (defn-memo to-poke-center-computer
578 ([] (to-poke-center-computer
579 (viridian-store->viridian-poke-center)))
580 ([script]
581 (->> script
582 (walk [→ →
583 ↑ ↑ ↑
584 → → → → → → → → → ↑])
585 (do-nothing 1))))
587 (defn-memo begin-deposits
588 ([] (begin-deposits
589 (to-poke-center-computer)))
590 ([script]
591 (->> script
592 ;; access PC
593 (scroll-text 2)
595 ;; access item storage
596 (menu [[:a] [:d] [:a]])
597 (scroll-text 2)
599 ;; begin deposit
600 (menu [[:d] [:a]])
601 (do-nothing 40))))
603 (defn deposit-n-items
604 [n script]
605 (->> script
606 (do-nothing 100)
607 (play-moves [[:a]])
608 (do-nothing 80)
609 (multiple-times
610 (dec n)
611 (fn [script]
612 (->> script
613 (play-moves [[:u]])
614 (do-nothing 1))))
615 (play-moves [[:a]])
616 (scroll-text)))
618 (defn deposit-one-item
619 [script]
620 (->> script
621 (do-nothing 100)
622 (play-moves [[:a]])
623 (do-nothing 80)
624 (play-moves [[:a]])
625 (scroll-text)))
627 (defn-memo create-header
628 ([] (create-header (begin-deposits)))
629 ([script]
630 (->> script
631 (multiple-times 33 deposit-one-item)
632 (do-nothing 1))))
634 (defn bootstrap-init []
635 [(read-moves "bootstrap-init")
636 (read-state "bootstrap-init")])
638 (defn create-bootstrap-program
639 ([] (create-bootstrap-program
640 (create-header)))
641 ([script]
642 (->> script
643 (do-nothing 120)
644 (menu [↓ ↓ ↓ ↓ ↓ ↓ ↓])
645 ;;(deposit-n-items 33)
647 (menu (repeat 17 ↓))
651 (do-nothing 1))))
654 (defn test-pc-item-program []
655 (-> (read-state "bootstrap-init")
656 (set-memory pc-item-list-start 50)
657 (set-memory-range
658 map-function-address-start [0x8B 0xD5])
659 (set-memory-range
660 (inc pc-item-list-start)
661 (flatten
662 [(repeat
663 28
664 [0xFF 0x01])
665 [;; second part of item manipulation program
666 0x00 ;; this starts at address 0xD56C
667 0x2A ;; save (HL)=(target) to A, increment HL
669 0x00
670 0x47 ;; save A to B
672 0x00
673 0x3A ;; save (target+1) to A, decrement HL
675 0x00
676 0x22 ;; A -> target, increment HL [(target+1) -> target]
678 0x00
679 0x70 ;; load B into target+1 [(target) -> target+1]
681 0x00
682 0xC3 ;; first part of absolute jump
684 0x0C ;; return control to pokemon kernel
685 0x5F]
686 (repeat
687 5
688 [0xFF 0x01])
690 [;; first part of item manipulation program
691 0x00
692 0x21 ;; load target into HL
694 0x94 ;; this is the target address
695 0xD5
697 0x00 ;; relative jump back to first part
698 0x18
700 0xE1 ;; of program
701 0x01
703 0xFF ;; spacer
704 0x01
706 0x04 ;; target ID (pokeball)
707 0x3E ;; target Quantity (lemonade)
708 ]]))))