# HG changeset patch # User Robert McIntyre # Date 1334310658 18000 # Node ID c7a43f4ffd9d1a7321c8867f27cfa1660c86b167 # Parent 6ab872c5a7e785ff46a1cefdea11530d38d17e26 fixed bug where A was always 0 when the self-modigying code was executed. diff -r 6ab872c5a7e7 -r c7a43f4ffd9d clojure/com/aurellem/gb/rlm_assembly.clj --- a/clojure/com/aurellem/gb/rlm_assembly.clj Fri Apr 13 04:37:12 2012 -0500 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj Fri Apr 13 04:50:58 2012 -0500 @@ -213,18 +213,18 @@ input [0xC1 ;; pop BC so it's not volatile - 0x00 ;; A->C + 0x4F ;; A->C + 0xAF ;; test for output-mode (bytes-to-write > 0) + 0x00 ;; (cp A B) + 0x79 ;; C->A - 0x00 ;; test for output-mode (bytes-to-write > 0) - 0x00 ;; (cp A B) - - 0x00 ;; skip input section if - 0x00 ;;:to-output ;; we're not in input mode + 0x20 ;; skip input section if + :to-output ;; we're not in input mode :to-be-executed ;; write mode to instruction-to-be-executed (pun) - 0x00 ;; C->A + 0xEA :to-be-executed-address 0x18 ;; return @@ -282,7 +282,7 @@ (+ start-address jump-distance (count init) (symbol-index :to-be-executed input)))) - :to-be-executed 0x3F} ;; clear carry flag no-op + :to-be-executed 0x00} ;; clear carry flag no-op program** (flatten (replace @@ -304,11 +304,11 @@ {:to-beginning-1 (->signed-8-bit (+ (count init) - -2 (- (inc (symbol-index :to-beginning-1 program*))))) + -2 (- (dec (symbol-index :to-beginning-1 program*))))) :to-beginning-2 (->signed-8-bit (+ (count init) - -2 (- (inc (symbol-index :to-beginning-2 program*)))))} + -2 (- (dec (symbol-index :to-beginning-2 program*)))))} program (replace resolve-external-jumps program*)]