Mercurial > vba-clojure
diff clojure/com/aurellem/exp/item_bridge.clj @ 145:412ca096a9ba
major refactoring complete.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 19 Mar 2012 21:23:46 -0500 |
parents | clojure/com/aurellem/item_bridge.clj@b12d2408fd9b |
children | 3a3bb2197b7f |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/clojure/com/aurellem/exp/item_bridge.clj Mon Mar 19 21:23:46 2012 -0500 1.3 @@ -0,0 +1,65 @@ 1.4 +(ns com.aurellem.item-bridge 1.5 + (:use (com.aurellem gb-driver vbm title save-corruption items assembly)) 1.6 + (:import [com.aurellem.gb_driver SaveState])) 1.7 + 1.8 + 1.9 +(defn corrupt-item-state [] 1.10 + (second (destroy-item-end-of-list-marker))) 1.11 + 1.12 +(defn corrupt-item-state [] 1.13 + (read-state "corrupt-items")) 1.14 + 1.15 + 1.16 +(defn view-memory-range [state start end] 1.17 + (dorun 1.18 + (map (fn [loc val] 1.19 + (println (format "%04X : %02X" loc val))) 1.20 + 1.21 + (range start end) (subvec (vec (memory state)) start end))) 1.22 + state) 1.23 + 1.24 +(defn almost-broken 1.25 + "if one more memory location is turned into 0x03, the game crashes." 1.26 + [n] 1.27 + (view-memory-range 1.28 + (set-inv-mem (mid-game) 1.29 + (concat [0xFF] (repeat 64 0x03) 1.30 + (subvec (vec (memory (mid-game))) 1.31 + (+ item-list-start 65) 1.32 + (+ item-list-start 65 n)) 1.33 + (repeat (- 255 65 n) 0x03) 1.34 + )) 1.35 + 1.36 + item-list-start (+ item-list-start 255))) 1.37 + 1.38 +(defn actually-broken 1.39 + "if one more memory location is turned into 0x03, the game crashes." 1.40 + [] 1.41 + (set-memory (mid-game) 0xD35D 0x03)) 1.42 + 1.43 + 1.44 +;; (almost-broken 20) more or less works 1.45 + 1.46 +(defn capture-program-counter 1.47 + "records the program counter for each tick" 1.48 + [^SaveState state ticks] 1.49 + (let [i (atom 0)] 1.50 + (reduce (fn [[program-counters state] _] 1.51 + (println (swap! i inc)) 1.52 + [(conj program-counters (PC state)) 1.53 + (tick state)]) 1.54 + [[] state] 1.55 + (range ticks)))) 1.56 + 1.57 + 1.58 +(defn capture-program-counter 1.59 + [^SaveState state ticks] 1.60 + (set-state! state) 1.61 + (loop [i 0 1.62 + pcs []] 1.63 + (if (= i ticks) 1.64 + pcs 1.65 + (do 1.66 + (com.aurellem.gb.Gb/tick) 1.67 + (recur (inc i) 1.68 + (conj pcs (first (registers))))))))