# HG changeset patch # User Robert McIntyre # Date 1332029881 18000 # Node ID 203d64e161564507845edff0ee38b6a392be23a0 # Parent 901ee6b648da516259fee11ee9fd2c4ac3c21a54 dylan added some code diff -r 901ee6b648da -r 203d64e16156 clojure/com/aurellem/assembly.clj --- a/clojure/com/aurellem/assembly.clj Sat Mar 17 03:43:42 2012 -0500 +++ b/clojure/com/aurellem/assembly.clj Sat Mar 17 19:18:01 2012 -0500 @@ -66,6 +66,12 @@ (defn A [state] (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8)) +(defn B [state] + (bit-shift-right (bit-and 0x0000FF00 (BC state)) 8)) + +(defn C [state] + (bit-and 0xFF (BC state))) + (defn binary-str [num] (format "%08d" (Integer/parseInt @@ -434,6 +440,19 @@ 0xD3 ; ]) + +(defn print-pc [state] + (println (format "PC: 0x%04X" (PC state))) + state) + +(defn print-op [state] + (println (format "OP: 0x%02X" (aget (memory state) (PC state)))) + state) + +(defn d-tick + ([state] + (-> state print-pc print-op tick))) + (defn input-number [] (-> (tick (mid-game)) (IE! 0) ; disable interrupts @@ -445,9 +464,106 @@ (set-state! (input-number)) (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) +(defn d2 [] + (-> + (write-mem-dyl) + (view-memory 0xD31F) + step step step step step + (view-memory 0xD31F))) + +(defn dylan [] + (-> + (write-mem-dyl) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + + (tick) + (tick) + (tick) + (tick) + (tick) + + (d-tick) + (view-register "A" A) + (view-register "B" B) + (view-register "C" C) + + )) + + + + +(defn write-memory-assembly* [] + [ + 0x18 ;; D31D + 0x02 + 0x00 ;; frame-count D31F + 0x00 ;; v-blank-prev D320 + + 0xFA ;; load modes into A + 0x41 + 0xFF + + 0x47 + + 0xCB + 0x2F + 0x2F + + 0xA0 + 0xE6 + 0x01 + 0x47 ;; now B contains (VB==1) + + 0xFA ;; load v-blank-prev + 0x20 + 0xD3 + + 0x2F + + 0xA0 + 0x4F ;; now C contains increment? + + 0xFA ;; load frame count + 0x1F + 0xD3 + + 0x81 ;; add A+C->A + 0xEA ;; spit A --> fc + 0x1F + 0xD3 + + 0x78 ;; B->A + + 0xEA ;; spit A --> vbprev + 0x20 + 0xD3 + + 0xC3 ;D40F ; go back to beginning + 0x1D ;D410 + 0xD3 ;D411 + ] + ) + +(defn write-mem-dyl [] + (-> (tick (mid-game)) + (IE! 0) + (inject-item-assembly (write-memory-assembly*)))) + + + (defn write-memory-assembly [] - - [ + [ ;; Main Timing Loop ;; Constantly check for v-blank and Trigger main state machine on ;; every transtion from v-blank to non-v-blank. @@ -537,14 +653,6 @@ 0xD3 ; D34C 0x00 ; D34D ; glue :) - - - ;;;;;;;;; BEGIN RLM DEBUG - ;;0xC3 ;; jump to beginning - ;;0x1D - ;;0xD3 - ;;;;;;;;; END RLM DEBUG - 0x18 ;D34E ; skip next 3 bytes 0x03 ;D34F @@ -933,82 +1041,84 @@ (step []) (view-memory frame-count))) -(defn test-mode-4 [] - (-> - (write-memory) - (#(do (println "memory from 0xC00F to 0xC01F:" - (subvec (vec (memory %)) 0xC00F 0xC01F)) %)) - (view-memory current-mode) - (step []) - (step []) - (step []) - (#(do (println "after three steps") %)) - (view-memory current-mode) +(defn test-mode-4 + ([] (test-mode-4 (write-memory))) + ([target-state] + (-> + target-state + (#(do (println "memory from 0xC00F to 0xC01F:" + (subvec (vec (memory %)) 0xC00F 0xC01F)) %)) + (view-memory current-mode) + (step []) + (step []) + (step []) + (#(do (println "after three steps") %)) + (view-memory current-mode) - ;; Activate memory writing mode - - (#(do (println "step with [:a]") %)) - (step [:a]) - (view-memory current-mode) - (view-memory bytes-to-write) - (view-memory start-point-high) - (view-memory start-point-low) + ;; Activate memory writing mode + + (#(do (println "step with [:a]") %)) + (step [:a]) + (view-memory current-mode) + (view-memory bytes-to-write) + (view-memory start-point-high) + (view-memory start-point-low) - ;; Specify four bytes to be written - - (#(do (println "step with [:select]")%)) - (step [:select]) - (view-memory current-mode) - (view-memory bytes-to-write) - (view-memory start-point-high) - (view-memory start-point-low) + ;; Specify four bytes to be written + + (#(do (println "step with [:select]")%)) + (step [:select]) + (view-memory current-mode) + (view-memory bytes-to-write) + (view-memory start-point-high) + (view-memory start-point-low) - ;; Specify target memory address as 0xC00F - - (#(do (println "step with [:u :d]")%)) - (step [:u :d]) - (view-memory current-mode) - (view-memory bytes-to-write) - (view-memory start-point-high) - (view-memory start-point-low) + ;; Specify target memory address as 0xC00F + + (#(do (println "step with [:u :d]")%)) + (step [:u :d]) + (view-memory current-mode) + (view-memory bytes-to-write) + (view-memory start-point-high) + (view-memory start-point-low) - (#(do (println "step with [:a :b :start :select]")%)) - (step [:a :b :start :select]) - (view-memory current-mode) - (view-memory bytes-to-write) - (view-memory start-point-high) - (view-memory start-point-low) + (#(do (println "step with [:a :b :start :select]")%)) + (step [:a :b :start :select]) + (view-memory current-mode) + (view-memory bytes-to-write) + (view-memory start-point-high) + (view-memory start-point-low) - ;; Start reprogramming memory + ;; Start reprogramming memory - (#(do (println "step with [:a]")%)) - (step [:a]) - (view-memory current-mode) - (view-memory bytes-written) + (#(do (println "step with [:a]")%)) + (step [:a]) + (view-memory current-mode) + (view-memory bytes-written) - (#(do (println "step with [:b]")%)) - (step [:b]) - (view-memory current-mode) - (view-memory bytes-written) + (#(do (println "step with [:b]")%)) + (step [:b]) + (view-memory current-mode) + (view-memory bytes-written) - (#(do (println "step with [:a :b]")%)) - (step [:a :b]) - (view-memory current-mode) - (view-memory bytes-written) + (#(do (println "step with [:a :b]")%)) + (step [:a :b]) + (view-memory current-mode) + (view-memory bytes-written) - (#(do (println "step with [:select]")%)) - (step [:select]) - (view-memory current-mode) - (view-memory bytes-written) + (#(do (println "step with [:select]")%)) + (step [:select]) + (view-memory current-mode) + (view-memory bytes-written) - ;; Reprogramming done, program ready for more commands. + ;; Reprogramming done, program ready for more commands. - (#(do (println "step with []")%)) - (step []) - (view-memory current-mode) - (view-memory bytes-written) - - (#(do (println "memory from 0xC00F to 0xC01F:" - (subvec (vec (memory %)) 0xC00F 0xC01F)) %)))) + (#(do (println "step with []")%)) + (step []) + (view-memory current-mode) + (view-memory bytes-written) + + (#(do (println "memory from 0xC00F to 0xC01F:" + (subvec (vec (memory %)) 0xC00F 0xC01F)) %)))))