comparison clojure/com/aurellem/gb/rlm_assembly.clj @ 385:3f3cfc89be91

working on mode-dispatch
author Robert McIntyre <rlm@mit.edu>
date Thu, 12 Apr 2012 06:20:17 -0500
parents 8013915a07b3
children d8cbbf2a3133
comparison
equal deleted inserted replaced
384:8013915a07b3 385:3f3cfc89be91
114 0x3E 114 0x3E
115 (Integer/parseInt "00100000" 2) ; prepare to measure d-pad 115 (Integer/parseInt "00100000" 2) ; prepare to measure d-pad
116 116
117 0x02 117 0x02
118 0x0A ;; get D-pad info 118 0x0A ;; get D-pad info
119 119
120 0xF5 ;; push AF
121
122 0x3E
123 (Integer/parseInt "00010000" 2) ; prepare to measure buttons
124
125 0x02
126 0x0A ;; get button info
127
128
120 0xE6 ;; select bottom bits of A 129 0xE6 ;; select bottom bits of A
121 0x0F 130 0x0F
122 131
132 0x47 ;; A->B
133
134 0xF1 ;; pop AF
135
136 0xE6
137 0x0F ;; select bottom bits of A
138
123 0xCB 139 0xCB
124 0x37 ;; swap A nybbles 140 0x37 ;; swap A nybbles
125 141
126 0x57 ;; A->D 142 0xB0 ;; (AND A B) -> A
127 143
128 0x3E
129 (Integer/parseInt "00010000" 2) ; prepare to measure buttons
130
131 0x02
132 0x0A ;; get button info
133
134 0xE6
135 0x0F ;; select bottom bits of A
136
137 0xB2 ;; combine together into A
138 0x2F ;; (NOT A) -> A 144 0x2F ;; (NOT A) -> A
139 ]) 145 ])
140 146
141 (defn test-read-user-input [] 147 (defn test-read-user-input []
142 (let [program 148 (let [program
152 (-> (tick (mid-game)) 158 (-> (tick (mid-game))
153 (IE! 0) 159 (IE! 0)
154 (set-memory-range pokemon-list-start program) 160 (set-memory-range pokemon-list-start program)
155 (PC! pokemon-list-start))] 161 (PC! pokemon-list-start))]
156 (dorun 162 (dorun
157 (for [i (range 0x100)] 163 (for [i (range 0x100)]
158 (assert (= (E (step read-input (buttons i))) i)))) 164 (assert (= (E (step read-input (buttons i))) i))))
159 (println "Tested all inputs.") 165 (println "Tested all inputs.")
160 read-input)) 166 read-input))
161 167
162 168 (def mode-select-mode (Integer/parseInt "00000000" 2))
169 (def write-mode (Integer/parseInt "00000001" 2))
170 (def jump-mode (Integer/parseInt "10000000" 2))
171
172 (def input-high-addr-jump (Integer/parseInt "10000010" 2))
173 (def input-high-addr-write (Integer/parseInt "00000010" 2))
174 (def input-low-addr-jump (Integer/parseInt "10000100" 2))
175 (def input-low-addr-write (Integer/parseInt "00000100" 2))
176
177 (def input-write-num-mode (Integer/parseInt "00001000" 2))
178 (def do-write-mode (Integer/parseInt "00010000" 2))
179
180
181
182
183
184
163 185
164 (defn main-bootstrap-program [start-address] 186 (defn main-bootstrap-program [start-address]
165 (let [[start-high start-low] (disect-bytes-2 start-address) 187 (let [[start-high start-low] (disect-bytes-2 start-address)
166 ] 188 jump-distance (+ (count (frame-metronome)
189 (read-user-input)))
190
191 init
192 [0x1E 0xFF 0x1C] ;; 0-> E without repeats
193
194
195 ;; HL -> BC
196 ;; HL = here
197 ;; add E to HL
198 ;; jp HL
199
200 mode-dispatch
201 [0x44
202
203
204
205 ;;(here) jr metronome
206
207 ;;stuff
208 ;;modify E
209 ;;jr metronome
210
211 ;;stuff
212 ;;jr metronome
213
214
215
216
217
218
219
220 mode-dispatch
221 [0xCB
222 0x43 ;; test bit 0
223
224 0xCB
225 0x4B ;; test bit 1
226
227 0xCB
228 0x53 ;; test bit 2
229
230 0xCB
231 0x5B ;; test bit 3
232
233 0xCB
234 0x63 ;; test bit 4
235
236 0xCB
237 0x6B ;; test bit 5
238
239 ];;default
240
241
242 mode-select
243 [0x5F] ;; A->E
244
245 ;; delayed inputs
246 input-high 0x67 ;; A->H
247 input-low 0x6F ;; A->L
248 input-num 0x57 ;; A->D
249
250 ;; final-actions
251 jump 0xE9 ;; jp (HL)
252 write 0x22 ;; A->(HL); inc HL
253 input-mode 0x00 ;; no-op
254
255
256
257 input-high
258 [0x67 ;; A->H
259 0x1E ;; change mode
260 input-low-mode]
261
262
263
264
265 mode-dispatch
266
267
268
269
270
271
272
167 )) 273 ))
168 274
169 275
170 276
171 277