# HG changeset patch # User Robert McIntyre # Date 1335377346 18000 # Node ID 20a9d5faf47cfed80b80923eecf1fd6db2ae3152 # Parent 3171cbe077f32bb8114b1fb4539012ecf2776205 now I can play two voices at once! diff -r 3171cbe077f3 -r 20a9d5faf47c clojure/com/aurellem/run/music.clj --- a/clojure/com/aurellem/run/music.clj Wed Apr 25 12:41:30 2012 -0500 +++ b/clojure/com/aurellem/run/music.clj Wed Apr 25 13:09:06 2012 -0500 @@ -226,8 +226,6 @@ ;; 0x2A ;; load duration ;; ]) -(def storage-start 0xC999) - (defn music-step [sound-base-address] ;; C == current-ticks ;; A == desired-ticks @@ -293,7 +291,7 @@ ;; initialize frame 1 0x21 0x00 - 0xD0 ;; set HL to 0xD000 == music-start 1 + 0xA0 ;; set HL to 0xA000 == music-start 1 0x0E 0x00 ;; 0->C 0x06 @@ -308,33 +306,34 @@ ;; initialize frame 2 0x21 0x00 - 0xC0 ;; set HL to 0xC000 == music-start 2 + 0xB0 ;; set HL to 0xB000 == music-start 2 0xF5 ;; push AF 0xC5 ;; push CB 0xE5 ;; push HL + ;; main music loop + + 0xE8 ;; SP + 6; activate frame 1 + 6 + (music-step music-1) + ;;(repeat (count (music-step music-1)) 0x00) - ;; init-2 (0->A,B,C), 0xC000 -> HL - - ;; push to stack - - 0xE8 ;; SP + 8 - 6 - ;; pop from stack - (music-step music-1) - ;; save to stack + 0xE8 ;; SP - 6; activate frame 2 + (->signed-8-bit -6) + ;;(repeat (count (music-step music-2)) 0x00) + (music-step music-2) - ;; SP + 5 - ;; pop from stack - ;;(music-step music-2) - ;; save to stack - 0x18 - (->signed-8-bit (+ (- (count (music-step 0))) - -2))])) + (->signed-8-bit (+ + ;; two music-steps + (- (* 2 (count (music-step 0)))) + -2 ;; this jump instruction + -2 ;; activate frame 1 + -2 ;; activate frame 2 + ))])) (defn frequency-code->frequency [code] @@ -471,22 +470,22 @@ (defn play-music [music-bytes] (let [program-target 0xC000 - music-target 0xD000] + music-target 0xA000] (-> (set-memory-range (second (music-base)) program-target (music-kernel)) (set-memory-range music-target music-bytes) (PC! program-target)))) -(defn test-note [music-bytes] - (-> (set-memory-range (second (music-base)) - 0xC000 (concat (clear-music-registers) - (play-note) - (infinite-loop))) - (set-memory-range 0xD000 music-bytes) - (PC! 0xC000) - (HL! 0xD000) - )) +;; (defn test-note [music-bytes] +;; (-> (set-memory-range (second (music-base)) +;; 0xC000 (concat (clear-music-registers) +;; (play-note) +;; (infinite-loop))) +;; (set-memory-range 0xD000 music-bytes) +;; (PC! 0xC000) +;; (HL! 0xD000) +;; )) (defn run-program