diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-02-15 19:31:12 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-02-15 19:31:12 +0300 |
commit | 97bbb430e4f1460858b2f1baaffc2ef804c63086 (patch) | |
tree | 4cbf88a77e471c6c21ea7935d6a54f71c72728e3 /src/Suem.hs | |
parent | 0cdd25d921202030745069dbccd16ef856e16750 (diff) | |
download | suem-97bbb430e4f1460858b2f1baaffc2ef804c63086.tar suem-97bbb430e4f1460858b2f1baaffc2ef804c63086.tar.xz suem-97bbb430e4f1460858b2f1baaffc2ef804c63086.zip |
New style of command dispatcher! =)
Diffstat (limited to 'src/Suem.hs')
-rw-r--r-- | src/Suem.hs | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/src/Suem.hs b/src/Suem.hs index 3ca635b..fe73a1e 100644 --- a/src/Suem.hs +++ b/src/Suem.hs @@ -3,9 +3,9 @@ module Suem (Config(..), ConfigSocket(..), suem) where import qualified Data.Vector.Unboxed as V import qualified Data.ByteString as B import Data.Word -import Data.Bits import Machine import Commands +import Utils data ConfigSocket = ConfigInet String | ConfigUnix String @@ -22,35 +22,20 @@ data Config = Config Int -- frequence (Maybe ConfigSocket) (Maybe ConfigSocket) -boolToInt :: Bool -> Int -boolToInt True = 1 -boolToInt False = 0 - -toBits :: Word16 -> [Int] -toBits x = map (boolToInt . testBit x) [0..(finiteBitSize x-1)] - -fromBits :: [Int] -> Int -fromBits = foldl (\a b -> 2 * a + b) 0 . reverse - doCommand :: [Int] -> Machine -> Machine ---doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,0,0,0] = doReset +doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,0,0,0] = doReset doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,0,0,1] = doNothing ---doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,0,1,0] = doStop ---doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,0,1,1] = doRTE ---doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,1,0,1] = doRTS ---doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,1,1,0] = doTrapV ---doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,1,1,1] = doRTR ---doCommand [0,1,0,0,1,0,1,0, 1,1,1,1,1,1,0,0] = doIllegal ---doCommand [0,1,0,0,1,0,1,0, 1,1,a,b,c,d,e,f] = --- doTAS (fromBits [a,b,c]) (fromBits [d,e,f]) ---doCommand [0,1,0,0,1,0,1,0, a,b,c,d,e,f,g,h] = --- doTST (fromBits [a,b]) (fromBits [c,d,e]) (fromBits [f,g,h]) ---doCommand [0,1,0,0,1,0,1,0, 0,1,0,0,a,b,c,d] = --- doTrap (fromBits [a,b,c,d]) ---doCommand [0,1,0,0,1,0,1,0, 0,1,0,1,0,a,b,c] = --- doLink (fromBits [a,b,c]) -doCommand [0,1,0,0,1,0,1,0, 0,1,0,1,1,a,b,c] = - doUnlink (fromBits [a,b,c]) +doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,0,1,0] = doStop +doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,0,1,1] = doRTE +doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,1,0,1] = doRTS +doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,1,1,0] = doTrapV +doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,0,1,1,1] = doRTR +doCommand [0,1,0,0,1,0,1,0, 1,1,1,1,1,1,0,0] = doIllegal +doCommand [0,1,0,0,1,0,1,0, 1,1,a,b,c,d,e,f] = doTAS [a,b,c] [d,e,f] +doCommand [0,1,0,0,1,0,1,0, 0,1,0,0,a,b,c,d] = doTrap [a,b,c,d] +doCommand [0,1,0,0,1,0,1,0, 0,1,0,1,0,a,b,c] = doLink [a,b,c] +doCommand [0,1,0,0,1,0,1,0, 0,1,0,1,1,a,b,c] = doUnlink [a,b,c] +doCommand [0,1,0,0,1,0,1,0, a,b,c,d,e,f,g,h] = doTST [a,b] [c,d,e] [f,g,h] doCommand _ = error "Bad command." runMachine :: Machine -> IO () |