comparison 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
comparison
equal deleted inserted replaced
144:ec477931f077 145:412ca096a9ba
1 (ns com.aurellem.item-bridge
2 (:use (com.aurellem gb-driver vbm title save-corruption items assembly))
3 (:import [com.aurellem.gb_driver SaveState]))
4
5
6 (defn corrupt-item-state []
7 (second (destroy-item-end-of-list-marker)))
8
9 (defn corrupt-item-state []
10 (read-state "corrupt-items"))
11
12
13 (defn view-memory-range [state start end]
14 (dorun
15 (map (fn [loc val]
16 (println (format "%04X : %02X" loc val)))
17
18 (range start end) (subvec (vec (memory state)) start end)))
19 state)
20
21 (defn almost-broken
22 "if one more memory location is turned into 0x03, the game crashes."
23 [n]
24 (view-memory-range
25 (set-inv-mem (mid-game)
26 (concat [0xFF] (repeat 64 0x03)
27 (subvec (vec (memory (mid-game)))
28 (+ item-list-start 65)
29 (+ item-list-start 65 n))
30 (repeat (- 255 65 n) 0x03)
31 ))
32
33 item-list-start (+ item-list-start 255)))
34
35 (defn actually-broken
36 "if one more memory location is turned into 0x03, the game crashes."
37 []
38 (set-memory (mid-game) 0xD35D 0x03))
39
40
41 ;; (almost-broken 20) more or less works
42
43 (defn capture-program-counter
44 "records the program counter for each tick"
45 [^SaveState state ticks]
46 (let [i (atom 0)]
47 (reduce (fn [[program-counters state] _]
48 (println (swap! i inc))
49 [(conj program-counters (PC state))
50 (tick state)])
51 [[] state]
52 (range ticks))))
53
54
55 (defn capture-program-counter
56 [^SaveState state ticks]
57 (set-state! state)
58 (loop [i 0
59 pcs []]
60 (if (= i ticks)
61 pcs
62 (do
63 (com.aurellem.gb.Gb/tick)
64 (recur (inc i)
65 (conj pcs (first (registers))))))))