Mercurial > vba-clojure
view clojure/com/aurellem/run/adv_choreo.clj @ 553:0901694725f0
saving progress for the night.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 30 Aug 2012 14:11:11 -0500 |
parents | 9068685e7d96 |
children | 37daf1acb212 |
line wrap: on
line source
1 ;;;; "Advanced Choreography" -- this is the final video for this project.3 (ns com.aurellem.run.adv-choreo4 (:use (com.aurellem.gb saves gb-driver util constants5 items vbm characters money6 rlm-assembly))7 (:use (com.aurellem.run util music title save-corruption8 bootstrap-0 bootstrap-1 image9 ram-display final-cut basic-choreo))10 (:require clojure.string)11 (:import java.awt.image.BufferedImage)12 (:import (javax.imageio ImageWriteParam IIOImage ImageIO))13 (:import [com.aurellem.gb.gb_driver SaveState])14 (:import java.io.File))18 ;; Use the gameboy's screen to display the new programming19 ;; instead of a side window. This will make it look much20 ;; cooler and create a terminal-like effect as the game is21 ;; being reprogramed. To do this, use a fixed data entry22 ;; region in ram, and run a program that translates this23 ;; region into the screen. Every time this data entry region24 ;; is full, run a program that copies the data to the25 ;; appropriate region in memory. This will cost ~15 seconds26 ;; at the beginning to set up, and then should have minimal27 ;; overhead (~5%) for the rest of the data transfer, but28 ;; will have a good psychological effect for the viewer29 ;; since he can see that something is actually happening in30 ;; the game.33 ;; Symbol size and type.35 ;; use fonts from zophar's domain:36 ;; http://www.zophar.net/utilities/fonts/8x8-font-archive.html38 ;; Green font on black background for matrix look.41 (defn program-data [base-address]42 (let [image-program43 (display-image-kernel44 base-address45 pinkie-pie-mark)47 music-base-address (+ (count image-program) base-address)49 initial-music-data50 (midi-bytes pony-csv 0 0 0 0)52 data-lengths53 (map (comp count :data)54 [(:kernel initial-music-data)55 (:voice-1 initial-music-data)56 (:voice-2 initial-music-data)]);; noise not needed57 addresses58 (map (partial + music-base-address) (reductions + 0 data-lengths))60 final-music-data61 (apply (partial midi-bytes pony-csv) addresses)63 music-program64 (concat65 (:data (:kernel final-music-data))66 (:data (:voice-1 final-music-data))67 (:data (:voice-2 final-music-data))68 (:data (:noise final-music-data)))]70 (concat71 image-program ;; image program falls through to music program72 music-program)))77 (def glyphs78 "The sixteen 8x8 glyphs which make up the \"terminal\" font."79 (mapv #(ImageIO/read80 (File. user-home (str "proj/vba-clojure/font/" % ".png")))81 ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"]))83 (defn glyphs-init-program84 [start-address]85 (let [zero-glyph (image->gb-image (glyphs 0))87 ;; write same pallet information to all pallettes88 A (flatten89 [(write-byte LCD-control-register 0x00)90 (set-palettes bg-palette-select bg-palette-data91 (repeat 8 (first (:palettes zero-glyph))))92 (select-LCD-bank 0)93 (write-byte SCX-register 0)94 (write-byte SCY-register 0)])95 B (flatten96 [(write-data97 (+ start-address (count A))98 character-data-address99 (flatten100 (map (comp gb-tile->bytes first :tiles image->gb-image)101 glyphs)))])]102 (concat A B)))105 (defn glyph-display-program106 [start-address107 delay-count108 total-glyph-count]109 (glyphs-init-program start-address) ;; ONLY for testing!110 )113 (defn glyph-bootstrap-program114 [start-address delay-count total-glyph-count]115 (let [init [0xAF 0x4F 0x47] ;; 0->A; 0->C; 0->B116 header (concat (frame-metronome) (read-user-input))118 glyph-display (glyph-display-program119 (+ (count init) (count header)120 start-address)121 0 0) ;; ONLY FOR TESTING123 state-machine-start-address124 (+ start-address (count init) (count header) (count glyph-display))125 state-machine126 (bootstrap-state-machine state-machine-start-address)128 return-to-header129 (flatten130 [0x18131 (->signed-8-bit132 (- (count init)133 2 ;; this command length134 3 ;; I have no idea why we need a 3 here135 ;; need to investigate.136 (count glyph-display)137 (count header)138 (count state-machine)))])]140 (concat init glyph-display header state-machine return-to-header)))145 (def main-program-base-address 0xC000)149 ;; RLM want to transfer control here --- this is where I left off.150 (defn begin-glyph-bootstrap151 ([] (begin-glyph-bootstrap (relocate-main-bootstrap)))152 ([script]153 (let [glyph-program (glyph-bootstrap-program154 0xDF00 0 0)160 (defn write-all-program-data161 ([] (write-all-program-data (relocate-main-bootstrap)))162 ([script]163 (let [base-address main-program-base-address]164 (->> script165 (write-RAM 0xFF1A [0 0 0]) ;; silence remnant music166 (write-RAM base-address (program-data base-address))))))168 (defn activate-program169 ([] (activate-program (write-all-program-data)))170 ([script]171 (->> script172 (transfer-control main-program-base-address)173 (do-nothing 1800))))176 ;; possible screen writing programs178 ;; (program needs to stop executing at some point)179 ;; maybe have total length counter or something?181 ;; automatic counter that reads from program-start and clears the182 ;; screen every 360 (* 18 20) gliphs184 ;; advantages -- very simple and low bandwidth185 ;; disadvantages -- hard to align counter187 ;; implementation -- refactor main-bootstrap-program to provide a188 ;; state-machine code-section which can be recombined into another189 ;; program.