Mercurial > vba-clojure
view clojure/com/aurellem/gb_driver.clj @ 71:39928bf4622d
refactored
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 08 Mar 2012 02:47:09 -0600 |
parents | ff6f1acae59e |
children | 8a895ed4c0f9 |
line wrap: on
line source
1 (ns com.aurellem.gb-driver2 (:import com.aurellem.gb.Gb)3 (:import java.io.File)4 (:import (java.nio IntBuffer ByteOrder)))6 (Gb/loadVBA)8 (def yellow-rom-image9 (File. "/home/r/proj/pokemon-escape/roms/yellow.gbc"))11 (def yellow-save-file12 (File. "/home/r/proj/pokemon-escape/roms/yellow.sav"))14 (defn vba-init []15 (.delete yellow-save-file)16 (Gb/startEmulator (.getCanonicalPath yellow-rom-image)))18 (defn shutdown [] (Gb/shutdown))20 (defn reset [] (shutdown) (vba-init))22 (defn cpu-data [size arr-fn]23 (let [store (int-array size)]24 (fn []25 (arr-fn store)26 store)))28 (def ram29 (cpu-data (Gb/getRAMSize) #(Gb/getRAM %)))31 (def rom32 (cpu-data (Gb/getROMSize) #(Gb/getROM %)))34 (def working-ram35 (cpu-data Gb/WRAM_SIZE #(Gb/getWRAM %)))37 (def video-ram38 (cpu-data Gb/VRAM_SIZE #(Gb/getVRAM %)))40 (def registers41 (cpu-data Gb/NUM_REGISTERS #(Gb/getRegisters %)))43 (def button-code44 {;; main buttons45 :a 0x000146 :b 0x000248 ;; directional pad49 :r 0x001050 :l 0x002051 :u 0x004052 :d 0x008054 ;; meta buttons55 :select 0x000456 :start 0x000858 ;; hard reset -- not really a button59 :reset 0x0800})61 (defn button-mask [buttons]62 (reduce bit-or 0x0000 (map button-code buttons)))64 (defn buttons [mask]65 (loop [buttons []66 masks (seq button-code)]67 (if (empty? masks) buttons68 (let [[button value] (first masks)]69 (if (not= 0x0000 (bit-and value mask))70 (recur (conj buttons button) (rest masks))71 (recur buttons (rest masks)))))))73 (defn step74 ([] (Gb/step))75 ([mask-or-buttons]76 (if (number? mask-or-buttons)77 (Gb/step mask-or-buttons)78 (Gb/step (button-mask mask-or-buttons)))))