annotate clojure/com/aurellem/run/ram_display.clj @ 539:a64485223afa

cleanup.
author Robert McIntyre <rlm@mit.edu>
date Mon, 25 Jun 2012 14:55:55 -0500
parents 5596cd4a3fc6
children
rev   line source
rlm@522 1 (ns com.aurellem.run.ram-display
rlm@522 2 (:use (com.aurellem.gb saves gb-driver util constants
rlm@522 3 items vbm characters money
rlm@522 4 rlm-assembly))
rlm@522 5 (:use (com.aurellem.run image util music title save-corruption
rlm@522 6 bootstrap-0 bootstrap-1))
rlm@522 7 (:require clojure.string)
rlm@522 8 (:import [com.aurellem.gb.gb_driver SaveState])
rlm@522 9
rlm@522 10 (:import java.awt.image.BufferedImage)
rlm@522 11 (:import java.io.File))
rlm@522 12
rlm@522 13 (defn accurate-memory-range
rlm@522 14 ([^SaveState state start end]
rlm@522 15 (map accurate-memory (range start end)))
rlm@522 16 ([start end]
rlm@522 17 (accurate-memory-range @current-state start end)))
rlm@522 18
rlm@522 19 (def video-ram-start 0x8000)
rlm@522 20
rlm@522 21 (def GB-memory-end 0x10000)
rlm@522 22
rlm@522 23 (defn ram-image
rlm@522 24 ([^SaveState state]
rlm@522 25 (let [width 128
rlm@522 26 height 256
rlm@522 27 image (BufferedImage. width height
rlm@522 28 BufferedImage/TYPE_INT_RGB)
rlm@522 29 data (vec
rlm@522 30 (accurate-memory-range
rlm@522 31 state video-ram-start GB-memory-end))]
rlm@522 32 (dorun
rlm@522 33 (map
rlm@522 34 (fn [index]
rlm@522 35 (let [gray (data index)]
rlm@522 36 (.setRGB image (rem index width)
rlm@522 37 (int (/ index width))
rlm@522 38 (+
rlm@522 39 (bit-shift-left gray 16)
rlm@522 40 (bit-shift-left gray 8)
rlm@522 41 gray))))
rlm@522 42 (range (count data))))
rlm@522 43 image))
rlm@522 44 ([] (ram-image @current-state)))
rlm@522 45
rlm@522 46 (defn write-ram-image!
rlm@522 47 ([^SaveState state ^File target]
rlm@522 48 (write-image! (ram-image state) target))
rlm@522 49 ([^File target]
rlm@522 50 (write-ram-image! @current-state target)))
rlm@522 51
rlm@522 52 (def test-ram-image
rlm@522 53 (File. "/home/r/proj/vba-clojure/images/RAM-test.png"))