comparison clojure/com/aurellem/gb/mem_util.clj @ 346:5639312a393f

Saving progress. Cleaned up documentation a little; found more ROM stuff, including names of status ailments and amount of HP restored by potions.
author Dylan Holmes <ocsenave@gmail.com>
date Sun, 08 Apr 2012 01:28:39 -0500
parents 3d4f60b4a4af
children
comparison
equal deleted inserted replaced
344:9366539d29b6 346:5639312a393f
188 ((partial rewrite-memory (vec (rom(root)))) 188 ((partial rewrite-memory (vec (rom(root))))
189 start strs-or-bytes)) 189 start strs-or-bytes))
190 190
191 (defn restore-rom! [] (write-rom! original-rom)) 191 (defn restore-rom! [] (write-rom! original-rom))
192 192
193
194 (defn endian-flip
195 "Flip the bytes of the two-byte number."
196 [n]
197 (assert (< n 0xFFFF))
198 (+ (* 0x100 (rem n 0x100))
199 (int (/ n 0x100))))
200
201
202 (defn offset->ptr
203 "Convert an offset into a little-endian pointer."
204 [n]
205 (->
206 n
207 (rem 0x10000) ;; take last four bytes
208 (rem 0x4000) ;; get relative offset from the start of the bank
209 (+ 0x4000)
210 endian-flip))
211
212 (defn offset->bank
213 "Get the bank of the offset."
214 [n]
215 (int (/ n 0x4000)))
216
217 (defn ptr->offset
218 "Convert a two-byte little-endian pointer into an offset."
219 [bank ptr]
220 (->
221 ptr
222 endian-flip
223 (- 0x4000)
224 (+ (* 0x4000 bank))
225 ))
226
227 (defn same-bank-offset
228 "Convert a ptr into an absolute offset by using the bank of the reference."
229 [reference ptr]
230 (ptr->offset
231 (offset->bank reference)
232 ptr))