diff clojure/com/aurellem/assembly.clj @ 106:3a60bb14a64a

better functional assembly interface; removed frame numbers from SaveStates
author Robert McIntyre <rlm@mit.edu>
date Wed, 14 Mar 2012 21:37:37 -0500
parents 2f8089eacab9
children ad96e9464d6a
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/assembly.clj	Tue Mar 13 14:40:01 2012 -0500
     1.2 +++ b/clojure/com/aurellem/assembly.clj	Wed Mar 14 21:37:37 2012 -0500
     1.3 @@ -2,14 +2,13 @@
     1.4    (:use (com.aurellem gb-driver vbm title items))
     1.5    (:import [com.aurellem.gb_driver SaveState]))
     1.6  
     1.7 -
     1.8 -
     1.9 +(defn mid-game []
    1.10 +  (read-state "mid-game"))
    1.11  
    1.12  (defn inject-assembly
    1.13    [^SaveState state
    1.14     program-counter registers
    1.15     assembly-code]
    1.16 -  (set-state! state)
    1.17    (let [scratch-memory (memory state)]
    1.18      ;; inject assembly code
    1.19      (dorun (map (fn [index val]
    1.20 @@ -17,12 +16,11 @@
    1.21                  (range program-counter
    1.22                         (+ program-counter (count assembly-code)))
    1.23                  assembly-code))
    1.24 -    (write-memory! scratch-memory)
    1.25 -    (set-state! (update-state))
    1.26 -    (write-registers! registers)
    1.27 -    (set-state! (update-state))
    1.28 -    (PC! program-counter)
    1.29 -    (update-state)))
    1.30 +    (-> state
    1.31 +        (write-memory! scratch-memory)
    1.32 +        (write-registers! registers)
    1.33 +        (PC! program-counter))))
    1.34 +        
    1.35  
    1.36  (defn inject-item-assembly
    1.37    ([^SaveState state assembly-code]
    1.38 @@ -34,19 +32,17 @@
    1.39  
    1.40  (defn info
    1.41    ([^SaveState state]
    1.42 -     (set-state! state)
    1.43 -     (println "PC: " (PC))
    1.44 -     (println "Instruction:" (format "0x%02X" (aget (memory state) (PC))))
    1.45 +     (println "PC: " (PC state))
    1.46 +     (println "Instruction:"
    1.47 +              (format "0x%02X" (aget (memory state) (PC state))))
    1.48       state))    
    1.49  
    1.50 -(defn irony [] (read-state 578544))
    1.51 -
    1.52  (defn run-assembly
    1.53    ([info-fn assembly n]
    1.54       (let [final-state
    1.55             (reduce (fn [state _]
    1.56                       (tick (info-fn state)))
    1.57 -                   (inject-item-assembly (tick (tick (tick (irony)))) assembly)
    1.58 +                   (inject-item-assembly (tick (tick (tick (mid-game)))) assembly)
    1.59                     (range n))]
    1.60         (shutdown!)
    1.61         final-state))