Mercurial > vba-clojure
changeset 522:5596cd4a3fc6
added RAM display.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 23 Jun 2012 19:12:26 -0500 |
parents | bad7b7430245 |
children | d00096b6bf17 |
files | clojure/com/aurellem/gb/gb_driver.clj clojure/com/aurellem/run/image.clj clojure/com/aurellem/run/ram_display.clj images/RAM-test.png java/src/com/aurellem/gb/Gb.java src/clojure/clojure.cpp src/gb/GB.h todo.org |
diffstat | 8 files changed, 94 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/gb/gb_driver.clj Sat Jun 23 17:45:38 2012 -0500 1.2 +++ b/clojure/com/aurellem/gb/gb_driver.clj Sat Jun 23 19:12:26 2012 -0500 1.3 @@ -154,6 +154,13 @@ 1.4 (set-state! state) 1.5 (dorun (map (fn [move] (step @current-state move)) moves)) 1.6 [(concat prev moves) @current-state])) 1.7 + 1.8 +(defn accurate-memory 1.9 + ([^SaveState state address] 1.10 + (set-state! state) 1.11 + (Gb/readMemory address)) 1.12 + ([address] 1.13 + (accurate-memory @current-state address))) 1.14 1.15 ;;;;;;;;;;; 1.16 1.17 @@ -166,9 +173,6 @@ 1.18 ([^File target] 1.19 (write-png! @current-state target))) 1.20 1.21 - 1.22 - 1.23 - 1.24 ;;;;;;;;;;;;;;; CPU data 1.25 1.26 (defn cpu-data [size arr-fn] 1.27 @@ -294,6 +298,4 @@ 1.28 (defn rgb->gb-rb [[r g b :as color]] 1.29 (let [store (int-array 3)] 1.30 (Gb/translateRGB (int-array color) store) 1.31 - (vec store))) 1.32 - 1.33 - 1.34 + (vec store))) 1.35 \ No newline at end of file
2.1 --- a/clojure/com/aurellem/run/image.clj Sat Jun 23 17:45:38 2012 -0500 2.2 +++ b/clojure/com/aurellem/run/image.clj Sat Jun 23 19:12:26 2012 -0500 2.3 @@ -6,6 +6,7 @@ 2.4 bootstrap-0 bootstrap-1)) 2.5 (:require clojure.string) 2.6 (:import [com.aurellem.gb.gb_driver SaveState]) 2.7 + (:import java.awt.image.BufferedImage) 2.8 (:import java.io.File)) 2.9 2.10 ;; want to display an image onto the screen. 2.11 @@ -149,7 +150,7 @@ 2.12 (display-one-color @current-state [r g b]))) 2.13 2.14 ;;(require 'cortex.sense) 2.15 -(import java.awt.image.BufferedImage) 2.16 + 2.17 2.18 ;; (defn show-screenshot [] 2.19 ;; (let [im (BufferedImage. 160 144 BufferedImage/TYPE_INT_RGB) 2.20 @@ -203,6 +204,15 @@ 2.21 (import '(javax.imageio ImageWriteParam IIOImage ImageIO)) 2.22 2.23 2.24 +(defn write-image! [^BufferedImage image ^File target] 2.25 + (doto 2.26 + (.next (ImageIO/getImageWritersByFormatName "png")) 2.27 + (.setOutput (FileImageOutputStream. target)) 2.28 + (.write (IIOImage. image nil nil)) 2.29 + (.dispose)) 2.30 + image) 2.31 + 2.32 + 2.33 (defn gen-gb-color-image! [] 2.34 (let [im (BufferedImage. 68 69 BufferedImage/TYPE_INT_RGB) 2.35 pix (vec 2.36 @@ -242,13 +252,9 @@ 2.37 b)] 2.38 (.setRGB im x y rgb)))) 2.39 ;;(view im) 2.40 - (doto 2.41 - (.next (ImageIO/getImageWritersByFormatName "png")) 2.42 - (.setOutput (FileImageOutputStream. target)) 2.43 - (.write (IIOImage. im nil nil)) 2.44 - (.dispose)) 2.45 - im)) 2.46 - 2.47 + (write-image! im target))) 2.48 + 2.49 + 2.50 (defn gen-gb-color-image*! [] 2.51 (let [im (BufferedImage. 213 213 BufferedImage/TYPE_INT_RGB) 2.52 squares 2.53 @@ -274,12 +280,7 @@ 2.54 (+ 3 (* 35 (int (/ s-index 6))) y) 2.55 rgb)))))) 2.56 ;;(view im) 2.57 - (doto 2.58 - (.next (ImageIO/getImageWritersByFormatName "png")) 2.59 - (.setOutput (FileImageOutputStream. target)) 2.60 - (.write (IIOImage. im nil nil)) 2.61 - (.dispose)) 2.62 - im)) 2.63 + (write-image! im target))) 2.64 2.65 (defn gen-gimp-palette! [] 2.66 (let [target 2.67 @@ -670,9 +671,10 @@ 2.68 (concat A B C D))) 2.69 2.70 (defn display-image [#^BufferedImage image] 2.71 - (let [kernel-address 0xB000] 2.72 + (let [kernel-address 0xB500] 2.73 (-> (tick (tick (tick (mid-game)))) 2.74 (set-memory-range 2.75 kernel-address 2.76 (display-image-kernel kernel-address image)) 2.77 (PC! kernel-address)))) 2.78 +
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/clojure/com/aurellem/run/ram_display.clj Sat Jun 23 19:12:26 2012 -0500 3.3 @@ -0,0 +1,53 @@ 3.4 +(ns com.aurellem.run.ram-display 3.5 + (:use (com.aurellem.gb saves gb-driver util constants 3.6 + items vbm characters money 3.7 + rlm-assembly)) 3.8 + (:use (com.aurellem.run image util music title save-corruption 3.9 + bootstrap-0 bootstrap-1)) 3.10 + (:require clojure.string) 3.11 + (:import [com.aurellem.gb.gb_driver SaveState]) 3.12 + 3.13 + (:import java.awt.image.BufferedImage) 3.14 + (:import java.io.File)) 3.15 + 3.16 +(defn accurate-memory-range 3.17 + ([^SaveState state start end] 3.18 + (map accurate-memory (range start end))) 3.19 + ([start end] 3.20 + (accurate-memory-range @current-state start end))) 3.21 + 3.22 +(def video-ram-start 0x8000) 3.23 + 3.24 +(def GB-memory-end 0x10000) 3.25 + 3.26 +(defn ram-image 3.27 + ([^SaveState state] 3.28 + (let [width 128 3.29 + height 256 3.30 + image (BufferedImage. width height 3.31 + BufferedImage/TYPE_INT_RGB) 3.32 + data (vec 3.33 + (accurate-memory-range 3.34 + state video-ram-start GB-memory-end))] 3.35 + (dorun 3.36 + (map 3.37 + (fn [index] 3.38 + (let [gray (data index)] 3.39 + (.setRGB image (rem index width) 3.40 + (int (/ index width)) 3.41 + (+ 3.42 + (bit-shift-left gray 16) 3.43 + (bit-shift-left gray 8) 3.44 + gray)))) 3.45 + (range (count data)))) 3.46 + image)) 3.47 + ([] (ram-image @current-state))) 3.48 + 3.49 +(defn write-ram-image! 3.50 + ([^SaveState state ^File target] 3.51 + (write-image! (ram-image state) target)) 3.52 + ([^File target] 3.53 + (write-ram-image! @current-state target))) 3.54 + 3.55 +(def test-ram-image 3.56 + (File. "/home/r/proj/vba-clojure/images/RAM-test.png"))
4.1 Binary file images/RAM-test.png has changed
5.1 --- a/java/src/com/aurellem/gb/Gb.java Sat Jun 23 17:45:38 2012 -0500 5.2 +++ b/java/src/com/aurellem/gb/Gb.java Sat Jun 23 19:12:26 2012 -0500 5.3 @@ -129,4 +129,5 @@ 5.4 5.5 public static native void nwritePNG(String filename); 5.6 5.7 + public static native int readMemory(int address); 5.8 }
6.1 --- a/src/clojure/clojure.cpp Sat Jun 23 17:45:38 2012 -0500 6.2 +++ b/src/clojure/clojure.cpp Sat Jun 23 19:12:26 2012 -0500 6.3 @@ -2,6 +2,7 @@ 6.4 #include "../sdl/Drive.h" 6.5 #include "../gb/GB.h" 6.6 6.7 + 6.8 #include <string.h> 6.9 6.10 #define UNUSED(x) (void)(x) 6.11 @@ -336,3 +337,13 @@ 6.12 } 6.13 6.14 6.15 + 6.16 +/* 6.17 + * Class: com_aurellem_gb_Gb 6.18 + * Method: readMemory 6.19 + * Signature: (I)I 6.20 + */ 6.21 +JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_readMemory 6.22 +(JNIEnv *env, jclass clazz, jint address){ 6.23 + return (jint) gbReadMemory((u16) address); 6.24 +}
7.1 --- a/src/gb/GB.h Sat Jun 23 17:45:38 2012 -0500 7.2 +++ b/src/gb/GB.h Sat Jun 23 19:12:26 2012 -0500 7.3 @@ -63,6 +63,8 @@ 7.4 7.5 extern long gbWriteMemSaveStatePos(char *, int); 7.6 7.7 +extern u8 gbReadMemory(u16 address); 7.8 + 7.9 extern struct EmulatedSystem GBSystem; 7.10 extern struct EmulatedSystemCounters &GBSystemCounters; 7.11
8.1 --- a/todo.org Sat Jun 23 17:45:38 2012 -0500 8.2 +++ b/todo.org Sat Jun 23 19:12:26 2012 -0500 8.3 @@ -1,5 +1,5 @@ 8.4 -* vba-clojure [0/7] 8.5 - - [ ] create ram display 8.6 +* vba-clojure [1/7] 8.7 + - [X] create ram display 8.8 - [ ] derpy hack 8.9 - [ ] sound recording 8.10 - [ ] fix unnecessary pauses before take-over