Mercurial > vba-clojure
view clojure/com/aurellem/gb/pokemon.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.pokemon2 (:use (com.aurellem.gb gb-driver util constants characters3 moves types items status dv species4 experience5 ))6 (:import [com.aurellem.gb.gb_driver SaveState]))8 (def pokemon-names-start 0xD2B4)10 (defn set-party-number11 ([^SaveState state new-party-num]12 (set-memory state 0xD162 new-party-num))13 ([new-party-num]14 (set-party-number @current-state new-party-num)))16 (def party-number-address 0xD162)18 (defn party-number19 ([^SaveState state]20 (aget (memory state) party-number-address))21 ([] (party-number @current-state)))23 (defn party-names24 ([^SaveState state]25 (let [raw-names26 (subvec (vec (memory state))27 pokemon-names-start28 (+ pokemon-names-start29 (* name-width 6)))]30 (map31 read-name32 (take33 (party-number state)34 (partition name-width35 raw-names)))))36 ([] (party-names @current-state)))38 (defn pokemon-nickname39 ([^SaveState state poke-num]40 (nth (party-names state) poke-num))41 ([poke-num]42 (pokemon-nickname @current-state poke-num)))44 (defn rename-pokemon45 ([^SaveState state n new-name]46 (assert (<= 0 n (dec (party-number state))))47 (assert (<= (count new-name) max-name-length))48 (set-memory-range49 state50 (+ (* n name-width) pokemon-names-start)51 (concat (str->character-codes new-name) [end-of-name-marker])))52 ([n new-name]53 (rename-pokemon @current-state n new-name)))55 (def OT-start 0xD272)57 (defn original-trainers58 ([^SaveState state]59 (let [raw-names60 (subvec (vec (memory state))61 OT-start62 (+ OT-start63 (* name-width 6)))]64 (map read-name65 (take (party-number state)66 (partition name-width raw-names)))))67 ([] (original-trainers @current-state)))69 (defn set-original-trainer70 "Set the OT name for a pokemon.71 Note that a pokemon is still considered 'yours' if72 the OT ID is the same as your own."73 ([^SaveState state poke-num new-name]74 (assert (<= 0 poke-num (dec (party-number state))))75 (assert (<= (count new-name) max-name-length))76 (set-memory-range77 state78 (+ (* poke-num name-width) OT-start)79 (concat (str->character-codes new-name) [end-of-name-marker])))80 ([n new-name]81 (set-original-trainer @current-state n new-name)))83 (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD228 0xD252])85 (defn set-pokemon-id86 ([^SaveState state n new-id]87 (assert (<= 0 n (dec (party-number state))))88 (assert (<= 0 new-id 0xFFFF))89 (set-memory-range90 state91 (OT-ID-addresses n)92 [(bit-shift-right (bit-and new-id 0xFF00) 8)93 (bit-and new-id 0xFF)94 ]))95 ([n new-id]96 (set-pokemon-id @current-state n new-id)))98 (def unknown "[[[UNKNOWN]]]")100 (def unknown "")102 (def pokemon-1-record103 {0xD16A "Color Map" ;; 0104 0xD16B "Current-HP (h)" ;; 1105 0xD16C "Current-HP (l)" ;; 2106 0XD16D "Unused" ;; 3107 0xD16E "Status" ;; 4108 0xD16F "Type 1" ;; 5109 0xD170 "Type 2" ;; 6110 0xD171 "scratch/C.R." ;; 7111 0xD172 "Move 1 ID" ;; 8112 0xD173 "Move 2 ID" ;; 9113 0xD174 "Move 3 ID" ;; 10114 0xD175 "Move 4 ID" ;; 11115 0xD176 "OT-ID (h)" ;; 12116 0xD177 "OT-ID (l)" ;; 13117 0xD178 "Exp. Points (h)" ;; 14118 0xD179 "Exp. Points (m)" ;; 15119 0xD17A "Exp. Points (l)" ;; 16120 0xD17B "HP Exp. (h)" ;; 17121 0xD17C "HP Exp. (l)" ;; 18122 0xD17D "Attack Exp. (h)" ;; 19123 0xD17E "Attack Exp. (l)" ;; 20124 0xD17F "Defense Exp. (h)" ;; 21125 0xD180 "Defense Exp. (l)" ;; 22126 0xD181 "Speed Exp. (h)" ;; 23127 0xD182 "Speed Exp. (l)" ;; 24128 0xD183 "Special Exp. (h)" ;; 25129 0xD184 "Special Exp. (l)" ;; 26130 0xD185 "DV Atk/Def" ;; 27131 0xD186 "DV Speed/Spc" ;; 28132 0xD187 "PP Move 1" ;; 29133 0xD188 "PP Move 2" ;; 30134 0xD189 "PP Move 3" ;; 31135 0xD18A "PP Move 4" ;; 32136 0xD18B "Current Level" ;; 33137 0xD18C "HP Total (h)" ;; 34138 0xD18D "HP Total (l)" ;; 35139 0xD18E "Attack (h)" ;; 36140 0xD18F "Attack (l)" ;; 37141 0xD190 "Defense (h)" ;; 38142 0xD191 "Defense (l)" ;; 39143 0xD192 "Speed (h)" ;; 40144 0xD193 "Speed (l)" ;; 41145 0xD194 "Special (h)" ;; 42146 0xD195 "Special (l)" ;; 43147 })149 (defn pokemon-record150 ([^SaveState state pokemon-num]151 (assert (<= 0 pokemon-num 5))152 (let [base (+ (* pokemon-num pokemon-record-width) 0xD16A)]153 (subvec (vec (memory state)) base154 (+ base pokemon-record-width))))155 ([pokemon-num] (pokemon-record @current-state pokemon-num)))157 (defn set-pokemon-record158 ([^SaveState state pokemon-num new-data]159 (assert (<= 0 pokemon-num 5))160 (let [base (+ (* pokemon-num pokemon-record-width) 0xD16A)]161 (set-memory-range state base new-data)))162 ([pokemon-num new-data]163 (set-pokemon-record @current-state pokemon-num new-data)))165 (defn print-pokemon-record166 ([^SaveState state pokemon-num]167 (assert (<= 0 pokemon-num 5))168 (let [poke-data (pokemon-record state pokemon-num)169 backbone (sort (keys pokemon-1-record))]170 (println "Pokemon " pokemon-num " -- "171 (nth (party-names state)172 pokemon-num) \newline)174 (println " Desc. | Hex | Dec | Binary |")175 (println "-------------------+------+-----+----------+")176 (dorun177 (map178 (comp println179 (fn [desc data]180 (format "%-16s | 0x%02X | %3d | %s |"181 desc data data182 (let [s (Integer/toBinaryString data)]183 (apply184 str185 (concat (repeat (- 8 (count s)) "0" )186 s))))))187 (map pokemon-1-record backbone)188 poke-data))))189 ([pokemon-num]190 (print-pokemon-record @current-state pokemon-num)))192 (def mint-berry-item-code-gsc 0x54)194 (defn pokemon-info195 ([^SaveState state poke-num]196 (assert (<= 0 poke-num 5))197 (let [dv-values (read-DV state poke-num)198 type (read-type state poke-num)199 species (read-species state poke-num)200 species2 (read-species2 state poke-num)201 moves (read-moves state poke-num)202 moves-pp (mapv (partial read-pp state203 poke-num)204 (range (count moves)))205 nickname (pokemon-nickname state poke-num)206 status (read-status state poke-num)207 experience (read-experience state poke-num)208 ]210 {:name nickname211 :species species212 :species2 species2213 :type type214 :dv dv-values215 :moves (zipmap moves moves-pp)217 :satus status218 :experience experience219 }220 ))221 ([poke-num]222 (pokemon-info @current-state poke-num)))