module Language.Pck.Cpu.Register (
GRegArray
, Flag(..)
, FlagArray
, initGReg
, getGReg
, getGReg2
, getGRegs
, modifyGReg
, initFlag
, getFlag
, getFlags
, modifyFlag
, judgeFCond
) where
import Data.Array (Array, Ix, listArray, (//), (!), elems)
import Language.Pck.Cpu.Instruction
type GRegArray = Array GReg Int
initGReg :: GRegArray
initGReg = listArray (minBound::GReg, maxBound::GReg)
$ replicate (fromEnum (maxBound::GReg) + 1) 0
getGReg :: GRegArray -> GReg -> Int
getGReg ary reg = ary ! reg
getGReg2 :: GRegArray -> GReg -> GReg -> (Int, Int)
getGReg2 ary ra rb = (ary ! ra, ary ! rb)
getGRegs :: GRegArray -> [Int]
getGRegs = elems
modifyGReg :: GRegArray -> GReg -> Int -> GRegArray
modifyGReg ary reg val = ary // [(reg,val)]
data Flag = FLZ
| FLC
deriving (Show, Eq, Ord, Ix, Enum, Bounded)
type FlagArray = Array Flag Bool
initFlag :: FlagArray
initFlag = listArray (minBound::Flag, maxBound::Flag)
$ replicate (fromEnum (maxBound::Flag) + 1) False
getFlag :: FlagArray -> Flag -> Bool
getFlag ary flag = ary ! flag
getFlags :: FlagArray -> [Bool]
getFlags = elems
modifyFlag :: FlagArray -> Flag -> Bool -> FlagArray
modifyFlag ary flag val = ary // [(flag,val)]
judgeFCond :: FlagArray -> FCond -> Bool
judgeFCond ary FCEQ = (getFlag ary FLZ) == True
judgeFCond ary FCNE = (getFlag ary FLZ) == False
judgeFCond ary FCLT = (getFlag ary FLC) == True
judgeFCond ary FCLE = (getFlag ary FLC) == True || (getFlag ary FLZ) == True
judgeFCond ary FCGT = (getFlag ary FLC) == False && (getFlag ary FLZ) == False
judgeFCond ary FCGE = (getFlag ary FLC) == False