templeos-info/public/Wb/Kernel/KMisc.HC.HTML

358 lines
35 KiB
Plaintext
Raw Normal View History

2024-03-24 21:24:44 +00:00
<!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=cF1>U0</span><span class=cF0> </span><span class=cF5>PortNop</span><span class=cF0>()
<a name="l2"></a>{</span><span class=cF2>//Innoculous (reads IRQ Mask) which should take fixed time</span><span class=cF0>
<a name="l3"></a></span><span class=cF2>//because it's an ISA-bus standard. It takes 1.0uS-2.0uS.</span><span class=cF0>
<a name="l4"></a> </span><span class=cF5>InU8</span><span class=cF0>(0x21);
<a name="l5"></a>}
<a name="l6"></a>
<a name="l7"></a></span><span class=cF9>U16</span><span class=cF0> </span><span class=cF5>EndianU16</span><span class=cF0>(</span><span class=cF9>U16</span><span class=cF0> d)
<a name="l8"></a>{</span><span class=cF2>//Swap big&lt;--&gt;little endian.</span><span class=cF0>
<a name="l9"></a> </span><span class=cF9>I64</span><span class=cF0> res=0;
<a name="l10"></a> res.u8[1]=d.u8[0];
<a name="l11"></a> res.u8[0]=d.u8[1];
<a name="l12"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l13"></a>}
<a name="l14"></a>
<a name="l15"></a></span><span class=cF9>U32</span><span class=cF0> </span><span class=cF5>EndianU32</span><span class=cF0>(</span><span class=cF9>U32</span><span class=cF0> d)
<a name="l16"></a>{</span><span class=cF2>//Swap big&lt;--&gt;little endian.</span><span class=cF0>
<a name="l17"></a> </span><span class=cF9>I64</span><span class=cF0> res=0;
<a name="l18"></a> res.u8[3]=d.u8[0];
<a name="l19"></a> res.u8[2]=d.u8[1];
<a name="l20"></a> res.u8[1]=d.u8[2];
<a name="l21"></a> res.u8[0]=d.u8[3];
<a name="l22"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l23"></a>}
<a name="l24"></a>
<a name="l25"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>EndianI64</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> d)
<a name="l26"></a>{</span><span class=cF2>//Swap big&lt;--&gt;little endian.</span><span class=cF0>
<a name="l27"></a> </span><span class=cF9>U64</span><span class=cF0> res;
<a name="l28"></a> res.u8[7]=d.u8[0];
<a name="l29"></a> res.u8[6]=d.u8[1];
<a name="l30"></a> res.u8[5]=d.u8[2];
<a name="l31"></a> res.u8[4]=d.u8[3];
<a name="l32"></a> res.u8[3]=d.u8[4];
<a name="l33"></a> res.u8[2]=d.u8[5];
<a name="l34"></a> res.u8[1]=d.u8[6];
<a name="l35"></a> res.u8[0]=d.u8[7];
<a name="l36"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l37"></a>}
<a name="l38"></a>
<a name="l39"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>BCnt</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> d)
<a name="l40"></a>{</span><span class=cF2>//Count set bits in I64.</span><span class=cF0>
<a name="l41"></a> </span><span class=cF9>I64</span><span class=cF0> res=0,i;
<a name="l42"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;8;i++)
<a name="l43"></a> res+=</span><span class=cFB>set_bits_table</span><span class=cF0>[d.u8[i]];
<a name="l44"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l45"></a>}
<a name="l46"></a>
<a name="l47"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>IntCore0TimerHndlr</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *)
<a name="l48"></a>{</span><span class=cF2>//Called from </span><a href="/Wb/Kernel/KInts.HC.HTML#l55"><span class=cF4>IntCore0TimerHndlr</span></a><span class=cF0>
<a name="l49"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mp_cnt</span><span class=cF0>&gt;1)
<a name="l51"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SYS_TIMER</span><span class=cF0>],0</span><span class=cF7>)</span><span class=cF0>)
<a name="l52"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l53"></a> </span><span class=cF1>lock</span><span class=cF0> </span><span class=cFB>cnts</span><span class=cF0>.jiffies++;
<a name="l54"></a> </span><span class=cFB>cnts</span><span class=cF0>.timer+=</span><span class=cF3>SYS_TIMER0_PERIOD</span><span class=cF0>+1;
<a name="l55"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SYS_TIMER</span><span class=cF0>],0);
<a name="l56"></a> </span><span class=cF1>for</span><span class=cF0> (i=1;i&lt;</span><span class=cFB>mp_cnt</span><span class=cF0>;i++)
<a name="l57"></a> </span><span class=cF5>MPInt</span><span class=cF0>(</span><span class=cF3>I_TIMER</span><span class=cF0>,i);
<a name="l58"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x20,0x20); </span><span class=cF2>//Acknowledge PIC Interrupt</span><span class=cF0>
<a name="l59"></a>}
<a name="l60"></a>
<a name="l61"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>SysTimerRead</span><span class=cF0>()
<a name="l62"></a>{</span><span class=cF2>//System timer count with overflow already handled.</span><span class=cF0>
<a name="l63"></a> </span><span class=cF9>I64</span><span class=cF0> i,res;
<a name="l64"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l65"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l66"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mp_cnt</span><span class=cF0>&gt;1)
<a name="l67"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SYS_TIMER</span><span class=cF0>],0</span><span class=cF7>)</span><span class=cF0>)
<a name="l68"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l69"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x43,0); </span><span class=cF2>//Latch Timer0</span><span class=cF0>
<a name="l70"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>i=</span><span class=cF5>InU8</span><span class=cF0>(0x40)+</span><span class=cF5>InU8</span><span class=cF0>(0x40)&lt;&lt;8</span><span class=cF7>)</span><span class=cF0>==</span><span class=cF3>SYS_TIMER0_PERIOD</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l71"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>0x20</span><span class=cF7>)</span><span class=cF0> &amp; 1)
<a name="l72"></a> i=-1;
<a name="l73"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l74"></a> res=</span><span class=cFB>cnts</span><span class=cF0>.timer+</span><span class=cF3>SYS_TIMER0_PERIOD</span><span class=cF0>-i;
<a name="l75"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SYS_TIMER</span><span class=cF0>],0);
<a name="l76"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l77"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l78"></a>}
<a name="l79"></a>
<a name="l80"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>HPET</span><span class=cF0>()
<a name="l81"></a>{ </span><span class=cF2>//Get high precision event timer.</span><span class=cF0>
<a name="l82"></a> </span><span class=cF1>return</span><span class=cF0> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>HPET_MAIN_CNT</span><span class=cF0>)(</span><span class=cF9>I64</span><span class=cF0> *);
<a name="l83"></a>}
<a name="l84"></a>
<a name="l85"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>TimeCal</span><span class=cF0>()
<a name="l86"></a>{
<a name="l87"></a> </span><span class=cF1>static</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> time_stamp_start=0,timer_start=0,HPET_start=0;
<a name="l88"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l89"></a> </span><span class=cF1>if</span><span class=cF0> (time_stamp_start) </span><span class=cF7>{</span><span class=cF0>
<a name="l90"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l91"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l92"></a> </span><span class=cF1>if</span><span class=cF0> (HPET_start) {
<a name="l93"></a> </span><span class=cFB>cnts</span><span class=cF0>.time_stamp_freq=</span><span class=cFB>cnts</span><span class=cF0>.HPET_freq*(</span><span class=cF5>GetTSC</span><span class=cF0>-time_stamp_start);
<a name="l94"></a> i=</span><span class=cF5>HPET</span><span class=cF0>-HPET_start;
<a name="l95"></a> } </span><span class=cF1>else</span><span class=cF0> {
<a name="l96"></a> </span><span class=cFB>cnts</span><span class=cF0>.time_stamp_freq=</span><span class=cF3>SYS_TIMER_FREQ</span><span class=cF0>*(</span><span class=cF5>GetTSC</span><span class=cF0>-time_stamp_start);
<a name="l97"></a> i=</span><span class=cF5>SysTimerRead</span><span class=cF0>-timer_start;
<a name="l98"></a> }
<a name="l99"></a> </span><span class=cF1>if</span><span class=cF0> (!i)
<a name="l100"></a> </span><span class=cF5>AdamErr</span><span class=cF0>(</span><span class=cF6>&quot;Timer Cal Error&quot;</span><span class=cF0>);
<a name="l101"></a> </span><span class=cF1>else</span><span class=cF0> {
<a name="l102"></a> </span><span class=cFB>cnts</span><span class=cF0>.time_stamp_freq/=i;
<a name="l103"></a> </span><span class=cFB>cnts</span><span class=cF0>.time_stamp_kHz_freq=</span><span class=cFB>cnts</span><span class=cF0>.time_stamp_freq/1000;
<a name="l104"></a> </span><span class=cFB>cnts</span><span class=cF0>.time_stamp_calibrated=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l105"></a> }
<a name="l106"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l107"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l108"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l109"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l110"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>cnts</span><span class=cF0>.HPET_freq) </span><span class=cF7>{</span><span class=cF0>
<a name="l111"></a> timer_start=0;
<a name="l112"></a> HPET_start=</span><span class=cF5>HPET</span><span class=cF0>;
<a name="l113"></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="l114"></a> timer_start=</span><span class=cF5>SysTimerRead</span><span class=cF0>;
<a name="l115"></a> HPET_start=0;
<a name="l116"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l117"></a> time_stamp_start=</span><span class=cF5>GetTSC</span><span class=cF0>;
<a name="l118"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l119"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFB>cnts</span><span class=cF0>.time_stamp_freq;
<a name="l120"></a>}
<a name="l121"></a>
<a name="l122"></a></span><span class=cF1>F64</span><span class=cF0> </span><span class=cF5>tS</span><span class=cF0>()
<a name="l123"></a>{</span><span class=cF2>//Time since boot in seconds as a float.</span><span class=cF0>
<a name="l124"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>cnts</span><span class=cF0>.HPET_freq)
<a name="l125"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ToF64</span><span class=cF0>(</span><span class=cF5>HPET</span><span class=cF0>-</span><span class=cFB>cnts</span><span class=cF0>.HPET_initial)/</span><span class=cFB>cnts</span><span class=cF0>.HPET_freq;
<a name="l126"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l127"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>SysTimerRead</span><span class=cF0>/</span><span class=cF5>ToF64</span><span class=cF0>(</span><span class=cF3>SYS_TIMER_FREQ</span><span class=cF0>);
<a name="l128"></a>}
<a name="l129"></a>
<a name="l130"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>Blink</span><span class=cF0>(</span><span class=cF1>F64</span><span class=cF0> Hz=2.5)
<a name="l131"></a>{</span><span class=cF2>//Return TRUE, then FALSE, then TRUE at given frequency.</span><span class=cF0>
<a name="l132"></a> </span><span class=cF1>if</span><span class=cF0> (!Hz) </span><span class=cF1>return</span><span class=cF0> 0;
<a name="l133"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ToI64</span><span class=cF0>(</span><span class=cFB>cnts</span><span class=cF0>.jiffies*2*Hz/</span><span class=cF3>JIFFY_FREQ</span><span class=cF0>)&amp;1;
<a name="l134"></a>}
<a name="l135"></a>
<a name="l136"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Busy</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> uS)
<a name="l137"></a>{</span><span class=cF2>//Loosely timed.</span><span class=cF0>
<a name="l138"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l139"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>cnts</span><span class=cF0>.HPET_freq) </span><span class=cF7>{</span><span class=cF0>
<a name="l140"></a> i=</span><span class=cF5>HPET</span><span class=cF0>+</span><span class=cFB>cnts</span><span class=cF0>.HPET_freq*uS/1000000;
<a name="l141"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>HPET</span><span class=cF0>&lt;i);
<a name="l142"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l143"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;uS;i++)
<a name="l144"></a> </span><span class=cF5>PortNop</span><span class=cF0>;
<a name="l145"></a>}
<a name="l146"></a>
<a name="l147"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>SleepUntil</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> wake_jiffy)
<a name="l148"></a>{</span><span class=cF2>//Not for power-saving. It is to make a program pause without hogging the CPU.</span><span class=cF0>
<a name="l149"></a> </span><span class=cF1>Bool</span><span class=cF0> old_idle=</span><span class=cF5>LBts</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags,</span><span class=cF3>TASKf_IDLE</span><span class=cF0>);
<a name="l150"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;wake_jiffy=wake_jiffy;
<a name="l151"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l152"></a> </span><span class=cF5>LBEqu</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags,</span><span class=cF3>TASKf_IDLE</span><span class=cF0>,old_idle);
<a name="l153"></a>}
<a name="l154"></a>
<a name="l155"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> mS)
<a name="l156"></a>{</span><span class=cF2>//Not for power-saving. It is to make a program pause without hogging the CPU.</span><span class=cF0>
<a name="l157"></a> </span><span class=cF1>if</span><span class=cF0> (!mS)
<a name="l158"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l159"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l160"></a> </span><span class=cF5>SleepUntil</span><span class=cF0>(</span><span class=cFB>cnts</span><span class=cF0>.jiffies+mS*</span><span class=cF3>JIFFY_FREQ</span><span class=cF0>/1000);
<a name="l161"></a>}
<a name="l162"></a>
<a name="l163"></a></span><span class=cF1>F64</span><span class=cF0> </span><span class=cF5>Ona2Freq</span><span class=cF0>(</span><span class=cF1>I8</span><span class=cF0> ona)
<a name="l164"></a>{</span><span class=cF2>//Ona to freq. Ona=60 is 440.0Hz.</span><span class=cF0>
<a name="l165"></a> </span><span class=cF1>if</span><span class=cF0> (!ona)
<a name="l166"></a> </span><span class=cF1>return</span><span class=cF0> 0;
<a name="l167"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l168"></a> </span><span class=cF1>return</span><span class=cF0> 440.0/32*2.0`(ona/12.0);
<a name="l169"></a>}
<a name="l170"></a>
<a name="l171"></a></span><span class=cF1>I8</span><span class=cF0> </span><span class=cF5>Freq2Ona</span><span class=cF0>(</span><span class=cF1>F64</span><span class=cF0> freq)
<a name="l172"></a>{</span><span class=cF2>//Freq to Ona. 440.0Hz is Ona=60.</span><span class=cF0>
<a name="l173"></a> </span><span class=cF1>if</span><span class=cF0> (freq&gt;0)
<a name="l174"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ClampI64</span><span class=cF0>(12*</span><span class=cF5>Log2</span><span class=cF7>(</span><span class=cF0>32.0/440.0*freq</span><span class=cF7>)</span><span class=cF0>,1,</span><span class=cF3>I8_MAX</span><span class=cF0>);
<a name="l175"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l176"></a> </span><span class=cF1>return</span><span class=cF0> 0;
<a name="l177"></a>}
<a name="l178"></a>
<a name="l179"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Snd</span><span class=cF0>(</span><span class=cF1>I8</span><span class=cF0> ona=0)
<a name="l180"></a>{</span><span class=cF2>//Play ona, a piano key num. 0 means rest.</span><span class=cF0>
<a name="l181"></a> </span><span class=cF9>I64</span><span class=cF0> period;
<a name="l182"></a> </span><span class=cF9>CSndData</span><span class=cF0> *d;
<a name="l183"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_MUTE</span><span class=cF0>],0</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l184"></a> !</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SND</span><span class=cF0>],0</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>//Mutex. Just throw-out if in use</span><span class=cF0>
<a name="l185"></a> </span><span class=cF1>if</span><span class=cF0> (!ona) {
<a name="l186"></a> </span><span class=cFB>scrncast</span><span class=cF0>.ona=ona;
<a name="l187"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x61,</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>0x61</span><span class=cF7>)</span><span class=cF0>&amp;~3);
<a name="l188"></a> } </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (ona!=</span><span class=cFB>scrncast</span><span class=cF0>.ona) {
<a name="l189"></a> </span><span class=cFB>scrncast</span><span class=cF0>.ona=ona;
<a name="l190"></a> period=</span><span class=cF5>ClampI64</span><span class=cF0>(</span><span class=cF3>SYS_TIMER_FREQ</span><span class=cF0>/</span><span class=cF5>Ona2Freq</span><span class=cF7>(</span><span class=cF0>ona</span><span class=cF7>)</span><span class=cF0>,1,</span><span class=cF3>U16_MAX</span><span class=cF0>);
<a name="l191"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x43,0xB6);
<a name="l192"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x42,period);
<a name="l193"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x42,period.u8[1]);
<a name="l194"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x61,3|</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>0x61</span><span class=cF7>)</span><span class=cF0>);
<a name="l195"></a> }
<a name="l196"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>IsDbgMode</span><span class=cF0> &amp;&amp; </span><span class=cFB>scrncast</span><span class=cF0>.record) {
<a name="l197"></a> d=</span><span class=cF5>ACAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CSndData</span><span class=cF7>)</span><span class=cF0>);
<a name="l198"></a> d-&gt;ona=ona;
<a name="l199"></a> d-&gt;</span><span class=cF5>tS</span><span class=cF0>=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l200"></a> </span><span class=cF5>QueIns</span><span class=cF0>(d,</span><span class=cFB>scrncast</span><span class=cF0>.snd_head.last);
<a name="l201"></a> }
<a name="l202"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SND</span><span class=cF0>],0);
<a name="l203"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l204"></a>}
<a name="l205"></a>
<a name="l206"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>ScrnCast</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> val=</span><span class=cF3>ON</span><span class=cF0>,</span><span class=cF1>Bool</span><span class=cF0> just_audio=</span><span class=cF3>FALSE</span><span class=cF0>,</span><span class=cF1>U8</span><span class=cF0> *print_fmt=</span><span class=cF6>&quot;B:/Tmp/%X.GR&quot;</span><span class=cF0>)
<a name="l207"></a>{</span><span class=cF2>//WinMgr saves GR files to a dir.</span><span class=cF0>
<a name="l208"></a> </span><span class=cF1>Bool</span><span class=cF0> old_val;
<a name="l209"></a> </span><span class=cFB>scrncast</span><span class=cF0>.just_audio=just_audio;
<a name="l210"></a> </span><span class=cF1>if</span><span class=cF0> (val) </span><span class=cF7>{</span><span class=cF0>
<a name="l211"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>old_val=</span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>scrncast</span><span class=cF0>.record,0)</span><span class=cF7>)</span><span class=cF0>) {
<a name="l212"></a> </span><span class=cF5>Free</span><span class=cF0>(</span><span class=cFB>scrncast</span><span class=cF0>.print_fmt);
<a name="l213"></a> </span><span class=cFB>scrncast</span><span class=cF0>.print_fmt=</span><span class=cF5>AStrNew</span><span class=cF0>(print_fmt);
<a name="l214"></a> </span><span class=cFB>scrncast</span><span class=cF0>.t0_now=</span><span class=cF5>Now</span><span class=cF0>;
<a name="l215"></a> </span><span class=cFB>scrncast</span><span class=cF0>.snd_head.</span><span class=cF5>tS</span><span class=cF0>=</span><span class=cFB>scrncast</span><span class=cF0>.t0_tS=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l216"></a> </span><span class=cFB>scrncast</span><span class=cF0>.snd_head.ona=</span><span class=cFB>scrncast</span><span class=cF0>.ona;
<a name="l217"></a> </span><span class=cF5>LBts</span><span class=cF0>(&amp;</span><span class=cFB>scrncast</span><span class=cF0>.record,0);
<a name="l218"></a> }
<a name="l219"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l220"></a> old_val=</span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>scrncast</span><span class=cF0>.record,0);
<a name="l221"></a> </span><span class=cF5>Snd</span><span class=cF0>;
<a name="l222"></a> </span><span class=cF1>return</span><span class=cF0> old_val;
<a name="l223"></a>}
<a name="l224"></a>
<a name="l225"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>SndRst</span><span class=cF0>()
<a name="l226"></a>{</span><span class=cF2>//Fix stuck sound.</span><span class=cF0>
<a name="l227"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SND</span><span class=cF0>],0</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l228"></a> </span><span class=cF5>Sleep</span><span class=cF0>(1);
<a name="l229"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SND</span><span class=cF0>],0</span><span class=cF7>)</span><span class=cF0>) {
<a name="l230"></a> </span><span class=cF5>Sleep</span><span class=cF0>(1);
<a name="l231"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SND</span><span class=cF0>],0);
<a name="l232"></a> }
<a name="l233"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l234"></a> </span><span class=cF5>Snd</span><span class=cF0>;
<a name="l235"></a>}
<a name="l236"></a>
<a name="l237"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Beep</span><span class=cF0>(</span><span class=cF1>I8</span><span class=cF0> ona=62,</span><span class=cF1>Bool</span><span class=cF0> busy=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l238"></a>{</span><span class=cF2>//Make beep at given ona freq.</span><span class=cF0>
<a name="l239"></a> </span><span class=cF5>Snd</span><span class=cF0>(ona);
<a name="l240"></a> </span><span class=cF1>if</span><span class=cF0> (busy)
<a name="l241"></a> </span><span class=cF5>Busy</span><span class=cF0>(500000);
<a name="l242"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l243"></a> </span><span class=cF5>Sleep</span><span class=cF0>(500);
<a name="l244"></a> </span><span class=cF5>Snd</span><span class=cF0>;
<a name="l245"></a> </span><span class=cF1>if</span><span class=cF0> (busy)
<a name="l246"></a> </span><span class=cF5>Busy</span><span class=cF0>(200000);
<a name="l247"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l248"></a> </span><span class=cF5>Sleep</span><span class=cF0>(200);
<a name="l249"></a>}
<a name="l250"></a>
<a name="l251"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>Mute</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> val)
<a name="l252"></a>{</span><span class=cF2>//Turn-off sound.</span><span class=cF0>
<a name="l253"></a> </span><span class=cF1>Bool</span><span class=cF0> res;
<a name="l254"></a> </span><span class=cF1>if</span><span class=cF0> (val) </span><span class=cF7>{</span><span class=cF0>
<a name="l255"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l256"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l257"></a> </span><span class=cF5>Snd</span><span class=cF0>;
<a name="l258"></a> res=</span><span class=cF5>LBts</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_MUTE</span><span class=cF0>],0);
<a name="l259"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l260"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l261"></a> res=</span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_MUTE</span><span class=cF0>],0);
<a name="l262"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l263"></a>}
<a name="l264"></a>
<a name="l265"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>IsMute</span><span class=cF0>()
<a name="l266"></a>{</span><span class=cF2>//Return is-mute flag.</span><span class=cF0>
<a name="l267"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>Bt</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_MUTE</span><span class=cF0>],0);
<a name="l268"></a>}
<a name="l269"></a>
<a name="l270"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>Silent</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> val=</span><span class=cF3>ON</span><span class=cF0>)
<a name="l271"></a>{</span><span class=cF2>//Turn-off StdOut console text. (Not sound.)</span><span class=cF0>
<a name="l272"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>LBEqu</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;display_flags,</span><span class=cF3>DISPLAYf_SILENT</span><span class=cF0>,val);
<a name="l273"></a>}
<a name="l274"></a>
<a name="l275"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>IsSilent</span><span class=cF0>()
<a name="l276"></a>{</span><span class=cF2>//Return StdOut turned-off?</span><span class=cF0>
<a name="l277"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>Bt</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;display_flags,</span><span class=cF3>DISPLAYf_SILENT</span><span class=cF0>);
<a name="l278"></a>}
<a name="l279"></a>
<a name="l280"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>SysDbg</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> val)
<a name="l281"></a>{</span><span class=cF2>//Set SysDbg bit you can use while debugging.</span><span class=cF0>
<a name="l282"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>LBEqu</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DEBUG</span><span class=cF0>],0,val);
<a name="l283"></a>}
<a name="l284"></a>
<a name="l285"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>IsSysDbg</span><span class=cF0>()
<a name="l286"></a>{</span><span class=cF2>//Return SysDbg bit.</span><span class=cF0>
<a name="l287"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>Bt</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DEBUG</span><span class=cF0>],0);
<a name="l288"></a>}
<a name="l289"></a>
<a name="l290"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>Raw</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> val)
<a name="l291"></a>{</span><span class=cF2>//Set to direct scrn, BLACK &amp; WHITE, non-windowed output mode.</span><span class=cF0>
<a name="l292"></a> </span><span class=cF1>if</span><span class=cF0> (!val)
<a name="l293"></a> </span><span class=cF5>VGAFlush</span><span class=cF0>;
<a name="l294"></a> </span><span class=cF1>return</span><span class=cF0> !</span><span class=cF5>LBEqu</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;display_flags,</span><span class=cF3>DISPLAYf_NOT_RAW</span><span class=cF0>,!val);
<a name="l295"></a>}
<a name="l296"></a>
<a name="l297"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>IsRaw</span><span class=cF0>()
<a name="l298"></a>{</span><span class=cF2>//Are we in BLACK &amp; WHITE raw scrn mode?</span><span class=cF0>
<a name="l299"></a> </span><span class=cF1>return</span><span class=cF0> !</span><span class=cF5>Bt</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;display_flags,</span><span class=cF3>DISPLAYf_NOT_RAW</span><span class=cF0>);
<a name="l300"></a>}
<a name="l301"></a>
<a name="l302"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>SingleUser</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> val)
<a name="l303"></a>{</span><span class=cF2>//Set single-user mode.</span><span class=cF0>
<a name="l304"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>LBEqu</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SINGLE_USER</span><span class=cF0>],0,val);
<a name="l305"></a>}
<a name="l306"></a>
<a name="l307"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>IsSingleUser</span><span class=cF0>()
<a name="l308"></a>{</span><span class=cF2>//Return single-user mode.</span><span class=cF0>
<a name="l309"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>Bt</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_SINGLE_USER</span><span class=cF0>],0);
<a name="l310"></a>}
<a name="l311"></a>
<a name="l312"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>DbgMode</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> val)
<a name="l313"></a>{</span><span class=cF2>//Set dbg-mode.</span><span class=cF0>
<a name="l314"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>LBEqu</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DBG_MODE</span><span class=cF0>],0,val);
<a name="l315"></a>}
<a name="l316"></a>
<a name="l317"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>IsDbgMode</span><span class=cF0>()
<a name="l318"></a>{</span><span class=cF2>//Return dbg-mode.</span><span class=cF0>
<a name="l319"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>Bt</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DBG_MODE</span><span class=cF0>],0);
<a name="l320"></a>}
<a name="l321"></a>
<a name="l322"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>ProgressBarsRst</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *path=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l323"></a>{</span><span class=cF2>//Reset all progress bars to zero.</span><span class=cF0>
<a name="l324"></a> </span><span class=cF5>CallExtStr</span><span class=cF0>(</span><span class=cF6>&quot;ProgressBarsRegTf&quot;</span><span class=cF0>,path);
<a name="l325"></a> </span><span class=cF5>MemSet</span><span class=cF0>(</span><span class=cFB>sys_progresses</span><span class=cF0>,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cFB>sys_progresses</span><span class=cF7>)</span><span class=cF0>);
<a name="l326"></a>}
</span></pre></body>
</html>