changeset 537:04f61ade7879

allow repositioning of music data.
author Robert McIntyre <rlm@mit.edu>
date Mon, 25 Jun 2012 14:50:28 -0500
parents c2ee7222a3c4
children 3ebd321f198e
files clojure/com/aurellem/run/choreo.clj clojure/com/aurellem/run/music.clj
diffstat 2 files changed, 32 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/choreo.clj	Mon Jun 25 14:23:16 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/choreo.clj	Mon Jun 25 14:50:28 2012 -0500
     1.3 @@ -3,7 +3,8 @@
     1.4                           items vbm characters money
     1.5                           rlm-assembly))
     1.6    (:use (com.aurellem.run util music title save-corruption
     1.7 -                          bootstrap-0 bootstrap-1 image))
     1.8 +                          bootstrap-0 bootstrap-1 image
     1.9 +                          ram-display))
    1.10    (:require clojure.string)
    1.11    (:import [com.aurellem.gb.gb_driver SaveState])
    1.12    (:import java.io.File))
    1.13 @@ -26,22 +27,25 @@
    1.14  
    1.15  
    1.16  (defn-memo write-pony-music-data
    1.17 -  ([] (write-pony-music-data (silence-noise)))
    1.18 +  ([] (write-pony-music-data (launch-main-bootstrap-program)))
    1.19    ([script]
    1.20       (let [bytes (midi-bytes pony-csv)]
    1.21         (->> script
    1.22 +            (do-nothing 10)
    1.23              (write-RAM (:address (:voice-1 bytes))
    1.24                         (:data    (:voice-1 bytes)))
    1.25  
    1.26 +            (do-nothing 100)
    1.27              (write-RAM (:address (:voice-2 bytes))
    1.28                         (:data    (:voice-2 bytes)))
    1.29  
    1.30 +            (do-nothing 100)
    1.31              (write-RAM (:address (:noise bytes))
    1.32                         (:data    (:noise bytes)))
    1.33  
    1.34 +            (do-nothing 100)
    1.35              (write-RAM (:address (:kernel bytes))
    1.36                         (:data    (:kernel bytes)))
    1.37 -
    1.38              (transfer-control (:address (:kernel bytes)))))))
    1.39  
    1.40  
     2.1 --- a/clojure/com/aurellem/run/music.clj	Mon Jun 25 14:23:16 2012 -0500
     2.2 +++ b/clojure/com/aurellem/run/music.clj	Mon Jun 25 14:50:28 2012 -0500
     2.3 @@ -325,7 +325,12 @@
     2.4  (def music-1 0x11)
     2.5  (def music-2 0x16)
     2.6  
     2.7 -(defn music-kernel [wave-duty-1 wave-duty-2]
     2.8 +(defn music-kernel
     2.9 +  [voice-1-address
    2.10 +   voice-2-address
    2.11 +   noise-address
    2.12 +   voice-1-wave-duty
    2.13 +   voice-2-wave-duty]
    2.14    (flatten
    2.15     [;; global initilization section
    2.16      (clear-music-registers)
    2.17 @@ -342,8 +347,8 @@
    2.18  
    2.19      ;; initialize frame 1 
    2.20      0x21
    2.21 -    0x00
    2.22 -    0xA0 ;; set HL to 0xA000 == music-start 1
    2.23 +    (reverse (disect-bytes-2 voice-1-address))
    2.24 +    ;; set HL to voice-1-address
    2.25      0x0E
    2.26      0x00 ;; 0->C
    2.27      0x06
    2.28 @@ -357,8 +362,8 @@
    2.29  
    2.30      ;; initialize frame 2
    2.31      0x21
    2.32 -    0x00
    2.33 -    0xB0 ;; set HL to 0xB000 == music-start 2
    2.34 +    (reverse (disect-bytes-2 voice-2-address))
    2.35 +    ;; set HL to voice-2-address
    2.36  
    2.37      0xF5 ;; push AF
    2.38      0xC5 ;; push CB
    2.39 @@ -367,8 +372,8 @@
    2.40  
    2.41      ;; initialize frame 3 (noise)
    2.42      0x21
    2.43 -    0x00
    2.44 -    0xA9 ;; 0xA9OO -> HL
    2.45 +    (reverse (disect-bytes-2 noise-address))
    2.46 +    ;; set HL to noise-address
    2.47  
    2.48      0xF5 ;; push AF
    2.49      0xC5 ;; push CB
    2.50 @@ -378,11 +383,11 @@
    2.51  
    2.52      0xE8 ;; SP + 12; activate frame 1
    2.53      12
    2.54 -    (music-step music-1 wave-duty-1 false)
    2.55 +    (music-step music-1 voice-1-wave-duty false)
    2.56      
    2.57      0xE8 ;; SP - 6; activate frame 2
    2.58      (->signed-8-bit -6)
    2.59 -    (music-step music-2 wave-duty-2 false)
    2.60 +    (music-step music-2 voice-1-wave-duty false)
    2.61  
    2.62      0xE8 ;; SP - 6;  activate frame 3
    2.63      (->signed-8-bit -6)
    2.64 @@ -581,14 +586,14 @@
    2.65                        (map #(get % :duty 0) duty-info))}))
    2.66  
    2.67  (defn midi-bytes [^File midi-file]
    2.68 -  (let [voice-1-target 0xA000
    2.69 -        voice-2-target 0xB000
    2.70 -        noise-target   0xA900
    2.71 +  (let [voice-1-target 0xC400
    2.72 +        voice-2-target 0xC800
    2.73 +        noise-target   0xCC00
    2.74          program-target 0xC000
    2.75          mini-midi (midi->mini-midi midi-file)
    2.76 -        long-silence (flatten (note-codes 20 0 5000))
    2.77 +        long-silence (flatten (note-codes 20 0 3000))
    2.78          long-noise-silence 
    2.79 -        (interleave (range 100) (repeat 0x00) (repeat 255))
    2.80 +        (interleave (range 20) (repeat 0x00) (repeat 255))
    2.81          voice-1 (flatten (:voice-1 mini-midi))
    2.82          wave-duty-1 ((:duty mini-midi) 0 0)
    2.83  
    2.84 @@ -596,7 +601,11 @@
    2.85          wave-duty-2 ((:duty mini-midi) 1 0)
    2.86  
    2.87          noise (flatten (:noise mini-midi))
    2.88 -        kernel (music-kernel wave-duty-1 wave-duty-2)]
    2.89 +        kernel (music-kernel
    2.90 +                voice-1-target
    2.91 +                voice-2-target
    2.92 +                noise-target
    2.93 +                wave-duty-1 wave-duty-2)]
    2.94      
    2.95      {:voice-1 {:address voice-1-target
    2.96                 :data  (concat voice-1 long-silence)}
    2.97 @@ -605,7 +614,7 @@
    2.98       :noise   {:address noise-target
    2.99                 :data (concat noise long-noise-silence)}
   2.100       :kernel  {:address program-target
   2.101 -               :data (music-kernel wave-duty-1 wave-duty-2)}}))
   2.102 +               :data kernel}}))
   2.103  
   2.104  (defn play-midi [^File midi-file]
   2.105    (let [bytes (midi-bytes midi-file)]