Mercurial > vba-clojure
diff clojure/com/aurellem/run/ram_display.clj @ 522:5596cd4a3fc6
added RAM display.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 23 Jun 2012 19:12:26 -0500 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/clojure/com/aurellem/run/ram_display.clj Sat Jun 23 19:12:26 2012 -0500 1.3 @@ -0,0 +1,53 @@ 1.4 +(ns com.aurellem.run.ram-display 1.5 + (:use (com.aurellem.gb saves gb-driver util constants 1.6 + items vbm characters money 1.7 + rlm-assembly)) 1.8 + (:use (com.aurellem.run image util music title save-corruption 1.9 + bootstrap-0 bootstrap-1)) 1.10 + (:require clojure.string) 1.11 + (:import [com.aurellem.gb.gb_driver SaveState]) 1.12 + 1.13 + (:import java.awt.image.BufferedImage) 1.14 + (:import java.io.File)) 1.15 + 1.16 +(defn accurate-memory-range 1.17 + ([^SaveState state start end] 1.18 + (map accurate-memory (range start end))) 1.19 + ([start end] 1.20 + (accurate-memory-range @current-state start end))) 1.21 + 1.22 +(def video-ram-start 0x8000) 1.23 + 1.24 +(def GB-memory-end 0x10000) 1.25 + 1.26 +(defn ram-image 1.27 + ([^SaveState state] 1.28 + (let [width 128 1.29 + height 256 1.30 + image (BufferedImage. width height 1.31 + BufferedImage/TYPE_INT_RGB) 1.32 + data (vec 1.33 + (accurate-memory-range 1.34 + state video-ram-start GB-memory-end))] 1.35 + (dorun 1.36 + (map 1.37 + (fn [index] 1.38 + (let [gray (data index)] 1.39 + (.setRGB image (rem index width) 1.40 + (int (/ index width)) 1.41 + (+ 1.42 + (bit-shift-left gray 16) 1.43 + (bit-shift-left gray 8) 1.44 + gray)))) 1.45 + (range (count data)))) 1.46 + image)) 1.47 + ([] (ram-image @current-state))) 1.48 + 1.49 +(defn write-ram-image! 1.50 + ([^SaveState state ^File target] 1.51 + (write-image! (ram-image state) target)) 1.52 + ([^File target] 1.53 + (write-ram-image! @current-state target))) 1.54 + 1.55 +(def test-ram-image 1.56 + (File. "/home/r/proj/vba-clojure/images/RAM-test.png"))