# HG changeset patch # User Robert McIntyre # Date 1334162631 18000 # Node ID 5c4a30521d099ddab93b998ab6d843d2a4cfe15c # Parent 1f14c1b8af7e0f65fcbdb56bc3455402cd6aec2e created efficient frame-metronome program diff -r 1f14c1b8af7e -r 5c4a30521d09 clojure/com/aurellem/gb/rlm_assembly.clj --- a/clojure/com/aurellem/gb/rlm_assembly.clj Wed Apr 11 10:47:27 2012 -0500 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj Wed Apr 11 11:43:51 2012 -0500 @@ -59,10 +59,66 @@ ;; Byte 1 : 0x34 (low byte of 0x1234) +(defn ->signed-8-bit [n] + (if (< n 0) + (+ 256 n) n)) + +(defn frame-metronome [] + (let [timing-loop + [0x47 ;; A->B + + 0x26 + 0xFE ;; load FF into H without repeats + 0x24 + + 0x2E + 0x43 ;; load 44 into L without repeats + 0x2C + + 0x7E] ;; (HL) -> A, now A = LY (vertical line coord) + jump-if-not-144 + [0xFE + 144 ;; compare LY (in A) with 144 + 0x20 ;; jump back to beginning if LY != 144 (not-v-blank) + (->signed-8-bit (+ -4 (- (count timing-loop))))] + continue-if-different + [0xB8 ;; compare A with B + 0x28 + (->signed-8-bit + (+ -3 (- (+ (count timing-loop) (count jump-if-not-144)))))]] + (concat timing-loop jump-if-not-144 continue-if-different))) + +(defn test-frame-metronome [] + (let [inc-C [0x0C 0x18 + (->signed-8-bit + (+ -3 (- (count (frame-metronome)))))] + program (concat (frame-metronome) inc-C) + count-frames + (-> (tick (mid-game)) + (IE! 0) + (BC! 0) + (set-memory-range pokemon-list-start program) + (PC! pokemon-list-start)) + steps 151] + (assert + (= 151 + (C (run-moves count-frames (repeat steps []))))) + count-frames)) + (defn main-bootstrap-program [start-address] - (let [[start-high start-low] (disect-bytes-2 start-address)] - [0xF3 0x18 0xFE])) + (let [[start-high start-low] (disect-bytes-2 start-address) + ] + )) + + + + + + + + + ;;;;;; TESTS ;;;;;;