comparison 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
comparison
equal deleted inserted replaced
434:988f0fda6c93 435:3939ad680681
224 ;; 0x18 ;; set frequency-low-bits 224 ;; 0x18 ;; set frequency-low-bits
225 225
226 ;; 0x2A ;; load duration 226 ;; 0x2A ;; load duration
227 ;; ]) 227 ;; ])
228 228
229 (def storage-start 0xC999)
230
229 (defn music-step [sound-base-address] 231 (defn music-step [sound-base-address]
230 ;; C == current-ticks 232 ;; C == current-ticks
231 ;; A == desired-ticks 233 ;; A == desired-ticks
232 234
233 (flatten 235 (flatten
234 [0xF5 ;; push A 236 [;; restore variables from stack
237 0xE1 ;; pop HL
238 0xC1 ;; pop CB
239 0xF1 ;; pop AF
240
241
242 0xF5 ;; push A
235 0xF0 243 0xF0
236 0x05 ;; load current ticks from 0xF005 244 0x05 ;; load current ticks from 0xF005
237 0xB8 ;; 245 0xB8 ;;
238 0x30 ;; increment C only if last result caused carry 246 0x30 ;; increment C only if last result caused carry
239 0x01 247 0x01
252 (+ (count (do-message 0)) 2) 260 (+ (count (do-message 0)) 2)
253 261
254 (do-message sound-base-address) 262 (do-message sound-base-address)
255 263
256 0x0E 264 0x0E
257 0x00])) ;; 0->C (current-ticks) 265 0x00 ;; 0->C (current-ticks)
258 266
267 ;; save variables to stack
268 0xF5 ;; push AF
269 0xC5 ;; push CB
270 0xE5 ;; push HL
271
272
273 ]))
274
275 (def music-1 0x11)
259 (def music-2 0x16) 276 (def music-2 0x16)
260 277
261 (defn music-kernel [] 278 (defn music-kernel []
262 (flatten 279 (flatten
263 [;; global initilization section 280 [;; global initilization section
271 0x3E 288 0x3E
272 (Integer/parseInt "00000110" 2) 289 (Integer/parseInt "00000110" 2)
273 0xE0 290 0xE0
274 0x07 ;; set TAC to 65536 Hz and activate timer 291 0x07 ;; set TAC to 65536 Hz and activate timer
275 292
276 ;; local initilization section 293 ;; initialize frame 1
277 0x21 294 0x21
278 0x00 295 0x00
279 0xD0 ;; set HL to 0xD000 == music-start 296 0xD0 ;; set HL to 0xD000 == music-start
280 0x0E 297 0x0E
281 0x00 ;; 0->C 298 0x00 ;; 0->C
282 0x06 299 0x06
283 0x00 ;; 0->B 300 0x00 ;; 0->B
301
284 0xAF ;; 0->A 302 0xAF ;; 0->A
285 303
286 304 0xF5 ;; push AF
287 305 0xC5 ;; push CB
288 306 0xE5 ;; push HL
289 (music-step music-2) 307
308 ;; initialize frame 2
309
310
311 ;; init-2 (0->A,B,C), 0xC000 -> HL
312
313 ;; push to stack
314
315 ;; SP - 5
316 ;; pop from stack
317 (music-step music-1)
318 ;; save to stack
319
320
321 ;; SP + 5
322 ;; pop from stack
323 ;;(music-step music-2)
324 ;; save to stack
325
290 0x18 326 0x18
291 (->signed-8-bit (+ (- (count (music-step 0))) 327 (->signed-8-bit (+ (- (count (music-step 0)))
292 -2))])) 328 -2))]))
293 329
294 (defn frequency-code->frequency 330 (defn frequency-code->frequency