diff clojure/com/aurellem/run/music.clj @ 437:20a9d5faf47c

now I can play two voices at once!
author Robert McIntyre <rlm@mit.edu>
date Wed, 25 Apr 2012 13:09:06 -0500
parents 3171cbe077f3
children 067ea3f0d951
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/music.clj	Wed Apr 25 12:41:30 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/music.clj	Wed Apr 25 13:09:06 2012 -0500
     1.3 @@ -226,8 +226,6 @@
     1.4  ;;    0x2A   ;; load duration
     1.5  ;;    ]) 
     1.6  
     1.7 -(def storage-start 0xC999)
     1.8 -
     1.9  (defn music-step [sound-base-address]
    1.10    ;; C == current-ticks
    1.11    ;; A == desired-ticks
    1.12 @@ -293,7 +291,7 @@
    1.13      ;; initialize frame 1 
    1.14      0x21
    1.15      0x00
    1.16 -    0xD0 ;; set HL to 0xD000 == music-start 1
    1.17 +    0xA0 ;; set HL to 0xA000 == music-start 1
    1.18      0x0E
    1.19      0x00 ;; 0->C
    1.20      0x06
    1.21 @@ -308,33 +306,34 @@
    1.22      ;; initialize frame 2
    1.23      0x21
    1.24      0x00
    1.25 -    0xC0 ;; set HL to 0xC000 == music-start 2
    1.26 +    0xB0 ;; set HL to 0xB000 == music-start 2
    1.27  
    1.28      0xF5 ;; push AF
    1.29      0xC5 ;; push CB
    1.30      0xE5 ;; push HL
    1.31  
    1.32  
    1.33 +    ;; main music loop
    1.34 +
    1.35 +    0xE8 ;; SP + 6; activate frame 1
    1.36 +    6
    1.37 +    (music-step music-1)
    1.38 +    ;;(repeat (count (music-step music-1)) 0x00)
    1.39      
    1.40 -    ;; init-2 (0->A,B,C), 0xC000 -> HL
    1.41 -
    1.42 -    ;; push to stack
    1.43 -
    1.44 -    0xE8 ;; SP + 8
    1.45 -    6
    1.46 -    ;; pop from stack
    1.47 -    (music-step music-1)
    1.48 -    ;; save to stack
    1.49 +    0xE8 ;; SP - 6; activate frame 2
    1.50 +    (->signed-8-bit -6)
    1.51 +    ;;(repeat (count (music-step music-2)) 0x00)
    1.52 +    (music-step music-2)
    1.53      
    1.54  
    1.55 -    ;; SP + 5
    1.56 -    ;; pop from stack
    1.57 -    ;;(music-step music-2)
    1.58 -    ;; save to stack
    1.59 -
    1.60      0x18
    1.61 -    (->signed-8-bit (+ (- (count (music-step 0)))
    1.62 -                       -2))]))
    1.63 +    (->signed-8-bit (+
    1.64 +                     ;; two music-steps
    1.65 +                     (- (* 2 (count (music-step 0))))
    1.66 +                     -2 ;; this jump instruction
    1.67 +                     -2 ;; activate frame 1
    1.68 +                     -2 ;; activate frame 2
    1.69 +                     ))]))
    1.70  
    1.71  (defn frequency-code->frequency
    1.72    [code]
    1.73 @@ -471,22 +470,22 @@
    1.74                   
    1.75  (defn play-music [music-bytes]
    1.76    (let [program-target 0xC000
    1.77 -        music-target 0xD000]
    1.78 +        music-target 0xA000]
    1.79      (-> (set-memory-range (second (music-base))
    1.80                            program-target (music-kernel))
    1.81          (set-memory-range music-target music-bytes)
    1.82          (PC! program-target))))
    1.83  
    1.84  
    1.85 -(defn test-note [music-bytes]
    1.86 -  (-> (set-memory-range (second (music-base))
    1.87 -                        0xC000 (concat (clear-music-registers)
    1.88 -                                       (play-note)
    1.89 -                                       (infinite-loop)))
    1.90 -      (set-memory-range 0xD000 music-bytes)
    1.91 -      (PC! 0xC000)
    1.92 -      (HL! 0xD000)
    1.93 -      ))
    1.94 +;; (defn test-note [music-bytes]
    1.95 +;;   (-> (set-memory-range (second (music-base))
    1.96 +;;                         0xC000 (concat (clear-music-registers)
    1.97 +;;                                        (play-note)
    1.98 +;;                                        (infinite-loop)))
    1.99 +;;       (set-memory-range 0xD000 music-bytes)
   1.100 +;;       (PC! 0xC000)
   1.101 +;;       (HL! 0xD000)
   1.102 +;;       ))
   1.103  
   1.104  
   1.105  (defn run-program