changeset 541:cd557c922cec

working on basic choreo.
author Robert McIntyre <rlm@mit.edu>
date Mon, 25 Jun 2012 15:32:16 -0500
parents 7f8030812ac2
children 614eddc5b38c
files clojure/com/aurellem/run/basic_choreo.clj clojure/com/aurellem/run/bootstrap_1.clj clojure/com/aurellem/run/choreo.clj clojure/com/aurellem/run/music.clj
diffstat 4 files changed, 117 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/clojure/com/aurellem/run/basic_choreo.clj	Mon Jun 25 15:32:16 2012 -0500
     1.3 @@ -0,0 +1,72 @@
     1.4 +(ns com.aurellem.run.basic_choreo
     1.5 +  (:use (com.aurellem.gb saves gb-driver util constants
     1.6 +                         items vbm characters money
     1.7 +                         rlm-assembly))
     1.8 +  (:use (com.aurellem.run util music title save-corruption
     1.9 +                          bootstrap-0 bootstrap-1 image
    1.10 +                          ram-display))
    1.11 +  (:require clojure.string)
    1.12 +  (:import [com.aurellem.gb.gb_driver SaveState])
    1.13 +  (:import java.io.File))
    1.14 +
    1.15 +
    1.16 +
    1.17 +;; take over game
    1.18 +;; [X] silence noise
    1.19 +;; [ ] run picture program to display pinkie pie mark
    1.20 +;; [ ] play pony song 
    1.21 +
    1.22 +
    1.23 +(defn-memo silence-noise
    1.24 +  ([] (silence-noise (relocate-main-bootstrap)))
    1.25 +  ([script]
    1.26 +     (->> script
    1.27 +          (write-RAM 0xFF1A [0 0 0]))))
    1.28 +
    1.29 +(def music-program-start 0xC000)
    1.30 +(def image-program-start 0xCE00)
    1.31 +
    1.32 +(defn-memo write-pony-music-data
    1.33 +  ([] (write-pony-music-data (silence-noise)))
    1.34 +  ([script]
    1.35 +     (let [bytes (midi-bytes
    1.36 +                  pony-csv
    1.37 +                  0xC400
    1.38 +                  0xC800
    1.39 +                  0xCC00
    1.40 +                  0xC000)]
    1.41 +       (->> script
    1.42 +            (write-RAM (:address (:voice-1 bytes))
    1.43 +                       (:data    (:voice-1 bytes)))
    1.44 +            (write-RAM (:address (:voice-2 bytes))
    1.45 +                       (:data    (:voice-2 bytes)))
    1.46 +            (write-RAM (:address (:noise bytes))
    1.47 +                       (:data    (:noise bytes)))
    1.48 +            (write-RAM (:address (:kernel bytes))
    1.49 +                       (:data    (:kernel bytes)))))))
    1.50 +
    1.51 +(defn-memo write-image-display-program
    1.52 +  ([] (write-image-display-program (write-pony-music-data)))
    1.53 +  ([script]
    1.54 +     (let [return-to-bootstrap
    1.55 +           (flatten
    1.56 +            [0xC3
    1.57 +             (disect-bytes-2 relocated-bootstrap-start)])]
    1.58 +       (->> script
    1.59 +            (write-RAM
    1.60 +             image-program-start
    1.61 +             (concat
    1.62 +              (display-image-kernel
    1.63 +               image-program-start
    1.64 +               pinkie-pie-mark)
    1.65 +              return-to-bootstrap))))))
    1.66 +     
    1.67 +(defn-memo activate-media
    1.68 +  ([] (activate-media (write-image-display-program)))
    1.69 +  ([script]
    1.70 +     (->> script
    1.71 +          (transfer-control image-program-start)
    1.72 +          (do-nothing 100)
    1.73 +          (transfer-control music-program-start))))
    1.74 +
    1.75 +
     2.1 --- a/clojure/com/aurellem/run/bootstrap_1.clj	Mon Jun 25 15:08:52 2012 -0500
     2.2 +++ b/clojure/com/aurellem/run/bootstrap_1.clj	Mon Jun 25 15:32:16 2012 -0500
     2.3 @@ -791,14 +791,16 @@
     2.4              (play-moves
     2.5               (take 253 (interleave (repeat 1000 [:b])
     2.6                                     (repeat 1000 [])))))))
     2.7 +(def bootstrap-start pokemon-list-start)
     2.8  
     2.9  (defn test-main-bootstrap-integrety
    2.10    []
    2.11    (assert
    2.12     (= (main-bootstrap-program)
    2.13 -      (subvec (vec (memory (second (launch-main-bootstrap-program))))
    2.14 -              pokemon-list-start
    2.15 -              (+ pokemon-list-start (count (main-bootstrap-program)))))))
    2.16 +      (subvec
    2.17 +       (vec (memory (second (launch-main-bootstrap-program))))
    2.18 +       pokemon-list-start
    2.19 +       (+ pokemon-list-start (count (main-bootstrap-program)))))))
    2.20     
    2.21  (defn set-target-address
    2.22    "Assumes that the game is under control of the main-bootstrap
    2.23 @@ -845,18 +847,22 @@
    2.24         (set-target-address target-address)
    2.25         (play-moves [(buttons jump-mode)])))
    2.26  
    2.27 -(def box-target (+ 90 pokemon-box-1-address))
    2.28 +
    2.29 +(def relocated-bootstrap-start
    2.30 +  (+ 90 pokemon-box-1-address))
    2.31  
    2.32  (defn-memo relocate-main-bootstrap
    2.33    ([] (relocate-main-bootstrap (launch-main-bootstrap-program)))
    2.34    ([script]
    2.35 -     (let [target (+ 90 pokemon-box-1-address)]
    2.36 -       (->> script
    2.37 -            (do-nothing 2)
    2.38 -            (write-RAM target (main-bootstrap-program target))
    2.39 -            (do-nothing 1)
    2.40 -            (transfer-control target)
    2.41 -            (do-nothing 1)))))
    2.42 +     (->> script
    2.43 +          (do-nothing 2)
    2.44 +          (write-RAM
    2.45 +           relocated-bootstrap-start
    2.46 +           (main-bootstrap-program
    2.47 +            relocated-bootstrap-start))
    2.48 +          (do-nothing 1)
    2.49 +          (transfer-control relocated-bootstrap-start)
    2.50 +          (do-nothing 1))))
    2.51  
    2.52  (defn gen-new-kernel-checkpoint! []
    2.53    (write-script! (do-nothing 10 (relocate-main-bootstrap))
    2.54 @@ -864,7 +870,6 @@
    2.55  
    2.56  (defn new-kernel [] (read-script "new-kernel"))
    2.57  
    2.58 -
    2.59  (def mid-game-data
    2.60    (subvec (vec (memory (mid-game)))
    2.61            pokemon-list-start
     3.1 --- a/clojure/com/aurellem/run/choreo.clj	Mon Jun 25 15:08:52 2012 -0500
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,49 +0,0 @@
     3.4 -(ns com.aurellem.run.choreo
     3.5 -  (:use (com.aurellem.gb saves gb-driver util constants
     3.6 -                         items vbm characters money
     3.7 -                         rlm-assembly))
     3.8 -  (:use (com.aurellem.run util music title save-corruption
     3.9 -                          bootstrap-0 bootstrap-1 image
    3.10 -                          ram-display))
    3.11 -  (:require clojure.string)
    3.12 -  (:import [com.aurellem.gb.gb_driver SaveState])
    3.13 -  (:import java.io.File))
    3.14 -
    3.15 -
    3.16 -
    3.17 -;; take over game
    3.18 -;; [X] silence noise
    3.19 -;; [ ] run picture program to display pinkie pie mark
    3.20 -;; [ ] play pony song 
    3.21 -
    3.22 -
    3.23 -(defn-memo silence-noise
    3.24 -  ([] (silence-noise (launch-main-bootstrap-program)))
    3.25 -  ([script]
    3.26 -     (->> script
    3.27 -          (write-RAM 0xFF1A [0 0 0]))))
    3.28 -
    3.29 -(def program-target 0xC000)
    3.30 -
    3.31 -(defn-memo write-pony-music-data
    3.32 -  ([] (write-pony-music-data (silence-noise)))
    3.33 -  ([script]
    3.34 -     (let [bytes (midi-bytes pony-csv)]
    3.35 -       (->> script
    3.36 -            (write-RAM (:address (:voice-1 bytes))
    3.37 -                       (:data    (:voice-1 bytes)))
    3.38 -            (write-RAM (:address (:voice-2 bytes))
    3.39 -                       (:data    (:voice-2 bytes)))
    3.40 -            (write-RAM (:address (:noise bytes))
    3.41 -                       (:data    (:noise bytes)))
    3.42 -            (write-RAM (:address (:kernel bytes))
    3.43 -                       (:data    (:kernel bytes)))))))
    3.44 -
    3.45 -(defn-memo write-image-display-program
    3.46 -  ([] (write-image-display-program (write-pony-music-data)))
    3.47 -  ([script]
    3.48 -     
    3.49 -
    3.50 -
    3.51 -
    3.52 -
     4.1 --- a/clojure/com/aurellem/run/music.clj	Mon Jun 25 15:08:52 2012 -0500
     4.2 +++ b/clojure/com/aurellem/run/music.clj	Mon Jun 25 15:32:16 2012 -0500
     4.3 @@ -585,36 +585,36 @@
     4.4       :duty    (zipmap (map :out duty-info)
     4.5                        (map #(get % :duty 0) duty-info))}))
     4.6  
     4.7 -(defn midi-bytes [^File midi-file]
     4.8 -  (let [voice-1-target 0xC400
     4.9 -        voice-2-target 0xC800
    4.10 -        noise-target   0xCC00
    4.11 -        program-target 0xC000
    4.12 -        mini-midi (midi->mini-midi midi-file)
    4.13 -        long-silence (flatten (note-codes 20 0 3000))
    4.14 -        long-noise-silence 
    4.15 -        (interleave (range 20) (repeat 0x00) (repeat 255))
    4.16 -        voice-1 (flatten (:voice-1 mini-midi))
    4.17 -        wave-duty-1 ((:duty mini-midi) 0 0)
    4.18 +(defn midi-bytes
    4.19 +  ([^File midi-file voice-1-target voice-2-target
    4.20 +    noise-target program-target]
    4.21 +     (let [mini-midi (midi->mini-midi midi-file)
    4.22 +           long-silence (flatten (note-codes 20 0 3000))
    4.23 +           long-noise-silence 
    4.24 +           (interleave (range 20) (repeat 0x00) (repeat 255))
    4.25 +           voice-1 (flatten (:voice-1 mini-midi))
    4.26 +           wave-duty-1 ((:duty mini-midi) 0 0)
    4.27  
    4.28 -        voice-2 (flatten (:voice-2 mini-midi))
    4.29 -        wave-duty-2 ((:duty mini-midi) 1 0)
    4.30 +           voice-2 (flatten (:voice-2 mini-midi))
    4.31 +           wave-duty-2 ((:duty mini-midi) 1 0)
    4.32  
    4.33 -        noise (flatten (:noise mini-midi))
    4.34 -        kernel (music-kernel
    4.35 -                voice-1-target
    4.36 -                voice-2-target
    4.37 -                noise-target
    4.38 -                wave-duty-1 wave-duty-2)]
    4.39 -    
    4.40 -    {:voice-1 {:address voice-1-target
    4.41 -               :data  (concat voice-1 long-silence)}
    4.42 -     :voice-2 {:address voice-2-target
    4.43 -               :data (concat voice-2 long-silence)}
    4.44 -     :noise   {:address noise-target
    4.45 -               :data (concat noise long-noise-silence)}
    4.46 -     :kernel  {:address program-target
    4.47 -               :data kernel}}))
    4.48 +           noise (flatten (:noise mini-midi))
    4.49 +           kernel (music-kernel
    4.50 +                   voice-1-target
    4.51 +                   voice-2-target
    4.52 +                   noise-target
    4.53 +                   wave-duty-1 wave-duty-2)]
    4.54 +       
    4.55 +       {:voice-1 {:address voice-1-target
    4.56 +                  :data  (concat voice-1 long-silence)}
    4.57 +        :voice-2 {:address voice-2-target
    4.58 +                  :data (concat voice-2 long-silence)}
    4.59 +        :noise   {:address noise-target
    4.60 +                  :data (concat noise long-noise-silence)}
    4.61 +        :kernel  {:address program-target
    4.62 +                  :data kernel}}))
    4.63 +  ([^File midi-file]
    4.64 +     (midi-bytes midi-file 0xC400 0xC800 0xCC00 0xC000)))
    4.65  
    4.66  (defn play-midi [^File midi-file]
    4.67    (let [bytes (midi-bytes midi-file)]