view clojure/com/aurellem/exp/item_bridge.clj @ 171:d7e2cfecef1d

fixed compilation problems.
author Robert McIntyre <rlm@mit.edu>
date Wed, 21 Mar 2012 03:20:03 -0500
parents 09caf6a5bbf4
children 8665160f0f3d
line wrap: on
line source
1 (ns com.aurellem.exp.item-bridge
2 (:use (com.aurellem.gb util constants gb-driver vbm items assembly))
3 (:use (com.aurellem.run title save-corruption))
4 (:use (com.aurellem.exp pokemon))
5 (:import [com.aurellem.gb.gb_driver SaveState]))
7 (defn corrupt-item-state []
8 (second (destroy-item-end-of-list-marker)))
10 (defn corrupt-item-state []
11 (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)))
17 (range start end) (subvec (vec (memory state)) start end)))
18 state)
20 (defn almost-broken
21 "if one more memory location is turned into 0x03, the game crashes."
22 [n]
23 (view-memory-range
24 (set-inv-mem (mid-game)
25 (concat [0xFF] (repeat 64 0x03)
26 (subvec (vec (memory (mid-game)))
27 (+ item-list-start 65)
28 (+ item-list-start 65 n))
29 (repeat (- 255 65 n) 0x03)))
30 item-list-start (+ item-list-start 255)))
32 (defn actually-broken
33 "if this memory location is turned into 0x03, the game crashes."
34 []
35 (set-memory (mid-game) 0xD35D 0x03))
38 ;; (almost-broken 20) more or less works
40 (defn capture-program-counter
41 "records the program counter for each tick"
42 [^SaveState state ticks]
43 (let [i (atom 0)]
44 (reduce (fn [[program-counters state] _]
45 (println (swap! i inc))
46 [(conj program-counters (PC state))
47 (tick state)])
48 [[] state]
49 (range ticks))))
52 (defn capture-program-counter
53 [^SaveState state ticks]
54 (set-state! state)
55 (loop [i 0
56 pcs []]
57 (if (= i ticks)
58 pcs
59 (do
60 (com.aurellem.gb.Gb/tick)
61 (recur (inc i)
62 (conj pcs (first (registers))))))))
64 (defn loop-program []
65 [0xF3 ;0xD31D ;; disable-interrupts
67 0xC3 ;; loop forever
68 0x1D
69 0xD3])
71 (def map-function-address-start 0xD36D)
73 (defn test-loop []
74 (capture-program-counter
75 (-> (mid-game)
76 (set-memory-range 0xD31D (loop-program))
77 (set-memory-range
78 map-function-address-start
79 [0xD3 0x1D])
80 (IE! 0))
81 1000))
84 (defn-memo corrupt-moves []
85 (concat
86 (first
87 (->>
88 [[] (mid-game)]
89 (advance [:b] [:b :start])
90 (advance [] [:d])
91 (play-moves [[] [] [] [:d] [] [] [] [:d] [] [] [:a]])
92 scroll-text
93 (play-moves
94 ;; this section is copied from speedrun-2942
95 ;; and corrupts the save so that the end-of-list marker
96 ;; for the pokemon roster is destroyed, but the save is still
97 ;; playable.
98 [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
99 [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])
100 (play-moves
101 (first (title)))
102 (advance [] [:start])
103 (advance [] [:a])
104 (advance [:a] [:a :start])))
105 [[]]))
109 (defn corrupt
110 "enter the codes to destroy the
111 pokemon list using save corruption"
112 ([^SaveState state]
113 (run-moves
114 state
115 (corrupt-moves)))
116 ([] (corrupt @current-state)))