comparison clojure/com/aurellem/gb/rlm_assembly.clj @ 379:f86bd04bd9fc

simplifying frame-metronome
author Robert McIntyre <rlm@mit.edu>
date Wed, 11 Apr 2012 12:35:31 -0500
parents 5c4a30521d09
children 4d2767423266
comparison
equal deleted inserted replaced
378:5c4a30521d09 379:f86bd04bd9fc
62 (defn ->signed-8-bit [n] 62 (defn ->signed-8-bit [n]
63 (if (< n 0) 63 (if (< n 0)
64 (+ 256 n) n)) 64 (+ 256 n) n))
65 65
66 (defn frame-metronome [] 66 (defn frame-metronome []
67 (let [timing-loop 67 (let [init [0x06 155] ;; init B to out of LY range
68 timing-loop
68 [0x47 ;; A->B 69 [0x47 ;; A->B
69 70
70 0x26 71 0x26
71 0xFE ;; load FF into H without repeats 72 0xFE ;; load FF into H without repeats
72 0x24 73 0x24
74 0x2E 75 0x2E
75 0x43 ;; load 44 into L without repeats 76 0x43 ;; load 44 into L without repeats
76 0x2C 77 0x2C
77 78
78 0x7E] ;; (HL) -> A, now A = LY (vertical line coord) 79 0x7E] ;; (HL) -> A, now A = LY (vertical line coord)
79 jump-if-not-144
80 [0xFE
81 144 ;; compare LY (in A) with 144
82 0x20 ;; jump back to beginning if LY != 144 (not-v-blank)
83 (->signed-8-bit (+ -4 (- (count timing-loop))))]
84 continue-if-different 80 continue-if-different
85 [0xB8 ;; compare A with B 81 [0xB8 ;; compare A with B
86 0x28 82 0x28
87 (->signed-8-bit 83 (->signed-8-bit
88 (+ -3 (- (+ (count timing-loop) (count jump-if-not-144)))))]] 84 (+ -3 (- (count timing-loop))))
89 (concat timing-loop jump-if-not-144 continue-if-different))) 85 ]
86 continue-if-144
87 [0xFE
88 144 ;; compare LY (in A) with 144
89 0x20 ;; jump back to beginning if LY != 144 (not-v-blank)
90 (->signed-8-bit
91 (+ -4 (- (count timing-loop))
92 (- (count continue-if-different))))]]
90 93
91 (defn test-frame-metronome [] 94 (concat init timing-loop continue-if-different continue-if-144)))
92 (let [inc-C [0x0C 0x18
93 (->signed-8-bit
94 (+ -3 (- (count (frame-metronome)))))]
95 program (concat (frame-metronome) inc-C)
96 count-frames
97 (-> (tick (mid-game))
98 (IE! 0)
99 (BC! 0)
100 (set-memory-range pokemon-list-start program)
101 (PC! pokemon-list-start))
102 steps 151]
103 (assert
104 (= 151
105 (C (run-moves count-frames (repeat steps [])))))
106 count-frames))
107 95
96
97 (defn test-frame-metronome
98 "Ensure that frame-metronome ticks exactly once every frame."
99 ([] (test-frame-metronome 151))
100 ([steps]
101 (let [inc-C [0x0C 0x18
102 (->signed-8-bit
103 (+ -3 (- (count (frame-metronome)))))]
104 program (concat (frame-metronome) inc-C)
105 count-frames
106 (-> (tick (mid-game))
107 (IE! 0)
108 (BC! 0)
109 (set-memory-range pokemon-list-start program)
110 (PC! pokemon-list-start))
111 C-after-moves (C (run-moves count-frames (repeat steps [])))]
112 (println "C:" C-after-moves)
113 (assert (= steps C-after-moves))
114
115 (println "C =" steps "after" steps "steps")
116 count-frames)))
108 117
109 (defn main-bootstrap-program [start-address] 118 (defn main-bootstrap-program [start-address]
110 (let [[start-high start-low] (disect-bytes-2 start-address) 119 (let [[start-high start-low] (disect-bytes-2 start-address)
111 ] 120 ]
112 )) 121 ))