Mercurial > vba-clojure
diff clojure/com/aurellem/run/music.clj @ 433:985c90ffa1fe
paramaterized do-message
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 25 Apr 2012 01:56:39 -0500 |
parents | 8e88366a81b9 |
children | 988f0fda6c93 |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/run/music.clj Tue Apr 24 23:51:30 2012 -0500 1.2 +++ b/clojure/com/aurellem/run/music.clj Wed Apr 25 01:56:39 2012 -0500 1.3 @@ -114,11 +114,11 @@ 1.4 1.5 (defn clear-music-registers [] 1.6 (flatten 1.7 - [(store (Integer/parseInt "00000000" 2) 0xFF10) 1.8 - (store (Integer/parseInt "00000000" 2) 0xFF11) 1.9 - (store (Integer/parseInt "00000000" 2) 0xFF12) 1.10 - (store (Integer/parseInt "00000000" 2) 0xFF13) 1.11 - (store (Integer/parseInt "00000000" 2) 0xFF14) 1.12 + [(store (Integer/parseInt "00000000" 2) 0xFF10) ;; sweep 1.13 + (store (Integer/parseInt "00000000" 2) 0xFF11) ;; pattern duty 1.14 + (store (Integer/parseInt "00000000" 2) 0xFF12) ;; volume 1.15 + (store (Integer/parseInt "00000000" 2) 0xFF13) ;; frequency-low 1.16 + (store (Integer/parseInt "00000000" 2) 0xFF14) ;; frequency-high 1.17 1.18 (store (Integer/parseInt "00000000" 2) 0xFF16) ;; pattern duty 000000 1.19 (store (Integer/parseInt "00000000" 2) 0xFF17) ;; volume 0000 1.20 @@ -131,10 +131,11 @@ 1.21 (store (Integer/parseInt "00000000" 2) 0xFF1D) 1.22 (store (Integer/parseInt "00000000" 2) 0xFF1E) 1.23 1.24 - (store (Integer/parseInt "00000000" 2) 0xFF20) 1.25 - (store (Integer/parseInt "00000000" 2) 0xFF21) 1.26 - (store (Integer/parseInt "00000000" 2) 0xFF22) 1.27 - (store (Integer/parseInt "00000000" 2) 0xFF23)])) 1.28 + (store (Integer/parseInt "00000000" 2) 0xFF20) ;; length 1.29 + (store (Integer/parseInt "00000000" 2) 0xFF21) ;; volume 1.30 + (store (Integer/parseInt "00000000" 2) 0xFF22) ;; noise-frequency 1.31 + (store (Integer/parseInt "00000000" 2) 0xFF23) ;; control 1.32 + ])) 1.33 1.34 1.35 ;; mini-midi syntax 1.36 @@ -169,69 +170,68 @@ 1.37 "Read the message which starts at the current value of HL and do 1.38 what it says. Duration is left in A, and HL is advanced 1.39 appropraitely." 1.40 - [] 1.41 - (let [switch 1.42 - [0x2A ;; load message code into A, increment HL 1.43 - 1.44 - ;; switch on message 1.45 - 0xFE 1.46 - note-code 1.47 - 1.48 - 0x20 1.49 - :note-length] 1.50 + ([] (do-message 0x16)) 1.51 + ([sound-base-address] 1.52 + (let [switch 1.53 + [0x2A ;; load message code into A, increment HL 1.54 + 1.55 + ;; switch on message 1.56 + 0xFE 1.57 + note-code 1.58 + 1.59 + 0x20 1.60 + :note-length] 1.61 1.62 - play-note 1.63 - [0x2A ;; load volume/frequency-high info 1.64 - 0xF5 ;; push A 1.65 - 0xE6 1.66 - (Integer/parseInt "11110000" 2) ;; volume mask 1.67 - 0xE0 1.68 - 0x17 ;; set volume 1.69 - 0xF1 ;; pop A 1.70 - 0xE6 1.71 - (Integer/parseInt "00000111" 2) ;; frequency-high mask 1.72 - 0xE0 1.73 - 0x19 ;; set frequency-high 1.74 - 1.75 - 0x2A ;; load frequency low-bits 1.76 - 0xE0 1.77 - 0x18 ;; set frequency-low-bits 1.78 - 1.79 - 0x2A]] ;; load duration 1.80 - (replace 1.81 - {:note-length (count play-note)} 1.82 - (concat switch play-note)))) 1.83 + play-note 1.84 + [0x2A ;; load volume/frequency-high info 1.85 + 0xF5 ;; push A 1.86 + 0xE6 1.87 + (Integer/parseInt "11110000" 2) ;; volume mask 1.88 + 0xE0 1.89 + (inc sound-base-address) ;;0x17 ;; set volume 1.90 + 0xF1 ;; pop A 1.91 + 0xE6 1.92 + (Integer/parseInt "00000111" 2) ;; frequency-high mask 1.93 + 0xE0 1.94 + (+ 3 sound-base-address) ;;0x19 ;; set frequency-high 1.95 + 1.96 + 0x2A ;; load frequency low-bits 1.97 + 0xE0 1.98 + (+ 2 sound-base-address) ;;0x18 ;; set frequency-low-bits 1.99 + 0x2A]] ;; load duration 1.100 + (replace 1.101 + {:note-length (count play-note)} 1.102 + (concat switch play-note))))) 1.103 1.104 -(defn play-note 1.105 - "Play the note referenced by HL in the appropiate channel. 1.106 - Leaves desired-duration in A." 1.107 - [] 1.108 - [0x2A ;; load volume/frequency-high info 1.109 - 0xF5 ;; push A 1.110 - 0xE6 1.111 - (Integer/parseInt "11110000" 2) ;; volume mask 1.112 - 0xE0 1.113 - 0x17 ;; set volume 1.114 - 0xF1 ;; pop A 1.115 - 0xE6 1.116 - (Integer/parseInt "00000111" 2) ;; frequency-high mask 1.117 - 0xE0 1.118 - 0x19 ;; set frequency-high 1.119 +;; (defn play-note 1.120 +;; "Play the note referenced by HL in the appropiate channel. 1.121 +;; Leaves desired-duration in A." 1.122 + 1.123 +;; [0x2A ;; load volume/frequency-high info 1.124 +;; 0xF5 ;; push A 1.125 +;; 0xE6 1.126 +;; (Integer/parseInt "11110000" 2) ;; volume mask 1.127 +;; 0xE0 1.128 +;; 0x17 ;; set volume 1.129 +;; 0xF1 ;; pop A 1.130 +;; 0xE6 1.131 +;; (Integer/parseInt "00000111" 2) ;; frequency-high mask 1.132 +;; 0xE0 1.133 +;; 0x19 ;; set frequency-high 1.134 1.135 - 0x2A ;; load frequency low-bits 1.136 - 0xE0 1.137 - 0x18 ;; set frequency-low-bits 1.138 +;; 0x2A ;; load frequency low-bits 1.139 +;; 0xE0 1.140 +;; 0x18 ;; set frequency-low-bits 1.141 1.142 - 0x2A ;; load duration 1.143 - ]) 1.144 +;; 0x2A ;; load duration 1.145 +;; ]) 1.146 1.147 (defn music-step [] 1.148 ;; C == current-ticks 1.149 ;; A == desired-ticks 1.150 1.151 (flatten 1.152 - [ 1.153 - 0xF5 ;; push A 1.154 + [0xF5 ;; push A 1.155 0xF0 1.156 0x05 ;; load current ticks from 0xF005 1.157 0xB8 ;; 1.158 @@ -279,11 +279,10 @@ 1.159 0x00 ;; 0->C 1.160 0x06 1.161 0x00 ;; 0->B 1.162 + 0xAF ;; 0->A 1.163 1.164 1.165 - 1.166 - 0xAF ;; initialiaze A to zero 1.167 - 1.168 + 1.169 1.170 (music-step) 1.171 0x18