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-0
2 (:use (com.aurellem.gb saves gb-driver util
3 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-name
12 ([] (to-rival-name (boot-root)))
13 ([script]
14 (->> script
15 title
16 oak
17 name-entry-rlm
18 (scroll-text 5))))
20 (defn-memo name-rival-bootstrap
21 ([] (name-rival-bootstrap (to-rival-name)))
22 ([script]
23 (->> script
24 (first-difference [] [:a] AF)
25 (first-difference [] [:r] DE)
26 (play-moves
27 [[]
28 [] [] [:r] [] [:d] [:a] ;; L
29 [:r] [] [:r] [] [:r] [] [:r] []
30 [:r] [] [:d] [] [:d] [:a] ;; [PK]
31 [:u] [] [:l] [] [:l] []
32 [:l] [] [:l] [] [:l] [:a] ;; U
33 [:r] [] [:r] [] [:r] []
34 [:r] [] [:r] [] [:d] [:a] ;; [PK]
35 [] [:a] ;; [PK]
36 [] [:a] ;; [PK]
37 [:r] [] [:d] [:a] ;; END
38 ]))))
40 (defn-memo leave-house
41 ([] (leave-house (name-rival-bootstrap)))
42 ([script]
43 (->> script
44 finish-title
45 walk-to-stairs
46 walk-to-door
47 (walk [↓ ↓]))))
49 (defn-memo to-pallet-town-edge
50 ([] (to-pallet-town-edge (leave-house)))
51 ([script]
52 (->> script
53 (walk [→ → → → →
54 ↑ ↑ ↑ ↑ ↑ ↑]))))
56 (defn-memo start-pikachu-battle
57 ([] (start-pikachu-battle
58 (to-pallet-town-edge)))
59 ([script]
60 (->> script
61 (first-difference [:b] [:b :a] DE)
62 scroll-text
63 (do-nothing 200)
64 (play-moves [[:b]]))))
66 (defn-memo capture-pikachu
67 ([] (capture-pikachu (start-pikachu-battle)))
68 ([script]
69 (->> script
70 (scroll-text 3))))
72 (defn-memo go-to-lab
73 ([] (go-to-lab (capture-pikachu)))
74 ([script]
75 (->> script
76 end-text
77 (scroll-text 5)
78 end-text
79 ;; oak walks you to his lab; no input required.
80 (do-nothing 400))))
82 (defn-memo talk-to-oak-in-lab
83 ([] (talk-to-oak-in-lab (go-to-lab)))
84 ([script]
85 (->> script
86 (scroll-text 14)
87 end-text)))
89 (defn-memo try-to-get-eevee
90 ([] (try-to-get-eevee (talk-to-oak-in-lab)))
91 ([script]
92 (->> script
93 ;; walk to pokeball
94 (walk [↓ → →])
95 ;; and try to grab it
96 (play-moves
97 (concat [↑ ↑ [:a]]
98 (repeat 100 [])))
99 (scroll-text 10)
100 (end-text))))
102 (defn-memo obtain-pikachu
103 ([] (obtain-pikachu (try-to-get-eevee)))
104 ([script]
105 (->> script
106 (scroll-text 6)
107 (end-text))))
110 (defn-memo begin-battle-with-rival
111 ([] (begin-battle-with-rival
112 (obtain-pikachu)))
113 ([script]
114 (->> script
115 (walk [↓ ↓ ↓])
116 (scroll-text 3)
117 (end-text)
118 (scroll-text))))
120 (defn-memo defeat-eevee
121 ([] (defeat-eevee
122 (begin-battle-with-rival)))
123 ([script]
124 (->> script
125 (do-nothing 400)
126 (play-moves [[:a]])
127 (critical-hit)
128 (do-nothing 200)
129 (scroll-text 2) ;; for eevee's tail-whip
130 (do-nothing 10)
131 (play-moves [[:a]])
132 (critical-hit)
133 (do-nothing 200)
134 (scroll-text 2) ;; tail whip again
135 (do-nothing 10)
136 (play-moves [[:a]])
137 (critical-hit)
138 (do-nothing 200))))
140 (defn-memo finish-rival-text
141 ([] (finish-rival-text
142 (defeat-eevee)))
143 ([script]
144 (->> script
145 (scroll-text 12)
146 (end-text))))
148 (defn-memo pikachu-comes-out
149 ([] (pikachu-comes-out
150 (finish-rival-text)))
151 ([script]
152 (->> script
153 (scroll-text 8)
154 (end-text))))
156 (defn-memo leave-oaks-lab
157 ([] (leave-oaks-lab
158 (pikachu-comes-out)))
159 ([script]
160 (->> script
161 (walk [↓ ↓ ↓ ↓ ↓ ↓]))))
163 (defn-memo oaks-lab->pallet-town-edge
164 ([] (oaks-lab->pallet-town-edge
165 (leave-oaks-lab)))
166 ([script]
167 (->> script
168 (walk [← ← ←
169 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ →]))))
171 (defn-memo pallet-edge->viridian-mart
172 ([] (pallet-edge->viridian-mart true
173 (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 (->> script
183 ;; leave straight grass
184 (walk-thru-grass
185 [↑ ↑ ↑ ↑ ↑])
187 (walk [↑ ↑ ↑ ↑])
189 (walk-thru-grass
190 [← ← ↑])
192 (walk [↑ ↑ ↑ ↑ → → → ])
194 (walk-thru-grass
195 [→ ↑ ↑ ←])
197 (walk
198 [← ←
199 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
200 → → → → ])
202 ;; this part is dependent on that
203 ;; stupid NPC in the grass patch
204 (walk-thru-grass
205 (concat dodge-1
206 [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ]))
208 (walk
209 (concat
210 dodge-2
211 [← ← ←
212 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
213 ← ←
214 ↑ ↑ ↑ ↑
215 → → → → → → → → → →
216 ↑ ↑ ↑ ↑ ↑ ↑ ↑]))))))
218 (defn-memo get-oaks-parcel
219 ([] (get-oaks-parcel
220 (pallet-edge->viridian-mart)))
221 ([script]
222 (->> script
223 (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-lab
231 ([] (viridian-store->oaks-lab
232 (get-oaks-parcel)))
233 ([script]
234 (->> script
235 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
236 ← ← ← ← ← ← ← ← ←
237 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
238 ← ←
239 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
240 ↓ ↓ ↓ ↓ ↓ ↓ ↓
241 → → → → → → → →
242 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
243 ← ← ← ← ←
244 ↓ ↓ ↓ ↓
245 ])
246 (walk-thru-grass
247 [↓ ↓ ↓ ↓ ↓ ↓ ↓])
248 (walk [↓ ↓ ← ↓ ↓ ↓ ←
249 ↓ ↓ ↓ ↓ ↓ ↓
250 → → → ↑])
252 (do-nothing 1))))
255 (defn-memo viridian-store->oaks-lab-like-a-boss
256 ([] (viridian-store->oaks-lab-like-a-boss
257 (get-oaks-parcel)))
258 ([script]
259 (->> script
260 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
261 ← ← ← ← ← ← ← ← ←
262 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓])
264 (walk-thru-grass
265 [↓ ↓ ↓ ↓ ↓])
267 (walk
268 [↓ ↓ ← ↓
269 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
270 → → → ↓])
272 (walk-thru-grass
273 [↓ ↓ ↓])
275 (walk [↓ ← ← ↓ ↓ ↓ ↓ ↓ ↓])
277 (walk-thru-grass
278 [↓ ↓ ↓ ↓ ↓ ↓])
280 (walk [↓ ↓ ↓ ← ↓ ↓ ↓
281 ↓ ↓ ↓ ↓ ↓
282 → → → ↑]))))
284 (defn-memo deliver-oaks-parcel
285 ([] (deliver-oaks-parcel
286 (viridian-store->oaks-lab-like-a-boss)))
287 ([script]
288 (->> script
289 (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-mart
307 ([] (return-to-viridian-mart
308 (deliver-oaks-parcel)))
309 ([script]
310 (->> script
311 oaks-lab->pallet-town-edge
312 (pallet-edge->viridian-mart false))))
314 (defn-memo walk-to-counter
315 ([] (walk-to-counter
316 (return-to-viridian-mart)))
317 ([script]
318 (->> script
319 (walk [↑ ↑ ←]))))
323 ;; useful addresses
324 52262 ;; --- current-cursor-offset
325 52278 ;; --- current screen-offset
328 (defn exp-item-list []
329 (clojure.pprint/pprint
330 (apply harmonic-compare
331 (map read-state
332 ["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-item
342 "Assumes that the main item-screen is up, and buys
343 quantity of the nth item in the list, assuming that you
344 have enough money."
345 [n quantity script]
346 (if (= 0 quantity)
347 script
348 (let [after-initial-pause
349 (do-nothing 20 script)
350 move-to-item
351 (reduce (fn [script _]
352 (->> script
353 (play-moves [[:d]])
354 (do-nothing 3)))
355 after-initial-pause
356 (range n))
357 select-item
358 (play-moves [[:a]] move-to-item)
359 request-items
360 (reduce (fn [script _]
361 (->> script
362 (play-moves [[:u]])
363 (do-nothing 1)))
364 select-item
365 (range (dec quantity)))
366 buy-items
367 (->> request-items
368 (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-items
379 "Given a list of [item-no quantity], buys the quantity
380 from the shop's list. Assumes that the item list is
381 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-purchase
385 (->> script
386 (buy-item 0 (item-lookup 0))
387 (buy-item 1 (item-lookup 1))
388 (buy-item 2 (item-lookup 2)))]
389 (cond
390 (and
391 (not= 0 (item-lookup 3))
392 (not= 0 (item-lookup 4)))
393 (->> initial-purchase
394 (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-purchase
413 (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-purchase
426 (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-items
440 ([] (test-buy-items
441 (walk-to-counter)))
442 ([script]
443 (->> [(first script) (set-money (second script)
444 999999)]
445 (play-moves
446 [[] [:a] []])
447 (scroll-text)
448 (do-nothing 100)
449 (play-moves [[:a]])
450 (do-nothing 100)
451 (buy-items
452 [[0 1]
453 [1 15]
454 [2 1]
455 [3 20]
456 [4 95]
457 ]))))
459 (defn-memo buy-initial-items
460 ([] (buy-initial-items
461 (walk-to-counter)))
462 ([script]
463 (->> script
464 (play-moves
465 [[] [:a] []])
466 (scroll-text)
467 (do-nothing 100)
468 (play-moves [[:a]])
469 (do-nothing 100)
470 (buy-items
471 [[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-corruption
486 ([] (do-save-corruption
487 (buy-initial-items)))
488 ([script]
489 (->> script
490 (first-difference [] [:d] AF)
491 (play-moves [[] [] [] [:d]
492 [] [] [] [:d]
493 [] [] [] [:d]
494 [] [] [:a]])
495 scroll-text
496 (play-moves
497 ;; this section is copied from speedrun-2942 and corrupts
498 ;; the save so that the total number of pokemon is set to
499 ;; 0xFF, allowing manipulation of non-pokemon data in RAM
500 ;; 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-list
511 ([] (corrupt-item-list
512 (do-save-corruption)))
513 ([script]
514 (->> script
515 (do-nothing 200)
516 (menu [↓ [:a]]) ; select "POKEMON" from
517 ; from main menu
518 (menu [↓ ↓ ↓ ↓ ↓ ↓ ; go to 6th pokemon
519 [:a] ↓ [:a] ; select "switch"
520 ↓ ↓ ↓ [:a]]) ; switch with 9th "pokemon"
522 (do-nothing 1))))
524 (defn-memo get-burn-heals
525 ([] (get-burn-heals
526 (corrupt-item-list)))
527 ([script]
528 (->> script
529 (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-again
565 ([] (corrupt-item-list-again (get-burn-heals)))
566 ([script]
567 (->> script
568 (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 pokemon
576 [:a] ↓ [:a] ; and corrupt the
577 ↓ ↓ ↓ ↓ ↓ [:a]]) ; item list again by
578 ; switching it to
579 ))) ; tenth place.
581 (defn-memo viridian-store->viridian-poke-center
582 ([] (viridian-store->viridian-poke-center
583 (corrupt-item-list-again)))
584 ([script]
585 (->> script
586 (do-nothing 100)
587 (play-moves [[:b]])
588 (do-nothing 100)
589 (play-moves [[:b]])
590 (do-nothing 40)
591 ;; leave store
592 (walk [↓ ↓
593 → ↓ ↓])
594 (walk [← ← ← ←
595 ↓ ↓ ↓ ↓ ↓ ↓
596 ← ← ← ↑]))))
598 (defn-memo to-poke-center-computer
599 ([] (to-poke-center-computer
600 (viridian-store->viridian-poke-center)))
601 ([script]
602 (->> script
603 (walk [→ →
604 ↑ ↑ ↑
605 → → → → → → → → → ↑])
606 (do-nothing 1))))
608 (defn-memo begin-deposits
609 ([] (begin-deposits
610 (to-poke-center-computer)))
611 ([script]
612 (->> script
613 ;; access PC
614 (scroll-text 2)
616 ;; access item storage
617 (menu [[:a] [:d] [:a]])
618 (scroll-text 2)
620 ;; begin deposit
621 (menu [[:d] [:a]])
622 (do-nothing 40))))
624 (defn deposit-n-items
625 [n script]
626 (->> script
627 (do-nothing 100)
628 (play-moves [[:a]])
629 (do-nothing 80)
630 (multiple-times
631 (dec n)
632 (fn [script]
633 (->> script
634 (play-moves [[:u]])
635 (do-nothing 1))))
636 (play-moves [[:a]])
637 (scroll-text)))
639 (defn deposit-one-item
640 [script]
641 (->> script
642 (do-nothing 100)
643 (play-moves [[:a]])
644 (do-nothing 80)
645 (play-moves [[:a]])
646 (scroll-text)))
648 (defn-memo create-header
649 ([] (create-header (begin-deposits)))
650 ([script]
651 (->> script
652 (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-program
660 ([] (create-bootstrap-program
661 (create-header)))
662 ([script]
663 (->> script
664 (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-range
679 map-function-address-start [0x8B 0xD5])
680 (set-memory-range
681 (inc pc-item-list-start)
682 (flatten
683 [(repeat
684 28
685 [0xFF 0x01])
686 [;; second part of item manipulation program
687 0x00 ;; this starts at address 0xD56C
688 0x2A ;; save (HL)=(target) to A, increment HL
690 0x00
691 0x47 ;; save A to B
693 0x00
694 0x3A ;; save (target+1) to A, decrement HL
696 0x00
697 0x22 ;; A -> target, increment HL [(target+1) -> target]
699 0x00
700 0x70 ;; load B into target+1 [(target) -> target+1]
702 0x00
703 0xC3 ;; first part of absolute jump
705 0x0C ;; return control to pokemon kernel
706 0x5F]
707 (repeat
708 5
709 [0xFF 0x01])
711 [;; first part of item manipulation program
712 0x00
713 0x21 ;; load target into HL
715 0x94 ;; this is the target address
716 0xD5
718 0x00 ;; relative jump back to first part
719 0x18
721 0xE1 ;; of program
722 0x01
724 0xFF ;; spacer
725 0x01
727 0x04 ;; target ID (pokeball)
728 0x3E ;; target Quantity (lemonade)
729 ]]))))