Mercurial > vba-clojure
view clojure/com/aurellem/gb/experience.clj @ 191:893c753f8088
added function to set ROM
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 20:10:09 -0500 |
parents | |
children | fd549c8f42ae |
line wrap: on
line source
1 (ns com.aurellem.gb.experience2 (:use (com.aurellem.gb gb-driver util constants))3 (:import [com.aurellem.gb.gb_driver SaveState]))5 (def experience-pokemon-1 0xD178)7 (defn experience-start-address [poke-num]8 (+ experience-pokemon-19 (* pokemon-record-width poke-num)))11 (def experience-record-width 13)13 (defn read-experience14 ([^SaveState state poke-num]15 (let [start (experience-start-address poke-num)16 [exp-h17 exp-m18 exp-l19 hp-exp-h20 hp-exp-l21 attack-exp-h22 attack-exp-l23 defense-exp-h24 defense-exp-l25 speed-exp-h26 speed-exp-l27 special-exp-h28 special-exp-l]29 (subvec (vec (memory state))30 start (+ experience-record-width start))31 glue-bytes (fn [l h]32 (+ l (bit-shift-left h 8)))]33 {:main-exp (+ (glue-bytes exp-l exp-m)34 (bit-shift-left exp-h 16))35 :hp-exp (glue-bytes hp-exp-l hp-exp-h)36 :attack-exp (glue-bytes attack-exp-l attack-exp-h)37 :defense-exp (glue-bytes defense-exp-l defense-exp-h)38 :speed-exp (glue-bytes speed-exp-l speed-exp-h)39 :special-exp (glue-bytes special-exp-l special-exp-h)}))40 ([poke-num]41 (read-experience @current-state poke-num)))43 (defn give-experience44 ([^SaveState state poke-num exp]45 (let [exp* (merge (read-experience state poke-num)46 exp)48 disect-bytes49 (fn [exp]50 [(bit-shift-right51 (bit-and exp 0xFF00) 8)52 (bit-and exp 0xFF)])54 raw-exp-data55 (flatten56 [(bit-shift-right (bit-and (:main-exp exp*) 0xFF0000) 16)57 (disect-bytes (:main-exp exp*))58 (disect-bytes (:hp-exp exp*))59 (disect-bytes (:attack-exp exp*))60 (disect-bytes (:defense-exp exp*))61 (disect-bytes (:speed-exp exp*))62 (disect-bytes (:special-exp exp*))])]63 (set-memory-range state64 (experience-start-address poke-num)65 raw-exp-data)))66 ([poke-num exp]67 (give-experience @current-state poke-num exp)))