diff clojure/com/aurellem/run/music.clj @ 435:3939ad680681

workig on two voices using square wave generators.
author Robert McIntyre <rlm@mit.edu>
date Wed, 25 Apr 2012 12:35:53 -0500
parents 988f0fda6c93
children 3171cbe077f3
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/music.clj	Wed Apr 25 01:58:44 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/music.clj	Wed Apr 25 12:35:53 2012 -0500
     1.3 @@ -226,12 +226,20 @@
     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 +  
    1.13 +  (flatten
    1.14 +   [;; restore variables from stack
    1.15 +    0xE1 ;; pop HL
    1.16 +    0xC1 ;; pop CB
    1.17 +    0xF1 ;; pop AF
    1.18  
    1.19 -  (flatten
    1.20 -   [0xF5 ;; push A
    1.21 +
    1.22 +    0xF5 ;; push A
    1.23      0xF0
    1.24      0x05 ;; load current ticks from 0xF005
    1.25      0xB8 ;; 
    1.26 @@ -254,8 +262,17 @@
    1.27      (do-message sound-base-address)
    1.28      
    1.29      0x0E
    1.30 -    0x00])) ;; 0->C (current-ticks)
    1.31 +    0x00 ;; 0->C (current-ticks)
    1.32  
    1.33 +    ;; save variables to stack
    1.34 +    0xF5 ;; push AF
    1.35 +    0xC5 ;; push CB
    1.36 +    0xE5 ;; push HL
    1.37 +    
    1.38 +
    1.39 +    ]))
    1.40 +    
    1.41 +(def music-1 0x11)
    1.42  (def music-2 0x16)
    1.43  
    1.44  (defn music-kernel []
    1.45 @@ -273,7 +290,7 @@
    1.46      0xE0
    1.47      0x07 ;; set TAC to 65536 Hz and activate timer
    1.48  
    1.49 -    ;; local initilization section
    1.50 +    ;; initialize frame 1 
    1.51      0x21
    1.52      0x00
    1.53      0xD0 ;; set HL to 0xD000 == music-start
    1.54 @@ -281,12 +298,31 @@
    1.55      0x00 ;; 0->C
    1.56      0x06
    1.57      0x00 ;; 0->B
    1.58 +
    1.59      0xAF ;; 0->A
    1.60  
    1.61 +    0xF5 ;; push AF
    1.62 +    0xC5 ;; push CB
    1.63 +    0xE5 ;; push HL
    1.64  
    1.65 +    ;; initialize frame 2
    1.66 +    
    1.67 +    
    1.68 +    ;; init-2 (0->A,B,C), 0xC000 -> HL
    1.69 +
    1.70 +    ;; push to stack
    1.71 +
    1.72 +    ;; SP - 5
    1.73 +    ;; pop from stack
    1.74 +    (music-step music-1)
    1.75 +    ;; save to stack
    1.76      
    1.77  
    1.78 -    (music-step music-2)
    1.79 +    ;; SP + 5
    1.80 +    ;; pop from stack
    1.81 +    ;;(music-step music-2)
    1.82 +    ;; save to stack
    1.83 +
    1.84      0x18
    1.85      (->signed-8-bit (+ (- (count (music-step 0)))
    1.86                         -2))]))