# HG changeset patch # User Robert McIntyre # Date 1334171061 18000 # Node ID 8013915a07b30c5945b2934ed201694f0cfb6838 # Parent 9eae7e914bf05d1c270651b723ef611da952f861 completed read-user-input by working off of Dylan's version. diff -r 9eae7e914bf0 -r 8013915a07b3 clojure/com/aurellem/gb/rlm_assembly.clj --- a/clojure/com/aurellem/gb/rlm_assembly.clj Wed Apr 11 13:39:53 2012 -0500 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj Wed Apr 11 14:04:21 2012 -0500 @@ -104,6 +104,63 @@ (println "D =" D-after-moves "after" steps "steps") count-frames))) +(defn read-user-input [] + [0x01 ;\ + 0x01 ;| + 0xFE ;| load 0xFF00 into BC without repeats + 0x04 ;| + 0x0D ;/ + + 0x3E + (Integer/parseInt "00100000" 2) ; prepare to measure d-pad + + 0x02 + 0x0A ;; get D-pad info + + 0xE6 ;; select bottom bits of A + 0x0F + + 0xCB + 0x37 ;; swap A nybbles + + 0x57 ;; A->D + + 0x3E + (Integer/parseInt "00010000" 2) ; prepare to measure buttons + + 0x02 + 0x0A ;; get button info + + 0xE6 + 0x0F ;; select bottom bits of A + + 0xB2 ;; combine together into A + 0x2F ;; (NOT A) -> A + ]) + +(defn test-read-user-input [] + (let [program + (concat + (frame-metronome) (read-user-input) + [0x5F ;; A-> E + 0x18 + (->signed-8-bit + (+ (- (count (frame-metronome))) + (- (count (read-user-input))) + (- 3)))]) + read-input + (-> (tick (mid-game)) + (IE! 0) + (set-memory-range pokemon-list-start program) + (PC! pokemon-list-start))] + (dorun + (for [i (range 0x100)] + (assert (= (E (step read-input (buttons i))) i)))) + (println "Tested all inputs.") + read-input)) + + + (defn main-bootstrap-program [start-address] (let [[start-high start-low] (disect-bytes-2 start-address) ]