Hide more implementation details
This commit is contained in:
parent
d0f3985ff1
commit
a355095ea7
3 changed files with 18 additions and 12 deletions
|
|
@ -7,7 +7,6 @@ module Mima.Instruction
|
||||||
, wordToInstruction
|
, wordToInstruction
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Bits
|
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Word
|
import Data.Word
|
||||||
|
|
@ -65,14 +64,6 @@ instance ToText Instruction where
|
||||||
toText (SmallInstruction oc addr) = toText oc <> " " <> toText addr
|
toText (SmallInstruction oc addr) = toText oc <> " " <> toText addr
|
||||||
toText (LargeInstruction oc) = toText oc
|
toText (LargeInstruction oc) = toText oc
|
||||||
|
|
||||||
upperOpcode :: MimaWord -> Word32
|
|
||||||
upperOpcode mw = shiftR (toWord32 mw) 20 .&. 0xF
|
|
||||||
|
|
||||||
lowerOpcode :: MimaWord -> Word32
|
|
||||||
lowerOpcode mw = shiftR (toWord32 mw) 16 .&. 0xF
|
|
||||||
|
|
||||||
address :: MimaWord -> MimaAddress
|
|
||||||
address = fromWord32 . toWord32 -- no shifting required
|
|
||||||
|
|
||||||
wordToInstruction :: MimaWord -> Either T.Text Instruction
|
wordToInstruction :: MimaWord -> Either T.Text Instruction
|
||||||
wordToInstruction mw = if upperOpcode mw == 0xF
|
wordToInstruction mw = if upperOpcode mw == 0xF
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ step ms = do
|
||||||
(LargeInstruction oc) -> executeLargeOpcode oc ms
|
(LargeInstruction oc) -> executeLargeOpcode oc ms
|
||||||
|
|
||||||
executeSmallOpcode :: SmallOpcode -> MimaAddress -> MimaState -> Either ExecException MimaState
|
executeSmallOpcode :: SmallOpcode -> MimaAddress -> MimaState -> Either ExecException MimaState
|
||||||
executeSmallOpcode LDC addr ms = incrementIp ms{msAcc = fromWord32 $ toWord32 addr}
|
executeSmallOpcode LDC addr ms = incrementIp ms{msAcc = addressToWord addr}
|
||||||
executeSmallOpcode LDV addr ms = incrementIp ms{msAcc = readAt addr (msMemory ms)}
|
executeSmallOpcode LDV addr ms = incrementIp ms{msAcc = readAt addr (msMemory ms)}
|
||||||
executeSmallOpcode STV addr ms = incrementIp ms{msMemory = writeAt addr (msAcc ms) (msMemory ms)}
|
executeSmallOpcode STV addr ms = incrementIp ms{msMemory = writeAt addr (msAcc ms) (msMemory ms)}
|
||||||
executeSmallOpcode ADD addr ms = incrementIp ms{msAcc = addWords (msAcc ms) (readAt addr $ msMemory ms)}
|
executeSmallOpcode ADD addr ms = incrementIp ms{msAcc = addWords (msAcc ms) (readAt addr $ msMemory ms)}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Mima.Word
|
module Mima.Word
|
||||||
( Word32Based(..)
|
( MimaWord
|
||||||
, MimaWord
|
|
||||||
, wordFromBool
|
, wordFromBool
|
||||||
, topBit
|
, topBit
|
||||||
|
, upperOpcode
|
||||||
|
, lowerOpcode
|
||||||
|
, address
|
||||||
, addWords
|
, addWords
|
||||||
, MimaAddress
|
, MimaAddress
|
||||||
|
, addressToWord
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Bits
|
import Data.Bits
|
||||||
|
|
@ -77,6 +80,15 @@ wordFromBool True = complement zeroBits
|
||||||
topBit :: MimaWord -> Bool
|
topBit :: MimaWord -> Bool
|
||||||
topBit mw = testBit (toWord32 mw) (wordSize - 1)
|
topBit mw = testBit (toWord32 mw) (wordSize - 1)
|
||||||
|
|
||||||
|
upperOpcode :: MimaWord -> Word32
|
||||||
|
upperOpcode mw = shiftR (toWord32 mw) 20 .&. 0xF
|
||||||
|
|
||||||
|
lowerOpcode :: MimaWord -> Word32
|
||||||
|
lowerOpcode mw = shiftR (toWord32 mw) 16 .&. 0xF
|
||||||
|
|
||||||
|
address :: MimaWord -> MimaAddress
|
||||||
|
address = fromWord32 . toWord32
|
||||||
|
|
||||||
addWords :: MimaWord -> MimaWord -> MimaWord
|
addWords :: MimaWord -> MimaWord -> MimaWord
|
||||||
addWords mw1 mw2 = fromWord32 $ toWord32 mw1 + toWord32 mw2
|
addWords mw1 mw2 = fromWord32 $ toWord32 mw1 + toWord32 mw2
|
||||||
|
|
||||||
|
|
@ -110,3 +122,6 @@ instance Enum MimaAddress where
|
||||||
else error $ "Enum.toEnum{MimaAddress}: tag (" ++ show i
|
else error $ "Enum.toEnum{MimaAddress}: tag (" ++ show i
|
||||||
++ ") is out of bounds " ++ show (lower, upper)
|
++ ") is out of bounds " ++ show (lower, upper)
|
||||||
fromEnum = fromEnum . toWord32
|
fromEnum = fromEnum . toWord32
|
||||||
|
|
||||||
|
addressToWord :: MimaAddress -> MimaWord
|
||||||
|
addressToWord = fromWord32 . toWord32
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue