Mercurial > vba-clojure
view clojure/com/aurellem/run/image.clj @ 495:1d81ddd4fa41
merged changes from trip to wichita.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 11 Jun 2012 00:55:51 -0500 |
parents | 151c96d60921 79606f173658 |
children | a6d060a64246 |
line wrap: on
line source
1 (ns com.aurellem.run.image2 (:use (com.aurellem.gb saves gb-driver util constants3 items vbm characters money4 rlm-assembly))5 (:use (com.aurellem.run util music title save-corruption6 bootstrap-0 bootstrap-1))7 (:require clojure.string)8 (:import [com.aurellem.gb.gb_driver SaveState])9 (:import java.io.File))11 ;; want to display an image onto the screen.12 ;; probably will be the six ponies, possibly with scrolling.14 ;; probably don't need hi-color mode since the images shuld be15 ;; simple.17 ;; use background tiles? they provide greater color depth than18 ;; sprites, and can still be scrolled, so why not?20 ;; could also use sprites to get 3 more colors per tile for a total of21 ;; 7 colors per tile, although not for all tiles...25 ;; want a function to27 ;; 1. read an image28 ;; 2. split into a grid of 8x8 pixels29 ;; 3. convert all RGB colors to gb-RGB colors30 ;; 4. determine efficient color palletes for the image31 ;; 5. output efficient assembly code to draw the image to the gb32 ;; screen.46 (def image-program-target 0xB000)48 (def display-width 160)49 (def display-height 144)53 ;{:r :g :b }55 (def character-data 0x8000)56 (def character-data-end 0x97FF)61 (def BG-data-1 0x9800)63 (def BG-data-2 0x9C00)65 (def OAM 0xFE00)69 (def video-bank-select-register 0xFF4F)71 (defn gb-rgb->bits [[r g b]]72 (assert (<= 0 r 31))73 (assert (<= 0 g 31))74 (assert (<= 0 b 31))75 [(bit-and76 0xFF77 (+78 r79 (bit-shift-left g 5)))80 (+81 (bit-shift-right g 3)82 (bit-shift-left b 2))])85 (def bg-palette-select 0xFF68)86 (def bg-palette-data 0xFF69)88 (def obj-palette-select 0xFF6A)89 (def obj-palette-data 0xFF6B)91 (def max-palettes 8)93 (defn write-data [target data]94 (flatten95 [0x3E ;; load literal to A96 data97 0xEA ;; load A into target98 (reverse (disect-bytes-2 target))]))100 (defn begin-sequential-palette-write101 [palette-num palette-select-address]102 (assert (<= 0 palette-num max-palettes))103 (assert104 (or (= palette-select-address bg-palette-select)105 (= palette-select-address obj-palette-select)))106 (let [palette-write-data107 (Integer/parseInt108 (str "1" ;; auto increment109 "0" ;; not used110 (format111 "%03d"112 (Integer/parseInt113 (Integer/toBinaryString palette-num) 10))114 "00" ;; color num115 "0" ;; H/L116 ) 2)]117 (write-data palette-select-address palette-write-data)))119 (defn set-palettes [palette-select palette-data palettes]120 (assert (<= (count palettes)) max-palettes)121 (flatten122 [(begin-sequential-palette-write 0 palette-select)123 (map (partial write-data palette-data)124 (flatten (map gb-rgb->bits palettes)))]))126 (defn display-one-color127 "Displayes a single color onto the gameboy screen. input rgb in128 gameboy rgb."129 [[r g b]]130 ;; construct a kernel that displays a single color131 (let132 [palettes (repeat 8 [r g b])133 kernel-address 0xC000134 kernel135 [0xF3 ;; disable interrupts136 (clear-music-registers)137 (frame-metronome)138 (set-palettes obj-palette-select obj-palette-data palettes)139 (set-palettes bg-palette-select bg-palette-data palettes)140 (infinite-loop)]]141 (-> (set-memory-range (second (music-base))142 kernel-address (flatten kernel))143 (PC! kernel-address))))148 (defn write-palette-color [palette-num r g b]149 (let [[byte-1 byte-2] (gb-rgb->bits r g b)]152 ))