# HG changeset patch # User Robert McIntyre # Date 1334230023 18000 # Node ID d8cbbf2a313307111733ba82373fecd62850668a # Parent 3f3cfc89be914bbfe390a5f5c8cda79542c7b5ea changed scratch ragisters from BC to DE. diff -r 3f3cfc89be91 -r d8cbbf2a3133 clojure/com/aurellem/gb/rlm_assembly.clj --- a/clojure/com/aurellem/gb/rlm_assembly.clj Thu Apr 12 06:20:17 2012 -0500 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj Thu Apr 12 06:27:03 2012 -0500 @@ -65,12 +65,20 @@ (defn frame-metronome [] (let [timing-loop - [0x01 ; \ - 0x43 ; | - 0xFE ; | load 0xFF44 into BC without repeats - 0x0C ; | - 0x04 ; / - 0x0A] ;; (BC) -> A, now A = LY (vertical line coord) + [;;0x01 ; \ + ;;0x43 ; | + ;;0xFE ; | load 0xFF44 into BC without repeats + ;;0x0C ; | + ;;0x04 ; / + ;;0x0A ;; (BC) -> A, now A = LY (vertical line coord) + + 0x11 ; \ + 0x43 ; | + 0xFE ; | load 0xFF44 into DE without repeats + 0x1C ; | + 0x14 ; / + 0x1A ;; (DE) -> A, now A = LY (vertical line coord) + ] continue-if-144 [0xFE 144 ;; compare LY (in A) with 144 @@ -78,7 +86,8 @@ (->signed-8-bit (+ -4 (- (count timing-loop))))] spin-loop - [0x05 ;; dec B, which is 0xFF + [;;0x05 ;; dec B, which is 0xFF + 0x15 ;; dec D, which is 0xFF 0x20 ;; spin until B==0 0xFD]] (concat timing-loop continue-if-144 spin-loop))) @@ -87,43 +96,49 @@ "Ensure that frame-metronome ticks exactly once every frame." ([] (test-frame-metronome 151)) ([steps] - (let [inc-D [0x14 0x18 + (let [inc-B [0x04 0x18 (->signed-8-bit (+ -3 (- (count (frame-metronome)))))] - program (concat (frame-metronome) inc-D) + program (concat (frame-metronome) inc-B) count-frames (-> (tick (mid-game)) (IE! 0) - (DE! 0) + (BC! 0) (set-memory-range pokemon-list-start program) (PC! pokemon-list-start)) - D-after-moves (D (run-moves count-frames (repeat steps [])))] - (println "D:" D-after-moves) - (assert (= steps D-after-moves)) + B-after-moves (B (run-moves count-frames (repeat steps [])))] + (println "B:" B-after-moves) + (assert (= steps B-after-moves)) - (println "D =" D-after-moves "after" steps "steps") + (println "B =" B-after-moves "after" steps "steps") count-frames))) (defn read-user-input [] - [0x01 ;\ - 0x01 ;| - 0xFE ;| load 0xFF00 into BC without repeats - 0x04 ;| - 0x0D ;/ + [;;0x01 ;\ + ;;0x01 ;| + ;;0xFE ;| load 0xFF00 into BC without repeats + ;;0x04 ;| + ;;0x0D ;/ + 0x11 ; \ + 0x01 ; | + 0xFE ; | load 0xFF44 into DE without repeats + 0x14 ; | + 0x1D ; / + 0x3E (Integer/parseInt "00100000" 2) ; prepare to measure d-pad - 0x02 - 0x0A ;; get D-pad info + 0x12 + 0x1A ;; get D-pad info 0xF5 ;; push AF 0x3E (Integer/parseInt "00010000" 2) ; prepare to measure buttons - 0x02 - 0x0A ;; get button info + 0x12 + 0x1A ;; get button info 0xE6 ;; select bottom bits of A @@ -148,7 +163,7 @@ (let [program (concat (frame-metronome) (read-user-input) - [0x5F ;; A-> E + [0x47 ;; A->B 0x18 (->signed-8-bit (+ (- (count (frame-metronome))) @@ -161,7 +176,7 @@ (PC! pokemon-list-start))] (dorun (for [i (range 0x100)] - (assert (= (E (step read-input (buttons i))) i)))) + (assert (= (B (step read-input (buttons i))) i)))) (println "Tested all inputs.") read-input))