# HG changeset patch
# User Robert McIntyre <rlm@mit.edu>
# Date 1332317900 18000
# Node ID 09caf6a5bbf40c177a194b779f9dd9858ee70eb2
# Parent  4857f59f63a67dd9743d5ae5b5b9d87d28378d19
added facilities to corrupt any state.

diff -r 4857f59f63a6 -r 09caf6a5bbf4 clojure/com/aurellem/exp/item_bridge.clj
--- a/clojure/com/aurellem/exp/item_bridge.clj	Wed Mar 21 01:37:10 2012 -0500
+++ b/clojure/com/aurellem/exp/item_bridge.clj	Wed Mar 21 03:18:20 2012 -0500
@@ -1,20 +1,19 @@
-(ns com.aurellem.item-bridge
-  (:use (com.aurellem.gb gb-driver vbm title save-corruption items assembly))
+(ns com.aurellem.exp.item-bridge
+  (:use (com.aurellem.gb util constants gb-driver vbm items assembly))
+  (:use (com.aurellem.run title save-corruption))
+  (:use (com.aurellem.exp pokemon))
   (:import [com.aurellem.gb.gb_driver SaveState]))
 
-
 (defn corrupt-item-state []
   (second (destroy-item-end-of-list-marker)))
 
 (defn corrupt-item-state []
   (read-state "corrupt-items"))
 
-
 (defn view-memory-range [state start end]
   (dorun
    (map (fn [loc val]
           (println (format "%04X : %02X" loc val)))
-        
         (range start end) (subvec (vec (memory state)) start end)))
   state)
 
@@ -27,13 +26,11 @@
                         (subvec (vec (memory (mid-game)))
                                 (+ item-list-start 65)
                                 (+ item-list-start 65 n))
-                        (repeat (- 255 65 n) 0x03)
-                        ))
-                
+                        (repeat (- 255 65 n) 0x03)))
    item-list-start (+ item-list-start 255)))
 
 (defn actually-broken
-  "if one more memory location is turned into 0x03, the game crashes."
+  "if this memory location is turned into 0x03, the game crashes."
   []
   (set-memory (mid-game) 0xD35D 0x03))
 
@@ -63,3 +60,87 @@
         (com.aurellem.gb.Gb/tick)
         (recur (inc i)
                (conj pcs (first (registers))))))))
+
+(defn loop-program []
+  [0xF3     ;0xD31D  ;; disable-interrupts
+
+   0xC3     ;; loop forever
+   0x1D
+   0xD3])
+
+(def map-function-address-start 0xD36D)
+
+(defn test-loop []
+  (capture-program-counter
+   (-> (mid-game) 
+       (set-memory-range 0xD31D (loop-program))
+       (set-memory-range
+        map-function-address-start
+        [0xD3 0x1D])
+       (IE! 0))
+   1000))
+
+
+(defn-memo corrupt-moves []
+  (concat
+   (first
+    (->>
+     [[] (mid-game)]
+     (advance [:b] [:b :start])
+     (advance [] [:d])
+     (play-moves [[] [] [] [:d] [] [] [] [:d] [] [] [:a]])
+     scroll-text
+     (play-moves
+      ;; this section is copied from speedrun-2942
+      ;; and corrupts the save so that the end-of-list marker
+      ;; for the pokemon roster is destroyed, but the save is still
+      ;; playable.
+      [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
+       [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])
+     (play-moves
+      (first (title)))
+     (advance [] [:start])
+     (advance [] [:a])
+     (advance [:a] [:a :start])))
+   [[]]))
+  
+
+
+(defn corrupt
+  "enter the codes to destroy the
+   pokemon list using save corruption"
+  ([^SaveState state]
+  (run-moves
+   state
+   (corrupt-moves)))
+    
+
+
+   
+  (step 
+  (second 
+   (->>
+    [[] state]
+    (advance [:b] [:a :b :start])
+    (advance [] [:d])
+    (play-moves [[] [] [] [:d] [] [] [] [:d] [] [] [:a]])
+    scroll-text
+    (play-moves
+     ;; this section is copied from speedrun-2942
+     ;; and corrupts the save so that the end-of-list marker
+     ;; for the pokemon roster is destroyed, but the save is still
+     ;; playable.
+     [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
+      [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])
+    (play-moves
+     (first (title)))
+    (advance [] [:start])
+    (advance [] [:a])
+    (advance [:a] [:a :start]))) []))
+  
+   
+
+             
+
+
+
diff -r 4857f59f63a6 -r 09caf6a5bbf4 clojure/com/aurellem/run/save_corruption.clj
--- a/clojure/com/aurellem/run/save_corruption.clj	Wed Mar 21 01:37:10 2012 -0500
+++ b/clojure/com/aurellem/run/save_corruption.clj	Wed Mar 21 03:18:20 2012 -0500
@@ -1,5 +1,6 @@
-(ns com.aurellem.save-corruption
-  (:use (com.aurellem gb-driver vbm title)))
+(ns com.aurellem.run.save-corruption
+  (:use (com.aurellem.gb gb-driver vbm))
+  (:use (com.aurellem.run title)))
 
 (use 'clojure.repl)
 
@@ -84,7 +85,7 @@
         [] [] [] [] [] [] [] [] [] [] []
 
         ;; [:b] [] [] [] [] [] [] [] []
-        ;; [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
+        ;; [] [] [] [] [] [] [] [] [] [] [] [] [] [] [][][][][] [] []
         ;; [] [] [] [] [] [] [] [] [] [] [] [] [] [:d] [] [] [:a] [] []
         ;; [] [] [] [] [] [] [] [] [] [] [] [] [] [:d] [] [] [] [:d] []
         ])))
diff -r 4857f59f63a6 -r 09caf6a5bbf4 clojure/com/aurellem/run/title.clj
--- a/clojure/com/aurellem/run/title.clj	Wed Mar 21 01:37:10 2012 -0500
+++ b/clojure/com/aurellem/run/title.clj	Wed Mar 21 03:18:20 2012 -0500
@@ -1,5 +1,5 @@
-(ns com.aurellem.title
-  (:use (com.aurellem gb-driver vbm)))
+(ns com.aurellem.run.title
+  (:use (com.aurellem.gb gb-driver vbm)))
 
 (defn first-difference [base alt summary root]
   (loop [branch-point root
diff -r 4857f59f63a6 -r 09caf6a5bbf4 save-states/mid-game.sav
Binary file save-states/mid-game.sav has changed