view clojure/com/aurellem/experiments/items.clj @ 106:3a60bb14a64a

better functional assembly interface; removed frame numbers from SaveStates
author Robert McIntyre <rlm@mit.edu>
date Wed, 14 Mar 2012 21:37:37 -0500
parents 9fad96094950
children
line wrap: on
line source
1 (ns com.aurellem.experiments.items
2 (:use (com.aurellem gb-driver vbm title items))
3 (:import [com.aurellem.gb_driver SaveState]))
5 ;; try just buying five potions in sequence and see what changes
6 ;; each time.
8 (defn common-differences [& seqs]
9 (let [backbone (range (count (first seqs)))]
10 (filter
11 (comp (partial apply distinct?) second)
12 (zipmap backbone
13 (apply (partial map list) seqs)))))
15 ;; trying to find how items are represented in memory
17 (def zero-potions (read-state "zero-potions"))
19 (def one-potion (read-state "one-potion"))
21 (def two-potions (read-state "two-potions"))
23 (def three-potions (read-state "three-potions"))
25 (def four-potions (read-state "four-potions"))
27 (def five-potions (read-state "five-potions"))
30 ;; result
31 (defn canidates []
32 (apply common-differences
33 (map (comp vec memory)
34 [zero-potions one-potion two-potions three-potions
35 four-potions five-potions])))
37 (comment [55875 (37 15 49 27 14 44)]
38 [55876 (30 1 49 56 55 23)]
39 [49158 (154 191 78 135 70 73)]
40 [54087 (49 40 37 34 25 22)]
41 [49160 (7 24 59 243 50 217)]
42 [49704 (31 14 72 33 84 27)]
43 [49162 (126 159 183 110 176 179)]
44 [39984 (0 254 251 248 127 252)]
45 [49904 (29 72 64 78 1 95)]
46 [65491 (222 127 149 132 226 38)]
47 [65492 (44 20 89 11 253 163)]
48 [49335 (52 15 6 14 3 17)]
49 [49720 (78 152 96 60 83 103)]
50 [65304 (19 89 214 33 18 113)]
51 [53561 (132 185 145 162 159 183)]
52 [54046 (0 1 2 3 4 5)])
54 ;;; hmmmmmm...... I guess that the potion quantities are at 54046,
55 ;;;huh?
59 (defn get-mem []
60 (subvec (vec (memory @current-state)) 54040 (+ 54046 100)))
63 ;; potion -- 99
64 [0 16 0 0 1 20 99 255 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]
66 ;; potion -- 95
67 [0 16 0 0 1 20 95 255 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]
69 ;; potion -- 95
70 ;; pokeball -- 1
71 [0 16 0 0 2 20 95 4 1 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 41 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]
73 ;; potion -- 95
74 ;; pokeball -- 10
75 [0 16 0 0 2 20 95 4 10 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]
78 ;; pokeball -- 10
79 ;; potion -- 95
80 [0 16 0 0 2 4 10 20 95 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]
82 ;; pokeball -- 10
83 ;; potion -- 95
84 ;; antidote -- 1
86 ;;prediction
87 ;;[0 16 0 0 3 4 10 20 95 ?? 1 255 0 0 0 0 0 ....]
88 [0 16 0 0 3 4 10 20 95 11 1 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10]
92 ;; now it's time to learn the item codes
94 (def inventory-begin
95 (read-state "inventory-begin"))
97 (defn show-item
98 "Run a saved pokemon with the first item replaced by the item named
99 by n."
100 [n]
101 (set-state! inventory-begin)
102 (let [mem (memory)]
103 (aset mem 54044 1)
104 (aset mem 54045 n)
105 (aset mem 54046 1)
106 (aset mem 54047 255)
107 (write-memory! mem))
108 (step)
109 (->> [[] @current-state]
110 (play-moves
111 [[:a] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
112 [] [] [] [] []])))
115 (defn get-item-names []
116 (dorun (map (fn [n] (println n)
117 (show-item n)
118 (Thread/sleep 5000))
119 (range 0x00 0xFF))))
121 ;; results (took about 10 minutes to generate)
123 ;; 0 garbage
124 ;; 1 master-ball
125 ;; 2 ultra-ball
126 ;; 3 great-ball
127 ;; 4 poke-ball
128 ;; 5 town-map
129 ;; 6 bicycle
130 ;; 7 ?????
131 ;; 8 safari-ball
132 ;; 9 pokedex
133 ;; 10 moon-stone
134 ;; 11 antidote
135 ;; 12 burn-heal
136 ;; 13 ice-heal
137 ;; 14 awakening
138 ;; 15 parlyz-heal
139 ;; 16 full-restore
140 ;; 17 max-potion
141 ;; 18 hyper-potion
142 ;; 19 super-potion
143 ;; 20 potion
144 ;; 21 boulderbadge
145 ;; 22 cascadebadge
146 ;; 23 thunderbadge
147 ;; 24 rainbowbadge
148 ;; 25 soulbadge
149 ;; 26 marshbadge
150 ;; 27 volcanobadge
151 ;; 28 earthbadge
152 ;; 29 escape-rope
153 ;; 30 repel
154 ;; 31 old amber
155 ;; 32 fire-stone
156 ;; 33 thunderstone
157 ;; 34 water-stone
158 ;; 35 hp-up
159 ;; 36 protein
160 ;; 37 iron
161 ;; 38 carbos
162 ;; 39 calcium
163 ;; 40 rare-candy
164 ;; 41 dome-fossil
165 ;; 42 helix-fossil
166 ;; 43 secret-key
167 ;; 44 ?????
168 ;; 45 bike-voucher
169 ;; 46 x-accuracy
170 ;; 47 leaf-stone
171 ;; 48 card-key
172 ;; 49 nugget
173 ;; 50 pp-up
174 ;; 51 poke-doll
175 ;; 52 full-heal
176 ;; 53 revive
177 ;; 54 max-revive
178 ;; 55 guard-spec.
179 ;; 56 super-repel
180 ;; 57 max-repel
181 ;; 58 dire-hit
182 ;; 59 coin
183 ;; 60 fresh-water
184 ;; 61 soda-pop
185 ;; 62 lemonade
186 ;; 63 s.s.ticket
187 ;; 64 gold-teeth
188 ;; 65 x-attach
189 ;; 66 x-defend
190 ;; 67 x-speed
191 ;; 68 x-special
192 ;; 69 coin-case
193 ;; 70 oak's-parcel
194 ;; 71 itemfinder
195 ;; 72 silph-scope
196 ;; 73 poke-flute
197 ;; 74 lift-key
198 ;; 75 exp.all
199 ;; 76 old-rod
200 ;; 77 good-rod
201 ;; 78 super-rod
202 ;; 79 pp-up
203 ;; 80 ether
204 ;; 81 max-ether
205 ;; 82 elixer
206 ;; 83 max-elixer
207 ;; 84 B2F
208 ;; 85 B1F
209 ;; 86 1F
210 ;; 87 2F
211 ;; 88 3F
212 ;; 89 4F
213 ;; 90 5F
214 ;; 91 6F
215 ;; 92 7F
216 ;; 93 8F
217 ;; 94 9F
218 ;; 95 10F
219 ;; 96 11F
220 ;; 97 B4F
221 ;; 98 garbage
222 ;; 99 garbage
223 ;; 100 garbage
224 ;; 101 garbage
225 ;; 102 garbage
226 ;; 103 garbage
227 ;; 104 garbage
228 ;; 105 garbage
229 ;; 106 garbage
230 ;; 107 garbage
231 ;; 108 garbage
232 ;; 109 garbage
233 ;; 110 garbage
234 ;; 111 garbage
235 ;; 112 garbage
236 ;; 113 garbage
237 ;; 114 garbage
238 ;; 115 garbage
239 ;; 116 garbage
240 ;; 117 garbage
241 ;; 118 garbage
242 ;; 119 4
243 ;; 120 garbage
244 ;; 121 garbage
245 ;; 122 slow
246 ;; 123 garbage
247 ;; 124 garbage
248 ;; 125 garbage
249 ;; 126 garbage
250 ;; 127 garbage
251 ;; 128 garbage
252 ;; 129 garbage
253 ;; 130 garbage
254 ;; 131 slow
255 ;; 132 slow
256 ;; 133 garbage
257 ;; 134 slow
258 ;; 135 garbage
259 ;; 136 garbage
260 ;; 137 slow
261 ;; 138 garbage
262 ;; 139 garbage
263 ;; 140 garbage
264 ;; 141 slow
265 ;; 142 garbage
266 ;; 143 garbage
267 ;; 144 garbage
268 ;; 145 garbage
269 ;; 146 garbage
270 ;; 147 garbage
271 ;; 148 garbage
272 ;; 149 garbage
273 ;; 150 slow
274 ;; 151 garbage
275 ;; 152 Q
276 ;; 153 garbage
277 ;; 154 garbage
278 ;; 155 garbage
279 ;; 156 garbage
280 ;; 157 garbage
281 ;; 158 garbage
282 ;; 159 garbage
283 ;; 160 garbage (alaphabet)
284 ;; 161 garbage
285 ;; 162 garbage
286 ;; 163 garbage
287 ;; 164 rival's
288 ;; 165 name?
289 ;; 166 nickname?
290 ;; 167 slow
291 ;; 168 garbage
292 ;; 169 slow
293 ;; 170 garbage
294 ;; 171 garbage
295 ;; 172 garbage
296 ;; 173 garbage
297 ;; 174 garbage
298 ;; 175 yellow
299 ;; 176 ash
300 ;; 177 jack
301 ;; 178 new-name
302 ;; 179 blue
303 ;; 180 gary
304 ;; 181 john
305 ;; 182 garbage
306 ;; 183 garbage
307 ;; 184 garbage
308 ;; 185 garbage
309 ;; 186 slow
310 ;; 187 garbage
311 ;; 188 garbage
312 ;; 189 garbage
313 ;; 190 garbage
314 ;; 191 garbage
315 ;; 192 garbage
316 ;; 193 garbage
317 ;; 194 garbage
318 ;; 195 slow
319 ;; 196 HM01
320 ;; 197 HM02
321 ;; 198 HM03
322 ;; 199 HM04
323 ;; 200 HM05
324 ;; 201 TM01
325 ;; 202 TM02
326 ;; 203 TM03
327 ;; 204 TM04
328 ;; 205 TM05
329 ;; 206 TM06
330 ;; 207 TM07
331 ;; 208 TM08
332 ;; 209 TM09
333 ;; 210 TM10
334 ;; 211 TM11
335 ;; 212 TM12
336 ;; 213 TM13
337 ;; 214 TM13
338 ;; 215 TM15
339 ;; 216 TM16
340 ;; 217 TM17
341 ;; 218 TM18
342 ;; 219 TM19
343 ;; 220 TM20
344 ;; 221 TM21
345 ;; 222 TM22
346 ;; 223 TM23
347 ;; 224 TM24
348 ;; 225 TM25
349 ;; 226 TM26
350 ;; 227 TM27
351 ;; 228 TM28
352 ;; 229 TM29
353 ;; 230 TM30
354 ;; 231 TM31
355 ;; 232 TM32
356 ;; 233 TM33
357 ;; 234 TM34
358 ;; 235 TM35
359 ;; 236 TM36
360 ;; 237 TM37
361 ;; 238 TM38
362 ;; 239 TM39
363 ;; 240 TM40
364 ;; 241 TM41
365 ;; 242 TM42
366 ;; 243 TM43
367 ;; 244 TM44
368 ;; 245 TM45
369 ;; 246 TM46
370 ;; 247 TM47
371 ;; 248 TM48
372 ;; 249 TM49
373 ;; 250 TM50
374 ;; 251 TM51
375 ;; 252 TM52
376 ;; 253 TM53
377 ;; 254 TM54
378 ;; 255 end-of-list-sentinel
382 (defn run-item-program
383 "This is my first assembly/item program!
384 it just increments BC by one.
386 The code places a 3 'great balls' at the beginning of the
387 inventory, then directly sets the program counter to start
388 executing at the position of the 'great balls' in memory.
390 Since a 'great ball' is represented in memory as 0x03, which
391 corresponts to the opcode which increments BC by one, that is
392 what happens. Then the program counter to the 0x03 quantity entry
393 and BC is incremented again.
395 Obviously, the game crashes more or less immediately after the
396 program counter advances past the 'great balls' into the next items
397 in the inventory, thus I call shutdown! before anything bad happens."
398 []
399 (set-inventory (read-state "mid-game") [[:great-ball 3]])
400 (print-inventory)
401 (println "3 ticks") (tick) (tick) (tick)
402 (println "PC before:" (PC))
403 (println "BC before:" (BC))
404 (PC! (inc item-list-start))
405 (println "PC after setting:" (PC))
406 (println "data at PC:" (aget (memory) (PC)))
407 (println "one tick")
408 (tick)
409 (println "PC after one tick:" (PC))
410 (println "BC after one tick:" (BC))
411 (tick)
412 (println "PC after two ticks:" (PC))
413 (println "BC after two ticks:" (BC))
415 (shutdown!))
420 (defn test-opcodes-1
421 []
422 (let [final-state
423 (->
424 (read-state "mid-game")
425 (set-inv-mem
426 [20 0x02 0x00 0x00 0x02 0x00 0x00
427 0x00 0x0 0xFF])
428 (print-inventory)
429 ;;((fn [_] (println "3 ticks") _))
430 (tick) (tick) (tick)
432 ;;(println "PC before:" (PC))
433 ;;(println "BC before:" (BC))
434 ;;(println "AF:" (AF))
435 (PC! (inc item-list-start))
436 (BC! (+ 1 item-list-start))
437 ;;(println "PC after setting:" (PC))
438 ;;(println "data at PC:" (aget (memory) (PC)))
439 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
441 ;;(println "one tick")
442 (tick)
443 ;;(println "PC after one tick:" (PC))
444 ;;(println "BC after one tick:" (BC))
445 ;;(println "data at PC:" (aget (memory) (PC)))
446 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
447 (tick)
448 (AF! 0xFFFF)
449 ;;(println "PC after two ticks:" (PC))
450 ;;(println "BC after two ticks:" (BC))
451 ;;(println "data at PC:" (aget (memory) (PC)))
452 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
453 (tick)
454 ;;(println "PC after three ticks:" (PC))
455 ;;(println "BC after three ticks:" (BC))
456 ;;(println "data at PC:" (aget (memory) (PC)))
457 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
458 (tick)
459 ;;(println "PC after four ticks:" (PC))
460 ;;(println "BC after four ticks:" (BC))
461 ;;(println "data at PC:" (aget (memory) (PC)))
462 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
463 (tick)
464 ;;(println "PC after five ticks:" (PC))
465 ;;(println "BC after five ticks:" (BC))
466 ;;(println "data at PC:" (aget (memory) (PC)))
467 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
468 (print-inventory)
469 )]
471 (shutdown!)
472 final-state))
476 (defn test-opcodes-2
477 []
478 (set-inv-mem (read-state "mid-game")
479 [20 0x08 0x1D 0xD3 0x00 0x00 0x00
480 0x00 0x0 0xFF])
481 (print-inventory)
482 (println "3 ticks") (tick) (tick) (tick)
483 (println "PC before:" (PC))
484 (println "SP:" (SP))
485 (PC! (inc item-list-start))
486 (println "PC after setting:" (PC))
487 (println "SP:" (Integer/toBinaryString (SP)))
488 (println "data at PC:" (aget (memory) (PC)))
489 (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
490 (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
491 (println "one tick")
492 (tick)
493 (println "PC after one tick:" (PC))
494 (println "data at PC:" (aget (memory) (PC)))
495 (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
496 (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
497 (tick) (tick) (tick)
498 (println "PC aftter four tick:" (PC))
499 (println "data at PC:" (aget (memory) (PC)))
500 (println "data at 0xD31D:" (aget (memory) 0xD31D))
502 (print-inventory)
503 (shutdown!))