Mercurial > vba-clojure
diff clojure/com/aurellem/run/image.clj @ 508:e6c02264dc9c
trying to track down pesky assembly bug.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 20 Jun 2012 21:41:38 -0500 |
parents | 24b459a95b46 |
children | d2c40a12de28 |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/run/image.clj Wed Jun 20 19:51:50 2012 -0500 1.2 +++ b/clojure/com/aurellem/run/image.clj Wed Jun 20 21:41:38 2012 -0500 1.3 @@ -427,9 +427,78 @@ 1.4 (map row->bits 1.5 (partition 8 tile)))))) 1.6 1.7 - 1.8 1.9 -(defn display-image-kernel [^BufferedImage image] 1.10 +(defn write-data 1.11 + "Efficient assembly to write a sequence of values to 1.12 + memory, starting at a target address." 1.13 + [base-address target-address data] 1.14 + (let [len (count data)] 1.15 + (flatten 1.16 + (if (<= len 255) 1.17 + [0x21 ;; load data address start into HL 1.18 + (reverse (disect-bytes-2 (+ 16 base-address))) 1.19 + 1.20 + 0x01 ;; load target address into BC 1.21 + (reverse (disect-bytes-2 target-address)) 1.22 + 1.23 + 0x16 ;; load len into D 1.24 + len 1.25 + 1.26 + 1.27 + ;; data x-fer loop start 1.28 + 0x2A ;; (HL) -> A; HL++; 1.29 + 0x02 ;; A -> (BC); 1.30 + 0x03 ;; INC BC; 1.31 + 0x15 ;; DEC D 1.32 + 1.33 + 0x20 ;; if D is not now 0, 1.34 + (->signed-8-bit -6) ;; GOTO start 1.35 + 1.36 + 0x18 1.37 + len 1.38 + 1.39 + data] 1.40 + (let [first-part (write-data base-address target-address 1.41 + (take 255 data))] 1.42 + [first-part 1.43 + (write-data (+ base-address (count first-part)) 1.44 + (+ target-address 255) 1.45 + (drop 255 data))]))))) 1.46 + 1.47 +(defn test-write-data [] 1.48 + (let [test-data (repeat 3 0xD3) 1.49 + base-address 0xA000 1.50 + target-address 0xA500 1.51 + 1.52 + test-kernel 1.53 + (flatten 1.54 + [0xF3 ;; disable interrupts 1.55 + (write-data (+ 1 base-address) 1.56 + target-address test-data) 1.57 + (infinite-loop)])] 1.58 +;; (assert 1.59 + ;; (= test-data 1.60 + (-> (mid-game) 1.61 + tick tick tick 1.62 + (set-memory-range base-address test-kernel) 1.63 + (PC! base-address) 1.64 + 1.65 + ;;(run-moves (repeat 100 [])) 1.66 + ;;(memory) 1.67 + ;;vec 1.68 + ;;(subvec target-address 1.69 + ;; (+ target-address 1.70 + ;; (count test-data))) 1.71 + ;;println 1.72 + ))) 1.73 + 1.74 + 1.75 + 1.76 + 1.77 + 1.78 + 1.79 + 1.80 +(defn display-image-kernel [base-address ^BufferedImage image] 1.81 (let [gb-image (image->gb-image image)] 1.82 1.83 [(clear-music-registers) 1.84 @@ -455,17 +524,16 @@ 1.85 ;; section 1.86 1.87 1.88 - 1.89 ;; [ ] disable the display of OBJ tiles. 1.90 1.91 1.92 ;; [ ] reactivate the LCD display 1.93 1.94 1.95 - (infinite-loop) 1.96 + (infinite-loop)] 1.97 1.98 1.99 - ) 1.100 + )) 1.101 1.102 1.103