comparison 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
comparison
equal deleted inserted replaced
191:893c753f8088 192:fd549c8f42ae
108 108
109 (defn mid-game [] 109 (defn mid-game []
110 (read-state "mid-game")) 110 (read-state "mid-game"))
111 111
112 112
113 113
114 (defn disect-bytes-2
115 "return a vector consiting of the last 16 bytes of the
116 integer expressed as two 8 bit nimbers (inside an integer)
117 in the form [high-bits low-bits."
118 [num]
119 [(bit-shift-right
120 (bit-and num 0xFF00) 8)
121 (bit-and num 0xFF)])
122
123 (defn disect-bytes-3
124 "same as disect-bytes-2 except that it assumes the input is a
125 24 bit number and returns [high-bits medium-bits low-bits]"
126 [num]
127 (vec
128 (concat
129 [(bit-shift-right (bit-and num 0xFF0000) 16)]
130 (disect-bytes-2 num))))
131
132 (defn glue-bytes
133 "Given two or three 8-bit numbers inside 32-bit integers,
134 combine them into the integer number that they together
135 represent."
136 ([h l]
137 (+ l (bit-shift-left h 8)))
138
139 ([h m l]
140 (+ (glue-bytes m l)
141 (bit-shift-left h 16))))
142
143