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