# HG changeset patch # User Robert McIntyre # Date 1339394151 18000 # Node ID 1d81ddd4fa41b5463a12b0a424f1303b929e845a # Parent 151c96d6092177961cc98810355c8c901d1e01cc# Parent 79606f17365832f03c0a5432726586bf487b1f83 merged changes from trip to wichita. diff -r 79606f173658 -r 1d81ddd4fa41 clojure/com/aurellem/gb/gb_driver.clj --- a/clojure/com/aurellem/gb/gb_driver.clj Thu Jun 07 23:11:18 2012 -0500 +++ b/clojure/com/aurellem/gb/gb_driver.clj Mon Jun 11 00:55:51 2012 -0500 @@ -271,6 +271,11 @@ (def original-rom (rom (root))) + +;; RGB colors in an image are not the same as those in a GameBoy, so I +;; need to convert them. Fortunately, this code is already written +;; for me in this C-code from the public domain hi-color converter by +;; Glen Cook, Jeff Frohwein, and Rob Jones. (defn rgb->gb-rb [[r g b :as color]] (let [store (int-array 3)] (Gb/translateRGB (int-array color) store) diff -r 79606f173658 -r 1d81ddd4fa41 clojure/com/aurellem/run/image.clj --- a/clojure/com/aurellem/run/image.clj Thu Jun 07 23:11:18 2012 -0500 +++ b/clojure/com/aurellem/run/image.clj Mon Jun 11 00:55:51 2012 -0500 @@ -17,82 +17,34 @@ ;; use background tiles? they provide greater color depth than ;; sprites, and can still be scrolled, so why not? +;; could also use sprites to get 3 more colors per tile for a total of +;; 7 colors per tile, although not for all tiles... -;; First of all, RGB colors in an image are not the same as those in a -;; GameBoy, so I need to convert them. Fortunately, this code is -;; already written for me in this C-code from the public domain -;; hi-color converter by Glen Cook, Jeff Frohwein, and Rob Jones. -;; the code snipped itself is by Brett Bibby and is translated here -;; from C into clojure. +;; want a function to -;; This section of code is used to convert an RGB (pc) triplet into -;; a RGB (gameboy) triplet. This section of code was kindly donated -;; by Brett Bibby (GameBrains). +;; 1. read an image +;; 2. split into a grid of 8x8 pixels +;; 3. convert all RGB colors to gb-RGB colors +;; 4. determine efficient color palletes for the image +;; 5. output efficient assembly code to draw the image to the gb +;; screen. -;; BYTE intensity[32] = { -;; 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94, -;; 0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7, -;; 0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff }; -;; unsigned char influence[3][3] = -;; { -;; {16,4,4}, -;; {8,16,8}, -;; {0,8,16} -;; }; -;; RGBQUAD translate(BYTE rgb[3]) -;; { -;; RGBQUAD color; -;; BYTE tmp[3]; -;; BYTE m[3][3]; -;; BYTE i,j; -;; for (i=0;i<3;i++) -;; for (j=0;j<3;j++) -;; m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5; -;; for (i=0;i<3;i++) -;; { -;; if (m[0][i]>m[1][i]) -;; { -;; j=m[0][i]; -;; m[0][i]=m[1][i]; -;; m[1][i]=j; -;; } -;; if (m[1][i]>m[2][i]) -;; { -;; j=m[1][i]; -;; m[1][i]=m[2][i]; -;; m[2][i]=j; -;; } -;; if (m[0][i]>m[1][i]) -;; { -;; j=m[0][i]; -;; m[0][i]=m[1][i]; -;; m[1][i]=j; -;; } -;; tmp[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32; -;; } -;; color.rgbRed = tmp[0]; -;; color.rgbGreen = tmp[1]; -;; color.rgbBlue = tmp[2]; -;; return color; -;; } - (def image-program-target 0xB000) - (def display-width 160) (def display-height 144) @@ -199,3 +151,4 @@ )) +