view clojure/com/aurellem/item_bridge.clj @ 134:718abf3bec8a

removed hardcoded /home/r/ strings from paths and made them relative to user.home
author Robert McIntyre <rlm@mit.edu>
date Sun, 18 Mar 2012 00:56:29 -0500
parents 424510993296
children b12d2408fd9b
line wrap: on
line source
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]))
6 (defn corrupt-item-state []
7 (second (destroy-item-end-of-list-marker)))
9 (defn corrupt-item-state []
10 (read-state "corrupt-items"))
13 (defn view-memory-range [state start end]
14 (dorun
15 (map (fn [loc val]
16 (println (format "%04X : %02X" loc val)))
18 (range start end) (subvec (vec (memory state)) start end)))
19 state)
21 (defn set-memory [state location value]
22 (set-state! state)
23 (let [mem (memory state)]
24 (aset mem location value)
25 (write-memory! mem)
26 (update-state)))
28 (defn almost-broken
29 "if one more memory location is turned into 0x03, the game crashes."
30 [n]
31 (view-memory-range
32 (set-inv-mem (mid-game)
33 (concat [0xFF] (repeat 64 0x03)
34 (subvec (vec (memory (mid-game)))
35 (+ item-list-start 65)
36 (+ item-list-start 65 n))
37 (repeat (- 255 65 n) 0x03)
38 ))
40 item-list-start (+ item-list-start 255)))
42 (defn actually-broken
43 "if one more memory location is turned into 0x03, the game crashes."
44 []
45 (set-memory (mid-game) 0xD35D 0x03))
48 ;; (almost-broken 20) more or less works
50 (defn capture-program-counter
51 "records the program counter for each tick"
52 [^SaveState state ticks]
53 (let [i (atom 0)]
54 (reduce (fn [[program-counters state] _]
55 (println (swap! i inc))
56 [(conj program-counters (PC state))
57 (tick state)])
58 [[] state]
59 (range ticks))))
62 (defn capture-program-counter
63 [^SaveState state ticks]
64 (set-state! state)
65 (loop [i 0
66 pcs []]
67 (if (= i ticks)
68 pcs
69 (do
70 (com.aurellem.gb.Gb/tick)
71 (recur (inc i)
72 (conj pcs (first (registers))))))))