# HG changeset patch # User Robert McIntyre # Date 1334662577 18000 # Node ID f211cd655ccbb9edabff778375d0ddeb3fa7980e # Parent 0b6624c1291c60d13886fbe11876107050fa4b57 completed basic music playing kernel diff -r 0b6624c1291c -r f211cd655ccb clojure/com/aurellem/run/music.clj --- a/clojure/com/aurellem/run/music.clj Mon Apr 16 14:08:56 2012 -0500 +++ b/clojure/com/aurellem/run/music.clj Tue Apr 17 06:36:17 2012 -0500 @@ -83,9 +83,9 @@ 0x18 ;; set frequency-low-bits 0x7E ;; load duration - ;;0x2B ;; - ;;0x2B - ]) ;; HL-2 -> HL + 0x2B ;; + 0x2B ;; HL-2 -> HL + ]) (defn music-step [] (flatten @@ -93,14 +93,14 @@ 0xF5 ;; push A 0xF0 0x05 ;; load current ticks - 0x90 ;; B holds previous sub-ticks, subtract it from A + 0xB8 ;; B holds previous sub-ticks, subtract it from A ;; if A-B caused a carry, then (B > A) is true, and ;; A = current-sub-tics, B = previous-sub-ticks, so ;; current-sub-ticks < previous-sub-ticks, which means that the ;; timer counter HAS overflowed. 0x30 ;; increment C only if last result caused carry 0x01 - 0x00;;0x0C + 0x0C 0x47 ;; update sub-ticks (A->B) @@ -121,9 +121,28 @@ 0x0E 0x00])) ;; 0->C (current-ticks) +(defn test-timer [] + (flatten + [0x3E + 0x01 + 0xE0 + 0x06 ;; set TMA to 0 + + 0x3E + (Integer/parseInt "00000100" 2) + 0xE0 + 0x07 ;; set TAC to 16384 Hz and activate timer + + (repeat + 500 + [0xF0 + 0x05])])) + + (defn music-kernel [] (flatten [(clear-music-registers) + 0x21 0x00 0xD0 ;; set HL to 0xD000 == music-start @@ -133,22 +152,40 @@ 0x00 ;; 0->B 0x3E - 0x00 + 0x01 0xE0 0x06 ;; set TMA to 0 0x3E (Integer/parseInt "00000111" 2) 0xE0 - 0x07 ;; set TAC to 16384 Hz + 0x07 ;; set TAC to 16384 Hz and activate timer + 0xF0 + 0x07 + (music-step) 0x18 (->signed-8-bit (+ (- (count (music-step))) -2))])) +(def one-note + [0xA0 0x00 0xFF]) -(defn play-music [steps music-bytes] +(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 + 0xA7 0x00 0x55]) + +(defn play-music [music-bytes] (let [program-target 0xC000 music-target 0xD000] (-> (set-memory-range (second (music-base)) @@ -169,11 +206,12 @@ (defn run-program - ([program] (run-program program 90)) - ([program steps] + ([program] (let [target 0xC000] (-> (set-memory-range (second (music-base)) target program) (PC! target))))) +(defn trippy [] + (run-moves (play-music many-notes ) (repeat 8000 [])))