view clojure/com/aurellem/run/ram_display.clj @ 574:be6f46094ad0

implemented video-memory pointer logic.
author Robert McIntyre <rlm@mit.edu>
date Sat, 01 Sep 2012 04:05:51 -0500
parents 5596cd4a3fc6
children
line wrap: on
line source
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])
10 (:import java.awt.image.BufferedImage)
11 (:import java.io.File))
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)))
19 (def video-ram-start 0x8000)
21 (def GB-memory-end 0x10000)
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)))
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)))
52 (def test-ram-image
53 (File. "/home/r/proj/vba-clojure/images/RAM-test.png"))