view clojure/com/aurellem/gb/util.clj @ 148:06426d25c65b

can now get/set pokemon OT name
author Robert McIntyre <rlm@mit.edu>
date Mon, 19 Mar 2012 23:14:21 -0500
parents 412ca096a9ba
children 3a3bb2197b7f
line wrap: on
line source
1 (ns com.aurellem.gb.util
2 (:use (com.aurellem.gb gb-driver vbm))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
6 (defn A [state]
7 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8))
9 (defn B [state]
10 (bit-shift-right (bit-and 0x0000FF00 (BC state)) 8))
12 (defn D [state]
13 (bit-shift-right (bit-and 0x0000FF00 (DE state)) 8))
15 (defn H [state]
16 (bit-shift-right (bit-and 0x0000FF00 (HL state)) 8))
18 (defn C [state]
19 (bit-and 0xFF (BC state)))
20 (defn F [state]
21 (bit-and 0xFF (AF state)))
22 (defn E [state]
23 (bit-and 0xFF (DE state)))
24 (defn L [state]
25 (bit-and 0xFF (HL state)))
27 (defn binary-str [num]
28 (format "%08d"
29 (Integer/parseInt
30 (Integer/toBinaryString num) 10)))
32 (defn view-register [state name reg-fn]
33 (println (format "%s: %s" name
34 (binary-str (reg-fn state))))
35 state)
37 (defn view-memory [state mem]
38 (println (format "mem 0x%04X = %s" mem
39 (binary-str (aget (memory state) mem))))
40 state)
42 (defn print-listing [state begin end]
43 (dorun (map
44 (fn [opcode line]
45 (println (format "0x%04X: 0x%02X" line opcode)))
46 (subvec (vec (memory state)) begin end)
47 (range begin end)))
48 state)
50 (defn print-pc [state]
51 (println (format "PC: 0x%04X" (PC state)))
52 state)
54 (defn print-op [state]
55 (println (format "OP: 0x%02X" (aget (memory state) (PC state))))
56 state)
58 (defn d-tick
59 ([state]
60 (-> state print-pc print-op tick)))
62 (defn print-interrupt
63 [^SaveState state]
64 (println (format "IE: %d" (IE state)))
65 state)
67 (defn set-memory
68 ([state location value]
69 (set-state! state)
70 (let [mem (memory state)]
71 (aset mem location value)
72 (write-memory! mem)
73 (update-state)))
74 ([location value]
75 (set-memory @current-state location value)))
77 (defn set-memory-range
78 ([state start values]
79 (set-state! state)
80 (let [mem (memory state)]
82 (dorun (map (fn [index val]
83 (aset mem index val))
84 (range start
85 (+ start (count values))) values))
86 (write-memory! mem)
87 (update-state)))
88 ([start values]
89 (set-memory-range
90 @current-state start values)))
92 (defn common-differences [& seqs]
93 (let [backbone (range (count (first seqs)))]
94 (filter
95 (comp (partial apply distinct?) second)
96 (zipmap backbone
97 (apply (partial map list) seqs)))))
99 (defn mid-game []
100 (read-state "mid-game"))