diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-02-13 19:24:35 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-02-13 19:24:35 +0300 |
commit | 550acd4ef9387df87699b63e7d606b3b88e20254 (patch) | |
tree | ec4b38e4968e263fb1f1e6713c45ade78f22d206 | |
parent | f88cbf20be4007ed7174c292dc1b57cc9495aaa2 (diff) | |
download | suem-550acd4ef9387df87699b63e7d606b3b88e20254.tar suem-550acd4ef9387df87699b63e7d606b3b88e20254.tar.xz suem-550acd4ef9387df87699b63e7d606b3b88e20254.zip |
Machine model created.
-rw-r--r-- | Main.hs | 2 | ||||
-rw-r--r-- | package.yaml | 3 | ||||
-rw-r--r-- | src/Suem.hs | 61 |
3 files changed, 49 insertions, 17 deletions
@@ -32,7 +32,7 @@ config = Config <> short 'm' <> metavar "RAM_SIZE" <> showDefault - <> value (8 * 1024 * 1024) + <> value (8 * 1024 * 1024 - 128 * 1024) <> help "Available RAM in bytes" ) <*> strOption ( long "rom" diff --git a/package.yaml b/package.yaml index 546eed6..23821e0 100644 --- a/package.yaml +++ b/package.yaml @@ -10,6 +10,8 @@ ghc-options: -O2 -Wall -static -optl-static -optl-pthread dependencies: - base >= 4.7 && < 5 +- bytestring +- optparse-applicative library: source-dirs: src @@ -19,4 +21,3 @@ executable: ghc-options: -threaded -rtsopts -with-rtsopts=-N dependencies: - suem - - optparse-applicative diff --git a/src/Suem.hs b/src/Suem.hs index a6df56f..39632c5 100644 --- a/src/Suem.hs +++ b/src/Suem.hs @@ -1,21 +1,52 @@ module Suem (Config(..), ConfigSocket(..), suem) where -data ConfigSocket = ConfigInet String | ConfigUnix String +import qualified Data.ByteString as B +import Data.Word + + +data Registers = Registers { + pc :: Word32, + sr :: Word16, + drs :: [Word32], -- d0 to d7 + ars :: [Word32], -- a0 to a6 + usp :: Word32, -- this is a7 in user mode + ssp :: Word32 -- this is a7 in supermode +} -data Config = Config { - freq :: Int, - ram :: Int, - rom :: String, - s0 :: Maybe ConfigSocket, - s1 :: Maybe ConfigSocket, - s2 :: Maybe ConfigSocket, - s3 :: Maybe ConfigSocket, - s4 :: Maybe ConfigSocket, - s5 :: Maybe ConfigSocket, - s6 :: Maybe ConfigSocket, - s7 :: Maybe ConfigSocket +data Machine = Machine { + regs :: Registers, + ram :: B.ByteString, + rom :: B.ByteString } +getbyte :: Machine -> Int -> Word8 +getbyte m a | a < 0x8 = B.index (rom m) a + | a < 0x7e0000 = if B.length (ram m) >= a then B.index (ram m) a else 0 + | a < 0x800000 = B.index (rom m) (a - 0x7e0000) + | otherwise = 0 + + + +data ConfigSocket = ConfigInet String | ConfigUnix String + +data Config = Config Int -- frequence + Int -- size of RAM + FilePath -- path to ROM + (Maybe ConfigSocket) + (Maybe ConfigSocket) + (Maybe ConfigSocket) + (Maybe ConfigSocket) + (Maybe ConfigSocket) + (Maybe ConfigSocket) + (Maybe ConfigSocket) + (Maybe ConfigSocket) + +printmachine :: Machine -> IO () +printmachine _ = putStrLn "Machine created." + suem :: Config -> IO () -suem (Config _ _ r _ _ _ _ _ _ _ _) = putStrLn $ "Loaded " ++ r ++ " into ROM." -suem _ = return () +suem (Config _ ramsize rompath _ _ _ _ _ _ _ _) = do + romdata <- B.readFile rompath + printmachine (Machine regs ramdata romdata) + where ramdata = (B.replicate ramsize 0) + regs = (Registers 0 0 (replicate 8 0) (replicate 7 0) 0 0) |