comparison clojure/com/aurellem/gb_driver.clj @ 101:37711ff4a7bc

filled out functions for the rest of the registers.
author Robert McIntyre <rlm@mit.edu>
date Mon, 12 Mar 2012 12:41:55 -0500
parents 2090bcb78f44
children d2e00ea31508
comparison
equal deleted inserted replaced
100:2090bcb78f44 101:37711ff4a7bc
177 (write-cpu-data Gb/GB_MEMORY #(Gb/writeMemory %))) 177 (write-cpu-data Gb/GB_MEMORY #(Gb/writeMemory %)))
178 178
179 (def write-registers! 179 (def write-registers!
180 (write-cpu-data Gb/NUM_REGISTERS #(Gb/writeRegisters %))) 180 (write-cpu-data Gb/NUM_REGISTERS #(Gb/writeRegisters %)))
181 181
182 ;; (defn write-memory! [new-memory] 182 ;;;;; Registers ;;;;;;;;;;;;;;;;;;;;;;;;;;;
183 ;; (let [store (int-array new-memory)]
184 ;; (assert (= Gb/GB_MEMORY) (count new-memory))
185 ;; (Gb/writeMemory new-memory)))
186
187
188 ;; TODO add register names
189
190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
191 183
192 (defmacro gen-get-set-register [name index] 184 (defmacro gen-get-set-register [name index]
193 (let [name-bang (symbol (str name "!"))] 185 (let [name-bang (symbol (str name "!"))]
194 `(do 186 `(do
195 (defn ~name 187 (defn ~name
208 (aset registers# ~index new-register#) 200 (aset registers# ~index new-register#)
209 (Gb/writeRegisters registers#) 201 (Gb/writeRegisters registers#)
210 (update-state))) 202 (update-state)))
211 ([new-register#] 203 ([new-register#]
212 (~name-bang @current-state new-register#)))))) 204 (~name-bang @current-state new-register#))))))
213 205
214 206 ;; 16 bit registers
215
216 (gen-get-set-register PC 0) 207 (gen-get-set-register PC 0)
217 (gen-get-set-register SP 1) 208 (gen-get-set-register SP 1)
218 (gen-get-set-register AF 2) 209 (gen-get-set-register AF 2)
219 (gen-get-set-register BC 3) 210 (gen-get-set-register BC 3)
220 (gen-get-set-register DE 4) 211 (gen-get-set-register DE 4)
221 (gen-get-set-register HL 5) 212 (gen-get-set-register HL 5)
222 (gen-get-set-register IFF 6) 213 (gen-get-set-register IFF 6)
223 214
224 215 ;; 8 bit registers
225 216 (gen-get-set-register DIV 7)
217 (gen-get-set-register TIMA 8)
218 (gen-get-set-register TMA 9)
219 (gen-get-set-register IF 11)
220 (gen-get-set-register LCDC 12)
221 (gen-get-set-register STAT 13)
222 (gen-get-set-register SCY 14)
223 (gen-get-set-register SCX 15)
224 (gen-get-set-register LY 16)
225 (gen-get-set-register DMA 18)
226 (gen-get-set-register WY 19)
227 (gen-get-set-register WX 20)
228 (gen-get-set-register VBK 21)
229 (gen-get-set-register HDMA1 22)
230 (gen-get-set-register HDMA2 23)
231 (gen-get-set-register HDMA3 24)
232 (gen-get-set-register HDMA4 25)
233 (gen-get-set-register HDMA5 26)
234 (gen-get-set-register SVBK 27)
235 (gen-get-set-register IE 28)
236
226 ;;;;;;;;;;;;;;; 237 ;;;;;;;;;;;;;;;
227 238
228 (defmacro defn-memo 239 (defmacro defn-memo
229 [& forms] 240 [& forms]
230 (let [fun-name (first forms)] 241 (let [fun-name (first forms)]