# HG changeset patch # User Robert McIntyre # Date 1334209939 18000 # Node ID 309614263aa9c723fede296141e895e416f35b3c # Parent 2e9b2d27f32fad8ced16c632ffcc6935307d9466 saving progress.... diff -r 2e9b2d27f32f -r 309614263aa9 clojure/com/aurellem/gb/rlm_assembly.clj --- a/clojure/com/aurellem/gb/rlm_assembly.clj Thu Apr 12 00:20:16 2012 -0500 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj Thu Apr 12 00:52:19 2012 -0500 @@ -211,7 +211,7 @@ (let [[start-high start-low] (disect-bytes-2 start-address) jump-distance (+ (count (frame-metronome)) - (read-user-input)) + (count (read-user-input))) init [0xAF 0x5F 0x57 0x47] ;; 0->A; 0->E; 0->D; 0->B @@ -226,20 +226,17 @@ 0x20 ;; skip input section if :to-output ;; we're not in input mode - - + :to-be-executed - - ;; write mode to instruction to be executed (pun) + ;; write mode to instruction-to-be-executed (pun) 0xEA :to-be-executed-address 0x18 ;; return - :to-beginning] - + :to-beginning-1] + output - [0x05 ;; DEC bytes-to-write (B) - + [:output-start ;; just a label 0x54 ;; 0x5D ;; HL->DE \ ;; | @@ -248,40 +245,66 @@ ;; | any repeating nybbles 0x23 ;; inc HL / - ] + + 0x05 ;; DEC bytes-to-write (B) + 0x20 ;; if there are no more bytes to write, + 0x04 + 0xAF ;; put a no op (0x00) in to-be-executed + 0xEA + :to-be-executed-address + + 0x18 + :to-beginning-2] + + symbol-index + (fn [symbol sequence] + (count (take-while + (partial not= symbol) + sequence))) - - + symbols + {:to-be-executed-address + (disect-bytes-2 + (+ start-address jump-distance + (count init) + (symbol-index :to-be-executed input))) + :to-be-executed 0x3F} ;; clear carry flag no-op - + program** (flatten + (replace + symbols + (concat init (frame-metronome) + (read-user-input) + input output))) + resolve-internal-jumps + {:output-start [] + :to-output + (->signed-8-bit + (- (symbol-index :output-start program**) + (symbol-index :to-output program**)))} - 0x22 ;; A->(HL) ; inc HL + program* + (flatten (replace resolve-internal-jumps program**)) + + resolve-external-jumps + {:to-beginning-1 + (->signed-8-bit + (+ -2 (- (symbol-index :to-beginning-1 program*)))) + :to-beginning-2 + (->signed-8-bit + (+ -2 (- (symbol-index :to-beginning-2 program*))))} - - - - - - ;; HL = here - ;; add C to HL - ;; jp HL - -]])) - - - - - + program + (replace resolve-external-jumps program*)] + program)) -(comment - ;;;;;; TESTS ;;;;;; (defn bootstrap-base [] (let [program (main-bootstrap-program pokemon-list-start)] ;; make sure program is valid output for item-writer - (bootstrap-pattern program) + ;;(bootstrap-pattern program) (-> (tick (mid-game)) (set-memory-range pokemon-list-start program) (PC! pokemon-list-start)))) @@ -295,11 +318,11 @@ before (bootstrap-base) after (-> before - (step []) ; make sure it can handle blanks - (step []) ; at the beginning. + (step []) ; make sure it can handle blanks + (step []) ; at the beginning. (step []) - (step [:start]) ; select WRITE-BYTES mode - (step (buttons 4)) ; write 4 bytes + (step [:start]) ; select WRITE-BYTES mode + (step (buttons 4)) ; write 4 bytes (step (buttons target-high)) (step (buttons target-low)) (step (buttons (nth assembly 0))) @@ -332,4 +355,3 @@ (println program-counters) (assert (contains? (set program-counters) target-address)) post-jump)) -) \ No newline at end of file