Mercurial > vba-clojure
changeset 176:95b2758dd517
wrote functions to read and write pokemon DV values and status
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 21 Mar 2012 22:13:43 -0500 |
parents | 5d9a7a0ca09a |
children | b42a2552016c |
files | clojure/com/aurellem/exp/item_bridge.clj clojure/com/aurellem/exp/pokemon-layout clojure/com/aurellem/exp/pokemon.clj clojure/com/aurellem/gb/assembly.clj clojure/com/aurellem/gb/characters.clj clojure/com/aurellem/gb/constants.clj clojure/com/aurellem/gb/dv.clj clojure/com/aurellem/gb/pokemon.clj clojure/com/aurellem/gb/status.clj clojure/com/aurellem/gb/util.clj src/sdl/SDL.cpp |
diffstat | 11 files changed, 390 insertions(+), 138 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/exp/item_bridge.clj Wed Mar 21 18:17:37 2012 -0500 1.2 +++ b/clojure/com/aurellem/exp/item_bridge.clj Wed Mar 21 22:13:43 2012 -0500 1.3 @@ -51,11 +51,12 @@ 1.4 1.5 (defn capture-program-counter 1.6 [^SaveState state ticks] 1.7 - (set-state! state) 1.8 + (tick state) 1.9 + 1.10 (loop [i 0 1.11 pcs []] 1.12 (if (= i ticks) 1.13 - pcs 1.14 + (set pcs) 1.15 (do 1.16 (com.aurellem.gb.Gb/tick) 1.17 (recur (inc i)
2.1 --- a/clojure/com/aurellem/exp/pokemon-layout Wed Mar 21 18:17:37 2012 -0500 2.2 +++ b/clojure/com/aurellem/exp/pokemon-layout Wed Mar 21 22:13:43 2012 -0500 2.3 @@ -5,7 +5,7 @@ 2.4 D166 Pokemon 4 Species 2.5 D167 Pokemon 5 Species 2.6 D168 Pokemon 6 Species 2.7 -D169 2.8 +D169 End-of-List Sentinel (0xFF) 2.9 D16A Pokemon 1 Color Map 2.10 D16B /h 2.11 D16C \l Pokemon 1 Current Hit Points
3.1 --- a/clojure/com/aurellem/exp/pokemon.clj Wed Mar 21 18:17:37 2012 -0500 3.2 +++ b/clojure/com/aurellem/exp/pokemon.clj Wed Mar 21 22:13:43 2012 -0500 3.3 @@ -116,18 +116,6 @@ 3.4 ([new-name] 3.5 (rename-sixth-pokemon @current-state new-name))) 3.6 3.7 -(defn print-text 3.8 - ([^SaveState state begin end] 3.9 - (dorun 3.10 - (map (fn [character-code line] 3.11 - (println 3.12 - (format "0x%04X: " line) 3.13 - (str (character-code->character character-code)))) 3.14 - (subvec (vec (memory state)) begin end) 3.15 - (range begin end))) 3.16 - state) 3.17 - ([begin end] 3.18 - (print-text @current-state begin end))) 3.19 3.20 (defn examine-name-memory [] 3.21 (print-text 3.22 @@ -517,9 +505,6 @@ 3.23 (set-pokemon-id @current-state n new-id))) 3.24 3.25 3.26 - 3.27 - 3.28 - 3.29 (defn get-pokemon-1-info 3.30 ([state] 3.31 (subvec (vec (memory state)) 3.32 @@ -733,117 +718,33 @@ 3.33 ;; 10000000 3.34 ;; Speed => 210 (+16) 3.35 3.36 -(def pokemon-1-DV-start 0xD185) 3.37 3.38 -(defn pokemon-DV-start-point [poke-num] 3.39 - (+ (* poke-num pokemon-record-width) 3.40 - pokemon-1-DV-start)) 3.41 +;; investigating status effects 3.42 3.43 -(def reverse-4-bit 3.44 - {0 0 3.45 - 1 8 3.46 - 2 4 3.47 - 3 12 3.48 - 5 10 3.49 - 6 6 3.50 - 7 14 3.51 - 9 9 3.52 - 15 15 3.53 - 13 11 3.54 +;; status of pokemon 1 appears to be 3.55 +;; 0xD16E 3.56 3.57 - 8 1 3.58 - 4 2 3.59 - 12 3 3.60 - 10 5 3.61 - 11 13 3.62 - 14 7 }) 3.63 - 3.64 -(defn read-DV 3.65 - ([^SaveState state poke-num] 3.66 - (assert (<= 0 poke-num 5)) 3.67 - (let [[raw-DV-1 3.68 - raw-DV-2] 3.69 - (subvec (vec (memory state)) 3.70 - (pokemon-DV-start-point poke-num) 3.71 - (+ 2 (pokemon-DV-start-point poke-num))) 3.72 - defense-DV (bit-and raw-DV-1 0x0F) 3.73 - attack-DV (bit-shift-right 3.74 - (bit-and raw-DV-1 0xF0) 3.75 - 4) 3.76 - special-DV (bit-and raw-DV-2 0x0F) 3.77 - speed-DV (bit-shift-right 3.78 - (bit-and raw-DV-2 0xF0) 3.79 - 4) 3.80 - HP-DV 3.81 - (+ 3.82 - (if (bit-test special-DV 0) 1 0) 3.83 - (if (bit-test speed-DV 0) 2 0) 3.84 - (if (bit-test defense-DV 0) 4 0) 3.85 - (if (bit-test attack-DV 0) 8 0))] 3.86 - {:attack attack-DV 3.87 - :defense defense-DV 3.88 - :speed speed-DV 3.89 - :special special-DV 3.90 - :hp HP-DV})) 3.91 - ([poke-num] 3.92 - (read-DV @current-state poke-num))) 3.93 - 3.94 +;; with pidgeot 3.95 +;; 00000000 -- normal 3.96 +;; 00000001 -- sleep (wake-immediately) 3.97 +;; 00000010 -- sleep 3.98 +;; 00000100 -- sleep 3.99 +;; 00001000 -- poisoned 3.100 +;; 00010000 -- burned 3.101 +;; 00100000 -- frozen 3.102 +;; 01000000 -- paralyzed 3.103 +;; 10000000 -- ball is dark, but no status 3.104 3.105 -(defn give-DV 3.106 - ([^SaveState state poke-num dv-values] 3.107 - 3.108 - (assert (<= 0 poke-num 5)) 3.109 - (map #(assert (<= 0 % 15)) (vals dv-values)) 3.110 - (let [raw-dv-1* 3.111 - (+ (:defense dv-values) 3.112 - (bit-shift-left (:attack dv-values) 4)) 3.113 - raw-dv-2* 3.114 - (+ (:special dv-values) 3.115 - (bit-shift-left (:speed dv-values) 4)) 3.116 - hp-dv (:hp dv-values) 3.117 - hp-masks-1 3.118 - [[0 (bit-test hp-dv 2)] 3.119 - [4 (bit-test hp-dv 3)]] 3.120 - hp-masks-2 3.121 - [[0 (bit-test hp-dv 0)] 3.122 - [4 (bit-test hp-dv 1)]] 3.123 - set-hp-bits 3.124 - (fn [init [index hp?]] 3.125 - (if hp? 3.126 - (bit-set init index) 3.127 - (bit-clear init index))) 3.128 +;; with pikachu 3.129 +;; 00000000 -- normal 3.130 +;; 00000001 -- sleep (1 turn wasted) \ 3.131 +;; 00000010 -- sleep (2 turns wasted) |-- additive 3.132 +;; 00000100 -- sleep (3 turns wasted) / 3.133 +;; 00001000 -- poisoned 3.134 +;; 00010000 -- burned 3.135 +;; 00100000 -- frozen 3.136 +;; 01000000 -- paralyzed 3.137 +;; 10000000 -- ball is dark, but no status 3.138 3.139 - raw-dv-1 (reduce set-hp-bits raw-dv-1* 3.140 - hp-masks-1) 3.141 - 3.142 - raw-dv-2 (reduce set-hp-bits raw-dv-2* 3.143 - hp-masks-2) 3.144 - 3.145 - dv-start (pokemon-DV-start-point poke-num)] 3.146 3.147 - (if (or (not= raw-dv-1* raw-dv-1) 3.148 - (not= raw-dv-2* raw-dv-2)) 3.149 - (println "Warning: inconsistent DV-values." 3.150 - "Using HP settings.")) 3.151 - 3.152 - (set-memory 3.153 - (set-memory state dv-start raw-dv-1) 3.154 - (inc dv-start) raw-dv-2))) 3.155 - ([poke-num dv-values] 3.156 - (give-DV @current-state poke-num dv-values))) 3.157 - 3.158 -(def good-DVs 3.159 - {:attack 15 3.160 - :defense 15 3.161 - :speed 15 3.162 - :special 15 3.163 - :hp 15}) 3.164 - 3.165 -(def bad-DVs 3.166 - {:attack 0 3.167 - :defense 0 3.168 - :speed 0 3.169 - :special 0 3.170 - :hp 0}) 3.171 - 3.172 - 3.173 \ No newline at end of file 3.174 + 3.175 \ No newline at end of file
4.1 --- a/clojure/com/aurellem/gb/assembly.clj Wed Mar 21 18:17:37 2012 -0500 4.2 +++ b/clojure/com/aurellem/gb/assembly.clj Wed Mar 21 22:13:43 2012 -0500 4.3 @@ -406,7 +406,6 @@ 4.4 (set-state! (input-number)) 4.5 (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) 4.6 4.7 - 4.8 (defn write-memory-assembly* 4.9 "A program for altering in-game memory by pressing buttons." 4.10 []
5.1 --- a/clojure/com/aurellem/gb/characters.clj Wed Mar 21 18:17:37 2012 -0500 5.2 +++ b/clojure/com/aurellem/gb/characters.clj Wed Mar 21 22:13:43 2012 -0500 5.3 @@ -1,5 +1,5 @@ 5.4 (ns com.aurellem.gb.characters 5.5 - (:use (com.aurellem.gb gb-driver)) 5.6 + (:use (com.aurellem.gb gb-driver constants)) 5.7 (:import [com.aurellem.gb.gb_driver SaveState])) 5.8 5.9 (def character-code->character 5.10 @@ -114,5 +114,21 @@ 5.11 % 5.12 (format "[0x%02X]" %)) 5.13 codes))) 5.14 - 5.15 5.16 +(defn print-text 5.17 + ([^SaveState state begin end] 5.18 + (dorun 5.19 + (map (fn [character-code line] 5.20 + (println 5.21 + (format "0x%04X: " line) 5.22 + (str (character-code->character character-code)))) 5.23 + (subvec (vec (memory state)) begin end) 5.24 + (range begin end))) 5.25 + state) 5.26 + ([begin end] 5.27 + (print-text @current-state begin end))) 5.28 + 5.29 +(defn read-name [codes] 5.30 + (character-codes->str 5.31 + (take-while 5.32 + (partial not= end-of-name-marker) codes)))
6.1 --- a/clojure/com/aurellem/gb/constants.clj Wed Mar 21 18:17:37 2012 -0500 6.2 +++ b/clojure/com/aurellem/gb/constants.clj Wed Mar 21 22:13:43 2012 -0500 6.3 @@ -1,3 +1,7 @@ 6.4 (ns com.aurellem.gb.constants) 6.5 6.6 -(def pokemon-record-width 44) 6.7 \ No newline at end of file 6.8 +(def pokemon-record-width 44) 6.9 + 6.10 +(def end-of-name-marker 0x50) 6.11 +(def max-name-length 10) 6.12 +(def name-width 11)
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/clojure/com/aurellem/gb/dv.clj Wed Mar 21 22:13:43 2012 -0500 7.3 @@ -0,0 +1,97 @@ 7.4 +(ns com.aurellem.gb.dv 7.5 + (:use (com.aurellem.gb gb-driver util constants)) 7.6 + (:import [com.aurellem.gb.gb_driver SaveState])) 7.7 + 7.8 +(def pokemon-1-DV-start 0xD185) 7.9 + 7.10 +(defn pokemon-DV-start-point [poke-num] 7.11 + (+ (* poke-num pokemon-record-width) 7.12 + pokemon-1-DV-start)) 7.13 + 7.14 +(defn read-DV 7.15 + ([^SaveState state poke-num] 7.16 + (assert (<= 0 poke-num 5)) 7.17 + (let [[raw-DV-1 7.18 + raw-DV-2] 7.19 + (subvec (vec (memory state)) 7.20 + (pokemon-DV-start-point poke-num) 7.21 + (+ 2 (pokemon-DV-start-point poke-num))) 7.22 + defense-DV (bit-and raw-DV-1 0x0F) 7.23 + attack-DV (bit-shift-right 7.24 + (bit-and raw-DV-1 0xF0) 7.25 + 4) 7.26 + special-DV (bit-and raw-DV-2 0x0F) 7.27 + speed-DV (bit-shift-right 7.28 + (bit-and raw-DV-2 0xF0) 7.29 + 4) 7.30 + HP-DV 7.31 + (+ 7.32 + (if (bit-test special-DV 0) 1 0) 7.33 + (if (bit-test speed-DV 0) 2 0) 7.34 + (if (bit-test defense-DV 0) 4 0) 7.35 + (if (bit-test attack-DV 0) 8 0))] 7.36 + {:attack attack-DV 7.37 + :defense defense-DV 7.38 + :speed speed-DV 7.39 + :special special-DV 7.40 + :hp HP-DV})) 7.41 + ([poke-num] 7.42 + (read-DV @current-state poke-num))) 7.43 + 7.44 + 7.45 +(defn give-DV 7.46 + ([^SaveState state poke-num dv-values] 7.47 + 7.48 + (assert (<= 0 poke-num 5)) 7.49 + (map #(assert (<= 0 % 15)) (vals dv-values)) 7.50 + (let [raw-dv-1* 7.51 + (+ (:defense dv-values) 7.52 + (bit-shift-left (:attack dv-values) 4)) 7.53 + raw-dv-2* 7.54 + (+ (:special dv-values) 7.55 + (bit-shift-left (:speed dv-values) 4)) 7.56 + hp-dv (:hp dv-values) 7.57 + hp-masks-1 7.58 + [[0 (bit-test hp-dv 2)] 7.59 + [4 (bit-test hp-dv 3)]] 7.60 + hp-masks-2 7.61 + [[0 (bit-test hp-dv 0)] 7.62 + [4 (bit-test hp-dv 1)]] 7.63 + set-hp-bits 7.64 + (fn [init [index hp?]] 7.65 + (if hp? 7.66 + (bit-set init index) 7.67 + (bit-clear init index))) 7.68 + 7.69 + raw-dv-1 (reduce set-hp-bits raw-dv-1* 7.70 + hp-masks-1) 7.71 + 7.72 + raw-dv-2 (reduce set-hp-bits raw-dv-2* 7.73 + hp-masks-2) 7.74 + 7.75 + dv-start (pokemon-DV-start-point poke-num)] 7.76 + 7.77 + (if (or (not= raw-dv-1* raw-dv-1) 7.78 + (not= raw-dv-2* raw-dv-2)) 7.79 + (println "Warning: inconsistent DV-values." 7.80 + "Using HP settings.")) 7.81 + 7.82 + (set-memory 7.83 + (set-memory state dv-start raw-dv-1) 7.84 + (inc dv-start) raw-dv-2))) 7.85 + ([poke-num dv-values] 7.86 + (give-DV @current-state poke-num dv-values))) 7.87 + 7.88 +(def good-DVs 7.89 + {:attack 15 7.90 + :defense 15 7.91 + :speed 15 7.92 + :special 15 7.93 + :hp 15}) 7.94 + 7.95 +(def bad-DVs 7.96 + {:attack 0 7.97 + :defense 0 7.98 + :speed 0 7.99 + :special 0 7.100 + :hp 0})
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/clojure/com/aurellem/gb/pokemon.clj Wed Mar 21 22:13:43 2012 -0500 8.3 @@ -0,0 +1,178 @@ 8.4 +(ns com.aurellem.gb.pokemon 8.5 + (:use (com.aurellem.gb gb-driver util constants characters)) 8.6 + (:import [com.aurellem.gb.gb_driver SaveState])) 8.7 + 8.8 +(def pokemon-names-start 0xD2B4) 8.9 + 8.10 +(defn change-party-number [^SaveState state new-num] 8.11 + (set-memory state 0xD162 new-num)) 8.12 + 8.13 +(def party-number-address 0xD162) 8.14 + 8.15 +(defn party-number 8.16 + ([^SaveState state] 8.17 + (aget (memory state) party-number-address)) 8.18 + ([] (party-number @current-state))) 8.19 + 8.20 +(defn party-names 8.21 + ([^SaveState state] 8.22 + (let [raw-names 8.23 + (subvec (vec (memory state)) 8.24 + pokemon-names-start 8.25 + (+ pokemon-names-start 8.26 + (* name-width 6)))] 8.27 + (map 8.28 + read-name 8.29 + (take 8.30 + (party-number state) 8.31 + (partition name-width 8.32 + raw-names))))) 8.33 + ([] (party-names @current-state))) 8.34 + 8.35 +(defn rename-pokemon 8.36 + ([^SaveState state n new-name] 8.37 + (assert (<= 0 n (dec (party-number state)))) 8.38 + (assert (<= (count new-name) max-name-length)) 8.39 + (set-memory-range 8.40 + state 8.41 + (+ (* n name-width) pokemon-names-start) 8.42 + (concat (str->character-codes new-name) [end-of-name-marker]))) 8.43 + ([n new-name] 8.44 + (rename-pokemon @current-state n new-name))) 8.45 + 8.46 +(def OT-start 0xD272) 8.47 + 8.48 +(defn original-trainers 8.49 + ([^SaveState state] 8.50 + (let [raw-names 8.51 + (subvec (vec (memory state)) 8.52 + OT-start 8.53 + (+ OT-start 8.54 + (* name-width 6)))] 8.55 + (map read-name 8.56 + (take (party-number state) 8.57 + (partition name-width raw-names))))) 8.58 + ([] (original-trainers @current-state))) 8.59 + 8.60 +(defn set-original-trainer 8.61 + "Set the OT name for a pokemon. 8.62 + Note that a pokemon is still considered 'yours' if 8.63 + the OT ID is the same as your own." 8.64 + ([^SaveState state poke-num new-name] 8.65 + (assert (<= 0 poke-num (dec (party-number state)))) 8.66 + (assert (<= (count new-name) max-name-length)) 8.67 + (set-memory-range 8.68 + state 8.69 + (+ (* poke-num name-width) OT-start) 8.70 + (concat (str->character-codes new-name) [end-of-name-marker]))) 8.71 + ([n new-name] 8.72 + (set-original-trainer @current-state n new-name))) 8.73 + 8.74 +(def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD228 0xD252]) 8.75 + 8.76 +(defn set-pokemon-id 8.77 + ([^SaveState state n new-id] 8.78 + (assert (<= 0 n (dec (party-number state)))) 8.79 + (assert (<= 0 new-id 0xFFFF)) 8.80 + (set-memory-range 8.81 + state 8.82 + (OT-ID-addresses n) 8.83 + [(bit-shift-right (bit-and new-id 0xFF00) 8) 8.84 + (bit-and new-id 0xFF) 8.85 + ])) 8.86 + ([n new-id] 8.87 + (set-pokemon-id @current-state n new-id))) 8.88 + 8.89 +(def unknown "[[[UNKNOWN]]]") 8.90 + 8.91 +(def unknown "") 8.92 + 8.93 +(def pokemon-1-info 8.94 + {0xD16A "Color Map" ;; 0 8.95 + 0xD16B "Current-HP (h)" ;; 1 8.96 + 0xD16C "Current-HP (l)" ;; 2 8.97 + 0XD16D unknown ;; 3 8.98 + 0xD16E unknown ;; 4 8.99 + 0xD16F unknown ;; 5 8.100 + 0xD170 unknown ;; 6 8.101 + 0xD171 unknown ;; 7 8.102 + 0xD172 "Move 1 ID" ;; 8 8.103 + 0xD173 "Move 2 ID" ;; 9 8.104 + 0xD174 "Move 3 ID" ;; 10 8.105 + 0xD175 "Move 4 ID" ;; 11 8.106 + 0xD176 "OT-ID (h)" ;; 12 8.107 + 0xD177 "OT-ID (l)" ;; 13 8.108 + 0xD178 "Exp. Points (h)" ;; 14 8.109 + 0xD179 "Exp. Points (m)" ;; 15 8.110 + 0xD17A "Exp. Points (l)" ;; 16 8.111 + 0xD17B "HP Exp. (h)" ;; 17 8.112 + 0xD17C "HP Exp. (l)" ;; 18 8.113 + 0xD17D "Attack Exp. (h)" ;; 19 8.114 + 0xD17E "Attack Exp. (l)" ;; 20 8.115 + 0xD17F "Defense Exp. (h)" ;; 21 8.116 + 0xD180 "Defense Exp. (l)" ;; 22 8.117 + 0xD181 "Speed Exp. (h)" ;; 23 8.118 + 0xD182 "Speed Exp. (l)" ;; 24 8.119 + 0xD183 "Special Exp. (h)" ;; 25 8.120 + 0xD184 "Special Exp. (l)" ;; 26 8.121 + 0xD185 "DV Atk/Def" ;; 27 8.122 + 0xD186 "DV Speed/Spc" ;; 28 8.123 + 0xD187 "PP Move 1" ;; 29 8.124 + 0xD188 "PP Move 2" ;; 30 8.125 + 0xD189 "PP Move 3" ;; 31 8.126 + 0xD18A "PP Move 4" ;; 32 8.127 + 0xD18B "Current Level" ;; 33 8.128 + 0xD18C "HP Total (h)" ;; 34 8.129 + 0xD18D "HP Total (l)" ;; 35 8.130 + 0xD18E "Attack (h)" ;; 36 8.131 + 0xD18F "Attack (l)" ;; 37 8.132 + 0xD190 "Defense (h)" ;; 38 8.133 + 0xD191 "Defense (l)" ;; 39 8.134 + 0xD192 "Speed (h)" ;; 40 8.135 + 0xD193 "Speed (l)" ;; 41 8.136 + 0xD194 "Special (h)" ;; 42 8.137 + 0xD195 "Special (l)" ;; 43 8.138 + }) 8.139 + 8.140 +(defn pokemon-data 8.141 + ([^SaveState state pokemon-num] 8.142 + (assert (<= 0 pokemon-num 5)) 8.143 + (let [base (+ (* pokemon-num pokemon-record-width) 0xD16A)] 8.144 + (subvec (vec (memory state)) base 8.145 + (+ base pokemon-record-width)))) 8.146 + ([pokemon-num] (pokemon-data @current-state pokemon-num))) 8.147 + 8.148 +(defn set-pokemon-data 8.149 + ([^SaveState state pokemon-num new-data] 8.150 + (assert (<= 0 pokemon-num 5)) 8.151 + (let [base (+ (* pokemon-num pokemon-record-width) 0xD16A)] 8.152 + (set-memory-range state base new-data))) 8.153 + ([pokemon-num new-data] 8.154 + (set-pokemon-data @current-state pokemon-num new-data))) 8.155 + 8.156 +(defn print-pokemon-data 8.157 + ([^SaveState state pokemon-num] 8.158 + (assert (<= 0 pokemon-num 5)) 8.159 + (let [poke-data (pokemon-data state pokemon-num) 8.160 + backbone (sort (keys pokemon-1-info))] 8.161 + (println "Pokemon " pokemon-num " -- " 8.162 + (nth (party-names state) 8.163 + pokemon-num) \newline) 8.164 + 8.165 + (println " Desc. | Hex | Dec | Binary |") 8.166 + (println "-------------------+------+-----+----------+") 8.167 + (dorun 8.168 + (map 8.169 + (comp println 8.170 + (fn [desc data] 8.171 + (format "%-16s | 0x%02X | %3d | %s |" 8.172 + desc data data 8.173 + (let [s (Integer/toBinaryString data)] 8.174 + (apply 8.175 + str 8.176 + (concat (repeat (- 8 (count s)) "0" ) 8.177 + s)))))) 8.178 + (map pokemon-1-info backbone) 8.179 + poke-data)))) 8.180 + ([pokemon-num] 8.181 + (print-pokemon-data @current-state pokemon-num)))
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/clojure/com/aurellem/gb/status.clj Wed Mar 21 22:13:43 2012 -0500 9.3 @@ -0,0 +1,50 @@ 9.4 +(ns com.aurellem.gb.status 9.5 + (:use (com.aurellem.gb gb-driver util constants)) 9.6 + (:import [com.aurellem.gb.gb_driver SaveState])) 9.7 + 9.8 +(def status-name->status-code 9.9 + {:normal (Integer/parseInt "00000000" 2) 9.10 + :sleep-1 (Integer/parseInt "00000001" 2) 9.11 + :sleep-2 (Integer/parseInt "00000010" 2) 9.12 + :sleep-3 (Integer/parseInt "00000011" 2) 9.13 + :sleep-4 (Integer/parseInt "00000100" 2) 9.14 + :sleep-5 (Integer/parseInt "00000101" 2) 9.15 + :sleep-6 (Integer/parseInt "00000111" 2) 9.16 + :poisoned (Integer/parseInt "00001000" 2) 9.17 + :burned (Integer/parseInt "00010000" 2) 9.18 + :frozen (Integer/parseInt "00100000" 2) 9.19 + :paralyzed (Integer/parseInt "01000000" 2)}) 9.20 + 9.21 +(def status-code->status-name 9.22 + (zipmap (vals status-name->status-code) 9.23 + (keys status-name->status-code))) 9.24 + 9.25 + 9.26 +(def pokemon-1-status-address 0xD16E) 9.27 + 9.28 +(defn pokemon-status-address [poke-num] 9.29 + (+ pokemon-1-status-address 9.30 + (* poke-num pokemon-record-width))) 9.31 + 9.32 +(defn give-stat 9.33 + ([^SaveState state poke-num status] 9.34 + (assert (<= 0 poke-num 5)) 9.35 + (let [status-code 9.36 + (status-name->status-code status)] 9.37 + (assert status-code) 9.38 + (set-memory state 9.39 + (pokemon-status-address poke-num) 9.40 + status-code))) 9.41 + ([poke-num status] 9.42 + (give-stat @current-state poke-num status)) 9.43 + ([status] 9.44 + (give-stat @current-state 0 status))) 9.45 + 9.46 +(defn give-stat-all 9.47 + ([^SaveState state status] 9.48 + (reduce (fn [state num] 9.49 + (give-stat state num status)) 9.50 + state 9.51 + (range (party-number state)))) 9.52 + ([status] 9.53 + (give-stat-all @current-state status)))
10.1 --- a/clojure/com/aurellem/gb/util.clj Wed Mar 21 18:17:37 2012 -0500 10.2 +++ b/clojure/com/aurellem/gb/util.clj Wed Mar 21 22:13:43 2012 -0500 10.3 @@ -42,13 +42,16 @@ 10.4 ([mem] 10.5 (view-memory @current-state mem))) 10.6 10.7 -(defn print-listing [state begin end] 10.8 - (dorun (map 10.9 - (fn [opcode line] 10.10 - (println (format "0x%04X: 0x%02X" line opcode))) 10.11 - (subvec (vec (memory state)) begin end) 10.12 - (range begin end))) 10.13 - state) 10.14 +(defn print-listing 10.15 + ([^SaveState state begin end] 10.16 + (dorun (map 10.17 + (fn [opcode line] 10.18 + (println (format "0x%04X: 0x%02X" line opcode))) 10.19 + (subvec (vec (memory state)) begin end) 10.20 + (range begin end))) 10.21 + state) 10.22 + ([begin end] 10.23 + (print-listing @current-state begin end))) 10.24 10.25 (defn print-pc 10.26 ([^SaveState state]
11.1 --- a/src/sdl/SDL.cpp Wed Mar 21 18:17:37 2012 -0500 11.2 +++ b/src/sdl/SDL.cpp Wed Mar 21 22:13:43 2012 -0500 11.3 @@ -2063,7 +2063,10 @@ 11.4 } 11.5 11.6 int tick () { 11.7 - return theEmulator.emuMain(theEmulator.emuCount); 11.8 + int ret; 11.9 + ret = theEmulator.emuMain(theEmulator.emuCount); 11.10 + // enable user input while ticking. 11.11 + if (ret) { sdlPollEvents(); } 11.12 } 11.13 11.14 void step () {