Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/util.clj @ 145:412ca096a9ba
major refactoring complete.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 19 Mar 2012 21:23:46 -0500 |
parents | |
children | 3a3bb2197b7f |
comparison
equal
deleted
inserted
replaced
144:ec477931f077 | 145:412ca096a9ba |
---|---|
1 (ns com.aurellem.gb.util | |
2 (:use (com.aurellem.gb gb-driver vbm)) | |
3 (:import [com.aurellem.gb.gb_driver SaveState])) | |
4 | |
5 | |
6 (defn A [state] | |
7 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8)) | |
8 | |
9 (defn B [state] | |
10 (bit-shift-right (bit-and 0x0000FF00 (BC state)) 8)) | |
11 | |
12 (defn D [state] | |
13 (bit-shift-right (bit-and 0x0000FF00 (DE state)) 8)) | |
14 | |
15 (defn H [state] | |
16 (bit-shift-right (bit-and 0x0000FF00 (HL state)) 8)) | |
17 | |
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))) | |
26 | |
27 (defn binary-str [num] | |
28 (format "%08d" | |
29 (Integer/parseInt | |
30 (Integer/toBinaryString num) 10))) | |
31 | |
32 (defn view-register [state name reg-fn] | |
33 (println (format "%s: %s" name | |
34 (binary-str (reg-fn state)))) | |
35 state) | |
36 | |
37 (defn view-memory [state mem] | |
38 (println (format "mem 0x%04X = %s" mem | |
39 (binary-str (aget (memory state) mem)))) | |
40 state) | |
41 | |
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) | |
49 | |
50 (defn print-pc [state] | |
51 (println (format "PC: 0x%04X" (PC state))) | |
52 state) | |
53 | |
54 (defn print-op [state] | |
55 (println (format "OP: 0x%02X" (aget (memory state) (PC state)))) | |
56 state) | |
57 | |
58 (defn d-tick | |
59 ([state] | |
60 (-> state print-pc print-op tick))) | |
61 | |
62 (defn print-interrupt | |
63 [^SaveState state] | |
64 (println (format "IE: %d" (IE state))) | |
65 state) | |
66 | |
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))) | |
76 | |
77 (defn set-memory-range | |
78 ([state start values] | |
79 (set-state! state) | |
80 (let [mem (memory state)] | |
81 | |
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))) | |
91 | |
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))))) | |
98 | |
99 (defn mid-game [] | |
100 (read-state "mid-game")) |