diff clojure/com/aurellem/run/image.clj @ 510:b9814e3114e4

efficient data writing assembly complete.
author Robert McIntyre <rlm@mit.edu>
date Wed, 20 Jun 2012 22:49:31 -0500
parents d2c40a12de28
children 964957680c11
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/image.clj	Wed Jun 20 22:08:56 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/image.clj	Wed Jun 20 22:49:31 2012 -0500
     1.3 @@ -432,50 +432,53 @@
     1.4    "Efficient assembly to write a sequence of values to
     1.5     memory, starting at a target address."
     1.6    [base-address target-address data]
     1.7 -  (let [len (count data)]
     1.8 +  (let [len (count data)
     1.9 +        program-length 21] ;; change this if program length
    1.10 +        ;; below changes!
    1.11 +        
    1.12      (flatten
    1.13 -     (if (<= len 255)
    1.14         [0x21 ;; load data address start into HL
    1.15 -        (reverse (disect-bytes-2 (+ 16 base-address)))
    1.16 +        (reverse (disect-bytes-2 (+ base-address program-length)))
    1.17  
    1.18          0x01 ;; load target address into BC
    1.19          (reverse (disect-bytes-2 target-address))
    1.20          
    1.21 -        0x16 ;; load len into D
    1.22 -        len
    1.23 +        0x11 ;; load len into DE
    1.24 +        (reverse (disect-bytes-2 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 +        0x1B ;; DEC DE
    1.33  
    1.34 -        0x20 ;; if D is not now 0,
    1.35 -        (->signed-8-bit -6) ;; GOTO start
    1.36 +        0xAF
    1.37 +        0xB2 ;; (OR D E) -> A
    1.38 +        0xB3
    1.39 +
    1.40          
    1.41 -        0x18
    1.42 -        len
    1.43 +        0x20 ;; if DE is not now 0,
    1.44 +        (->signed-8-bit -9) ;; GOTO start
    1.45          
    1.46 -        data]
    1.47 -       (let [first-part (write-data base-address target-address
    1.48 -                                    (take 255 data))]
    1.49 -         [first-part 
    1.50 -          (write-data (+ base-address (count first-part))
    1.51 -                      (+ target-address 255)
    1.52 -                      (drop 255 data))])))))
    1.53 +        0xC3
    1.54 +        (reverse
    1.55 +         (disect-bytes-2
    1.56 +          (+ len base-address program-length)))
    1.57 +        data])))
    1.58 +
    1.59  
    1.60  (defn test-write-data []
    1.61 -  (let [test-data [0xDE 0xAD 0xBE 0xEF]
    1.62 -        base-address 0xA000
    1.63 -        target-address 0xC000
    1.64 +  (let [test-data (concat (range 256)
    1.65 +                          (reverse (range 256)))
    1.66 +        base-address 0xC000
    1.67 +        target-address 0xD000
    1.68  
    1.69          test-kernel
    1.70          (flatten
    1.71           [0xF3 ;; disable interrupts
    1.72            (write-data (+ 1 base-address)
    1.73                        target-address test-data)
    1.74 -          (clear-music-registers)
    1.75            (infinite-loop)])]
    1.76      (assert
    1.77       (= test-data
    1.78 @@ -483,7 +486,6 @@
    1.79              tick tick tick
    1.80              (set-memory-range base-address test-kernel)
    1.81              (PC! base-address)
    1.82 -            
    1.83              (run-moves (repeat 100 []))
    1.84              (memory)
    1.85              vec
    1.86 @@ -491,12 +493,6 @@
    1.87                      (+ target-address
    1.88                         (count test-data))))))))
    1.89  
    1.90 -    
    1.91 -        
    1.92 -    
    1.93 -
    1.94 -
    1.95 -
    1.96  (defn display-image-kernel [base-address ^BufferedImage image]
    1.97    (let [gb-image (image->gb-image image)]
    1.98