annotate clojure/com/aurellem/exp/item_bridge.clj @ 148:06426d25c65b

can now get/set pokemon OT name
author Robert McIntyre <rlm@mit.edu>
date Mon, 19 Mar 2012 23:14:21 -0500
parents 412ca096a9ba
children 3a3bb2197b7f
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 almost-broken
rlm@133 22 "if one more memory location is turned into 0x03, the game crashes."
rlm@133 23 [n]
rlm@133 24 (view-memory-range
rlm@133 25 (set-inv-mem (mid-game)
rlm@133 26 (concat [0xFF] (repeat 64 0x03)
rlm@133 27 (subvec (vec (memory (mid-game)))
rlm@133 28 (+ item-list-start 65)
rlm@133 29 (+ item-list-start 65 n))
rlm@133 30 (repeat (- 255 65 n) 0x03)
rlm@133 31 ))
rlm@133 32
rlm@133 33 item-list-start (+ item-list-start 255)))
rlm@131 34
rlm@133 35 (defn actually-broken
rlm@133 36 "if one more memory location is turned into 0x03, the game crashes."
rlm@133 37 []
rlm@133 38 (set-memory (mid-game) 0xD35D 0x03))
rlm@131 39
rlm@131 40
rlm@133 41 ;; (almost-broken 20) more or less works
rlm@133 42
rlm@133 43 (defn capture-program-counter
rlm@133 44 "records the program counter for each tick"
rlm@133 45 [^SaveState state ticks]
rlm@133 46 (let [i (atom 0)]
rlm@133 47 (reduce (fn [[program-counters state] _]
rlm@133 48 (println (swap! i inc))
rlm@133 49 [(conj program-counters (PC state))
rlm@133 50 (tick state)])
rlm@133 51 [[] state]
rlm@133 52 (range ticks))))
rlm@133 53
rlm@133 54
rlm@133 55 (defn capture-program-counter
rlm@133 56 [^SaveState state ticks]
rlm@133 57 (set-state! state)
rlm@133 58 (loop [i 0
rlm@133 59 pcs []]
rlm@133 60 (if (= i ticks)
rlm@133 61 pcs
rlm@133 62 (do
rlm@133 63 (com.aurellem.gb.Gb/tick)
rlm@133 64 (recur (inc i)
rlm@133 65 (conj pcs (first (registers))))))))