templeos-info/public/Wb/Apps/Logic/Logic.HC.HTML

622 lines
56 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=cF0>#</span><span class=cF1>define</span><span class=cF0> TABLE_SIZE_MAX 0x10000
<a name="l2"></a>
<a name="l3"></a></span><span class=cF9>I64</span><span class=cF0> output_found,passes,table_size;
<a name="l4"></a>
<a name="l5"></a></span><span class=cF1>U8</span><span class=cF0> *gate_type_table =</span><span class=cF3>NULL</span><span class=cF0>,
<a name="l6"></a> *displayed_design=</span><span class=cF3>NULL</span><span class=cF0>,
<a name="l7"></a> *added_this_pass =</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l8"></a>
<a name="l9"></a></span><span class=cF9>U16</span><span class=cF0> *input1_table=</span><span class=cF3>NULL</span><span class=cF0>,
<a name="l10"></a> *input2_table=</span><span class=cF3>NULL</span><span class=cF0>,
<a name="l11"></a> *input3_table=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l12"></a>
<a name="l13"></a>#</span><span class=cF1>define</span><span class=cF0> CONNECT_WIDTH 16
<a name="l14"></a>#</span><span class=cF1>define</span><span class=cF0> GATE_WIDTH 37
<a name="l15"></a>
<a name="l16"></a> </span><span class=cFA>
<a name="l17"></a> /* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l18"></a>
<a name="l19"></a> </span><span class=cFA>
<a name="l20"></a> /* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l21"></a>
<a name="l22"></a> </span><span class=cFA>
<a name="l23"></a> /* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l24"></a>
<a name="l25"></a> </span><span class=cFA>
<a name="l26"></a> /* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l27"></a>
<a name="l28"></a> </span><span class=cFA>
<a name="l29"></a> /* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l30"></a>
<a name="l31"></a> </span><span class=cFA>
<a name="l32"></a> /* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l33"></a>
<a name="l34"></a> </span><span class=cFA>
<a name="l35"></a> /* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l36"></a>
<a name="l37"></a>
<a name="l38"></a> </span><span class=cFA>
<a name="l39"></a> /* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l40"></a>
<a name="l41"></a>
<a name="l42"></a> </span><span class=cFA>
<a name="l43"></a> /* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l44"></a>
<a name="l45"></a>
<a name="l46"></a> </span><span class=cFA>
<a name="l47"></a> /* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l48"></a>
<a name="l49"></a>
<a name="l50"></a></span><span class=cF1>U8</span><span class=cF0> *gate_type_lst=</span><span class=cF6>&quot;NULL\0OUTPUT\0INPUT\0&quot;</span><span class=cF0>
<a name="l51"></a> </span><span class=cF6>&quot;NOT\0AND\0OR\0NAND\0NOR\0XOR\0AND3\0OR3\0NAND3\0NOR3\0&quot;</span><span class=cF0>;
<a name="l52"></a>
<a name="l53"></a>#</span><span class=cF1>define</span><span class=cF0> GT_NULL 0 </span><span class=cF2>//Specifies that table entry has not been filled-in</span><span class=cF0>
<a name="l54"></a>#</span><span class=cF1>define</span><span class=cF0> GT_OUTPUT 1 </span><span class=cF2>//Specifies the table entry is a desired output</span><span class=cF0>
<a name="l55"></a>#</span><span class=cF1>define</span><span class=cF0> GT_INPUT 2 </span><span class=cF2>//Specifies that table entry comes from an input signal</span><span class=cF0>
<a name="l56"></a>
<a name="l57"></a>#</span><span class=cF1>define</span><span class=cF0> GT_FIRST_REAL_GATE 3
<a name="l58"></a>#</span><span class=cF1>define</span><span class=cF0> GT_NOT 3
<a name="l59"></a>#</span><span class=cF1>define</span><span class=cF0> GT_AND 4
<a name="l60"></a>#</span><span class=cF1>define</span><span class=cF0> GT_OR 5
<a name="l61"></a>#</span><span class=cF1>define</span><span class=cF0> GT_NAND 6
<a name="l62"></a>#</span><span class=cF1>define</span><span class=cF0> GT_NOR 7
<a name="l63"></a>#</span><span class=cF1>define</span><span class=cF0> GT_XOR 8
<a name="l64"></a>#</span><span class=cF1>define</span><span class=cF0> GT_AND3 9
<a name="l65"></a>#</span><span class=cF1>define</span><span class=cF0> GT_OR3 10
<a name="l66"></a>#</span><span class=cF1>define</span><span class=cF0> GT_NAND3 11
<a name="l67"></a>#</span><span class=cF1>define</span><span class=cF0> GT_NOR3 12
<a name="l68"></a>#</span><span class=cF1>define</span><span class=cF0> GT_ENTRIES_NUM 13
<a name="l69"></a>
<a name="l70"></a>#</span><span class=cF1>define</span><span class=cF0> SEL_GATES_NUM 128
<a name="l71"></a>
<a name="l72"></a></span><span class=cF1>U8</span><span class=cF0> *imgs[GT_ENTRIES_NUM]={</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cFA>
<a name="l73"></a>&lt;NOT&gt;</span><span class=cF0>,</span><span class=cFA>&lt;AND&gt;</span><span class=cF0>,</span><span class=cFA>&lt;OR&gt;</span><span class=cF0>,</span><span class=cFA>&lt;NAND&gt;</span><span class=cF0>,</span><span class=cFA>&lt;NOR&gt;</span><span class=cF0>,</span><span class=cFA>&lt;XOR&gt;</span><span class=cF0>,</span><span class=cFA>&lt;AND3&gt;</span><span class=cF0>,</span><span class=cFA>&lt;OR3&gt;</span><span class=cF0>,</span><span class=cFA>&lt;NAND3&gt;</span><span class=cF0>,</span><span class=cFA>&lt;NOR3&gt;</span><span class=cF0>};
<a name="l74"></a>
<a name="l75"></a></span><span class=cF9>I64</span><span class=cF0> num_inputs_entered,num_outputs_entered;
<a name="l76"></a></span><span class=cF9>I64</span><span class=cF0> num_sel_gates,
<a name="l77"></a> sel_gates[SEL_GATES_NUM];
<a name="l78"></a>
<a name="l79"></a></span><span class=cF1>U0</span><span class=cF0> GetGates()
<a name="l80"></a>{
<a name="l81"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l82"></a> </span><span class=cF1>U8</span><span class=cF0> *st;
<a name="l83"></a>
<a name="l84"></a> </span><span class=cF6>&quot;\nEnter the available gate types in the order you prefer them to be used.\n&quot;</span><span class=cF0>
<a name="l85"></a> </span><span class=cF6>&quot;Your choices are:\n&quot;</span><span class=cF0>;
<a name="l86"></a> </span><span class=cF1>for</span><span class=cF0> (i=GT_FIRST_REAL_GATE;i&lt;GT_ENTRIES_NUM;i++)
<a name="l87"></a> </span><span class=cF6>&quot;%z &quot;</span><span class=cF0>,i,gate_type_lst;
<a name="l88"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l89"></a>
<a name="l90"></a> num_sel_gates=0;
<a name="l91"></a> </span><span class=cF1>while</span><span class=cF0> (num_sel_gates&lt;GT_ENTRIES_NUM) </span><span class=cF7>{</span><span class=cF0>
<a name="l92"></a> </span><span class=cF6>&quot;%d&quot;</span><span class=cF0>,num_sel_gates;
<a name="l93"></a> st=</span><span class=cF5>GetStr</span><span class=cF0>(</span><span class=cF6>&quot; Gate: &quot;</span><span class=cF0>);
<a name="l94"></a> </span><span class=cF1>if</span><span class=cF0> (!*st) {
<a name="l95"></a> </span><span class=cF5>Free</span><span class=cF0>(st);
<a name="l96"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l97"></a> }
<a name="l98"></a> i=</span><span class=cF5>LstMatch</span><span class=cF0>(st,gate_type_lst,</span><span class=cF3>LMF_IGNORE_CASE</span><span class=cF0>);
<a name="l99"></a> </span><span class=cF5>Free</span><span class=cF0>(st);
<a name="l100"></a> </span><span class=cF1>if</span><span class=cF0> (i&lt;GT_FIRST_REAL_GATE)
<a name="l101"></a> </span><span class=cF6>&quot;Invalid response\n&quot;</span><span class=cF0>;
<a name="l102"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l103"></a> sel_gates[num_sel_gates++]=i;
<a name="l104"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l105"></a>}
<a name="l106"></a>
<a name="l107"></a></span><span class=cF1>U0</span><span class=cF0> Init()
<a name="l108"></a>{
<a name="l109"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l110"></a>
<a name="l111"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l112"></a> table_size=</span><span class=cF5>GetI64</span><span class=cF0>(</span><span class=cF6>&quot;\nTable size in hex (3 input=0x100,4=0x10000): &quot;</span><span class=cF0>,0);
<a name="l113"></a> </span><span class=cF1>if</span><span class=cF0> (table_size&gt;TABLE_SIZE_MAX)
<a name="l114"></a> </span><span class=cF6>&quot;Too large\n&quot;</span><span class=cF0>;
<a name="l115"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (table_size&lt;1) {
<a name="l116"></a> </span><span class=cF6>&quot;No table specified, aborting.\n&quot;</span><span class=cF0>;
<a name="l117"></a> </span><span class=cF5>throw</span><span class=cF0>;
<a name="l118"></a> }
<a name="l119"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>while</span><span class=cF0> (table_size&gt;TABLE_SIZE_MAX);
<a name="l120"></a>
<a name="l121"></a> gate_type_table =</span><span class=cF5>CAlloc</span><span class=cF0>(table_size*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF7>)</span><span class=cF0>);
<a name="l122"></a> displayed_design=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>table_size+7</span><span class=cF7>)</span><span class=cF0>/8);
<a name="l123"></a> added_this_pass =</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>table_size+7</span><span class=cF7>)</span><span class=cF0>/8);
<a name="l124"></a> input1_table =</span><span class=cF5>MAlloc</span><span class=cF0>(table_size*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>U16</span><span class=cF7>)</span><span class=cF0>);
<a name="l125"></a> input2_table =</span><span class=cF5>MAlloc</span><span class=cF0>(table_size*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>U16</span><span class=cF7>)</span><span class=cF0>);
<a name="l126"></a> input3_table =</span><span class=cF5>MAlloc</span><span class=cF0>(table_size*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>U16</span><span class=cF7>)</span><span class=cF0>);
<a name="l127"></a>
<a name="l128"></a> </span><span class=cF6>&quot;\nEnter the hex truth table column values of inputs.\n&quot;</span><span class=cF0>;
<a name="l129"></a> </span><span class=cF1>if</span><span class=cF0> (table_size&lt;=0x100)
<a name="l130"></a> </span><span class=cF6>&quot;For example, enter A=0xF0, B=0xCC and C=0xAA.\n&quot;</span><span class=cF0>;
<a name="l131"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l132"></a> </span><span class=cF6>&quot;For example, enter A=0xFF00, B=0xF0F0, C=0xCCCC and D=0xAAAA.\n&quot;</span><span class=cF0>;
<a name="l133"></a> num_inputs_entered=0;
<a name="l134"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l135"></a> </span><span class=cF6>&quot;Input %C: &quot;</span><span class=cF0>,</span><span class=cF6>'A'</span><span class=cF0>+num_inputs_entered;
<a name="l136"></a> i=</span><span class=cF5>GetI64</span><span class=cF0>(</span><span class=cF6>&quot;&quot;</span><span class=cF0>,-1);
<a name="l137"></a> </span><span class=cF1>if</span><span class=cF0> (i&lt;0) </span><span class=cF1>break</span><span class=cF0>;
<a name="l138"></a> </span><span class=cF1>if</span><span class=cF0> (i&gt;table_size)
<a name="l139"></a> </span><span class=cF6>&quot;Too large\n&quot;</span><span class=cF0>;
<a name="l140"></a> </span><span class=cF1>else</span><span class=cF0> {
<a name="l141"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i])
<a name="l142"></a> </span><span class=cF6>&quot;Duplicate\n&quot;</span><span class=cF0>;
<a name="l143"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l144"></a> gate_type_table[i]=GT_INPUT;
<a name="l145"></a> input1_table[i]=num_inputs_entered++;
<a name="l146"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l147"></a> }
<a name="l148"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l149"></a> </span><span class=cF1>if</span><span class=cF0> (!num_inputs_entered) </span><span class=cF7>{</span><span class=cF0>
<a name="l150"></a> </span><span class=cF6>&quot;No inputs specified, aborting.\n&quot;</span><span class=cF0>;
<a name="l151"></a> </span><span class=cF5>throw</span><span class=cF0>;
<a name="l152"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l153"></a>
<a name="l154"></a> </span><span class=cF6>&quot;\nEnter the hex truth table columns values of the outputs.\n&quot;</span><span class=cF0>;
<a name="l155"></a> num_outputs_entered=0;
<a name="l156"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l157"></a> </span><span class=cF6>&quot;Output %C: &quot;</span><span class=cF0>,</span><span class=cF6>'A'</span><span class=cF0>+num_outputs_entered;
<a name="l158"></a> i=</span><span class=cF5>GetI64</span><span class=cF0>(</span><span class=cF6>&quot;&quot;</span><span class=cF0>,-1);
<a name="l159"></a> </span><span class=cF1>if</span><span class=cF0> (i&lt;0) </span><span class=cF1>break</span><span class=cF0>;
<a name="l160"></a> </span><span class=cF1>if</span><span class=cF0> (i&gt;table_size)
<a name="l161"></a> </span><span class=cF6>&quot;Too large\n&quot;</span><span class=cF0>;
<a name="l162"></a> </span><span class=cF1>else</span><span class=cF0> {
<a name="l163"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]==GT_INPUT)
<a name="l164"></a> </span><span class=cF6>&quot;To produce this output, connect to input %C\n&quot;</span><span class=cF0>,
<a name="l165"></a> </span><span class=cF6>'A'</span><span class=cF0>+input1_table[i];
<a name="l166"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]==GT_OUTPUT)
<a name="l167"></a> </span><span class=cF6>&quot;Duplicate\n&quot;</span><span class=cF0>;
<a name="l168"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l169"></a> gate_type_table[i]=GT_OUTPUT;
<a name="l170"></a> input1_table[i]=num_outputs_entered++;
<a name="l171"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l172"></a> }
<a name="l173"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l174"></a>
<a name="l175"></a> </span><span class=cF1>if</span><span class=cF0> (!num_outputs_entered) </span><span class=cF7>{</span><span class=cF0>
<a name="l176"></a> </span><span class=cF6>&quot;No output specified, aborting.\n&quot;</span><span class=cF0>;
<a name="l177"></a> </span><span class=cF5>throw</span><span class=cF0>;
<a name="l178"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l179"></a>}
<a name="l180"></a>
<a name="l181"></a></span><span class=cF1>U0</span><span class=cF0> DrawDesign(</span><span class=cF9>CDC</span><span class=cF0> *dc,</span><span class=cF9>I64</span><span class=cF0> *_y,</span><span class=cF9>I64</span><span class=cF0> output,</span><span class=cF9>I64</span><span class=cF0> depth,</span><span class=cF9>I64</span><span class=cF0> *_x_out,</span><span class=cF9>I64</span><span class=cF0> *_y_out)
<a name="l182"></a>{
<a name="l183"></a> </span><span class=cF9>I64</span><span class=cF0> y=*_y,type=gate_type_table[output],
<a name="l184"></a> xx=(passes-depth)*(GATE_WIDTH+CONNECT_WIDTH),yy=y,
<a name="l185"></a> x1,y1,x2,y2,x3,y3;
<a name="l186"></a> </span><span class=cF1>if</span><span class=cF0> (_x_out) *_x_out=xx;
<a name="l187"></a> </span><span class=cF1>if</span><span class=cF0> (_y_out) *_y_out=yy;
<a name="l188"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>displayed_design,output</span><span class=cF7>)</span><span class=cF0> &amp;&amp; type!=GT_INPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l189"></a> dc-&gt;color=</span><span class=cF3>GREEN</span><span class=cF0>;
<a name="l190"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,xx-</span><span class=cF3>FONT_WIDTH</span><span class=cF0>*3,y-4,</span><span class=cF6>&quot;Dup&quot;</span><span class=cF0>);
<a name="l191"></a> y+=10;
<a name="l192"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l193"></a> </span><span class=cF1>switch</span><span class=cF0> (type) </span><span class=cF7>{</span><span class=cF0>
<a name="l194"></a> </span><span class=cF1>case</span><span class=cF0> GT_INPUT:
<a name="l195"></a> dc-&gt;color=</span><span class=cF3>GREEN</span><span class=cF0>;
<a name="l196"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,xx-</span><span class=cF3>FONT_WIDTH</span><span class=cF0>-4,y-4,</span><span class=cF6>&quot;%C&quot;</span><span class=cF0>,</span><span class=cF6>'A'</span><span class=cF0>+input1_table[output]);
<a name="l197"></a> y+=10;
<a name="l198"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l199"></a> </span><span class=cF1>case</span><span class=cF0> GT_NOT:
<a name="l200"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>displayed_design,output</span><span class=cF7>)</span><span class=cF0>) {
<a name="l201"></a> y+=16;
<a name="l202"></a> DrawDesign(dc,&amp;y,input1_table[output],depth+1,&amp;x1,&amp;y1);
<a name="l203"></a> yy=y1;
<a name="l204"></a>
<a name="l205"></a> dc-&gt;color=</span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l206"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,xx,yy,0,imgs[type]);
<a name="l207"></a>
<a name="l208"></a> dc-&gt;color=</span><span class=cF3>RED</span><span class=cF0>;
<a name="l209"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,xx-GATE_WIDTH,yy,x1,y1);
<a name="l210"></a> </span><span class=cF1>if</span><span class=cF0> (_y_out) *_y_out=yy;
<a name="l211"></a> }
<a name="l212"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l213"></a> </span><span class=cF1>case</span><span class=cF0> GT_AND:
<a name="l214"></a> </span><span class=cF1>case</span><span class=cF0> GT_OR:
<a name="l215"></a> </span><span class=cF1>case</span><span class=cF0> GT_NAND:
<a name="l216"></a> </span><span class=cF1>case</span><span class=cF0> GT_NOR:
<a name="l217"></a> </span><span class=cF1>case</span><span class=cF0> GT_XOR:
<a name="l218"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>displayed_design,output</span><span class=cF7>)</span><span class=cF0>) {
<a name="l219"></a> y+=24;
<a name="l220"></a> DrawDesign(dc,&amp;y,input1_table[output],depth+1,&amp;x1,&amp;y1);
<a name="l221"></a> DrawDesign(dc,&amp;y,input2_table[output],depth+1,&amp;x2,&amp;y2);
<a name="l222"></a> yy=(y1+y2)/2;
<a name="l223"></a>
<a name="l224"></a> dc-&gt;color=</span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l225"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,xx,yy,0,imgs[type]);
<a name="l226"></a>
<a name="l227"></a> dc-&gt;color=</span><span class=cF3>RED</span><span class=cF0>;
<a name="l228"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,xx-GATE_WIDTH,yy-4,x1,y1);
<a name="l229"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,xx-GATE_WIDTH,yy+4,x2,y2);
<a name="l230"></a> </span><span class=cF1>if</span><span class=cF0> (_y_out) *_y_out=yy;
<a name="l231"></a> }
<a name="l232"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l233"></a> </span><span class=cF1>case</span><span class=cF0> GT_AND3:
<a name="l234"></a> </span><span class=cF1>case</span><span class=cF0> GT_OR3:
<a name="l235"></a> </span><span class=cF1>case</span><span class=cF0> GT_NAND3:
<a name="l236"></a> </span><span class=cF1>case</span><span class=cF0> GT_NOR3:
<a name="l237"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>displayed_design,output</span><span class=cF7>)</span><span class=cF0>) {
<a name="l238"></a> y+=32;
<a name="l239"></a> DrawDesign(dc,&amp;y,input1_table[output],depth+1,&amp;x1,&amp;y1);
<a name="l240"></a> DrawDesign(dc,&amp;y,input2_table[output],depth+1,&amp;x2,&amp;y2);
<a name="l241"></a> DrawDesign(dc,&amp;y,input3_table[output],depth+1,&amp;x3,&amp;y3);
<a name="l242"></a> yy=(y1+y2+y3)/3;
<a name="l243"></a>
<a name="l244"></a> dc-&gt;color=</span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l245"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,xx,yy,0,imgs[type]);
<a name="l246"></a>
<a name="l247"></a> dc-&gt;color=</span><span class=cF3>RED</span><span class=cF0>;
<a name="l248"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,xx-GATE_WIDTH,yy-8,x1,y1);
<a name="l249"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,xx-GATE_WIDTH,yy ,x2,y2);
<a name="l250"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,xx-GATE_WIDTH,yy+8,x3,y3);
<a name="l251"></a> </span><span class=cF1>if</span><span class=cF0> (_y_out) *_y_out=yy;
<a name="l252"></a> }
<a name="l253"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l254"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l255"></a> dc-&gt;color=</span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l256"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,xx,yy+3,</span><span class=cF6>&quot;%04X&quot;</span><span class=cF0>,output);
<a name="l257"></a> </span><span class=cF5>Bts</span><span class=cF0>(displayed_design,output);
<a name="l258"></a> </span><span class=cF1>if</span><span class=cF0> (_y) *_y=y;
<a name="l259"></a>}
<a name="l260"></a>
<a name="l261"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DrawIt</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *,</span><span class=cF9>CDC</span><span class=cF0> *dc)
<a name="l262"></a>{
<a name="l263"></a> </span><span class=cF9>I64</span><span class=cF0> y=0;
<a name="l264"></a> </span><span class=cF5>MemSet</span><span class=cF0>(displayed_design,0,</span><span class=cF7>(</span><span class=cF0>table_size+7</span><span class=cF7>)</span><span class=cF0>/8*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF1>Bool</span><span class=cF7>)</span><span class=cF0>);
<a name="l265"></a> DrawDesign(dc,&amp;y,output_found,0,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>);
<a name="l266"></a>}
<a name="l267"></a>
<a name="l268"></a></span><span class=cF1>U0</span><span class=cF0> FillNot(</span><span class=cF1>Bool</span><span class=cF0> *chged,</span><span class=cF9>I64</span><span class=cF0> *num_outputs_found)
<a name="l269"></a>{
<a name="l270"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,old_type;
<a name="l271"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;table_size;i++)
<a name="l272"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,i</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l273"></a> </span><span class=cFB>progress1</span><span class=cF0>=i;
<a name="l274"></a> j= (~i) &amp; (table_size-1);
<a name="l275"></a> old_type=gate_type_table[j];
<a name="l276"></a> </span><span class=cF1>if</span><span class=cF0> (old_type&lt;GT_INPUT) {
<a name="l277"></a> gate_type_table[j]=GT_NOT;
<a name="l278"></a> input1_table[j]=i;
<a name="l279"></a> </span><span class=cF5>Bts</span><span class=cF0>(added_this_pass,j);
<a name="l280"></a> *chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l281"></a> </span><span class=cF1>if</span><span class=cF0> (old_type==GT_OUTPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l282"></a> </span><span class=cF1>if</span><span class=cF0> (output_found&lt;0) output_found=j;
<a name="l283"></a> *num_outputs_found=*num_outputs_found+1;
<a name="l284"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l285"></a> }
<a name="l286"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l287"></a>}
<a name="l288"></a>
<a name="l289"></a></span><span class=cF1>U0</span><span class=cF0> FillAnd(</span><span class=cF1>Bool</span><span class=cF0> *chged,</span><span class=cF9>I64</span><span class=cF0> *num_outputs_found)
<a name="l290"></a>{
<a name="l291"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,k,old_type;
<a name="l292"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;table_size;i++)
<a name="l293"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,i</span><span class=cF7>)</span><span class=cF0>)
<a name="l294"></a> </span><span class=cF1>for</span><span class=cF0> (k=0;k&lt;table_size;k++)
<a name="l295"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[k]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,k</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l296"></a> </span><span class=cFB>progress1</span><span class=cF0>=i;
<a name="l297"></a> j= (i &amp; k) &amp; (table_size-1);
<a name="l298"></a> old_type=gate_type_table[j];
<a name="l299"></a> </span><span class=cF1>if</span><span class=cF0> (old_type&lt;GT_INPUT) {
<a name="l300"></a> gate_type_table[j]=GT_AND;
<a name="l301"></a> input1_table[j]=i;
<a name="l302"></a> input2_table[j]=k;
<a name="l303"></a> </span><span class=cF5>Bts</span><span class=cF0>(added_this_pass,j);
<a name="l304"></a> *chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l305"></a> </span><span class=cF1>if</span><span class=cF0> (old_type==GT_OUTPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l306"></a> </span><span class=cF1>if</span><span class=cF0> (output_found&lt;0) output_found=j;
<a name="l307"></a> *num_outputs_found=*num_outputs_found+1;
<a name="l308"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l309"></a> }
<a name="l310"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l311"></a>}
<a name="l312"></a>
<a name="l313"></a></span><span class=cF1>U0</span><span class=cF0> FillOr(</span><span class=cF1>Bool</span><span class=cF0> *chged,</span><span class=cF9>I64</span><span class=cF0> *num_outputs_found)
<a name="l314"></a>{
<a name="l315"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,k,old_type;
<a name="l316"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;table_size;i++)
<a name="l317"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,i</span><span class=cF7>)</span><span class=cF0>)
<a name="l318"></a> </span><span class=cF1>for</span><span class=cF0> (k=0;k&lt;table_size;k++)
<a name="l319"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[k]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,k</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l320"></a> </span><span class=cFB>progress1</span><span class=cF0>=i;
<a name="l321"></a> j= (i | k) &amp; (table_size-1);
<a name="l322"></a> old_type=gate_type_table[j];
<a name="l323"></a> </span><span class=cF1>if</span><span class=cF0> (old_type&lt;GT_INPUT) {
<a name="l324"></a> gate_type_table[j]=GT_OR;
<a name="l325"></a> input1_table[j]=i;
<a name="l326"></a> input2_table[j]=k;
<a name="l327"></a> </span><span class=cF5>Bts</span><span class=cF0>(added_this_pass,j);
<a name="l328"></a> *chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l329"></a> </span><span class=cF1>if</span><span class=cF0> (old_type==GT_OUTPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l330"></a> </span><span class=cF1>if</span><span class=cF0> (output_found&lt;0) output_found=j;
<a name="l331"></a> *num_outputs_found=*num_outputs_found+1;
<a name="l332"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l333"></a> }
<a name="l334"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l335"></a>}
<a name="l336"></a>
<a name="l337"></a></span><span class=cF1>U0</span><span class=cF0> FillNAnd(</span><span class=cF1>Bool</span><span class=cF0> *chged,</span><span class=cF9>I64</span><span class=cF0> *num_outputs_found)
<a name="l338"></a>{
<a name="l339"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,k,old_type;
<a name="l340"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;table_size;i++)
<a name="l341"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,i</span><span class=cF7>)</span><span class=cF0>)
<a name="l342"></a> </span><span class=cF1>for</span><span class=cF0> (k=0;k&lt;table_size;k++)
<a name="l343"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[k]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,k</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l344"></a> </span><span class=cFB>progress1</span><span class=cF0>=i;
<a name="l345"></a> j= (~ </span><span class=cF7>(</span><span class=cF0>i &amp; k</span><span class=cF7>)</span><span class=cF0>) &amp; (table_size-1);
<a name="l346"></a> old_type=gate_type_table[j];
<a name="l347"></a> </span><span class=cF1>if</span><span class=cF0> (old_type&lt;GT_INPUT) {
<a name="l348"></a> gate_type_table[j]=GT_NAND;
<a name="l349"></a> input1_table[j]=i;
<a name="l350"></a> input2_table[j]=k;
<a name="l351"></a> </span><span class=cF5>Bts</span><span class=cF0>(added_this_pass,j);
<a name="l352"></a> *chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l353"></a> </span><span class=cF1>if</span><span class=cF0> (old_type==GT_OUTPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l354"></a> </span><span class=cF1>if</span><span class=cF0> (output_found&lt;0) output_found=j;
<a name="l355"></a> *num_outputs_found=*num_outputs_found+1;
<a name="l356"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l357"></a> }
<a name="l358"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l359"></a>}
<a name="l360"></a>
<a name="l361"></a></span><span class=cF1>U0</span><span class=cF0> FillNOr(</span><span class=cF1>Bool</span><span class=cF0> *chged,</span><span class=cF9>I64</span><span class=cF0> *num_outputs_found)
<a name="l362"></a>{
<a name="l363"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,k,old_type;
<a name="l364"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;table_size;i++)
<a name="l365"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,i</span><span class=cF7>)</span><span class=cF0>)
<a name="l366"></a> </span><span class=cF1>for</span><span class=cF0> (k=0;k&lt;table_size;k++)
<a name="l367"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[k]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,k</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l368"></a> </span><span class=cFB>progress1</span><span class=cF0>=i;
<a name="l369"></a> j= (~ </span><span class=cF7>(</span><span class=cF0>i | k</span><span class=cF7>)</span><span class=cF0>) &amp; (table_size-1);
<a name="l370"></a> old_type=gate_type_table[j];
<a name="l371"></a> </span><span class=cF1>if</span><span class=cF0> (old_type&lt;GT_INPUT) {
<a name="l372"></a> gate_type_table[j]=GT_NOR;
<a name="l373"></a> input1_table[j]=i;
<a name="l374"></a> input2_table[j]=k;
<a name="l375"></a> </span><span class=cF5>Bts</span><span class=cF0>(added_this_pass,j);
<a name="l376"></a> *chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l377"></a> </span><span class=cF1>if</span><span class=cF0> (old_type==GT_OUTPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l378"></a> </span><span class=cF1>if</span><span class=cF0> (output_found&lt;0) output_found=j;
<a name="l379"></a> *num_outputs_found=*num_outputs_found+1;
<a name="l380"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l381"></a> }
<a name="l382"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l383"></a>}
<a name="l384"></a>
<a name="l385"></a></span><span class=cF1>U0</span><span class=cF0> FillXor(</span><span class=cF1>Bool</span><span class=cF0> *chged,</span><span class=cF9>I64</span><span class=cF0> *num_outputs_found)
<a name="l386"></a>{
<a name="l387"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,k,old_type;
<a name="l388"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;table_size;i++)
<a name="l389"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,i</span><span class=cF7>)</span><span class=cF0>)
<a name="l390"></a> </span><span class=cF1>for</span><span class=cF0> (k=0;k&lt;table_size;k++)
<a name="l391"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[k]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,k</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l392"></a> </span><span class=cFB>progress1</span><span class=cF0>=i;
<a name="l393"></a> j= (i ^ k) &amp; (table_size-1);
<a name="l394"></a> old_type=gate_type_table[j];
<a name="l395"></a> </span><span class=cF1>if</span><span class=cF0> (old_type&lt;GT_INPUT) {
<a name="l396"></a> gate_type_table[j]=GT_XOR;
<a name="l397"></a> input1_table[j]=i;
<a name="l398"></a> input2_table[j]=k;
<a name="l399"></a> </span><span class=cF5>Bts</span><span class=cF0>(added_this_pass,j);
<a name="l400"></a> *chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l401"></a> </span><span class=cF1>if</span><span class=cF0> (old_type==GT_OUTPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l402"></a> </span><span class=cF1>if</span><span class=cF0> (output_found&lt;0) output_found=j;
<a name="l403"></a> *num_outputs_found=*num_outputs_found+1;
<a name="l404"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l405"></a> }
<a name="l406"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l407"></a>}
<a name="l408"></a>
<a name="l409"></a></span><span class=cF1>U0</span><span class=cF0> FillAnd3(</span><span class=cF1>Bool</span><span class=cF0> *chged,</span><span class=cF9>I64</span><span class=cF0> *num_outputs_found)
<a name="l410"></a>{
<a name="l411"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,k,l,old_type;
<a name="l412"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;table_size;i++)
<a name="l413"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,i</span><span class=cF7>)</span><span class=cF0>)
<a name="l414"></a> </span><span class=cF1>for</span><span class=cF0> (k=0;k&lt;table_size;k++)
<a name="l415"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[k]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,k</span><span class=cF7>)</span><span class=cF0>)
<a name="l416"></a> </span><span class=cF1>for</span><span class=cF0> (l=0;l&lt;table_size;l++)
<a name="l417"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[l]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,l</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l418"></a> </span><span class=cFB>progress1</span><span class=cF0>=i;
<a name="l419"></a> j= (i &amp; k &amp; l) &amp; (table_size-1);
<a name="l420"></a> old_type=gate_type_table[j];
<a name="l421"></a> </span><span class=cF1>if</span><span class=cF0> (old_type&lt;GT_INPUT) {
<a name="l422"></a> gate_type_table[j]=GT_AND3;
<a name="l423"></a> input1_table[j]=i;
<a name="l424"></a> input2_table[j]=k;
<a name="l425"></a> input3_table[j]=l;
<a name="l426"></a> </span><span class=cF5>Bts</span><span class=cF0>(added_this_pass,j);
<a name="l427"></a> *chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l428"></a> </span><span class=cF1>if</span><span class=cF0> (old_type==GT_OUTPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l429"></a> </span><span class=cF1>if</span><span class=cF0> (output_found&lt;0) output_found=j;
<a name="l430"></a> *num_outputs_found=*num_outputs_found+1;
<a name="l431"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l432"></a> }
<a name="l433"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l434"></a>}
<a name="l435"></a>
<a name="l436"></a></span><span class=cF1>U0</span><span class=cF0> FillOr3(</span><span class=cF1>Bool</span><span class=cF0> *chged,</span><span class=cF9>I64</span><span class=cF0> *num_outputs_found)
<a name="l437"></a>{
<a name="l438"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,k,l,old_type;
<a name="l439"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;table_size;i++)
<a name="l440"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,i</span><span class=cF7>)</span><span class=cF0>)
<a name="l441"></a> </span><span class=cF1>for</span><span class=cF0> (k=0;k&lt;table_size;k++)
<a name="l442"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[k]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,k</span><span class=cF7>)</span><span class=cF0>)
<a name="l443"></a> </span><span class=cF1>for</span><span class=cF0> (l=0;l&lt;table_size;l++)
<a name="l444"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[l]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,l</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l445"></a> </span><span class=cFB>progress1</span><span class=cF0>=i;
<a name="l446"></a> j= (i | k | l) &amp; (table_size-1);
<a name="l447"></a> old_type=gate_type_table[j];
<a name="l448"></a> </span><span class=cF1>if</span><span class=cF0> (old_type&lt;GT_INPUT) {
<a name="l449"></a> gate_type_table[j]=GT_OR3;
<a name="l450"></a> input1_table[j]=i;
<a name="l451"></a> input2_table[j]=k;
<a name="l452"></a> input3_table[j]=l;
<a name="l453"></a> </span><span class=cF5>Bts</span><span class=cF0>(added_this_pass,j);
<a name="l454"></a> *chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l455"></a> </span><span class=cF1>if</span><span class=cF0> (old_type==GT_OUTPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l456"></a> </span><span class=cF1>if</span><span class=cF0> (output_found&lt;0) output_found=j;
<a name="l457"></a> *num_outputs_found=*num_outputs_found+1;
<a name="l458"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l459"></a> }
<a name="l460"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l461"></a>}
<a name="l462"></a>
<a name="l463"></a></span><span class=cF1>U0</span><span class=cF0> FillNAnd3(</span><span class=cF1>Bool</span><span class=cF0> *chged,</span><span class=cF9>I64</span><span class=cF0> *num_outputs_found)
<a name="l464"></a>{
<a name="l465"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,k,l,old_type;
<a name="l466"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;table_size;i++)
<a name="l467"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,i</span><span class=cF7>)</span><span class=cF0>)
<a name="l468"></a> </span><span class=cF1>for</span><span class=cF0> (k=0;k&lt;table_size;k++)
<a name="l469"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[k]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,k</span><span class=cF7>)</span><span class=cF0>)
<a name="l470"></a> </span><span class=cF1>for</span><span class=cF0> (l=0;l&lt;table_size;l++)
<a name="l471"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[l]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,l</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l472"></a> </span><span class=cFB>progress1</span><span class=cF0>=i;
<a name="l473"></a> j= (~</span><span class=cF7>(</span><span class=cF0>i &amp; k &amp; l</span><span class=cF7>)</span><span class=cF0>) &amp; (table_size-1);
<a name="l474"></a> old_type=gate_type_table[j];
<a name="l475"></a> </span><span class=cF1>if</span><span class=cF0> (old_type&lt;GT_INPUT) {
<a name="l476"></a> gate_type_table[j]=GT_NAND3;
<a name="l477"></a> input1_table[j]=i;
<a name="l478"></a> input2_table[j]=k;
<a name="l479"></a> input3_table[j]=l;
<a name="l480"></a> </span><span class=cF5>Bts</span><span class=cF0>(added_this_pass,j);
<a name="l481"></a> *chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l482"></a> </span><span class=cF1>if</span><span class=cF0> (old_type==GT_OUTPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l483"></a> </span><span class=cF1>if</span><span class=cF0> (output_found&lt;0) output_found=j;
<a name="l484"></a> *num_outputs_found=*num_outputs_found+1;
<a name="l485"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l486"></a> }
<a name="l487"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l488"></a>}
<a name="l489"></a>
<a name="l490"></a></span><span class=cF1>U0</span><span class=cF0> FillNOr3(</span><span class=cF1>Bool</span><span class=cF0> *chged,</span><span class=cF9>I64</span><span class=cF0> *num_outputs_found)
<a name="l491"></a>{
<a name="l492"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,k,l,old_type;
<a name="l493"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;table_size;i++)
<a name="l494"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[i]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,i</span><span class=cF7>)</span><span class=cF0>)
<a name="l495"></a> </span><span class=cF1>for</span><span class=cF0> (k=0;k&lt;table_size;k++)
<a name="l496"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[k]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,k</span><span class=cF7>)</span><span class=cF0>)
<a name="l497"></a> </span><span class=cF1>for</span><span class=cF0> (l=0;l&lt;table_size;l++)
<a name="l498"></a> </span><span class=cF1>if</span><span class=cF0> (gate_type_table[l]&gt;GT_OUTPUT &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>added_this_pass,l</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l499"></a> </span><span class=cFB>progress1</span><span class=cF0>=i;
<a name="l500"></a> j= (~</span><span class=cF7>(</span><span class=cF0>i | k | l</span><span class=cF7>)</span><span class=cF0>) &amp; (table_size-1);
<a name="l501"></a> old_type=gate_type_table[j];
<a name="l502"></a> </span><span class=cF1>if</span><span class=cF0> (old_type&lt;GT_INPUT) {
<a name="l503"></a> gate_type_table[j]=GT_NOR3;
<a name="l504"></a> input1_table[j]=i;
<a name="l505"></a> input2_table[j]=k;
<a name="l506"></a> input3_table[j]=l;
<a name="l507"></a> </span><span class=cF5>Bts</span><span class=cF0>(added_this_pass,j);
<a name="l508"></a> *chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l509"></a> </span><span class=cF1>if</span><span class=cF0> (old_type==GT_OUTPUT) </span><span class=cF7>{</span><span class=cF0>
<a name="l510"></a> </span><span class=cF1>if</span><span class=cF0> (output_found&lt;0) output_found=j;
<a name="l511"></a> *num_outputs_found=*num_outputs_found+1;
<a name="l512"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l513"></a> }
<a name="l514"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l515"></a>}
<a name="l516"></a>
<a name="l517"></a></span><span class=cF9>I64</span><span class=cF0> FillGateTable()
<a name="l518"></a>{
<a name="l519"></a> </span><span class=cF9>I64</span><span class=cF0> current_gate,num_outputs_found=0;
<a name="l520"></a> </span><span class=cF1>Bool</span><span class=cF0> chged=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l521"></a> passes=1;
<a name="l522"></a> output_found=-1;
<a name="l523"></a> </span><span class=cF5>ProgressBarsRst</span><span class=cF0>;
<a name="l524"></a> </span><span class=cFB>progress1_max</span><span class=cF0>=table_size;
<a name="l525"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l526"></a> </span><span class=cF1>while</span><span class=cF0> (num_outputs_found&lt;num_outputs_entered &amp;&amp; chged) </span><span class=cF7>{</span><span class=cF0>
<a name="l527"></a> </span><span class=cF6>&quot;Pass : %d\n&quot;</span><span class=cF0>,passes++;
<a name="l528"></a> chged=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l529"></a> </span><span class=cF5>MemSet</span><span class=cF0>(added_this_pass,0,</span><span class=cF7>(</span><span class=cF0>table_size+7</span><span class=cF7>)</span><span class=cF0>/8);
<a name="l530"></a> </span><span class=cF1>for</span><span class=cF0> (current_gate=0;current_gate&lt;num_sel_gates &amp;&amp;
<a name="l531"></a> num_outputs_found&lt;num_outputs_entered;current_gate++) {
<a name="l532"></a> </span><span class=cF1>switch</span><span class=cF0> (sel_gates[current_gate]) </span><span class=cF7>{</span><span class=cF0>
<a name="l533"></a> </span><span class=cF1>case</span><span class=cF0> GT_NOT: FillNot (&amp;chged,&amp;num_outputs_found); </span><span class=cF1>break</span><span class=cF0>;
<a name="l534"></a> </span><span class=cF1>case</span><span class=cF0> GT_AND: FillAnd (&amp;chged,&amp;num_outputs_found); </span><span class=cF1>break</span><span class=cF0>;
<a name="l535"></a> </span><span class=cF1>case</span><span class=cF0> GT_OR: FillOr (&amp;chged,&amp;num_outputs_found); </span><span class=cF1>break</span><span class=cF0>;
<a name="l536"></a> </span><span class=cF1>case</span><span class=cF0> GT_NAND: FillNAnd (&amp;chged,&amp;num_outputs_found); </span><span class=cF1>break</span><span class=cF0>;
<a name="l537"></a> </span><span class=cF1>case</span><span class=cF0> GT_NOR: FillNOr (&amp;chged,&amp;num_outputs_found); </span><span class=cF1>break</span><span class=cF0>;
<a name="l538"></a> </span><span class=cF1>case</span><span class=cF0> GT_XOR: FillXor (&amp;chged,&amp;num_outputs_found); </span><span class=cF1>break</span><span class=cF0>;
<a name="l539"></a> </span><span class=cF1>case</span><span class=cF0> GT_AND3: FillAnd3 (&amp;chged,&amp;num_outputs_found); </span><span class=cF1>break</span><span class=cF0>;
<a name="l540"></a> </span><span class=cF1>case</span><span class=cF0> GT_OR3: FillOr3 (&amp;chged,&amp;num_outputs_found); </span><span class=cF1>break</span><span class=cF0>;
<a name="l541"></a> </span><span class=cF1>case</span><span class=cF0> GT_NAND3: FillNAnd3(&amp;chged,&amp;num_outputs_found); </span><span class=cF1>break</span><span class=cF0>;
<a name="l542"></a> </span><span class=cF1>case</span><span class=cF0> GT_NOR3: FillNOr3 (&amp;chged,&amp;num_outputs_found); </span><span class=cF1>break</span><span class=cF0>;
<a name="l543"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l544"></a> }
<a name="l545"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l546"></a> </span><span class=cF5>ProgressBarsRst</span><span class=cF0>;
<a name="l547"></a> </span><span class=cF1>return</span><span class=cF0> num_outputs_found;
<a name="l548"></a>}
<a name="l549"></a>
<a name="l550"></a></span><span class=cF1>U0</span><span class=cF0> CleanUp()
<a name="l551"></a>{
<a name="l552"></a> </span><span class=cF5>Free</span><span class=cF0>(gate_type_table);
<a name="l553"></a> </span><span class=cF5>Free</span><span class=cF0>(displayed_design);
<a name="l554"></a> </span><span class=cF5>Free</span><span class=cF0>(added_this_pass);
<a name="l555"></a> </span><span class=cF5>Free</span><span class=cF0>(input1_table);
<a name="l556"></a> </span><span class=cF5>Free</span><span class=cF0>(input2_table);
<a name="l557"></a> </span><span class=cF5>Free</span><span class=cF0>(input3_table);
<a name="l558"></a>}
<a name="l559"></a>
<a name="l560"></a></span><span class=cF1>U0</span><span class=cF0> DigitalLogic()
<a name="l561"></a>{
<a name="l562"></a> gate_type_table =</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l563"></a> displayed_design=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l564"></a> added_this_pass =</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l565"></a> input1_table =</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l566"></a> input2_table =</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l567"></a> input3_table =</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l568"></a>
<a name="l569"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="/Wb/Adam/TaskSettings.HC.HTML#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l570"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l571"></a> </span><span class=cF5>WinBorder</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l572"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l573"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l574"></a> GetGates;
<a name="l575"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l576"></a> Init;
<a name="l577"></a> </span><span class=cF1>if</span><span class=cF0> (FillGateTable) {
<a name="l578"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l579"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l580"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;draw_it=&amp;</span><span class=cF5>DrawIt</span><span class=cF0>;
<a name="l581"></a> </span><span class=cF5>GetChar</span><span class=cF0>;
<a name="l582"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l583"></a> </span><span class=cF5>Refresh</span><span class=cF0>(2,</span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l584"></a> </span><span class=cF5>DocBottom</span><span class=cF0>;
<a name="l585"></a> }
<a name="l586"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l587"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l588"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l589"></a> CleanUp;
<a name="l590"></a>}
</span></pre></body>
</html>