comparison clojure/com/aurellem/run/bootstrap_1.clj @ 369:abcc522a3242

script: wrote memory pattern from within game!
author Robert McIntyre <rlm@mit.edu>
date Tue, 10 Apr 2012 06:33:44 -0500
parents 08f8284e2f1b
children 7c89fe478de4
comparison
equal deleted inserted replaced
368:08f8284e2f1b 369:abcc522a3242
106 0x18 ;; relative jump backwards 106 0x18 ;; relative jump backwards
107 0xCD ;; literal -51 == TM05; go back to input section 107 0xCD ;; literal -51 == TM05; go back to input section
108 0x01 ;; (item-hack) will never reach this instruction 108 0x01 ;; (item-hack) will never reach this instruction
109 109
110 ] 110 ]
111 (repeat 8 [0x00 0x02]);; these can be anything 111 (repeat 8 [0x00 0x01]);; these can be anything
112 112
113 [;; jump to actual program 113 [;; jump to actual program
114 0x00 114 0x00
115 0x37 ;; (item-hack) set carry flag no-op 115 0x37 ;; (item-hack) set carry flag no-op
116 116
180 ([script] 180 ([script]
181 (->> script 181 (->> script
182 finish-title 182 finish-title
183 (walk [← ← ↑ ← ↑ ↑ ↑])))) 183 (walk [← ← ↑ ← ↑ ↑ ↑]))))
184 184
185 (defn-memo bootstrap-corrupt-save 185 ;; (defn wait-for-quantity
186 ([] (bootstrap-corrupt-save (to-room-pc))) 186 ;; [[moves state :as script]]
187 ([script] 187 ;; (if (not= (item-quantity-selected state) 1)
188 (->> script 188 ;; (repeat-until-different [] item-quantity-selected script)
189 (do-save-corruption 2) 189 ;; script))
190 (corrupt-item-list 0)
191 close-all-menus)))
192
193 (defn-memo begin-initial-deposits
194 ([] (begin-initial-deposits
195 (bootstrap-corrupt-save)))
196 ([script]
197 (->> script
198 (first-difference [] [:a] AF)
199 (scroll-text)
200 (set-cursor 1)
201 select-menu-entry)))
202
203 (defn wait-for-quantity
204 [[moves state :as script]]
205 (if (not= (item-quantity-selected state) 1)
206 (repeat-until-different [] item-quantity-selected script)
207 script))
208 190
209 ;; TODO use this: 191 ;; TODO use this:
210 ;;(wait-until (partial set-cursor-relative 1)) 192 ;;(wait-until (partial set-cursor-relative 1))
211 193
212 (defn wait-for-cursor 194 ;; (defn wait-for-cursor
213 [[moves state :as script]] 195 ;; [[moves state :as script]]
214 (if (not= (list-offset state) 0) 196 ;; (if (not= (list-offset state) 0)
215 (repeat-until-different [] list-offset script) 197 ;; (repeat-until-different [] list-offset script)
216 script)) 198 ;; script))
217 199
218 (defn deposit-held-item [n quantity [moves state :as script]] 200 (defn deposit-held-item [n quantity [moves state :as script]]
219 (let [total-quantity (second (nth-item state n))] 201 (let [total-quantity (second (nth-item state n))]
220 (println "total-quantity" total-quantity) 202 (println "total-quantity" total-quantity)
221 (->> script 203 (->> script
222 (set-cursor n) 204 (set-cursor n)
223 (select-menu-entry 1) 205 (select-menu-entry 1)
224 (wait-for-quantity) 206 ;;(wait-for-quantity)
225 (set-quantity total-quantity quantity) 207 (set-quantity total-quantity quantity)
226 (delayed-difference [] [:a] 100 #(search-string % "stored")) 208 (delayed-difference [] [:a] 100 #(search-string % "stored"))
227 (scroll-text)))) 209 (scroll-text))))
228 210
229 (defn sell-held-item [n quantity [moves state :as script]] 211 (defn sell-held-item [n quantity [moves state :as script]]
230 (let [total-quantity (second (nth-item state n))] 212 (let [total-quantity (second (nth-item state n))]
231 (->> script 213 (->> script
232 (wait-for-cursor) ;; when selling, the cursor always 214 ;;(wait-for-cursor) ;; when selling, the cursor always
233 (set-cursor n) ;; returns to the top of the list. 215 (set-cursor n) ;; returns to the top of the list.
234 (select-menu-entry 1) 216 (select-menu-entry 1)
235 (wait-for-quantity) 217 ;;(wait-for-quantity)
236 (set-quantity total-quantity quantity) 218 (set-quantity total-quantity quantity)
237 (delayed-difference [] [:a] 100 current-depth) 219 (delayed-difference [] [:a] 100 current-depth)
238 (play-moves (repeat 20 [:b])) 220 (play-moves (repeat 20 [:b]))
239 (delayed-difference [] [:a] 100 #(search-string % "What")) 221 (delayed-difference [] [:a] 100 #(search-string % "What"))
240 ))) 222 )))
242 (defn widthdraw-pc-item [n quantity [moves state :as script]] 224 (defn widthdraw-pc-item [n quantity [moves state :as script]]
243 (let [total-quantity (second (nth-pc-item state n))] 225 (let [total-quantity (second (nth-pc-item state n))]
244 (->> script 226 (->> script
245 (set-cursor n) 227 (set-cursor n)
246 (select-menu-entry 1) 228 (select-menu-entry 1)
247 (wait-for-quantity) 229 ;;(wait-for-quantity)
248 (set-quantity total-quantity quantity) 230 (set-quantity total-quantity quantity)
249 (delayed-difference [] [:a] 100 #(search-string % "Withdrew")) 231 (delayed-difference [] [:a] 100 #(search-string % "Withdrew"))
250 (scroll-text)))) 232 (scroll-text))))
251 233
252 (defn toss-held-item [n quantity [moves state :as script]] 234 (defn toss-held-item [n quantity [moves state :as script]]
254 (->> script 236 (->> script
255 (set-cursor n) 237 (set-cursor n)
256 (select-menu-entry 1) 238 (select-menu-entry 1)
257 (set-cursor-relative 1) 239 (set-cursor-relative 1)
258 (select-menu-entry -1) 240 (select-menu-entry -1)
259 (wait-for-quantity) 241 ;;(wait-for-quantity)
260 (set-quantity total-quantity quantity) 242 (set-quantity total-quantity quantity)
261 (play-moves [[:a]]) 243 (play-moves [[:a]])
262 (scroll-text) 244 (scroll-text)
263 (delayed-difference [] [:a] 100 #(search-string % "Threw")) 245 (delayed-difference [] [:a] 100 #(search-string % "Threw"))
264 (scroll-text) 246 (scroll-text)
267 (defn buy-item [n quantity [moves state :as script]] 249 (defn buy-item [n quantity [moves state :as script]]
268 (->> script 250 (->> script
269 (set-cursor n) 251 (set-cursor n)
270 (purchase-item quantity))) 252 (purchase-item quantity)))
271 253
254 (defn switch-items [item-fn idx-1 idx-2 script]
255 (->> script
256 (wait-until select-menu-entry)
257 (set-cursor idx-1)
258 (wait-until select-menu-entry)
259 (play-moves [[][:select][]])
260 (set-cursor idx-2)
261 (delayed-difference [] [:select] 100
262 #(item-fn % (list-offset %)))))
263
264 (def switch-pc-items (partial switch-items nth-pc-item))
265 (def switch-held-items (partial switch-items nth-item))
266
267 (defn combine-pc-items [idx-1 script]
268 (->> script
269 (switch-pc-items idx-1 (inc idx-1))))
272 270
273 (def desired-zero-quantities 271 (def desired-zero-quantities
274 (map second (filter (comp (partial = 0) first) 272 (map second (filter (comp (partial = 0) first)
275 (partition 2 (pc-item-writer-program))))) 273 (partition 2 (pc-item-writer-program)))))
276 274
275 (defn-memo bootstrap-corrupt-save
276 ([] (bootstrap-corrupt-save (to-room-pc)))
277 ([script]
278 (->> script
279 (do-save-corruption 3)
280 (corrupt-item-list 0)
281 close-all-menus)))
282
283 (defn-memo prepare-celadon-warp
284 ([] (prepare-celadon-warp (bootstrap-corrupt-save)))
285 ([script]
286 (->> script
287 (activate-start-menu)
288 (set-cursor-relative 1)
289 (select-menu-entry)
290 ;; vastly increase text speed while we're here.
291 (switch-held-items 21 27)
292 (toss-held-item 35 0xFA)
293 (close-all-menus))))
294
295 (defn-memo begin-initial-deposits
296 ([] (begin-initial-deposits
297 (prepare-celadon-warp)))
298 ([script]
299 (->> script
300 (first-difference [] [:a] AF)
301 (scroll-text)
302 (set-cursor 1)
303 select-menu-entry)))
304
277 (defn-memo initial-deposits 305 (defn-memo initial-deposits
278 ([] (initial-deposits (begin-initial-deposits))) 306 ([] (initial-deposits (begin-initial-deposits)))
279 ([script] 307 ([script]
280 (->> script 308 (->> script
281 (deposit-held-item 0 0x1) 309 (deposit-held-item 0 0x1)
285 script 313 script
286 (range 3 (+ 13 3))))) 314 (range 3 (+ 13 3)))))
287 close-all-menus))) 315 close-all-menus)))
288 316
289 317
290 (defn-memo prepare-celadon-warp
291 ([] (prepare-celadon-warp (initial-deposits)))
292 ([script]
293 (->> script
294 (activate-start-menu)
295 (set-cursor-relative 1)
296 (select-menu-entry)
297 (toss-held-item 35 0xFA)
298 (close-all-menus))))
299
300
301 ;;0 -- 256 318 ;;0 -- 256
302 ;;1 -- 254 319 ;;1 -- 254
303 ;;2 -- 254 320 ;;2 -- 254
304 ;;3 -- 255 321 ;;3 -- 255
305 322
323 (defn activate-home-pc
324 [script]
325 (->> script
326 (delayed-difference [] [:a]
327 200 first-character)
328 (scroll-text)))
329
306 (defn-memo restore-items 330 (defn-memo restore-items
307 ([] (restore-items (prepare-celadon-warp))) 331 ([] (restore-items (initial-deposits)))
308 ([script] 332 ([script]
309 (->> script 333 (->> script
310 (first-difference [] [:a] AF) 334 activate-home-pc
311 (scroll-text)
312 (select-menu-entry) 335 (select-menu-entry)
313 (widthdraw-pc-item 0 1) 336 (widthdraw-pc-item 0 1)
314 ;;(widthdraw-pc-item 0 99) 337 ;;(widthdraw-pc-item 0 99)
315 ;;(widthdraw-pc-item 1 1) 338 ;;(widthdraw-pc-item 1 1)
316 (widthdraw-pc-item 13 255) 339 (widthdraw-pc-item 13 255)
402 425
403 (defn-memo floor-two-TMs 426 (defn-memo floor-two-TMs
404 ([] (floor-two-TMs (get-money-floor-two))) 427 ([] (floor-two-TMs (get-money-floor-two)))
405 ([script] 428 ([script]
406 (->> script 429 (->> script
407 (wait-for-cursor) 430 (set-cursor 0)
408 (select-menu-entry) 431 (select-menu-entry)
409 (buy-item 2 98) ;; TM02 (razor-wind) 432 (buy-item 2 98) ;; TM02 (razor-wind)
410 (buy-item 4 71) ;; TM37 (doubleteam) 433 (buy-item 4 71) ;; TM37 (doubleteam)
411 (buy-item 5 63) ;; TM01 (mega-punch) 434 (buy-item 5 63) ;; TM01 (mega-punch)
412 (buy-item 6 1) ;; TM05 (mega-kick) 435 (buy-item 6 1) ;; TM05 (mega-kick)
422 445
423 (defn-memo floor-two-more-money 446 (defn-memo floor-two-more-money
424 ([] (floor-two-more-money (floor-two-TMs))) 447 ([] (floor-two-more-money (floor-two-TMs)))
425 ([script] 448 ([script]
426 (->> script 449 (->> script
427 (wait-for-cursor)
428 (set-cursor 1) 450 (set-cursor 1)
429 (select-menu-entry) 451 (select-menu-entry)
430 (sell-held-item 0 1) 452 (sell-held-item 0 1)
431 (sell-held-item 0 1) 453 (sell-held-item 0 1)
432 close-menu 454 close-menu
525 [n script] 547 [n script]
526 (->> script 548 (->> script
527 (do-nothing 20) 549 (do-nothing 20)
528 (play-moves [[:a][:a]]) 550 (play-moves [[:a][:a]])
529 scroll-text 551 scroll-text
530 (wait-for-cursor)
531 (set-cursor n) 552 (set-cursor n)
532 select-menu-entry 553 select-menu-entry
533 close-menu)) 554 close-menu))
534 555
535 (defn-memo roof-drinks 556 (defn-memo roof-drinks
543 564
544 (defn-memo get-TM13 565 (defn-memo get-TM13
545 ([] (get-TM13 (roof-drinks))) 566 ([] (get-TM13 (roof-drinks)))
546 ([script] 567 ([script]
547 (->> script 568 (->> script
548 (walk [← ← ← ← ← ← ↓]) 569 ;;(walk [← ← ← ← ← ← ↓])
549 (play-moves [[][:a][:a][]]) 570 (walk [↓ ↓ ↓ ← ← ← ← ← ←])
571 (play-moves [[][][][][:a][:a][]])
550 (scroll-text 3) 572 (scroll-text 3)
551 select-menu-entry 573 select-menu-entry
552 select-menu-entry 574 select-menu-entry
553 (scroll-text 6) 575 (scroll-text 6)
554 close-menu))) 576 close-menu)))
555 577
556 (defn-memo to-celadon-poke-center 578 (defn-memo to-celadon-poke-center
557 ([] (to-celadon-poke-center (get-TM13))) 579 ([] (to-celadon-poke-center (get-TM13)))
558 ([script] 580 ([script]
559 (->> script 581 (->> script
560 (walk [↑ → → → → → → → → → ↑]) ; leave roof 582 ;;(walk [↑ → → → → → → → → → ↑]) ; leave roof
583 (walk [→ → → → → → → → → ↑ ↑ ↑ ↑])
561 (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ← 584 (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ←
562 ↑ ↑ ↑ ← ← ↑]) ; to elevator 585 ↑ ↑ ↑ ← ← ↑]) ; to elevator
563 586
564 (walk [→ → ↑ ↑]) ; to controls 587 (walk [→ → ↑ ↑]) ; to controls
565 talk 588 talk
574 597
575 (defn activate-rlm-pc [script] 598 (defn activate-rlm-pc [script]
576 (->> script 599 (->> script
577 talk 600 talk
578 scroll-text 601 scroll-text
579 wait-for-cursor 602 ;;wait-for-cursor
580 (set-cursor 1) 603 (set-cursor 1)
581 select-menu-entry 604 select-menu-entry
582 (scroll-text 2))) 605 (scroll-text 2)))
583 606
584 (defn begin-deposit [script] 607 (defn begin-deposit [script]
600 (< quant quantity))) 623 (< quant quantity)))
601 (inventory state)))] 624 (inventory state)))]
602 (println "index" index) 625 (println "index" index)
603 (deposit-held-item index quantity script))) 626 (deposit-held-item index quantity script)))
604 627
605 628 (defn open-held-items
606 (defn-memo begin-hacking 629 [script]
607 ([] (begin-hacking(to-celadon-poke-center))) 630 (->> script
631 select-menu-entry))
632
633 (defn to-held-items
634 [script]
635 (->> script
636 close-menu
637 close-menu
638 end-text;;; grr
639
640 activate-start-menu
641 open-held-items))
642
643 (defn toss-pc-item [n quantity [moves state :as script]]
644 (let [total-quantity (second (nth-pc-item state n))]
645 (->> script
646 (set-cursor n)
647 (select-menu-entry 1)
648 (set-quantity total-quantity quantity)
649 (delayed-difference [] [:a] 100 #(search-string % "Is"))
650 (scroll-text)
651 select-menu-entry
652 (scroll-text))))
653
654 (defn-memo hacking-1
655 ([] (hacking-1 (to-celadon-poke-center)))
608 ([script] 656 ([script]
609 (->> script 657 (->> script
610 activate-rlm-pc 658 activate-rlm-pc
611 begin-deposit 659 begin-deposit
612 (deposit-held-item-named 0x00 30) 660 (deposit-held-item-named 0x00 30)
614 (deposit-held-item-named :awakening 4) 662 (deposit-held-item-named :awakening 4)
615 (deposit-held-item-named :thunderstone 98) 663 (deposit-held-item-named :thunderstone 98)
616 (deposit-held-item-named :TM09 55) 664 (deposit-held-item-named :TM09 55)
617 (deposit-held-item-named 0x00 55)))) 665 (deposit-held-item-named 0x00 55))))
618 666
619 (defn open-held-items
620 [script]
621 (->> script
622 select-menu-entry))
623
624 (defn to-held-items
625 [script]
626 (->> script
627 close-menu
628 close-menu
629 end-text;;; grr
630
631 activate-start-menu
632 open-held-items))
633
634 (defn-memo hacking-2 667 (defn-memo hacking-2
635 ([] (hacking-2 (begin-hacking))) 668 ([] (hacking-2 (hacking-1)))
636 ([script] 669 ([script]
637 (->> script 670 (->> script
638 (to-held-items) 671 (to-held-items)
639 (toss-held-item 0 166) ;; discard cruft 672 (toss-held-item 0 166) ;; discard cruft
640 close-menu 673 close-menu
695 (deposit-held-item 17 40) 728 (deposit-held-item 17 40)
696 (deposit-held-item-named :TM37 71) 729 (deposit-held-item-named :TM37 71)
697 (deposit-held-item-named :ice-heal 55) 730 (deposit-held-item-named :ice-heal 55)
698 (deposit-held-item-named :fire-stone 23) 731 (deposit-held-item-named :fire-stone 23)
699 (deposit-held-item-named :burn-heal 12) 732 (deposit-held-item-named :burn-heal 12)
700 close-menu))) 733 ;; as a special case, /don't/ close the menu.
701 734 )))
702 (defn switch-items [item-fn idx-1 idx-2 script]
703 (->> script
704 (wait-until select-menu-entry)
705 (set-cursor idx-1)
706 (wait-until select-menu-entry)
707 (play-moves [[][:select][]])
708 (set-cursor idx-2)
709 (delayed-difference [] [:select] 100
710 #(item-fn % (list-offset %)))))
711
712 (def switch-pc-items (partial switch-items nth-pc-item))
713 (def switch-held-items (partial switch-items nth-item))
714
715 (defn combine-pc-items [idx-1 script]
716 (->> script
717 (switch-pc-items idx-1 (inc idx-1))))
718
719 (defn combine-items [idx-1 script]
720 (->> script
721 (wait-until select-menu-entry)
722 (set-cursor idx-1)
723 (wait-until select-menu-entry)
724 (play-moves [[][:select][]])
725 (set-cursor-relative 1)
726 (delayed-difference [] [:select] 100
727 #(nth-pc-item % (list-offset %)))))
728 735
729 (defn-memo hacking-8 736 (defn-memo hacking-8
730 "Clear cruft away from held item list." 737 "Clear cruft away from held item list."
731 ([] (hacking-8 (hacking-7))) 738 ([] (hacking-8 (hacking-7)))
732 ([script] 739 ([script]
767 (deposit-held-item-named :TM18 1) 774 (deposit-held-item-named :TM18 1)
768 (deposit-held-item 13 1) 775 (deposit-held-item 13 1)
769 (deposit-held-item 13 191) 776 (deposit-held-item 13 191)
770 (deposit-held-item-named :TM02 98) 777 (deposit-held-item-named :TM02 98)
771 (deposit-held-item-named :TM09 1) 778 (deposit-held-item-named :TM09 1)
772 close-menu
773 close-menu))) 779 close-menu)))
774 780
775 (defn-memo hacking-11 781 (defn-memo hacking-11
776 ([] (hacking-11 (hacking-10))) 782 ([] (hacking-11 (hacking-10)))
777 ([script] 783 ([script]
783 (widthdraw-pc-item 5 1) 789 (widthdraw-pc-item 5 1)
784 (widthdraw-pc-item 5 1) 790 (widthdraw-pc-item 5 1)
785 (widthdraw-pc-item 5 0xFB) 791 (widthdraw-pc-item 5 0xFB)
786 (multiple-times 792 (multiple-times
787 3 793 3
788 (partial combine-items 2)) 794 (partial combine-pc-items 2))
789 close-menu))) 795 close-menu)))
790 796
791 (defn-memo hacking-12 797 (defn-memo hacking-12
792 ([] (hacking-12 (hacking-11))) 798 ([] (hacking-12 (hacking-11)))
793 ([script] 799 ([script]
797 (deposit-held-item-named :guard-spec 87) 803 (deposit-held-item-named :guard-spec 87)
798 (deposit-held-item-named :guard-spec 24) 804 (deposit-held-item-named :guard-spec 24)
799 (deposit-held-item-named :TM05 1) 805 (deposit-held-item-named :TM05 1)
800 (multiple-times 806 (multiple-times
801 8 807 8
802 (partial deposit-held-item 14 2)) 808 (partial deposit-held-item 14 1))
803 (deposit-held-item 14 55) 809 (deposit-held-item 14 55)
804 (deposit-held-item-named :x-accuracy 58) 810 (deposit-held-item-named :x-accuracy 58)
805 (deposit-held-item 14 38) 811 (deposit-held-item 14 38)
806 (deposit-held-item-named :TM13 1) 812 (deposit-held-item-named :TM13 1)
807 (deposit-held-item 13 1) 813 (deposit-held-item 13 1)
808 (deposit-held-item 13 233) 814 (deposit-held-item 13 233)
809 close-menu 815 close-menu)))
810 close-menu)))
811
812
813 (defn toss-pc-item [n quantity [moves state :as script]]
814 (let [total-quantity (second (nth-pc-item state n))]
815 (->> script
816 (set-cursor n)
817 (select-menu-entry 1)
818 (wait-for-quantity)
819 (set-quantity total-quantity quantity)
820 (delayed-difference [] [:a] 100 #(search-string % "Is"))
821 (scroll-text)
822 select-menu-entry
823 (scroll-text))))
824 816
825 (defn-memo hacking-13 817 (defn-memo hacking-13
826 ([] (hacking-13 (hacking-12))) 818 ([] (hacking-13 (hacking-12)))
827 ([script] 819 ([script]
828 (->> script 820 (->> script
840 start-address 832 start-address
841 (+ start-address (count target-pattern)))] 833 (+ start-address (count target-pattern)))]
842 (println target-pattern) 834 (println target-pattern)
843 (println actual-pattern) 835 (println actual-pattern)
844 (= target-pattern actual-pattern))) 836 (= target-pattern actual-pattern)))
845
846 ;; this will be useful for starting program
847
848 837
849 (defn-memo go-to-mansion-for-the-lulz 838 (defn-memo go-to-mansion-for-the-lulz
850 ([] (go-to-mansion-for-the-lulz (hacking-13))) 839 ([] (go-to-mansion-for-the-lulz (hacking-13)))
851 ([script] 840 ([script]
852 (->> script 841 (->> script
859 (walk [↓ ← ↑]) 848 (walk [↓ ← ↑])
860 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ 849 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓
861 ← ← ← ← ↑ ↑ ↑ ← ↑]) 850 ← ← ← ← ↑ ↑ ↑ ← ↑])
862 (talk) 851 (talk)
863 (scroll-text 2) 852 (scroll-text 2)
864 close-menu))) 853 (do-nothing 100)
865 854 close-menu)))
866 (defn get-cursor [script]
867 (wait-until (partial set-cursor-relative 1) script))
868 855
869 (defn-memo launch-bootstrap-program 856 (defn-memo launch-bootstrap-program
870 ([] (launch-bootstrap-program 857 ([] (launch-bootstrap-program
871 (go-to-mansion-for-the-lulz))) 858 (go-to-mansion-for-the-lulz)))
872 ([script] 859 ([script]
873 (->> script 860 (->> script
874 ;; must corrupt item list again by switching pokemon 861 ;; must corrupt item list again by switching pokemon
875 activate-start-menu 862 activate-start-menu ;; \
876 ;;get-cursor 863 (set-cursor 0) ;; |
877 (set-cursor 0) 864 select-menu-entry ;; |
878 select-menu-entry 865 select-menu-entry ;; |
879 ;;get-cursor 866 (set-cursor 1) ;; | -- switch 9th pokemon
880 (select-menu-entry) 867 select-menu-entry ;; | with 4th pokemon
881 ;;get-cursor 868 (set-cursor 3) ;; |
882 (set-cursor 1) 869 select-menu-entry ;; |
883 (select-menu-entry) 870 close-menu ;; /
884 ;;get-cursor 871 ;; now, open items and set map-function to
885 (set-cursor 3) 872 ;; the program inside the item-computer.
886 (delayed-difference [] [:a] 50 first-character)
887 close-menu
888 ;; now, open items and set map-function
889 ;;get-cursor
890 (set-cursor 1) 873 (set-cursor 1)
891 (select-menu-entry) 874 (select-menu-entry)
892 (toss-held-item 22 12) 875 (toss-held-item 22 12)
893 (switch-held-items 22 40) 876 (switch-held-items 22 40)
894 close-all-menus))) 877 close-all-menus)))
895 878
896 879 (defn no-consecutive-repeats? [seq]
897 880 (not (contains? (set(map - seq (rest seq))) 0)))
898 881
882 (defn byte->nybbles [byte]
883 [(bit-shift-right byte 4) (bit-and byte 0x0F)])
884
885 (defn bootstrap-pattern
886 "Given an assembly sequence, generate the keypresses required to
887 create that sequence in memory using the pc-item-writer
888 program. The assembly must not have any consecutive repeating
889 nybbles."
890 [assembly]
891 (let [nybbles (flatten (map byte->nybbles assembly))
892 moves (map (comp buttons (partial - 15)) nybbles)
893 header (map buttons
894 (concat (repeat
895 50
896 (- 15 (first nybbles)))
897 [(first nybbles)]))
898 tail (map buttons
899 (take
900 (- 201 (count moves))
901 (interleave (repeat 100 (last nybbles))
902 (repeat 1000 (- 15 (last nybbles))))))]
903 (assert (no-consecutive-repeats? nybbles))
904 (concat header moves tail)))
905
906 (def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF])
907
908 (defn test-pattern-writing
909 ([] (test-pattern-writing increasing-pattern))
910 ([pattern]
911 (let [moves (bootstrap-pattern pattern)
912 pattern-insertion
913 (->> (launch-bootstrap-program)
914 (play-moves
915 (take 100 moves)))]
916 (println "Input Pattern:")
917 (apply println (map #(format "0x%02X" %) pattern))
918 (println "\nMemory Listing:")
919 (print-listing (second pattern-insertion)
920 0xD162 (+ 0xD162 (count pattern)))
921 (= (subvec (vec (memory (second pattern-insertion)))
922 0xD162 (+ 0xD162 (count pattern)))
923 pattern))))
924
925
926