view clojure/com/aurellem/run/adv_choreo.clj @ 551:b69a3dba8045

condensed gameboy program into a contigous sequence of bytes.
author Robert McIntyre <rlm@mit.edu>
date Thu, 30 Aug 2012 11:19:52 -0500
parents 23572082c4a5
children 9068685e7d96
line wrap: on
line source
1 ;;;; "Advanced Choreography" -- this is the final video for this project.
3 (ns com.aurellem.run.adv-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 basic-choreo))
10 (:require clojure.string)
11 (:import [com.aurellem.gb.gb_driver SaveState])
12 (:import java.io.File))
16 ;; Use the gameboy's screen to display the new programming
17 ;; instead of a side window. This will make it look much
18 ;; cooler and create a terminal-like effect as the game is
19 ;; being reprogramed. To do this, use a fixed data entry
20 ;; region in ram, and run a program that translates this
21 ;; region into the screen. Every time this data entry region
22 ;; is full, run a program that copies the data to the
23 ;; appropriate region in memory. This will cost ~15 seconds
24 ;; at the beginning to set up, and then should have minimal
25 ;; overhead (~5%) for the rest of the data transfer, but
26 ;; will have a good psychological effect for the viewer
27 ;; since he can see that something is actually happening in
28 ;; the game.
31 ;; Symbol size and type.
33 ;; use fonts from zophar's domain:
34 ;; http://www.zophar.net/utilities/fonts/8x8-font-archive.html
36 ;; Green font on black background for matrix look.
40 ;; [ ] get single long ram write.
45 (defn program-data [base-address]
46 (let [image-program
47 (display-image-kernel
48 base-address
49 pinkie-pie-mark)
51 music-base-address (+ (count image-program) base-address)
53 initial-music-data
54 (midi-bytes pony-csv 0 0 0 0)
56 data-lengths
57 (map (comp count :data)
58 [(:kernel initial-music-data)
59 (:voice-1 initial-music-data)
60 (:voice-2 initial-music-data)]);; noise not needed
61 addresses
62 (map (partial + music-base-address) (reductions + 0 data-lengths))
64 final-music-data
65 (apply (partial midi-bytes pony-csv) addresses)
67 music-program
68 (concat
69 (:data (:kernel final-music-data))
70 (:data (:voice-1 final-music-data))
71 (:data (:voice-2 final-music-data))
72 (:data (:noise final-music-data)))]
74 (concat
75 image-program ;; image program falls through to music program
76 music-program)))
80 (def main-program-base-address 0xC000)
82 (defn write-all-program-data
83 ([] (write-all-program-data (silence-noise)))
84 ([script]
85 (let [base-address main-program-base-address]
86 (->> script
87 (write-RAM base-address (program-data base-address))))))
89 (defn activate-program
90 ([] (activate-program (write-all-program-data)))
91 ([script]
92 (->> script
93 (transfer-control main-program-base-address)
94 (do-nothing 1800))))