comparison clojure/com/aurellem/gb/rlm_assembly.clj @ 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
comparison
equal deleted inserted replaced
377:1f14c1b8af7e 378:5c4a30521d09
57 ;; Example: to jump to address 0x1234 enter 57 ;; Example: to jump to address 0x1234 enter
58 ;; Byte 0 : 0x12 (high byte of 0x1234) 58 ;; Byte 0 : 0x12 (high byte of 0x1234)
59 ;; Byte 1 : 0x34 (low byte of 0x1234) 59 ;; Byte 1 : 0x34 (low byte of 0x1234)
60 60
61 61
62 (defn ->signed-8-bit [n]
63 (if (< n 0)
64 (+ 256 n) n))
65
66 (defn frame-metronome []
67 (let [timing-loop
68 [0x47 ;; A->B
69
70 0x26
71 0xFE ;; load FF into H without repeats
72 0x24
73
74 0x2E
75 0x43 ;; load 44 into L without repeats
76 0x2C
77
78 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
85 [0xB8 ;; compare A with B
86 0x28
87 (->signed-8-bit
88 (+ -3 (- (+ (count timing-loop) (count jump-if-not-144)))))]]
89 (concat timing-loop jump-if-not-144 continue-if-different)))
90
91 (defn test-frame-metronome []
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
62 108
63 (defn main-bootstrap-program [start-address] 109 (defn main-bootstrap-program [start-address]
64 (let [[start-high start-low] (disect-bytes-2 start-address)] 110 (let [[start-high start-low] (disect-bytes-2 start-address)
65 [0xF3 0x18 0xFE])) 111 ]
112 ))
113
114
115
116
117
118
119
120
121
66 122
67 ;;;;;; TESTS ;;;;;; 123 ;;;;;; TESTS ;;;;;;
68 124
69 (defn bootstrap-base [] 125 (defn bootstrap-base []
70 (let [program (main-bootstrap-program pokemon-list-start)] 126 (let [program (main-bootstrap-program pokemon-list-start)]