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