comparison clojure/com/aurellem/gb/rlm_assembly.clj @ 396:c7a43f4ffd9d

fixed bug where A was always 0 when the self-modigying code was executed.
author Robert McIntyre <rlm@mit.edu>
date Fri, 13 Apr 2012 04:50:58 -0500
parents 6ab872c5a7e7
children 9b0d79cad624
comparison
equal deleted inserted replaced
395:6ab872c5a7e7 396:c7a43f4ffd9d
211 [0xAF 0x5F 0x57 0x47] ;; 0->A; 0->E; 0->D; 0->B 211 [0xAF 0x5F 0x57 0x47] ;; 0->A; 0->E; 0->D; 0->B
212 212
213 input 213 input
214 [0xC1 ;; pop BC so it's not volatile 214 [0xC1 ;; pop BC so it's not volatile
215 215
216 0x00 ;; A->C 216 0x4F ;; A->C
217 0xAF ;; test for output-mode (bytes-to-write > 0)
218 0x00 ;; (cp A B)
219 0x79 ;; C->A
217 220
218 0x00 ;; test for output-mode (bytes-to-write > 0) 221 0x20 ;; skip input section if
219 0x00 ;; (cp A B) 222 :to-output ;; we're not in input mode
220
221 0x00 ;; skip input section if
222 0x00 ;;:to-output ;; we're not in input mode
223 223
224 :to-be-executed 224 :to-be-executed
225 225
226 ;; write mode to instruction-to-be-executed (pun) 226 ;; write mode to instruction-to-be-executed (pun)
227 0x00 ;; C->A 227
228 0xEA 228 0xEA
229 :to-be-executed-address 229 :to-be-executed-address
230 0x18 ;; return 230 0x18 ;; return
231 :to-beginning-1] 231 :to-beginning-1]
232 232
280 (reverse 280 (reverse
281 (disect-bytes-2 281 (disect-bytes-2
282 (+ start-address jump-distance 282 (+ start-address jump-distance
283 (count init) 283 (count init)
284 (symbol-index :to-be-executed input)))) 284 (symbol-index :to-be-executed input))))
285 :to-be-executed 0x3F} ;; clear carry flag no-op 285 :to-be-executed 0x00} ;; clear carry flag no-op
286 286
287 program** (flatten 287 program** (flatten
288 (replace 288 (replace
289 symbols 289 symbols
290 (concat init (frame-metronome) 290 (concat init (frame-metronome)
302 302
303 resolve-external-jumps 303 resolve-external-jumps
304 {:to-beginning-1 304 {:to-beginning-1
305 (->signed-8-bit 305 (->signed-8-bit
306 (+ (count init) 306 (+ (count init)
307 -2 (- (inc (symbol-index :to-beginning-1 program*))))) 307 -2 (- (dec (symbol-index :to-beginning-1 program*)))))
308 :to-beginning-2 308 :to-beginning-2
309 (->signed-8-bit 309 (->signed-8-bit
310 (+ (count init) 310 (+ (count init)
311 -2 (- (inc (symbol-index :to-beginning-2 program*)))))} 311 -2 (- (dec (symbol-index :to-beginning-2 program*)))))}
312 312
313 program 313 program
314 (replace resolve-external-jumps program*)] 314 (replace resolve-external-jumps program*)]
315 program)) 315 program))
316 316