diff --git a/Makefile b/Makefile index cc32dfb..ca3eab7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ export TEXINPUTS := $(shell pwd)//:${TEXINPUTS} -doc: +source/avremu.pdf: cd source; latexmk -pdf -shell-escape avremu test: test-simple @@ -12,4 +12,24 @@ test-simple: source/simple-testsuite.tex test-%: source/test-suite/%.c cd source/test-suite; ./test-suite single $(shell basename $<) -.PHONY: test-simple doc +avremu.zip: source/avremu.pdf + rm -rf avremu avremu.zip + mkdir avremu + # TeX Directory + mkdir -p avremu/tex/latex/avremu + cp tex/latex/avremu/*.tex avremu/tex/latex/avremu + cp tex/latex/avremu/*.sty avremu/tex/latex/avremu + # Source directory + mkdir -p avremu/source/latex/avremu + cp -r imgs avremu/source/latex/avremu + mkdir -p avremu/source/latex/avremu/test-suite + cp source/test-suite/*.c avremu/source/latex/avremu/test-suite + cp source/simple-testsuite.tex avremu/source/latex/avremu/ + # Documenation directory + mkdir -p avremu/doc/latex/avremu + cp source/avremu.pdf avremu/doc/latex/avremu + zip -r avremu.zip avremu + rm -rf avremu + + +.PHONY: test-simple source/avremu.pdf avremu.zip diff --git a/README.md b/README.md index 63deaf7..45f6752 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ programming language. TeX can compute anything, that is computable. Computeability is a concept from theoretical computer science. After visiting a theoretical CS course, you will know that there are things that cannot be solved by a machine. Never. Look out -for the halting machine. So, Turing-complete does not say "It's a +for the halting problem. So, Turing-complete does not say "It's a proper programming language", but more "someone can write a proper interpreter for any programming language in it, theoretically". @@ -28,6 +28,8 @@ future, if you start this. But, we can use a normal C compiler to compile the C code to some simple platform. Like AVR[4]. Since I have other things to do than writing an AVR Emulator in TeX, here it is! +The newest source can be found at https://gitlab.brokenpipe.de/stettberger/avr_tex. + ## You are writing an CPU emulator in TeX, the TYPESETTING system? ## Yep. diff --git a/source/avremu.tex b/source/avremu.tex index 1d7f95b..dd12b23 100644 --- a/source/avremu.tex +++ b/source/avremu.tex @@ -4,6 +4,13 @@ \usepackage{hyperref} \usepackage{filecontents} \usepackage{tcolorbox} +\usepackage{ydoc} + +\makeatletter +\def\cmd#1{\cs{\expandafter\cmd@to@cs\string#1}} +\def\cmd@to@cs#1#2{\char\number`#2\relax} +\DeclareRobustCommand\cs[1]{\texttt{\char`\\#1}} +\makeatother \begin{filecontents*}{hello-world.c} #include @@ -22,7 +29,8 @@ main(void) \title{The \texttt{avremu} Package} \author{Christian Dietrich\\ -\url{stettberger@dokucode.de}} +\url{stettberger@dokucode.de}\\ +\url{https://gitlab.brokenpipe.de/stettberger/avr_tex}} \begin{document} @@ -42,6 +50,60 @@ UDR='\avrUDR' in \avrinstrcount\ instructions UDR='\avrUDR' in \avrinstrcount\ instructions \end{tcolorbox} + +\LaTeX\ is known as a typesetting system. But the underlying \TeX\ system is a powerful macro +processor. In fact, TeX is a Turing-complete programming language. \TeX\ can compute anything that +is computable. Computeability is a concept from theoretical computer science. After visiting a +theoretical computer-science course, you will know that there are things that cannot be solved by a +machine. Never. Look out for the halting problem. + +This package does contain an \emph{CPU emulator} for the 8-bit microcontroller platform Atmel AVR, more +precisely it implements the instruction-set architecture of the \texttt{ATmega8}. + +\section{Provided Commands} + +\DescribeMacro{\avrloadihex}{\meta{filename}} +Load an Intel HEX formatted image of the flash into the code memory of the AVR +emulator. Additionally the state of the AVR emulator is set back to zero. + +\DescribeMacro{\avrloadc}[\meta{compiler options}]{\meta{filename}} +Requires \verb|--shell-escape|. Compiles C source code file with \verb|avr-gcc| and the given +compiler options. The default compiler option set is \verb|-mmcu=atmega8 -Os|. The resulting +\texttt{.elf} file is transformed to an Intel HEX file and loaded into the code memory of the +emulator. + +\DescribeMacro{\avrrun} +Run the emulator until a \textbf{break} instruction occurs. + +\DescribeMacro{\avrstep}[\meta{steps}=1] +Run the emulator for N instructions. The default is a single step. The stepping does automatically +end, if a \textbf{break} instruction is executed. + +\DescribeMacro{\avrinstrcount} +Expands to the number of executed instructions. + +\DescribeMacro{\avrsinglestep} +Starts an interactive single-stepping mode, which was mainly used for implementing the emulator. + +\DescribeMacro{\usravremulibrary}{\meta{list of libraryies}} + +\subsection{Access to the Serial Console} +If the program write to the \verb|UDR| IO register, the emulator catched those characters in an +internal buffer. + +\DescribeMacro{\avrUDR} +Expands to the internal UDR buffer. + +\DescribeMacro{\avrUDRclear} +Clears the internal UDR buffer. + +\subsection{Draw Library} +\DescribeMacro{\useavremulibrary}{avr.draw} + +See source/test-suite/mandelbrot.c for more details. + +\section{Implementation Details} +Read the source. \end{document} %%% Local Variables: diff --git a/source/simple-testsuite.tex b/source/simple-testsuite.tex index c41b899..23d851a 100644 --- a/source/simple-testsuite.tex +++ b/source/simple-testsuite.tex @@ -1,5 +1,5 @@ \documentclass{article} -\usepackage{avremu} +\usepackage[debug]{avremu} \begin{document} \makeatletter diff --git a/source/test-suite/HEADER b/source/test-suite/HEADER index 9755856..2df95b0 100644 --- a/source/test-suite/HEADER +++ b/source/test-suite/HEADER @@ -1,7 +1,7 @@ \documentclass{article} \usepackage{graphicx} -\usepackage{avremu} +\usepackage[debug]{avremu} \useavremulibrary{avr.draw} \errorcontextlines=23