comparison clojure/com/aurellem/assembly.clj @ 112:6fe33bb5ea22

saving progress
author Robert McIntyre <rlm@mit.edu>
date Thu, 15 Mar 2012 17:29:49 -0500
parents 8be7ce890184
children 0831da75d2c5
comparison
equal deleted inserted replaced
111:8be7ce890184 112:6fe33bb5ea22
17 (+ program-counter (count assembly-code))) 17 (+ program-counter (count assembly-code)))
18 assembly-code)) 18 assembly-code))
19 (-> state 19 (-> state
20 (write-memory! scratch-memory) 20 (write-memory! scratch-memory)
21 (write-registers! registers) 21 (write-registers! registers)
22 (PC! program-counter)))) 22 (PC! program-counter)))))
23 ;;([program-counter]
24 ;; (fn [^SaveState state registers assembly-code]
25 ;; (inject-assembly state program-counter registers assembly-code)))
26 )
27
28
29 ;;(def inject-assembly-item
30 ;; (inject-assembly (inc item-list-start)))
31 23
32 (defn inject-item-assembly 24 (defn inject-item-assembly
33 ([^SaveState state assembly-code] 25 ([^SaveState state assembly-code]
34 (inject-assembly state (inc item-list-start) 26 (inject-assembly state (inc item-list-start)
35 (registers state) 27 (registers state)
59 (range n))] 51 (range n))]
60 final-state)) 52 final-state))
61 ([assembly n] 53 ([assembly n]
62 (run-assembly info assembly n))) 54 (run-assembly info assembly n)))
63 55
64
65 (def buttons-port 0xFF00) 56 (def buttons-port 0xFF00)
66
67 57
68 (defn A [state] 58 (defn A [state]
69 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8)) 59 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8))
70 60
71 (defn binary-str [num] 61 (defn binary-str [num]
131 0xD3 ;D332 121 0xD3 ;D332
132 ] 122 ]
133 123
134 [])))) 124 []))))
135 125
136
137 (defn run-a-bit [] 126 (defn run-a-bit []
138 (-> (read-buttons) 127 (-> (read-buttons)
139 (info) 128 (info)
140 (tick) ;; skip over data section 129 (tick) ;; skip over data section
141 (info) 130 (info)
158 (tick) 147 (tick)
159 (info) 148 (info)
160 (tick) 149 (tick)
161 (print-inventory))) 150 (print-inventory)))
162 151
163 152 (defn test-read-pad []
164 (comment 153 (= (view-memory (step (step (read-buttons) [:d])) 0xD328)
165 (view-memory (step (step (read-buttons) [:d])) 0xD328) 154 (view-memory (step (step (read-buttons))) 0xD328)))
166 ;;mem 0xD328 = 11100111
167 (view-memory (step (step (read-buttons))) 0xD328)
168 ;;mem 0xD328 = 00000000
169 )
170 155
171 (defn trace [state] 156 (defn trace [state]
172 (loop [program-counters [] 157 (loop [program-counters []
173 opcodes []] 158 opcodes []]
174 (let [frame-boundary? 159 (let [frame-boundary?
180 (conj program-counters 165 (conj program-counters
181 (first (registers @current-state))) 166 (first (registers @current-state)))
182 (conj opcodes 167 (conj opcodes
183 (aget (memory @current-state) 168 (aget (memory @current-state)
184 (PC @current-state)))))))) 169 (PC @current-state))))))))
185
186 170
187 (defn good-trace [] 171 (defn good-trace []
188 (-> (mid-game) (tick) (IE! 0) 172 (-> (mid-game) (tick) (IE! 0)
189 (set-inv-mem [0x00 0x00 0X00 0x00]) 173 (set-inv-mem [0x00 0x00 0X00 0x00])
190 (PC! item-list-start)(print-interrupt) 174 (PC! item-list-start)(print-interrupt)