Run MiMa for a specified amount of steps
Also, print IP and Acc at the time of the dump
This commit is contained in:
parent
082a205a7e
commit
1c895add5a
2 changed files with 33 additions and 9 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module MimaRun where
|
module MimaRun where
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
|
@ -7,6 +9,7 @@ import Options.Applicative
|
||||||
import Mima.Load
|
import Mima.Load
|
||||||
import Mima.State
|
import Mima.State
|
||||||
import Mima.Util
|
import Mima.Util
|
||||||
|
import Mima.Word
|
||||||
|
|
||||||
data Settings = Settings
|
data Settings = Settings
|
||||||
{ infile :: String
|
{ infile :: String
|
||||||
|
|
@ -53,12 +56,17 @@ runMima settings s =
|
||||||
case steps settings of
|
case steps settings of
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
putStrLn "Running until HALT or execution exception..."
|
putStrLn "Running until HALT or execution exception..."
|
||||||
let (s', e) = run s
|
let (s', e, x) = run s
|
||||||
|
putStrLn $ "Ran for " ++ show x ++ " steps"
|
||||||
T.putStrLn $ toText e
|
T.putStrLn $ toText e
|
||||||
pure s'
|
pure s'
|
||||||
Just _ -> do
|
Just n -> do
|
||||||
putStrLn "This option is currently not supported"
|
let (s', me, x) = runN n s
|
||||||
undefined
|
putStrLn $ "Ran for " ++ show x ++ " steps"
|
||||||
|
case me of
|
||||||
|
Nothing -> putStrLn "Encountered no exception"
|
||||||
|
Just e -> T.putStrLn $ toText e
|
||||||
|
pure s'
|
||||||
|
|
||||||
-- TODO exception handling
|
-- TODO exception handling
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
|
|
@ -71,6 +79,9 @@ main = do
|
||||||
let s = initialState mem
|
let s = initialState mem
|
||||||
s' <- if norun settings then pure s else runMima settings s
|
s' <- if norun settings then pure s else runMima settings s
|
||||||
|
|
||||||
|
T.putStrLn $ "IP: " <> addrToHexDec (msIp s') <> " "
|
||||||
|
<> "Acc: " <> wordToHexDec (msAcc s')
|
||||||
|
|
||||||
unless (quiet settings) $ do
|
unless (quiet settings) $ do
|
||||||
putStrLn "Dump of memory:"
|
putStrLn "Dump of memory:"
|
||||||
T.putStrLn $ memoryToText (sparse settings) (msMemory s')
|
T.putStrLn $ memoryToText (sparse settings) (msMemory s')
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ module Mima.State
|
||||||
, ExecException(..)
|
, ExecException(..)
|
||||||
, step
|
, step
|
||||||
, run
|
, run
|
||||||
|
, runN
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Bits
|
import Data.Bits
|
||||||
|
|
@ -146,8 +147,20 @@ executeLargeOpcode HALT ms =
|
||||||
executeLargeOpcode NOT ms = incrementIp ms{msAcc = complement (msAcc ms)}
|
executeLargeOpcode NOT ms = incrementIp ms{msAcc = complement (msAcc ms)}
|
||||||
executeLargeOpcode RAR ms = incrementIp ms{msAcc = rotateR (msAcc ms) 1}
|
executeLargeOpcode RAR ms = incrementIp ms{msAcc = rotateR (msAcc ms) 1}
|
||||||
|
|
||||||
run :: MimaState -> (MimaState, ExecException)
|
run :: MimaState -> (MimaState, ExecException, Integer)
|
||||||
run ms =
|
run ms = helper 0 ms
|
||||||
case step ms of
|
where
|
||||||
Left e -> (ms, e)
|
helper completed s =
|
||||||
Right ms' -> run ms'
|
case step s of
|
||||||
|
Left e -> (s, e, completed)
|
||||||
|
Right s' -> helper (completed + 1) s'
|
||||||
|
|
||||||
|
runN :: Integer -> MimaState -> (MimaState, Maybe ExecException, Integer)
|
||||||
|
runN n ms = helper 0 ms
|
||||||
|
where
|
||||||
|
helper completed s =
|
||||||
|
if completed >= n
|
||||||
|
then (s, Nothing, completed)
|
||||||
|
else case step s of
|
||||||
|
Left e -> (s, Just e, completed)
|
||||||
|
Right s' -> helper (completed + 1) s'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue