aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2021-02-13 20:06:48 +0300
committerAleksey Veresov <aleksey@veresov.pro>2021-02-13 20:06:48 +0300
commitdcbdb1df0cba8e5ff187900f0a9b03e8fd9fe757 (patch)
tree5359793f17eba5b861809c29b032301efb807566 /src
parent550acd4ef9387df87699b63e7d606b3b88e20254 (diff)
downloadsuem-dcbdb1df0cba8e5ff187900f0a9b03e8fd9fe757.tar
suem-dcbdb1df0cba8e5ff187900f0a9b03e8fd9fe757.tar.xz
suem-dcbdb1df0cba8e5ff187900f0a9b03e8fd9fe757.zip
Initialisation added.
Diffstat (limited to 'src')
-rw-r--r--src/Suem.hs36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/Suem.hs b/src/Suem.hs
index 39632c5..0288d62 100644
--- a/src/Suem.hs
+++ b/src/Suem.hs
@@ -19,12 +19,20 @@ data Machine = Machine {
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
+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 0xff
| a < 0x800000 = B.index (rom m) (a - 0x7e0000)
- | otherwise = 0
+ | otherwise = 0xff
+getWord :: Machine -> Int -> Word16 -- TODO: only even addresses are allowed
+getWord m a = (fromIntegral $ getByte m a) * 256 +
+ (fromIntegral $ getByte m (a + 1))
+
+getLong :: Machine -> Int -> Word32 -- TODO: only even addresses are allowed
+getLong m a = (fromIntegral $ getWord m a) * 256 * 256 +
+ (fromIntegral $ getWord m (a + 2))
data ConfigSocket = ConfigInet String | ConfigUnix String
@@ -41,12 +49,18 @@ data Config = Config Int -- frequence
(Maybe ConfigSocket)
(Maybe ConfigSocket)
-printmachine :: Machine -> IO ()
-printmachine _ = putStrLn "Machine created."
+runMachine :: Machine -> IO ()
+runMachine _ = do
+ putStrLn "Machine created."
+
+makeMachine :: B.ByteString -> Int -> Machine
+makeMachine romData ramSize = Machine regs ramData romData
+ where ramData = (B.replicate ramSize 0)
+ regs = (Registers (getLong m 0x7e0004) 0x2700 (replicate 8 0)
+ (replicate 7 0) 0 (getLong m 0x7e0000))
+ m = Machine (Registers 0 0 [] [] 0 0) B.empty romData
suem :: Config -> IO ()
-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)
+suem (Config _ ramSize romPath _ _ _ _ _ _ _ _) = do
+ romData <- B.readFile romPath
+ runMachine (makeMachine romData ramSize)