changeset 183:5e34473ac774

merged assembly
author Dylan Holmes <ocsenave@gmail.com>
date Wed, 21 Mar 2012 23:19:01 -0500
parents d63886d63b2f
children d585b91de06c
files clojure/com/aurellem/gb/assembly.clj
diffstat 1 files changed, 69 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/assembly.clj	Wed Mar 21 23:02:45 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/assembly.clj	Wed Mar 21 23:19:01 2012 -0500
     1.3 @@ -406,6 +406,11 @@
     1.4    (set-state! (input-number)) 
     1.5    (dotimes [_ 90000] (step (view-memory @current-state 0xD352))))
     1.6  
     1.7 +
     1.8 +
     1.9 +
    1.10 +
    1.11 +
    1.12  (defn write-memory-assembly*
    1.13    "A program for altering in-game memory by pressing buttons."
    1.14    []
    1.15 @@ -419,22 +424,25 @@
    1.16     0xF1 ;; pop AF (vblank prev) [D320]
    1.17  
    1.18     0x2F ;; invert A
    1.19 -   0x47 ;; A -> B
    1.20 +   0x4F ;; A -> C
    1.21     
    1.22     0xF0 ;; copy STAT into A
    1.23     0x41
    1.24  
    1.25 -   0xCB ;; swap A nybbles; now A_0 is (VB==1).
    1.26 -   0x37
    1.27 -
    1.28 +   0x47 ;; A->B
    1.29 +   0x1F ;; rotate A right
    1.30 +   0x2F ;; complement A
    1.31 +   0xA0 ;; A & B --> A
    1.32 +   
    1.33     0xF5 ;; push AF (vbprev)
    1.34     
    1.35 -   0xA0 ;; A & B --> A. Now A_0 contains "increment?"
    1.36 +   0xA1 ;; A & C --> A. Now A_0 contains "increment?"
    1.37     
    1.38     0xCB ;; test A_0. this result will be used twice.
    1.39     0x47
    1.40 +   
    1.41     0x28 ;; end frame (JUMP) if A_0 = 0.  
    1.42 -   0x00 ;; TODO: set jump length
    1.43 +   0xF3 ;; TODO: set jump length
    1.44     
    1.45     ;; -------- GET BUTTON INPUT
    1.46     
    1.47 @@ -470,8 +478,8 @@
    1.48  
    1.49     0xBF ;; compare(A,A) sets Z=0
    1.50     
    1.51 -   0x18 ;; JUMP back to "load A into [FF00]" [20 steps?]
    1.52 -   0xED
    1.53 +   0x18 ;; JUMP back to "load A into [FF00]"
    1.54 +   0xEF
    1.55  
    1.56  
    1.57     ;; ------ TAKE ACTION BASED ON USER INPUT
    1.58 @@ -556,6 +564,59 @@
    1.59        (IE! 0)
    1.60        (inject-item-assembly (write-memory-assembly*))))
    1.61  
    1.62 +(defn ntick [s n]
    1.63 +  (if (zero? n) s
    1.64 +      (do
    1.65 +        (set-state! s)
    1.66 +        (dorun (dotimes [_ n] 
    1.67 +                 (com.aurellem.gb.Gb/tick)))
    1.68 +        (update-state))))
    1.69 +
    1.70 +
    1.71 +(defn find-frame-shift [state]
    1.72 +  ;;(restart!)
    1.73 +  (set-state! state)
    1.74 +  (loop [n 0]
    1.75 +    (if (>= (first (registers)) 0xD32D)
    1.76 +      (do (println n)
    1.77 +      (update-state))
    1.78 +      (do
    1.79 +        (com.aurellem.gb.Gb/tick)
    1.80 +        (recur (inc n) )))))
    1.81 +  
    1.82 +(defn demo-assembly [n]
    1.83 +  (repeat n 0x00))
    1.84 +
    1.85 +
    1.86 +(defn find-frame-shift* [state]
    1.87 +  (set-state! state)
    1.88 +  (loop []
    1.89 +    (com.aurellem.gb.Gb/tick)
    1.90 +    ;;(println (first (registers)))
    1.91 +    (if (>= (first (registers)) 0xD32D)
    1.92 +      (update-state)
    1.93 +      (recur))))
    1.94 +
    1.95 +
    1.96 +(defn dylan**
    1.97 +  ([k]
    1.98 +  (->
    1.99 +   (tick (mid-game))
   1.100 +   (inject-item-assembly(write-memory-assembly*))
   1.101 +   ;;(find-frame-shift)
   1.102 +   (ntick k)
   1.103 +   (d-tick)
   1.104 +   (view-register "A" A)
   1.105 +   (view-register "B" B)
   1.106 +   (view-register "D" D)
   1.107 +   (view-register "E" E)
   1.108 +   (view-register "F" F)
   1.109 +   (#(do (println) %))
   1.110 +   ))
   1.111 +  ([] (dylan** 0)))
   1.112 +   
   1.113 +   
   1.114 +
   1.115  
   1.116  (defn dylan* []
   1.117    (->