mirror of
1
0
Fork 0

tests/mandelbrot: Added Mandelbrot example

This commit is contained in:
Christian Dietrich 2014-09-30 14:30:01 +02:00
parent 44fe73ff8f
commit 8bddaf53a2
5 changed files with 262 additions and 1 deletions

121
avr.draw.tex Normal file
View File

@ -0,0 +1,121 @@
% We define 2 IO Registers to communicate from AVR to the Drawing
% mechanism
\usepackage{tikz}
% TWAR
\newcount\avr@draw@argc
\csdef{avr@io@000010@set}#1{%
\avr@bin@tocount{#1}{\avr@accA}%
\avr@log{DRAW CMD: \the\avr@accA}%
\avr@draw@command{\the\avr@accA}%
\avr@draw@argc = 0\relax
}
\csdef{avr@io@000011@set}#1{%
\avr@bin@tocount{#1}{\avr@accA}%
\avr@debug{AVR DRAW PUSH: \the\avr@accA}%
\csxdef{avr@draw@stack@\the\avr@draw@argc}{\the\avr@accA}%
\advance\avr@draw@argc by 1\relax
}
\def\avr@draw@stack#1{\csuse{avr@draw@stack@#1}}
\def\avr@draw@command#1{%
\ifcsdef{avr@draw@command@#1}{%
\csuse{avr@draw@command@#1}%
}{%
\avr@error{AVR DRAW: Unkown Command #1}%
}%
}
\def\avr@draw@canvas{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Draw Commands
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\csdef{avr@draw@command@0}{} % NOP
% Set Draw Color
\definecolor{avrdraw}{rgb}{255,255,255}
\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}
}
% Set Fill Color
\definecolor{avrfill}{rgb}{255,255,255}
\csdef{avr@draw@command@2}{%
\ifnum \avr@draw@argc < 3%
\avr@debug{DRAW: Set Fill COLOR, Not enough arguments}%
\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)}
\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)}
\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}%
}
\newcommand{\avrdrawcanvas}{%
\begin{tikzpicture}
\scantokens\expandafter{\avr@draw@canvas}%
\end{tikzpicture}
}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "avr.tex"
%%% End:

View File

@ -1,3 +1,7 @@
\def\avr@log#1{%
\typeout{AVR (\the\avr@instr@executed): #1}%
}
\def\avr@debug#1{%
\typeout{\the\avr@pc: #1}%
}
@ -48,6 +52,20 @@
\avr@instr@stepn@helper%
}
% Run Forever
\def\avr@instr@run{
\avr@instr@steps=1%
\def\avr@instr@stepn@helper{
\ifnum \avr@instr@steps > 0%
\avr@instr@step%
\else%
\let\avr@instr@stepn@helper\relax%
\fi%
\avr@instr@stepn@helper%
}%
\avr@instr@stepn@helper%
}
\def\avr@instr@dispatch#1#2#3#4#5#6#7#8#9\@nnil{%
\ifcsdef{avr@instr@#1#2#3#4#5#6#7#8#9}{%
\csuse{avr@instr@#1#2#3#4#5#6#7#8#9}\@nnil%

View File

@ -12,6 +12,7 @@
\input{../avr.instr}
\input{../avr.io}
\input{../avr.testsuite}
\input{../avr.draw}
\begin{document}
\makeatletter

121
tests/mandelbrot.c Normal file
View File

@ -0,0 +1,121 @@
/** mandel.c by Eric R. Weeks written 9-28-96
** weeks@physics.emory.edu
** http://www.physics.emory.edu/~weeks/
**
** This program is public domain, but this header must be left intact
** and unchanged.
**
**/
#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
static
void setcolor(uint8_t color, 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;
}
static
void dot(uint8_t x, uint8_t y) {
TWDR = x, TWDR = y;
TWAR = CMD_SHORT_RECTANGLE;
}
/* Colors
import colorsys
def color(i):
h = i/float(100)
s = 1.0
v = h
print h, s, v
x = colorsys.hsv_to_rgb(h, s, v)
return (str(int(x[0] * 255)),
str(int(x[1] * 255)),
str(int(x[2] * 255)))
colors = [color (i) for i in range(0, 100)]
print "char color_R[] = {%s};" % (",".join([x[0] for x in colors]))
print "char color_G[] = {%s};" % (",".join([x[1] for x in colors]))
print "char color_B[] = {%s};" % (",".join([x[2] for x in colors]))
*/
char color_R[] = {0,2,5,7,10,12,15,17,20,22,25,28,30,33,35,38,40,42,42,41,40,39,38,36,34,31,29,26,22,19,15,11,6,1,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,0,0,3,13,24,35,47,58,70,83,95,108,121,135,149,163,177,192,207,214,216,219,221,224,226,229,232,234,237,239,242,244,247,249,252};
char color_G[] = {0,0,0,1,2,3,5,7,9,12,15,18,22,25,29,34,39,43,45,48,51,53,56,58,61,63,66,68,71,73,76,79,81,84,86,89,91,94,96,99,102,104,107,109,112,114,117,119,122,124,127,122,116,110,104,98,91,84,76,69,61,52,44,35,26,16,6,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,0,0};
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,0,0,0,3,8,14,20,27,33,40,48,55,63,71,80,89,98,107,117,127,130,132,135,137,140,142,145,147,150,153,155,158,160,163,165,168,170,173,175,178,181,183,186,188,191,193,196,198,201,204,206,209,211,205,195,184,173,161,149,137,125,112,99,86,72,58,44,29,15};
int main() {
float x,xx,y,cx,cy;
uint16_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;
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;
x = 0.0; y = 0.0;
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 (iteration<0xff) {
setcolor(SET_ALL_COLOR, 0,0,0);
} else {
setcolor(SET_ALL_COLOR,
color_R[i],
color_G[i],
color_B[i]);
}
dot(hx-1, hy-1);
}
}
asm volatile ("break");
}
/*
check-name: Complex Memory Operations
check-start:
\def\avr@debug#1{}
\avr@instr@run
\avrdrawcanvas
\newwrite\commentfile
\openout\commentfile=\jobname.tikz.tex
\write\commentfile{\avr@draw@canvas}
\closeout\commentfile
check-end:
*/

View File

@ -107,7 +107,7 @@ do_test()
# grab the actual output & exit value
pdflatex -halt-on-error -shell-escape "$file".tex 1> $file.output 2> $file.error
actual_exit_value=$?
rm -f *.log *.aux *.pdf
rm -f *.log *.aux
if [ "$actual_exit_value" -ne 0 ]; then
echo