Mercurial > vba-clojure
changeset 378:5c4a30521d09
created efficient frame-metronome program
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 11 Apr 2012 11:43:51 -0500 |
parents | 1f14c1b8af7e |
children | f86bd04bd9fc |
files | clojure/com/aurellem/gb/rlm_assembly.clj |
diffstat | 1 files changed, 58 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/gb/rlm_assembly.clj Wed Apr 11 10:47:27 2012 -0500 1.2 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj Wed Apr 11 11:43:51 2012 -0500 1.3 @@ -59,10 +59,66 @@ 1.4 ;; Byte 1 : 0x34 (low byte of 0x1234) 1.5 1.6 1.7 +(defn ->signed-8-bit [n] 1.8 + (if (< n 0) 1.9 + (+ 256 n) n)) 1.10 + 1.11 +(defn frame-metronome [] 1.12 + (let [timing-loop 1.13 + [0x47 ;; A->B 1.14 + 1.15 + 0x26 1.16 + 0xFE ;; load FF into H without repeats 1.17 + 0x24 1.18 + 1.19 + 0x2E 1.20 + 0x43 ;; load 44 into L without repeats 1.21 + 0x2C 1.22 + 1.23 + 0x7E] ;; (HL) -> A, now A = LY (vertical line coord) 1.24 + jump-if-not-144 1.25 + [0xFE 1.26 + 144 ;; compare LY (in A) with 144 1.27 + 0x20 ;; jump back to beginning if LY != 144 (not-v-blank) 1.28 + (->signed-8-bit (+ -4 (- (count timing-loop))))] 1.29 + continue-if-different 1.30 + [0xB8 ;; compare A with B 1.31 + 0x28 1.32 + (->signed-8-bit 1.33 + (+ -3 (- (+ (count timing-loop) (count jump-if-not-144)))))]] 1.34 + (concat timing-loop jump-if-not-144 continue-if-different))) 1.35 + 1.36 +(defn test-frame-metronome [] 1.37 + (let [inc-C [0x0C 0x18 1.38 + (->signed-8-bit 1.39 + (+ -3 (- (count (frame-metronome)))))] 1.40 + program (concat (frame-metronome) inc-C) 1.41 + count-frames 1.42 + (-> (tick (mid-game)) 1.43 + (IE! 0) 1.44 + (BC! 0) 1.45 + (set-memory-range pokemon-list-start program) 1.46 + (PC! pokemon-list-start)) 1.47 + steps 151] 1.48 + (assert 1.49 + (= 151 1.50 + (C (run-moves count-frames (repeat steps []))))) 1.51 + count-frames)) 1.52 + 1.53 1.54 (defn main-bootstrap-program [start-address] 1.55 - (let [[start-high start-low] (disect-bytes-2 start-address)] 1.56 - [0xF3 0x18 0xFE])) 1.57 + (let [[start-high start-low] (disect-bytes-2 start-address) 1.58 + ] 1.59 + )) 1.60 + 1.61 + 1.62 + 1.63 + 1.64 + 1.65 + 1.66 + 1.67 + 1.68 + 1.69 1.70 ;;;;;; TESTS ;;;;;; 1.71