view clojure/com/aurellem/run/bootstrap_1.clj @ 594:ea448eecb615

improved route from celadon dept. store to celadon pokemon center.
author Robert McIntyre <rlm@mit.edu>
date Sat, 01 Sep 2012 12:52:46 -0500
parents daa3497bbe12
children 96ee9d72aeb9
line wrap: on
line source
1 (ns com.aurellem.run.bootstrap-1
2 (:use (com.aurellem.gb saves gb-driver util constants
3 items vbm characters money
4 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/pprint
13 (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-range
19 map-function-address-start
20 [0x8B 0xD5])
21 (set-memory-range
22 (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 (-> orig
28 (print-listing 0xD162 (+ 0xD162 20))
29 (run-moves (reduce concat
30 (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 s
40 (recur (close-menu s))))))
42 (defn-memo name-rival
43 ([] (name-rival (to-rival-name)))
44 ([script]
45 (->> script
46 (first-difference [] [:a] AF)
47 (first-difference [] [:r] DE)
48 (play-moves
49 [[]
50 [] [] [:r] [] [:d] [:a] ;; L
51 [:r] [] [:r] [] [:r] [] [:r] []
52 [:r] [] [:d] [] [:d] [:a] ;; [PK]
53 [:d] [] [:r] [:a]
54 ]))))
56 (defn-memo to-room-pc
57 ([] (to-room-pc (name-rival)))
58 ([script]
59 (->> script
60 finish-title
61 (walk [← ← ↑ ← ↑ ↑ ↑]))))
63 ;; (defn wait-for-quantity
64 ;; [[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-cursor
73 ;; [[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 (->> script
82 (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 (->> script
92 ;;(wait-for-cursor) ;; when selling, the cursor always
93 (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 (->> script
105 (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 (->> script
115 (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 (->> script
129 (set-cursor n)
130 (purchase-item quantity)))
132 (defn switch-items [item-fn idx-1 idx-2 script]
133 (->> script
134 (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] 100
140 #(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 (->> script
147 (switch-pc-items idx-1 (inc idx-1))))
149 (def desired-zero-quantities
150 (map second (filter (comp (partial = 0) first)
151 (partition 2 (pc-item-writer-program)))))
153 (defn bootstrap-corrupt-save
154 ([] (bootstrap-corrupt-save (to-room-pc)))
155 ([script]
156 (->> script
157 (do-save-corruption 3)
158 (corrupt-item-list 0)
159 close-all-menus)))
161 (defn-memo prepare-celadon-warp
162 ([] (prepare-celadon-warp (bootstrap-corrupt-save)))
163 ([script]
164 (->> script
165 (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-deposits
174 ([] (begin-initial-deposits
175 (prepare-celadon-warp)))
176 ([script]
177 (->> script
178 (first-difference [] [:a] AF)
179 (scroll-text)
180 (set-cursor 1)
181 select-menu-entry)))
183 (defn-memo initial-deposits
184 ([] (initial-deposits (begin-initial-deposits)))
185 ([script]
186 (->> script
187 (deposit-held-item 0 0x1)
188 ((fn [script]
189 (reduce
190 (fn [script item] (deposit-held-item item 0xFF script))
191 script
192 (range 3 (+ 13 3)))))
193 close-all-menus)))
196 ;;0 -- 256
197 ;;1 -- 254
198 ;;2 -- 254
199 ;;3 -- 255
201 (defn activate-home-pc
202 [script]
203 (->> script
204 (delayed-difference [] [:a]
205 200 first-character)
206 (scroll-text)))
208 (defn-memo restore-items
209 ([] (restore-items (initial-deposits)))
210 ([script]
211 (->> script
212 activate-home-pc
213 (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-celadon
221 ([] (to-celadon (restore-items)))
222 ([script]
223 (->> script
224 (walk [→ → → → → → → ↑
225 ↓ ↓ ↓ ↓ ↓ ← ← ← ←
226 ↓ ↓]))))
229 ;; celadon store inventory
231 ;; Floor 2
232 ;;=====================================
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 3
245 ;;=====================================
246 ;; TM18 (counter)
249 ;; Floor 4
250 ;;=====================================
251 ;; Poke Doll
252 ;; Fire Stone
253 ;; Thunder Stone
254 ;; Water Stone
255 ;; Leaf Stone
257 ;; Floor 5
258 ;;=====================================
259 ;; X Accuracy HP UP
260 ;; Guard Spec. Protein
261 ;; Dire Hit Iron
262 ;; X Attack Carbos
263 ;; X Defend Calcium
264 ;; X Speed
265 ;; X Special
267 ;; Roof
268 ;;=====================================
269 ;; Fresh Water TM13 (ice-beam)
270 ;; Soda Pop TM48 (rock-slide)
271 ;; Lemonade :) TM49 (tri-attack)
274 (defn-memo go-to-floor-two
275 ([] (go-to-floor-two (to-celadon)))
276 ([script]
277 (->> script
278 (walk [→ → ↑
279 ↑ ↑ ↑ ↑
280 ← ← ← ←
281 ↑ ↑
282 ← ← ← ←
283 ↓ ↓ ↓
284 ← ←])
285 (first-difference [] ↑ AF))))
287 (defn talk
288 "Assumes that you are facing something that initiates text and
289 causes it to do so."
290 [script]
291 (->> script
292 (delayed-difference [] [:a] 100
293 first-character)))
295 (defn-memo get-money-floor-two
296 ([] (get-money-floor-two (go-to-floor-two)))
297 ([script]
298 (->> script
299 talk
300 (set-cursor 1)
301 (select-menu-entry)
303 ;; These glitch items have to be sold one at a time
304 ;; because the game will only award up to 500000 at
305 ;; 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-TMs
312 ([] (floor-two-TMs (get-money-floor-two)))
313 ([script]
314 (->> script
315 (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-conversation
325 [script]
326 (->> script
327 (wait-until scroll-text [:b])
328 (play-moves [[] [:b]])
329 close-menu))
331 (defn-memo floor-two-more-money
332 ([] (floor-two-more-money (floor-two-TMs)))
333 ([script]
334 (->> script
335 (set-cursor 1)
336 (select-menu-entry)
337 (sell-held-item 0 1)
338 (sell-held-item 0 1)
339 close-menu
340 end-shop-conversation)))
342 (defn turn [direction script]
343 (->> script
344 (first-difference [] direction AF)))
346 (defn-memo floor-two-items
347 ([] (floor-two-items (floor-two-more-money)))
348 ([script]
349 (->> script
350 (walk [←])
351 (turn ↑)
352 talk
353 select-menu-entry
354 (buy-item 5 12) ;; burn heal
355 (buy-item 6 55) ;; ice heal
356 (buy-item 7 4) ;; awakening
357 (buy-item 8 99) ;; parlyz heal
358 (buy-item 8 55) ;; parlyz heal
359 close-menu
360 end-shop-conversation)))
362 (defn-memo go-to-floor-three
363 ([] (go-to-floor-three (floor-two-items)))
364 ([script]
365 (->> script
366 (walk [→ → → → → → → → → → ↑ ↑ ↑
367 → ↑]))))
368 (defn-memo get-TM18
369 ([] (get-TM18 (go-to-floor-three)))
370 ([script]
371 (->> script
372 (walk [↓ ↓])
373 talk
374 (scroll-text 3)
375 end-text)))
377 (defn-memo go-to-floor-four
378 ([] (go-to-floor-four (get-TM18)))
379 ([script]
380 (->> script
381 (walk [← ← ← ← ↑ ↑
382 ↓ ← ← ↓ ↓ ↓
383 ← ← ← ← ←])
384 (turn ↓))))
386 (defn-memo floor-four-items
387 ([] (floor-four-items (go-to-floor-four)))
388 ([script]
389 (->> script
390 talk
391 select-menu-entry
392 (buy-item 1 23) ;; Fire Stone
393 (buy-item 2 98) ;; Thunder Stone
394 (buy-item 3 29) ;; Water Stone
395 close-menu
396 end-shop-conversation)))
398 (defn-memo go-to-floor-five
399 ([] (go-to-floor-five (floor-four-items)))
400 ([script]
401 (->> script
402 (walk [→ → → → → →
403 ↑ ↑ ↑
404 → → → → → ↑ ;; leave floor four
405 ↓ ← ← ← ← ← ← ← ←
406 ↓ ↓ ↓ ← ← ← ]);; go to five's clerk
407 (turn ↑))))
409 (defn-memo floor-five-items
410 ([] (floor-five-items (go-to-floor-five)))
411 ([script]
412 (->> script
413 talk
414 select-menu-entry
415 (buy-item 0 58) ;; X-Accuracy
416 (buy-item 1 99) ;; Guard Spec.
417 (buy-item 1 24) ;; Guard Spec.
418 close-menu
419 end-shop-conversation)))
421 (defn-memo go-to-roof
422 ([] (go-to-roof (floor-five-items)))
423 ([script]
424 (->> script
425 (walk [→ → → → ↑ ↑ ↑ → → → ↑ ;; leave floor five
426 ↓ ← ← ←]) ;; walk to vending machine
427 (turn ↑))))
429 (defn buy-drink
430 "Assumes you're in front of the vending machine. Buys the indicated
431 drink."
432 [n script]
433 (->> script
434 (do-nothing 20)
435 (play-moves [[:a][:a]])
436 scroll-text
437 (set-cursor n)
438 select-menu-entry
439 close-menu))
441 (defn-memo roof-drinks
442 ([] (roof-drinks (go-to-roof)))
443 ([script]
444 (->> script
445 (buy-drink 0) ;; fresh water (for TM13)
446 ;; buy 16 lemonades
447 ;; LEMONADE is the best item <3 :)
448 (multiple-times 16 (partial buy-drink 2)))))
450 (defn-memo get-TM13
451 ([] (get-TM13 (roof-drinks)))
452 ([script]
453 (->> script
454 ;; alternate route depending on girl's motions
455 ;;(walk [← ← ← ← ← ← ↓])
456 (walk [↓ ↓ ↓ ← ← ← ← ← ←])
457 (play-moves [[][][][][:a][:a][]])
458 (scroll-text 3)
459 select-menu-entry
460 select-menu-entry
461 (scroll-text 6)
462 close-menu)))
464 (defn-memo to-celadon-poke-center
465 ([] (to-celadon-poke-center (get-TM13)))
466 ([script]
467 (->> script
468 ;; alternate route depending on girl's motions
469 ;;(walk [↑ → → → → → → → → → ↑]) ; leave roof
470 (walk [→ → → → → → → → → ↑ ↑ ↑ ↑])
471 (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ←
472 ↑ ↑ ↑ ← ← ↑]) ; to elevator
474 (walk [→ → ↑ ↑]) ; to controls
475 talk
476 select-menu-entry ; to floor 1
477 (walk [↓ ↓ ←])
478 (walk [↓ → ↓ ↓ ↓ ↓ ↓ ↓]) ; leave store
479 (walk [→ → → → → → → → → → ↑])
480 (walk (repeat 23 →))
481 (walk [↑ ↑ ↑ ↑]) ; enter poke center
482 (walk [↑ ↑ ↑ → → → → → → → → → →]) ; to computer
483 (turn ↑))))
485 (defn activate-rlm-pc [script]
486 (->> script
487 talk
488 scroll-text
489 ;;wait-for-cursor
490 (set-cursor 1)
491 select-menu-entry
492 (scroll-text 2)))
494 (defn begin-deposit [script]
495 (->> script
496 (set-cursor 1)
497 select-menu-entry))
499 (defn begin-withdraw [script]
500 (->> script
501 (set-cursor 0)
502 (select-menu-entry)))
504 (defn deposit-held-item-named
505 [item-name quantity [moves state :as script]]
506 (let [index (count
507 (take-while
508 (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-items
516 [script]
517 (->> script
518 select-menu-entry))
520 (defn to-held-items
521 [script]
522 (->> script
523 close-menu
524 close-menu
525 end-text;;; grr
527 activate-start-menu
528 open-held-items))
530 (defn toss-pc-item [n quantity [moves state :as script]]
531 (let [total-quantity (second (nth-pc-item state n))]
532 (->> script
533 (set-cursor n)
534 (select-menu-entry 1)
535 (set-quantity total-quantity quantity)
536 (delayed-difference [] [:a] 100 #(search-string % "Is"))
537 (scroll-text)
538 select-menu-entry
539 (scroll-text))))
541 (defn-memo hacking-1
542 ([] (hacking-1 (to-celadon-poke-center)))
543 ([script]
544 (->> script
545 activate-rlm-pc
546 begin-deposit
547 (deposit-held-item-named 0x00 30)
548 (deposit-held-item-named :TM01 63)
549 (deposit-held-item-named :awakening 4)
550 (deposit-held-item-named :thunderstone 98)
551 (deposit-held-item-named :TM09 55)
552 (deposit-held-item-named 0x00 55))))
554 (defn-memo hacking-2
555 ([] (hacking-2 (hacking-1)))
556 ([script]
557 (->> script
558 (to-held-items)
559 (toss-held-item 0 166) ;; discard cruft
560 close-menu
561 close-menu)))
563 (defn-memo hacking-3
564 ([] (hacking-3 (hacking-2)))
565 ([script]
566 (->> script
567 activate-rlm-pc
568 begin-withdraw
569 (widthdraw-pc-item 0 99)
570 (widthdraw-pc-item 0 1)
571 (widthdraw-pc-item 2 0xFE)
572 (widthdraw-pc-item 3 0xFE)
573 close-menu)))
575 (defn-memo hacking-4
576 ([] (hacking-4 (hacking-3)))
577 ([script]
578 (->> script
579 begin-deposit
580 (deposit-held-item 19 243)
581 (deposit-held-item-named :lemonade 16)
582 (deposit-held-item 18 224))))
584 (defn-memo hacking-5
585 "clean out the held-item list again"
586 ([] (hacking-5 (hacking-4)))
587 ([script]
588 (->> script
589 (to-held-items)
590 (toss-held-item 18 30)
591 (toss-held-item 17 1)
592 close-menu
593 close-menu)))
595 (defn-memo hacking-6
596 ([] (hacking-6 (hacking-5)))
597 ([script]
598 (->> script
599 activate-rlm-pc
600 begin-withdraw
601 (widthdraw-pc-item 4 0xFE)
602 (widthdraw-pc-item 5 0xFE)
603 (widthdraw-pc-item 6 0xFE)
604 close-menu)))
606 (defn-memo hacking-7
607 ([] (hacking-7 (hacking-6)))
608 ([script]
609 (->> script
610 begin-deposit
611 (deposit-held-item 19 240)
612 (deposit-held-item 18 230)
613 (deposit-held-item-named :parlyz-heal 55)
614 (deposit-held-item 17 184)
615 (deposit-held-item 17 40)
616 (deposit-held-item-named :TM37 71)
617 (deposit-held-item-named :ice-heal 55)
618 (deposit-held-item-named :fire-stone 23)
619 (deposit-held-item-named :burn-heal 12)
620 ;; as a special case, /don't/ close the menu.
621 )))
623 (defn-memo hacking-8
624 "Clear cruft away from held item list."
625 ([] (hacking-8 (hacking-7)))
626 ([script]
627 (->> script
628 to-held-items
629 (toss-held-item 15 1)
630 (toss-held-item 14 1)
631 (toss-held-item 13 1)
632 close-menu
633 close-menu)))
635 (defn-memo hacking-9
636 ([] (hacking-9 (hacking-8)))
637 ([script]
638 (->> script
639 activate-rlm-pc
640 begin-withdraw
641 (widthdraw-pc-item 7 0xFE)
642 (widthdraw-pc-item 8 0xFC)
643 (widthdraw-pc-item 8 1)
644 (widthdraw-pc-item 8 1)
645 (widthdraw-pc-item 9 0xFE)
646 (multiple-times
647 7
648 (partial combine-pc-items 2))
649 close-menu)))
651 (defn-memo hacking-10
652 ([] (hacking-10 (hacking-9)))
653 ([script]
654 (->> script
655 begin-deposit
656 (deposit-held-item 17 230)
657 (deposit-held-item-named :parlyz-heal 55)
658 (deposit-held-item 14 178)
659 (deposit-held-item-named :water-stone 29)
660 (deposit-held-item 14 32)
661 (deposit-held-item-named :TM18 1)
662 (deposit-held-item 13 1)
663 (deposit-held-item 13 191)
664 (deposit-held-item-named :TM02 98)
665 (deposit-held-item-named :TM09 1)
666 close-menu)))
668 (defn-memo hacking-11
669 ([] (hacking-11 (hacking-10)))
670 ([script]
671 (->> script
672 begin-withdraw
673 (widthdraw-pc-item 3 0xFE)
674 (widthdraw-pc-item 4 0xFE)
675 (widthdraw-pc-item 5 1)
676 (widthdraw-pc-item 5 1)
677 (widthdraw-pc-item 5 1)
678 (widthdraw-pc-item 5 0xFB)
679 (multiple-times
680 3
681 (partial combine-pc-items 2))
682 close-menu)))
684 (defn-memo hacking-12
685 ([] (hacking-12 (hacking-11)))
686 ([script]
687 (->> script
688 begin-deposit
689 (deposit-held-item 18 203)
690 (deposit-held-item-named :guard-spec 87)
691 (deposit-held-item-named :guard-spec 24)
692 (deposit-held-item-named :TM05 1)
693 (multiple-times
694 8
695 (partial deposit-held-item 14 1))
696 (deposit-held-item 14 55)
697 (deposit-held-item-named :x-accuracy 58)
698 (deposit-held-item 14 38)
699 (deposit-held-item-named :TM13 1)
700 (deposit-held-item 13 1)
701 (deposit-held-item 13 233)
702 close-menu)))
704 (defn-memo hacking-13
705 ([] (hacking-13 (hacking-12)))
706 ([script]
707 (->> script
708 (set-cursor-relative 1)
709 (select-menu-entry)
710 (toss-pc-item 1 1)
711 (toss-pc-item 0 156)
712 (toss-pc-item 0 11))))
714 (defn confirm-pattern []
715 (let [start-address (inc pc-item-list-start)
716 target-pattern (pc-item-writer-program)
717 actual-pattern
718 (subvec (vec (memory (second (hacking-13))))
719 start-address
720 (+ start-address (count target-pattern)))]
721 (println target-pattern)
722 (println actual-pattern)
723 (= target-pattern actual-pattern)))
725 (defn-memo go-to-mansion-for-the-lulz
726 ([] (go-to-mansion-for-the-lulz (hacking-13)))
727 ([script]
728 (->> script
729 close-menu
730 close-menu
731 end-text ;;grr
732 (walk [↓ ← ← ← ← ← ← ← ← ← ↓ ↓ ↓])
733 (walk (repeat 17 ←))
734 (walk [↑ → → → → ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])
735 (walk [↓ ← ↑])
736 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓
737 ← ← ← ← ↑ ↑ ↑ ← ↑])
738 (talk)
739 (scroll-text 2)
740 (do-nothing 100)
741 close-menu)))
743 (defn-memo launch-bootstrap-program
744 ([] (launch-bootstrap-program
745 (go-to-mansion-for-the-lulz)))
746 ([script]
747 (->> script
748 ;; must corrupt item list again by switching pokemon
749 activate-start-menu ;; \
750 (set-cursor 0) ;; |
751 select-menu-entry ;; |
752 select-menu-entry ;; |
753 (set-cursor 1) ;; | -- switch 9th pokemon
754 select-menu-entry ;; | with 4th pokemon
755 (set-cursor 3) ;; |
756 select-menu-entry ;; |
757 close-menu ;; /
758 ;; now, open items and set map-function to
759 ;; the program inside the item-computer.
760 (set-cursor 1)
761 (select-menu-entry)
762 (toss-held-item 22 12)
763 (switch-held-items 22 40)
764 close-all-menus)))
766 (defn regen-control-checkpoint!
767 [] (write-script! (launch-bootstrap-program) "control-checkpoint"))
769 (defn control-checkpoint []
770 (read-script "control-checkpoint"))
772 (def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF])
774 (defn test-pattern-writing
775 ([] (test-pattern-writing increasing-pattern))
776 ([pattern]
777 (let [moves (bootstrap-pattern pattern)
778 pattern-insertion
779 (->> (launch-bootstrap-program)
780 (play-moves
781 (take 100 moves)))]
782 (println "Input Pattern:")
783 (apply println (map #(format "0x%02X" %) pattern))
784 (println "\nMemory Listing:")
785 (print-listing (second pattern-insertion)
786 0xD162 (+ 0xD162 (count pattern)))
787 (= (subvec (vec (memory (second pattern-insertion)))
788 0xD162 (+ 0xD162 (count pattern)))
789 pattern))))
791 (defn-memo launch-main-bootstrap-program
792 ([] (launch-main-bootstrap-program
793 (control-checkpoint)
794 ;;(launch-bootstrap-program)
795 ))
796 ([script]
797 (->> script
798 (play-moves
799 (bootstrap-pattern (main-bootstrap-program)))
800 (play-moves
801 (take 253 (interleave (repeat 1000 [:b])
802 (repeat 1000 [])))))))
803 (def bootstrap-start pokemon-list-start)
805 (defn test-main-bootstrap-integrety
806 []
807 (assert
808 (= (main-bootstrap-program)
809 (subvec
810 (vec (memory (second (launch-main-bootstrap-program))))
811 pokemon-list-start
812 (+ pokemon-list-start (count (main-bootstrap-program)))))))
814 (defn set-target-address
815 "Assumes that the game is under control of the main-bootstrap
816 program in MODE-SELECT mode, and sets the target address to which
817 jumps/writes will occur."
818 [target-address script]
819 (let [[target-high target-low] (disect-bytes-2 target-address)]
820 (->> script
821 (play-moves
822 (map buttons
823 [set-H-mode target-high 0x00
824 set-L-mode target-low 0x00])))))
826 (defn write-RAM-segment
827 "Assumes that the game is under control of the main-bootstrap
828 program in MODE-SELECT mode and that target-address has been
829 appropriately set, and writes 255 bytes or less to RAM."
830 [segment script]
831 (->> script
832 (play-moves
833 (map buttons
834 [write-mode (count segment)]))
835 (play-moves (map buttons segment))
836 (play-moves [[]])))
838 (defn write-RAM
839 "Assumes that the game is under control of the main-bootstrap
840 program in MODE-SELECT mode, and rewrites RAM starting at
841 'start-address with 'new-ram."
842 [start-address new-ram script]
843 (loop [s (set-target-address start-address script)
844 to-write new-ram]
845 (if (< (count to-write) 0x100)
846 (write-RAM-segment to-write s)
847 (recur
848 (write-RAM-segment (take 0xFF to-write) s)
849 (drop 0xFF to-write)))))
851 (defn transfer-control
852 "Assumes that the game is under control of the main-bootstrap
853 program in MODE-SELECT mode, and jumps to the target-address."
854 [target-address script]
855 (->> script
856 (set-target-address target-address)
857 (play-moves [(buttons jump-mode)])))
860 (def relocated-bootstrap-start
861 (+ 90 pokemon-box-1-address))
863 (defn-memo relocate-main-bootstrap
864 ([] (relocate-main-bootstrap (launch-main-bootstrap-program)))
865 ([script]
866 (->> script
867 (do-nothing 2)
868 (write-RAM
869 relocated-bootstrap-start
870 (main-bootstrap-program
871 relocated-bootstrap-start))
872 (do-nothing 1)
873 (transfer-control relocated-bootstrap-start)
874 (do-nothing 1))))
876 (defn gen-new-kernel-checkpoint! []
877 (write-script! (do-nothing 10 (relocate-main-bootstrap))
878 "new-kernel"))
880 (defn new-kernel [] (read-script "new-kernel"))
882 (def mid-game-data
883 (subvec (vec (memory (mid-game)))
884 pokemon-list-start
885 (+ pokemon-list-start 697)))
887 (def mid-game-map-address 0x46BC)
889 (defn-memo set-mid-game-data
890 ([] (set-mid-game-data (relocate-main-bootstrap)))
891 ([script]
892 (->> script
893 (do-nothing 10)
894 (write-RAM pokemon-list-start
895 mid-game-data))))
896 (defn test-set-data
897 ([] (test-set-data (relocate-main-bootstrap)))
898 ([script]
899 (->> script
900 (do-nothing 10)
901 (write-RAM pokemon-list-start
902 (repeat 500 0xCC)))))
904 (defn test-mid-game-transfer []
905 (= (subvec (vec (memory (second (set-mid-game-data))))
906 pokemon-list-start
907 (+ pokemon-list-start 500))
908 (subvec (vec (memory (mid-game)))
909 pokemon-list-start
910 (+ pokemon-list-start 500))))
912 (defn-memo return-to-pokemon-kernel
913 ([] (return-to-pokemon-kernel (set-mid-game-data)))
914 ([script]
915 (let [scratch (+ 200 pokemon-box-1-address)
916 return-program
917 (flatten
918 [0xFB
919 0xC3
920 (reverse (disect-bytes-2 mid-game-map-address))])]
921 (->> script
922 (write-RAM scratch return-program)
923 (transfer-control scratch)
924 (do-nothing 1)))))