Mercurial > vba-clojure
comparison clojure/com/aurellem/gb_driver.clj @ 100:2090bcb78f44
created functions to get and set register values
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 12 Mar 2012 12:37:04 -0500 |
parents | 9fad96094950 |
children | 37711ff4a7bc |
comparison
equal
deleted
inserted
replaced
99:9fad96094950 | 100:2090bcb78f44 |
---|---|
112 (SaveState. (inc (:frame state))(Gb/saveState)))) | 112 (SaveState. (inc (:frame state))(Gb/saveState)))) |
113 ([^SaveState state] | 113 ([^SaveState state] |
114 (step state [:listen])) | 114 (step state [:listen])) |
115 ([] (step (if @current-state @current-state (root))))) | 115 ([] (step (if @current-state @current-state (root))))) |
116 | 116 |
117 (defn tick | |
118 ([] (tick @current-state)) | |
119 ([state] | |
120 (set-state! state) | |
121 (Gb/tick) | |
122 (update-state))) | |
123 | |
117 (defn move | 124 (defn move |
118 [^Move move buttons] | 125 [^Move move buttons] |
119 (Move. (step (:state move) buttons) buttons)) | 126 (Move. (step (:state move) buttons) buttons)) |
120 | 127 |
121 (defn play | 128 (defn play |
140 (fn get-data | 147 (fn get-data |
141 ([] (get-data @current-state)) | 148 ([] (get-data @current-state)) |
142 ([state] | 149 ([state] |
143 (set-state! state) (arr-fn store) store)))) | 150 (set-state! state) (arr-fn store) store)))) |
144 | 151 |
152 (defn write-cpu-data [size store-fn] | |
153 (fn [new-data] | |
154 (let [store (int-array new-data)] | |
155 (assert (= size (count new-data))) | |
156 (store-fn store)))) | |
157 | |
145 (def memory | 158 (def memory |
146 (cpu-data Gb/GB_MEMORY #(Gb/getMemory %))) | 159 (cpu-data Gb/GB_MEMORY #(Gb/getMemory %))) |
147 | 160 |
148 (def ram | 161 (def ram |
149 (cpu-data Gb/RAM_SIZE #(Gb/getRAM %))) | 162 (cpu-data Gb/RAM_SIZE #(Gb/getRAM %))) |
158 (cpu-data Gb/VRAM_SIZE #(Gb/getVRAM %))) | 171 (cpu-data Gb/VRAM_SIZE #(Gb/getVRAM %))) |
159 | 172 |
160 (def registers | 173 (def registers |
161 (cpu-data Gb/NUM_REGISTERS #(Gb/getRegisters %))) | 174 (cpu-data Gb/NUM_REGISTERS #(Gb/getRegisters %))) |
162 | 175 |
163 | 176 (def write-memory! |
164 (defn write-memory! [new-memory] | 177 (write-cpu-data Gb/GB_MEMORY #(Gb/writeMemory %))) |
165 (let [store (int-array new-memory)] | 178 |
166 (assert (= Gb/GB_MEMORY) (count new-memory)) | 179 (def write-registers! |
167 (Gb/writeMemory new-memory))) | 180 (write-cpu-data Gb/NUM_REGISTERS #(Gb/writeRegisters %))) |
181 | |
182 ;; (defn write-memory! [new-memory] | |
183 ;; (let [store (int-array new-memory)] | |
184 ;; (assert (= Gb/GB_MEMORY) (count new-memory)) | |
185 ;; (Gb/writeMemory new-memory))) | |
168 | 186 |
169 | 187 |
170 ;; TODO add register names | 188 ;; TODO add register names |
171 | 189 |
172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
173 | 191 |
174 (defn AF [state] | 192 (defmacro gen-get-set-register [name index] |
175 (nth (registers state) 2)) | 193 (let [name-bang (symbol (str name "!"))] |
176 | 194 `(do |
177 (defn BC [state] | 195 (defn ~name |
178 (nth (registers state) 3)) | 196 ~(str "Retrieve the " name " register from state, or " |
179 | 197 "from @current-state if state is absent.") |
180 (defn DE [state] | 198 ([state#] |
181 (nth (registers state) 4)) | 199 (nth (registers state#) ~index)) |
182 | 200 ([] |
201 (~name @current-state))) | |
202 (defn ~name-bang | |
203 ~(str "Set the " name " register for state, or " | |
204 "for @current-state if state is absent.") | |
205 ([state# new-register#] | |
206 (set-state! state#) | |
207 (let [registers# (registers state#)] | |
208 (aset registers# ~index new-register#) | |
209 (Gb/writeRegisters registers#) | |
210 (update-state))) | |
211 ([new-register#] | |
212 (~name-bang @current-state new-register#)))))) | |
213 | |
214 | |
215 | |
216 (gen-get-set-register PC 0) | |
217 (gen-get-set-register SP 1) | |
218 (gen-get-set-register AF 2) | |
219 (gen-get-set-register BC 3) | |
220 (gen-get-set-register DE 4) | |
221 (gen-get-set-register HL 5) | |
222 (gen-get-set-register IFF 6) | |
223 | |
224 | |
225 | |
183 ;;;;;;;;;;;;;;; | 226 ;;;;;;;;;;;;;;; |
184 | 227 |
185 (defmacro defn-memo | 228 (defmacro defn-memo |
186 [& forms] | 229 [& forms] |
187 (let [fun-name (first forms)] | 230 (let [fun-name (first forms)] |