Rename "short" to "small" and "long" to "large"
This commit is contained in:
parent
6e0678d9b4
commit
2d76ff4f93
1 changed files with 54 additions and 54 deletions
108
src/Mima/Word.hs
108
src/Mima/Word.hs
|
|
@ -16,29 +16,29 @@ module Mima.Word
|
||||||
, getSmallOpcode
|
, getSmallOpcode
|
||||||
, getLargeOpcode
|
, getLargeOpcode
|
||||||
, getAddress
|
, getAddress
|
||||||
, getLongValue
|
, getLargeValue
|
||||||
, getShortValue
|
, getSmallValue
|
||||||
-- ** Operations
|
-- ** Operations
|
||||||
, addWords
|
, addWords
|
||||||
-- * 20-bit value
|
-- * 20-bit value
|
||||||
, LongValue
|
, LargeValue
|
||||||
, MimaAddress
|
, MimaAddress
|
||||||
-- ** Formatting
|
-- ** Formatting
|
||||||
, longValueToHex
|
, largeValueToHex
|
||||||
, longValueToDec
|
, largeValueToDec
|
||||||
, longValueToHexDec
|
, largeValueToHexDec
|
||||||
-- ** Converting
|
-- ** Converting
|
||||||
, bytesToLongValue
|
, bytesToLargeValue
|
||||||
, longValueToBytes
|
, largeValueToBytes
|
||||||
, longValueToWord
|
, largeValueToWord
|
||||||
-- * 16-bit value
|
-- * 16-bit value
|
||||||
, ShortValue
|
, SmallValue
|
||||||
-- ** Formatting
|
-- ** Formatting
|
||||||
, shortValueToHex
|
, smallValueToHex
|
||||||
, shortValueToDec
|
, smallValueToDec
|
||||||
, shortValueToHexDec
|
, smallValueToHexDec
|
||||||
-- ** Converting
|
-- ** Converting
|
||||||
, signedShortValueToWord
|
, signedSmallValueToWord
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Bits
|
import Data.Bits
|
||||||
|
|
@ -174,68 +174,68 @@ getLargeOpcode :: MimaWord -> Word32
|
||||||
getLargeOpcode mw = shiftR (toWord32 mw) 16 .&. 0xF
|
getLargeOpcode mw = shiftR (toWord32 mw) 16 .&. 0xF
|
||||||
|
|
||||||
getAddress :: MimaWord -> MimaAddress
|
getAddress :: MimaWord -> MimaAddress
|
||||||
getAddress = getLongValue
|
getAddress = getLargeValue
|
||||||
|
|
||||||
getLongValue :: MimaWord -> LongValue
|
getLargeValue :: MimaWord -> LargeValue
|
||||||
getLongValue = fromWord32 . toWord32
|
getLargeValue = fromWord32 . toWord32
|
||||||
|
|
||||||
getShortValue :: MimaWord -> ShortValue
|
getSmallValue :: MimaWord -> SmallValue
|
||||||
getShortValue = fromWord32 . toWord32
|
getSmallValue = fromWord32 . toWord32
|
||||||
|
|
||||||
addWords :: MimaWord -> MimaWord -> MimaWord
|
addWords :: MimaWord -> MimaWord -> MimaWord
|
||||||
addWords w1 w2 = fromWord32 $ toWord32 w1 + toWord32 w2
|
addWords w1 w2 = fromWord32 $ toWord32 w1 + toWord32 w2
|
||||||
|
|
||||||
type MimaAddress = LongValue
|
type MimaAddress = LargeValue
|
||||||
type LongValue = WB LongValue_
|
type LargeValue = WB LargeValue_
|
||||||
newtype LongValue_ = LongValue_ Word32
|
newtype LargeValue_ = LargeValue_ Word32
|
||||||
|
|
||||||
instance Word32Based LongValue_ where
|
instance Word32Based LargeValue_ where
|
||||||
usedBits _ = 20
|
usedBits _ = 20
|
||||||
fromWord32 w = LongValue_ $ w .&. 0xFFFFF
|
fromWord32 w = LargeValue_ $ w .&. 0xFFFFF
|
||||||
toWord32 (LongValue_ w) = w
|
toWord32 (LargeValue_ w) = w
|
||||||
|
|
||||||
instance Show LongValue_ where
|
instance Show LargeValue_ where
|
||||||
show lv = T.unpack $ "LongValue_ 0x" <> toHex 5 (toWord32 lv)
|
show lv = T.unpack $ "LargeValue_ 0x" <> toHex 5 (toWord32 lv)
|
||||||
|
|
||||||
longValueToHex :: MimaWord -> T.Text
|
largeValueToHex :: MimaWord -> T.Text
|
||||||
longValueToHex = toHex 5 . toWord32
|
largeValueToHex = toHex 5 . toWord32
|
||||||
|
|
||||||
longValueToDec :: MimaWord -> T.Text
|
largeValueToDec :: MimaWord -> T.Text
|
||||||
longValueToDec = toDec 7 . toWord32
|
largeValueToDec = toDec 7 . toWord32
|
||||||
|
|
||||||
longValueToHexDec :: MimaWord -> T.Text
|
largeValueToHexDec :: MimaWord -> T.Text
|
||||||
longValueToHexDec mw = longValueToHex mw <> " (" <> longValueToDec mw <> ")"
|
largeValueToHexDec mw = largeValueToHex mw <> " (" <> largeValueToDec mw <> ")"
|
||||||
|
|
||||||
bytesToLongValue :: Word8 -> Word8 -> Word8 -> LongValue
|
bytesToLargeValue :: Word8 -> Word8 -> Word8 -> LargeValue
|
||||||
bytesToLongValue w1 w2 w3 = getAddress $ bytesToWord w1 w2 w3
|
bytesToLargeValue w1 w2 w3 = getAddress $ bytesToWord w1 w2 w3
|
||||||
|
|
||||||
longValueToBytes :: LongValue -> (Word8, Word8, Word8)
|
largeValueToBytes :: LargeValue -> (Word8, Word8, Word8)
|
||||||
longValueToBytes = wordToBytes . longValueToWord
|
largeValueToBytes = wordToBytes . largeValueToWord
|
||||||
|
|
||||||
longValueToWord :: LongValue -> MimaWord
|
largeValueToWord :: LargeValue -> MimaWord
|
||||||
longValueToWord = fromWord32 . toWord32
|
largeValueToWord = fromWord32 . toWord32
|
||||||
|
|
||||||
type ShortValue = WB ShortValue_
|
type SmallValue = WB SmallValue_
|
||||||
newtype ShortValue_ = ShortValue_ Word32
|
newtype SmallValue_ = SmallValue_ Word32
|
||||||
|
|
||||||
instance Word32Based ShortValue_ where
|
instance Word32Based SmallValue_ where
|
||||||
usedBits _ = 16
|
usedBits _ = 16
|
||||||
fromWord32 w = ShortValue_ $ w .&. 0xFFFF
|
fromWord32 w = SmallValue_ $ w .&. 0xFFFF
|
||||||
toWord32 (ShortValue_ w) = w
|
toWord32 (SmallValue_ w) = w
|
||||||
|
|
||||||
instance Show ShortValue_ where
|
instance Show SmallValue_ where
|
||||||
show lv = T.unpack $ "ShortValue_ 0x" <> toHex 4 (toWord32 lv)
|
show lv = T.unpack $ "SmallValue_ 0x" <> toHex 4 (toWord32 lv)
|
||||||
|
|
||||||
shortValueToHex :: MimaWord -> T.Text
|
smallValueToHex :: MimaWord -> T.Text
|
||||||
shortValueToHex = toHex 4 . toWord32
|
smallValueToHex = toHex 4 . toWord32
|
||||||
|
|
||||||
shortValueToDec :: MimaWord -> T.Text
|
smallValueToDec :: MimaWord -> T.Text
|
||||||
shortValueToDec = toDec 5 . toWord32
|
smallValueToDec = toDec 5 . toWord32
|
||||||
|
|
||||||
shortValueToHexDec :: MimaWord -> T.Text
|
smallValueToHexDec :: MimaWord -> T.Text
|
||||||
shortValueToHexDec mw = shortValueToHex mw <> " (" <> shortValueToDec mw <> ")"
|
smallValueToHexDec mw = smallValueToHex mw <> " (" <> smallValueToDec mw <> ")"
|
||||||
|
|
||||||
signedShortValueToWord :: ShortValue -> MimaWord
|
signedSmallValueToWord :: SmallValue -> MimaWord
|
||||||
signedShortValueToWord sv
|
signedSmallValueToWord sv
|
||||||
| topBit sv = fromWord32 $ 0xFFFF0000 .|. toWord32 sv
|
| topBit sv = fromWord32 $ 0xFFFF0000 .|. toWord32 sv
|
||||||
| otherwise = fromWord32 $ toWord32 sv
|
| otherwise = fromWord32 $ toWord32 sv
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue