Improve memory dump output

This commit is contained in:
Joscha 2019-11-06 18:23:47 +00:00
parent 1c895add5a
commit f07b825313
2 changed files with 17 additions and 9 deletions

View file

@ -79,12 +79,12 @@ 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
unless (quiet settings) $ do
putStrLn "\nDump of memory:"
T.putStrLn $ "IP: " <> addrToHexDec (msIp s') <> " " T.putStrLn $ "IP: " <> addrToHexDec (msIp s') <> " "
<> "Acc: " <> wordToHexDec (msAcc s') <> "Acc: " <> wordToHexDec (msAcc s')
unless (quiet settings) $ do
putStrLn "Dump of memory:"
T.putStrLn $ memoryToText (sparse settings) (msMemory s') T.putStrLn $ memoryToText (sparse settings) (msMemory s')
putStrLn ""
forM_ (memoryDump settings) $ \path -> do forM_ (memoryDump settings) $ \path -> do
putStrLn $ "Saving memdump at " ++ path putStrLn $ "Saving memdump at " ++ path

View file

@ -42,11 +42,18 @@ wordsToMemory = MimaMemory
memoryToWords :: MimaMemory -> [MimaWord] memoryToWords :: MimaMemory -> [MimaWord]
memoryToWords mem = map (\addr -> readAt addr mem) $ addressRange mem memoryToWords mem = map (\addr -> readAt addr mem) $ addressRange mem
addressWordToText :: MimaAddress -> MimaWord -> T.Text addrWordLegend :: T.Text
addressWordToText addr word = addrWordLegend = "UO: Upper Opcode (bits 24-21) LO: Lower Opcode (bits 20-17)\n"
<> "Addr (decimal) - Word ( decimal|UO,LO, Addr) - Instruction\n"
addrWordToText :: MimaAddress -> MimaWord -> T.Text
addrWordToText addr word =
let separator = " - " let separator = " - "
addrText = addrToHex addr <> " (" <> addrToDec addr <> ")" addrText = addrToHex addr <> " (" <> addrToDec addr <> ")"
wordText = wordToHex word <> " (" <> wordToDec word <> ")" wordSplit = toDec 2 (upperOpcode word) <> ","
<> toDec 2 (lowerOpcode word) <> ","
<> addrToDec (address word)
wordText = wordToHex word <> " (" <> wordToDec word <> "|" <> wordSplit <> ")"
instrText = case wordToInstruction word of instrText = case wordToInstruction word of
Left _ -> "" Left _ -> ""
Right i -> separator <> toText i Right i -> separator <> toText i
@ -54,8 +61,9 @@ addressWordToText addr word =
memoryToText :: Bool -> MimaMemory -> T.Text memoryToText :: Bool -> MimaMemory -> T.Text
memoryToText sparse mem@(MimaMemory m) memoryToText sparse mem@(MimaMemory m)
= T.intercalate "\n" = (addrWordLegend <>)
$ map (\addr -> addressWordToText addr (readAt addr mem)) $ T.intercalate "\n"
$ map (\addr -> addrWordToText addr (readAt addr mem))
$ addresses sparse $ addresses sparse
where where
addresses False = addressRange mem addresses False = addressRange mem