Commit 8d320f37 authored by Christian Dietrich's avatar Christian Dietrich

Use TDS Layout

parent 84f4c7f5
test:
pdflatex -halt-on-error avr.tex
cd tests; ./test-suite
export TEXINPUTS := $(shell pwd)//:${TEXINPUTS}
test: test-simple
cd source/test-suite; ./test-suite
test-simple: source/simple-testsuite.tex
pdflatex -halt-on-error $<
test-%: source/test-suite/%.c
cd source/test-suite; ./test-suite single $(shell basename $<)
.PHONY: test-simple
%% This is the test suite for my avr Implementation
\def\avr@test@setup#1{%
\typeout{---- Test: #1 ----}%
\typeout{-> Initialize the AVR}%
\avr@init%
}
\def\avr@test@SREG#1{% Tests SREG for value
\avr@sreg@get{\@@SREG}%
\expandafter\ifstrequal\expandafter{\@@SREG}{#1}{%Success
}{%
\avr@error{SREG unequal: #1 != \@@SREG}%
}%
}
\def\avr@test@REG#1#2{% Tests SREG for value
\avr@reg@get{\csuse{avr@#1}}{\@@REG}%
\expandafter\ifstrequal\expandafter{\@@REG}{#2}{%Success
}{%
\avr@error{REG unequal: #2 != \@@REG}%
}%
}
\def\avr@test@MEM#1#2{% Tests MEM for value
\avr@mem@get{#1}{\@@MEM}%
\expandafter\ifstrequal\expandafter{\@@MEM}{#2}{%Success
}{%
\avr@error{MEM unequal: #2 != \@@MEM}%
}%
}
\def\avr@test@UDR#1{% Tests UDR output
\ifdefstring{\avr@UDR}{#1}{%Success
}{%
\avr@error{UDR unequal: #1 != \avr@UDR}%
}%
\def\avr@UDR{}%
}
\documentclass{article}
\usepackage{avremu}
\begin{document}
\makeatletter
% Hook Macro for the tests
\def\avr@test{}
......@@ -532,9 +498,14 @@
}
\preto\avr@test{\avr@test@ADIW}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Run the test-suite
\avr@test
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "avr.tex"
%%% TeX-master: t
%%% End:
\documentclass{article}
\usepackage{avremu}
\errorcontextlines=23
\begin{document}
\makeatletter
......@@ -9,34 +9,23 @@
#include <avr/io.h>
#define SET_DRAW_COLOR 1
#define SET_FILL_COLOR 2
#define SET_ALL_COLOR 3
#define CMD_RECTANGLE 4
#define CMD_SHORT_RECTANGLE 5
#define CMD_COLOR 1
#define CMD_DOT 2
static
void setcolor(uint8_t color, uint8_t r, uint8_t g, uint8_t b) {
void setcolor(uint8_t r, uint8_t g, uint8_t b) {
TWDR = r;
TWDR = g;
TWDR = b;
TWAR = color;
}
static
void rectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h) {
TWDR = x, TWDR = y;
TWDR = w, TWDR = h;
TWAR = CMD_RECTANGLE;
TWAR = CMD_COLOR;
}
static
void dot(uint8_t x, uint8_t y) {
TWDR = x, TWDR = y;
TWAR = CMD_SHORT_RECTANGLE;
TWAR = CMD_DOT;
}
......@@ -67,35 +56,39 @@ char color_B[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
int main() {
float x,xx,y,cx,cy;
uint16_t iteration;
uint8_t iteration;
uint8_t hx,hy;
const uint8_t itermax = 100; /* how many iterations to do */
float magnify=2.0; /* no magnification */
uint8_t hxres = 20; /* horizonal resolution */
uint8_t hyres = 20; /* vertical resolution */
uint8_t i;
#define itermax 100 /* how many iterations to do */
#define magnify 4.0 /* no magnification */
#define hxres 128 /* horizonal resolution */
#define hyres 128 /* vertical resolution */
#define ydelta 0
#define xdelta -0.75
uint8_t i;
for (hy=1;hy<=hyres;hy++) {
for (hx=1;hx<=hxres;hx++) {
cx = (((float)hx)/((float)hxres)-0.5)/magnify*3.0-0.7;
cy = (((float)hy)/((float)hyres)-0.5)/magnify*3.0;
cx += xdelta;
cy += ydelta;
x = 0.0; y = 0.0;
for (iteration=1;iteration<itermax;iteration++) {
for (iteration=1; iteration < itermax; iteration++) {
xx = x*x-y*y+cx;
y = 2.0*x*y+cy;
x = xx;
if (x*x+y*y>100.0) {
i = iteration;
iteration = 0xff;
}
if (x*x+y*y>128.0){
i = iteration;
iteration = itermax + 1;
}
}
if (iteration<0xff) {
setcolor(SET_ALL_COLOR, 0,0,0);
// Print a dot
if (iteration<itermax+1) {
setcolor(0,0,0);
} else {
setcolor(SET_ALL_COLOR,
color_R[i],
color_G[i],
color_B[i]);
setcolor(color_R[i],
color_G[i],
color_B[i]);
}
dot(hx-1, hy-1);
}
......@@ -105,18 +98,36 @@ int main() {
}
/*
check-name: Complex Memory Operations
check-name: Mandelbrot Set
compiler-opts: -O3
check-long: 1
check-start:
\def\avr@debug#1{}
\avr@instr@run
\avrdrawcanvas
\newcommand{\mydot}[3]{%
\definecolor{avrfill}{RGB}{#3}%
\node[minimum size = 1mm,%
anchor=north west,
inner sep=0,
draw=avrfill,fill=avrfill]
at (#1 mm,#2 mm) {};%
}
\avr@instr@run
\newwrite\commentfile
\openout\commentfile=\jobname.tikz.tex
\write\commentfile{\avr@draw@canvas}
\closeout\commentfile
% Dump to .dat file
\newwrite\coords
\openout\coords=\jobname.coords.dat
\newcommand{\mydump}[3]{%
\edef\@tempa{#1,#2,#3}%
\expandafter\write\expandafter\coords\expandafter{\@tempa}%
}
\avrdrawiter{\mydump}
\closeout\coords
\begin{tikzpicture}[every node/.style={draw}]
\avrdrawiter{\mydot}
\end{tikzpicture}
check-end:
*/
......@@ -16,6 +16,7 @@ ok_tests=0
ko_tests=0
known_ko_tests=0
# defaults to not verbose
[ -z "$V" ] && V=0
......@@ -105,7 +106,7 @@ do_test()
# grab the actual output & exit value
pdflatex -halt-on-error -shell-escape "$file".tex 1> $file.output 2> $file.error
stdbuf -oL pdflatex -halt-on-error -shell-escape "$file".tex 1> $file.output 2> $file.error
actual_exit_value=$?
rm -f *.log *.aux
......
\documentclass{article}
\usepackage{etoolbox}
\usepackage{tabularx}
\makeatletter
\errorcontextlines=23
\input{../avr.numbers}
\input{../avr.binary}
\input{../avr.bitops}
\input{../avr.memory}
\input{../avr.instr}
\input{../avr.io}
\input{../avr.testsuite}
\input{../avr.draw}
\begin{document}
\makeatletter
This diff is collapsed.
......@@ -4,6 +4,18 @@
\usepackage{tikz}
\newcount\avr@draw@x
\newcount\avr@draw@y
\newcount\avr@draw@maxx
\newcount\avr@draw@maxy
\def\avr@draw@init{%
\avr@draw@maxx = 0%
\avr@draw@maxy = 0%
}
% TWAR
\newcount\avr@draw@argc
\csdef{avr@io@000010@set}#1{%
......@@ -32,85 +44,51 @@
}
\def\avr@draw@canvas{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Draw Commands
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\csdef{avr@draw@command@0}{} % NOP
% Set Draw Color
\definecolor{avrdraw}{rgb}{255,255,255}
% Set Color
\def\avr@draw@color{0,0,0}
\csdef{avr@draw@command@1}{%
\ifnum \avr@draw@argc < 3%
\avr@debug{DRAW: Set Draw COLOR, Not enough arguments}%
\fi%
\edef\@@append{%
\detokenize{\definecolor{avrdraw}}%
{rgb}{\avr@draw@stack{0},\avr@draw@stack{1},\avr@draw@stack{2}}%
}
\eappto\avr@draw@canvas{\@@append}
\xdef\avr@draw@color{\avr@draw@stack{0},\avr@draw@stack{1},\avr@draw@stack{2}}%
}
% Set Fill Color
\definecolor{avrfill}{rgb}{255,255,255}
% Small Rectangle
\csdef{avr@draw@command@2}{%
\ifnum \avr@draw@argc < 3%
\avr@debug{DRAW: Set Fill COLOR, Not enough arguments}%
\ifnum \avr@draw@argc < 2%
\avr@debug{DRAW: Dot, Not enough arguments (2 required)}%
\fi%
\edef\@@append{%
\detokenize{\definecolor{avrfill}}%
{rgb}{\avr@draw@stack{0},\avr@draw@stack{1},\avr@draw@stack{2}}%
}
\eappto\avr@draw@canvas{\@@append}
}
\csdef{avr@draw@command@3}{%
\avr@draw@command{1}% Set Draw Color
\avr@draw@command{2}% Set Fill Color
}
% Rectangle
\csdef{avr@draw@command@4}{%
\ifnum \avr@draw@argc < 4%
\avr@debug{DRAW: Rectangle, Not enough arguments (4 required)}
\edef\@@X{\avr@draw@stack{0}}%
\edef\@@Y{\avr@draw@stack{1}}%
\ifnum \@@X > \avr@draw@maxx%
\avr@draw@maxx=\@@X%
\fi%
\edef\@@append{%
\detokenize{\node}%
[minimum height = \avr@draw@stack{2}mm,%
minimum width = \avr@draw@stack{3}mm,%
inner sep=0,%
anchor=north west,
draw=avrdraw,fill=avrfill]
at (\avr@draw@stack{0}mm,\avr@draw@stack{1}mm) {};%
}%
\eappto\avr@draw@canvas{\@@append}%
}
% Small Rectangle
\csdef{avr@draw@command@5}{%
\ifnum \avr@draw@argc < 2%
\avr@debug{DRAW: Short Rectangle, Not enough arguments (2 required)}
\ifnum \@@Y > \avr@draw@maxy%
\avr@draw@maxy=\@@Y%
\fi%
\edef\@@append{%
\detokenize{\node}%
[minimum size = 1mm,%
inner sep=0,%
anchor=north west,
draw=avrdraw,fill=avrfill]
at (\avr@draw@stack{0}mm,\avr@draw@stack{1}mm) {};%
}%
\eappto\avr@draw@canvas{\@@append}%
\csxdef{avr@draw@\@@X @\@@Y}{\avr@draw@color}%
}
\newcommand{\avrdrawcanvas}{%
\begin{tikzpicture}
\scantokens\expandafter{\avr@draw@canvas}%
\end{tikzpicture}
\newcommand{\avrdrawiter}[1]{%
\avr@draw@x=0%
\loop%
\unless\ifnum \avr@draw@x > \avr@draw@maxx
\avr@draw@y=0%
{\loop%
\unless\ifnum \avr@draw@y > \avr@draw@maxy
\ifcsdef{avr@draw@\the\avr@draw@x @\the\avr@draw@y}{%
#1{\the\avr@draw@x}{\the\avr@draw@y}{\csuse{avr@draw@\the\avr@draw@x @\the\avr@draw@y}}%
}{}%
\advance \avr@draw@y by 1\relax%
\repeat}%
\advance \avr@draw@x by 1\relax%
\repeat%
}
......
......@@ -3,7 +3,7 @@
}
\def\avr@debug#1{%
\typeout{\the\avr@pc: #1}%
\typeout{\the\avr@instr@executed:\the\avr@pc: #1}%
}
\def\avr@error#1{%
......@@ -12,9 +12,12 @@
}
\newif\ifavrbreak
\avrbreakfalse
\newcount\avr@instr@executed
\def\avr@instr@init{%
\avr@instr@executed=0%
\avrbreakfalse%
}
% Execution Engine
......@@ -1053,6 +1056,7 @@
\csdef{avr@instr@1001010110011000}\@nnil{%
\avr@debug{BREAK: (\the\avr@instr@executed) instructions}%
\avr@instr@steps=0\relax%
\avrbreaktrue%
\avr@pc@inc%
}
......
%% These Functions are used within the test-suite
\def\avr@test@setup#1{%
\typeout{---- Test: #1 ----}%
\typeout{-> Initialize the AVR}%
\avr@init%
}
\def\avr@test@SREG#1{% Tests SREG for value
\avr@sreg@get{\@@SREG}%
\expandafter\ifstrequal\expandafter{\@@SREG}{#1}{%Success
}{%
\avr@error{SREG unequal: #1 != \@@SREG}%
}%
}
\def\avr@test@REG#1#2{% Tests SREG for value
\avr@reg@get{\csuse{avr@#1}}{\@@REG}%
\expandafter\ifstrequal\expandafter{\@@REG}{#2}{%Success
}{%
\avr@error{REG unequal: #2 != \@@REG}%
}%
}
\def\avr@test@MEM#1#2{% Tests MEM for value
\avr@mem@get{#1}{\@@MEM}%
\expandafter\ifstrequal\expandafter{\@@MEM}{#2}{%Success
}{%
\avr@error{MEM unequal: #2 != \@@MEM}%
}%
}
\def\avr@test@UDR#1{% Tests UDR output
\ifdefstring{\avr@UDR}{#1}{%Success
}{%
\avr@error{UDR unequal: #1 != \avr@UDR}%
}%
\def\avr@UDR{}%
}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "avr.tex"
%%% End:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{tabularx}
\parindent=0pt
\makeatletter
\errorcontextlines=23
\RequirePackage{etoolbox}
\RequirePackage{tabularx}
\input{avr.numbers}
\input{avr.binary}
......@@ -15,19 +8,3 @@
\input{avr.instr}
\input{avr.io}
\input{avr.testsuite}
\begin{document}
\makeatletter
\avr@test
\avr@dump@totex
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment