Add more conversions

This commit is contained in:
Joscha 2019-11-09 23:37:22 +00:00
parent 803c826395
commit 21e72420dd
3 changed files with 21 additions and 14 deletions

View file

@ -13,6 +13,8 @@ module Mima.Word
, boolToWord
, largeValueToWord
, signedSmallValueToWord
, wordFromSmallOpcode
, wordFromLargeOpcode
-- ** 'MimaWord' properties
, getSmallOpcode
, getLargeOpcode
@ -59,6 +61,12 @@ signedSmallValueToWord sv
| topBit sv = 0xFF0000 .|. fromIntegral sv
| otherwise = fromIntegral sv
wordFromSmallOpcode :: Opcode -> LargeValue -> MimaWord
wordFromSmallOpcode so lv = shiftL (fromIntegral so) 20 .|. fromIntegral lv
wordFromLargeOpcode :: Opcode -> SmallValue -> MimaWord
wordFromLargeOpcode lo sv = 0xF00000 .|. shiftL (fromIntegral lo) 16 .|. fromIntegral sv
getSmallOpcode :: MimaWord -> Opcode
getSmallOpcode mw = fromIntegral $ shiftR mw 20