annotate clojure/com/aurellem/gb_driver.clj @ 66:43d4fb2a6fc2

resets now work correctly
author Robert McIntyre <rlm@mit.edu>
date Wed, 07 Mar 2012 23:23:15 -0600
parents 60c768964937
children 8cb500493ec2
rev   line source
rlm@60 1 (ns com.aurellem.gb-driver
rlm@60 2 (:import com.aurellem.gb.Gb)
rlm@65 3 (:import java.io.File)
rlm@60 4 (:import (java.nio IntBuffer ByteOrder)))
rlm@48 5
rlm@66 6 (Gb/loadVBA)
rlm@65 7
rlm@65 8 (def yellow-rom-image
rlm@65 9 (File. "/home/r/proj/pokemon-escape/roms/yellow.gbc"))
rlm@65 10
rlm@62 11 (defn vba-init []
rlm@60 12 (future
rlm@65 13 (Gb/startEmulator (.getCanonicalPath yellow-rom-image))))
rlm@60 14
rlm@64 15 (defn cpu-data [size arr-fn]
rlm@64 16 (let [store (int-array size)]
rlm@64 17 (fn []
rlm@64 18 (arr-fn store)
rlm@64 19 store)))
rlm@60 20
rlm@64 21 (def ram
rlm@64 22 (cpu-data (Gb/getRAMSize) #(Gb/getRAM %)))
rlm@61 23
rlm@64 24 (def rom
rlm@64 25 (cpu-data (Gb/getROMSize) #(Gb/getROM %)))
rlm@61 26
rlm@64 27 (def working-ram
rlm@64 28 (cpu-data Gb/WRAM_SIZE #(Gb/getWRAM %)))
rlm@62 29
rlm@64 30 (def video-ram
rlm@64 31 (cpu-data Gb/VRAM_SIZE #(Gb/getVRAM %)))
rlm@64 32
rlm@64 33 (def registers
rlm@64 34 (cpu-data Gb/NUM_REGISTERS #(Gb/getRegisters %)))
rlm@64 35
rlm@64 36
rlm@65 37 (def key-mask
rlm@65 38 {:a 0x0001
rlm@65 39 :b 0x0002
rlm@65 40
rlm@65 41 :l 0x0020
rlm@65 42 :r 0x0010
rlm@65 43 :u 0x0040
rlm@65 44 :d 0x0080
rlm@65 45
rlm@66 46 :0 0x0000
rlm@66 47
rlm@65 48 :select 0x0004
rlm@65 49 :start 0x0008
rlm@65 50 :restart 0x0800})
rlm@65 51
rlm@65 52 (defn keycode [& keys]
rlm@65 53 (reduce bit-or (map key-mask keys)))
rlm@65 54
rlm@65 55 (defn step
rlm@65 56 ([] (Gb/step))
rlm@65 57 ([& keys] (Gb/step (apply keycode keys))))
rlm@65 58
rlm@65 59
rlm@65 60
rlm@65 61