Mercurial > vba-clojure
diff clojure/com/aurellem/gb/util.clj @ 192:fd549c8f42ae
fixed compilation problems, added more functionality to pokemon-info
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 22:35:57 -0500 |
parents | 95b2758dd517 |
children | 8523faa122b0 |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/gb/util.clj Thu Mar 22 20:10:09 2012 -0500 1.2 +++ b/clojure/com/aurellem/gb/util.clj Thu Mar 22 22:35:57 2012 -0500 1.3 @@ -110,4 +110,34 @@ 1.4 (read-state "mid-game")) 1.5 1.6 1.7 - 1.8 \ No newline at end of file 1.9 + 1.10 +(defn disect-bytes-2 1.11 + "return a vector consiting of the last 16 bytes of the 1.12 + integer expressed as two 8 bit nimbers (inside an integer) 1.13 + in the form [high-bits low-bits." 1.14 + [num] 1.15 + [(bit-shift-right 1.16 + (bit-and num 0xFF00) 8) 1.17 + (bit-and num 0xFF)]) 1.18 + 1.19 +(defn disect-bytes-3 1.20 + "same as disect-bytes-2 except that it assumes the input is a 1.21 + 24 bit number and returns [high-bits medium-bits low-bits]" 1.22 + [num] 1.23 + (vec 1.24 + (concat 1.25 + [(bit-shift-right (bit-and num 0xFF0000) 16)] 1.26 + (disect-bytes-2 num)))) 1.27 + 1.28 +(defn glue-bytes 1.29 + "Given two or three 8-bit numbers inside 32-bit integers, 1.30 + combine them into the integer number that they together 1.31 + represent." 1.32 + ([h l] 1.33 + (+ l (bit-shift-left h 8))) 1.34 + 1.35 + ([h m l] 1.36 + (+ (glue-bytes m l) 1.37 + (bit-shift-left h 16)))) 1.38 + 1.39 +