164 lines
12 KiB
HTML
Executable File
164 lines
12 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="generator" content="TempleOS V5.03">
|
|
<meta name="viewport" content="width=device-width">
|
|
<link rel="stylesheet" href="/style/templeos.css">
|
|
<script src="/script/templeos.js"></script>
|
|
<style type="text/css">
|
|
.cF0{color:#000000;background-color:#ffffff;}
|
|
.cF1{color:#0000aa;background-color:#ffffff;}
|
|
.cF2{color:#00aa00;background-color:#ffffff;}
|
|
.cF3{color:#00aaaa;background-color:#ffffff;}
|
|
.cF4{color:#aa0000;background-color:#ffffff;}
|
|
.cF5{color:#aa00aa;background-color:#ffffff;}
|
|
.cF6{color:#aa5500;background-color:#ffffff;}
|
|
.cF7{color:#aaaaaa;background-color:#ffffff;}
|
|
.cF8{color:#555555;background-color:#ffffff;}
|
|
.cF9{color:#5555ff;background-color:#ffffff;}
|
|
.cFA{color:#55ff55;background-color:#ffffff;}
|
|
.cFB{color:#55ffff;background-color:#ffffff;}
|
|
.cFC{color:#ff5555;background-color:#ffffff;}
|
|
.cFD{color:#ff55ff;background-color:#ffffff;}
|
|
.cFE{color:#ffff55;background-color:#ffffff;}
|
|
.cFF{color:#ffffff;background-color:#ffffff;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre id="content">
|
|
<a name="l1"></a><span class=cF2>//See </span><a href="/Wb/Demo/Lectures/GraphicsCPULoad.HC.HTML#l1"><span class=cF4>::/Demo/Lectures/GraphicsCPULoad.HC</span></a><span class=cF0>
|
|
<a name="l2"></a></span><span class=cF1>U8</span><span class=cF0> rev[256], </span><span class=cF2>//The VGA bits are bwd</span><span class=cF0>
|
|
<a name="l3"></a>
|
|
<a name="l4"></a> image[640*480/8]; </span><span class=cF2>//We need read-modify write.</span><span class=cF0>
|
|
<a name="l5"></a> </span><span class=cF2>//0xA0000 alias memory can't be read.</span><span class=cF0>
|
|
<a name="l6"></a>
|
|
<a name="l7"></a></span><span class=cF1>U0</span><span class=cF0> MGInit()
|
|
<a name="l8"></a>{
|
|
<a name="l9"></a> </span><span class=cF9>I64</span><span class=cF0> i,j;
|
|
<a name="l10"></a> </span><span class=cF5>MemSet</span><span class=cF0>(image,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>image</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l11"></a> </span><span class=cF5>MemSet</span><span class=cF0>(rev,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>rev</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l12"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<256;i++)
|
|
<a name="l13"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j<8;j++)
|
|
<a name="l14"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&i,j</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l15"></a> </span><span class=cF5>Bts</span><span class=cF0>(&rev[i],7-j);
|
|
<a name="l16"></a>}
|
|
<a name="l17"></a>
|
|
<a name="l18"></a></span><span class=cF1>U0</span><span class=cF0> MGUpdate()
|
|
<a name="l19"></a>{</span><span class=cF2>//Copy image to VGA memory</span><span class=cF0>
|
|
<a name="l20"></a></span><span class=cF2>//For better performance we could only write what's changed.</span><span class=cF0>
|
|
<a name="l21"></a> </span><span class=cF2>//0xA0000 alias is slower than normal RAM.</span><span class=cF0>
|
|
<a name="l22"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>VGAP_IDX</span><span class=cF0>,</span><span class=cF3>VGAR_MAP_MASK</span><span class=cF0>);
|
|
<a name="l23"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>VGAP_DATA</span><span class=cF0>,0xF);</span><span class=cF2>//All color planes at once -- Black and White</span><span class=cF0>
|
|
<a name="l24"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(</span><span class=cFB>text</span><span class=cF0>.vga_alias,image,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>image</span><span class=cF7>)</span><span class=cF0>); </span><span class=cF2>//Alias of 0xA0000</span><span class=cF0>
|
|
<a name="l25"></a>}
|
|
<a name="l26"></a>
|
|
<a name="l27"></a></span><span class=cF1>U0</span><span class=cF0> MGPlot(</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y)
|
|
<a name="l28"></a>{
|
|
<a name="l29"></a> </span><span class=cF1>if</span><span class=cF0> (0<=x<640 && 0<=y<480)
|
|
<a name="l30"></a> </span><span class=cF5>Bts</span><span class=cF0>(image,y*640+x^7);
|
|
<a name="l31"></a>}
|
|
<a name="l32"></a>
|
|
<a name="l33"></a></span><span class=cF1>U0</span><span class=cF0> MGHLine(</span><span class=cF9>I64</span><span class=cF0> x1,</span><span class=cF9>I64</span><span class=cF0> x2,</span><span class=cF9>I64</span><span class=cF0> y)
|
|
<a name="l34"></a>{</span><span class=cF2>//Warning! No clipping</span><span class=cF0>
|
|
<a name="l35"></a></span><span class=cF2>//For performance, we do as many whole-bytes as possible.</span><span class=cF0>
|
|
<a name="l36"></a> </span><span class=cF1>U8</span><span class=cF0> *ptr;
|
|
<a name="l37"></a> </span><span class=cF9>I64</span><span class=cF0> i,w,leading,trailing,whole_bytes;
|
|
<a name="l38"></a> </span><span class=cF1>if</span><span class=cF0> (x2<x1) </span><span class=cF5>SwapI64</span><span class=cF0>(&x1,&x2);
|
|
<a name="l39"></a> ptr=image+y*640/8+x1>>3;
|
|
<a name="l40"></a> w=x2-x1+1;
|
|
<a name="l41"></a> leading =8-x1&7;
|
|
<a name="l42"></a> trailing=(x2+1)&7;
|
|
<a name="l43"></a> </span><span class=cF1>if</span><span class=cF0> (leading+trailing>w)
|
|
<a name="l44"></a> *ptr|=rev[(0xFF00>>leading&</span><span class=cF7>(</span><span class=cF0>0x00FF<<trailing</span><span class=cF7>)</span><span class=cF0>>>8)];
|
|
<a name="l45"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l46"></a> whole_bytes=(w-leading-trailing)>>3;
|
|
<a name="l47"></a> </span><span class=cF1>if</span><span class=cF0> (leading)
|
|
<a name="l48"></a> *ptr++|=rev[(0xFF00>>leading)&0xFF];
|
|
<a name="l49"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<whole_bytes;i++)
|
|
<a name="l50"></a> *ptr++=0xFF;
|
|
<a name="l51"></a> </span><span class=cF1>if</span><span class=cF0> (trailing)
|
|
<a name="l52"></a> *ptr++|=rev[(0x00FF<<trailing)>>8];
|
|
<a name="l53"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l54"></a>}
|
|
<a name="l55"></a>
|
|
<a name="l56"></a></span><span class=cF1>U0</span><span class=cF0> MGLine(</span><span class=cF9>I64</span><span class=cF0> x1,</span><span class=cF9>I64</span><span class=cF0> y1,</span><span class=cF9>I64</span><span class=cF0> x2,</span><span class=cF9>I64</span><span class=cF0> y2)
|
|
<a name="l57"></a>{</span><span class=cF2>//Warning! No clipping</span><span class=cF0>
|
|
<a name="l58"></a> </span><span class=cF9>I64</span><span class=cF0> dx=x2-x1,dy=y2-y1;
|
|
<a name="l59"></a> x1<<=32; x2<<=32;
|
|
<a name="l60"></a> y1<<=32; y2<<=32;
|
|
<a name="l61"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>AbsI64</span><span class=cF7>(</span><span class=cF0>dx</span><span class=cF7>)</span><span class=cF0>></span><span class=cF5>AbsI64</span><span class=cF7>(</span><span class=cF0>dy</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l62"></a> dy=dy<<32/</span><span class=cF5>AbsI64</span><span class=cF0>(dx);
|
|
<a name="l63"></a> dx=</span><span class=cF5>SignI64</span><span class=cF0>(dx)<<32;
|
|
<a name="l64"></a> </span><span class=cF1>while</span><span class=cF0> (x1!=x2) {
|
|
<a name="l65"></a> MGPlot(x1.i32[1],y1.i32[1]);
|
|
<a name="l66"></a> x1+=dx; y1+=dy;
|
|
<a name="l67"></a> }
|
|
<a name="l68"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l69"></a> dx=dx<<32/</span><span class=cF5>AbsI64</span><span class=cF0>(dy);
|
|
<a name="l70"></a> dy=</span><span class=cF5>SignI64</span><span class=cF0>(dy)<<32;
|
|
<a name="l71"></a> </span><span class=cF1>while</span><span class=cF0> (y1!=y2) {
|
|
<a name="l72"></a> MGPlot(x1.i32[1],y1.i32[1]);
|
|
<a name="l73"></a> x1+=dx; y1+=dy;
|
|
<a name="l74"></a> }
|
|
<a name="l75"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l76"></a> MGPlot(x1.i32[1],y1.i32[1]);
|
|
<a name="l77"></a>}
|
|
<a name="l78"></a>
|
|
<a name="l79"></a></span><span class=cF1>U0</span><span class=cF0> MGCircle(</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y,</span><span class=cF1>F64</span><span class=cF0> r)
|
|
<a name="l80"></a>{
|
|
<a name="l81"></a> </span><span class=cF1>F64</span><span class=cF0> s,c,x1,y1,x2,y2;
|
|
<a name="l82"></a> </span><span class=cF9>I64</span><span class=cF0> len;
|
|
<a name="l83"></a> </span><span class=cF1>if</span><span class=cF0> (r<0) </span><span class=cF1>return</span><span class=cF0>;
|
|
<a name="l84"></a> x1=r; y1=0;
|
|
<a name="l85"></a> c=</span><span class=cF5>Cos</span><span class=cF0>(1/r);
|
|
<a name="l86"></a> s=</span><span class=cF5>Sin</span><span class=cF0>(1/r);
|
|
<a name="l87"></a> len=2*r*</span><span class=cF3>pi</span><span class=cF0>;
|
|
<a name="l88"></a> MGPlot(x+x1,y+y1);
|
|
<a name="l89"></a> </span><span class=cF1>while</span><span class=cF0> (len-->=0) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l90"></a>
|
|
<a name="l91"></a> </span><span class=cF2>//m1@a1 * m2@a2</span><span class=cF0> </span><span class=cF2>= m1*m2@(arg1+arg2)</span><span class=cF0>
|
|
<a name="l92"></a>
|
|
<a name="l93"></a> </span><span class=cF2>//(x1+y1i)*(x2+y2i) = x1*x2+(x1*y1+x2*y2)i-y1*y2</span><span class=cF0>
|
|
<a name="l94"></a>
|
|
<a name="l95"></a> </span><span class=cF2>// meti=mCos(t)+imSin(t)</span><span class=cF0>
|
|
<a name="l96"></a>
|
|
<a name="l97"></a> x2=x1; y2=y1;
|
|
<a name="l98"></a> x1=c*x2-s*y2;
|
|
<a name="l99"></a> y1=s*x2+c*y2;
|
|
<a name="l100"></a> MGPlot(x+x1,y+y1);
|
|
<a name="l101"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l102"></a>}
|
|
<a name="l103"></a>
|
|
<a name="l104"></a>
|
|
<a name="l105"></a></span><span class=cF1>U0</span><span class=cF0> MiniGrLibDemo()
|
|
<a name="l106"></a>{
|
|
<a name="l107"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
|
<a name="l108"></a> MGInit;
|
|
<a name="l109"></a>
|
|
<a name="l110"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<100;i++)
|
|
<a name="l111"></a> MGHLine(200+i,400+i,300+i);
|
|
<a name="l112"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<500;i+=10)
|
|
<a name="l113"></a> MGLine(i,0,0,480-i);
|
|
<a name="l114"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<300;i+=4)
|
|
<a name="l115"></a> MGCircle(200,100+i,i);
|
|
<a name="l116"></a> MGUpdate;
|
|
<a name="l117"></a> </span><span class=cF5>Busy</span><span class=cF0>(1500000);
|
|
<a name="l118"></a></span><span class=cF2>/*</span><span class=cF0>
|
|
<a name="l119"></a></span><span class=cF2>We are returning graphics to normal operations under TempleOS.</span><span class=cF0>
|
|
<a name="l120"></a></span><span class=cF2>It is not normal to by-pass the TempleOS graphcis routines.</span><span class=cF0>
|
|
<a name="l121"></a></span><span class=cF2>The TempleOS graphics don't know VGA has changed.</span><span class=cF0>
|
|
<a name="l122"></a></span><span class=cF2>This bit tells TempleOS to update whole scrn.</span><span class=cF0>
|
|
<a name="l123"></a></span><span class=cF2>*/</span><span class=cF0>
|
|
<a name="l124"></a> </span><span class=cF2>//<CTRL-ALT-v> will flush scrn VGA cache.</span><span class=cF0>
|
|
<a name="l125"></a> </span><span class=cF5>VGAFlush</span><span class=cF0>;
|
|
<a name="l126"></a>}
|
|
<a name="l127"></a>
|
|
<a name="l128"></a>MiniGrLibDemo;
|
|
<a name="l129"></a>
|
|
<a name="l130"></a></span><span class=cF2>//See </span><a href="/Wb/Kernel/Display.HC.HTML#l1"><span class=cF4>RawPutChar</span></a><span class=cF2>() for text.</span><span class=cF0>
|
|
<a name="l131"></a></span><span class=cF2>//See </span><a href="/Wb/Demo/Lectures/ScrnMemory.HC.HTML#l1"><span class=cF4>::/Demo/Lectures/ScrnMemory.HC</span></a><span class=cF2> for color.</span><span class=cF0>
|
|
<a name="l132"></a></span><span class=cF2>//See </span><a href="/Wb/Demo/Lectures/GraphicsCPULoad.HC.HTML#l1"><span class=cF4>::/Demo/Lectures/GraphicsCPULoad.HC</span></a><span class=cF2>.</span><span class=cF0>
|
|
</span></pre></body>
|
|
</html>
|