view clojure/com/aurellem/run/basic_choreo.clj @ 620:1b52b14868d3 tip

merge.
author rlm <rlm@aurellem.org>
date Sun, 07 Feb 2016 23:16:04 -0800
parents 31128a10ee28
children
line wrap: on
line source
1 ;;;; "Basic Choreography" -- just show off audio/video
3 (ns com.aurellem.run.basic-choreo
4 (:use (com.aurellem.gb saves gb-driver util constants
5 items vbm characters money
6 rlm-assembly))
7 (:use (com.aurellem.run util music title save-corruption
8 bootstrap-0 bootstrap-1 image
9 ram-display final-cut))
10 (:require clojure.string)
11 (:import [com.aurellem.gb.gb_driver SaveState])
12 (:import java.io.File))
14 ;; take over game
15 ;; [X] silence noise
16 ;; [X] preload audio/video programs
17 ;; [X] run picture program to display pinkie pie mark
18 ;; [X] play pony song
20 (defn-memo silence-noise
21 ([] (silence-noise (launch-main-bootstrap-program)))
22 ([script]
23 (->> script
24 (write-RAM 0xFF1A [0 0 0])
25 (relocate-main-bootstrap))))
27 (def music-program-start 0xC000)
28 (def image-program-start 0xCE00)
30 (defn-memo write-pony-music
31 ([] (write-pony-music (silence-noise)))
32 ([script]
33 (let [bytes (midi-bytes
34 pony-csv
35 music-program-start
36 0xC400
37 0xC800
38 0xCC00)]
39 (->> script
40 (write-RAM (:address (:voice-1 bytes))
41 (:data (:voice-1 bytes)))
42 (write-RAM (:address (:voice-2 bytes))
43 (:data (:voice-2 bytes)))
44 (write-RAM (:address (:noise bytes))
45 (:data (:noise bytes)))
46 (write-RAM (:address (:kernel bytes))
47 (:data (:kernel bytes)))))))
49 (defn-memo write-image-display-program
50 ([] (write-image-display-program (write-pony-music)))
51 ([script]
52 (let [goto-music
53 (flatten
54 [0xC3
55 (reverse (disect-bytes-2 music-program-start))])]
56 (->> script
57 (write-RAM
58 image-program-start
59 (concat
60 (display-image-kernel
61 image-program-start
62 pinkie-pie-mark)
63 goto-music))))))
65 (defn-memo activate-media
66 ([] (activate-media (write-image-display-program)))
67 ([script]
68 (->> script
69 (transfer-control image-program-start)
70 (do-nothing 1800))))
72 (defn basic-write-move-image! [move target-file]
73 (let [actual-keys (set move)
74 keys [:a :b :start :select :u :d :l :r]
75 button-on-name ["-size" "5x5" "xc:red"]
76 button-off-name ["-size" "5x5" "xc:white"]]
77 (apply
78 clojure.java.shell/sh
79 (flatten
80 ["convert"
81 "-size" "64x5" "xc:white"
82 (map
83 (fn [index]
84 (let [position ["-geometry"
85 (str "+" (* index 8)
86 "+" "0") "-composite"]]
87 (if (actual-keys (keys index))
88 [button-on-name position]
89 [button-off-name position])))
90 (range (count keys)))
91 (.getCanonicalPath target-file)]))))
93 (defn basic-composite-frames-command
94 [move-image screenshot ram-map target]
95 ["convert"
96 "-size" "318x276" "xc:white"
97 move-image "-geometry" "+30+225" "-composite"
98 screenshot "-geometry" "+10+10" "-composite"
99 ram-map "-geometry" "+180+10" "-composite"
100 target])
102 (defn basic-generate-composite-frames!
103 [^File rendered-dir]
104 (let [final-frames (File. rendered-dir "final")
105 _ (.mkdir final-frames)
106 move-images (file-names (File. rendered-dir "moves"))
107 screenshots (file-names (File. rendered-dir "frames"))
108 ram-maps (file-names (File. rendered-dir "ram-map"))
109 targets (map #(.getCanonicalPath
110 (File. final-frames (format "%07d.png" %)))
111 (range (count screenshots)))]
112 (dorun
113 (map
114 (comp
115 (partial apply clojure.java.shell/sh)
116 flatten
117 (partial apply basic-composite-frames-command)
118 (fn [a b c d] (println d) [a b c d]))
119 move-images screenshots ram-maps targets))))
121 (def basic-render-dir
122 (File. user-home "proj/vba-clojure/render/basic"))
124 (defn basic-steps [] (first (activate-media)))
126 (defn basic-step-1! []
127 (render-files!
128 basic-render-dir
129 basic-write-move-image!
130 true
131 (root) (basic-steps)))
133 (defn basic-step-2! []
134 (basic-generate-composite-frames!
135 basic-render-dir))
137 (defn basic-step-3! [] (final-cut! basic-render-dir))