Mercurial > vba-clojure
view clojure/com/aurellem/gb/moves.clj @ 182:f0c1e5574e81
finished mapping out pokemon memory region.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 06:07:31 -0500 |
parents | 9c3769060201 |
children | 9a7a46c4aa1b |
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 0x01 :pound8 0x02 :karate-chop9 0x03 :doubleslap10 0x04 :comet-punch11 0x05 :mega-punch12 0x06 :pay-day13 0x07 :fire-punch14 0x08 :ice-punch15 0x09 :thunderpunch16 0x0A :scratch17 0x0B :vicegrip18 0x0C :guillotine19 0x0D :razor-wind20 0x0E :swords-dance21 0x0F :cut22 0x10 :gust23 0x11 :wing-attack24 0x12 :whirlwind25 0x13 :fly26 0x14 :bind27 0x15 :slam28 0x16 :vine-whip29 0x17 :stomp30 0x18 :double-kick31 0x19 :mega-kick32 0x1A :jump-kick33 0x1B :rolling-kick34 0x1C :sand-attack35 0x1D :headbutt36 0x1E :horn-attack37 0x1F :fury-attack38 0x20 :horn-drill39 0x21 :tackle40 0x22 :body-slam41 0x23 :wrap42 0x24 :take-down43 0x25 :thrash44 0x26 :double-edge45 0x27 :tail-whip46 0x28 :poison-sting47 0x29 :twinneedle48 0x2A :pin-missle49 0x2B :leer50 0x2C :bite51 0x2D :growl52 0x2E :roar53 0x2F :sing54 0x30 :supersonic55 0x31 :sonicboom56 0x32 :disable57 0x33 :acid58 0x34 :ember59 0x35 :flamethrower60 0x36 :mist61 0x37 :water-gun62 0x38 :hydro-pump63 0x39 :surf64 0x3A :ice-beam65 0x3B :blizzard66 0x3C :psybeam67 0x3D :bubblebeam68 0x3E :aurora-beam69 0x3F :hyper-beam70 0x40 :peck71 0x41 :drill-peck72 0x42 :submission73 0x43 :low-kick74 0x44 :counter75 0x45 :seismic-toss76 0x46 :strength77 0x47 :absorb78 0x48 :mega-drain79 0x49 :leech-seed80 0x4A :growth81 0x4B :razor-leaf82 0x4C :solarbeam83 0x4D :poisonpowder84 0x4E :stun-spore85 0x4F :sleep-powder86 0x50 :petal-dance87 0x51 :string-shot88 0x52 :dragon-rage89 0x53 :fire-spin90 0x54 :thundershock91 0x55 :thunderbolt92 0x56 :thunder-wave93 0x57 :thunder94 0x58 :rock-throw95 0x59 :earthquake96 0x5A :fissure97 0x5B :dig98 0x5C :toxic99 0x5D :confusion100 0x5E :psychic101 0x5F :hypnosis102 0x60 :meditate103 0x61 :agility104 0x62 :quick-attack105 0x63 :rage106 0x64 :teleport107 0x65 :night-shade108 0x66 :mimic109 0x67 :screech110 0x68 :double-team111 0x69 :recover112 0x6A :harden113 0x6B :minimize114 0x6C :smokescreen115 0x6D :confuse-ray116 0x6E :withdraw117 0x6F :defense-curl118 0x70 :barrier119 0x71 :light-screen120 0x72 :haze121 0x73 :reflect122 0x74 :focus-energy123 0x75 :bide124 0x76 :metronome125 0x77 :mirror-move126 0x78 :selfdestruct127 0x79 :egg-bomb128 0x7A :lick129 0x7B :smog130 0x7C :sludge131 0x7D :bone-club132 0x7E :fire-blast133 0x7F :waterfall134 0x80 :clamp135 0x81 :swift136 0x82 :skull-bash137 0x83 :spike-cannon138 0x84 :constrict139 0x85 :amnesia140 0x86 :kinesis141 0x87 :softboiled142 0x88 :hi-jump-kick143 0x89 :glare144 0x8A :dream-eater145 0x8B :poison-gas146 0x8C :barrage147 0x8D :leech-life148 0x8E :lovely-kiss149 0x8F :sky-attack150 0x90 :transform151 0x91 :bubble152 0x92 :dizzy-punch153 0x93 :spore154 0x94 :flash155 0x95 :psywave156 0x96 :splash157 0x97 :acid-armor158 0x98 :crabhammer159 0x99 :explosion160 0x9A :fury-swipes161 0x9B :bonemerang162 0x9C :rest163 0x9D :rock-slide164 0x9E :hyper-fang165 0x9F :sharpen166 0xA0 :conversion167 0xA1 :tri-attack168 0xA2 :super-fang169 0xA3 :slash170 0xA4 :substitute171 0xA5 :struggle})173 (def moves-codes-pokemon-1 0xD172)175 (defn moves-codes-start [pokemon-num]176 (assert (<= 0 pokemon-num 5))177 (+ moves-codes-pokemon-1178 (* pokemon-num pokemon-record-width)))180 (def move-name->move-code181 (zipmap (vals move-code->move-name)182 (keys move-code->move-name)))184 (defn give-moves185 ([^SaveState state pokemon-num moves]186 (set-memory-range187 state188 (moves-codes-start pokemon-num)189 (map #(move-name->move-code % %) moves)))190 ([pokemon-num moves]191 (give-moves @current-state pokemon-num moves))192 ([moves]193 (give-moves 0 moves)))195 ;; Note regarding PP of moves -- both the current PP and the196 ;; total PP are stored in the same value.197 ;; they are bit-packed, with the first 2 bits containing the198 ;; number of pp-ups that have been applied, and the next199 ;; six bits containing the current pp of the move.200 ;; thus, a move can have up to 63 current pp and up to201 ;; three pp-ups applied.204 (def pokemon-1-pp-start 0xD187)206 (defn moves-pp-start [pokemon-num]207 (assert (<= 0 pokemon-num 5))208 (+ pokemon-1-pp-start (* pokemon-num pokemon-record-width)))210 (defn read-pp211 ([^SaveState state pokemon-num move-num]212 (assert (<= 0 move-num 3))213 (assert (<= 0 pokemon-num 5))214 (let [pp-raw215 (aget (memory state)216 (+ (moves-pp-start pokemon-num)217 move-num))218 pp-up219 (bit-shift-right220 (bit-and221 pp-raw222 (Integer/parseInt "11000000" 2)) 6)223 current-pp224 (bit-and225 pp-raw226 (Integer/parseInt "00111111" 2))]227 [pp-up current-pp]))228 ([pokemon-num move-num]229 (read-pp @current-state pokemon-num move-num)))231 (defn give-pp232 ([^SaveState state pokemon-num move-num pp-ups current-pp]233 (assert (<= 0 move-num 3))234 (assert (<= 0 pokemon-num 5))235 (assert (<= 0 pp-ups 3))236 (assert (<= 0 current-pp 63))238 (set-memory239 state240 (+ (moves-pp-start pokemon-num)241 move-num)242 (+243 (bit-shift-left pp-ups 6)244 (bit-and (Integer/parseInt245 "00111111" 2)246 current-pp))))247 ([pokemon-num move-num pp-ups current-pp]248 (give-pp @current-state249 pokemon-num move-num pp-ups current-pp)))