rlm@130: (ns com.aurellem.item-bridge rlm@131: (:use (com.aurellem gb-driver vbm title save-corruption items assembly)) rlm@130: (:import [com.aurellem.gb_driver SaveState])) rlm@130: rlm@130: rlm@131: (defn corrupt-item-state [] rlm@131: (second (destroy-item-end-of-list-marker))) rlm@131: rlm@131: (defn corrupt-item-state [] rlm@131: (read-state "corrupt-items")) rlm@131: rlm@131: rlm@133: (defn view-memory-range [state start end] rlm@133: (dorun rlm@133: (map (fn [loc val] rlm@133: (println (format "%04X : %02X" loc val))) rlm@133: rlm@133: (range start end) (subvec (vec (memory state)) start end))) rlm@133: state) rlm@131: rlm@133: (defn set-memory [state location value] rlm@131: (set-state! state) rlm@131: (let [mem (memory state)] rlm@133: (aset mem location value) rlm@131: (write-memory! mem) rlm@131: (update-state))) rlm@131: rlm@133: (defn almost-broken rlm@133: "if one more memory location is turned into 0x03, the game crashes." rlm@133: [n] rlm@133: (view-memory-range rlm@133: (set-inv-mem (mid-game) rlm@133: (concat [0xFF] (repeat 64 0x03) rlm@133: (subvec (vec (memory (mid-game))) rlm@133: (+ item-list-start 65) rlm@133: (+ item-list-start 65 n)) rlm@133: (repeat (- 255 65 n) 0x03) rlm@133: )) rlm@133: rlm@133: item-list-start (+ item-list-start 255))) rlm@131: rlm@133: (defn actually-broken rlm@133: "if one more memory location is turned into 0x03, the game crashes." rlm@133: [] rlm@133: (set-memory (mid-game) 0xD35D 0x03)) rlm@131: rlm@131: rlm@133: ;; (almost-broken 20) more or less works rlm@133: rlm@133: (defn capture-program-counter rlm@133: "records the program counter for each tick" rlm@133: [^SaveState state ticks] rlm@133: (let [i (atom 0)] rlm@133: (reduce (fn [[program-counters state] _] rlm@133: (println (swap! i inc)) rlm@133: [(conj program-counters (PC state)) rlm@133: (tick state)]) rlm@133: [[] state] rlm@133: (range ticks)))) rlm@133: rlm@133: rlm@133: (defn capture-program-counter rlm@133: [^SaveState state ticks] rlm@133: (set-state! state) rlm@133: (loop [i 0 rlm@133: pcs []] rlm@133: (if (= i ticks) rlm@133: pcs rlm@133: (do rlm@133: (com.aurellem.gb.Gb/tick) rlm@133: (recur (inc i) rlm@133: (conj pcs (first (registers))))))))