# HG changeset patch # User Robert McIntyre # Date 1335177925 18000 # Node ID df4e03672b05d64eed37e763bff9d475e2193700 # Parent 7bd806c4dbb608cca06d028a4bec0f232fa6ad99 implemented note-code message. diff -r 7bd806c4dbb6 -r df4e03672b05 clojure/com/aurellem/run/music.clj --- a/clojure/com/aurellem/run/music.clj Mon Apr 23 04:45:55 2012 -0500 +++ b/clojure/com/aurellem/run/music.clj Mon Apr 23 05:45:25 2012 -0500 @@ -87,18 +87,47 @@ ;; [change-duty-code (0x01)] ;; [new-duty] +(def note-code 0x00) +(def change-duty-code 0x01) +(def silence-code 0x02) + + (defn do-message "Read the message which starts at the current value of HL and do what it says. Duration is left in A, and HL is advanced appropraitely." [] + (let [switch + [0x2A ;; load message code into A, increment HL + + ;; switch on message + 0xFE + note-code + + 0x20 + :note-length] - ) - - - - - + play-note + [0x2A ;; load volume/frequency-high info + 0xF5 ;; push A + 0xE6 + (Integer/parseInt "11110000" 2) ;; volume mask + 0xE0 + 0x17 ;; set volume + 0xF1 ;; pop A + 0xE6 + (Integer/parseInt "00000111" 2) ;; frequency-high mask + 0xE0 + 0x19 ;; set frequency-high + + 0x2A ;; load frequency low-bits + 0xE0 + 0x18 ;; set frequency-low-bits + + 0x2A]] ;; load duration + (replace + {:note-length (count play-note)} + (concat switch play-note)))) (defn play-note "Play the note referenced by HL in the appropiate channel. @@ -148,9 +177,9 @@ ;; go to next note ; set current set ticks to 0. 0x20 - (+ (count (play-note)) 2) + (+ (count (do-message)) 2) - (play-note) + (do-message) 0x0E 0x00])) ;; 0->C (current-ticks) @@ -186,26 +215,6 @@ (->signed-8-bit (+ (- (count (music-step))) -2))])) -(def one-note - [0xA0 0x00 0xFF]) - -(def many-notes - (flatten (repeat 10 one-note))) - -(def increasing-notes - [0xA0 0x00 0x55 - 0xA1 0x00 0x55 - 0xA2 0x00 0x55 - 0xA3 0x00 0x55 - 0xA4 0x00 0x55 - 0xA5 0x00 0x55 - 0xA6 0x00 0x55 - 0xA6 0x55 0xFF - 0xA6 0x55 0xFF - 0xA6 0x55 0xFF - 0x00 0x00 0xFF - ]) - (defn frequency-code->frequency [code] (assert (<= 0 code 2047)) @@ -234,7 +243,8 @@ (bit-shift-right frequency-code 8)) low-frequency (bit-and 0xFF frequency-code)] - [volume&high-frequency + [note-code + volume&high-frequency low-frequency duration]))