view clojure/com/aurellem/item_bridge.clj @ 142:b12d2408fd9b

moved set-memory to proper position, added pokemon.clj
author Robert McIntyre <rlm@mit.edu>
date Mon, 19 Mar 2012 19:56:55 -0500
parents 424510993296
children
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 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 ))
33 item-list-start (+ item-list-start 255)))
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))
41 ;; (almost-broken 20) more or less works
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))))
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))))))))