comparison clojure/com/aurellem/exp/item_bridge.clj @ 170:09caf6a5bbf4

added facilities to corrupt any state.
author Robert McIntyre <rlm@mit.edu>
date Wed, 21 Mar 2012 03:18:20 -0500
parents 3a3bb2197b7f
children d7e2cfecef1d
comparison
equal deleted inserted replaced
169:4857f59f63a6 170:09caf6a5bbf4
1 (ns com.aurellem.item-bridge 1 (ns com.aurellem.exp.item-bridge
2 (:use (com.aurellem.gb gb-driver vbm title save-corruption items assembly)) 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))
3 (:import [com.aurellem.gb.gb_driver SaveState])) 5 (:import [com.aurellem.gb.gb_driver SaveState]))
4
5 6
6 (defn corrupt-item-state [] 7 (defn corrupt-item-state []
7 (second (destroy-item-end-of-list-marker))) 8 (second (destroy-item-end-of-list-marker)))
8 9
9 (defn corrupt-item-state [] 10 (defn corrupt-item-state []
10 (read-state "corrupt-items")) 11 (read-state "corrupt-items"))
11 12
12
13 (defn view-memory-range [state start end] 13 (defn view-memory-range [state start end]
14 (dorun 14 (dorun
15 (map (fn [loc val] 15 (map (fn [loc val]
16 (println (format "%04X : %02X" loc val))) 16 (println (format "%04X : %02X" loc val)))
17
18 (range start end) (subvec (vec (memory state)) start end))) 17 (range start end) (subvec (vec (memory state)) start end)))
19 state) 18 state)
20 19
21 (defn almost-broken 20 (defn almost-broken
22 "if one more memory location is turned into 0x03, the game crashes." 21 "if one more memory location is turned into 0x03, the game crashes."
25 (set-inv-mem (mid-game) 24 (set-inv-mem (mid-game)
26 (concat [0xFF] (repeat 64 0x03) 25 (concat [0xFF] (repeat 64 0x03)
27 (subvec (vec (memory (mid-game))) 26 (subvec (vec (memory (mid-game)))
28 (+ item-list-start 65) 27 (+ item-list-start 65)
29 (+ item-list-start 65 n)) 28 (+ item-list-start 65 n))
30 (repeat (- 255 65 n) 0x03) 29 (repeat (- 255 65 n) 0x03)))
31 ))
32
33 item-list-start (+ item-list-start 255))) 30 item-list-start (+ item-list-start 255)))
34 31
35 (defn actually-broken 32 (defn actually-broken
36 "if one more memory location is turned into 0x03, the game crashes." 33 "if this memory location is turned into 0x03, the game crashes."
37 [] 34 []
38 (set-memory (mid-game) 0xD35D 0x03)) 35 (set-memory (mid-game) 0xD35D 0x03))
39 36
40 37
41 ;; (almost-broken 20) more or less works 38 ;; (almost-broken 20) more or less works
61 pcs 58 pcs
62 (do 59 (do
63 (com.aurellem.gb.Gb/tick) 60 (com.aurellem.gb.Gb/tick)
64 (recur (inc i) 61 (recur (inc i)
65 (conj pcs (first (registers)))))))) 62 (conj pcs (first (registers))))))))
63
64 (defn loop-program []
65 [0xF3 ;0xD31D ;; disable-interrupts
66
67 0xC3 ;; loop forever
68 0x1D
69 0xD3])
70
71 (def map-function-address-start 0xD36D)
72
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))
82
83
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 [[]]))
106
107
108
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
117
118
119
120 (step
121 (second
122 (->>
123 [[] state]
124 (advance [:b] [:a :b :start])
125 (advance [] [:d])
126 (play-moves [[] [] [] [:d] [] [] [] [:d] [] [] [:a]])
127 scroll-text
128 (play-moves
129 ;; this section is copied from speedrun-2942
130 ;; and corrupts the save so that the end-of-list marker
131 ;; for the pokemon roster is destroyed, but the save is still
132 ;; playable.
133 [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
134 [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])
135 (play-moves
136 (first (title)))
137 (advance [] [:start])
138 (advance [] [:a])
139 (advance [:a] [:a :start]))) []))
140
141
142
143
144
145
146