Mercurial > vba-clojure
view clojure/com/aurellem/gb/moves.clj @ 191:893c753f8088
added function to set ROM
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 20:10:09 -0500 |
parents | 9a7a46c4aa1b |
children | fd549c8f42ae |
line wrap: on
line source
1 (ns com.aurellem.gb.moves2 (:use (com.aurellem.gb gb-driver util constants))3 (:import [com.aurellem.gb.gb_driver SaveState]))5 (def move-code->move-name6 {7 0x00 :end-of-moves8 0x01 :pound9 0x02 :karate-chop10 0x03 :doubleslap11 0x04 :comet-punch12 0x05 :mega-punch13 0x06 :pay-day14 0x07 :fire-punch15 0x08 :ice-punch16 0x09 :thunderpunch17 0x0A :scratch18 0x0B :vicegrip19 0x0C :guillotine20 0x0D :razor-wind21 0x0E :swords-dance22 0x0F :cut23 0x10 :gust24 0x11 :wing-attack25 0x12 :whirlwind26 0x13 :fly27 0x14 :bind28 0x15 :slam29 0x16 :vine-whip30 0x17 :stomp31 0x18 :double-kick32 0x19 :mega-kick33 0x1A :jump-kick34 0x1B :rolling-kick35 0x1C :sand-attack36 0x1D :headbutt37 0x1E :horn-attack38 0x1F :fury-attack39 0x20 :horn-drill40 0x21 :tackle41 0x22 :body-slam42 0x23 :wrap43 0x24 :take-down44 0x25 :thrash45 0x26 :double-edge46 0x27 :tail-whip47 0x28 :poison-sting48 0x29 :twinneedle49 0x2A :pin-missle50 0x2B :leer51 0x2C :bite52 0x2D :growl53 0x2E :roar54 0x2F :sing55 0x30 :supersonic56 0x31 :sonicboom57 0x32 :disable58 0x33 :acid59 0x34 :ember60 0x35 :flamethrower61 0x36 :mist62 0x37 :water-gun63 0x38 :hydro-pump64 0x39 :surf65 0x3A :ice-beam66 0x3B :blizzard67 0x3C :psybeam68 0x3D :bubblebeam69 0x3E :aurora-beam70 0x3F :hyper-beam71 0x40 :peck72 0x41 :drill-peck73 0x42 :submission74 0x43 :low-kick75 0x44 :counter76 0x45 :seismic-toss77 0x46 :strength78 0x47 :absorb79 0x48 :mega-drain80 0x49 :leech-seed81 0x4A :growth82 0x4B :razor-leaf83 0x4C :solarbeam84 0x4D :poisonpowder85 0x4E :stun-spore86 0x4F :sleep-powder87 0x50 :petal-dance88 0x51 :string-shot89 0x52 :dragon-rage90 0x53 :fire-spin91 0x54 :thundershock92 0x55 :thunderbolt93 0x56 :thunder-wave94 0x57 :thunder95 0x58 :rock-throw96 0x59 :earthquake97 0x5A :fissure98 0x5B :dig99 0x5C :toxic100 0x5D :confusion101 0x5E :psychic102 0x5F :hypnosis103 0x60 :meditate104 0x61 :agility105 0x62 :quick-attack106 0x63 :rage107 0x64 :teleport108 0x65 :night-shade109 0x66 :mimic110 0x67 :screech111 0x68 :double-team112 0x69 :recover113 0x6A :harden114 0x6B :minimize115 0x6C :smokescreen116 0x6D :confuse-ray117 0x6E :withdraw118 0x6F :defense-curl119 0x70 :barrier120 0x71 :light-screen121 0x72 :haze122 0x73 :reflect123 0x74 :focus-energy124 0x75 :bide125 0x76 :metronome126 0x77 :mirror-move127 0x78 :selfdestruct128 0x79 :egg-bomb129 0x7A :lick130 0x7B :smog131 0x7C :sludge132 0x7D :bone-club133 0x7E :fire-blast134 0x7F :waterfall135 0x80 :clamp136 0x81 :swift137 0x82 :skull-bash138 0x83 :spike-cannon139 0x84 :constrict140 0x85 :amnesia141 0x86 :kinesis142 0x87 :softboiled143 0x88 :hi-jump-kick144 0x89 :glare145 0x8A :dream-eater146 0x8B :poison-gas147 0x8C :barrage148 0x8D :leech-life149 0x8E :lovely-kiss150 0x8F :sky-attack151 0x90 :transform152 0x91 :bubble153 0x92 :dizzy-punch154 0x93 :spore155 0x94 :flash156 0x95 :psywave157 0x96 :splash158 0x97 :acid-armor159 0x98 :crabhammer160 0x99 :explosion161 0x9A :fury-swipes162 0x9B :bonemerang163 0x9C :rest164 0x9D :rock-slide165 0x9E :hyper-fang166 0x9F :sharpen167 0xA0 :conversion168 0xA1 :tri-attack169 0xA2 :super-fang170 0xA3 :slash171 0xA4 :substitute172 0xA5 :struggle})174 (def move-name->move-code175 (zipmap (vals move-code->move-name)176 (keys move-code->move-name)))178 (def moves-codes-pokemon-1 0xD172)180 (defn moves-codes-start [pokemon-num]181 (assert (<= 0 pokemon-num 5))182 (+ moves-codes-pokemon-1183 (* pokemon-num pokemon-record-width)))185 (defn read-moves186 ([^SaveState state poke-num]187 (let [start (moves-codes-start poke-num)]188 (vec189 (take-while190 (partial not= :end-of-moves)191 (map192 move-code->move-name193 (subvec (vec (memory state))194 start (+ start (num-moves state poke-num))))))))195 ([poke-num]196 (read-moves @current-state poke-num)))198 (defn give-moves199 ([^SaveState state pokemon-num moves]200 (assert (<= (count moves) 4))201 (set-memory-range202 state203 (moves-codes-start pokemon-num)204 (map #(move-name->move-code % %)205 (concat moves206 (repeat (- 4 (count moves)) :end-of-moves)))))207 ([pokemon-num moves]208 (give-moves @current-state pokemon-num moves))209 ([moves]210 (give-moves 0 moves)))212 ;; Note regarding PP of moves -- both the current PP and the213 ;; total PP are stored in the same value.214 ;; they are bit-packed, with the first 2 bits containing the215 ;; number of pp-ups that have been applied, and the next216 ;; six bits containing the current pp of the move.217 ;; thus, a move can have up to 63 current pp and up to218 ;; three pp-ups applied.220 (def pokemon-1-pp-start 0xD187)222 (defn moves-pp-start [pokemon-num]223 (assert (<= 0 pokemon-num 5))224 (+ pokemon-1-pp-start (* pokemon-num pokemon-record-width)))226 (defn read-pp227 ([^SaveState state pokemon-num move-num]228 (assert (<= 0 move-num 3))229 (assert (<= 0 pokemon-num 5))230 (let [pp-raw231 (aget (memory state)232 (+ (moves-pp-start pokemon-num)233 move-num))234 pp-up235 (bit-shift-right236 (bit-and237 pp-raw238 (Integer/parseInt "11000000" 2)) 6)239 current-pp240 (bit-and241 pp-raw242 (Integer/parseInt "00111111" 2))]243 [pp-up current-pp]))244 ([pokemon-num move-num]245 (read-pp @current-state pokemon-num move-num)))247 (defn give-pp248 ([^SaveState state pokemon-num move-num pp-ups current-pp]249 (assert (<= 0 move-num 3))250 (assert (<= 0 pokemon-num 5))251 (assert (<= 0 pp-ups 3))252 (assert (<= 0 current-pp 63))254 (set-memory255 state256 (+ (moves-pp-start pokemon-num)257 move-num)258 (+259 (bit-shift-left pp-ups 6)260 (bit-and (Integer/parseInt261 "00111111" 2)262 current-pp))))263 ([pokemon-num move-num pp-ups current-pp]264 (give-pp @current-state265 pokemon-num move-num pp-ups current-pp)))