ZealOS/docs/Demo/Sound/MorseCode.CC.html
TomAwezome dbf8647d59 Fixed non-writable drive throw on F5 and Ctrl-S.
Added top & right borders to RawDr.
Improved spacing in some debug and compiler reporting.
Fixed RawPutChar and EdLite tab width.
Fixed Ui missing '0x' prefix syntax highlighter bug.
Added 32BitPaint demo.
2021-07-14 18:38:02 -04:00

226 lines
18 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.08">
<style type="text/css">
body {background-color:#000000;}
.cF0{color:#ffffff;background-color:#000000;}
.cF1{color:#3465a4;background-color:#000000;}
.cF2{color:#4e9a06;background-color:#000000;}
.cF3{color:#06989a;background-color:#000000;}
.cF4{color:#a24444;background-color:#000000;}
.cF5{color:#75507b;background-color:#000000;}
.cF6{color:#ce982f;background-color:#000000;}
.cF7{color:#bcc0b9;background-color:#000000;}
.cF8{color:#555753;background-color:#000000;}
.cF9{color:#729fcf;background-color:#000000;}
.cFA{color:#82bc49;background-color:#000000;}
.cFB{color:#34e2e2;background-color:#000000;}
.cFC{color:#ac3535;background-color:#000000;}
.cFD{color:#ad7fa8;background-color:#000000;}
.cFE{color:#fce94f;background-color:#000000;}
.cFF{color:#000000;background-color:#000000;}
</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> M_DASH_THRESHOLD </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>140</span><span class=cF0>
<a name="l2"></a>#</span><span class=cF1>define</span><span class=cF0> M_SPACE_THRESHOLD </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>300</span><span class=cF0>
<a name="l3"></a>
<a name="l4"></a></span><span class=cF1>U8</span><span class=cF0> *morse_list =
<a name="l5"></a></span><span class=cF6>&quot;A.-\0&quot;</span><span class=cF0>
<a name="l6"></a></span><span class=cF6>&quot;B-...\0&quot;</span><span class=cF0>
<a name="l7"></a></span><span class=cF6>&quot;C-.-.\0&quot;</span><span class=cF0>
<a name="l8"></a></span><span class=cF6>&quot;D-..\0&quot;</span><span class=cF0>
<a name="l9"></a></span><span class=cF6>&quot;E.\0&quot;</span><span class=cF0>
<a name="l10"></a></span><span class=cF6>&quot;F..-.\0&quot;</span><span class=cF0>
<a name="l11"></a></span><span class=cF6>&quot;G--.\0&quot;</span><span class=cF0>
<a name="l12"></a></span><span class=cF6>&quot;H....\0&quot;</span><span class=cF0>
<a name="l13"></a></span><span class=cF6>&quot;I..\0&quot;</span><span class=cF0>
<a name="l14"></a></span><span class=cF6>&quot;J.---\0&quot;</span><span class=cF0>
<a name="l15"></a></span><span class=cF6>&quot;K-.-\0&quot;</span><span class=cF0>
<a name="l16"></a></span><span class=cF6>&quot;L.-..\0&quot;</span><span class=cF0>
<a name="l17"></a></span><span class=cF6>&quot;M--\0&quot;</span><span class=cF0>
<a name="l18"></a></span><span class=cF6>&quot;N-.\0&quot;</span><span class=cF0>
<a name="l19"></a></span><span class=cF6>&quot;O---\0&quot;</span><span class=cF0>
<a name="l20"></a></span><span class=cF6>&quot;P.--.\0&quot;</span><span class=cF0>
<a name="l21"></a></span><span class=cF6>&quot;Q--.-\0&quot;</span><span class=cF0>
<a name="l22"></a></span><span class=cF6>&quot;R.-.\0&quot;</span><span class=cF0>
<a name="l23"></a></span><span class=cF6>&quot;S...\0&quot;</span><span class=cF0>
<a name="l24"></a></span><span class=cF6>&quot;T-\0&quot;</span><span class=cF0>
<a name="l25"></a></span><span class=cF6>&quot;U..-\0&quot;</span><span class=cF0>
<a name="l26"></a></span><span class=cF6>&quot;V...-\0&quot;</span><span class=cF0>
<a name="l27"></a></span><span class=cF6>&quot;W.--\0&quot;</span><span class=cF0>
<a name="l28"></a></span><span class=cF6>&quot;X-..-\0&quot;</span><span class=cF0>
<a name="l29"></a></span><span class=cF6>&quot;Y-.--\0&quot;</span><span class=cF0>
<a name="l30"></a></span><span class=cF6>&quot;Z--..\0&quot;</span><span class=cF0>
<a name="l31"></a>
<a name="l32"></a></span><span class=cF6>&quot;1.----\0&quot;</span><span class=cF0>
<a name="l33"></a></span><span class=cF6>&quot;2..---\0&quot;</span><span class=cF0>
<a name="l34"></a></span><span class=cF6>&quot;3...--\0&quot;</span><span class=cF0>
<a name="l35"></a></span><span class=cF6>&quot;4....-\0&quot;</span><span class=cF0>
<a name="l36"></a></span><span class=cF6>&quot;5.....\0&quot;</span><span class=cF0>
<a name="l37"></a></span><span class=cF6>&quot;6-....\0&quot;</span><span class=cF0>
<a name="l38"></a></span><span class=cF6>&quot;7--...\0&quot;</span><span class=cF0>
<a name="l39"></a></span><span class=cF6>&quot;8---..\0&quot;</span><span class=cF0>
<a name="l40"></a></span><span class=cF6>&quot;9----.\0&quot;</span><span class=cF0>
<a name="l41"></a></span><span class=cF6>&quot;0-----\0&quot;</span><span class=cF0>
<a name="l42"></a>
<a name="l43"></a></span><span class=cF6>&quot;/-..-.\0&quot;</span><span class=cF0>
<a name="l44"></a></span><span class=cF6>&quot;+.-.-.\0&quot;</span><span class=cF0>
<a name="l45"></a></span><span class=cF6>&quot;..-.-.-\0&quot;</span><span class=cF0>
<a name="l46"></a></span><span class=cF6>&quot;,--..--\0&quot;</span><span class=cF0>
<a name="l47"></a></span><span class=cF6>&quot;?..--..\0&quot;</span><span class=cF0>
<a name="l48"></a></span><span class=cF6>&quot;(-.--.\0&quot;</span><span class=cF0>
<a name="l49"></a></span><span class=cF6>&quot;)-.--.-\0&quot;</span><span class=cF0>
<a name="l50"></a></span><span class=cF6>&quot;--....-\0&quot;</span><span class=cF0>
<a name="l51"></a></span><span class=cF6>&quot;\&quot;.-..-.\0&quot;</span><span class=cF0>
<a name="l52"></a></span><span class=cF6>&quot;_..--.-\0&quot;</span><span class=cF0>
<a name="l53"></a></span><span class=cF6>&quot;'.----.\0&quot;</span><span class=cF0>
<a name="l54"></a></span><span class=cF6>&quot;:---...\0&quot;</span><span class=cF0>
<a name="l55"></a></span><span class=cF6>&quot;;-.-.-.\0&quot;</span><span class=cF0>
<a name="l56"></a></span><span class=cF6>&quot;=-...-\0&quot;</span><span class=cF0>;
<a name="l57"></a>
<a name="l58"></a></span><span class=cF1>U0</span><span class=cF0> MorseTable()
<a name="l59"></a>{
<a name="l60"></a> </span><span class=cF1>U8</span><span class=cF0> *st;
<a name="l61"></a> </span><span class=cF9>I64</span><span class=cF0> i = </span><span class=cFE>0</span><span class=cF0>;
<a name="l62"></a>
<a name="l63"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>13</span><span class=cF0>; i++ )
<a name="l64"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l65"></a> </span><span class=cF1>if</span><span class=cF0> (st = </span><span class=cF5>ListSub</span><span class=cF7>(</span><span class=cF0>i ,morse_list</span><span class=cF7>)</span><span class=cF0>)
<a name="l66"></a> </span><span class=cF6>&quot;$RED$%C$FG$ %-7s &quot;</span><span class=cF0>, *st, st + </span><span class=cFE>1</span><span class=cF0>;
<a name="l67"></a> </span><span class=cF1>if</span><span class=cF0> (st = </span><span class=cF5>ListSub</span><span class=cF7>(</span><span class=cF0>i + </span><span class=cFE>13</span><span class=cF0>, morse_list</span><span class=cF7>)</span><span class=cF0>)
<a name="l68"></a> </span><span class=cF6>&quot;$RED$%C$FG$ %-7s &quot;</span><span class=cF0>, *st, st + </span><span class=cFE>1</span><span class=cF0>;
<a name="l69"></a> </span><span class=cF1>if</span><span class=cF0> (st = </span><span class=cF5>ListSub</span><span class=cF7>(</span><span class=cF0>i + </span><span class=cFE>26</span><span class=cF0>, morse_list</span><span class=cF7>)</span><span class=cF0>)
<a name="l70"></a> </span><span class=cF6>&quot;$RED$%C$FG$ %-7s &quot;</span><span class=cF0>, *st, st + </span><span class=cFE>1</span><span class=cF0>;
<a name="l71"></a> </span><span class=cF1>if</span><span class=cF0> (st = </span><span class=cF5>ListSub</span><span class=cF7>(</span><span class=cF0>i + </span><span class=cFE>39</span><span class=cF0>, morse_list</span><span class=cF7>)</span><span class=cF0>)
<a name="l72"></a> </span><span class=cF6>&quot;$RED$%C$FG$ %-7s &quot;</span><span class=cF0>, *st, st + </span><span class=cFE>1</span><span class=cF0>;
<a name="l73"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l74"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l75"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l76"></a>}
<a name="l77"></a>
<a name="l78"></a></span><span class=cF1>F64</span><span class=cF0> m_start, m_end, dt_down, dt_up;
<a name="l79"></a></span><span class=cF1>Bool</span><span class=cF0> space_sent;
<a name="l80"></a>
<a name="l81"></a></span><span class=cF1>U8</span><span class=cF0> *MorseTimes(</span><span class=cF9>CDoc</span><span class=cF0> *, </span><span class=cF9>CDocEntry</span><span class=cF0> *, </span><span class=cF9>CTask</span><span class=cF0> *mem_task)
<a name="l82"></a>{
<a name="l83"></a> </span><span class=cF1>U8</span><span class=cF0> *st = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cFE>64</span><span class=cF0>, mem_task);
<a name="l84"></a>
<a name="l85"></a> </span><span class=cF5>StrPrint</span><span class=cF0>(st, </span><span class=cF6>&quot;Down:%10.6f Up:%10.6f&quot;</span><span class=cF0>, dt_down, dt_up);
<a name="l86"></a>
<a name="l87"></a> </span><span class=cF1>return</span><span class=cF0> st;
<a name="l88"></a>}
<a name="l89"></a>
<a name="l90"></a></span><span class=cF9>I64</span><span class=cF0> MorseWaitKey()
<a name="l91"></a>{
<a name="l92"></a> </span><span class=cF9>I64</span><span class=cF0> ch;
<a name="l93"></a> </span><span class=cF1>F64</span><span class=cF0> dt;
<a name="l94"></a>
<a name="l95"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l96"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (m_start)
<a name="l98"></a> {
<a name="l99"></a> </span><span class=cF5>MessageGet</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=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_UP</span><span class=cF0>);
<a name="l100"></a> m_end = </span><span class=cF5>tS</span><span class=cF0>;
<a name="l101"></a> </span><span class=cF5>Sound</span><span class=cF0>;
<a name="l102"></a> dt_down = m_end - m_start;
<a name="l103"></a> m_start = </span><span class=cFE>0</span><span class=cF0>;
<a name="l104"></a> space_sent = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l105"></a> </span><span class=cF1>if</span><span class=cF0> (dt_down &lt; M_DASH_THRESHOLD)
<a name="l106"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF6>'.'</span><span class=cF0>;
<a name="l107"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l108"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF6>'-'</span><span class=cF0>;
<a name="l109"></a> }
<a name="l110"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l111"></a> {
<a name="l112"></a> </span><span class=cF1>if</span><span class=cF0> (!space_sent)
<a name="l113"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l114"></a> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF5>MessageScan</span><span class=cF7>(</span><span class=cF0>&amp;ch, </span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF7>)</span><span class=cF0>)
<a name="l115"></a> {
<a name="l116"></a> dt = </span><span class=cF5>tS</span><span class=cF0> - m_end;
<a name="l117"></a> </span><span class=cF1>if</span><span class=cF0> (dt &gt;= M_SPACE_THRESHOLD)
<a name="l118"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l119"></a> space_sent = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l120"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>CH_SPACE</span><span class=cF0>;
<a name="l121"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l122"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l123"></a> }
<a name="l124"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l125"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l126"></a> ch = </span><span class=cF5>CharGet</span><span class=cF0>(, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l127"></a> m_start = </span><span class=cF5>tS</span><span class=cF0>;
<a name="l128"></a> </span><span class=cF5>Sound</span><span class=cF0>(</span><span class=cFE>74</span><span class=cF0>);
<a name="l129"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0> || ch == </span><span class=cF3>CH_ESC</span><span class=cF0>)
<a name="l130"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l131"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l132"></a> </span><span class=cF5>Sound</span><span class=cF0>;
<a name="l133"></a> </span><span class=cF5>throw</span><span class=cF0>; </span><span class=cF2>//exit program</span><span class=cF0>
<a name="l134"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l135"></a> dt_up = m_start - m_end;
<a name="l136"></a> </span><span class=cF1>if</span><span class=cF0> (!space_sent &amp;&amp; dt_up &gt;= M_SPACE_THRESHOLD)
<a name="l137"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l138"></a> space_sent = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l139"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>CH_SPACE</span><span class=cF0>;
<a name="l140"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l141"></a> }
<a name="l142"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l143"></a>}
<a name="l144"></a>
<a name="l145"></a></span><span class=cF1>U0</span><span class=cF0> Morse()
<a name="l146"></a>{
<a name="l147"></a> </span><span class=cF9>CDocEntry</span><span class=cF0> *doc_e;
<a name="l148"></a> </span><span class=cF9>I64</span><span class=cF0> ch;
<a name="l149"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cFE>8</span><span class=cF0>], *dst, *src;
<a name="l150"></a>
<a name="l151"></a> MorseTable;
<a name="l152"></a> m_start = </span><span class=cFE>0</span><span class=cF0>;
<a name="l153"></a> m_end = </span><span class=cF5>tS</span><span class=cF0>;
<a name="l154"></a> dt_down = </span><span class=cFE>0</span><span class=cF0>;
<a name="l155"></a> dt_up = </span><span class=cFE>0</span><span class=cF0>;
<a name="l156"></a> space_sent = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l157"></a>
<a name="l158"></a> </span><span class=cF6>&quot;$GREEN$&quot;</span><span class=cF0>;
<a name="l159"></a>
<a name="l160"></a> doc_e = </span><span class=cF5>DocPrint</span><span class=cF0>(</span><span class=cF5>DocPut</span><span class=cF0>, </span><span class=cF6>&quot;$TX+TC,\&quot; \&quot;$&quot;</span><span class=cF0>);
<a name="l161"></a> doc_e-&gt;tag_cb = &amp;MorseTimes;
<a name="l162"></a>
<a name="l163"></a> </span><span class=cF6>&quot;$FG$\n&quot;</span><span class=cF0>;
<a name="l164"></a>
<a name="l165"></a> dst = buf;
<a name="l166"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l167"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l168"></a> ch = MorseWaitKey;
<a name="l169"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF3>CH_SPACE</span><span class=cF0>)
<a name="l170"></a> {
<a name="l171"></a> *dst = </span><span class=cFE>0</span><span class=cF0>;
<a name="l172"></a> src = morse_list;
<a name="l173"></a> </span><span class=cF1>while</span><span class=cF0> (*src) </span><span class=cF7>{</span><span class=cF0>
<a name="l174"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>src + </span><span class=cFE>1</span><span class=cF0>, buf</span><span class=cF7>)</span><span class=cF0>)
<a name="l175"></a> {
<a name="l176"></a> </span><span class=cF6>&quot;$GREEN$%C$FG$&quot;</span><span class=cF0>, *src;
<a name="l177"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l178"></a> }
<a name="l179"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l180"></a> src += </span><span class=cF5>StrLen</span><span class=cF0>(src) + </span><span class=cFE>1</span><span class=cF0>;
<a name="l181"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l182"></a> </span><span class=cF6>''</span><span class=cF0> </span><span class=cF3>CH_SPACE</span><span class=cF0>;
<a name="l183"></a> dst = buf;
<a name="l184"></a> }
<a name="l185"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l186"></a> {
<a name="l187"></a> </span><span class=cF1>if</span><span class=cF0> (dst - buf &lt; </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>buf</span><span class=cF7>)</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>)
<a name="l188"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l189"></a> </span><span class=cF6>''</span><span class=cF0> ch;
<a name="l190"></a> *dst++ = ch;
<a name="l191"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l192"></a> }
<a name="l193"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l194"></a> </span><span class=cF5>Sound</span><span class=cF0>;
<a name="l195"></a>}
<a name="l196"></a>
<a name="l197"></a>Morse;
</span></pre></body>
</html>