comparison clojure/com/aurellem/gb/rlm_assembly.clj @ 400:1b9137ef7380

this f@#@# thing oh my god.
author Robert McIntyre <rlm@mit.edu>
date Fri, 13 Apr 2012 07:30:11 -0500
parents ddb3c6299619
children 0262094d0914
comparison
equal deleted inserted replaced
399:ddb3c6299619 400:1b9137ef7380
215 215
216 0x5F ;; A->E 216 0x5F ;; A->E
217 0xAF ;; test for output-mode (bytes-to-write > 0) 217 0xAF ;; test for output-mode (bytes-to-write > 0)
218 0x00 ;; (cp A B) 218 0x00 ;; (cp A B)
219 0x7B ;; E->A 219 0x7B ;; E->A
220 0x20 ;; skip input section if 220 0x20 ;; skip to output section if
221 :to-output ;; we're not in input mode 221 :to-output ;; we're not in input mode
222 222
223 :to-be-executed 223 :to-be-executed
224 224
225 ;; write mode to instruction-to-be-executed (pun) 225 ;; write mode to instruction-to-be-executed (pun)
226 0xEA 226 0xEA
227 :to-be-executed-address 227 :to-be-executed-address
228 228
229 ;; if A is zero, skip the protection section 229 ;; protection region -- do not queue this op for
230 0xA7 230 ;; execution if the last one was non-zero
231 0x79 ;; C->A
232 0xA7 ;; test A==0
231 0x28 233 0x28
232 0x09
233
234 0x0C ;; inc C
235 0xCB
236 0x41 ;; test bit 0 of C
237 0x20 ;; if (0 == (C % 2))
238 0x04 234 0x04
239 0xAF ;; put a no op (0x00) in to-be-executed 235 0xAF ;; put a no op (0x00) in to-be-executed
240 0xEA ;; every other time. 236 0xEA ;;
241 :to-be-executed-address 237 :to-be-executed-address
242 238
239 0x7B ;; E->A
240 0x4F ;; A->C now C stores previous instruction
243 0x18 ;; return 241 0x18 ;; return
244 :to-beginning-1] 242 :to-beginning-1]
245 243
246 ;; output 244 ;; output
247 ;; [:output-start ;; just a label 245 ;; [:output-start ;; just a label
332 (let [program (main-bootstrap-program pokemon-list-start)] 330 (let [program (main-bootstrap-program pokemon-list-start)]
333 ;; make sure program is valid output for item-writer 331 ;; make sure program is valid output for item-writer
334 ;;(bootstrap-pattern program) 332 ;;(bootstrap-pattern program)
335 (-> (tick (mid-game)) 333 (-> (tick (mid-game))
336 (set-memory-range pokemon-list-start program) 334 (set-memory-range pokemon-list-start program)
337 (PC! pokemon-list-start)))) 335 (PC! pokemon-list-start)
338 336 (step [])
339 (defn test-set-H [n] 337 (step []))))
340 (let [after 338
341 (-> (bootstrap-base) 339
342 (step []) 340 (defn test-set-H []
343 (step (buttons 0x67)) 341 (letfn [(test-H [state n]
344 (step (buttons n)) 342 (let [after
345 (step []) 343 (-> state
346 (step []) 344 (step (buttons 0x67))
347 )] 345 (step (buttons n))
348 (hex (H after)))) 346 (step []))]
347 (println "desired H =" n "actual =" (H after))
348 (assert (= n (H after)))
349 after))]
350 (println "tested all H values")
351 (reduce test-H (bootstrap-base) (range 0x100))))
352
353
354
355
349 356
350 (defn test-write-bytes-mode [] 357 (defn test-write-bytes-mode []
351 (let [target-address 0xC00F 358 (let [target-address 0xC00F
352 [target-high target-low] (disect-bytes-2 target-address) 359 [target-high target-low] (disect-bytes-2 target-address)
353 assembly [0xF3 0x18 0xFE 0x12] 360 assembly [0xF3 0x18 0xFE 0x12]