annotate clojure/com/aurellem/item_bridge.clj @ 135:eb6ba88088d3

Wrote a more efficient input-number-assembly program; 91 oc -> 60 oc.
author Dylan Holmes <ocsenave@gmail.com>
date Sun, 18 Mar 2012 05:13:19 -0500
parents 424510993296
children b12d2408fd9b
rev   line source
rlm@130 1 (ns com.aurellem.item-bridge
rlm@131 2 (:use (com.aurellem gb-driver vbm title save-corruption items assembly))
rlm@130 3 (:import [com.aurellem.gb_driver SaveState]))
rlm@130 4
rlm@130 5
rlm@131 6 (defn corrupt-item-state []
rlm@131 7 (second (destroy-item-end-of-list-marker)))
rlm@131 8
rlm@131 9 (defn corrupt-item-state []
rlm@131 10 (read-state "corrupt-items"))
rlm@131 11
rlm@131 12
rlm@133 13 (defn view-memory-range [state start end]
rlm@133 14 (dorun
rlm@133 15 (map (fn [loc val]
rlm@133 16 (println (format "%04X : %02X" loc val)))
rlm@133 17
rlm@133 18 (range start end) (subvec (vec (memory state)) start end)))
rlm@133 19 state)
rlm@131 20
rlm@133 21 (defn set-memory [state location value]
rlm@131 22 (set-state! state)
rlm@131 23 (let [mem (memory state)]
rlm@133 24 (aset mem location value)
rlm@131 25 (write-memory! mem)
rlm@131 26 (update-state)))
rlm@131 27
rlm@133 28 (defn almost-broken
rlm@133 29 "if one more memory location is turned into 0x03, the game crashes."
rlm@133 30 [n]
rlm@133 31 (view-memory-range
rlm@133 32 (set-inv-mem (mid-game)
rlm@133 33 (concat [0xFF] (repeat 64 0x03)
rlm@133 34 (subvec (vec (memory (mid-game)))
rlm@133 35 (+ item-list-start 65)
rlm@133 36 (+ item-list-start 65 n))
rlm@133 37 (repeat (- 255 65 n) 0x03)
rlm@133 38 ))
rlm@133 39
rlm@133 40 item-list-start (+ item-list-start 255)))
rlm@131 41
rlm@133 42 (defn actually-broken
rlm@133 43 "if one more memory location is turned into 0x03, the game crashes."
rlm@133 44 []
rlm@133 45 (set-memory (mid-game) 0xD35D 0x03))
rlm@131 46
rlm@131 47
rlm@133 48 ;; (almost-broken 20) more or less works
rlm@133 49
rlm@133 50 (defn capture-program-counter
rlm@133 51 "records the program counter for each tick"
rlm@133 52 [^SaveState state ticks]
rlm@133 53 (let [i (atom 0)]
rlm@133 54 (reduce (fn [[program-counters state] _]
rlm@133 55 (println (swap! i inc))
rlm@133 56 [(conj program-counters (PC state))
rlm@133 57 (tick state)])
rlm@133 58 [[] state]
rlm@133 59 (range ticks))))
rlm@133 60
rlm@133 61
rlm@133 62 (defn capture-program-counter
rlm@133 63 [^SaveState state ticks]
rlm@133 64 (set-state! state)
rlm@133 65 (loop [i 0
rlm@133 66 pcs []]
rlm@133 67 (if (= i ticks)
rlm@133 68 pcs
rlm@133 69 (do
rlm@133 70 (com.aurellem.gb.Gb/tick)
rlm@133 71 (recur (inc i)
rlm@133 72 (conj pcs (first (registers))))))))