Mercurial > vba-clojure
view clojure/com/aurellem/gb/dv.clj @ 310:3d4f60b4a4af
added hxc-intro-pkmn for seeing which pokemon is displayed in oak's intro, and sxc-intro-pkmn! for modifying it.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Sun, 01 Apr 2012 01:50:34 -0500 |
parents | 95b2758dd517 |
children |
line wrap: on
line source
1 (ns com.aurellem.gb.dv2 (:use (com.aurellem.gb gb-driver util constants))3 (:import [com.aurellem.gb.gb_driver SaveState]))5 (def pokemon-1-DV-start 0xD185)7 (defn pokemon-DV-start-point [poke-num]8 (+ (* poke-num pokemon-record-width)9 pokemon-1-DV-start))11 (defn read-DV12 ([^SaveState state poke-num]13 (assert (<= 0 poke-num 5))14 (let [[raw-DV-115 raw-DV-2]16 (subvec (vec (memory state))17 (pokemon-DV-start-point poke-num)18 (+ 2 (pokemon-DV-start-point poke-num)))19 defense-DV (bit-and raw-DV-1 0x0F)20 attack-DV (bit-shift-right21 (bit-and raw-DV-1 0xF0)22 4)23 special-DV (bit-and raw-DV-2 0x0F)24 speed-DV (bit-shift-right25 (bit-and raw-DV-2 0xF0)26 4)27 HP-DV28 (+29 (if (bit-test special-DV 0) 1 0)30 (if (bit-test speed-DV 0) 2 0)31 (if (bit-test defense-DV 0) 4 0)32 (if (bit-test attack-DV 0) 8 0))]33 {:attack attack-DV34 :defense defense-DV35 :speed speed-DV36 :special special-DV37 :hp HP-DV}))38 ([poke-num]39 (read-DV @current-state poke-num)))42 (defn give-DV43 ([^SaveState state poke-num dv-values]45 (assert (<= 0 poke-num 5))46 (map #(assert (<= 0 % 15)) (vals dv-values))47 (let [raw-dv-1*48 (+ (:defense dv-values)49 (bit-shift-left (:attack dv-values) 4))50 raw-dv-2*51 (+ (:special dv-values)52 (bit-shift-left (:speed dv-values) 4))53 hp-dv (:hp dv-values)54 hp-masks-155 [[0 (bit-test hp-dv 2)]56 [4 (bit-test hp-dv 3)]]57 hp-masks-258 [[0 (bit-test hp-dv 0)]59 [4 (bit-test hp-dv 1)]]60 set-hp-bits61 (fn [init [index hp?]]62 (if hp?63 (bit-set init index)64 (bit-clear init index)))66 raw-dv-1 (reduce set-hp-bits raw-dv-1*67 hp-masks-1)69 raw-dv-2 (reduce set-hp-bits raw-dv-2*70 hp-masks-2)72 dv-start (pokemon-DV-start-point poke-num)]74 (if (or (not= raw-dv-1* raw-dv-1)75 (not= raw-dv-2* raw-dv-2))76 (println "Warning: inconsistent DV-values."77 "Using HP settings."))79 (set-memory80 (set-memory state dv-start raw-dv-1)81 (inc dv-start) raw-dv-2)))82 ([poke-num dv-values]83 (give-DV @current-state poke-num dv-values)))85 (def good-DVs86 {:attack 1587 :defense 1588 :speed 1589 :special 1590 :hp 15})92 (def bad-DVs93 {:attack 094 :defense 095 :speed 096 :special 097 :hp 0})