aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.hs
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2021-04-02 13:36:08 +0300
committerAleksey Veresov <aleksey@veresov.pro>2021-04-02 13:36:08 +0300
commit0ecc75b1134d221f544653025150948f0ac2a743 (patch)
tree55c8b53591f10dc437df05291c2a31070e771c3d /src/Utils.hs
parente8b1e83bcfbd7d3969e43c7c6e9e2e228528a67b (diff)
downloadsuem-0ecc75b1134d221f544653025150948f0ac2a743.tar
suem-0ecc75b1134d221f544653025150948f0ac2a743.tar.xz
suem-0ecc75b1134d221f544653025150948f0ac2a743.zip
Puf.
Diffstat (limited to 'src/Utils.hs')
-rw-r--r--src/Utils.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Utils.hs b/src/Utils.hs
index 03d6db3..82b31ca 100644
--- a/src/Utils.hs
+++ b/src/Utils.hs
@@ -2,6 +2,7 @@
module Utils where
import Data.Bits
+import Data.Word (Word8, Word16, Word32)
-------------------------------------------------------------------------------
@@ -19,3 +20,20 @@ fromBits = foldl (\a b -> 2 * a + b) 0 . reverse
extractBits :: Bits a => a -> [Int] -> Int
extractBits x r = fromBits $ toBits x r
+
+
+-------------------------------------------------------------------------------
+-- Size Convertion
+
+convertLong :: Word32 -> Int -> Word32
+convertLong x 1 = x .&. 0x000000FF
+convertLong x 2 = x .&. 0x0000FFFF
+convertLong x 3 = x
+convertLong _ s = error $ "Wrong size (" ++ show s ++ ") of convertLong"
+
+combineLong :: Word32 -> Word32 -> Int -> Word32
+combineLong update base 1 = base .&. 0xFFFFFF00 .|. (convertLong update 1)
+combineLong update base 2 = base .&. 0xFFFF0000 .|. (convertLong update 2)
+combineLong update _ 3 = update
+combineLong _ _ s = error $
+ "Wrong size (" ++ show s ++ ") of combineLong"