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.moves
2 (:use (com.aurellem.gb gb-driver util constants))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
5 (def move-code->move-name
6 {
7 0x01 :pound
8 0x02 :karate-chop
9 0x03 :doubleslap
10 0x04 :comet-punch
11 0x05 :mega-punch
12 0x06 :pay-day
13 0x07 :fire-punch
14 0x08 :ice-punch
15 0x09 :thunderpunch
16 0x0A :scratch
17 0x0B :vicegrip
18 0x0C :guillotine
19 0x0D :razor-wind
20 0x0E :swords-dance
21 0x0F :cut
22 0x10 :gust
23 0x11 :wing-attack
24 0x12 :whirlwind
25 0x13 :fly
26 0x14 :bind
27 0x15 :slam
28 0x16 :vine-whip
29 0x17 :stomp
30 0x18 :double-kick
31 0x19 :mega-kick
32 0x1A :jump-kick
33 0x1B :rolling-kick
34 0x1C :sand-attack
35 0x1D :headbutt
36 0x1E :horn-attack
37 0x1F :fury-attack
38 0x20 :horn-drill
39 0x21 :tackle
40 0x22 :body-slam
41 0x23 :wrap
42 0x24 :take-down
43 0x25 :thrash
44 0x26 :double-edge
45 0x27 :tail-whip
46 0x28 :poison-sting
47 0x29 :twinneedle
48 0x2A :pin-missle
49 0x2B :leer
50 0x2C :bite
51 0x2D :growl
52 0x2E :roar
53 0x2F :sing
54 0x30 :supersonic
55 0x31 :sonicboom
56 0x32 :disable
57 0x33 :acid
58 0x34 :ember
59 0x35 :flamethrower
60 0x36 :mist
61 0x37 :water-gun
62 0x38 :hydro-pump
63 0x39 :surf
64 0x3A :ice-beam
65 0x3B :blizzard
66 0x3C :psybeam
67 0x3D :bubblebeam
68 0x3E :aurora-beam
69 0x3F :hyper-beam
70 0x40 :peck
71 0x41 :drill-peck
72 0x42 :submission
73 0x43 :low-kick
74 0x44 :counter
75 0x45 :seismic-toss
76 0x46 :strength
77 0x47 :absorb
78 0x48 :mega-drain
79 0x49 :leech-seed
80 0x4A :growth
81 0x4B :razor-leaf
82 0x4C :solarbeam
83 0x4D :poisonpowder
84 0x4E :stun-spore
85 0x4F :sleep-powder
86 0x50 :petal-dance
87 0x51 :string-shot
88 0x52 :dragon-rage
89 0x53 :fire-spin
90 0x54 :thundershock
91 0x55 :thunderbolt
92 0x56 :thunder-wave
93 0x57 :thunder
94 0x58 :rock-throw
95 0x59 :earthquake
96 0x5A :fissure
97 0x5B :dig
98 0x5C :toxic
99 0x5D :confusion
100 0x5E :psychic
101 0x5F :hypnosis
102 0x60 :meditate
103 0x61 :agility
104 0x62 :quick-attack
105 0x63 :rage
106 0x64 :teleport
107 0x65 :night-shade
108 0x66 :mimic
109 0x67 :screech
110 0x68 :double-team
111 0x69 :recover
112 0x6A :harden
113 0x6B :minimize
114 0x6C :smokescreen
115 0x6D :confuse-ray
116 0x6E :withdraw
117 0x6F :defense-curl
118 0x70 :barrier
119 0x71 :light-screen
120 0x72 :haze
121 0x73 :reflect
122 0x74 :focus-energy
123 0x75 :bide
124 0x76 :metronome
125 0x77 :mirror-move
126 0x78 :selfdestruct
127 0x79 :egg-bomb
128 0x7A :lick
129 0x7B :smog
130 0x7C :sludge
131 0x7D :bone-club
132 0x7E :fire-blast
133 0x7F :waterfall
134 0x80 :clamp
135 0x81 :swift
136 0x82 :skull-bash
137 0x83 :spike-cannon
138 0x84 :constrict
139 0x85 :amnesia
140 0x86 :kinesis
141 0x87 :softboiled
142 0x88 :hi-jump-kick
143 0x89 :glare
144 0x8A :dream-eater
145 0x8B :poison-gas
146 0x8C :barrage
147 0x8D :leech-life
148 0x8E :lovely-kiss
149 0x8F :sky-attack
150 0x90 :transform
151 0x91 :bubble
152 0x92 :dizzy-punch
153 0x93 :spore
154 0x94 :flash
155 0x95 :psywave
156 0x96 :splash
157 0x97 :acid-armor
158 0x98 :crabhammer
159 0x99 :explosion
160 0x9A :fury-swipes
161 0x9B :bonemerang
162 0x9C :rest
163 0x9D :rock-slide
164 0x9E :hyper-fang
165 0x9F :sharpen
166 0xA0 :conversion
167 0xA1 :tri-attack
168 0xA2 :super-fang
169 0xA3 :slash
170 0xA4 :substitute
171 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-1
178 (* pokemon-num pokemon-record-width)))
180 (def move-name->move-code
181 (zipmap (vals move-code->move-name)
182 (keys move-code->move-name)))
184 (defn give-moves
185 ([^SaveState state pokemon-num moves]
186 (set-memory-range
187 state
188 (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 the
196 ;; total PP are stored in the same value.
197 ;; they are bit-packed, with the first 2 bits containing the
198 ;; number of pp-ups that have been applied, and the next
199 ;; six bits containing the current pp of the move.
200 ;; thus, a move can have up to 63 current pp and up to
201 ;; 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-pp
211 ([^SaveState state pokemon-num move-num]
212 (assert (<= 0 move-num 3))
213 (assert (<= 0 pokemon-num 5))
214 (let [pp-raw
215 (aget (memory state)
216 (+ (moves-pp-start pokemon-num)
217 move-num))
218 pp-up
219 (bit-shift-right
220 (bit-and
221 pp-raw
222 (Integer/parseInt "11000000" 2)) 6)
223 current-pp
224 (bit-and
225 pp-raw
226 (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-pp
232 ([^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-memory
239 state
240 (+ (moves-pp-start pokemon-num)
241 move-num)
242 (+
243 (bit-shift-left pp-ups 6)
244 (bit-and (Integer/parseInt
245 "00111111" 2)
246 current-pp))))
247 ([pokemon-num move-num pp-ups current-pp]
248 (give-pp @current-state
249 pokemon-num move-num pp-ups current-pp)))