view clojure/com/aurellem/run/bootstrap_1.clj @ 593:daa3497bbe12

increased speed to travel to floor two of celadon dept. store.
author Robert McIntyre <rlm@mit.edu>
date Sat, 01 Sep 2012 12:38:26 -0500
parents cd557c922cec
children ea448eecb615
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)
302 (sell-held-item 0 1)
303 (sell-held-item 0 1)
304 (close-menu))))
306 (defn-memo floor-two-TMs
307 ([] (floor-two-TMs (get-money-floor-two)))
308 ([script]
309 (->> script
310 (set-cursor 0)
311 (select-menu-entry)
312 (buy-item 2 98) ;; TM02 (razor-wind)
313 (buy-item 4 71) ;; TM37 (doubleteam)
314 (buy-item 5 63) ;; TM01 (mega-punch)
315 (buy-item 6 1) ;; TM05 (mega-kick)
316 (buy-item 7 56) ;; TM09 (take-down)
317 (close-menu))))
319 (defn end-shop-conversation
320 [script]
321 (->> script
322 (wait-until scroll-text [:b])
323 (play-moves [[] [:b]])
324 close-menu))
326 (defn-memo floor-two-more-money
327 ([] (floor-two-more-money (floor-two-TMs)))
328 ([script]
329 (->> script
330 (set-cursor 1)
331 (select-menu-entry)
332 (sell-held-item 0 1)
333 (sell-held-item 0 1)
334 close-menu
335 end-shop-conversation)))
337 (defn turn [direction script]
338 (->> script
339 (first-difference [] direction AF)))
341 (defn-memo floor-two-items
342 ([] (floor-two-items (floor-two-more-money)))
343 ([script]
344 (->> script
345 (walk [←])
346 (turn ↑)
347 talk
348 select-menu-entry
349 (buy-item 5 12) ;; burn heal
350 (buy-item 6 55) ;; ice heal
351 (buy-item 7 4) ;; awakening
352 (buy-item 8 99) ;; parlyz heal
353 (buy-item 8 55) ;; parlyz heal
354 close-menu
355 end-shop-conversation)))
357 (defn-memo go-to-floor-three
358 ([] (go-to-floor-three (floor-two-items)))
359 ([script]
360 (->> script
361 (walk [→ → → → → → → → → → ↑ ↑ ↑
362 → ↑]))))
363 (defn-memo get-TM18
364 ([] (get-TM18 (go-to-floor-three)))
365 ([script]
366 (->> script
367 (walk [↓ ↓])
368 talk
369 (scroll-text 3)
370 end-text)))
372 (defn-memo go-to-floor-four
373 ([] (go-to-floor-four (get-TM18)))
374 ([script]
375 (->> script
376 (walk [← ← ← ← ↑ ↑
377 ↓ ← ← ↓ ↓ ↓
378 ← ← ← ← ←])
379 (turn ↓))))
381 (defn-memo floor-four-items
382 ([] (floor-four-items (go-to-floor-four)))
383 ([script]
384 (->> script
385 talk
386 select-menu-entry
387 (buy-item 1 23) ;; Fire Stone
388 (buy-item 2 98) ;; Thunder Stone
389 (buy-item 3 29) ;; Water Stone
390 close-menu
391 end-shop-conversation)))
393 (defn-memo go-to-floor-five
394 ([] (go-to-floor-five (floor-four-items)))
395 ([script]
396 (->> script
397 (walk [→ → → → → →
398 ↑ ↑ ↑
399 → → → → → ↑ ;; leave floor four
400 ↓ ← ← ← ← ← ← ← ←
401 ↓ ↓ ↓ ← ← ← ]);; go to five's clerk
402 (turn ↑))))
404 (defn-memo floor-five-items
405 ([] (floor-five-items (go-to-floor-five)))
406 ([script]
407 (->> script
408 talk
409 select-menu-entry
410 (buy-item 0 58) ;; X-Accuracy
411 (buy-item 1 99) ;; Guard Spec.
412 (buy-item 1 24) ;; Guard Spec.
413 close-menu
414 end-shop-conversation)))
416 (defn-memo go-to-roof
417 ([] (go-to-roof (floor-five-items)))
418 ([script]
419 (->> script
420 (walk [→ → → → ↑ ↑ ↑ → → → ↑ ;; leave floor five
421 ↓ ← ← ←]) ;; walk to vending machine
422 (turn ↑))))
424 (defn buy-drink
425 "Assumes you're in front of the vending machine. Buys the indicated
426 drink."
427 [n script]
428 (->> script
429 (do-nothing 20)
430 (play-moves [[:a][:a]])
431 scroll-text
432 (set-cursor n)
433 select-menu-entry
434 close-menu))
436 (defn-memo roof-drinks
437 ([] (roof-drinks (go-to-roof)))
438 ([script]
439 (->> script
440 (buy-drink 0) ;; fresh water (for TM13)
441 ;; buy 16 lemonades
442 ;; LEMONADE is the best item <3 :)
443 (multiple-times 16 (partial buy-drink 2)))))
445 (defn-memo get-TM13
446 ([] (get-TM13 (roof-drinks)))
447 ([script]
448 (->> script
449 ;;(walk [← ← ← ← ← ← ↓])
450 (walk [↓ ↓ ↓ ← ← ← ← ← ←])
451 (play-moves [[][][][][:a][:a][]])
452 (scroll-text 3)
453 select-menu-entry
454 select-menu-entry
455 (scroll-text 6)
456 close-menu)))
458 (defn-memo to-celadon-poke-center
459 ([] (to-celadon-poke-center (get-TM13)))
460 ([script]
461 (->> script
462 ;;(walk [↑ → → → → → → → → → ↑]) ; leave roof
463 (walk [→ → → → → → → → → ↑ ↑ ↑ ↑])
464 (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ←
465 ↑ ↑ ↑ ← ← ↑]) ; to elevator
467 (walk [→ → ↑ ↑]) ; to controls
468 talk
469 select-menu-entry ; to floor 1
470 (walk [↓ ↓ ← ←])
471 (walk [↓ → ↓ ↓ ↓ ↓ ↓ ↓]) ; leave store
472 (walk [↓ → → → → → → → → → → ↑ ↑])
473 (walk (repeat 23 →))
474 (walk [↑ ↑ ↑ ↑]) ; enter poke center
475 (walk [↑ ↑ ↑ → → → → → → → → → →]) ; to computer
476 (turn ↑))))
478 (defn activate-rlm-pc [script]
479 (->> script
480 talk
481 scroll-text
482 ;;wait-for-cursor
483 (set-cursor 1)
484 select-menu-entry
485 (scroll-text 2)))
487 (defn begin-deposit [script]
488 (->> script
489 (set-cursor 1)
490 select-menu-entry))
492 (defn begin-withdraw [script]
493 (->> script
494 (set-cursor 0)
495 (select-menu-entry)))
497 (defn deposit-held-item-named
498 [item-name quantity [moves state :as script]]
499 (let [index (count
500 (take-while
501 (fn [[name quant]]
502 (or (not= name item-name)
503 (< quant quantity)))
504 (inventory state)))]
505 (println "index" index)
506 (deposit-held-item index quantity script)))
508 (defn open-held-items
509 [script]
510 (->> script
511 select-menu-entry))
513 (defn to-held-items
514 [script]
515 (->> script
516 close-menu
517 close-menu
518 end-text;;; grr
520 activate-start-menu
521 open-held-items))
523 (defn toss-pc-item [n quantity [moves state :as script]]
524 (let [total-quantity (second (nth-pc-item state n))]
525 (->> script
526 (set-cursor n)
527 (select-menu-entry 1)
528 (set-quantity total-quantity quantity)
529 (delayed-difference [] [:a] 100 #(search-string % "Is"))
530 (scroll-text)
531 select-menu-entry
532 (scroll-text))))
534 (defn-memo hacking-1
535 ([] (hacking-1 (to-celadon-poke-center)))
536 ([script]
537 (->> script
538 activate-rlm-pc
539 begin-deposit
540 (deposit-held-item-named 0x00 30)
541 (deposit-held-item-named :TM01 63)
542 (deposit-held-item-named :awakening 4)
543 (deposit-held-item-named :thunderstone 98)
544 (deposit-held-item-named :TM09 55)
545 (deposit-held-item-named 0x00 55))))
547 (defn-memo hacking-2
548 ([] (hacking-2 (hacking-1)))
549 ([script]
550 (->> script
551 (to-held-items)
552 (toss-held-item 0 166) ;; discard cruft
553 close-menu
554 close-menu)))
556 (defn-memo hacking-3
557 ([] (hacking-3 (hacking-2)))
558 ([script]
559 (->> script
560 activate-rlm-pc
561 begin-withdraw
562 (widthdraw-pc-item 0 99)
563 (widthdraw-pc-item 0 1)
564 (widthdraw-pc-item 2 0xFE)
565 (widthdraw-pc-item 3 0xFE)
566 close-menu)))
568 (defn-memo hacking-4
569 ([] (hacking-4 (hacking-3)))
570 ([script]
571 (->> script
572 begin-deposit
573 (deposit-held-item 19 243)
574 (deposit-held-item-named :lemonade 16)
575 (deposit-held-item 18 224))))
577 (defn-memo hacking-5
578 "clean out the held-item list again"
579 ([] (hacking-5 (hacking-4)))
580 ([script]
581 (->> script
582 (to-held-items)
583 (toss-held-item 18 30)
584 (toss-held-item 17 1)
585 close-menu
586 close-menu)))
588 (defn-memo hacking-6
589 ([] (hacking-6 (hacking-5)))
590 ([script]
591 (->> script
592 activate-rlm-pc
593 begin-withdraw
594 (widthdraw-pc-item 4 0xFE)
595 (widthdraw-pc-item 5 0xFE)
596 (widthdraw-pc-item 6 0xFE)
597 close-menu)))
599 (defn-memo hacking-7
600 ([] (hacking-7 (hacking-6)))
601 ([script]
602 (->> script
603 begin-deposit
604 (deposit-held-item 19 240)
605 (deposit-held-item 18 230)
606 (deposit-held-item-named :parlyz-heal 55)
607 (deposit-held-item 17 184)
608 (deposit-held-item 17 40)
609 (deposit-held-item-named :TM37 71)
610 (deposit-held-item-named :ice-heal 55)
611 (deposit-held-item-named :fire-stone 23)
612 (deposit-held-item-named :burn-heal 12)
613 ;; as a special case, /don't/ close the menu.
614 )))
616 (defn-memo hacking-8
617 "Clear cruft away from held item list."
618 ([] (hacking-8 (hacking-7)))
619 ([script]
620 (->> script
621 to-held-items
622 (toss-held-item 15 1)
623 (toss-held-item 14 1)
624 (toss-held-item 13 1)
625 close-menu
626 close-menu)))
628 (defn-memo hacking-9
629 ([] (hacking-9 (hacking-8)))
630 ([script]
631 (->> script
632 activate-rlm-pc
633 begin-withdraw
634 (widthdraw-pc-item 7 0xFE)
635 (widthdraw-pc-item 8 0xFC)
636 (widthdraw-pc-item 8 1)
637 (widthdraw-pc-item 8 1)
638 (widthdraw-pc-item 9 0xFE)
639 (multiple-times
640 7
641 (partial combine-pc-items 2))
642 close-menu)))
644 (defn-memo hacking-10
645 ([] (hacking-10 (hacking-9)))
646 ([script]
647 (->> script
648 begin-deposit
649 (deposit-held-item 17 230)
650 (deposit-held-item-named :parlyz-heal 55)
651 (deposit-held-item 14 178)
652 (deposit-held-item-named :water-stone 29)
653 (deposit-held-item 14 32)
654 (deposit-held-item-named :TM18 1)
655 (deposit-held-item 13 1)
656 (deposit-held-item 13 191)
657 (deposit-held-item-named :TM02 98)
658 (deposit-held-item-named :TM09 1)
659 close-menu)))
661 (defn-memo hacking-11
662 ([] (hacking-11 (hacking-10)))
663 ([script]
664 (->> script
665 begin-withdraw
666 (widthdraw-pc-item 3 0xFE)
667 (widthdraw-pc-item 4 0xFE)
668 (widthdraw-pc-item 5 1)
669 (widthdraw-pc-item 5 1)
670 (widthdraw-pc-item 5 1)
671 (widthdraw-pc-item 5 0xFB)
672 (multiple-times
673 3
674 (partial combine-pc-items 2))
675 close-menu)))
677 (defn-memo hacking-12
678 ([] (hacking-12 (hacking-11)))
679 ([script]
680 (->> script
681 begin-deposit
682 (deposit-held-item 18 203)
683 (deposit-held-item-named :guard-spec 87)
684 (deposit-held-item-named :guard-spec 24)
685 (deposit-held-item-named :TM05 1)
686 (multiple-times
687 8
688 (partial deposit-held-item 14 1))
689 (deposit-held-item 14 55)
690 (deposit-held-item-named :x-accuracy 58)
691 (deposit-held-item 14 38)
692 (deposit-held-item-named :TM13 1)
693 (deposit-held-item 13 1)
694 (deposit-held-item 13 233)
695 close-menu)))
697 (defn-memo hacking-13
698 ([] (hacking-13 (hacking-12)))
699 ([script]
700 (->> script
701 (set-cursor-relative 1)
702 (select-menu-entry)
703 (toss-pc-item 1 1)
704 (toss-pc-item 0 156)
705 (toss-pc-item 0 11))))
707 (defn confirm-pattern []
708 (let [start-address (inc pc-item-list-start)
709 target-pattern (pc-item-writer-program)
710 actual-pattern
711 (subvec (vec (memory (second (hacking-13))))
712 start-address
713 (+ start-address (count target-pattern)))]
714 (println target-pattern)
715 (println actual-pattern)
716 (= target-pattern actual-pattern)))
718 (defn-memo go-to-mansion-for-the-lulz
719 ([] (go-to-mansion-for-the-lulz (hacking-13)))
720 ([script]
721 (->> script
722 close-menu
723 close-menu
724 end-text ;;grr
725 (walk [↓ ← ← ← ← ← ← ← ← ← ↓ ↓ ↓])
726 (walk (repeat 17 ←))
727 (walk [↑ → → → → ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])
728 (walk [↓ ← ↑])
729 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓
730 ← ← ← ← ↑ ↑ ↑ ← ↑])
731 (talk)
732 (scroll-text 2)
733 (do-nothing 100)
734 close-menu)))
736 (defn-memo launch-bootstrap-program
737 ([] (launch-bootstrap-program
738 (go-to-mansion-for-the-lulz)))
739 ([script]
740 (->> script
741 ;; must corrupt item list again by switching pokemon
742 activate-start-menu ;; \
743 (set-cursor 0) ;; |
744 select-menu-entry ;; |
745 select-menu-entry ;; |
746 (set-cursor 1) ;; | -- switch 9th pokemon
747 select-menu-entry ;; | with 4th pokemon
748 (set-cursor 3) ;; |
749 select-menu-entry ;; |
750 close-menu ;; /
751 ;; now, open items and set map-function to
752 ;; the program inside the item-computer.
753 (set-cursor 1)
754 (select-menu-entry)
755 (toss-held-item 22 12)
756 (switch-held-items 22 40)
757 close-all-menus)))
759 (defn regen-control-checkpoint!
760 [] (write-script! (launch-bootstrap-program) "control-checkpoint"))
762 (defn control-checkpoint []
763 (read-script "control-checkpoint"))
765 (def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF])
767 (defn test-pattern-writing
768 ([] (test-pattern-writing increasing-pattern))
769 ([pattern]
770 (let [moves (bootstrap-pattern pattern)
771 pattern-insertion
772 (->> (launch-bootstrap-program)
773 (play-moves
774 (take 100 moves)))]
775 (println "Input Pattern:")
776 (apply println (map #(format "0x%02X" %) pattern))
777 (println "\nMemory Listing:")
778 (print-listing (second pattern-insertion)
779 0xD162 (+ 0xD162 (count pattern)))
780 (= (subvec (vec (memory (second pattern-insertion)))
781 0xD162 (+ 0xD162 (count pattern)))
782 pattern))))
784 (defn-memo launch-main-bootstrap-program
785 ([] (launch-main-bootstrap-program
786 (control-checkpoint)
787 ;;(launch-bootstrap-program)
788 ))
789 ([script]
790 (->> script
791 (play-moves
792 (bootstrap-pattern (main-bootstrap-program)))
793 (play-moves
794 (take 253 (interleave (repeat 1000 [:b])
795 (repeat 1000 [])))))))
796 (def bootstrap-start pokemon-list-start)
798 (defn test-main-bootstrap-integrety
799 []
800 (assert
801 (= (main-bootstrap-program)
802 (subvec
803 (vec (memory (second (launch-main-bootstrap-program))))
804 pokemon-list-start
805 (+ pokemon-list-start (count (main-bootstrap-program)))))))
807 (defn set-target-address
808 "Assumes that the game is under control of the main-bootstrap
809 program in MODE-SELECT mode, and sets the target address to which
810 jumps/writes will occur."
811 [target-address script]
812 (let [[target-high target-low] (disect-bytes-2 target-address)]
813 (->> script
814 (play-moves
815 (map buttons
816 [set-H-mode target-high 0x00
817 set-L-mode target-low 0x00])))))
819 (defn write-RAM-segment
820 "Assumes that the game is under control of the main-bootstrap
821 program in MODE-SELECT mode and that target-address has been
822 appropriately set, and writes 255 bytes or less to RAM."
823 [segment script]
824 (->> script
825 (play-moves
826 (map buttons
827 [write-mode (count segment)]))
828 (play-moves (map buttons segment))
829 (play-moves [[]])))
831 (defn write-RAM
832 "Assumes that the game is under control of the main-bootstrap
833 program in MODE-SELECT mode, and rewrites RAM starting at
834 'start-address with 'new-ram."
835 [start-address new-ram script]
836 (loop [s (set-target-address start-address script)
837 to-write new-ram]
838 (if (< (count to-write) 0x100)
839 (write-RAM-segment to-write s)
840 (recur
841 (write-RAM-segment (take 0xFF to-write) s)
842 (drop 0xFF to-write)))))
844 (defn transfer-control
845 "Assumes that the game is under control of the main-bootstrap
846 program in MODE-SELECT mode, and jumps to the target-address."
847 [target-address script]
848 (->> script
849 (set-target-address target-address)
850 (play-moves [(buttons jump-mode)])))
853 (def relocated-bootstrap-start
854 (+ 90 pokemon-box-1-address))
856 (defn-memo relocate-main-bootstrap
857 ([] (relocate-main-bootstrap (launch-main-bootstrap-program)))
858 ([script]
859 (->> script
860 (do-nothing 2)
861 (write-RAM
862 relocated-bootstrap-start
863 (main-bootstrap-program
864 relocated-bootstrap-start))
865 (do-nothing 1)
866 (transfer-control relocated-bootstrap-start)
867 (do-nothing 1))))
869 (defn gen-new-kernel-checkpoint! []
870 (write-script! (do-nothing 10 (relocate-main-bootstrap))
871 "new-kernel"))
873 (defn new-kernel [] (read-script "new-kernel"))
875 (def mid-game-data
876 (subvec (vec (memory (mid-game)))
877 pokemon-list-start
878 (+ pokemon-list-start 697)))
880 (def mid-game-map-address 0x46BC)
882 (defn-memo set-mid-game-data
883 ([] (set-mid-game-data (relocate-main-bootstrap)))
884 ([script]
885 (->> script
886 (do-nothing 10)
887 (write-RAM pokemon-list-start
888 mid-game-data))))
889 (defn test-set-data
890 ([] (test-set-data (relocate-main-bootstrap)))
891 ([script]
892 (->> script
893 (do-nothing 10)
894 (write-RAM pokemon-list-start
895 (repeat 500 0xCC)))))
897 (defn test-mid-game-transfer []
898 (= (subvec (vec (memory (second (set-mid-game-data))))
899 pokemon-list-start
900 (+ pokemon-list-start 500))
901 (subvec (vec (memory (mid-game)))
902 pokemon-list-start
903 (+ pokemon-list-start 500))))
905 (defn-memo return-to-pokemon-kernel
906 ([] (return-to-pokemon-kernel (set-mid-game-data)))
907 ([script]
908 (let [scratch (+ 200 pokemon-box-1-address)
909 return-program
910 (flatten
911 [0xFB
912 0xC3
913 (reverse (disect-bytes-2 mid-game-map-address))])]
914 (->> script
915 (write-RAM scratch return-program)
916 (transfer-control scratch)
917 (do-nothing 1)))))