-#!/bin/bash -x
+#!/bin/bash
ARG2=$2
../3a_asm/dtas < $ARG2 > ${ARG2%.s}.dthex
}
+runasmbin() {
+ if [ "$ARG2" == "" ]; then
+ echo "runasm: please provide a assembler file"
+ exit 1
+ fi
+ ../3a_asm/dtas -b < $ARG2 > ${ARG2%.s}_bin.dthex
+}
+
runsim() {
if [ "$ARG2" == "" ]; then
echo "runsim: please provide a dthex file"
clean) cleantools;;
build) buildtools;;
asm) runasm;;
+ asmbin) runasmbin;;
sim) runsim;;
asmsim) runasmsim;;
- *) echo "first argument must be clean|build|asm <file.s>|sim <file.dthex>|asmsim <file.s>"
+ *) echo "first argument must be clean|build|"
+ echo "asm <file.s>|asmbin <file.s>|"
+ echo "sim <file.dthex>|asmsim <file.s>"
esac
module DTFormat where
+import Numeric
import Data.Word
+import Data.Char
import Text.Printf
import Text.Parsec
import Text.Parsec.String
datins :: String -> Address -> Value -> Code -> Label -> Comment -> String
datins = printf "%s;%08x;%08x;%s;%s;%s\n"
+tobin :: Value -> String
+tobin v = reverse $ take 32 $ reverse $ (['0' | _<-[0..32]]) ++ (showIntAtBase 2 (chr. ((+)0x30)) v "")
+
+showsDTFBase :: DTF -> Int -> ShowS
+showsDTFBase (DTF_Data a v c l s) 2 = (++) (datinsBin "0" a (tobin v) c l s)
+showsDTFBase (DTF_Instr a v c l s) 2 = (++) (datinsBin "1" a (tobin v) c l s)
+showsDTFBase d _ = showsDTF d
+
+datinsBin :: String -> Address -> String -> Code -> Label -> Comment -> String
+datinsBin = printf "%s;%08x;%s;%s;%s;%s\n"
-- datastructure for managing labels and defines
type Dict = (Address,[DictElem])
content <- getContents
let src = (filter (((/=) "") . snd) $ (zip [1..] (lines content)))
let (dict,formatedsrc) = convertDTF src NoState 0x00 0x00 [("start_",0x00)]
- if (not $ null args) && (head args == "-d")
+ if (not $ null args) && ("-d" `elem` args)
then do
printf "\nlabels:\n"
sequence_ [printf "%20s @ 0x%08x\n" l a | (l,a) <- (reverse dict)]
printf "\nafter parsing the instructions:\n"
else do
printf ""
+ let base = if "-b" `elem` args then 2 else 16
let parsed = parseInstr dict formatedsrc
- sequence_ [printf "%s" (show x) | x <- parsed]
+ sequence_ [printf "%s" (showsDTFBase x base "") | x <- parsed]
parseInstr :: [DictElem] -> [DTF] -> [DTF]