Mercurial > vba-clojure
view clojure/com/aurellem/gb/util.clj @ 176:95b2758dd517
wrote functions to read and write pokemon DV values and status
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 21 Mar 2012 22:13:43 -0500 |
parents | 5ce074824fac |
children | fd549c8f42ae |
line wrap: on
line source
1 (ns com.aurellem.gb.util2 (:use (com.aurellem.gb gb-driver vbm))3 (:import [com.aurellem.gb.gb_driver SaveState]))6 (defn A [state]7 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8))9 (defn B [state]10 (bit-shift-right (bit-and 0x0000FF00 (BC state)) 8))12 (defn D [state]13 (bit-shift-right (bit-and 0x0000FF00 (DE state)) 8))15 (defn H [state]16 (bit-shift-right (bit-and 0x0000FF00 (HL state)) 8))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)))27 (defn binary-str [num]28 (format "%08d"29 (Integer/parseInt30 (Integer/toBinaryString num) 10)))32 (defn view-register [state name reg-fn]33 (println (format "%s: %s" name34 (binary-str (reg-fn state))))35 state)37 (defn view-memory38 ([^SaveState state mem]39 (println (format "mem 0x%04X = %s" mem40 (binary-str (aget (memory state) mem))))41 state)42 ([mem]43 (view-memory @current-state mem)))45 (defn print-listing46 ([^SaveState state begin end]47 (dorun (map48 (fn [opcode line]49 (println (format "0x%04X: 0x%02X" line opcode)))50 (subvec (vec (memory state)) begin end)51 (range begin end)))52 state)53 ([begin end]54 (print-listing @current-state begin end)))56 (defn print-pc57 ([^SaveState state]58 (println (format "PC: 0x%04X" (PC state)))59 state)60 ([] (print-pc @current-state)))62 (defn print-op63 ([^SaveState state]64 (println (format "OP: 0x%02X" (aget (memory state) (PC state))))65 state)66 ([] (print-op @current-state)))68 (defn d-tick69 ([state]70 (-> state print-pc print-op tick)))72 (defn print-interrupt73 [^SaveState state]74 (println (format "IE: %d" (IE state)))75 state)77 (defn set-memory78 ([state location value]79 (set-state! state)80 (let [mem (memory state)]81 (aset mem location value)82 (write-memory! mem)83 (update-state)))84 ([location value]85 (set-memory @current-state location value)))87 (defn set-memory-range88 ([state start values]89 (set-state! state)90 (let [mem (memory state)]92 (dorun (map (fn [index val]93 (aset mem index val))94 (range start95 (+ start (count values))) values))96 (write-memory! mem)97 (update-state)))98 ([start values]99 (set-memory-range100 @current-state start values)))102 (defn common-differences [& seqs]103 (let [backbone (range (count (first seqs)))]104 (filter105 (comp (partial apply distinct?) second)106 (zipmap backbone107 (apply (partial map list) seqs)))))109 (defn mid-game []110 (read-state "mid-game"))