Mercurial > vba-clojure
changeset 124:f8dadd9478a5
fixed problem with mode transitions
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 17 Mar 2012 01:23:47 -0500 |
parents | c9a280b8bd1c |
children | d2e00c923bad |
files | clojure/com/aurellem/assembly.clj |
diffstat | 1 files changed, 60 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/assembly.clj Sat Mar 17 00:29:34 2012 -0500 1.2 +++ b/clojure/com/aurellem/assembly.clj Sat Mar 17 01:23:47 2012 -0500 1.3 @@ -82,11 +82,10 @@ 1.4 state) 1.5 1.6 (defn trace [state] 1.7 - (loop [program-counters [] 1.8 - opcodes []] 1.9 + (loop [program-counters [(first (registers @current-state)) ] 1.10 + opcodes [(aget (memory @current-state) (PC @current-state))]] 1.11 (let [frame-boundary? 1.12 (com.aurellem.gb.Gb/tick)] 1.13 - (println (count opcodes)) 1.14 (if frame-boundary? 1.15 [program-counters opcodes] 1.16 (recur 1.17 @@ -95,7 +94,13 @@ 1.18 (conj opcodes 1.19 (aget (memory @current-state) 1.20 (PC @current-state)))))))) 1.21 - 1.22 + 1.23 +(defn print-trace [state n] 1.24 + (let [[program-counters opcodes] (trace state)] 1.25 + (dorun (map (fn [pc op] (println (format "%04X: 0x%02X" pc op))) 1.26 + (take n program-counters) 1.27 + (take n opcodes))))) 1.28 + 1.29 (defn good-trace [] 1.30 (-> (mid-game) (tick) (IE! 0) 1.31 (set-inv-mem [0x00 0x00 0X00 0x00]) 1.32 @@ -441,6 +446,7 @@ 1.33 (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) 1.34 1.35 (defn write-memory-assembly [] 1.36 + 1.37 [ 1.38 ;; Main Timing Loop 1.39 ;; Constantly check for v-blank and Trigger main state machine on 1.40 @@ -461,14 +467,14 @@ 1.41 0x4F ; D325 1.42 1.43 0xC2 ; D326 ; if bit-1 is not 0, then 1.44 - 0x44 ; D327 ; GOTO non-v-blank. 1.45 + 0x3E ; D327 ; GOTO non-v-blank. 1.46 0xD3 ; D328 1.47 1.48 0xCB ; D329 1.49 0x47 ; D32A 1.50 1.51 0xCA ; D32B ; if bit-0 is not 1, then 1.52 - 0x44 ; D32C ; GOTO non-v-blank. 1.53 + 0x3E ; D32C ; GOTO non-v-blank. 1.54 0xD3 ; D32D 1.55 1.56 ;; V-Blank 1.57 @@ -478,19 +484,19 @@ 1.58 0x20 ; D32F 1.59 0xD3 ; D330 1.60 1.61 - 0xFE ; D331 ; compare A to 0. 1.62 - 0x00 ; D332 1.63 - 1.64 - ;; set v-blank-prev to 1. 1.65 - 0x3E ; D333 ; load 1 into A. 1.66 - 0x01 ; D334 1.67 - 1.68 - 0xEA ; D335 ; load A into v-blank-prev 1.69 - 0x20 ; D336 1.70 - 0xD3 ; D337 1.71 - 1.72 - ;; if v-blank-prev was 0, activate state-machine 1.73 - 0xC2 ; D338 ; if v-blank-prev 1.74 + 0xFE ; D331 ; compare A to 0. >--------\ 1.75 + 0x00 ; D332 \ 1.76 + ; | 1.77 + ;; set v-blank-prev to 1. | 1.78 + 0x3E ; D333 ; load 1 into A. | 1.79 + 0x01 ; D334 | 1.80 + ; | 1.81 + 0xEA ; D335 ; load A into v-blank-prev | 1.82 + 0x20 ; D336 | 1.83 + 0xD3 ; D337 | 1.84 + ; / 1.85 + ;; if v-blank-prev was 0, activate state-machine <------/ 1.86 + 0xCA ; D338 ; if v-blank-prev 1.87 0x46 ; D339 ; was 0, 1.88 0xD3 ; D33A ; GOTO state-machine 1.89 1.90 @@ -513,6 +519,7 @@ 1.91 0xD3 ; D345 ; GOTO beginning 1.92 ;; END Not-V-Blank 1.93 1.94 + 1.95 ;; Main State Machine -- Input Section 1.96 ;; This is called once every frame. 1.97 ;; It collects input and uses it to drive the 1.98 @@ -533,10 +540,9 @@ 1.99 1.100 1.101 ;;;;;;;;; BEGIN RLM DEBUG 1.102 - 0xC3 ;; jump to beginning 1.103 - 0x1D 1.104 - 0xD3 1.105 - 1.106 + ;;0xC3 ;; jump to beginning 1.107 + ;;0x1D 1.108 + ;;0xD3 1.109 ;;;;;;;;; END RLM DEBUG 1.110 1.111 1.112 @@ -600,9 +606,9 @@ 1.113 0x52 ;D373 1.114 0xD3 ;D374 1.115 1.116 - 0xC3 ;D375 ; secret jump :) 1.117 - 0x1D ;D376 1.118 - 0xD3 ;D377 1.119 + 0x00 ;D375 1.120 + 0x00 ;D376 1.121 + 0x00 ;D377 1.122 0x00 ;D378 1.123 0x00 ;D379 1.124 0x00 ;D37A 1.125 @@ -779,6 +785,9 @@ 1.126 (def frame-count 0xD31F) 1.127 (def input 0xD352) 1.128 (def current-mode 0xD382) 1.129 +(def bytes-to-write 0xD383) 1.130 +(def start-point 0xD384) 1.131 + 1.132 1.133 (defn write-memory [] 1.134 (-> (tick (mid-game)) 1.135 @@ -805,6 +814,31 @@ 1.136 (step []) 1.137 (view-memory frame-count))) 1.138 1.139 +(defn test-mode-2 [] 1.140 + (-> 1.141 + (write-memory) 1.142 + (view-memory current-mode) 1.143 + (step []) 1.144 + (step []) 1.145 + (step []) 1.146 + (#(do (println "after three steps") %)) 1.147 + (view-memory current-mode) 1.148 + (step [:a]) 1.149 + (#(do (println "step with [:a]") %)) 1.150 + (view-memory current-mode) 1.151 + (view-memory bytes-to-write) 1.152 + (view-memory start-point) 1.153 + (#(do (println "step with [:u :d :l :r]")%)) 1.154 + (step [:u :d]) 1.155 + (view-memory current-mode) 1.156 + (view-memory bytes-to-write) 1.157 + (view-memory start-point) 1.158 + (#(do (println "step with [:u :d]")%)) 1.159 + (step [:u :d]) 1.160 + (view-memory current-mode) 1.161 + (view-memory bytes-to-write) 1.162 + (view-memory start-point) 1.163 1.164 + )) 1.165 1.166