Mercurial > vba-clojure
changeset 128:203d64e16156
dylan added some code
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 17 Mar 2012 19:18:01 -0500 |
parents | 901ee6b648da |
children | 5e4feb77f2d8 |
files | clojure/com/aurellem/assembly.clj |
diffstat | 1 files changed, 186 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/assembly.clj Sat Mar 17 03:43:42 2012 -0500 1.2 +++ b/clojure/com/aurellem/assembly.clj Sat Mar 17 19:18:01 2012 -0500 1.3 @@ -66,6 +66,12 @@ 1.4 (defn A [state] 1.5 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8)) 1.6 1.7 +(defn B [state] 1.8 + (bit-shift-right (bit-and 0x0000FF00 (BC state)) 8)) 1.9 + 1.10 +(defn C [state] 1.11 + (bit-and 0xFF (BC state))) 1.12 + 1.13 (defn binary-str [num] 1.14 (format "%08d" 1.15 (Integer/parseInt 1.16 @@ -434,6 +440,19 @@ 1.17 0xD3 ; 1.18 ]) 1.19 1.20 + 1.21 +(defn print-pc [state] 1.22 + (println (format "PC: 0x%04X" (PC state))) 1.23 + state) 1.24 + 1.25 +(defn print-op [state] 1.26 + (println (format "OP: 0x%02X" (aget (memory state) (PC state)))) 1.27 + state) 1.28 + 1.29 +(defn d-tick 1.30 + ([state] 1.31 + (-> state print-pc print-op tick))) 1.32 + 1.33 (defn input-number [] 1.34 (-> (tick (mid-game)) 1.35 (IE! 0) ; disable interrupts 1.36 @@ -445,9 +464,106 @@ 1.37 (set-state! (input-number)) 1.38 (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) 1.39 1.40 +(defn d2 [] 1.41 + (-> 1.42 + (write-mem-dyl) 1.43 + (view-memory 0xD31F) 1.44 + step step step step step 1.45 + (view-memory 0xD31F))) 1.46 + 1.47 +(defn dylan [] 1.48 + (-> 1.49 + (write-mem-dyl) 1.50 + (tick) 1.51 + (tick) 1.52 + (tick) 1.53 + (tick) 1.54 + (tick) 1.55 + (tick) 1.56 + (tick) 1.57 + (tick) 1.58 + (tick) 1.59 + (tick) 1.60 + (tick) 1.61 + (tick) 1.62 + 1.63 + (tick) 1.64 + (tick) 1.65 + (tick) 1.66 + (tick) 1.67 + (tick) 1.68 + 1.69 + (d-tick) 1.70 + (view-register "A" A) 1.71 + (view-register "B" B) 1.72 + (view-register "C" C) 1.73 + 1.74 + )) 1.75 + 1.76 + 1.77 + 1.78 + 1.79 +(defn write-memory-assembly* [] 1.80 + [ 1.81 + 0x18 ;; D31D 1.82 + 0x02 1.83 + 0x00 ;; frame-count D31F 1.84 + 0x00 ;; v-blank-prev D320 1.85 + 1.86 + 0xFA ;; load modes into A 1.87 + 0x41 1.88 + 0xFF 1.89 + 1.90 + 0x47 1.91 + 1.92 + 0xCB 1.93 + 0x2F 1.94 + 0x2F 1.95 + 1.96 + 0xA0 1.97 + 0xE6 1.98 + 0x01 1.99 + 0x47 ;; now B contains (VB==1) 1.100 + 1.101 + 0xFA ;; load v-blank-prev 1.102 + 0x20 1.103 + 0xD3 1.104 + 1.105 + 0x2F 1.106 + 1.107 + 0xA0 1.108 + 0x4F ;; now C contains increment? 1.109 + 1.110 + 0xFA ;; load frame count 1.111 + 0x1F 1.112 + 0xD3 1.113 + 1.114 + 0x81 ;; add A+C->A 1.115 + 0xEA ;; spit A --> fc 1.116 + 0x1F 1.117 + 0xD3 1.118 + 1.119 + 0x78 ;; B->A 1.120 + 1.121 + 0xEA ;; spit A --> vbprev 1.122 + 0x20 1.123 + 0xD3 1.124 + 1.125 + 0xC3 ;D40F ; go back to beginning 1.126 + 0x1D ;D410 1.127 + 0xD3 ;D411 1.128 + ] 1.129 + ) 1.130 + 1.131 +(defn write-mem-dyl [] 1.132 + (-> (tick (mid-game)) 1.133 + (IE! 0) 1.134 + (inject-item-assembly (write-memory-assembly*)))) 1.135 + 1.136 + 1.137 + 1.138 (defn write-memory-assembly [] 1.139 - 1.140 - [ 1.141 + [ 1.142 ;; Main Timing Loop 1.143 ;; Constantly check for v-blank and Trigger main state machine on 1.144 ;; every transtion from v-blank to non-v-blank. 1.145 @@ -537,14 +653,6 @@ 1.146 0xD3 ; D34C 1.147 1.148 0x00 ; D34D ; glue :) 1.149 - 1.150 - 1.151 - ;;;;;;;;; BEGIN RLM DEBUG 1.152 - ;;0xC3 ;; jump to beginning 1.153 - ;;0x1D 1.154 - ;;0xD3 1.155 - ;;;;;;;;; END RLM DEBUG 1.156 - 1.157 1.158 0x18 ;D34E ; skip next 3 bytes 1.159 0x03 ;D34F 1.160 @@ -933,82 +1041,84 @@ 1.161 (step []) 1.162 (view-memory frame-count))) 1.163 1.164 -(defn test-mode-4 [] 1.165 - (-> 1.166 - (write-memory) 1.167 - (#(do (println "memory from 0xC00F to 0xC01F:" 1.168 - (subvec (vec (memory %)) 0xC00F 0xC01F)) %)) 1.169 - (view-memory current-mode) 1.170 - (step []) 1.171 - (step []) 1.172 - (step []) 1.173 - (#(do (println "after three steps") %)) 1.174 - (view-memory current-mode) 1.175 +(defn test-mode-4 1.176 + ([] (test-mode-4 (write-memory))) 1.177 + ([target-state] 1.178 + (-> 1.179 + target-state 1.180 + (#(do (println "memory from 0xC00F to 0xC01F:" 1.181 + (subvec (vec (memory %)) 0xC00F 0xC01F)) %)) 1.182 + (view-memory current-mode) 1.183 + (step []) 1.184 + (step []) 1.185 + (step []) 1.186 + (#(do (println "after three steps") %)) 1.187 + (view-memory current-mode) 1.188 1.189 - ;; Activate memory writing mode 1.190 - 1.191 - (#(do (println "step with [:a]") %)) 1.192 - (step [:a]) 1.193 - (view-memory current-mode) 1.194 - (view-memory bytes-to-write) 1.195 - (view-memory start-point-high) 1.196 - (view-memory start-point-low) 1.197 + ;; Activate memory writing mode 1.198 + 1.199 + (#(do (println "step with [:a]") %)) 1.200 + (step [:a]) 1.201 + (view-memory current-mode) 1.202 + (view-memory bytes-to-write) 1.203 + (view-memory start-point-high) 1.204 + (view-memory start-point-low) 1.205 1.206 - ;; Specify four bytes to be written 1.207 - 1.208 - (#(do (println "step with [:select]")%)) 1.209 - (step [:select]) 1.210 - (view-memory current-mode) 1.211 - (view-memory bytes-to-write) 1.212 - (view-memory start-point-high) 1.213 - (view-memory start-point-low) 1.214 + ;; Specify four bytes to be written 1.215 + 1.216 + (#(do (println "step with [:select]")%)) 1.217 + (step [:select]) 1.218 + (view-memory current-mode) 1.219 + (view-memory bytes-to-write) 1.220 + (view-memory start-point-high) 1.221 + (view-memory start-point-low) 1.222 1.223 - ;; Specify target memory address as 0xC00F 1.224 - 1.225 - (#(do (println "step with [:u :d]")%)) 1.226 - (step [:u :d]) 1.227 - (view-memory current-mode) 1.228 - (view-memory bytes-to-write) 1.229 - (view-memory start-point-high) 1.230 - (view-memory start-point-low) 1.231 + ;; Specify target memory address as 0xC00F 1.232 + 1.233 + (#(do (println "step with [:u :d]")%)) 1.234 + (step [:u :d]) 1.235 + (view-memory current-mode) 1.236 + (view-memory bytes-to-write) 1.237 + (view-memory start-point-high) 1.238 + (view-memory start-point-low) 1.239 1.240 - (#(do (println "step with [:a :b :start :select]")%)) 1.241 - (step [:a :b :start :select]) 1.242 - (view-memory current-mode) 1.243 - (view-memory bytes-to-write) 1.244 - (view-memory start-point-high) 1.245 - (view-memory start-point-low) 1.246 + (#(do (println "step with [:a :b :start :select]")%)) 1.247 + (step [:a :b :start :select]) 1.248 + (view-memory current-mode) 1.249 + (view-memory bytes-to-write) 1.250 + (view-memory start-point-high) 1.251 + (view-memory start-point-low) 1.252 1.253 - ;; Start reprogramming memory 1.254 + ;; Start reprogramming memory 1.255 1.256 - (#(do (println "step with [:a]")%)) 1.257 - (step [:a]) 1.258 - (view-memory current-mode) 1.259 - (view-memory bytes-written) 1.260 + (#(do (println "step with [:a]")%)) 1.261 + (step [:a]) 1.262 + (view-memory current-mode) 1.263 + (view-memory bytes-written) 1.264 1.265 - (#(do (println "step with [:b]")%)) 1.266 - (step [:b]) 1.267 - (view-memory current-mode) 1.268 - (view-memory bytes-written) 1.269 + (#(do (println "step with [:b]")%)) 1.270 + (step [:b]) 1.271 + (view-memory current-mode) 1.272 + (view-memory bytes-written) 1.273 1.274 - (#(do (println "step with [:a :b]")%)) 1.275 - (step [:a :b]) 1.276 - (view-memory current-mode) 1.277 - (view-memory bytes-written) 1.278 + (#(do (println "step with [:a :b]")%)) 1.279 + (step [:a :b]) 1.280 + (view-memory current-mode) 1.281 + (view-memory bytes-written) 1.282 1.283 - (#(do (println "step with [:select]")%)) 1.284 - (step [:select]) 1.285 - (view-memory current-mode) 1.286 - (view-memory bytes-written) 1.287 + (#(do (println "step with [:select]")%)) 1.288 + (step [:select]) 1.289 + (view-memory current-mode) 1.290 + (view-memory bytes-written) 1.291 1.292 - ;; Reprogramming done, program ready for more commands. 1.293 + ;; Reprogramming done, program ready for more commands. 1.294 1.295 - (#(do (println "step with []")%)) 1.296 - (step []) 1.297 - (view-memory current-mode) 1.298 - (view-memory bytes-written) 1.299 - 1.300 - (#(do (println "memory from 0xC00F to 0xC01F:" 1.301 - (subvec (vec (memory %)) 0xC00F 0xC01F)) %)))) 1.302 + (#(do (println "step with []")%)) 1.303 + (step []) 1.304 + (view-memory current-mode) 1.305 + (view-memory bytes-written) 1.306 + 1.307 + (#(do (println "memory from 0xC00F to 0xC01F:" 1.308 + (subvec (vec (memory %)) 0xC00F 0xC01F)) %))))) 1.309 1.310