mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-28 16:26:35 +00:00
176 lines
16 KiB
HTML
Executable file
176 lines
16 KiB
HTML
Executable file
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
|
|
<meta name="generator" content="ZealOS V1.00">
|
|
<style type="text/css">
|
|
body {background-color:#fef1f0;}
|
|
.cF0{color:#000000;background-color:#fef1f0;}
|
|
.cF1{color:#0148a4;background-color:#fef1f0;}
|
|
.cF2{color:#3b7901;background-color:#fef1f0;}
|
|
.cF3{color:#057c7e;background-color:#fef1f0;}
|
|
.cF4{color:#bb2020;background-color:#fef1f0;}
|
|
.cF5{color:#9e42ae;background-color:#fef1f0;}
|
|
.cF6{color:#b57901;background-color:#fef1f0;}
|
|
.cF7{color:#b2b6af;background-color:#fef1f0;}
|
|
.cF8{color:#555753;background-color:#fef1f0;}
|
|
.cF9{color:#678fbb;background-color:#fef1f0;}
|
|
.cFA{color:#82bc49;background-color:#fef1f0;}
|
|
.cFB{color:#0097a2;background-color:#fef1f0;}
|
|
.cFC{color:#e26a6a;background-color:#fef1f0;}
|
|
.cFD{color:#c671bc;background-color:#fef1f0;}
|
|
.cFE{color:#c7ab00;background-color:#fef1f0;}
|
|
.cFF{color:#fef1f0;background-color:#fef1f0;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre style="font-family:monospace;font-size:12pt">
|
|
<a name="l1"></a><span class=cF0>#</span><span class=cF1>define</span><span class=cF0> VGAP_IDX </span><span class=cFE>0x3C4</span><span class=cF0>
|
|
<a name="l2"></a>#</span><span class=cF1>define</span><span class=cF0> VGAP_DATA </span><span class=cFE>0x3C5</span><span class=cF0>
|
|
<a name="l3"></a>#</span><span class=cF1>define</span><span class=cF0> VGAR_MAP_MASK </span><span class=cFE>0x02</span><span class=cF0>
|
|
<a name="l4"></a>
|
|
<a name="l5"></a></span><span class=cF1>U8</span><span class=cF0> rev[</span><span class=cFE>256</span><span class=cF0>], </span><span class=cF2>//The VGA bits are backward</span><span class=cF0>
|
|
<a name="l6"></a> image[</span><span class=cFE>640</span><span class=cF0> * </span><span class=cFE>480</span><span class=cF0> / </span><span class=cFE>8</span><span class=cF0>]; </span><span class=cF2>//We need read-modify write.</span><span class=cF0>
|
|
<a name="l7"></a> </span><span class=cF2>//0xA0000 alias memory can't be read.</span><span class=cF0>
|
|
<a name="l8"></a>
|
|
<a name="l9"></a></span><span class=cF1>U0</span><span class=cF0> MGInit()
|
|
<a name="l10"></a>{
|
|
<a name="l11"></a> </span><span class=cF9>I64</span><span class=cF0> i, j;
|
|
<a name="l12"></a>
|
|
<a name="l13"></a> </span><span class=cF5>MemSet</span><span class=cF0>(image, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>image</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l14"></a> </span><span class=cF5>MemSet</span><span class=cF0>(rev, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>rev</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l15"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFE>256</span><span class=cF0>; i++)
|
|
<a name="l16"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j < </span><span class=cFE>8</span><span class=cF0>; j++)
|
|
<a name="l17"></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="l18"></a> </span><span class=cF5>Bts</span><span class=cF0>(&rev[i], </span><span class=cFE>7</span><span class=cF0> - j);
|
|
<a name="l19"></a>}
|
|
<a name="l20"></a>
|
|
<a name="l21"></a></span><span class=cF1>U0</span><span class=cF0> MGUpdate()
|
|
<a name="l22"></a>{</span><span class=cF2>//Copy image to VGA memory</span><span class=cF0>
|
|
<a name="l23"></a></span><span class=cF2>//For better performance we could only write what's changed.</span><span class=cF0>
|
|
<a name="l24"></a> </span><span class=cF2>//0xA0000 alias is slower than normal RAM.</span><span class=cF0>
|
|
<a name="l25"></a> </span><span class=cF5>OutU8</span><span class=cF0>(VGAP_IDX, VGAR_MAP_MASK);
|
|
<a name="l26"></a> </span><span class=cF5>OutU8</span><span class=cF0>(VGAP_DATA, </span><span class=cFE>0xF</span><span class=cF0>);</span><span class=cF2>//All color planes at once -- Black and White</span><span class=cF0>
|
|
<a name="l27"></a> </span><span class=cF5>MemCopy</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="l28"></a>}
|
|
<a name="l29"></a>
|
|
<a name="l30"></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="l31"></a>{
|
|
<a name="l32"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFE>0</span><span class=cF0> <= x < </span><span class=cFE>640</span><span class=cF0> && </span><span class=cFE>0</span><span class=cF0> <= y < </span><span class=cFE>480</span><span class=cF0>)
|
|
<a name="l33"></a> </span><span class=cF5>Bts</span><span class=cF0>(image,y * </span><span class=cFE>640</span><span class=cF0> + x ^ </span><span class=cFE>7</span><span class=cF0>);
|
|
<a name="l34"></a>}
|
|
<a name="l35"></a>
|
|
<a name="l36"></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="l37"></a>{</span><span class=cF2>//Warning! No clipping</span><span class=cF0>
|
|
<a name="l38"></a></span><span class=cF2>//For performance, we do as many whole-bytes as possible.</span><span class=cF0>
|
|
<a name="l39"></a> </span><span class=cF1>U8</span><span class=cF0> *ptr;
|
|
<a name="l40"></a> </span><span class=cF9>I64</span><span class=cF0> i, w, leading, trailing, whole_bytes;
|
|
<a name="l41"></a>
|
|
<a name="l42"></a> </span><span class=cF1>if</span><span class=cF0> (x2 < x1)
|
|
<a name="l43"></a> </span><span class=cF5>SwapI64</span><span class=cF0>(&x1, &x2);
|
|
<a name="l44"></a> ptr = image + y * </span><span class=cFE>640</span><span class=cF0> / </span><span class=cFE>8</span><span class=cF0> + x1 >> </span><span class=cFE>3</span><span class=cF0>;
|
|
<a name="l45"></a> w = x2 - x1 + </span><span class=cFE>1</span><span class=cF0>;
|
|
<a name="l46"></a> leading = </span><span class=cFE>8</span><span class=cF0> - x1 & </span><span class=cFE>7</span><span class=cF0>;
|
|
<a name="l47"></a> trailing = (x2 + </span><span class=cFE>1</span><span class=cF0>) & </span><span class=cFE>7</span><span class=cF0>;
|
|
<a name="l48"></a> </span><span class=cF1>if</span><span class=cF0> (leading + trailing > w)
|
|
<a name="l49"></a> *ptr |= rev[(</span><span class=cFE>0xFF00</span><span class=cF0> >> leading & </span><span class=cF7>(</span><span class=cFE>0x00FF</span><span class=cF0> << trailing</span><span class=cF7>)</span><span class=cF0> >> </span><span class=cFE>8</span><span class=cF0>)];
|
|
<a name="l50"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l51"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l52"></a> whole_bytes = (w - leading - trailing) >> </span><span class=cFE>3</span><span class=cF0>;
|
|
<a name="l53"></a> </span><span class=cF1>if</span><span class=cF0> (leading)
|
|
<a name="l54"></a> *ptr++ |= rev[(</span><span class=cFE>0xFF00</span><span class=cF0> >> leading) & </span><span class=cFE>0xFF</span><span class=cF0>];
|
|
<a name="l55"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < whole_bytes; i++)
|
|
<a name="l56"></a> *ptr++ = </span><span class=cFE>0xFF</span><span class=cF0>;
|
|
<a name="l57"></a> </span><span class=cF1>if</span><span class=cF0> (trailing)
|
|
<a name="l58"></a> *ptr++ |= rev[(</span><span class=cFE>0x00FF</span><span class=cF0> << trailing) >> </span><span class=cFE>8</span><span class=cF0>];
|
|
<a name="l59"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l60"></a>}
|
|
<a name="l61"></a>
|
|
<a name="l62"></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="l63"></a>{</span><span class=cF2>//Warning! No clipping</span><span class=cF0>
|
|
<a name="l64"></a> </span><span class=cF9>I64</span><span class=cF0> dx=x2-x1,dy=y2-y1;
|
|
<a name="l65"></a>
|
|
<a name="l66"></a> x1 <<= </span><span class=cFE>32</span><span class=cF0>; x2 <<= </span><span class=cFE>32</span><span class=cF0>;
|
|
<a name="l67"></a> y1 <<= </span><span class=cFE>32</span><span class=cF0>; y2 <<= </span><span class=cFE>32</span><span class=cF0>;
|
|
<a name="l68"></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>)
|
|
<a name="l69"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l70"></a> dy = dy << </span><span class=cFE>32</span><span class=cF0> / </span><span class=cF5>AbsI64</span><span class=cF0>(dx);
|
|
<a name="l71"></a> dx = </span><span class=cF5>SignI64</span><span class=cF0>(dx) << </span><span class=cFE>32</span><span class=cF0>;
|
|
<a name="l72"></a> </span><span class=cF1>while</span><span class=cF0> (x1 != x2)
|
|
<a name="l73"></a> {
|
|
<a name="l74"></a> MGPlot(x1.i32[</span><span class=cFE>1</span><span class=cF0>], y1.i32[</span><span class=cFE>1</span><span class=cF0>]);
|
|
<a name="l75"></a> x1 += dx; y1 += dy;
|
|
<a name="l76"></a> }
|
|
<a name="l77"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l78"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l79"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l80"></a> dx = dx << </span><span class=cFE>32</span><span class=cF0> / </span><span class=cF5>AbsI64</span><span class=cF0>(dy);
|
|
<a name="l81"></a> dy = </span><span class=cF5>SignI64</span><span class=cF0>(dy) << </span><span class=cFE>32</span><span class=cF0>;
|
|
<a name="l82"></a> </span><span class=cF1>while</span><span class=cF0> (y1 != y2)
|
|
<a name="l83"></a> {
|
|
<a name="l84"></a> MGPlot(x1.i32[</span><span class=cFE>1</span><span class=cF0>], y1.i32[</span><span class=cFE>1</span><span class=cF0>]);
|
|
<a name="l85"></a> x1 += dx;
|
|
<a name="l86"></a> y1 += dy;
|
|
<a name="l87"></a> }
|
|
<a name="l88"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l89"></a> MGPlot(x1.i32[</span><span class=cFE>1</span><span class=cF0>], y1.i32[</span><span class=cFE>1</span><span class=cF0>]);
|
|
<a name="l90"></a>}
|
|
<a name="l91"></a>
|
|
<a name="l92"></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="l93"></a>{
|
|
<a name="l94"></a> </span><span class=cF1>F64</span><span class=cF0> s, c, x1, y1, x2, y2;
|
|
<a name="l95"></a> </span><span class=cF9>I64</span><span class=cF0> len;
|
|
<a name="l96"></a>
|
|
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (r < </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l98"></a> </span><span class=cF1>return</span><span class=cF0>;
|
|
<a name="l99"></a> x1 = r;
|
|
<a name="l100"></a> y1 = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l101"></a> c = </span><span class=cF5>Cos</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0> / r);
|
|
<a name="l102"></a> s = </span><span class=cF5>Sin</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0> / r);
|
|
<a name="l103"></a> len = </span><span class=cFE>2</span><span class=cF0> * r * </span><span class=cF3>pi</span><span class=cF0>;
|
|
<a name="l104"></a> MGPlot(x + x1, y + y1);
|
|
<a name="l105"></a> </span><span class=cF1>while</span><span class=cF0> (len-- >= </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l106"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l107"></a>
|
|
<a name="l108"></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="l109"></a>
|
|
<a name="l110"></a> </span><span class=cF2>//(x1+y1i)*(x2+y2i) = x1*x2+(x1*y1+x2*y2)i-y1*y2</span><span class=cF0>
|
|
<a name="l111"></a>
|
|
<a name="l112"></a> </span><span class=cF2>// meti=mCos(t)+imSin(t)</span><span class=cF0>
|
|
<a name="l113"></a>
|
|
<a name="l114"></a> x2 = x1;
|
|
<a name="l115"></a> y2 = y1;
|
|
<a name="l116"></a> x1 = c * x2 - s * y2;
|
|
<a name="l117"></a> y1 = s * x2 + c * y2;
|
|
<a name="l118"></a> MGPlot(x+x1,y+y1);
|
|
<a name="l119"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l120"></a>}
|
|
<a name="l121"></a>
|
|
<a name="l122"></a>
|
|
<a name="l123"></a></span><span class=cF1>U0</span><span class=cF0> MiniGrLibDemo()
|
|
<a name="l124"></a>{
|
|
<a name="l125"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
|
<a name="l126"></a> MGInit;
|
|
<a name="l127"></a>
|
|
<a name="l128"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFE>100</span><span class=cF0>; i++)
|
|
<a name="l129"></a> MGHLine(</span><span class=cFE>200</span><span class=cF0> + i, </span><span class=cFE>400</span><span class=cF0> + i, </span><span class=cFE>300</span><span class=cF0> + i);
|
|
<a name="l130"></a>
|
|
<a name="l131"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFE>500</span><span class=cF0>; i += </span><span class=cFE>10</span><span class=cF0>)
|
|
<a name="l132"></a> MGLine(i, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>480</span><span class=cF0> - i);
|
|
<a name="l133"></a>
|
|
<a name="l134"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFE>300</span><span class=cF0>; i += </span><span class=cFE>4</span><span class=cF0>)
|
|
<a name="l135"></a> MGCircle(</span><span class=cFE>200</span><span class=cF0>, </span><span class=cFE>100</span><span class=cF0> + i, i);
|
|
<a name="l136"></a> MGUpdate;
|
|
<a name="l137"></a> </span><span class=cF5>Busy</span><span class=cF0>(</span><span class=cFE>1500000</span><span class=cF0>);
|
|
<a name="l138"></a></span><span class=cF2>/*</span><span class=cF0>
|
|
<a name="l139"></a></span><span class=cF2>We are returning graphics to normal operations under ZealOS.</span><span class=cF0>
|
|
<a name="l140"></a></span><span class=cF2>It is not normal to by-pass the ZealOS graphcis routines.</span><span class=cF0>
|
|
<a name="l141"></a></span><span class=cF2>The ZealOS graphics don't know VGA has changed.</span><span class=cF0>
|
|
<a name="l142"></a></span><span class=cF2>This bit tells ZealOS to update whole screen.</span><span class=cF0>
|
|
<a name="l143"></a></span><span class=cF2>*/</span><span class=cF0>
|
|
<a name="l144"></a> </span><span class=cF2>//<CTRL-ALT-v> will flush screen VGA cache.</span><span class=cF0>
|
|
<a name="l145"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
|
|
<a name="l146"></a>}
|
|
<a name="l147"></a>
|
|
<a name="l148"></a>MiniGrLibDemo;</span></pre></body>
|
|
</html>
|