changeset 139:74ec1ac044bb

write-memory-assembly* confirmed...stage one.
author Dylan Holmes <ocsenave@gmail.com>
date Mon, 19 Mar 2012 05:12:05 -0500
parents 2b69cbe8a5b9
children aa5b5927e5fe
files clojure/com/aurellem/assembly.clj
diffstat 1 files changed, 124 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/assembly.clj	Mon Mar 19 03:05:42 2012 -0500
     1.2 +++ b/clojure/com/aurellem/assembly.clj	Mon Mar 19 05:12:05 2012 -0500
     1.3 @@ -69,8 +69,24 @@
     1.4  (defn B [state]
     1.5    (bit-shift-right (bit-and 0x0000FF00 (BC state)) 8))
     1.6  
     1.7 +(defn D [state]
     1.8 +  (bit-shift-right (bit-and 0x0000FF00 (DE state)) 8))
     1.9 +
    1.10 +(defn H [state]
    1.11 +  (bit-shift-right (bit-and 0x0000FF00 (HL state)) 8))
    1.12 +
    1.13  (defn C [state]
    1.14    (bit-and 0xFF (BC state)))
    1.15 +(defn F [state]
    1.16 +  (bit-and 0xFF (AF state)))
    1.17 +(defn E [state]
    1.18 +  (bit-and 0xFF (DE state)))
    1.19 +(defn L [state]
    1.20 +  (bit-and 0xFF (HL state)))
    1.21 +
    1.22 +
    1.23 +
    1.24 +
    1.25  
    1.26  (defn binary-str [num]
    1.27    (format "%08d"
    1.28 @@ -532,7 +548,7 @@
    1.29     0x20   ; JUMP ahead to button input if nonzero
    1.30     0x02
    1.31     0x18   ; JUMP  back to frame metronome (D31F)
    1.32 -   0xE6   ; todo: verify this jump length  
    1.33 +   0xE7
    1.34     
    1.35     ;; -------- GET BUTTON INPUT
    1.36  
    1.37 @@ -573,12 +589,14 @@
    1.38  
    1.39     ;; ------ TAKE ACTION BASED ON USER INPUT
    1.40  
    1.41 +   ;; "input mode"
    1.42     ;; mode 0x00 : select mode
    1.43     ;; mode 0x08 : select bytes-to-write
    1.44     ;; mode 0x10 : select hi-bit
    1.45     ;; mode 0x18 : select lo-bit
    1.46  
    1.47 -   ;; mode 0xF0 : write bytes
    1.48 +   ;; "output mode"
    1.49 +   ;; mode 0x20 : write bytes
    1.50     ;; mode 0xFF : jump PC
    1.51  
    1.52  
    1.53 @@ -594,8 +612,8 @@
    1.54     0x47 ; A->B ;; now B contains the pressed keys
    1.55     0x7B ; E->A ;; now A contains the count.
    1.56  
    1.57 -   0xCB ; test bit 4 of D (are we in o/p mode?)
    1.58 -   0x26
    1.59 +   0xCB ; test bit 5 of D (are we in o/p mode?)
    1.60 +   0x6A
    1.61     0x28 ; if test == 0, skip this o/p section
    1.62     0x13 ; JUMP
    1.63     
    1.64 @@ -610,7 +628,7 @@
    1.65     ;; output mode II: writing bytes
    1.66     0xFE ; A compare 0. finished writing?
    1.67     0x00
    1.68 -   0x28 ; if we are not finished, skip cleanup
    1.69 +   0x20 ; if we are not finished, skip cleanup
    1.70     0x04 ; JUMP
    1.71  
    1.72     ;; CLEANUP
    1.73 @@ -624,17 +642,20 @@
    1.74  
    1.75     
    1.76     ;; continue writing bytes
    1.77 -   0x1D ;; decrement E, the number of bytes to write
    1.78 +   0x1D ;; decrement E, the number of bytes to write [D363]
    1.79     0x78 ;; B->A; now A contains the pressed keys
    1.80     0x77 ;; copy A to (HL)
    1.81     0x23 ;; increment HL
    1.82 -   0x18 ;; end frame.
    1.83 -   0xC2 ;; TODO: set skip length backwards
    1.84 +   0x18 ;; end frame. [goto D31F]
    1.85 +   0xB6 ;; TODO: set skip length backwards
    1.86  
    1.87  
    1.88     ;; ---- end of o/p section
    1.89     
    1.90 -   ;; get data
    1.91 +   ;; i/p mode
    1.92 +   ;; adhere to the mode discipline:
    1.93 +   ;; D must be one of 0x00 0x08 0x10 0x18.
    1.94 +
    1.95     0x3E ;; load the constant 57 into A. [D369]
    1.96     0x57
    1.97     0x82 ;; add the mode to A
    1.98 @@ -645,13 +666,14 @@
    1.99     0x3E ;; load the constant 8 into A
   1.100     0x08
   1.101     0x82 ;; add the mode to A
   1.102 +   
   1.103     0x57 ;; store the incremented mode into D
   1.104     0x78 ;; B->A; now A contains the pressed keys
   1.105     
   1.106     0x00 ;; var: thing to execute [D374]
   1.107  
   1.108     0x18 ;; end frame
   1.109 -   0xA8 ;; JUMP
   1.110 +   0xA8 ;; TODO: set jump correctly
   1.111     ]
   1.112    )
   1.113  
   1.114 @@ -1289,6 +1311,98 @@
   1.115     (step [])
   1.116     (view-memory frame-count)))
   1.117  
   1.118 +
   1.119 +
   1.120 +(defn dylan-test-mode
   1.121 +  ([] (dylan-test-mode (write-mem-dyl)))
   1.122 +  ([target-state]
   1.123 +     (let [
   1.124 +           v-blank-prev 54046
   1.125 +           btn-register 65280
   1.126 +           eggs 0xD374
   1.127 +           ]
   1.128 +       
   1.129 +       (->
   1.130 +        target-state
   1.131 +        
   1.132 +        (tick)
   1.133 +        (tick)
   1.134 +        (tick)
   1.135 +        (tick);; jumps back to beginning
   1.136 +        
   1.137 +        (tick)
   1.138 +        (tick)
   1.139 +        (tick)
   1.140 +        (tick)
   1.141 +        (tick)
   1.142 +        (tick)
   1.143 +        (tick)
   1.144 +        (tick)
   1.145 +        (tick)
   1.146 +        (tick)
   1.147 +        (tick)
   1.148 +        (tick)
   1.149 +
   1.150 +               
   1.151 +        (tick)
   1.152 +        (tick)
   1.153 +        (tick)
   1.154 +        (tick)
   1.155 +        (tick)
   1.156 +        (tick)
   1.157 +        (tick)
   1.158 +        (tick)
   1.159 +        (tick)
   1.160 +        (tick)
   1.161 +        (tick)
   1.162 +        (tick)
   1.163 +        (tick)
   1.164 +        (tick)
   1.165 +        (tick)
   1.166 +        (tick)
   1.167 +        (tick)
   1.168 +        (tick)
   1.169 +        (tick)
   1.170 +        (tick)
   1.171 +        (tick) ;; just complemented A
   1.172 +
   1.173 +        (tick)
   1.174 +        (DE! 0x0800)
   1.175 +        (AF! 0xCF00) ;; change inputs @ A
   1.176 +        (tick)
   1.177 +        (tick)
   1.178 +        (tick)
   1.179 +        (tick)
   1.180 +        (tick)
   1.181 +
   1.182 +        ;;(view-memory eggs)
   1.183 +        (tick)
   1.184 +        (tick)
   1.185 +        ;;(view-memory eggs)
   1.186 +        (tick)
   1.187 +        (tick)
   1.188 +        (tick)
   1.189 +        (tick)
   1.190 +
   1.191 +        (d-tick)
   1.192 +
   1.193 +        
   1.194 +        ;;(view-memory btn-register) 
   1.195 +        (view-register "A" A)
   1.196 +        (view-register "B" B)
   1.197 +        
   1.198 +        ;;(view-register "C" C)
   1.199 +        (view-register "D" D)
   1.200 +        (view-register "E" E)
   1.201 +        (view-register "H" H)
   1.202 +        (view-register "L" L)
   1.203 +        ))))
   1.204 +  
   1.205 +
   1.206 +
   1.207 +
   1.208 +
   1.209 +
   1.210  (defn test-mode-4
   1.211    ([] (test-mode-4 (write-memory)))
   1.212    ([target-state]