# HG changeset patch # User Robert McIntyre # Date 1340239910 18000 # Node ID 24b459a95b464a0124c4efd747cbb0bb0f930b7b # Parent 130ba9f49db592f13c63f651201d0eb8e55079c2 saving progress. diff -r 130ba9f49db5 -r 24b459a95b46 clojure/com/aurellem/run/image.clj --- a/clojure/com/aurellem/run/image.clj Wed Jun 20 16:50:36 2012 -0500 +++ b/clojure/com/aurellem/run/image.clj Wed Jun 20 19:51:50 2012 -0500 @@ -124,7 +124,7 @@ (flatten (map gb-rgb->bits palettes)))])) (defn display-one-color - "Displayes a single color onto the gameboy screen. input rgb in + "Displayes a single color onto the gameboy screen. Input rgb in gameboy rgb." ([state [r g b]] ;; construct a kernel that displays a single color @@ -276,12 +276,6 @@ (.dispose)) im)) - -(count - (filter - (fn [[r g b]] - (= (max r g b) r ))(set (vals gb-color-map)))) - (def test-image (ImageIO/read (File. user-home "/proj/vba-clojure/images/test-gb-image.png"))) @@ -385,15 +379,6 @@ (tile-pallete tile image-palettes))])))})) - - - - - - - - - ) (defn wait-until-v-blank "Modified version of frame-metronome. waits untill LY == 144, @@ -413,12 +398,73 @@ (concat timing-loop continue-if-144))) -(defn display-image-kernel [^BufferedImage image] - ;; assume image tile data is stored at 0xA000 - ;; " " palette date is at 0xB000 +(def bg-character-data 0x9000) + +(defn gb-tile->bytes + "Tile is a vector of 64 numbers between 0 and 3 that + represent a single 8x8 color tile in the GB screen. + It gets bit-packed into to 16 8-bit numbers in the following + form: + + 0-low 1-low ... 7-low + 0-high 1-high ... 7-high + . + . + . + 55-low ........ 63-low + 55-high ........ 63-high" + [tile] + (let [row->bits + (fn [row] + (mapv + (fn [row*] + (Integer/parseInt (apply str row*) 2)) + [(map #(bit-and 0x01 %) row) + (map #(bit-shift-right (bit-and 0x02 %) 1) + row)]))] + (vec + (flatten + (map row->bits + (partition 8 tile)))))) + +(defn display-image-kernel [^BufferedImage image] + (let [gb-image (image->gb-image image)] + + [(clear-music-registers) + ;; [ ] disable LCD protection circuit. + + ;; now we can write to all video RAM anytime with + ;; impunity. + + + + ;; we're only using background palettes; just set the + ;; minimum required bg palettes for this image, + ;; starting with palette #0. + + (set-palettes bg-palette-select bg-palette-data + (:palettes gb-image)) + + ;; [ ] switch to bank 0 to set BG character data. + + + ;; [ ] write minimum amount of tiles to BG character + ;; section + + + + ;; [ ] disable the display of OBJ tiles. + + + ;; [ ] reactivate the LCD display + + + (infinite-loop) + + )