# HG changeset patch # User Robert McIntyre # Date 1331965427 18000 # Node ID f8dadd9478a5f7d785f1127b147e684efee20385 # Parent c9a280b8bd1cfc7c21e4c29d617666ee7fd172d3 fixed problem with mode transitions diff -r c9a280b8bd1c -r f8dadd9478a5 clojure/com/aurellem/assembly.clj --- a/clojure/com/aurellem/assembly.clj Sat Mar 17 00:29:34 2012 -0500 +++ b/clojure/com/aurellem/assembly.clj Sat Mar 17 01:23:47 2012 -0500 @@ -82,11 +82,10 @@ state) (defn trace [state] - (loop [program-counters [] - opcodes []] + (loop [program-counters [(first (registers @current-state)) ] + opcodes [(aget (memory @current-state) (PC @current-state))]] (let [frame-boundary? (com.aurellem.gb.Gb/tick)] - (println (count opcodes)) (if frame-boundary? [program-counters opcodes] (recur @@ -95,7 +94,13 @@ (conj opcodes (aget (memory @current-state) (PC @current-state)))))))) - + +(defn print-trace [state n] + (let [[program-counters opcodes] (trace state)] + (dorun (map (fn [pc op] (println (format "%04X: 0x%02X" pc op))) + (take n program-counters) + (take n opcodes))))) + (defn good-trace [] (-> (mid-game) (tick) (IE! 0) (set-inv-mem [0x00 0x00 0X00 0x00]) @@ -441,6 +446,7 @@ (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) (defn write-memory-assembly [] + [ ;; Main Timing Loop ;; Constantly check for v-blank and Trigger main state machine on @@ -461,14 +467,14 @@ 0x4F ; D325 0xC2 ; D326 ; if bit-1 is not 0, then - 0x44 ; D327 ; GOTO non-v-blank. + 0x3E ; D327 ; GOTO non-v-blank. 0xD3 ; D328 0xCB ; D329 0x47 ; D32A 0xCA ; D32B ; if bit-0 is not 1, then - 0x44 ; D32C ; GOTO non-v-blank. + 0x3E ; D32C ; GOTO non-v-blank. 0xD3 ; D32D ;; V-Blank @@ -478,19 +484,19 @@ 0x20 ; D32F 0xD3 ; D330 - 0xFE ; D331 ; compare A to 0. - 0x00 ; D332 - - ;; set v-blank-prev to 1. - 0x3E ; D333 ; load 1 into A. - 0x01 ; D334 - - 0xEA ; D335 ; load A into v-blank-prev - 0x20 ; D336 - 0xD3 ; D337 - - ;; if v-blank-prev was 0, activate state-machine - 0xC2 ; D338 ; if v-blank-prev + 0xFE ; D331 ; compare A to 0. >--------\ + 0x00 ; D332 \ + ; | + ;; set v-blank-prev to 1. | + 0x3E ; D333 ; load 1 into A. | + 0x01 ; D334 | + ; | + 0xEA ; D335 ; load A into v-blank-prev | + 0x20 ; D336 | + 0xD3 ; D337 | + ; / + ;; if v-blank-prev was 0, activate state-machine <------/ + 0xCA ; D338 ; if v-blank-prev 0x46 ; D339 ; was 0, 0xD3 ; D33A ; GOTO state-machine @@ -513,6 +519,7 @@ 0xD3 ; D345 ; GOTO beginning ;; END Not-V-Blank + ;; Main State Machine -- Input Section ;; This is called once every frame. ;; It collects input and uses it to drive the @@ -533,10 +540,9 @@ ;;;;;;;;; BEGIN RLM DEBUG - 0xC3 ;; jump to beginning - 0x1D - 0xD3 - + ;;0xC3 ;; jump to beginning + ;;0x1D + ;;0xD3 ;;;;;;;;; END RLM DEBUG @@ -600,9 +606,9 @@ 0x52 ;D373 0xD3 ;D374 - 0xC3 ;D375 ; secret jump :) - 0x1D ;D376 - 0xD3 ;D377 + 0x00 ;D375 + 0x00 ;D376 + 0x00 ;D377 0x00 ;D378 0x00 ;D379 0x00 ;D37A @@ -779,6 +785,9 @@ (def frame-count 0xD31F) (def input 0xD352) (def current-mode 0xD382) +(def bytes-to-write 0xD383) +(def start-point 0xD384) + (defn write-memory [] (-> (tick (mid-game)) @@ -805,6 +814,31 @@ (step []) (view-memory frame-count))) +(defn test-mode-2 [] + (-> + (write-memory) + (view-memory current-mode) + (step []) + (step []) + (step []) + (#(do (println "after three steps") %)) + (view-memory current-mode) + (step [:a]) + (#(do (println "step with [:a]") %)) + (view-memory current-mode) + (view-memory bytes-to-write) + (view-memory start-point) + (#(do (println "step with [:u :d :l :r]")%)) + (step [:u :d]) + (view-memory current-mode) + (view-memory bytes-to-write) + (view-memory start-point) + (#(do (println "step with [:u :d]")%)) + (step [:u :d]) + (view-memory current-mode) + (view-memory bytes-to-write) + (view-memory start-point) + ))