Update documentation.

This commit is contained in:
TomAwezome 2021-11-29 23:50:05 -05:00
parent 262bd0249e
commit 406e31cfb6
28 changed files with 3450 additions and 2434 deletions

View file

@ -36,7 +36,7 @@ body {background-color:#1f1f1f;}
<a name="l9"></a> </span><span class=cF5>WinToTop</span><span class=cF0>;
<a name="l10"></a> </span><span class=cF5>WinZBufUpdate</span><span class=cF0>;
<a name="l11"></a> </span><span class=cF5>Dir</span><span class=cF0>;
<a name="l12"></a> </span><span class=cF6>&quot;\n95,264 LOC, &quot;</span><span class=cF0>;
<a name="l12"></a> </span><span class=cF6>&quot;\n95,267 LOC, &quot;</span><span class=cF0>;
<a name="l13"></a> </span><span class=cF6>&quot;%d MB RAM, &quot;</span><span class=cF0>, </span><span class=cF5>MemBIOSTotal</span><span class=cF0> / </span><span class=cFE>1024</span><span class=cF0> / </span><span class=cFE>1024</span><span class=cF0>;
<a name="l14"></a> </span><span class=cF5>CPURep</span><span class=cF0>;
<a name="l15"></a> </span><span class=cF6>&quot;\n&quot;</span><span class=cF0>;

View file

@ -38,7 +38,7 @@ body {background-color:#1f1f1f;}
<a name="l11"></a>* Low line count and code complexity is the highest good, so it is easy to learn the whole thing. Users should see the light
<a name="l12"></a>at the end of the tunnel. One file system, for example, is better than many file systems.
<a name="l13"></a>
<a name="l14"></a>* There is a limit of 100,000 lines of code for all time, not including applications and demos. Currently, there are 95,264
<a name="l14"></a>* There is a limit of 100,000 lines of code for all time, not including applications and demos. Currently, there are 95,267
<a name="l15"></a>lines of code. </span><span class=cF4>3rd party libraries are banned</span><span class=cF0> because they circumvent the intent of this limit. The vision is a Commodore 64
<a name="l16"></a>ROM -- a fixed core API that is the only dependency of applications. Dependency on components and libraries creates a hell
<a name="l17"></a>that is no longer blissful.

View file

@ -39,8 +39,8 @@ body {background-color:#1f1f1f;}
<a name="l12"></a>You can create new, independent heaps using </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/HeapCtrl.CC.html#l1"><span class=cF4>HeapCtrlInit</span></a><span class=cF0>(). Then, use the </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l3567"><span class=cF4>CHeapCtrl</span></a><span class=cF0> as the 2nd arg to </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l391"><span class=cF4>MAlloc</span></a><span class=cF0>(). See </span><a href="https://zeal-operating-system.github.io/ZealOS/System/Utils/HeapLog.CC.html#l83"><span class=cF4>HeapLog</span></a><span class=cF0>()
<a name="l13"></a>for an example.
<a name="l14"></a>
<a name="l15"></a>Memory alloced by a task will be freed when the task is killed. The </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/Glossary.DD.html#l154"><span class=cF4>System Task</span></a><span class=cF0> is a task that never dies. His memory is like
<a name="l16"></a>kernel memory in other operating systems. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l408"><span class=cF4>SysCAlloc</span></a><span class=cF0>(), </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l394"><span class=cF4>SysMAlloc</span></a><span class=cF0>(), </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l427"><span class=cF4>SysMAllocIdent</span></a><span class=cF0>() and </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l503"><span class=cF4>SysStrNew</span></a><span class=cF0>().
<a name="l15"></a>Memory alloced by a task will be freed when the task is killed. The </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/Glossary.DD.html#l154"><span class=cF4>System Task</span></a><span class=cF0> is a task that never dies. It's memory is
<a name="l16"></a>like kernel memory in other operating systems. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l408"><span class=cF4>SysCAlloc</span></a><span class=cF0>(), </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l394"><span class=cF4>SysMAlloc</span></a><span class=cF0>(), </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l427"><span class=cF4>SysMAllocIdent</span></a><span class=cF0>() and </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/Memory/MAllocFree.CC.html#l503"><span class=cF4>SysStrNew</span></a><span class=cF0>().
<a name="l17"></a>
<a name="l18"></a>All of the regular page tables are marked, &quot;cached&quot;. When accessing hardware, however, you need uncached page table. The
<a name="l19"></a>lowest 4Gig addresses have an alias to access hardware located toward the top of mapped space, </span><span class=cF2>0x01D7800000</span><span class=cF0>. See </span><span class=cF4>

View file

@ -37,7 +37,7 @@ body {background-color:#1f1f1f;}
<a name="l10"></a>
<a name="l11"></a>Simplicity is a goal to </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/Strategy.DD.html#l1"><span class=cF4>keep the line count down</span></a><span class=cF0>, so it's easy to tinker with. As it turns-out, simplicity makes it faster in
<a name="l12"></a>some ways, too. It never switches privilege levels, never changes address maps, tends to load whole contiguous files and
<a name="l13"></a>other, similar things which boost speed. It's only 95,264 lines of code including the kernel, the 64-bit compiler, the
<a name="l13"></a>other, similar things which boost speed. It's only 95,267 lines of code including the kernel, the 64-bit compiler, the
<a name="l14"></a>graphics library and all the tools. More importantly, it's designed to keep the user's line count down -- you can do a </span><span class=cF4>
<a name="l15"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/HelloWorld.DD.html#l1"><span class=cF4>Hello World</span></a><span class=cF0> application in one line of code and can put graphics on the screen with a three line program!
<a name="l16"></a>

View file

@ -64,7 +64,7 @@ body {background-color:#1f1f1f;}
<a name="l37"></a> line = </span><span class=cF5>StrPrint</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF6>&quot;%s\t%s\r\n&quot;</span><span class=cF0>, selector, query);
<a name="l38"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l39"></a>
<a name="l40"></a> sock(CTCPSocket *)-&gt;timeout = TCP_TIMEOUT * </span><span class=cFE>5</span><span class=cF0>;
<a name="l40"></a> sock(CTCPSocket *)-&gt;timeout = TCP_TIMEOUT;
<a name="l41"></a>
<a name="l42"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>sendString(sock, line, 0);</span><span class=cF0>
<a name="l43"></a> TCPSocketSendString(sock, line);
@ -107,260 +107,262 @@ body {background-color:#1f1f1f;}
<a name="l80"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l81"></a> f-&gt;de.size = total_len;
<a name="l82"></a> </span><span class=cF5>FClose</span><span class=cF0>(f);
<a name="l83"></a> </span><span class=cF1>return</span><span class=cF0> got;
<a name="l84"></a> }
<a name="l85"></a> data_len += got;
<a name="l86"></a> total_len += got;
<a name="l87"></a> </span><span class=cFB>progress4</span><span class=cF0> += got;
<a name="l88"></a> </span><span class=cF1>if</span><span class=cF0> (data_len == </span><span class=cF3>BLK_SIZE</span><span class=cF0>)
<a name="l89"></a> {
<a name="l90"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>FBlkWrite</span><span class=cF7>(</span><span class=cF0>f, buf</span><span class=cF7>)</span><span class=cF0>)
<a name="l91"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l92"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l93"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l94"></a> data_len = </span><span class=cFE>0</span><span class=cF0>;
<a name="l95"></a> }
<a name="l96"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l97"></a>
<a name="l98"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Write failed, %s may be corrupted\n&quot;</span><span class=cF0>, dest);
<a name="l99"></a> </span><span class=cF5>FClose</span><span class=cF0>(f);
<a name="l100"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l101"></a>
<a name="l102"></a>}
<a name="l83"></a> TCPSocketClose(sock);
<a name="l84"></a> </span><span class=cF1>return</span><span class=cF0> got;
<a name="l85"></a> }
<a name="l86"></a> data_len += got;
<a name="l87"></a> total_len += got;
<a name="l88"></a> </span><span class=cFB>progress4</span><span class=cF0> += got;
<a name="l89"></a> </span><span class=cF1>if</span><span class=cF0> (data_len == </span><span class=cF3>BLK_SIZE</span><span class=cF0>)
<a name="l90"></a> {
<a name="l91"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>FBlkWrite</span><span class=cF7>(</span><span class=cF0>f, buf</span><span class=cF7>)</span><span class=cF0>)
<a name="l92"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l93"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l94"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l95"></a> data_len = </span><span class=cFE>0</span><span class=cF0>;
<a name="l96"></a> }
<a name="l97"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l98"></a>
<a name="l99"></a> TCPSocketClose(sock);
<a name="l100"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Write failed, %s may be corrupted\n&quot;</span><span class=cF0>, dest);
<a name="l101"></a> </span><span class=cF5>FClose</span><span class=cF0>(f);
<a name="l102"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l103"></a>
<a name="l104"></a></span><span class=cF1>U0</span><span class=cF0> PrintEscaped(</span><span class=cF1>U8</span><span class=cF0> *txt, </span><span class=cF1>U8</span><span class=cF0> *backslashes = </span><span class=cF6>&quot;&quot;</span><span class=cF0>)
<a name="l105"></a>{
<a name="l106"></a> </span><span class=cF1>U8</span><span class=cF0> *cur;
<a name="l107"></a> </span><span class=cF9>U64</span><span class=cF0> offending;
<a name="l108"></a>
<a name="l109"></a> </span><span class=cF1>while</span><span class=cF0> (cur = </span><span class=cF5>StrFirstOcc</span><span class=cF7>(</span><span class=cF0>txt, </span><span class=cF6>&quot;$\\\&quot;&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l110"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l111"></a> offending = *cur;
<a name="l112"></a> *cur = </span><span class=cFE>0</span><span class=cF0>;
<a name="l113"></a> </span><span class=cF1>if</span><span class=cF0> (offending == </span><span class=cF6>'$'</span><span class=cF0>)
<a name="l114"></a> {
<a name="l115"></a> </span><span class=cF6>&quot;%s$$&quot;</span><span class=cF0>, txt;
<a name="l116"></a> }
<a name="l117"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l118"></a> {
<a name="l119"></a> </span><span class=cF6>&quot;%s%s%c&quot;</span><span class=cF0>, txt, backslashes, offending;
<a name="l120"></a> }
<a name="l121"></a> txt = cur + </span><span class=cFE>1</span><span class=cF0>;
<a name="l122"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l123"></a>
<a name="l124"></a> </span><span class=cF6>&quot;%s&quot;</span><span class=cF0>, txt;
<a name="l125"></a>}
<a name="l126"></a>
<a name="l127"></a></span><span class=cF1>U8</span><span class=cF0> *GopherBasename(</span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l128"></a>{
<a name="l129"></a> </span><span class=cF1>U8</span><span class=cF0> *lastslash = </span><span class=cF5>StrLastOcc</span><span class=cF0>(selector, </span><span class=cF6>&quot;/&quot;</span><span class=cF0>), *result;
<a name="l130"></a>
<a name="l131"></a> </span><span class=cF1>if</span><span class=cF0> (lastslash == </span><span class=cF3>NULL</span><span class=cF0>)
<a name="l132"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l133"></a> result = selector;
<a name="l134"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l135"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l136"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l137"></a> result = lastslash + </span><span class=cFE>1</span><span class=cF0>;
<a name="l138"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l139"></a>
<a name="l140"></a> </span><span class=cF2>//BAD FOR FILENAMES: ? / | = % : ; * + &quot; &lt; &gt; space </span><span class=cF0>
<a name="l141"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;?&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>);
<a name="l142"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;/&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l143"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;|&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l144"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;=&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l145"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;%&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l146"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;:&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l147"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l148"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;*&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l149"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;+&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l150"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;\&quot;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l151"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;&lt;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l152"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;&gt;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l153"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot; &quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l154"></a>
<a name="l155"></a> </span><span class=cF5>SysLog</span><span class=cF0>(</span><span class=cF6>&quot;%s\n&quot;</span><span class=cF0>, result);
<a name="l104"></a>}
<a name="l105"></a>
<a name="l106"></a></span><span class=cF1>U0</span><span class=cF0> PrintEscaped(</span><span class=cF1>U8</span><span class=cF0> *txt, </span><span class=cF1>U8</span><span class=cF0> *backslashes = </span><span class=cF6>&quot;&quot;</span><span class=cF0>)
<a name="l107"></a>{
<a name="l108"></a> </span><span class=cF1>U8</span><span class=cF0> *cur;
<a name="l109"></a> </span><span class=cF9>U64</span><span class=cF0> offending;
<a name="l110"></a>
<a name="l111"></a> </span><span class=cF1>while</span><span class=cF0> (cur = </span><span class=cF5>StrFirstOcc</span><span class=cF7>(</span><span class=cF0>txt, </span><span class=cF6>&quot;$\\\&quot;&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l112"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l113"></a> offending = *cur;
<a name="l114"></a> *cur = </span><span class=cFE>0</span><span class=cF0>;
<a name="l115"></a> </span><span class=cF1>if</span><span class=cF0> (offending == </span><span class=cF6>'$'</span><span class=cF0>)
<a name="l116"></a> {
<a name="l117"></a> </span><span class=cF6>&quot;%s$$&quot;</span><span class=cF0>, txt;
<a name="l118"></a> }
<a name="l119"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l120"></a> {
<a name="l121"></a> </span><span class=cF6>&quot;%s%s%c&quot;</span><span class=cF0>, txt, backslashes, offending;
<a name="l122"></a> }
<a name="l123"></a> txt = cur + </span><span class=cFE>1</span><span class=cF0>;
<a name="l124"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l125"></a>
<a name="l126"></a> </span><span class=cF6>&quot;%s&quot;</span><span class=cF0>, txt;
<a name="l127"></a>}
<a name="l128"></a>
<a name="l129"></a></span><span class=cF1>U8</span><span class=cF0> *GopherBasename(</span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l130"></a>{
<a name="l131"></a> </span><span class=cF1>U8</span><span class=cF0> *lastslash = </span><span class=cF5>StrLastOcc</span><span class=cF0>(selector, </span><span class=cF6>&quot;/&quot;</span><span class=cF0>), *result;
<a name="l132"></a>
<a name="l133"></a> </span><span class=cF1>if</span><span class=cF0> (lastslash == </span><span class=cF3>NULL</span><span class=cF0>)
<a name="l134"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l135"></a> result = selector;
<a name="l136"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l137"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l138"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l139"></a> result = lastslash + </span><span class=cFE>1</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=cF2>//BAD FOR FILENAMES: ? / | = % : ; * + &quot; &lt; &gt; space </span><span class=cF0>
<a name="l143"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;?&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>);
<a name="l144"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;/&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l145"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;|&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l146"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;=&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l147"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;%&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l148"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;:&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l149"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l150"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;*&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l151"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;+&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l152"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;\&quot;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l153"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;&lt;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l154"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot;&gt;&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l155"></a> result = </span><span class=cF5>StrReplace</span><span class=cF0>(result, </span><span class=cF6>&quot; &quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l156"></a>
<a name="l157"></a> </span><span class=cF1>return</span><span class=cF0> result;
<a name="l158"></a>}
<a name="l159"></a>
<a name="l160"></a></span><span class=cF1>U0</span><span class=cF0> GopherTextView(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port, </span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l161"></a>{
<a name="l162"></a> </span><span class=cF1>U8</span><span class=cF0> *basename;
<a name="l163"></a> </span><span class=cF1>U8</span><span class=cF0> *tmpname;
<a name="l164"></a>
<a name="l165"></a> </span><span class=cF5>DirMake</span><span class=cF0>(</span><span class=cF6>&quot;::/Tmp/Gopher&quot;</span><span class=cF0>);
<a name="l157"></a> </span><span class=cF5>SysLog</span><span class=cF0>(</span><span class=cF6>&quot;%s\n&quot;</span><span class=cF0>, result);
<a name="l158"></a>
<a name="l159"></a> </span><span class=cF1>return</span><span class=cF0> result;
<a name="l160"></a>}
<a name="l161"></a>
<a name="l162"></a></span><span class=cF1>U0</span><span class=cF0> GopherTextView(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port, </span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l163"></a>{
<a name="l164"></a> </span><span class=cF1>U8</span><span class=cF0> *basename;
<a name="l165"></a> </span><span class=cF1>U8</span><span class=cF0> *tmpname;
<a name="l166"></a>
<a name="l167"></a> tmpname = </span><span class=cF5>StrNew</span><span class=cF0>(selector);
<a name="l168"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>tmpname</span><span class=cF7>)</span><span class=cF0> &gt; </span><span class=cFE>22</span><span class=cF0>)
<a name="l169"></a> tmpname[</span><span class=cFE>21</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// too long, terminate it early</span><span class=cF0>
<a name="l170"></a> basename = </span><span class=cF5>ExtChange</span><span class=cF0>(GopherBasename</span><span class=cF7>(</span><span class=cF0>tmpname</span><span class=cF7>)</span><span class=cF0>, </span><span class=cF6>&quot;TXT&quot;</span><span class=cF0>);
<a name="l171"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpname);
<a name="l172"></a> tmpname = </span><span class=cF5>StrPrint</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF6>&quot;::/Tmp/Gopher/%s&quot;</span><span class=cF0>, basename);
<a name="l173"></a> </span><span class=cF5>Free</span><span class=cF0>(basename);
<a name="l174"></a>
<a name="l175"></a> </span><span class=cF1>if</span><span class=cF0> (GopherDl</span><span class=cF7>(</span><span class=cF0>host, port, selector,, tmpname</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>0</span><span class=cF0>)
<a name="l176"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l177"></a> </span><span class=cF5>SysLog</span><span class=cF0>(</span><span class=cF6>&quot;%s\n&quot;</span><span class=cF0>, tmpname);
<a name="l178"></a> </span><span class=cF5>Plain</span><span class=cF0>(tmpname);
<a name="l179"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l180"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l181"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l182"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Failed to download %s from %s:%d\n&quot;</span><span class=cF0>,
<a name="l183"></a> selector, host, port);
<a name="l184"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l185"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpname);
<a name="l186"></a>}
<a name="l187"></a>
<a name="l188"></a></span><span class=cF1>U0</span><span class=cF0> GopherLine(</span><span class=cF1>U8</span><span class=cF0> *line)
<a name="l189"></a>{
<a name="l190"></a> </span><span class=cF9>U64</span><span class=cF0> type;
<a name="l191"></a> </span><span class=cF1>U8</span><span class=cF0> *display;
<a name="l192"></a> </span><span class=cF1>U8</span><span class=cF0> *selector;
<a name="l193"></a> </span><span class=cF1>U8</span><span class=cF0> *host = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l194"></a> </span><span class=cF9>U16</span><span class=cF0> port = </span><span class=cFE>0</span><span class=cF0>;
<a name="l195"></a>
<a name="l196"></a> </span><span class=cF1>if</span><span class=cF0> (*line == </span><span class=cFE>0</span><span class=cF0>)
<a name="l197"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l198"></a> </span><span class=cF6>&quot;\n&quot;</span><span class=cF0>;
<a name="l199"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l200"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l201"></a> type = *line++;
<a name="l202"></a> display = line;
<a name="l203"></a>
<a name="l204"></a> line = </span><span class=cF5>StrFind</span><span class=cF0>(</span><span class=cF6>&quot;\t&quot;</span><span class=cF0>, line);
<a name="l205"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l206"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l207"></a> *line = </span><span class=cFE>0</span><span class=cF0>;
<a name="l208"></a> line++;
<a name="l209"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l210"></a> selector = line;
<a name="l211"></a>
<a name="l212"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l213"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l214"></a> line = </span><span class=cF5>StrFind</span><span class=cF0>(</span><span class=cF6>&quot;\t&quot;</span><span class=cF0>, line);
<a name="l215"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l216"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l217"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l218"></a> *line = </span><span class=cFE>0</span><span class=cF0>;
<a name="l219"></a> line++;
<a name="l220"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l221"></a> host = line;
<a name="l222"></a>
<a name="l223"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l224"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l225"></a> line = </span><span class=cF5>StrFind</span><span class=cF0>(</span><span class=cF6>&quot;\t&quot;</span><span class=cF0>, line);
<a name="l226"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l227"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l228"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l229"></a> *line = </span><span class=cFE>0</span><span class=cF0>;
<a name="l230"></a> line++;
<a name="l231"></a> port = </span><span class=cF5>Str2I64</span><span class=cF0>(line);
<a name="l232"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l233"></a>
<a name="l234"></a> </span><span class=cF1>if</span><span class=cF0> (!*host)
<a name="l235"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l236"></a>
<a name="l237"></a> </span><span class=cF1>switch</span><span class=cF0> (type)
<a name="l238"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l239"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'3'</span><span class=cF0>:
<a name="l240"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;&quot;</span><span class=cF0>);
<a name="l241"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'i'</span><span class=cF0>:
<a name="l242"></a> PrintEscaped(display);
<a name="l243"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l244"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l245"></a> </span><span class=cF6>&quot;$MA,\&quot;&quot;</span><span class=cF0>;
<a name="l246"></a> PrintEscaped(display, </span><span class=cF6>&quot;\\&quot;</span><span class=cF0>);
<a name="l247"></a> </span><span class=cF6>&quot;\&quot;,LM=\&quot;%s(\\\&quot;&quot;</span><span class=cF0>, gopher_associations[type];
<a name="l248"></a> PrintEscaped(host, </span><span class=cF6>&quot;\\\\\\&quot;</span><span class=cF0>);
<a name="l249"></a> </span><span class=cF6>&quot;\\\&quot;,%d,\\\&quot;&quot;</span><span class=cF0>, port;
<a name="l250"></a> PrintEscaped(selector, </span><span class=cF6>&quot;\\\\\\&quot;</span><span class=cF0>);
<a name="l251"></a> </span><span class=cF6>&quot;\\\&quot;);\\n\&quot;$&quot;</span><span class=cF0>;
<a name="l252"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l253"></a> </span><span class=cF6>&quot;\n&quot;</span><span class=cF0>;
<a name="l254"></a>}
<a name="l255"></a>
<a name="l256"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> GopherMenu(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port = </span><span class=cFE>70</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *selector = </span><span class=cF6>&quot;/&quot;</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *query = </span><span class=cF3>NULL</span><span class=cF0>)
<a name="l257"></a>{
<a name="l258"></a> </span><span class=cF9>I64</span><span class=cF0> sock, n;
<a name="l259"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cFE>256</span><span class=cF0>];
<a name="l260"></a>
<a name="l261"></a> sock = GopherOpen(host, port, selector, query);
<a name="l262"></a> </span><span class=cF1>if</span><span class=cF0> (sock &lt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l263"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l264"></a> </span><span class=cF1>return</span><span class=cF0> sock;
<a name="l265"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l266"></a>
<a name="l267"></a> </span><span class=cF1>do</span><span class=cF0>
<a name="l268"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l269"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>n = recvLine(sock, buf, sizeof(buf), 0);</span><span class=cF0>
<a name="l270"></a> n = TCPSocketReceiveLine(sock, buf, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>buf</span><span class=cF7>)</span><span class=cF0>);
<a name="l271"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>buf, </span><span class=cF6>&quot;.&quot;</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>0</span><span class=cF0>)
<a name="l272"></a> {
<a name="l273"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l274"></a> }
<a name="l275"></a> GopherLine(buf);
<a name="l276"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l277"></a> </span><span class=cF1>while</span><span class=cF0> (n &gt; </span><span class=cFE>0</span><span class=cF0>);
<a name="l278"></a>
<a name="l279"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>close(sock);</span><span class=cF0>
<a name="l280"></a> TCPSocketClose(sock);
<a name="l281"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
<a name="l282"></a>}
<a name="l283"></a>
<a name="l284"></a></span><span class=cF1>class</span><span class=cF0> CQueryForm
<a name="l285"></a>{
<a name="l286"></a> </span><span class=cF1>U8</span><span class=cF0> query[</span><span class=cFE>65</span><span class=cF0>] format </span><span class=cF6>&quot;$DA-P,A=\&quot;Query:%s\&quot;$&quot;</span><span class=cF0>;
<a name="l287"></a>};
<a name="l288"></a></span><span class=cF1>U0</span><span class=cF0> GopherQueryPrompt(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port, </span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l289"></a>{
<a name="l290"></a> CQueryForm form;
<a name="l291"></a>
<a name="l292"></a> form.query[</span><span class=cFE>0</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l293"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>PopUpForm</span><span class=cF7>(</span><span class=cF0>&amp;form</span><span class=cF7>)</span><span class=cF0>)
<a name="l294"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l295"></a> GopherMenu(host, port, selector, form.query);
<a name="l296"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l297"></a>}
<a name="l298"></a>
<a name="l299"></a></span><span class=cF1>class</span><span class=cF0> CDlForm
<a name="l300"></a>{
<a name="l301"></a> </span><span class=cF1>U8</span><span class=cF0> name[</span><span class=cFE>256</span><span class=cF0>] format </span><span class=cF6>&quot;$DA-P,LEN=255,A=\&quot;FileName:%s\&quot;$&quot;</span><span class=cF0>;
<a name="l302"></a>};
<a name="l303"></a></span><span class=cF1>U0</span><span class=cF0> GopherDlPrompt(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port, </span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l304"></a>{
<a name="l305"></a> CDlForm form;
<a name="l306"></a> </span><span class=cF1>U8</span><span class=cF0> *basename;
<a name="l307"></a>
<a name="l308"></a> basename = GopherBasename(selector);
<a name="l309"></a> </span><span class=cF5>MemSet</span><span class=cF0>(form.name, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>256</span><span class=cF0>);
<a name="l310"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(form.name, basename,
<a name="l311"></a> </span><span class=cF5>MinI64</span><span class=cF7>(</span><span class=cF5>StrLen</span><span class=cF0>(basename), </span><span class=cF1>sizeof</span><span class=cF0>(form.name) - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>);
<a name="l312"></a> form.name[</span><span class=cFE>255</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l313"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>PopUpForm</span><span class=cF7>(</span><span class=cF0>&amp;form</span><span class=cF7>)</span><span class=cF0>)
<a name="l314"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l315"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>form.name</span><span class=cF7>)</span><span class=cF0> &gt;= </span><span class=cFE>26</span><span class=cF0>)
<a name="l316"></a> form.name[</span><span class=cFE>25</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l317"></a> GopherDl(host, port, selector,, form.name);
<a name="l318"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l319"></a>}
<a name="l320"></a>
<a name="l321"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> Gopher(</span><span class=cF1>U8</span><span class=cF0> *hostname)
<a name="l322"></a>{
<a name="l323"></a> </span><span class=cF1>return</span><span class=cF0> GopherMenu(hostname);
<a name="l324"></a>}
<a name="l325"></a>
<a name="l326"></a></span><span class=cF5>MemSetI64</span><span class=cF0>(gopher_associations, </span><span class=cF6>&quot;GopherDlPrompt&quot;</span><span class=cF0>, </span><span class=cFE>256</span><span class=cF0>);
<a name="l327"></a>gopher_associations[</span><span class=cF6>'0'</span><span class=cF0>] = </span><span class=cF6>&quot;GopherTextView&quot;</span><span class=cF0>;
<a name="l328"></a>gopher_associations[</span><span class=cF6>'1'</span><span class=cF0>] = </span><span class=cF6>&quot;GopherMenu&quot;</span><span class=cF0>;
<a name="l329"></a>gopher_associations[</span><span class=cF6>'7'</span><span class=cF0>] = </span><span class=cF6>&quot;GopherQueryPrompt&quot;</span><span class=cF0>;
<a name="l330"></a></span><span class=cF2>/* Include this file from your Net/Load.CC, then add more associations */</span><span class=cF0>
<a name="l331"></a>
<a name="l332"></a>
<a name="l333"></a></span><span class=cF5>DocMax</span><span class=cF0>;
<a name="l334"></a></span><span class=cF6>&quot;\n\nTry using Gopher to connect to a gopher server, for example:&quot;</span><span class=cF0>
<a name="l335"></a></span><span class=cF6>&quot;\n\n Gopher(\&quot;gopher.floodgap.com\&quot;);&quot;</span><span class=cF0>
<a name="l336"></a></span><span class=cF6>&quot;\n\n GopherMenu(\&quot;eyeblea.ch\&quot;,70,\&quot;/~zealos\&quot;);&quot;</span><span class=cF0>
<a name="l337"></a></span><span class=cF6>&quot;\n\n Gopher(\&quot;codevoid.de\&quot;);&quot;</span><span class=cF0>
<a name="l338"></a></span><span class=cF6>&quot;\n\n&quot;</span><span class=cF0>;</span></pre></body>
<a name="l167"></a> </span><span class=cF5>DirMake</span><span class=cF0>(</span><span class=cF6>&quot;::/Tmp/Gopher&quot;</span><span class=cF0>);
<a name="l168"></a>
<a name="l169"></a> tmpname = </span><span class=cF5>StrNew</span><span class=cF0>(selector);
<a name="l170"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>tmpname</span><span class=cF7>)</span><span class=cF0> &gt; </span><span class=cFE>22</span><span class=cF0>)
<a name="l171"></a> tmpname[</span><span class=cFE>21</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// too long, terminate it early</span><span class=cF0>
<a name="l172"></a> basename = </span><span class=cF5>ExtChange</span><span class=cF0>(GopherBasename</span><span class=cF7>(</span><span class=cF0>tmpname</span><span class=cF7>)</span><span class=cF0>, </span><span class=cF6>&quot;TXT&quot;</span><span class=cF0>);
<a name="l173"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpname);
<a name="l174"></a> tmpname = </span><span class=cF5>StrPrint</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF6>&quot;::/Tmp/Gopher/%s&quot;</span><span class=cF0>, basename);
<a name="l175"></a> </span><span class=cF5>Free</span><span class=cF0>(basename);
<a name="l176"></a>
<a name="l177"></a> </span><span class=cF1>if</span><span class=cF0> (GopherDl</span><span class=cF7>(</span><span class=cF0>host, port, selector,, tmpname</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>0</span><span class=cF0>)
<a name="l178"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l179"></a> </span><span class=cF5>SysLog</span><span class=cF0>(</span><span class=cF6>&quot;%s\n&quot;</span><span class=cF0>, tmpname);
<a name="l180"></a> </span><span class=cF5>Plain</span><span class=cF0>(tmpname);
<a name="l181"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l182"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l183"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l184"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Failed to download %s from %s:%d\n&quot;</span><span class=cF0>,
<a name="l185"></a> selector, host, port);
<a name="l186"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l187"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpname);
<a name="l188"></a>}
<a name="l189"></a>
<a name="l190"></a></span><span class=cF1>U0</span><span class=cF0> GopherLine(</span><span class=cF1>U8</span><span class=cF0> *line)
<a name="l191"></a>{
<a name="l192"></a> </span><span class=cF9>U64</span><span class=cF0> type;
<a name="l193"></a> </span><span class=cF1>U8</span><span class=cF0> *display;
<a name="l194"></a> </span><span class=cF1>U8</span><span class=cF0> *selector;
<a name="l195"></a> </span><span class=cF1>U8</span><span class=cF0> *host = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l196"></a> </span><span class=cF9>U16</span><span class=cF0> port = </span><span class=cFE>0</span><span class=cF0>;
<a name="l197"></a>
<a name="l198"></a> </span><span class=cF1>if</span><span class=cF0> (*line == </span><span class=cFE>0</span><span class=cF0>)
<a name="l199"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l200"></a> </span><span class=cF6>&quot;\n&quot;</span><span class=cF0>;
<a name="l201"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l202"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l203"></a> type = *line++;
<a name="l204"></a> display = line;
<a name="l205"></a>
<a name="l206"></a> line = </span><span class=cF5>StrFind</span><span class=cF0>(</span><span class=cF6>&quot;\t&quot;</span><span class=cF0>, line);
<a name="l207"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l208"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l209"></a> *line = </span><span class=cFE>0</span><span class=cF0>;
<a name="l210"></a> line++;
<a name="l211"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l212"></a> selector = line;
<a name="l213"></a>
<a name="l214"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l215"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l216"></a> line = </span><span class=cF5>StrFind</span><span class=cF0>(</span><span class=cF6>&quot;\t&quot;</span><span class=cF0>, line);
<a name="l217"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l218"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l219"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l220"></a> *line = </span><span class=cFE>0</span><span class=cF0>;
<a name="l221"></a> line++;
<a name="l222"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l223"></a> host = line;
<a name="l224"></a>
<a name="l225"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l226"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l227"></a> line = </span><span class=cF5>StrFind</span><span class=cF0>(</span><span class=cF6>&quot;\t&quot;</span><span class=cF0>, line);
<a name="l228"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l229"></a> </span><span class=cF1>if</span><span class=cF0> (line)
<a name="l230"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l231"></a> *line = </span><span class=cFE>0</span><span class=cF0>;
<a name="l232"></a> line++;
<a name="l233"></a> port = </span><span class=cF5>Str2I64</span><span class=cF0>(line);
<a name="l234"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l235"></a>
<a name="l236"></a> </span><span class=cF1>if</span><span class=cF0> (!*host)
<a name="l237"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l238"></a>
<a name="l239"></a> </span><span class=cF1>switch</span><span class=cF0> (type)
<a name="l240"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l241"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'3'</span><span class=cF0>:
<a name="l242"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;&quot;</span><span class=cF0>);
<a name="l243"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'i'</span><span class=cF0>:
<a name="l244"></a> PrintEscaped(display);
<a name="l245"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l246"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l247"></a> </span><span class=cF6>&quot;$MA,\&quot;&quot;</span><span class=cF0>;
<a name="l248"></a> PrintEscaped(display, </span><span class=cF6>&quot;\\&quot;</span><span class=cF0>);
<a name="l249"></a> </span><span class=cF6>&quot;\&quot;,LM=\&quot;%s(\\\&quot;&quot;</span><span class=cF0>, gopher_associations[type];
<a name="l250"></a> PrintEscaped(host, </span><span class=cF6>&quot;\\\\\\&quot;</span><span class=cF0>);
<a name="l251"></a> </span><span class=cF6>&quot;\\\&quot;,%d,\\\&quot;&quot;</span><span class=cF0>, port;
<a name="l252"></a> PrintEscaped(selector, </span><span class=cF6>&quot;\\\\\\&quot;</span><span class=cF0>);
<a name="l253"></a> </span><span class=cF6>&quot;\\\&quot;);\\n\&quot;$&quot;</span><span class=cF0>;
<a name="l254"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l255"></a> </span><span class=cF6>&quot;\n&quot;</span><span class=cF0>;
<a name="l256"></a>}
<a name="l257"></a>
<a name="l258"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> GopherMenu(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port = </span><span class=cFE>70</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *selector = </span><span class=cF6>&quot;/&quot;</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *query = </span><span class=cF3>NULL</span><span class=cF0>)
<a name="l259"></a>{
<a name="l260"></a> </span><span class=cF9>I64</span><span class=cF0> sock, n;
<a name="l261"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cFE>256</span><span class=cF0>];
<a name="l262"></a>
<a name="l263"></a> sock = GopherOpen(host, port, selector, query);
<a name="l264"></a> </span><span class=cF1>if</span><span class=cF0> (sock &lt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l265"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l266"></a> </span><span class=cF1>return</span><span class=cF0> sock;
<a name="l267"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l268"></a>
<a name="l269"></a> </span><span class=cF1>do</span><span class=cF0>
<a name="l270"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l271"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>n = recvLine(sock, buf, sizeof(buf), 0);</span><span class=cF0>
<a name="l272"></a> n = TCPSocketReceiveLine(sock, buf, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>buf</span><span class=cF7>)</span><span class=cF0>);
<a name="l273"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>buf, </span><span class=cF6>&quot;.&quot;</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>0</span><span class=cF0>)
<a name="l274"></a> {
<a name="l275"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l276"></a> }
<a name="l277"></a> GopherLine(buf);
<a name="l278"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l279"></a> </span><span class=cF1>while</span><span class=cF0> (n &gt; </span><span class=cFE>0</span><span class=cF0>);
<a name="l280"></a>
<a name="l281"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>close(sock);</span><span class=cF0>
<a name="l282"></a> TCPSocketClose(sock);
<a name="l283"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
<a name="l284"></a>}
<a name="l285"></a>
<a name="l286"></a></span><span class=cF1>class</span><span class=cF0> CQueryForm
<a name="l287"></a>{
<a name="l288"></a> </span><span class=cF1>U8</span><span class=cF0> query[</span><span class=cFE>65</span><span class=cF0>] format </span><span class=cF6>&quot;$DA-P,A=\&quot;Query:%s\&quot;$&quot;</span><span class=cF0>;
<a name="l289"></a>};
<a name="l290"></a></span><span class=cF1>U0</span><span class=cF0> GopherQueryPrompt(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port, </span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l291"></a>{
<a name="l292"></a> CQueryForm form;
<a name="l293"></a>
<a name="l294"></a> form.query[</span><span class=cFE>0</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l295"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>PopUpForm</span><span class=cF7>(</span><span class=cF0>&amp;form</span><span class=cF7>)</span><span class=cF0>)
<a name="l296"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l297"></a> GopherMenu(host, port, selector, form.query);
<a name="l298"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l299"></a>}
<a name="l300"></a>
<a name="l301"></a></span><span class=cF1>class</span><span class=cF0> CDlForm
<a name="l302"></a>{
<a name="l303"></a> </span><span class=cF1>U8</span><span class=cF0> name[</span><span class=cFE>256</span><span class=cF0>] format </span><span class=cF6>&quot;$DA-P,LEN=255,A=\&quot;FileName:%s\&quot;$&quot;</span><span class=cF0>;
<a name="l304"></a>};
<a name="l305"></a></span><span class=cF1>U0</span><span class=cF0> GopherDlPrompt(</span><span class=cF1>U8</span><span class=cF0> *host, </span><span class=cF9>U16</span><span class=cF0> port, </span><span class=cF1>U8</span><span class=cF0> *selector)
<a name="l306"></a>{
<a name="l307"></a> CDlForm form;
<a name="l308"></a> </span><span class=cF1>U8</span><span class=cF0> *basename;
<a name="l309"></a>
<a name="l310"></a> basename = GopherBasename(selector);
<a name="l311"></a> </span><span class=cF5>MemSet</span><span class=cF0>(form.name, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>256</span><span class=cF0>);
<a name="l312"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(form.name, basename,
<a name="l313"></a> </span><span class=cF5>MinI64</span><span class=cF7>(</span><span class=cF5>StrLen</span><span class=cF0>(basename), </span><span class=cF1>sizeof</span><span class=cF0>(form.name) - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>);
<a name="l314"></a> form.name[</span><span class=cFE>255</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l315"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>PopUpForm</span><span class=cF7>(</span><span class=cF0>&amp;form</span><span class=cF7>)</span><span class=cF0>)
<a name="l316"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l317"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>form.name</span><span class=cF7>)</span><span class=cF0> &gt;= </span><span class=cFE>26</span><span class=cF0>)
<a name="l318"></a> form.name[</span><span class=cFE>25</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l319"></a> GopherDl(host, port, selector,, form.name);
<a name="l320"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l321"></a>}
<a name="l322"></a>
<a name="l323"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> Gopher(</span><span class=cF1>U8</span><span class=cF0> *hostname)
<a name="l324"></a>{
<a name="l325"></a> </span><span class=cF1>return</span><span class=cF0> GopherMenu(hostname);
<a name="l326"></a>}
<a name="l327"></a>
<a name="l328"></a></span><span class=cF5>MemSetI64</span><span class=cF0>(gopher_associations, </span><span class=cF6>&quot;GopherDlPrompt&quot;</span><span class=cF0>, </span><span class=cFE>256</span><span class=cF0>);
<a name="l329"></a>gopher_associations[</span><span class=cF6>'0'</span><span class=cF0>] = </span><span class=cF6>&quot;GopherTextView&quot;</span><span class=cF0>;
<a name="l330"></a>gopher_associations[</span><span class=cF6>'1'</span><span class=cF0>] = </span><span class=cF6>&quot;GopherMenu&quot;</span><span class=cF0>;
<a name="l331"></a>gopher_associations[</span><span class=cF6>'7'</span><span class=cF0>] = </span><span class=cF6>&quot;GopherQueryPrompt&quot;</span><span class=cF0>;
<a name="l332"></a></span><span class=cF2>/* Include this file from your Net/Load.CC, then add more associations */</span><span class=cF0>
<a name="l333"></a>
<a name="l334"></a>
<a name="l335"></a></span><span class=cF5>DocMax</span><span class=cF0>;
<a name="l336"></a></span><span class=cF6>&quot;\n\nTry using Gopher to connect to a gopher server, for example:&quot;</span><span class=cF0>
<a name="l337"></a></span><span class=cF6>&quot;\n\n Gopher(\&quot;gopher.floodgap.com\&quot;);&quot;</span><span class=cF0>
<a name="l338"></a></span><span class=cF6>&quot;\n\n GopherMenu(\&quot;eyeblea.ch\&quot;,70,\&quot;/~zealos\&quot;);&quot;</span><span class=cF0>
<a name="l339"></a></span><span class=cF6>&quot;\n\n Gopher(\&quot;codevoid.de\&quot;);&quot;</span><span class=cF0>
<a name="l340"></a></span><span class=cF6>&quot;\n\n&quot;</span><span class=cF0>;</span></pre></body>
</html>

View file

@ -1263,412 +1263,406 @@ body {background-color:#1f1f1f;}
<a name="l1236"></a>
<a name="l1237"></a> timeout = </span><span class=cFB>counts</span><span class=cF0>.jiffies + tcp_socket-&gt;timeout * </span><span class=cF3>JIFFY_FREQ</span><span class=cF0> / </span><span class=cFE>1000</span><span class=cF0>;
<a name="l1238"></a>
<a name="l1239"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>tcp_socket-&gt;state == TCP_STATE_ESTABLISHED || tcp_socket-&gt;state == TCP_STATE_FIN_WAIT1</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l1240"></a> tcp_socket-&gt;read_position == tcp_socket-&gt;write_position)
<a name="l1241"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1242"></a> TCPCheckACKQueue(tcp_socket);
<a name="l1243"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>);
<a name="l1244"></a>
<a name="l1245"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>counts</span><span class=cF0>.jiffies &gt; timeout)
<a name="l1246"></a> {
<a name="l1247"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>if (tcp_socket-&gt;timeout != 0) // Don't flood NetLog on non-blocking receives.</span><span class=cF0>
<a name="l1248"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>NetErr(&quot;TCP SOCKET RECEIVE: Timed out.&quot;);</span><span class=cF0>
<a name="l1249"></a>
<a name="l1250"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>return -1;</span><span class=cF0>
<a name="l1251"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1252"></a> }
<a name="l1253"></a>
<a name="l1239"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>tcp_socket-&gt;state == TCP_STATE_ESTABLISHED ||
<a name="l1240"></a> tcp_socket-&gt;state == TCP_STATE_FIN_WAIT1 ||
<a name="l1241"></a> tcp_socket-&gt;state == TCP_STATE_CLOSE_WAIT</span><span class=cF7>)</span><span class=cF0> &amp;&amp; </span><span class=cF2>// allowing receive during closing state</span><span class=cF0>
<a name="l1242"></a> tcp_socket-&gt;read_position == tcp_socket-&gt;write_position)
<a name="l1243"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1244"></a> TCPCheckACKQueue(tcp_socket);
<a name="l1245"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>);
<a name="l1246"></a>
<a name="l1247"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>counts</span><span class=cF0>.jiffies &gt; timeout)
<a name="l1248"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1249"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1250"></a>
<a name="l1251"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>tcp_socket-&gt;state != TCP_STATE_ESTABLISHED || tcp_socket-&gt;state == TCP_STATE_FIN_WAIT1</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l1252"></a> tcp_socket-&gt;read_position == tcp_socket-&gt;write_position || length == </span><span class=cFE>0</span><span class=cF0>)
<a name="l1253"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
<a name="l1254"></a>
<a name="l1255"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1256"></a>
<a name="l1257"></a> </span><span class=cF2>// Shrine has TODO: Should still be able to receive in closing states ...</span><span class=cF0>
<a name="l1258"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>tcp_socket-&gt;state != TCP_STATE_ESTABLISHED || tcp_socket-&gt;state == TCP_STATE_FIN_WAIT1</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l1259"></a> tcp_socket-&gt;read_position == tcp_socket-&gt;write_position || length == </span><span class=cFE>0</span><span class=cF0>)
<a name="l1260"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
<a name="l1261"></a>
<a name="l1262"></a>
<a name="l1263"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>counts</span><span class=cF0>.jiffies &gt; timeout)
<a name="l1264"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1265"></a> </span><span class=cF1>if</span><span class=cF0> (tcp_socket-&gt;timeout != </span><span class=cFE>0</span><span class=cF0>) </span><span class=cF2>// Don't flood NetLog on non-blocking receives.</span><span class=cF0>
<a name="l1266"></a> NetErr(</span><span class=cF6>&quot;TCP SOCKET RECEIVE: Timed out.&quot;</span><span class=cF0>);
<a name="l1255"></a>
<a name="l1256"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>counts</span><span class=cF0>.jiffies &gt; timeout)
<a name="l1257"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1258"></a> </span><span class=cF1>if</span><span class=cF0> (tcp_socket-&gt;timeout != </span><span class=cFE>0</span><span class=cF0>) </span><span class=cF2>// Don't flood NetLog on non-blocking receives.</span><span class=cF0>
<a name="l1259"></a> NetErr(</span><span class=cF6>&quot;TCP SOCKET RECEIVE: Timed out.&quot;</span><span class=cF0>);
<a name="l1260"></a>
<a name="l1261"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l1262"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1263"></a>
<a name="l1264"></a>
<a name="l1265"></a> read_position = tcp_socket-&gt;read_position;
<a name="l1266"></a> write_position = tcp_socket-&gt;write_position;
<a name="l1267"></a>
<a name="l1268"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l1269"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1270"></a>
<a name="l1268"></a> </span><span class=cF1>if</span><span class=cF0> (write_position &lt; read_position)
<a name="l1269"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1270"></a> step = tcp_socket-&gt;receive_buffer_size - read_position;
<a name="l1271"></a>
<a name="l1272"></a> read_position = tcp_socket-&gt;read_position;
<a name="l1273"></a> write_position = tcp_socket-&gt;write_position;
<a name="l1272"></a> </span><span class=cF1>if</span><span class=cF0> (step &gt; length)
<a name="l1273"></a> step = length;
<a name="l1274"></a>
<a name="l1275"></a> </span><span class=cF1>if</span><span class=cF0> (write_position &lt; read_position)
<a name="l1276"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1277"></a> step = tcp_socket-&gt;receive_buffer_size - read_position;
<a name="l1278"></a>
<a name="l1279"></a> </span><span class=cF1>if</span><span class=cF0> (step &gt; length)
<a name="l1280"></a> step = length;
<a name="l1281"></a>
<a name="l1282"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(buffer, tcp_socket-&gt;receive_buffer + read_position, step);
<a name="l1283"></a> buffer += step;
<a name="l1284"></a> length -= step;
<a name="l1285"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>read_position = (read_position + step) &amp; (tcp_socket-&gt;receive_buffer_size - 1);</span><span class=cF0>
<a name="l1286"></a> read_position = (read_position + step) % tcp_socket-&gt;receive_buffer_size;
<a name="l1287"></a> read_total += step;
<a name="l1288"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1275"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(buffer, tcp_socket-&gt;receive_buffer + read_position, step);
<a name="l1276"></a> buffer += step;
<a name="l1277"></a> length -= step;
<a name="l1278"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>read_position = (read_position + step) &amp; (tcp_socket-&gt;receive_buffer_size - 1);</span><span class=cF0>
<a name="l1279"></a> read_position = (read_position + step) % tcp_socket-&gt;receive_buffer_size;
<a name="l1280"></a> read_total += step;
<a name="l1281"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1282"></a>
<a name="l1283"></a> </span><span class=cF1>if</span><span class=cF0> (length &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1284"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1285"></a> step = write_position - read_position;
<a name="l1286"></a>
<a name="l1287"></a> </span><span class=cF1>if</span><span class=cF0> (step &gt; length)
<a name="l1288"></a> step = length;
<a name="l1289"></a>
<a name="l1290"></a> </span><span class=cF1>if</span><span class=cF0> (length &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1291"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1292"></a> step = write_position - read_position;
<a name="l1293"></a>
<a name="l1294"></a> </span><span class=cF1>if</span><span class=cF0> (step &gt; length)
<a name="l1295"></a> step = length;
<a name="l1290"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(buffer, tcp_socket-&gt;receive_buffer + read_position, step);
<a name="l1291"></a> buffer += step;
<a name="l1292"></a> length -= step;
<a name="l1293"></a> read_position += step;
<a name="l1294"></a> read_total += step;
<a name="l1295"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1296"></a>
<a name="l1297"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(buffer, tcp_socket-&gt;receive_buffer + read_position, step);
<a name="l1298"></a> buffer += step;
<a name="l1299"></a> length -= step;
<a name="l1300"></a> read_position += step;
<a name="l1301"></a> read_total += step;
<a name="l1302"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1303"></a>
<a name="l1304"></a> tcp_socket-&gt;read_position = read_position;
<a name="l1297"></a> tcp_socket-&gt;read_position = read_position;
<a name="l1298"></a>
<a name="l1299"></a> </span><span class=cF1>return</span><span class=cF0> read_total;
<a name="l1300"></a>}
<a name="l1301"></a>
<a name="l1302"></a></span><span class=cF9>I64</span><span class=cF0> TCPSocketReceiveLine(CTCPSocket *tcp_socket, </span><span class=cF1>U8</span><span class=cF0> *buffer, </span><span class=cF9>I64</span><span class=cF0> size)
<a name="l1303"></a>{
<a name="l1304"></a> </span><span class=cF9>I64</span><span class=cF0> received = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1305"></a>
<a name="l1306"></a> </span><span class=cF1>return</span><span class=cF0> read_total;
<a name="l1307"></a>}
<a name="l1308"></a>
<a name="l1309"></a></span><span class=cF9>I64</span><span class=cF0> TCPSocketReceiveLine(CTCPSocket *tcp_socket, </span><span class=cF1>U8</span><span class=cF0> *buffer, </span><span class=cF9>I64</span><span class=cF0> size)
<a name="l1310"></a>{
<a name="l1311"></a> </span><span class=cF9>I64</span><span class=cF0> received = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1312"></a>
<a name="l1313"></a> </span><span class=cF1>while</span><span class=cF0> (received + </span><span class=cFE>1</span><span class=cF0> &lt; size)
<a name="l1314"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1315"></a> </span><span class=cF1>if</span><span class=cF0> (TCPSocketReceive</span><span class=cF7>(</span><span class=cF0>tcp_socket, buffer + received, </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> &lt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l1316"></a> {
<a name="l1317"></a> NetErr(</span><span class=cF6>&quot;TCP SOCKET RECEIVE LINE: Failed at TCPSocketReceive.&quot;</span><span class=cF0>);
<a name="l1318"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l1319"></a> }
<a name="l1320"></a> </span><span class=cF1>if</span><span class=cF0> (buffer[received] == </span><span class=cF6>'\n'</span><span class=cF0>)
<a name="l1321"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1322"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (buffer[received] != </span><span class=cF6>'\r'</span><span class=cF0>)
<a name="l1323"></a> received++;
<a name="l1324"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1325"></a>
<a name="l1326"></a> </span><span class=cF2>// Shrine has 'FIXME: safe but incorrect behavior on overflow'</span><span class=cF0>
<a name="l1327"></a> buffer[received] = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// terminate string</span><span class=cF0>
<a name="l1328"></a> </span><span class=cF1>return</span><span class=cF0> received;
<a name="l1329"></a>}
<a name="l1330"></a>
<a name="l1331"></a></span><span class=cF9>I64</span><span class=cF0> TCPSocketSend(CTCPSocket *tcp_socket, </span><span class=cF1>U8</span><span class=cF0> *buffer, </span><span class=cF9>I64</span><span class=cF0> length)
<a name="l1332"></a>{
<a name="l1333"></a> </span><span class=cF9>I64</span><span class=cF0> sent_total = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1334"></a> </span><span class=cF9>I64</span><span class=cF0> timeout = </span><span class=cFB>counts</span><span class=cF0>.jiffies + tcp_socket-&gt;timeout * </span><span class=cF3>JIFFY_FREQ</span><span class=cF0> / </span><span class=cFE>1000</span><span class=cF0>;
<a name="l1335"></a> </span><span class=cF9>I64</span><span class=cF0> send_length;
<a name="l1336"></a>
<a name="l1337"></a> </span><span class=cF1>if</span><span class=cF0> (!SocketSend</span><span class=cF7>(</span><span class=cF0>tcp_socket-&gt;socket</span><span class=cF7>)</span><span class=cF0>)
<a name="l1306"></a> </span><span class=cF1>while</span><span class=cF0> (received + </span><span class=cFE>1</span><span class=cF0> &lt; size)
<a name="l1307"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1308"></a> </span><span class=cF1>if</span><span class=cF0> (TCPSocketReceive</span><span class=cF7>(</span><span class=cF0>tcp_socket, buffer + received, </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> &lt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l1309"></a> {
<a name="l1310"></a> NetErr(</span><span class=cF6>&quot;TCP SOCKET RECEIVE LINE: Failed at TCPSocketReceive.&quot;</span><span class=cF0>);
<a name="l1311"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l1312"></a> }
<a name="l1313"></a> </span><span class=cF1>if</span><span class=cF0> (buffer[received] == </span><span class=cF6>'\n'</span><span class=cF0>)
<a name="l1314"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1315"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (buffer[received] != </span><span class=cF6>'\r'</span><span class=cF0>)
<a name="l1316"></a> received++;
<a name="l1317"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1318"></a>
<a name="l1319"></a> </span><span class=cF2>// Shrine has 'FIXME: safe but incorrect behavior on overflow'</span><span class=cF0>
<a name="l1320"></a> buffer[received] = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// terminate string</span><span class=cF0>
<a name="l1321"></a> </span><span class=cF1>return</span><span class=cF0> received;
<a name="l1322"></a>}
<a name="l1323"></a>
<a name="l1324"></a></span><span class=cF9>I64</span><span class=cF0> TCPSocketSend(CTCPSocket *tcp_socket, </span><span class=cF1>U8</span><span class=cF0> *buffer, </span><span class=cF9>I64</span><span class=cF0> length)
<a name="l1325"></a>{
<a name="l1326"></a> </span><span class=cF9>I64</span><span class=cF0> sent_total = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1327"></a> </span><span class=cF9>I64</span><span class=cF0> timeout = </span><span class=cFB>counts</span><span class=cF0>.jiffies + tcp_socket-&gt;timeout * </span><span class=cF3>JIFFY_FREQ</span><span class=cF0> / </span><span class=cFE>1000</span><span class=cF0>;
<a name="l1328"></a> </span><span class=cF9>I64</span><span class=cF0> send_length;
<a name="l1329"></a>
<a name="l1330"></a> </span><span class=cF1>if</span><span class=cF0> (!SocketSend</span><span class=cF7>(</span><span class=cF0>tcp_socket-&gt;socket</span><span class=cF7>)</span><span class=cF0>)
<a name="l1331"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1332"></a> NetErr(</span><span class=cF6>&quot;TCP SOCKET SEND: Failed, Socket state-machine must be in OPEN state.&quot;</span><span class=cF0>);
<a name="l1333"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l1334"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1335"></a>
<a name="l1336"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>tcp_socket-&gt;state == TCP_STATE_ESTABLISHED || tcp_socket-&gt;state == TCP_STATE_CLOSE_WAIT</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l1337"></a> length)
<a name="l1338"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1339"></a> NetErr(</span><span class=cF6>&quot;TCP SOCKET SEND: Failed, Socket state-machine must be in OPEN state.&quot;</span><span class=cF0>);
<a name="l1340"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l1341"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1339"></a> send_length = (tcp_socket-&gt;first_unacked_seq + tcp_socket-&gt;send_window - tcp_socket-&gt;next_send_seq_num) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l1340"></a>
<a name="l1341"></a> </span><span class=cF2>// Shrine has TODO: Keep trying, tie to timeout: RFC 793 &quot;Managing The Window&quot;</span><span class=cF0>
<a name="l1342"></a>
<a name="l1343"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>tcp_socket-&gt;state == TCP_STATE_ESTABLISHED || tcp_socket-&gt;state == TCP_STATE_CLOSE_WAIT</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l1344"></a> length)
<a name="l1345"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1346"></a> send_length = (tcp_socket-&gt;first_unacked_seq + tcp_socket-&gt;send_window - tcp_socket-&gt;next_send_seq_num) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l1347"></a>
<a name="l1348"></a> </span><span class=cF2>// Shrine has TODO: Keep trying, tie to timeout: RFC 793 &quot;Managing The Window&quot;</span><span class=cF0>
<a name="l1349"></a>
<a name="l1350"></a> </span><span class=cF1>if</span><span class=cF0> (send_length == </span><span class=cFE>0</span><span class=cF0>)
<a name="l1351"></a> {
<a name="l1352"></a> </span><span class=cF1>if</span><span class=cF0> (sent_total &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1353"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1354"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1355"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1356"></a> TCPCheckACKQueue(tcp_socket);
<a name="l1357"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>);
<a name="l1358"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1359"></a> }
<a name="l1360"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1361"></a> {
<a name="l1362"></a> </span><span class=cF1>if</span><span class=cF0> (send_length &gt; length)
<a name="l1363"></a> send_length = length;
<a name="l1364"></a>
<a name="l1365"></a> </span><span class=cF1>if</span><span class=cF0> (send_length &gt; tcp_socket-&gt;max_segment_size)
<a name="l1366"></a> send_length = tcp_socket-&gt;max_segment_size;
<a name="l1367"></a>
<a name="l1368"></a> NetDebug(</span><span class=cF6>&quot;TCP SOCKET SEND: Trying TCPSendData() of %d bytes.&quot;</span><span class=cF0>, send_length);
<a name="l1369"></a> </span><span class=cF1>if</span><span class=cF0> (TCPSendData</span><span class=cF7>(</span><span class=cF0>tcp_socket, TCPF_ACK, buffer, send_length</span><span class=cF7>)</span><span class=cF0> &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1370"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>// Stall until outgoing data acknowledged.</span><span class=cF0>
<a name="l1371"></a> </span><span class=cF1>if</span><span class=cF0> (sent_total &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1372"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1373"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1374"></a> {
<a name="l1375"></a> TCPCheckACKQueue(tcp_socket);
<a name="l1376"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>);
<a name="l1377"></a> }
<a name="l1378"></a>
<a name="l1379"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1380"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1381"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1382"></a> buffer += send_length;
<a name="l1383"></a> length -= send_length;
<a name="l1384"></a> sent_total += send_length;
<a name="l1385"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1386"></a> }
<a name="l1387"></a>
<a name="l1388"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>counts</span><span class=cF0>.jiffies &gt; timeout)
<a name="l1389"></a> {
<a name="l1390"></a> </span><span class=cF1>if</span><span class=cF0> (tcp_socket-&gt;timeout != </span><span class=cFE>0</span><span class=cF0>) </span><span class=cF2>// Don't flood NetLog on non-blocking sends.</span><span class=cF0>
<a name="l1391"></a> NetErr(</span><span class=cF6>&quot;TCP SOCKET SEND: Timed out.&quot;</span><span class=cF0>);
<a name="l1343"></a> </span><span class=cF1>if</span><span class=cF0> (send_length == </span><span class=cFE>0</span><span class=cF0>)
<a name="l1344"></a> {
<a name="l1345"></a> </span><span class=cF1>if</span><span class=cF0> (sent_total &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1346"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1347"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1348"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1349"></a> TCPCheckACKQueue(tcp_socket);
<a name="l1350"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>);
<a name="l1351"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1352"></a> }
<a name="l1353"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1354"></a> {
<a name="l1355"></a> </span><span class=cF1>if</span><span class=cF0> (send_length &gt; length)
<a name="l1356"></a> send_length = length;
<a name="l1357"></a>
<a name="l1358"></a> </span><span class=cF1>if</span><span class=cF0> (send_length &gt; tcp_socket-&gt;max_segment_size)
<a name="l1359"></a> send_length = tcp_socket-&gt;max_segment_size;
<a name="l1360"></a>
<a name="l1361"></a> NetDebug(</span><span class=cF6>&quot;TCP SOCKET SEND: Trying TCPSendData() of %d bytes.&quot;</span><span class=cF0>, send_length);
<a name="l1362"></a> </span><span class=cF1>if</span><span class=cF0> (TCPSendData</span><span class=cF7>(</span><span class=cF0>tcp_socket, TCPF_ACK, buffer, send_length</span><span class=cF7>)</span><span class=cF0> &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1363"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>// Stall until outgoing data acknowledged.</span><span class=cF0>
<a name="l1364"></a> </span><span class=cF1>if</span><span class=cF0> (sent_total &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1365"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1366"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1367"></a> {
<a name="l1368"></a> TCPCheckACKQueue(tcp_socket);
<a name="l1369"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>);
<a name="l1370"></a> }
<a name="l1371"></a>
<a name="l1372"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1373"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1374"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1375"></a> buffer += send_length;
<a name="l1376"></a> length -= send_length;
<a name="l1377"></a> sent_total += send_length;
<a name="l1378"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1379"></a> }
<a name="l1380"></a>
<a name="l1381"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>counts</span><span class=cF0>.jiffies &gt; timeout)
<a name="l1382"></a> {
<a name="l1383"></a> </span><span class=cF1>if</span><span class=cF0> (tcp_socket-&gt;timeout != </span><span class=cFE>0</span><span class=cF0>) </span><span class=cF2>// Don't flood NetLog on non-blocking sends.</span><span class=cF0>
<a name="l1384"></a> NetErr(</span><span class=cF6>&quot;TCP SOCKET SEND: Timed out.&quot;</span><span class=cF0>);
<a name="l1385"></a>
<a name="l1386"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1387"></a> }
<a name="l1388"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1389"></a>
<a name="l1390"></a> </span><span class=cF1>return</span><span class=cF0> sent_total;
<a name="l1391"></a>}
<a name="l1392"></a>
<a name="l1393"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1394"></a> }
<a name="l1395"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1396"></a>
<a name="l1397"></a> </span><span class=cF1>return</span><span class=cF0> sent_total;
<a name="l1398"></a>}
<a name="l1399"></a>
<a name="l1400"></a></span><span class=cF9>I64</span><span class=cF0> TCPSocketSendAll(CTCPSocket *tcp_socket, </span><span class=cF1>U8</span><span class=cF0> *buffer, </span><span class=cF9>I64</span><span class=cF0> length)
<a name="l1401"></a>{
<a name="l1402"></a> </span><span class=cF9>I64</span><span class=cF0> total = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1403"></a> </span><span class=cF9>I64</span><span class=cF0> sent = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1404"></a>
<a name="l1405"></a> </span><span class=cF1>while</span><span class=cF0> (length)
<a name="l1406"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1407"></a> sent = TCPSocketSend(tcp_socket, buffer, length);
<a name="l1408"></a>
<a name="l1409"></a> </span><span class=cF1>if</span><span class=cF0> (sent &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1410"></a> {
<a name="l1411"></a> buffer += sent;
<a name="l1412"></a> total += sent;
<a name="l1413"></a> length -= sent;
<a name="l1414"></a> }
<a name="l1415"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1416"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1417"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1418"></a>
<a name="l1419"></a> </span><span class=cF1>return</span><span class=cF0> total;
<a name="l1420"></a>}
<a name="l1421"></a>
<a name="l1422"></a></span><span class=cF9>I64</span><span class=cF0> TCPSocketSendString(CTCPSocket *tcp_socket, </span><span class=cF1>U8</span><span class=cF0> *string)
<a name="l1423"></a>{
<a name="l1424"></a> </span><span class=cF1>return</span><span class=cF0> TCPSocketSendAll(tcp_socket, string, </span><span class=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>string</span><span class=cF7>)</span><span class=cF0>);
<a name="l1425"></a>}
<a name="l1426"></a>
<a name="l1427"></a>CTCPSocket *TCPConnectionCreate(</span><span class=cF1>U8</span><span class=cF0> *hostname, </span><span class=cF9>U16</span><span class=cF0> port)
<a name="l1428"></a>{
<a name="l1429"></a> CSocketAddressIPV4 socket_addr;
<a name="l1430"></a> CAddressInfo *current;
<a name="l1431"></a> CAddressInfo *info = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l1432"></a> </span><span class=cF9>I64</span><span class=cF0> error = DNSAddressInfoGet(hostname, </span><span class=cF3>NULL</span><span class=cF0>, &amp;info);
<a name="l1433"></a> CTCPSocket *result;
<a name="l1393"></a></span><span class=cF9>I64</span><span class=cF0> TCPSocketSendAll(CTCPSocket *tcp_socket, </span><span class=cF1>U8</span><span class=cF0> *buffer, </span><span class=cF9>I64</span><span class=cF0> length)
<a name="l1394"></a>{
<a name="l1395"></a> </span><span class=cF9>I64</span><span class=cF0> total = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1396"></a> </span><span class=cF9>I64</span><span class=cF0> sent = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1397"></a>
<a name="l1398"></a> </span><span class=cF1>while</span><span class=cF0> (length)
<a name="l1399"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1400"></a> sent = TCPSocketSend(tcp_socket, buffer, length);
<a name="l1401"></a>
<a name="l1402"></a> </span><span class=cF1>if</span><span class=cF0> (sent &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1403"></a> {
<a name="l1404"></a> buffer += sent;
<a name="l1405"></a> total += sent;
<a name="l1406"></a> length -= sent;
<a name="l1407"></a> }
<a name="l1408"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1409"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1410"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1411"></a>
<a name="l1412"></a> </span><span class=cF1>return</span><span class=cF0> total;
<a name="l1413"></a>}
<a name="l1414"></a>
<a name="l1415"></a></span><span class=cF9>I64</span><span class=cF0> TCPSocketSendString(CTCPSocket *tcp_socket, </span><span class=cF1>U8</span><span class=cF0> *string)
<a name="l1416"></a>{
<a name="l1417"></a> </span><span class=cF1>return</span><span class=cF0> TCPSocketSendAll(tcp_socket, string, </span><span class=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>string</span><span class=cF7>)</span><span class=cF0>);
<a name="l1418"></a>}
<a name="l1419"></a>
<a name="l1420"></a>CTCPSocket *TCPConnectionCreate(</span><span class=cF1>U8</span><span class=cF0> *hostname, </span><span class=cF9>U16</span><span class=cF0> port)
<a name="l1421"></a>{
<a name="l1422"></a> CSocketAddressIPV4 socket_addr;
<a name="l1423"></a> CAddressInfo *current;
<a name="l1424"></a> CAddressInfo *info = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l1425"></a> </span><span class=cF9>I64</span><span class=cF0> error = DNSAddressInfoGet(hostname, </span><span class=cF3>NULL</span><span class=cF0>, &amp;info);
<a name="l1426"></a> CTCPSocket *result;
<a name="l1427"></a>
<a name="l1428"></a> </span><span class=cF1>if</span><span class=cF0> (error &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1429"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1430"></a> NetErr(</span><span class=cF6>&quot;TCP CONNECTION CREATE: Failed at DNSAddressInfoGet.&quot;</span><span class=cF0>);
<a name="l1431"></a> AddressInfoFree(info);
<a name="l1432"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l1433"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1434"></a>
<a name="l1435"></a> </span><span class=cF1>if</span><span class=cF0> (error &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1436"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1437"></a> NetErr(</span><span class=cF6>&quot;TCP CONNECTION CREATE: Failed at DNSAddressInfoGet.&quot;</span><span class=cF0>);
<a name="l1438"></a> AddressInfoFree(info);
<a name="l1439"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l1440"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1441"></a>
<a name="l1442"></a> socket_addr.family = AF_INET;
<a name="l1443"></a> socket_addr.port = </span><span class=cF5>EndianU16</span><span class=cF0>(port);
<a name="l1444"></a> socket_addr.address.address = INADDR_ANY;
<a name="l1445"></a>
<a name="l1446"></a> current = info;
<a name="l1447"></a> </span><span class=cF1>while</span><span class=cF0> (current)
<a name="l1448"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1449"></a>
<a name="l1450"></a> </span><span class=cF1>if</span><span class=cF0> (current-&gt;family == AF_INET &amp;&amp; </span><span class=cF7>(</span><span class=cF0>current-&gt;socket_type == </span><span class=cFE>0</span><span class=cF0> || current-&gt;socket_type == SOCKET_STREAM</span><span class=cF7>)</span><span class=cF0>)
<a name="l1451"></a> { </span><span class=cF2>// TODO: IPV6 support !</span><span class=cF0>
<a name="l1452"></a> socket_addr.address.address = </span><span class=cF5>EndianU32</span><span class=cF0>(current-&gt;address</span><span class=cF7>(</span><span class=cF0>CSocketAddressIPV4 *</span><span class=cF7>)</span><span class=cF0>-&gt;address.address); </span><span class=cF2>// ?? why are bits flipped here</span><span class=cF0>
<a name="l1453"></a> AddressInfoFree(info);
<a name="l1454"></a>
<a name="l1455"></a> result = TCPSocket(AF_INET);
<a name="l1456"></a> </span><span class=cF1>if</span><span class=cF0> (!result)
<a name="l1435"></a> socket_addr.family = AF_INET;
<a name="l1436"></a> socket_addr.port = </span><span class=cF5>EndianU16</span><span class=cF0>(port);
<a name="l1437"></a> socket_addr.address.address = INADDR_ANY;
<a name="l1438"></a>
<a name="l1439"></a> current = info;
<a name="l1440"></a> </span><span class=cF1>while</span><span class=cF0> (current)
<a name="l1441"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1442"></a>
<a name="l1443"></a> </span><span class=cF1>if</span><span class=cF0> (current-&gt;family == AF_INET &amp;&amp; </span><span class=cF7>(</span><span class=cF0>current-&gt;socket_type == </span><span class=cFE>0</span><span class=cF0> || current-&gt;socket_type == SOCKET_STREAM</span><span class=cF7>)</span><span class=cF0>)
<a name="l1444"></a> { </span><span class=cF2>// TODO: IPV6 support !</span><span class=cF0>
<a name="l1445"></a> socket_addr.address.address = </span><span class=cF5>EndianU32</span><span class=cF0>(current-&gt;address</span><span class=cF7>(</span><span class=cF0>CSocketAddressIPV4 *</span><span class=cF7>)</span><span class=cF0>-&gt;address.address); </span><span class=cF2>// ?? why are bits flipped here</span><span class=cF0>
<a name="l1446"></a> AddressInfoFree(info);
<a name="l1447"></a>
<a name="l1448"></a> result = TCPSocket(AF_INET);
<a name="l1449"></a> </span><span class=cF1>if</span><span class=cF0> (!result)
<a name="l1450"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1451"></a> NetErr(</span><span class=cF6>&quot;TCP CONNECTION CREATE: Failed to create new TCP Socket.&quot;</span><span class=cF0>);
<a name="l1452"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l1453"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1454"></a> result-&gt;timeout = TCP_TIMEOUT * </span><span class=cFE>3</span><span class=cF0>; </span><span class=cF2>// generous</span><span class=cF0>
<a name="l1455"></a> error = TCPSocketConnect(result, &amp;socket_addr);
<a name="l1456"></a> </span><span class=cF1>if</span><span class=cF0> (error &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1457"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1458"></a> NetErr(</span><span class=cF6>&quot;TCP CONNECTION CREATE: Failed to create new TCP Socket.&quot;</span><span class=cF0>);
<a name="l1459"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l1460"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1461"></a> result-&gt;timeout = TCP_TIMEOUT * </span><span class=cFE>3</span><span class=cF0>; </span><span class=cF2>// generous</span><span class=cF0>
<a name="l1462"></a> error = TCPSocketConnect(result, &amp;socket_addr);
<a name="l1463"></a> </span><span class=cF1>if</span><span class=cF0> (error &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l1464"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1465"></a> NetErr(</span><span class=cF6>&quot;TCP CONNECTION CREATE: Failed to connect TCP Socket to address.&quot;</span><span class=cF0>);
<a name="l1466"></a> TCPSocketClose(result);
<a name="l1467"></a> </span><span class=cF1>return</span><span class=cF0> error;
<a name="l1468"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1469"></a>
<a name="l1470"></a> </span><span class=cF1>return</span><span class=cF0> result;
<a name="l1471"></a> }
<a name="l1472"></a>
<a name="l1473"></a> current = current-&gt;next;
<a name="l1474"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1458"></a> NetErr(</span><span class=cF6>&quot;TCP CONNECTION CREATE: Failed to connect TCP Socket to address.&quot;</span><span class=cF0>);
<a name="l1459"></a> TCPSocketClose(result);
<a name="l1460"></a> </span><span class=cF1>return</span><span class=cF0> error;
<a name="l1461"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1462"></a>
<a name="l1463"></a> </span><span class=cF1>return</span><span class=cF0> result;
<a name="l1464"></a> }
<a name="l1465"></a>
<a name="l1466"></a> current = current-&gt;next;
<a name="l1467"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1468"></a>
<a name="l1469"></a> NetErr(</span><span class=cF6>&quot;TCP CONNECTION CREATE: Failed to find a suitable address.&quot;</span><span class=cF0>);
<a name="l1470"></a>
<a name="l1471"></a> AddressInfoFree(info);
<a name="l1472"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l1473"></a>
<a name="l1474"></a>}
<a name="l1475"></a>
<a name="l1476"></a> NetErr(</span><span class=cF6>&quot;TCP CONNECTION CREATE: Failed to find a suitable address.&quot;</span><span class=cF0>);
<a name="l1477"></a>
<a name="l1478"></a> AddressInfoFree(info);
<a name="l1479"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l1480"></a>
<a name="l1481"></a>}
<a name="l1482"></a>
<a name="l1483"></a></span><span class=cF1>U0</span><span class=cF0> TCPTreeNodeRep(CTCPTreeNode *node)
<a name="l1484"></a>{
<a name="l1485"></a> CTCPTreeQueue *queue = node-&gt;queue-&gt;next;
<a name="l1486"></a> CTCPSocket *socket;
<a name="l1487"></a> CSocketAddressIPV4 *ipv4_addr;
<a name="l1488"></a> CSocketAddressIPV6 *ipv6_addr;
<a name="l1489"></a> </span><span class=cF1>U8</span><span class=cF0> *string;
<a name="l1490"></a> CTCPAcceptQueue *pending;
<a name="l1491"></a>
<a name="l1476"></a></span><span class=cF1>U0</span><span class=cF0> TCPTreeNodeRep(CTCPTreeNode *node)
<a name="l1477"></a>{
<a name="l1478"></a> CTCPTreeQueue *queue = node-&gt;queue-&gt;next;
<a name="l1479"></a> CTCPSocket *socket;
<a name="l1480"></a> CSocketAddressIPV4 *ipv4_addr;
<a name="l1481"></a> CSocketAddressIPV6 *ipv6_addr;
<a name="l1482"></a> </span><span class=cF1>U8</span><span class=cF0> *string;
<a name="l1483"></a> CTCPAcceptQueue *pending;
<a name="l1484"></a>
<a name="l1485"></a>
<a name="l1486"></a> </span><span class=cF6>&quot;Local Port $YELLOW$%d$FG$ (TCP Node @ $CYAN$0x%X$FG$):\n&quot;</span><span class=cF0>, node-&gt;value, node;
<a name="l1487"></a>
<a name="l1488"></a> </span><span class=cF1>while</span><span class=cF0> (queue != node-&gt;queue)
<a name="l1489"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1490"></a>
<a name="l1491"></a> socket = queue-&gt;socket;
<a name="l1492"></a>
<a name="l1493"></a> </span><span class=cF6>&quot;Local Port $YELLOW$%d$FG$ (TCP Node @ $CYAN$0x%X$FG$):\n&quot;</span><span class=cF0>, node-&gt;value, node;
<a name="l1494"></a>
<a name="l1495"></a> </span><span class=cF1>while</span><span class=cF0> (queue != node-&gt;queue)
<a name="l1496"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1497"></a>
<a name="l1498"></a> socket = queue-&gt;socket;
<a name="l1499"></a>
<a name="l1500"></a> </span><span class=cF1>switch</span><span class=cF0> (socket-&gt;destination_address.family)
<a name="l1501"></a> {
<a name="l1502"></a>
<a name="l1503"></a> </span><span class=cF1>case</span><span class=cF0> AF_UNSPEC:
<a name="l1504"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1505"></a>
<a name="l1506"></a> </span><span class=cF1>case</span><span class=cF0> AF_INET:
<a name="l1507"></a> ipv4_addr = &amp;socket-&gt;destination_address;
<a name="l1508"></a> string = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>&quot;%d.%d.%d.%d&quot;</span><span class=cF0>,
<a name="l1509"></a> ipv4_addr-&gt;address.address.u8[</span><span class=cFE>3</span><span class=cF0>],
<a name="l1510"></a> ipv4_addr-&gt;address.address.u8[</span><span class=cFE>2</span><span class=cF0>],
<a name="l1511"></a> ipv4_addr-&gt;address.address.u8[</span><span class=cFE>1</span><span class=cF0>],
<a name="l1512"></a> ipv4_addr-&gt;address.address.u8[</span><span class=cFE>0</span><span class=cF0>]); </span><span class=cF2>// todo: kludge, endianness...</span><span class=cF0>
<a name="l1513"></a>
<a name="l1514"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>$BROWN$%s$FG$ Destination Port $YELLOW$%d$FG$ (TCP Tree Queue @ $CYAN$0x%X$FG$):\n&quot;</span><span class=cF0>,
<a name="l1515"></a> string, </span><span class=cF5>EndianU16</span><span class=cF0>(ipv4_addr-&gt;port), queue;
<a name="l1516"></a> </span><span class=cF5>Free</span><span class=cF0>(string);
<a name="l1493"></a> </span><span class=cF1>switch</span><span class=cF0> (socket-&gt;destination_address.family)
<a name="l1494"></a> {
<a name="l1495"></a>
<a name="l1496"></a> </span><span class=cF1>case</span><span class=cF0> AF_UNSPEC:
<a name="l1497"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1498"></a>
<a name="l1499"></a> </span><span class=cF1>case</span><span class=cF0> AF_INET:
<a name="l1500"></a> ipv4_addr = &amp;socket-&gt;destination_address;
<a name="l1501"></a> string = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>&quot;%d.%d.%d.%d&quot;</span><span class=cF0>,
<a name="l1502"></a> ipv4_addr-&gt;address.address.u8[</span><span class=cFE>3</span><span class=cF0>],
<a name="l1503"></a> ipv4_addr-&gt;address.address.u8[</span><span class=cFE>2</span><span class=cF0>],
<a name="l1504"></a> ipv4_addr-&gt;address.address.u8[</span><span class=cFE>1</span><span class=cF0>],
<a name="l1505"></a> ipv4_addr-&gt;address.address.u8[</span><span class=cFE>0</span><span class=cF0>]); </span><span class=cF2>// todo: kludge, endianness...</span><span class=cF0>
<a name="l1506"></a>
<a name="l1507"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>$BROWN$%s$FG$ Destination Port $YELLOW$%d$FG$ (TCP Tree Queue @ $CYAN$0x%X$FG$):\n&quot;</span><span class=cF0>,
<a name="l1508"></a> string, </span><span class=cF5>EndianU16</span><span class=cF0>(ipv4_addr-&gt;port), queue;
<a name="l1509"></a> </span><span class=cF5>Free</span><span class=cF0>(string);
<a name="l1510"></a>
<a name="l1511"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1512"></a>
<a name="l1513"></a> </span><span class=cF1>case</span><span class=cF0> AF_INET6:
<a name="l1514"></a> ipv6_addr = &amp;socket-&gt;destination_address;
<a name="l1515"></a>
<a name="l1516"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1517"></a>
<a name="l1518"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1519"></a>
<a name="l1520"></a> </span><span class=cF1>case</span><span class=cF0> AF_INET6:
<a name="l1521"></a> ipv6_addr = &amp;socket-&gt;destination_address;
<a name="l1518"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l1519"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1520"></a>
<a name="l1521"></a> }
<a name="l1522"></a>
<a name="l1523"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1523"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>Timeout: %dms\n&quot;</span><span class=cF0>, socket-&gt;timeout;
<a name="l1524"></a>
<a name="l1525"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l1526"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1527"></a>
<a name="l1528"></a> }
<a name="l1529"></a>
<a name="l1530"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>Timeout: %dms\n&quot;</span><span class=cF0>, socket-&gt;timeout;
<a name="l1531"></a>
<a name="l1532"></a> pending = socket-&gt;accept_queue-&gt;next;
<a name="l1533"></a>
<a name="l1534"></a> </span><span class=cF1>while</span><span class=cF0> (pending != socket-&gt;accept_queue-&gt;next)
<a name="l1535"></a> {
<a name="l1536"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>Pending connection from $BROWN$%d.%d.%d.%d$FG$:&quot;</span><span class=cF0>,
<a name="l1537"></a> pending-&gt;ipv4_address.u8[</span><span class=cFE>3</span><span class=cF0>],
<a name="l1538"></a> pending-&gt;ipv4_address.u8[</span><span class=cFE>2</span><span class=cF0>],
<a name="l1539"></a> pending-&gt;ipv4_address.u8[</span><span class=cFE>1</span><span class=cF0>],
<a name="l1540"></a> pending-&gt;ipv4_address.u8[</span><span class=cFE>0</span><span class=cF0>]; </span><span class=cF2>//todo: kludge, endianness?</span><span class=cF0>
<a name="l1525"></a> pending = socket-&gt;accept_queue-&gt;next;
<a name="l1526"></a>
<a name="l1527"></a> </span><span class=cF1>while</span><span class=cF0> (pending != socket-&gt;accept_queue-&gt;next)
<a name="l1528"></a> {
<a name="l1529"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>Pending connection from $BROWN$%d.%d.%d.%d$FG$:&quot;</span><span class=cF0>,
<a name="l1530"></a> pending-&gt;ipv4_address.u8[</span><span class=cFE>3</span><span class=cF0>],
<a name="l1531"></a> pending-&gt;ipv4_address.u8[</span><span class=cFE>2</span><span class=cF0>],
<a name="l1532"></a> pending-&gt;ipv4_address.u8[</span><span class=cFE>1</span><span class=cF0>],
<a name="l1533"></a> pending-&gt;ipv4_address.u8[</span><span class=cFE>0</span><span class=cF0>]; </span><span class=cF2>//todo: kludge, endianness?</span><span class=cF0>
<a name="l1534"></a>
<a name="l1535"></a> pending = pending-&gt;next;
<a name="l1536"></a> }
<a name="l1537"></a>
<a name="l1538"></a>
<a name="l1539"></a> queue = queue-&gt;next;
<a name="l1540"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1541"></a>
<a name="l1542"></a> pending = pending-&gt;next;
<a name="l1543"></a> }
<a name="l1542"></a> </span><span class=cF6>&quot;\n&quot;</span><span class=cF0>;
<a name="l1543"></a>}
<a name="l1544"></a>
<a name="l1545"></a>
<a name="l1546"></a> queue = queue-&gt;next;
<a name="l1547"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1548"></a>
<a name="l1549"></a> </span><span class=cF6>&quot;\n&quot;</span><span class=cF0>;
<a name="l1550"></a>}
<a name="l1545"></a></span><span class=cF1>U0</span><span class=cF0> TCPRep()
<a name="l1546"></a>{
<a name="l1547"></a> CTCPTreeNode *node = tcp_globals.bound_socket_tree;
<a name="l1548"></a> CTCPRepEntry *head;
<a name="l1549"></a> CTCPRepEntry *entry;
<a name="l1550"></a> CTCPRepEntry *temp_entry;
<a name="l1551"></a>
<a name="l1552"></a></span><span class=cF1>U0</span><span class=cF0> TCPRep()
<a name="l1553"></a>{
<a name="l1554"></a> CTCPTreeNode *node = tcp_globals.bound_socket_tree;
<a name="l1555"></a> CTCPRepEntry *head;
<a name="l1556"></a> CTCPRepEntry *entry;
<a name="l1557"></a> CTCPRepEntry *temp_entry;
<a name="l1552"></a> </span><span class=cF6>&quot;$LTBLUE$TCP Report:$FG$\n\n&quot;</span><span class=cF0>;
<a name="l1553"></a>
<a name="l1554"></a> </span><span class=cF1>if</span><span class=cF0> (node)
<a name="l1555"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1556"></a> head = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPRepEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l1557"></a> </span><span class=cF5>QueueInit</span><span class=cF0>(head); </span><span class=cF2>// no QueueRemove the head</span><span class=cF0>
<a name="l1558"></a>
<a name="l1559"></a> </span><span class=cF6>&quot;$LTBLUE$TCP Report:$FG$\n\n&quot;</span><span class=cF0>;
<a name="l1560"></a>
<a name="l1561"></a> </span><span class=cF1>if</span><span class=cF0> (node)
<a name="l1562"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1563"></a> head = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPRepEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l1564"></a> </span><span class=cF5>QueueInit</span><span class=cF0>(head); </span><span class=cF2>// no QueueRemove the head</span><span class=cF0>
<a name="l1565"></a>
<a name="l1566"></a> entry = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPRepEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l1567"></a> entry-&gt;node = node;
<a name="l1568"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(entry, head);
<a name="l1569"></a>
<a name="l1570"></a> </span><span class=cF2>// perform depth-first-search while Entry Queue has nodes not fully visited.</span><span class=cF0>
<a name="l1571"></a> </span><span class=cF1>while</span><span class=cF0> (entry != head)
<a name="l1572"></a> {
<a name="l1573"></a> </span><span class=cF1>if</span><span class=cF0> (entry-&gt;node-&gt;left)
<a name="l1574"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>// if node has one, add an Entry for the left branch, continue loop.</span><span class=cF0>
<a name="l1575"></a> temp_entry = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPRepEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l1576"></a> temp_entry-&gt;node = entry-&gt;node-&gt;left;
<a name="l1577"></a> </span><span class=cF5>QueueInsertRev</span><span class=cF0>(temp_entry, head);
<a name="l1578"></a>
<a name="l1579"></a> </span><span class=cF2>// if left branch, but no right: toss early, now fully traveled.</span><span class=cF0>
<a name="l1580"></a> </span><span class=cF1>if</span><span class=cF0> (!entry-&gt;node-&gt;right)
<a name="l1581"></a> {
<a name="l1582"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(entry);
<a name="l1583"></a> TCPTreeNodeRep(entry-&gt;node);
<a name="l1584"></a> </span><span class=cF5>Free</span><span class=cF0>(entry);
<a name="l1585"></a> }
<a name="l1586"></a>
<a name="l1587"></a> entry = temp_entry;
<a name="l1588"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1589"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (entry-&gt;node-&gt;right)
<a name="l1590"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>// if no left, but right: add right to queue, pop Entry, Rep, set entry to right.</span><span class=cF0>
<a name="l1591"></a> temp_entry = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPRepEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l1592"></a> temp_entry-&gt;node = entry-&gt;node-&gt;right;
<a name="l1593"></a> </span><span class=cF5>QueueInsertRev</span><span class=cF0>(temp_entry, head);
<a name="l1594"></a>
<a name="l1595"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(entry);
<a name="l1596"></a> TCPTreeNodeRep(entry-&gt;node);
<a name="l1597"></a> </span><span class=cF5>Free</span><span class=cF0>(entry);
<a name="l1598"></a>
<a name="l1599"></a> entry = temp_entry;
<a name="l1600"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1601"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1602"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>// pop Entry, Rep, if last Entry in Queue has right add it, pop &amp; Rep travelled Entry, entry = right.</span><span class=cF0>
<a name="l1603"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(entry);
<a name="l1604"></a> TCPTreeNodeRep(entry-&gt;node);
<a name="l1605"></a> </span><span class=cF5>Free</span><span class=cF0>(entry);
<a name="l1606"></a>
<a name="l1607"></a> </span><span class=cF1>if</span><span class=cF0> (head-&gt;last != head)
<a name="l1608"></a> {
<a name="l1609"></a> temp_entry = head-&gt;last;
<a name="l1610"></a>
<a name="l1611"></a> </span><span class=cF1>if</span><span class=cF0> (temp_entry-&gt;node-&gt;right)
<a name="l1612"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1613"></a> entry = temp_entry;
<a name="l1614"></a>
<a name="l1615"></a> temp_entry = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPRepEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l1616"></a> temp_entry-&gt;node = entry-&gt;node-&gt;right;
<a name="l1617"></a> </span><span class=cF5>QueueInsertRev</span><span class=cF0>(temp_entry, head);
<a name="l1618"></a>
<a name="l1619"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(entry);
<a name="l1620"></a> TCPTreeNodeRep(entry-&gt;node);
<a name="l1621"></a> </span><span class=cF5>Free</span><span class=cF0>(entry);
<a name="l1622"></a>
<a name="l1623"></a> entry = temp_entry;
<a name="l1624"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1625"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1626"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1627"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(temp_entry);
<a name="l1628"></a> TCPTreeNodeRep(temp_entry-&gt;node);
<a name="l1629"></a> </span><span class=cF5>Free</span><span class=cF0>(temp_entry);
<a name="l1630"></a>
<a name="l1631"></a> entry = head-&gt;last;
<a name="l1632"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1633"></a> }
<a name="l1634"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1635"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1636"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1637"></a> }
<a name="l1559"></a> entry = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPRepEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l1560"></a> entry-&gt;node = node;
<a name="l1561"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(entry, head);
<a name="l1562"></a>
<a name="l1563"></a> </span><span class=cF2>// perform depth-first-search while Entry Queue has nodes not fully visited.</span><span class=cF0>
<a name="l1564"></a> </span><span class=cF1>while</span><span class=cF0> (entry != head)
<a name="l1565"></a> {
<a name="l1566"></a> </span><span class=cF1>if</span><span class=cF0> (entry-&gt;node-&gt;left)
<a name="l1567"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>// if node has one, add an Entry for the left branch, continue loop.</span><span class=cF0>
<a name="l1568"></a> temp_entry = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPRepEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l1569"></a> temp_entry-&gt;node = entry-&gt;node-&gt;left;
<a name="l1570"></a> </span><span class=cF5>QueueInsertRev</span><span class=cF0>(temp_entry, head);
<a name="l1571"></a>
<a name="l1572"></a> </span><span class=cF2>// if left branch, but no right: toss early, now fully traveled.</span><span class=cF0>
<a name="l1573"></a> </span><span class=cF1>if</span><span class=cF0> (!entry-&gt;node-&gt;right)
<a name="l1574"></a> {
<a name="l1575"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(entry);
<a name="l1576"></a> TCPTreeNodeRep(entry-&gt;node);
<a name="l1577"></a> </span><span class=cF5>Free</span><span class=cF0>(entry);
<a name="l1578"></a> }
<a name="l1579"></a>
<a name="l1580"></a> entry = temp_entry;
<a name="l1581"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1582"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (entry-&gt;node-&gt;right)
<a name="l1583"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>// if no left, but right: add right to queue, pop Entry, Rep, set entry to right.</span><span class=cF0>
<a name="l1584"></a> temp_entry = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPRepEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l1585"></a> temp_entry-&gt;node = entry-&gt;node-&gt;right;
<a name="l1586"></a> </span><span class=cF5>QueueInsertRev</span><span class=cF0>(temp_entry, head);
<a name="l1587"></a>
<a name="l1588"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(entry);
<a name="l1589"></a> TCPTreeNodeRep(entry-&gt;node);
<a name="l1590"></a> </span><span class=cF5>Free</span><span class=cF0>(entry);
<a name="l1591"></a>
<a name="l1592"></a> entry = temp_entry;
<a name="l1593"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1594"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1595"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>// pop Entry, Rep, if last Entry in Queue has right add it, pop &amp; Rep travelled Entry, entry = right.</span><span class=cF0>
<a name="l1596"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(entry);
<a name="l1597"></a> TCPTreeNodeRep(entry-&gt;node);
<a name="l1598"></a> </span><span class=cF5>Free</span><span class=cF0>(entry);
<a name="l1599"></a>
<a name="l1600"></a> </span><span class=cF1>if</span><span class=cF0> (head-&gt;last != head)
<a name="l1601"></a> {
<a name="l1602"></a> temp_entry = head-&gt;last;
<a name="l1603"></a>
<a name="l1604"></a> </span><span class=cF1>if</span><span class=cF0> (temp_entry-&gt;node-&gt;right)
<a name="l1605"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1606"></a> entry = temp_entry;
<a name="l1607"></a>
<a name="l1608"></a> temp_entry = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPRepEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l1609"></a> temp_entry-&gt;node = entry-&gt;node-&gt;right;
<a name="l1610"></a> </span><span class=cF5>QueueInsertRev</span><span class=cF0>(temp_entry, head);
<a name="l1611"></a>
<a name="l1612"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(entry);
<a name="l1613"></a> TCPTreeNodeRep(entry-&gt;node);
<a name="l1614"></a> </span><span class=cF5>Free</span><span class=cF0>(entry);
<a name="l1615"></a>
<a name="l1616"></a> entry = temp_entry;
<a name="l1617"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1618"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1619"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1620"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(temp_entry);
<a name="l1621"></a> TCPTreeNodeRep(temp_entry-&gt;node);
<a name="l1622"></a> </span><span class=cF5>Free</span><span class=cF0>(temp_entry);
<a name="l1623"></a>
<a name="l1624"></a> entry = head-&gt;last;
<a name="l1625"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1626"></a> }
<a name="l1627"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1628"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1629"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1630"></a> }
<a name="l1631"></a>
<a name="l1632"></a> </span><span class=cF5>Free</span><span class=cF0>(head);
<a name="l1633"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1634"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1635"></a> </span><span class=cF6>&quot;No TCP Sockets currently bound.\n\n&quot;</span><span class=cF0>;
<a name="l1636"></a>}
<a name="l1637"></a>
<a name="l1638"></a>
<a name="l1639"></a> </span><span class=cF5>Free</span><span class=cF0>(head);
<a name="l1640"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1641"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1642"></a> </span><span class=cF6>&quot;No TCP Sockets currently bound.\n\n&quot;</span><span class=cF0>;
<a name="l1643"></a>}
<a name="l1644"></a>
<a name="l1645"></a>
<a name="l1646"></a>TCPGlobalsInit;</span></pre></body>
<a name="l1639"></a>TCPGlobalsInit;
</span></pre></body>
</html>

View file

@ -41,355 +41,357 @@ body {background-color:#1f1f1f;}
<a name="l14"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_ESTABLISHED:
<a name="l15"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_FIN_WAIT1:
<a name="l16"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_FIN_WAIT2: </span><span class=cF2>// FIN2 check is ommitted in Shrine, yet used in below logic. Adding.</span><span class=cF0>
<a name="l17"></a>
<a name="l18"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE VALID SEQ: Updating data in receive buffer.&quot;</span><span class=cF0>);
<a name="l19"></a>
<a name="l20"></a> </span><span class=cF2>// TODO: review while loops, make sure we DO NOT HANG INTERRUPT HANDLER.</span><span class=cF0>
<a name="l21"></a> write_position = tcp_socket-&gt;write_position;
<a name="l22"></a>
<a name="l23"></a> </span><span class=cF1>while</span><span class=cF0> (length &amp;&amp; segment_seq_num != tcp_socket-&gt;next_recv_seq_num)
<a name="l24"></a> {
<a name="l25"></a> segment_seq_num = (segment_seq_num + </span><span class=cFE>1</span><span class=cF0>) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l26"></a> data++;
<a name="l27"></a> length--;
<a name="l28"></a> }
<a name="l29"></a>
<a name="l30"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; length; i++)
<a name="l31"></a> {
<a name="l32"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>next_position = (write_position + 1) &amp; (tcp_socket-&gt;receive_buffer_size - 1);</span><span class=cF0>
<a name="l33"></a> next_position = (write_position + </span><span class=cFE>1</span><span class=cF0>) % tcp_socket-&gt;receive_buffer_size;
<a name="l34"></a>
<a name="l35"></a> </span><span class=cF1>if</span><span class=cF0> (next_position == tcp_socket-&gt;read_position)
<a name="l36"></a> </span><span class=cF1>break</span><span class=cF0>; </span><span class=cF2>// ...?</span><span class=cF0>
<a name="l37"></a>
<a name="l38"></a> tcp_socket-&gt;receive_buffer[write_position] = data[i];
<a name="l39"></a> write_position = next_position;
<a name="l40"></a> }
<a name="l41"></a>
<a name="l42"></a> tcp_socket-&gt;write_position = write_position;
<a name="l43"></a> tcp_socket-&gt;next_recv_seq_num += i;
<a name="l44"></a>
<a name="l45"></a> </span><span class=cF1>if</span><span class=cF0> (i &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l46"></a> must_ack = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l47"></a>
<a name="l48"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_FIN</span><span class=cF7>)</span><span class=cF0>)
<a name="l49"></a> {
<a name="l50"></a> must_ack = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l51"></a> tcp_socket-&gt;next_recv_seq_num++;
<a name="l52"></a>
<a name="l53"></a> </span><span class=cF1>switch</span><span class=cF0> (tcp_socket-&gt;state)
<a name="l54"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l55"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_ESTABLISHED:
<a name="l56"></a> tcp_socket-&gt;state = TCP_STATE_CLOSE_WAIT;
<a name="l57"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l58"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_FIN_WAIT1:
<a name="l59"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_FIN_WAIT2:
<a name="l60"></a> tcp_socket-&gt;state = TCP_STATE_TIME_WAIT;
<a name="l61"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l62"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF2>// review RFC, whether more state checks needed here.</span><span class=cF0>
<a name="l63"></a> }
<a name="l64"></a>
<a name="l17"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_CLOSE_WAIT: </span><span class=cF2>// allowing data to be pushed to receive buffer during closing state</span><span class=cF0>
<a name="l18"></a>
<a name="l19"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE VALID SEQ: Updating data in receive buffer.&quot;</span><span class=cF0>);
<a name="l20"></a>
<a name="l21"></a> </span><span class=cF2>// TODO: review while loops, make sure we DO NOT HANG INTERRUPT HANDLER.</span><span class=cF0>
<a name="l22"></a> write_position = tcp_socket-&gt;write_position;
<a name="l23"></a>
<a name="l24"></a> </span><span class=cF1>while</span><span class=cF0> (length &amp;&amp; segment_seq_num != tcp_socket-&gt;next_recv_seq_num)
<a name="l25"></a> {
<a name="l26"></a> segment_seq_num = (segment_seq_num + </span><span class=cFE>1</span><span class=cF0>) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l27"></a> data++;
<a name="l28"></a> length--;
<a name="l29"></a> }
<a name="l30"></a>
<a name="l31"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; length; i++)
<a name="l32"></a> {
<a name="l33"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>next_position = (write_position + 1) &amp; (tcp_socket-&gt;receive_buffer_size - 1);</span><span class=cF0>
<a name="l34"></a> next_position = (write_position + </span><span class=cFE>1</span><span class=cF0>) % tcp_socket-&gt;receive_buffer_size;
<a name="l35"></a>
<a name="l36"></a> </span><span class=cF1>if</span><span class=cF0> (next_position == tcp_socket-&gt;read_position)
<a name="l37"></a> </span><span class=cF1>break</span><span class=cF0>; </span><span class=cF2>// ...?</span><span class=cF0>
<a name="l38"></a>
<a name="l39"></a> tcp_socket-&gt;receive_buffer[write_position] = data[i];
<a name="l40"></a> write_position = next_position;
<a name="l41"></a> }
<a name="l42"></a>
<a name="l43"></a> tcp_socket-&gt;write_position = write_position;
<a name="l44"></a> tcp_socket-&gt;next_recv_seq_num += i;
<a name="l45"></a>
<a name="l46"></a> </span><span class=cF1>if</span><span class=cF0> (i &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l47"></a> must_ack = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l48"></a>
<a name="l49"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_FIN</span><span class=cF7>)</span><span class=cF0>)
<a name="l50"></a> {
<a name="l51"></a> must_ack = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l52"></a> tcp_socket-&gt;next_recv_seq_num++;
<a name="l53"></a>
<a name="l54"></a> </span><span class=cF1>switch</span><span class=cF0> (tcp_socket-&gt;state)
<a name="l55"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l56"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_ESTABLISHED:
<a name="l57"></a> tcp_socket-&gt;state = TCP_STATE_CLOSE_WAIT;
<a name="l58"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l59"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_FIN_WAIT1:
<a name="l60"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_FIN_WAIT2:
<a name="l61"></a> tcp_socket-&gt;state = TCP_STATE_TIME_WAIT;
<a name="l62"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l63"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF2>// review RFC, whether more state checks needed here.</span><span class=cF0>
<a name="l64"></a> }
<a name="l65"></a>
<a name="l66"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l67"></a>
<a name="l68"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l69"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l70"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l71"></a>
<a name="l72"></a> </span><span class=cF1>return</span><span class=cF0> must_ack;
<a name="l73"></a>}
<a name="l74"></a>
<a name="l66"></a>
<a name="l67"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l68"></a>
<a name="l69"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l70"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l71"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l72"></a>
<a name="l73"></a> </span><span class=cF1>return</span><span class=cF0> must_ack;
<a name="l74"></a>}
<a name="l75"></a>
<a name="l76"></a></span><span class=cF1>Bool</span><span class=cF0> TCPHandleACK(CTCPSocket *tcp_socket, CIPV4Packet *packet, CTCPHeader *header,
<a name="l77"></a> </span><span class=cF9>U32</span><span class=cF0> segment_seq_num, </span><span class=cF9>U32</span><span class=cF0> segment_ack_num, </span><span class=cF9>U32</span><span class=cF0> segment_length)
<a name="l78"></a>{ </span><span class=cF2>// returns the value of must_ack, used later in TCPHandleSocket</span><span class=cF0>
<a name="l79"></a> </span><span class=cF9>I64</span><span class=cF0> ack_relative;
<a name="l80"></a> </span><span class=cF9>I64</span><span class=cF0> ack_next_relative;
<a name="l81"></a>
<a name="l82"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_ACK</span><span class=cF7>)</span><span class=cF0>)
<a name="l83"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l84"></a> ack_relative = (segment_ack_num - tcp_socket-&gt;first_unacked_seq) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l85"></a> ack_next_relative = (tcp_socket-&gt;next_send_seq_num - tcp_socket-&gt;first_unacked_seq) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l86"></a>
<a name="l87"></a> </span><span class=cF2>// Shrine has comments here about RFC poor wording,</span><span class=cF0>
<a name="l88"></a> </span><span class=cF2>// TODO: review RFC and implement more refined approach.</span><span class=cF0>
<a name="l89"></a> </span><span class=cF1>if</span><span class=cF0> (ack_relative &lt;= ack_next_relative)
<a name="l90"></a> {
<a name="l91"></a> TCPAcknowledgePacket(tcp_socket, segment_ack_num);
<a name="l92"></a>
<a name="l93"></a> </span><span class=cF2>// &quot;Accept ACK&quot;</span><span class=cF0>
<a name="l94"></a> tcp_socket-&gt;first_unacked_seq = segment_ack_num;
<a name="l95"></a>
<a name="l96"></a> </span><span class=cF1>switch</span><span class=cF0> (tcp_socket-&gt;state)
<a name="l97"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l98"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_SYN_SENT:
<a name="l99"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE ACK: Acceptable ACK; state: SYN_SENT&quot;</span><span class=cF0>);
<a name="l100"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_SYN</span><span class=cF7>)</span><span class=cF0>)
<a name="l101"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l102"></a> </span><span class=cF2>// else, fall-through</span><span class=cF0>
<a name="l103"></a>
<a name="l104"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_SYN_RECEIVED:
<a name="l105"></a> tcp_socket-&gt;state = TCP_STATE_ESTABLISHED;
<a name="l106"></a> tcp_socket-&gt;srtt = </span><span class=cF5>tS</span><span class=cF0> - tcp_socket-&gt;connection_time;
<a name="l107"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l108"></a>
<a name="l109"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l110"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l111"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l112"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE ACK: Acceptable ACK returning; state: 0x%0X&quot;</span><span class=cF0>, tcp_socket-&gt;state);
<a name="l113"></a> }
<a name="l114"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l115"></a> {
<a name="l116"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Invalid ACK.&quot;</span><span class=cF0>);
<a name="l117"></a>
<a name="l118"></a> </span><span class=cF1>switch</span><span class=cF0> (tcp_socket-&gt;state)
<a name="l119"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l120"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_LISTEN:
<a name="l121"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_SYN_SENT:
<a name="l122"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_SYN_RECEIVED:
<a name="l123"></a> TCPSend(packet-&gt;destination_ip_address,
<a name="l124"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;destination_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l125"></a> packet-&gt;source_ip_address,
<a name="l126"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;source_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l127"></a> segment_ack_num,
<a name="l128"></a> segment_seq_num + segment_length,
<a name="l129"></a> TCPF_ACK | TCPF_RST);
<a name="l130"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l131"></a>
<a name="l132"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l133"></a> </span><span class=cF1>if</span><span class=cF0> (IsTCPStateSync</span><span class=cF7>(</span><span class=cF0>tcp_socket</span><span class=cF7>)</span><span class=cF0>)
<a name="l134"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>; </span><span class=cF2>// must ACK the packet.</span><span class=cF0>
<a name="l135"></a>
<a name="l136"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l137"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l138"></a> }
<a name="l139"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l140"></a>
<a name="l141"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>; </span><span class=cF2>// do not need to ACK the packet.</span><span class=cF0>
<a name="l142"></a>}
<a name="l143"></a>
<a name="l144"></a></span><span class=cF1>Bool</span><span class=cF0> TCPHandleReset(CTCPSocket *tcp_socket, CTCPHeader *header, </span><span class=cF1>Bool</span><span class=cF0> is_seq_valid)
<a name="l145"></a>{ </span><span class=cF2>// returns whether or not to stop overall TCP procedure.</span><span class=cF0>
<a name="l146"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_RST</span><span class=cF7>)</span><span class=cF0>)
<a name="l147"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l148"></a> </span><span class=cF1>switch</span><span class=cF0> (tcp_socket-&gt;state)
<a name="l149"></a> {
<a name="l150"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_SYN_SENT:
<a name="l151"></a> </span><span class=cF1>if</span><span class=cF0> (tcp_socket-&gt;first_unacked_seq == tcp_socket-&gt;next_send_seq_num)
<a name="l152"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l153"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Got RST, socket state SYN_SENT. Connection refused.&quot;</span><span class=cF0>);
<a name="l154"></a> tcp_socket-&gt;state = TCP_STATE_CLOSED;
<a name="l155"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l156"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l157"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l158"></a>
<a name="l159"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l160"></a> </span><span class=cF1>if</span><span class=cF0> (is_seq_valid)
<a name="l161"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l162"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Got RST, connection refused by remote host.&quot;</span><span class=cF0>);
<a name="l163"></a> tcp_socket-&gt;state = TCP_STATE_CLOSED;
<a name="l164"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l165"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l166"></a> }
<a name="l167"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l168"></a>
<a name="l169"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l170"></a>}
<a name="l171"></a>
<a name="l172"></a></span><span class=cF1>U0</span><span class=cF0> TCPHandleSocketListen(CTCPSocket *tcp_socket, CIPV4Packet *packet, CTCPHeader *header, </span><span class=cF9>U32</span><span class=cF0> segment_seq_num)
<a name="l173"></a>{ </span><span class=cF2>// if SYN and socket listening, queue up the connection in the socket's accept queue.</span><span class=cF0>
<a name="l174"></a> CTCPAcceptQueue *new_connection;
<a name="l175"></a>
<a name="l176"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_SYN</span><span class=cF7>)</span><span class=cF0> &amp;&amp; </span><span class=cF5>QueueSize</span><span class=cF7>(</span><span class=cF0>tcp_socket-&gt;accept_queue</span><span class=cF7>)</span><span class=cF0> &lt; tcp_socket-&gt;accept_queue_limit)
<a name="l177"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l178"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE SOCKET LISTEN: Adding new connection to Socket accept queue&quot;</span><span class=cF0>);
<a name="l179"></a> new_connection = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPAcceptQueue</span><span class=cF7>)</span><span class=cF0>);
<a name="l180"></a>
<a name="l181"></a> new_connection-&gt;segment_seq_num = segment_seq_num;
<a name="l182"></a> new_connection-&gt;ipv4_address = packet-&gt;source_ip_address;
<a name="l183"></a> new_connection-&gt;port = header-&gt;source_port;
<a name="l184"></a>
<a name="l185"></a> </span><span class=cF5>QueueInsertRev</span><span class=cF0>(new_connection, tcp_socket-&gt;accept_queue);
<a name="l186"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l187"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l188"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>// refuse</span><span class=cF0>
<a name="l189"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE SOCKET LISTEN: Header flags not SYN or Queue full, REFUSING CONNECTION&quot;</span><span class=cF0>);
<a name="l190"></a> TCPSend(packet-&gt;destination_ip_address,
<a name="l191"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;destination_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l192"></a> packet-&gt;source_ip_address,
<a name="l193"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;source_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l194"></a> segment_seq_num + </span><span class=cFE>1</span><span class=cF0>,
<a name="l76"></a>
<a name="l77"></a></span><span class=cF1>Bool</span><span class=cF0> TCPHandleACK(CTCPSocket *tcp_socket, CIPV4Packet *packet, CTCPHeader *header,
<a name="l78"></a> </span><span class=cF9>U32</span><span class=cF0> segment_seq_num, </span><span class=cF9>U32</span><span class=cF0> segment_ack_num, </span><span class=cF9>U32</span><span class=cF0> segment_length)
<a name="l79"></a>{ </span><span class=cF2>// returns the value of must_ack, used later in TCPHandleSocket</span><span class=cF0>
<a name="l80"></a> </span><span class=cF9>I64</span><span class=cF0> ack_relative;
<a name="l81"></a> </span><span class=cF9>I64</span><span class=cF0> ack_next_relative;
<a name="l82"></a>
<a name="l83"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_ACK</span><span class=cF7>)</span><span class=cF0>)
<a name="l84"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l85"></a> ack_relative = (segment_ack_num - tcp_socket-&gt;first_unacked_seq) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l86"></a> ack_next_relative = (tcp_socket-&gt;next_send_seq_num - tcp_socket-&gt;first_unacked_seq) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l87"></a>
<a name="l88"></a> </span><span class=cF2>// Shrine has comments here about RFC poor wording,</span><span class=cF0>
<a name="l89"></a> </span><span class=cF2>// TODO: review RFC and implement more refined approach.</span><span class=cF0>
<a name="l90"></a> </span><span class=cF1>if</span><span class=cF0> (ack_relative &lt;= ack_next_relative)
<a name="l91"></a> {
<a name="l92"></a> TCPAcknowledgePacket(tcp_socket, segment_ack_num);
<a name="l93"></a>
<a name="l94"></a> </span><span class=cF2>// &quot;Accept ACK&quot;</span><span class=cF0>
<a name="l95"></a> tcp_socket-&gt;first_unacked_seq = segment_ack_num;
<a name="l96"></a>
<a name="l97"></a> </span><span class=cF1>switch</span><span class=cF0> (tcp_socket-&gt;state)
<a name="l98"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l99"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_SYN_SENT:
<a name="l100"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE ACK: Acceptable ACK; state: SYN_SENT&quot;</span><span class=cF0>);
<a name="l101"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_SYN</span><span class=cF7>)</span><span class=cF0>)
<a name="l102"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l103"></a> </span><span class=cF2>// else, fall-through</span><span class=cF0>
<a name="l104"></a>
<a name="l105"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_SYN_RECEIVED:
<a name="l106"></a> tcp_socket-&gt;state = TCP_STATE_ESTABLISHED;
<a name="l107"></a> tcp_socket-&gt;srtt = </span><span class=cF5>tS</span><span class=cF0> - tcp_socket-&gt;connection_time;
<a name="l108"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l109"></a>
<a name="l110"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l111"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l112"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l113"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE ACK: Acceptable ACK returning; state: 0x%0X&quot;</span><span class=cF0>, tcp_socket-&gt;state);
<a name="l114"></a> }
<a name="l115"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l116"></a> {
<a name="l117"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Invalid ACK.&quot;</span><span class=cF0>);
<a name="l118"></a>
<a name="l119"></a> </span><span class=cF1>switch</span><span class=cF0> (tcp_socket-&gt;state)
<a name="l120"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l121"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_LISTEN:
<a name="l122"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_SYN_SENT:
<a name="l123"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_SYN_RECEIVED:
<a name="l124"></a> TCPSend(packet-&gt;destination_ip_address,
<a name="l125"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;destination_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l126"></a> packet-&gt;source_ip_address,
<a name="l127"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;source_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l128"></a> segment_ack_num,
<a name="l129"></a> segment_seq_num + segment_length,
<a name="l130"></a> TCPF_ACK | TCPF_RST);
<a name="l131"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l132"></a>
<a name="l133"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l134"></a> </span><span class=cF1>if</span><span class=cF0> (IsTCPStateSync</span><span class=cF7>(</span><span class=cF0>tcp_socket</span><span class=cF7>)</span><span class=cF0>)
<a name="l135"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>; </span><span class=cF2>// must ACK the packet.</span><span class=cF0>
<a name="l136"></a>
<a name="l137"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l138"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l139"></a> }
<a name="l140"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l141"></a>
<a name="l142"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>; </span><span class=cF2>// do not need to ACK the packet.</span><span class=cF0>
<a name="l143"></a>}
<a name="l144"></a>
<a name="l145"></a></span><span class=cF1>Bool</span><span class=cF0> TCPHandleReset(CTCPSocket *tcp_socket, CTCPHeader *header, </span><span class=cF1>Bool</span><span class=cF0> is_seq_valid)
<a name="l146"></a>{ </span><span class=cF2>// returns whether or not to stop overall TCP procedure.</span><span class=cF0>
<a name="l147"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_RST</span><span class=cF7>)</span><span class=cF0>)
<a name="l148"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l149"></a> </span><span class=cF1>switch</span><span class=cF0> (tcp_socket-&gt;state)
<a name="l150"></a> {
<a name="l151"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_SYN_SENT:
<a name="l152"></a> </span><span class=cF1>if</span><span class=cF0> (tcp_socket-&gt;first_unacked_seq == tcp_socket-&gt;next_send_seq_num)
<a name="l153"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l154"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Got RST, socket state SYN_SENT. Connection refused.&quot;</span><span class=cF0>);
<a name="l155"></a> tcp_socket-&gt;state = TCP_STATE_CLOSED;
<a name="l156"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l157"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l158"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l159"></a>
<a name="l160"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l161"></a> </span><span class=cF1>if</span><span class=cF0> (is_seq_valid)
<a name="l162"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l163"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Got RST, connection refused by remote host.&quot;</span><span class=cF0>);
<a name="l164"></a> tcp_socket-&gt;state = TCP_STATE_CLOSED;
<a name="l165"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l166"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l167"></a> }
<a name="l168"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l169"></a>
<a name="l170"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l171"></a>}
<a name="l172"></a>
<a name="l173"></a></span><span class=cF1>U0</span><span class=cF0> TCPHandleSocketListen(CTCPSocket *tcp_socket, CIPV4Packet *packet, CTCPHeader *header, </span><span class=cF9>U32</span><span class=cF0> segment_seq_num)
<a name="l174"></a>{ </span><span class=cF2>// if SYN and socket listening, queue up the connection in the socket's accept queue.</span><span class=cF0>
<a name="l175"></a> CTCPAcceptQueue *new_connection;
<a name="l176"></a>
<a name="l177"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_SYN</span><span class=cF7>)</span><span class=cF0> &amp;&amp; </span><span class=cF5>QueueSize</span><span class=cF7>(</span><span class=cF0>tcp_socket-&gt;accept_queue</span><span class=cF7>)</span><span class=cF0> &lt; tcp_socket-&gt;accept_queue_limit)
<a name="l178"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l179"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE SOCKET LISTEN: Adding new connection to Socket accept queue&quot;</span><span class=cF0>);
<a name="l180"></a> new_connection = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPAcceptQueue</span><span class=cF7>)</span><span class=cF0>);
<a name="l181"></a>
<a name="l182"></a> new_connection-&gt;segment_seq_num = segment_seq_num;
<a name="l183"></a> new_connection-&gt;ipv4_address = packet-&gt;source_ip_address;
<a name="l184"></a> new_connection-&gt;port = header-&gt;source_port;
<a name="l185"></a>
<a name="l186"></a> </span><span class=cF5>QueueInsertRev</span><span class=cF0>(new_connection, tcp_socket-&gt;accept_queue);
<a name="l187"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l188"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l189"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>// refuse</span><span class=cF0>
<a name="l190"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE SOCKET LISTEN: Header flags not SYN or Queue full, REFUSING CONNECTION&quot;</span><span class=cF0>);
<a name="l191"></a> TCPSend(packet-&gt;destination_ip_address,
<a name="l192"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;destination_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l193"></a> packet-&gt;source_ip_address,
<a name="l194"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;source_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l195"></a> segment_seq_num + </span><span class=cFE>1</span><span class=cF0>,
<a name="l196"></a> TCPF_ACK | TCPF_RST);
<a name="l197"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l198"></a>}
<a name="l199"></a>
<a name="l200"></a></span><span class=cF1>U0</span><span class=cF0> TCPHandleSocket(CTCPSocket *tcp_socket, CIPV4Packet *packet, CTCPHeader *header, </span><span class=cF1>U8</span><span class=cF0> *data, </span><span class=cF9>I64</span><span class=cF0> length)
<a name="l201"></a>{
<a name="l202"></a> </span><span class=cF9>U32</span><span class=cF0> segment_length = length;
<a name="l203"></a> </span><span class=cF9>U32</span><span class=cF0> segment_seq_num = </span><span class=cF5>EndianU32</span><span class=cF0>(header-&gt;seq_num);
<a name="l204"></a> </span><span class=cF9>U32</span><span class=cF0> segment_ack_num = </span><span class=cF5>EndianU32</span><span class=cF0>(header-&gt;ack_num);
<a name="l205"></a> </span><span class=cF1>Bool</span><span class=cF0> must_ack = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l206"></a> </span><span class=cF1>Bool</span><span class=cF0> is_seq_valid = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l207"></a> </span><span class=cF9>I64</span><span class=cF0> seq_relative;
<a name="l208"></a> </span><span class=cF9>I64</span><span class=cF0> seq_end_relative;
<a name="l209"></a>
<a name="l210"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_FIN</span><span class=cF7>)</span><span class=cF0>)
<a name="l211"></a> segment_length++;
<a name="l212"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_SYN</span><span class=cF7>)</span><span class=cF0>)
<a name="l213"></a> segment_length++;
<a name="l214"></a>
<a name="l215"></a> </span><span class=cF1>switch</span><span class=cF0> (tcp_socket-&gt;state)
<a name="l216"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l217"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_LISTEN:
<a name="l218"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Running TCP HANDLE SOCKET LISTEN&quot;</span><span class=cF0>);
<a name="l219"></a> TCPHandleSocketListen(tcp_socket, packet, header, segment_seq_num);
<a name="l220"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l221"></a>
<a name="l222"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_CLOSED:
<a name="l223"></a> NetErr(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Received packet but TCP Socket is CLOSED.&quot;</span><span class=cF0>);
<a name="l224"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l225"></a>
<a name="l226"></a> </span><span class=cF1>default</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;header-&gt;flags, TCPf_SYN</span><span class=cF7>)</span><span class=cF0>)
<a name="l228"></a> {
<a name="l229"></a> tcp_socket-&gt;next_recv_seq_num = ++segment_seq_num;
<a name="l230"></a>
<a name="l231"></a> must_ack = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l232"></a> }
<a name="l233"></a>
<a name="l234"></a> </span><span class=cF1>if</span><span class=cF0> (segment_length == </span><span class=cFE>0</span><span class=cF0> &amp;&amp; tcp_socket-&gt;receive_window == </span><span class=cFE>0</span><span class=cF0>)
<a name="l235"></a> {
<a name="l236"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE SOCKET: segment length == 0 &amp;&amp; receive window == 0, SEQ valid if seq == next recv seq&quot;</span><span class=cF0>);
<a name="l237"></a> is_seq_valid = (segment_seq_num == tcp_socket-&gt;next_recv_seq_num);
<a name="l238"></a> }
<a name="l239"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l240"></a> {
<a name="l241"></a> seq_relative = (segment_seq_num - tcp_socket-&gt;next_recv_seq_num) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l242"></a> seq_end_relative = (segment_seq_num + segment_length - </span><span class=cFE>1</span><span class=cF0> - tcp_socket-&gt;next_recv_seq_num) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l243"></a>
<a name="l244"></a> is_seq_valid = (seq_relative &lt; tcp_socket-&gt;receive_window ||
<a name="l245"></a> seq_end_relative &lt; tcp_socket-&gt;receive_window);
<a name="l246"></a> }
<a name="l247"></a>
<a name="l248"></a> </span><span class=cF1>if</span><span class=cF0> (!is_seq_valid)
<a name="l249"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Invalid SEQ.&quot;</span><span class=cF0>);
<a name="l250"></a>
<a name="l251"></a> must_ack |= TCPHandleACK(tcp_socket, packet, header, segment_seq_num, segment_ack_num, segment_length);
<a name="l252"></a>
<a name="l196"></a> segment_seq_num + </span><span class=cFE>1</span><span class=cF0>,
<a name="l197"></a> TCPF_ACK | TCPF_RST);
<a name="l198"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l199"></a>}
<a name="l200"></a>
<a name="l201"></a></span><span class=cF1>U0</span><span class=cF0> TCPHandleSocket(CTCPSocket *tcp_socket, CIPV4Packet *packet, CTCPHeader *header, </span><span class=cF1>U8</span><span class=cF0> *data, </span><span class=cF9>I64</span><span class=cF0> length)
<a name="l202"></a>{
<a name="l203"></a> </span><span class=cF9>U32</span><span class=cF0> segment_length = length;
<a name="l204"></a> </span><span class=cF9>U32</span><span class=cF0> segment_seq_num = </span><span class=cF5>EndianU32</span><span class=cF0>(header-&gt;seq_num);
<a name="l205"></a> </span><span class=cF9>U32</span><span class=cF0> segment_ack_num = </span><span class=cF5>EndianU32</span><span class=cF0>(header-&gt;ack_num);
<a name="l206"></a> </span><span class=cF1>Bool</span><span class=cF0> must_ack = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l207"></a> </span><span class=cF1>Bool</span><span class=cF0> is_seq_valid = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l208"></a> </span><span class=cF9>I64</span><span class=cF0> seq_relative;
<a name="l209"></a> </span><span class=cF9>I64</span><span class=cF0> seq_end_relative;
<a name="l210"></a>
<a name="l211"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_FIN</span><span class=cF7>)</span><span class=cF0>)
<a name="l212"></a> segment_length++;
<a name="l213"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_SYN</span><span class=cF7>)</span><span class=cF0>)
<a name="l214"></a> segment_length++;
<a name="l215"></a>
<a name="l216"></a> </span><span class=cF1>switch</span><span class=cF0> (tcp_socket-&gt;state)
<a name="l217"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l218"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_LISTEN:
<a name="l219"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Running TCP HANDLE SOCKET LISTEN&quot;</span><span class=cF0>);
<a name="l220"></a> TCPHandleSocketListen(tcp_socket, packet, header, segment_seq_num);
<a name="l221"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l222"></a>
<a name="l223"></a> </span><span class=cF1>case</span><span class=cF0> TCP_STATE_CLOSED:
<a name="l224"></a> NetErr(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Received packet but TCP Socket is CLOSED.&quot;</span><span class=cF0>);
<a name="l225"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l226"></a>
<a name="l227"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l228"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_SYN</span><span class=cF7>)</span><span class=cF0>)
<a name="l229"></a> {
<a name="l230"></a> tcp_socket-&gt;next_recv_seq_num = ++segment_seq_num;
<a name="l231"></a>
<a name="l232"></a> must_ack = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l233"></a> }
<a name="l234"></a>
<a name="l235"></a> </span><span class=cF1>if</span><span class=cF0> (segment_length == </span><span class=cFE>0</span><span class=cF0> &amp;&amp; tcp_socket-&gt;receive_window == </span><span class=cFE>0</span><span class=cF0>)
<a name="l236"></a> {
<a name="l237"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLE SOCKET: segment length == 0 &amp;&amp; receive window == 0, SEQ valid if seq == next recv seq&quot;</span><span class=cF0>);
<a name="l238"></a> is_seq_valid = (segment_seq_num == tcp_socket-&gt;next_recv_seq_num);
<a name="l239"></a> }
<a name="l240"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l241"></a> {
<a name="l242"></a> seq_relative = (segment_seq_num - tcp_socket-&gt;next_recv_seq_num) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l243"></a> seq_end_relative = (segment_seq_num + segment_length - </span><span class=cFE>1</span><span class=cF0> - tcp_socket-&gt;next_recv_seq_num) &amp; </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>;
<a name="l244"></a>
<a name="l245"></a> is_seq_valid = (seq_relative &lt; tcp_socket-&gt;receive_window ||
<a name="l246"></a> seq_end_relative &lt; tcp_socket-&gt;receive_window);
<a name="l247"></a> }
<a name="l248"></a>
<a name="l249"></a> </span><span class=cF1>if</span><span class=cF0> (!is_seq_valid)
<a name="l250"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLE SOCKET: Invalid SEQ.&quot;</span><span class=cF0>);
<a name="l251"></a>
<a name="l252"></a> must_ack |= TCPHandleACK(tcp_socket, packet, header, segment_seq_num, segment_ack_num, segment_length);
<a name="l253"></a>
<a name="l254"></a> </span><span class=cF1>if</span><span class=cF0> (TCPHandleReset</span><span class=cF7>(</span><span class=cF0>tcp_socket, header, is_seq_valid</span><span class=cF7>)</span><span class=cF0>)
<a name="l255"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l256"></a>
<a name="l257"></a> </span><span class=cF1>if</span><span class=cF0> (is_seq_valid)
<a name="l258"></a> must_ack |= TCPHandleValidSEQ(tcp_socket, header, segment_seq_num, length, data);
<a name="l259"></a>
<a name="l260"></a> </span><span class=cF1>if</span><span class=cF0> (must_ack)
<a name="l261"></a> TCPSendFlags(tcp_socket, TCPF_ACK);
<a name="l262"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l263"></a>
<a name="l264"></a>}
<a name="l265"></a>
<a name="l266"></a></span><span class=cF9>I64</span><span class=cF0> TCPHandleRefuse(CIPV4Packet *packet, CTCPHeader *header, </span><span class=cF9>I64</span><span class=cF0> length)
<a name="l267"></a>{
<a name="l268"></a> </span><span class=cF9>I64</span><span class=cF0> de_index;
<a name="l269"></a> </span><span class=cF9>U32</span><span class=cF0> ack_num = </span><span class=cF5>EndianU32</span><span class=cF0>(header-&gt;ack_num);
<a name="l270"></a> </span><span class=cF9>U32</span><span class=cF0> seq_num = </span><span class=cF5>EndianU32</span><span class=cF0>(header-&gt;seq_num);
<a name="l271"></a>
<a name="l272"></a> </span><span class=cF1>no_warn</span><span class=cF0> length; </span><span class=cF2>// TODO: Will reset generation need length ?</span><span class=cF0>
<a name="l273"></a>
<a name="l274"></a> ack_num = ++seq_num;
<a name="l275"></a> seq_num = </span><span class=cFE>0</span><span class=cF0>;
<a name="l276"></a>
<a name="l277"></a> </span><span class=cF2>// review RFC Reset-Generation ...</span><span class=cF0>
<a name="l278"></a>
<a name="l279"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_RST</span><span class=cF7>)</span><span class=cF0> &amp;&amp; </span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_ACK</span><span class=cF7>)</span><span class=cF0>)
<a name="l280"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// bail: we probably sent an RST earlier, and this is the acknowledgement</span><span class=cF0>
<a name="l281"></a>
<a name="l282"></a> de_index = TCPSend(packet-&gt;destination_ip_address,
<a name="l283"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;destination_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l284"></a> packet-&gt;source_ip_address,
<a name="l285"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;source_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l286"></a> seq_num,
<a name="l287"></a> ack_num,
<a name="l288"></a> TCPF_RST | TCPF_ACK);
<a name="l289"></a> </span><span class=cF1>if</span><span class=cF0> (de_index &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l290"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l291"></a> NetErr(</span><span class=cF6>&quot;TCP Handler Refuse: TCP Send failed.&quot;</span><span class=cF0>);
<a name="l292"></a> </span><span class=cF1>return</span><span class=cF0> de_index;
<a name="l293"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l294"></a>
<a name="l295"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
<a name="l296"></a>}
<a name="l297"></a>
<a name="l298"></a></span><span class=cF9>I64</span><span class=cF0> TCPHandler(CIPV4Packet *packet)
<a name="l299"></a>{
<a name="l300"></a> CTCPHeader *header;
<a name="l301"></a> </span><span class=cF9>U16</span><span class=cF0> destination_port;
<a name="l302"></a> </span><span class=cF1>U8</span><span class=cF0> *data;
<a name="l303"></a> </span><span class=cF9>I64</span><span class=cF0> length;
<a name="l304"></a> CTCPTreeNode *head = tcp_globals.bound_socket_tree;
<a name="l305"></a> CTCPTreeNode *node;
<a name="l306"></a> CTCPTreeQueue *queue;
<a name="l307"></a> CTCPSocket *tcp_socket;
<a name="l308"></a> </span><span class=cF9>I64</span><span class=cF0> error = TCPPacketParse(&amp;header, &amp;data, &amp;length, packet);
<a name="l309"></a>
<a name="l310"></a> </span><span class=cF1>if</span><span class=cF0> (error &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l311"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l312"></a> NetErr(</span><span class=cF6>&quot;TCP HANDLER: Packet Parse Error.&quot;</span><span class=cF0>);
<a name="l313"></a> </span><span class=cF1>return</span><span class=cF0> error;
<a name="l314"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l315"></a>
<a name="l316"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLER: Caught packet with dest port of %0X (B.E.)&quot;</span><span class=cF0>, header-&gt;destination_port);
<a name="l317"></a>
<a name="l318"></a> destination_port = </span><span class=cF5>EndianU16</span><span class=cF0>(header-&gt;destination_port); </span><span class=cF2>// B.E. -&gt; L.E.</span><span class=cF0>
<a name="l319"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLER: Caught packet with dest port of %0X (L.E.)&quot;</span><span class=cF0>, destination_port);
<a name="l320"></a>
<a name="l321"></a> </span><span class=cF1>if</span><span class=cF0> (head)
<a name="l322"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l323"></a> node = TCPTreeNodeFind(destination_port, head);
<a name="l324"></a>
<a name="l325"></a> </span><span class=cF1>if</span><span class=cF0> (node)
<a name="l326"></a> {
<a name="l327"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLER: Found node for port, looking for address %0X (L.E.)&quot;</span><span class=cF0>, packet-&gt;source_ip_address);
<a name="l328"></a> queue = TCPTreeNodeQueueIPV4Find(packet-&gt;source_ip_address, node); </span><span class=cF2>// TODO: make sure bit order is correct here!!</span><span class=cF0>
<a name="l329"></a> </span><span class=cF1>if</span><span class=cF0> (queue)
<a name="l330"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l331"></a> tcp_socket = queue-&gt;socket;
<a name="l332"></a> NetLog(</span><span class=cF6>&quot;TCP HANDLER: Port and Address are in bound tree.&quot;</span><span class=cF0>);
<a name="l333"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l334"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l335"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l336"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Found node for port, but address is not in node queue.&quot;</span><span class=cF0>);
<a name="l337"></a> NetWarn(</span><span class=cF6>&quot; TCP source ip: 0x%0X.&quot;</span><span class=cF0>, packet-&gt;source_ip_address);
<a name="l338"></a>
<a name="l339"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Sending TCP RST ACK packet. Refusing connection.&quot;</span><span class=cF0>);
<a name="l340"></a> TCPHandleRefuse(packet, header, length);
<a name="l341"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l342"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l343"></a> }
<a name="l344"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l345"></a> {
<a name="l346"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLER: NODE SEARCH FAILURE: PORT %0X&quot;</span><span class=cF0>, destination_port);
<a name="l347"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Node for Port is not in tree.&quot;</span><span class=cF0>);
<a name="l348"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Sending TCP RST ACK packet. Refusing connection.&quot;</span><span class=cF0>);
<a name="l349"></a> TCPHandleRefuse(packet, header, length);
<a name="l350"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l351"></a> }
<a name="l352"></a>
<a name="l353"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l354"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l355"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l356"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Socket tree is currently empty.&quot;</span><span class=cF0>);
<a name="l357"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Sending TCP RST ACK packet. Refusing connection.&quot;</span><span class=cF0>);
<a name="l358"></a> TCPHandleRefuse(packet, header, length);
<a name="l359"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l360"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l361"></a>
<a name="l362"></a> </span><span class=cF2>// at this point, tcp_socket is set, otherwise has already returned -1.</span><span class=cF0>
<a name="l363"></a>
<a name="l364"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLER: Running TCP HANDLE SOCKET&quot;</span><span class=cF0>);
<a name="l365"></a> TCPHandleSocket(tcp_socket, packet, header, data, length);
<a name="l366"></a>
<a name="l367"></a>}</span></pre></body>
<a name="l254"></a>
<a name="l255"></a> </span><span class=cF1>if</span><span class=cF0> (TCPHandleReset</span><span class=cF7>(</span><span class=cF0>tcp_socket, header, is_seq_valid</span><span class=cF7>)</span><span class=cF0>)
<a name="l256"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l257"></a>
<a name="l258"></a> </span><span class=cF1>if</span><span class=cF0> (is_seq_valid)
<a name="l259"></a> must_ack |= TCPHandleValidSEQ(tcp_socket, header, segment_seq_num, length, data);
<a name="l260"></a>
<a name="l261"></a> </span><span class=cF1>if</span><span class=cF0> (must_ack)
<a name="l262"></a> TCPSendFlags(tcp_socket, TCPF_ACK);
<a name="l263"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l264"></a>
<a name="l265"></a>}
<a name="l266"></a>
<a name="l267"></a></span><span class=cF9>I64</span><span class=cF0> TCPHandleRefuse(CIPV4Packet *packet, CTCPHeader *header, </span><span class=cF9>I64</span><span class=cF0> length)
<a name="l268"></a>{
<a name="l269"></a> </span><span class=cF9>I64</span><span class=cF0> de_index;
<a name="l270"></a> </span><span class=cF9>U32</span><span class=cF0> ack_num = </span><span class=cF5>EndianU32</span><span class=cF0>(header-&gt;ack_num);
<a name="l271"></a> </span><span class=cF9>U32</span><span class=cF0> seq_num = </span><span class=cF5>EndianU32</span><span class=cF0>(header-&gt;seq_num);
<a name="l272"></a>
<a name="l273"></a> </span><span class=cF1>no_warn</span><span class=cF0> length; </span><span class=cF2>// TODO: Will reset generation need length ?</span><span class=cF0>
<a name="l274"></a>
<a name="l275"></a> ack_num = ++seq_num;
<a name="l276"></a> seq_num = </span><span class=cFE>0</span><span class=cF0>;
<a name="l277"></a>
<a name="l278"></a> </span><span class=cF2>// review RFC Reset-Generation ...</span><span class=cF0>
<a name="l279"></a>
<a name="l280"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_RST</span><span class=cF7>)</span><span class=cF0> &amp;&amp; </span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;header-&gt;flags, TCPf_ACK</span><span class=cF7>)</span><span class=cF0>)
<a name="l281"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// bail: we probably sent an RST earlier, and this is the acknowledgement</span><span class=cF0>
<a name="l282"></a>
<a name="l283"></a> de_index = TCPSend(packet-&gt;destination_ip_address,
<a name="l284"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;destination_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l285"></a> packet-&gt;source_ip_address,
<a name="l286"></a> </span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>header-&gt;source_port</span><span class=cF7>)</span><span class=cF0>,
<a name="l287"></a> seq_num,
<a name="l288"></a> ack_num,
<a name="l289"></a> TCPF_RST | TCPF_ACK);
<a name="l290"></a> </span><span class=cF1>if</span><span class=cF0> (de_index &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l291"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l292"></a> NetErr(</span><span class=cF6>&quot;TCP Handler Refuse: TCP Send failed.&quot;</span><span class=cF0>);
<a name="l293"></a> </span><span class=cF1>return</span><span class=cF0> de_index;
<a name="l294"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l295"></a>
<a name="l296"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
<a name="l297"></a>}
<a name="l298"></a>
<a name="l299"></a></span><span class=cF9>I64</span><span class=cF0> TCPHandler(CIPV4Packet *packet)
<a name="l300"></a>{
<a name="l301"></a> CTCPHeader *header;
<a name="l302"></a> </span><span class=cF9>U16</span><span class=cF0> destination_port;
<a name="l303"></a> </span><span class=cF1>U8</span><span class=cF0> *data;
<a name="l304"></a> </span><span class=cF9>I64</span><span class=cF0> length;
<a name="l305"></a> CTCPTreeNode *head = tcp_globals.bound_socket_tree;
<a name="l306"></a> CTCPTreeNode *node;
<a name="l307"></a> CTCPTreeQueue *queue;
<a name="l308"></a> CTCPSocket *tcp_socket;
<a name="l309"></a> </span><span class=cF9>I64</span><span class=cF0> error = TCPPacketParse(&amp;header, &amp;data, &amp;length, packet);
<a name="l310"></a>
<a name="l311"></a> </span><span class=cF1>if</span><span class=cF0> (error &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l312"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l313"></a> NetErr(</span><span class=cF6>&quot;TCP HANDLER: Packet Parse Error.&quot;</span><span class=cF0>);
<a name="l314"></a> </span><span class=cF1>return</span><span class=cF0> error;
<a name="l315"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l316"></a>
<a name="l317"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLER: Caught packet with dest port of %0X (B.E.)&quot;</span><span class=cF0>, header-&gt;destination_port);
<a name="l318"></a>
<a name="l319"></a> destination_port = </span><span class=cF5>EndianU16</span><span class=cF0>(header-&gt;destination_port); </span><span class=cF2>// B.E. -&gt; L.E.</span><span class=cF0>
<a name="l320"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLER: Caught packet with dest port of %0X (L.E.)&quot;</span><span class=cF0>, destination_port);
<a name="l321"></a>
<a name="l322"></a> </span><span class=cF1>if</span><span class=cF0> (head)
<a name="l323"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l324"></a> node = TCPTreeNodeFind(destination_port, head);
<a name="l325"></a>
<a name="l326"></a> </span><span class=cF1>if</span><span class=cF0> (node)
<a name="l327"></a> {
<a name="l328"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLER: Found node for port, looking for address %0X (L.E.)&quot;</span><span class=cF0>, packet-&gt;source_ip_address);
<a name="l329"></a> queue = TCPTreeNodeQueueIPV4Find(packet-&gt;source_ip_address, node); </span><span class=cF2>// TODO: make sure bit order is correct here!!</span><span class=cF0>
<a name="l330"></a> </span><span class=cF1>if</span><span class=cF0> (queue)
<a name="l331"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l332"></a> tcp_socket = queue-&gt;socket;
<a name="l333"></a> NetLog(</span><span class=cF6>&quot;TCP HANDLER: Port and Address are in bound tree.&quot;</span><span class=cF0>);
<a name="l334"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l335"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l336"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l337"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Found node for port, but address is not in node queue.&quot;</span><span class=cF0>);
<a name="l338"></a> NetWarn(</span><span class=cF6>&quot; TCP source ip: 0x%0X.&quot;</span><span class=cF0>, packet-&gt;source_ip_address);
<a name="l339"></a>
<a name="l340"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Sending TCP RST ACK packet. Refusing connection.&quot;</span><span class=cF0>);
<a name="l341"></a> TCPHandleRefuse(packet, header, length);
<a name="l342"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l343"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l344"></a> }
<a name="l345"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l346"></a> {
<a name="l347"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLER: NODE SEARCH FAILURE: PORT %0X&quot;</span><span class=cF0>, destination_port);
<a name="l348"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Node for Port is not in tree.&quot;</span><span class=cF0>);
<a name="l349"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Sending TCP RST ACK packet. Refusing connection.&quot;</span><span class=cF0>);
<a name="l350"></a> TCPHandleRefuse(packet, header, length);
<a name="l351"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l352"></a> }
<a name="l353"></a>
<a name="l354"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l355"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l356"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l357"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Socket tree is currently empty.&quot;</span><span class=cF0>);
<a name="l358"></a> NetWarn(</span><span class=cF6>&quot;TCP HANDLER: Sending TCP RST ACK packet. Refusing connection.&quot;</span><span class=cF0>);
<a name="l359"></a> TCPHandleRefuse(packet, header, length);
<a name="l360"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l361"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l362"></a>
<a name="l363"></a> </span><span class=cF2>// at this point, tcp_socket is set, otherwise has already returned -1.</span><span class=cF0>
<a name="l364"></a>
<a name="l365"></a> NetDebug(</span><span class=cF6>&quot;TCP HANDLER: Running TCP HANDLE SOCKET&quot;</span><span class=cF0>);
<a name="l366"></a> TCPHandleSocket(tcp_socket, packet, header, data, length);
<a name="l367"></a>
<a name="l368"></a>}
</span></pre></body>
</html>

View file

@ -65,10 +65,8 @@ body {background-color:#1f1f1f;}
<a name="l38"></a></span><span class=cF2>#define I_NETHANDLER</span><span class=cF0> </span><span class=cF2>I_USER + 4</span><span class=cF0>
<a name="l39"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l40"></a>
<a name="l41"></a></span><span class=cF9>I64</span><span class=cF0> I_NETHANDLER = </span><span class=cF5>IntEntryAlloc</span><span class=cF0>;
<a name="l42"></a></span><span class=cF2>// TODO: needed across NetHandler &amp; NetQueue,</span><span class=cF0>
<a name="l43"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2> need a dynamic #define.. (I64 allows trashing)</span><span class=cF0>
<a name="l44"></a>
<a name="l45"></a>#</span><span class=cF1>define</span><span class=cF0> INT_DEST_CPU </span><span class=cFE>0</span><span class=cF0>
<a name="l41"></a></span><span class=cF5>DefinePrint</span><span class=cF0>(</span><span class=cF6>&quot;I_NETHANDLER&quot;</span><span class=cF0>, </span><span class=cF6>&quot;%d&quot;</span><span class=cF0>, </span><span class=cF5>IntEntryAlloc</span><span class=cF0>);
<a name="l42"></a>
<a name="l43"></a>#</span><span class=cF1>define</span><span class=cF0> INT_DEST_CPU </span><span class=cFE>0</span><span class=cF0>
</span></pre></body>
</html>

View file

@ -57,47 +57,49 @@ body {background-color:#1f1f1f;}
<a name="l30"></a> </span><span class=cF5>WinFocus</span><span class=cF0>(net_log_task);
<a name="l31"></a>
<a name="l32"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(net_log_task-&gt;put_doc, </span><span class=cF6>&quot;$WW+H,1$&quot;</span><span class=cF0>);
<a name="l33"></a>}
<a name="l34"></a>
<a name="l35"></a></span><span class=cF1>U0</span><span class=cF0> NetLog(</span><span class=cF1>U8</span><span class=cF0> *format, ...)
<a name="l36"></a>{ </span><span class=cF2>// Output text to NetLogTask as Log.</span><span class=cF0>
<a name="l37"></a> </span><span class=cF1>U8</span><span class=cF0> *buf = </span><span class=cF5>StrPrintJoin</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, format, argc, argv);
<a name="l38"></a>
<a name="l39"></a> </span><span class=cF5>DocBottom</span><span class=cF0>(net_log_task-&gt;put_doc);
<a name="l40"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(net_log_task-&gt;put_doc, </span><span class=cF6>&quot;%s\n&quot;</span><span class=cF0>, buf);
<a name="l41"></a>
<a name="l42"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l43"></a>}
<a name="l44"></a>
<a name="l45"></a></span><span class=cF1>U0</span><span class=cF0> NetWarn(</span><span class=cF1>U8</span><span class=cF0> *format, ...)
<a name="l46"></a>{ </span><span class=cF2>// Output text to NetLogTask as Warning.</span><span class=cF0>
<a name="l47"></a> </span><span class=cF1>U8</span><span class=cF0> *buf = </span><span class=cF5>StrPrintJoin</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, format, argc, argv);
<a name="l48"></a>
<a name="l49"></a> </span><span class=cF5>DocBottom</span><span class=cF0>(net_log_task-&gt;put_doc);
<a name="l50"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(net_log_task-&gt;put_doc, </span><span class=cF6>&quot;$BG,BROWN$$WHITE$%s$BG$$FG$\n&quot;</span><span class=cF0>, buf);
<a name="l51"></a>
<a name="l52"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l53"></a>}
<a name="l54"></a>
<a name="l55"></a></span><span class=cF1>U0</span><span class=cF0> NetErr(</span><span class=cF1>U8</span><span class=cF0> *format, ...)
<a name="l56"></a>{ </span><span class=cF2>// Output text to NetLogTask as Error.</span><span class=cF0>
<a name="l57"></a> </span><span class=cF1>U8</span><span class=cF0> *buf = </span><span class=cF5>StrPrintJoin</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, format, argc, argv);
<a name="l58"></a>
<a name="l59"></a> </span><span class=cF5>DocBottom</span><span class=cF0>(net_log_task-&gt;put_doc);
<a name="l60"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(net_log_task-&gt;put_doc, </span><span class=cF6>&quot;$BG,RED$$WHITE$%s$BG$$FG$\n&quot;</span><span class=cF0>, buf);
<a name="l61"></a>
<a name="l62"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l63"></a>}
<a name="l64"></a>
<a name="l65"></a></span><span class=cF1>U0</span><span class=cF0> NetDebug(</span><span class=cF1>U8</span><span class=cF0> *format, ...)
<a name="l66"></a>{ </span><span class=cF2>// Output text to NetLogTask as Debug.</span><span class=cF0>
<a name="l67"></a> </span><span class=cF1>U8</span><span class=cF0> *buf = </span><span class=cF5>StrPrintJoin</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, format, argc, argv);
<a name="l68"></a>
<a name="l69"></a> </span><span class=cF5>DocBottom</span><span class=cF0>(net_log_task-&gt;put_doc);
<a name="l70"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(net_log_task-&gt;put_doc, </span><span class=cF6>&quot;$BG,YELLOW$$DKGRAY$%s$BG$$FG$\n&quot;</span><span class=cF0>, buf);
<a name="l71"></a>
<a name="l72"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l73"></a>}
<a name="l74"></a>
<a name="l75"></a>NetLogInit;</span></pre></body>
<a name="l33"></a>
<a name="l34"></a> </span><span class=cF5>Bts</span><span class=cF0>(&amp;net_log_task-&gt;win_inhibit, </span><span class=cF3>WIf_SELF_FOCUS</span><span class=cF0>);
<a name="l35"></a>}
<a name="l36"></a>
<a name="l37"></a></span><span class=cF1>U0</span><span class=cF0> NetLog(</span><span class=cF1>U8</span><span class=cF0> *format, ...)
<a name="l38"></a>{ </span><span class=cF2>// Output text to NetLogTask as Log.</span><span class=cF0>
<a name="l39"></a> </span><span class=cF1>U8</span><span class=cF0> *buf = </span><span class=cF5>StrPrintJoin</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, format, argc, argv);
<a name="l40"></a>
<a name="l41"></a> </span><span class=cF5>DocBottom</span><span class=cF0>(net_log_task-&gt;put_doc);
<a name="l42"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(net_log_task-&gt;put_doc, </span><span class=cF6>&quot;%s\n&quot;</span><span class=cF0>, buf);
<a name="l43"></a>
<a name="l44"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l45"></a>}
<a name="l46"></a>
<a name="l47"></a></span><span class=cF1>U0</span><span class=cF0> NetWarn(</span><span class=cF1>U8</span><span class=cF0> *format, ...)
<a name="l48"></a>{ </span><span class=cF2>// Output text to NetLogTask as Warning.</span><span class=cF0>
<a name="l49"></a> </span><span class=cF1>U8</span><span class=cF0> *buf = </span><span class=cF5>StrPrintJoin</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, format, argc, argv);
<a name="l50"></a>
<a name="l51"></a> </span><span class=cF5>DocBottom</span><span class=cF0>(net_log_task-&gt;put_doc);
<a name="l52"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(net_log_task-&gt;put_doc, </span><span class=cF6>&quot;$BG,BROWN$$WHITE$%s$BG$$FG$\n&quot;</span><span class=cF0>, buf);
<a name="l53"></a>
<a name="l54"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l55"></a>}
<a name="l56"></a>
<a name="l57"></a></span><span class=cF1>U0</span><span class=cF0> NetErr(</span><span class=cF1>U8</span><span class=cF0> *format, ...)
<a name="l58"></a>{ </span><span class=cF2>// Output text to NetLogTask as Error.</span><span class=cF0>
<a name="l59"></a> </span><span class=cF1>U8</span><span class=cF0> *buf = </span><span class=cF5>StrPrintJoin</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, format, argc, argv);
<a name="l60"></a>
<a name="l61"></a> </span><span class=cF5>DocBottom</span><span class=cF0>(net_log_task-&gt;put_doc);
<a name="l62"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(net_log_task-&gt;put_doc, </span><span class=cF6>&quot;$BG,RED$$WHITE$%s$BG$$FG$\n&quot;</span><span class=cF0>, buf);
<a name="l63"></a>
<a name="l64"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l65"></a>}
<a name="l66"></a>
<a name="l67"></a></span><span class=cF1>U0</span><span class=cF0> NetDebug(</span><span class=cF1>U8</span><span class=cF0> *format, ...)
<a name="l68"></a>{ </span><span class=cF2>// Output text to NetLogTask as Debug.</span><span class=cF0>
<a name="l69"></a> </span><span class=cF1>U8</span><span class=cF0> *buf = </span><span class=cF5>StrPrintJoin</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, format, argc, argv);
<a name="l70"></a>
<a name="l71"></a> </span><span class=cF5>DocBottom</span><span class=cF0>(net_log_task-&gt;put_doc);
<a name="l72"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(net_log_task-&gt;put_doc, </span><span class=cF6>&quot;$BG,YELLOW$$DKGRAY$%s$BG$$FG$\n&quot;</span><span class=cF0>, buf);
<a name="l73"></a>
<a name="l74"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l75"></a>}
<a name="l76"></a>
<a name="l77"></a>NetLogInit;</span></pre></body>
</html>

View file

@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF5>Cd</span><span class=cF0>(</span><span class=cF3>__DIR__</span><span class=cF0>);;
<a name="l2"></a>#</span><span class=cF1>define</span><span class=cF0> PALETTES_PATH </span><span class=cF6>&quot;~/PaletteEditor/Palettes/&quot;</span><span class=cF0>
<a name="l3"></a>#</span><span class=cF1>include</span><span class=cF0> </span><span class=cF6>&quot;PaletteSelect&quot;</span><span class=cF0>
<a name="l4"></a>#</span><span class=cF1>include</span><span class=cF0> </span><span class=cF6>&quot;PaletteEdit&quot;</span></pre></body>
</html>

View file

@ -0,0 +1,509 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF0>#</span><span class=cF1>ifndef</span><span class=cF0> PALETTES_PATH
<a name="l2"></a></span><span class=cF5>Cd</span><span class=cF0>(</span><span class=cF3>__DIR__</span><span class=cF0>);;
<a name="l3"></a>#</span><span class=cF1>include</span><span class=cF0> </span><span class=cF6>&quot;Load&quot;</span><span class=cF0>
<a name="l4"></a>#</span><span class=cF1>endif</span><span class=cF0>
<a name="l5"></a>
<a name="l6"></a></span><span class=cF2>// FIXME: bug where holding CTRL for 5-ish seconds crashes program!</span><span class=cF0>
<a name="l7"></a></span><span class=cF2>// TODO: move to Demo/Graphics, make sprite link in Menu</span><span class=cF0>
<a name="l8"></a>
<a name="l9"></a>#</span><span class=cF1>define</span><span class=cF0> SLIDER_RANGE </span><span class=cFE>255</span><span class=cF0>
<a name="l10"></a>#</span><span class=cF1>define</span><span class=cF0> SLIDER_SPACING </span><span class=cFE>28</span><span class=cF0>
<a name="l11"></a>#</span><span class=cF1>define</span><span class=cF0> SLIDER_BORDER </span><span class=cFE>2</span><span class=cF0>
<a name="l12"></a>
<a name="l13"></a></span><span class=cF9>I64</span><span class=cF0> current_palette = </span><span class=cF6>&quot;*New Palette&quot;</span><span class=cF0>;
<a name="l14"></a></span><span class=cF9>I64</span><span class=cF0> selected_color = </span><span class=cFE>0</span><span class=cF0>;
<a name="l15"></a></span><span class=cF9>I64</span><span class=cF0> l, r, t, b;
<a name="l16"></a>
<a name="l17"></a></span><span class=cF1>U8</span><span class=cF0> *manual_value;
<a name="l18"></a>
<a name="l19"></a></span><span class=cF9>CBGR24</span><span class=cF0> gr_temp_palette[</span><span class=cF3>COLORS_NUM</span><span class=cF0>];
<a name="l20"></a>
<a name="l21"></a></span><span class=cF1>class</span><span class=cF0> CSliderState
<a name="l22"></a>{
<a name="l23"></a> </span><span class=cF9>I64</span><span class=cF0> left_pos;
<a name="l24"></a> </span><span class=cF9>I64</span><span class=cF0> middle_pos;
<a name="l25"></a> </span><span class=cF9>I64</span><span class=cF0> right_pos;
<a name="l26"></a> </span><span class=cF9>I64</span><span class=cF0> preview;
<a name="l27"></a> </span><span class=cF9>CBGR24</span><span class=cF0> color;
<a name="l28"></a>
<a name="l29"></a>} sld;
<a name="l30"></a>
<a name="l31"></a></span><span class=cF1>I0</span><span class=cF0> DrawPixel(</span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y, </span><span class=cF9>CBGR24</span><span class=cF0> color)
<a name="l32"></a>{
<a name="l33"></a> </span><span class=cFB>text</span><span class=cF0>.fb_alias[x + y * </span><span class=cF3>GR_WIDTH</span><span class=cF0>] = color;
<a name="l34"></a>}
<a name="l35"></a>
<a name="l36"></a></span><span class=cF1>U0</span><span class=cF0> DrawCtrlSlider(</span><span class=cF9>CDC</span><span class=cF0> *dc, </span><span class=cF9>CCtrl</span><span class=cF0> *c)
<a name="l37"></a>{
<a name="l38"></a>
<a name="l39"></a> CSliderState *s = c-&gt;state;
<a name="l40"></a> </span><span class=cF9>I64</span><span class=cF0> size = (c-&gt;win_task-&gt;pix_width / </span><span class=cFE>16</span><span class=cF0>),
<a name="l41"></a> border = size / </span><span class=cFE>16</span><span class=cF0>,
<a name="l42"></a> size2 = (c-&gt;win_task-&gt;pix_height / </span><span class=cFE>32</span><span class=cF0>),
<a name="l43"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>slider_amount = 3,</span><span class=cF0>
<a name="l44"></a> i, k, j,</span><span class=cF2>// l,</span><span class=cF0>
<a name="l45"></a> pos, col,
<a name="l46"></a> bias;
<a name="l47"></a> </span><span class=cF9>CBGR24</span><span class=cF0> tempColor;
<a name="l48"></a>
<a name="l49"></a> </span><span class=cF2>///////////////////////</span><span class=cF0>
<a name="l50"></a> </span><span class=cF2>// CURRENT SELECTION //</span><span class=cF0>
<a name="l51"></a> </span><span class=cF2>///////////////////////</span><span class=cF0>
<a name="l52"></a>
<a name="l53"></a> </span><span class=cF2>// current color box preview</span><span class=cF0>
<a name="l54"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l55"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cFE>10</span><span class=cF0>, </span><span class=cFE>10</span><span class=cF0>, </span><span class=cF6>&quot;Preview:&quot;</span><span class=cF0>);
<a name="l56"></a>
<a name="l57"></a> </span><span class=cF2>// pixel loop for current color preview</span><span class=cF0>
<a name="l58"></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>12</span><span class=cF0>; i++)
<a name="l59"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt;= </span><span class=cFE>12</span><span class=cF0>; j++)
<a name="l60"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l61"></a> tempColor = </span><span class=cFB>gr_palette</span><span class=cF0>[selected_color];
<a name="l62"></a> </span><span class=cF1>if</span><span class=cF0> (i &lt; border || i &gt; </span><span class=cFE>12</span><span class=cF0> - border || j &lt; border || j &gt; </span><span class=cFE>12</span><span class=cF0> - border)
<a name="l63"></a> tempColor = </span><span class=cFE>0x000000</span><span class=cF0>;
<a name="l64"></a> DrawPixel(c-&gt;win_task-&gt;pix_left + </span><span class=cFE>78</span><span class=cF0> + i, t + </span><span class=cFE>7</span><span class=cF0> + j, tempColor);
<a name="l65"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l66"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cFE>10</span><span class=cF0>, </span><span class=cFE>26</span><span class=cF0>, </span><span class=cF6>&quot;Current Color: #%d&quot;</span><span class=cF0>, selected_color + </span><span class=cFE>1</span><span class=cF0>);
<a name="l67"></a> </span><span class=cF1>if</span><span class=cF0> (selected_color == </span><span class=cFE>15</span><span class=cF0>)
<a name="l68"></a> dc-&gt;color = </span><span class=cF3>LTGRAY</span><span class=cF0>;
<a name="l69"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>gr_palette</span><span class=cF0>[selected_color] &gt; </span><span class=cFE>0xCCCCCC</span><span class=cF0>)
<a name="l70"></a> dc-&gt;color = </span><span class=cF3>DKGRAY</span><span class=cF0>;
<a name="l71"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l72"></a> dc-&gt;color = </span><span class=cFE>15</span><span class=cF0>;
<a name="l73"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc, </span><span class=cFE>94</span><span class=cF0>, </span><span class=cFE>8</span><span class=cF0>, </span><span class=cFE>58</span><span class=cF0>, </span><span class=cFE>12</span><span class=cF0>);
<a name="l74"></a>
<a name="l75"></a> dc-&gt;color = selected_color;
<a name="l76"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cFE>95</span><span class=cF0>, </span><span class=cFE>10</span><span class=cF0>, </span><span class=cF6>&quot;#%x%x%x&quot;</span><span class=cF0>, </span><span class=cFB>gr_palette</span><span class=cF0>[selected_color].r,
<a name="l77"></a> </span><span class=cFB>gr_palette</span><span class=cF0>[selected_color].g,
<a name="l78"></a> </span><span class=cFB>gr_palette</span><span class=cF0>[selected_color].b);
<a name="l79"></a>
<a name="l80"></a> </span><span class=cF2>// palette name</span><span class=cF0>
<a name="l81"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l82"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cFE>10</span><span class=cF0>, </span><span class=cFE>43</span><span class=cF0>, </span><span class=cF6>&quot;Palette: %s&quot;</span><span class=cF0>, current_palette);
<a name="l83"></a>
<a name="l84"></a> </span><span class=cF2>////////////</span><span class=cF0>
<a name="l85"></a> </span><span class=cF2>// SLIDER //</span><span class=cF0>
<a name="l86"></a> </span><span class=cF2>////////////</span><span class=cF0>
<a name="l87"></a>
<a name="l88"></a> </span><span class=cF2>//box</span><span class=cF0>
<a name="l89"></a> dc-&gt;color = </span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l90"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc, c-&gt;left,
<a name="l91"></a> c-&gt;top,
<a name="l92"></a> SLIDER_SPACING * </span><span class=cFE>4</span><span class=cF0> + </span><span class=cFE>2</span><span class=cF0>,
<a name="l93"></a> SLIDER_SPACING * </span><span class=cFE>2</span><span class=cF0> + SLIDER_RANGE);
<a name="l94"></a> dc-&gt;color = </span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l95"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc, c-&gt;left + SLIDER_BORDER,
<a name="l96"></a> c-&gt;top + SLIDER_BORDER,
<a name="l97"></a> SLIDER_SPACING * </span><span class=cFE>4</span><span class=cF0> + </span><span class=cFE>2</span><span class=cF0> - </span><span class=cFE>2</span><span class=cF0> * SLIDER_BORDER,
<a name="l98"></a> SLIDER_SPACING * </span><span class=cFE>2</span><span class=cF0> + SLIDER_RANGE - </span><span class=cFE>2</span><span class=cF0> * SLIDER_BORDER);
<a name="l99"></a>
<a name="l100"></a> </span><span class=cF2>//slider</span><span class=cF0>
<a name="l101"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l102"></a>
<a name="l103"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>1</span><span class=cF0>; i &lt;= </span><span class=cFE>3</span><span class=cF0>; i++)
<a name="l104"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l105"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, c-&gt;left + i * SLIDER_SPACING + i - </span><span class=cFE>1</span><span class=cF0>,
<a name="l106"></a> c-&gt;top + SLIDER_SPACING,
<a name="l107"></a> c-&gt;left + i * SLIDER_SPACING + i - </span><span class=cFE>1</span><span class=cF0>,
<a name="l108"></a> c-&gt;top + SLIDER_SPACING + SLIDER_RANGE - </span><span class=cFE>1</span><span class=cF0>);
<a name="l109"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l110"></a>
<a name="l111"></a> </span><span class=cF2>//values</span><span class=cF0>
<a name="l112"></a> dc-&gt;color = </span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l113"></a>
<a name="l114"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>1</span><span class=cF0>; i &lt;= </span><span class=cFE>3</span><span class=cF0>; i++)
<a name="l115"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l116"></a> </span><span class=cF1>switch</span><span class=cF0> (i)
<a name="l117"></a> {
<a name="l118"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>1</span><span class=cF0>:
<a name="l119"></a> pos = s-&gt;left_pos;
<a name="l120"></a> col = </span><span class=cF6>&quot;R&quot;</span><span class=cF0>;
<a name="l121"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l122"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>2</span><span class=cF0>:
<a name="l123"></a> pos = s-&gt;middle_pos;
<a name="l124"></a> col = </span><span class=cF6>&quot;G&quot;</span><span class=cF0>;
<a name="l125"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l126"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>3</span><span class=cF0>:
<a name="l127"></a> pos = s-&gt;right_pos;
<a name="l128"></a> col = </span><span class=cF6>&quot;B&quot;</span><span class=cF0>;
<a name="l129"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l130"></a> }
<a name="l131"></a>
<a name="l132"></a> </span><span class=cF2>//values</span><span class=cF0>
<a name="l133"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, c-&gt;left + i * SLIDER_SPACING + i - </span><span class=cF3>FONT_WIDTH</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>,
<a name="l134"></a> c-&gt;top + SLIDER_SPACING + SLIDER_RANGE + </span><span class=cFE>8</span><span class=cF0>,
<a name="l135"></a> </span><span class=cF6>&quot;%d&quot;</span><span class=cF0>, pos);
<a name="l136"></a> </span><span class=cF2>//RGB label</span><span class=cF0>
<a name="l137"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, c-&gt;left + i * SLIDER_SPACING + </span><span class=cFE>3</span><span class=cF0> - </span><span class=cF3>FONT_WIDTH</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>,
<a name="l138"></a> c-&gt;top + </span><span class=cFE>14</span><span class=cF0>,
<a name="l139"></a> </span><span class=cF6>&quot;%s&quot;</span><span class=cF0>, col);
<a name="l140"></a> </span><span class=cF2>//knobs</span><span class=cF0>
<a name="l141"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc, c-&gt;left + i * SLIDER_SPACING + i - </span><span class=cFE>4</span><span class=cF0>,
<a name="l142"></a> c-&gt;top + SLIDER_SPACING + SLIDER_RANGE - </span><span class=cFE>1</span><span class=cF0> - pos - </span><span class=cFE>2</span><span class=cF0>,
<a name="l143"></a> </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>5</span><span class=cF0>);
<a name="l144"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l145"></a>
<a name="l146"></a> </span><span class=cF2>////////////////////</span><span class=cF0>
<a name="l147"></a> </span><span class=cF2>// COLORS PREVIEW //</span><span class=cF0>
<a name="l148"></a> </span><span class=cF2>////////////////////</span><span class=cF0>
<a name="l149"></a>
<a name="l150"></a> dc-&gt;color = </span><span class=cFE>8</span><span class=cF0>;
<a name="l151"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc, </span><span class=cFE>0</span><span class=cF0>, c-&gt;win_task-&gt;pix_height + size * </span><span class=cFE>1</span><span class=cF0>.</span><span class=cFE>5</span><span class=cF0> - size * </span><span class=cFE>2</span><span class=cF0>, c-&gt;win_task-&gt;pix_width, size * </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>75</span><span class=cF0>);
<a name="l152"></a>
<a name="l153"></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=cF3>COLORS_NUM</span><span class=cF0>; i++)
<a name="l154"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l155"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt;= size; j++)
<a name="l156"></a> {
<a name="l157"></a> </span><span class=cF1>for</span><span class=cF0> (k = </span><span class=cFE>0</span><span class=cF0>; k &lt;= size; k++)
<a name="l158"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l159"></a> tempColor = </span><span class=cFB>gr_palette</span><span class=cF0>[i];
<a name="l160"></a> </span><span class=cF2>// black borders</span><span class=cF0>
<a name="l161"></a> </span><span class=cF1>if</span><span class=cF0> (k &lt; border || k &gt; size - border || j &lt; border || j &gt; size - border - </span><span class=cFE>1</span><span class=cF0>)
<a name="l162"></a> {
<a name="l163"></a> </span><span class=cF1>if</span><span class=cF0> (selected_color == i)
<a name="l164"></a> tempColor = </span><span class=cFE>0xFFFFFF</span><span class=cF0>;
<a name="l165"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l166"></a> tempColor = </span><span class=cFE>0x000000</span><span class=cF0>;
<a name="l167"></a> }
<a name="l168"></a> </span><span class=cF2>// color preview</span><span class=cF0>
<a name="l169"></a> DrawPixel(c-&gt;win_task-&gt;pix_left + j + </span><span class=cF7>(</span><span class=cF0>size * i</span><span class=cF7>)</span><span class=cF0>, c-&gt;win_task-&gt;pix_bottom - size * </span><span class=cFE>1</span><span class=cF0>.</span><span class=cFE>5</span><span class=cF0> + k, tempColor);
<a name="l170"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l171"></a> }
<a name="l172"></a> </span><span class=cF2>// color label and text preview</span><span class=cF0>
<a name="l173"></a> </span><span class=cF2>// TODO: THIS LOGIC DOESNT WORK ON LIGHT THEMES</span><span class=cF0>
<a name="l174"></a> </span><span class=cF2>// if color too light or too dark add bg</span><span class=cF0>
<a name="l175"></a>
<a name="l176"></a> </span><span class=cF1>if</span><span class=cF0> (i == </span><span class=cFE>15</span><span class=cF0>)
<a name="l177"></a> dc-&gt;color = </span><span class=cF3>LTGRAY</span><span class=cF0>;
<a name="l178"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>gr_palette</span><span class=cF0>[i] &lt; </span><span class=cFB>gr_palette</span><span class=cF0>[</span><span class=cFE>15</span><span class=cF0>])
<a name="l179"></a> dc-&gt;color = </span><span class=cF3>LTGRAY</span><span class=cF0>;
<a name="l180"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>gr_palette</span><span class=cF0>[i] &gt; </span><span class=cFB>gr_palette</span><span class=cF0>[</span><span class=cFE>0</span><span class=cF0>])
<a name="l181"></a> dc-&gt;color = </span><span class=cF3>DKGRAY</span><span class=cF0>;
<a name="l182"></a> </span><span class=cF2>/*else if (i == 7)</span><span class=cF0>
<a name="l183"></a> </span><span class=cF2>dc-&gt;color = LTRED;*/</span><span class=cF0>
<a name="l184"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l185"></a> dc-&gt;color = </span><span class=cFE>15</span><span class=cF0>;
<a name="l186"></a> </span><span class=cF1>if</span><span class=cF0> (i == selected_color)
<a name="l187"></a> dc-&gt;color = </span><span class=cFE>0</span><span class=cF0>;
<a name="l188"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc, </span><span class=cFE>6</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>size2 * </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0> + </span><span class=cFE>65</span><span class=cF0> + </span><span class=cFE>16</span><span class=cF0> * i, </span><span class=cFE>80</span><span class=cF0>, </span><span class=cFE>18</span><span class=cF0>);
<a name="l189"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc, </span><span class=cF7>(</span><span class=cF0>size * i</span><span class=cF7>)</span><span class=cF0>, c-&gt;win_task-&gt;pix_height - </span><span class=cF7>(</span><span class=cF0>size - size / </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0>, size, size * </span><span class=cFE>1</span><span class=cF0>.</span><span class=cFE>5</span><span class=cF0>);
<a name="l190"></a>
<a name="l191"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc, </span><span class=cFE>6</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>size2 * </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0> + </span><span class=cFE>65</span><span class=cF0> + </span><span class=cFE>16</span><span class=cF0> * i, </span><span class=cFE>80</span><span class=cF0>, </span><span class=cFE>18</span><span class=cF0>);
<a name="l192"></a>
<a name="l193"></a>
<a name="l194"></a> </span><span class=cF1>if</span><span class=cF0> (i == selected_color)
<a name="l195"></a> dc-&gt;color = </span><span class=cFE>15</span><span class=cF0>;
<a name="l196"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l197"></a> dc-&gt;color = i;
<a name="l198"></a> bias = (size / </span><span class=cFE>2</span><span class=cF0>) - </span><span class=cFE>4</span><span class=cF0>;
<a name="l199"></a> </span><span class=cF1>if</span><span class=cF0> (i &gt;= </span><span class=cFE>9</span><span class=cF0>)
<a name="l200"></a> bias = (size / </span><span class=cFE>2</span><span class=cF0>) - </span><span class=cFE>8</span><span class=cF0>;
<a name="l201"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, bias + </span><span class=cF7>(</span><span class=cF0>i * size</span><span class=cF7>)</span><span class=cF0>, c-&gt;win_task-&gt;pix_height - </span><span class=cF7>(</span><span class=cF0>size * .</span><span class=cFE>6</span><span class=cF7>)</span><span class=cF0> + </span><span class=cF7>(</span><span class=cF0>size / </span><span class=cFE>4</span><span class=cF7>)</span><span class=cF0>, </span><span class=cF6>&quot;%d&quot;</span><span class=cF0>, i + </span><span class=cFE>1</span><span class=cF0>);
<a name="l202"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cFE>10</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>size2 * </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0> + </span><span class=cFE>70</span><span class=cF0> + </span><span class=cFE>16</span><span class=cF0> * i, </span><span class=cF6>&quot;#%d: Test&quot;</span><span class=cF0>, i + </span><span class=cFE>1</span><span class=cF0>);
<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=cF2>// Add Save/Load button?</span><span class=cF0>
<a name="l207"></a>
<a name="l208"></a>}
<a name="l209"></a>
<a name="l210"></a>
<a name="l211"></a>
<a name="l212"></a></span><span class=cF1>U0</span><span class=cF0> PESave(</span><span class=cF1>Bool</span><span class=cF0> prompt, </span><span class=cF9>CCtrl</span><span class=cF0> *c)
<a name="l213"></a>{
<a name="l214"></a> </span><span class=cF9>CDoc</span><span class=cF0> *doc = </span><span class=cF5>DocNew</span><span class=cF0>(PALETTES_PATH);
<a name="l215"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l216"></a> </span><span class=cF1>no_warn</span><span class=cF0> c; </span><span class=cF2>// TODO remove param if not needed</span><span class=cF0>
<a name="l217"></a> </span><span class=cF1>U8</span><span class=cF0> *tmp1, *tmp2; </span><span class=cF2>// 1: lower, 2: Capital</span><span class=cF0>
<a name="l218"></a>
<a name="l219"></a> </span><span class=cF1>if</span><span class=cF0> (prompt)
<a name="l220"></a> </span><span class=cF5>DocForm</span><span class=cF0>(&amp;doc-&gt;filename);
<a name="l221"></a>
<a name="l222"></a> tmp1 = </span><span class=cF5>StrNew</span><span class=cF0>(&amp;doc-&gt;filename.name);
<a name="l223"></a> </span><span class=cF5>StrLastRemove</span><span class=cF0>(tmp1, </span><span class=cF6>&quot;/&quot;</span><span class=cF0>, tmp1);
<a name="l224"></a> </span><span class=cF5>StrReplace</span><span class=cF0>(tmp1, </span><span class=cF6>&quot;.CC&quot;</span><span class=cF0>, </span><span class=cF6>&quot;&quot;</span><span class=cF0>);
<a name="l225"></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=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>tmp1</span><span class=cF7>)</span><span class=cF0>; i++)
<a name="l226"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF6>'A'</span><span class=cF0> &lt;= tmp1[i] &lt;= </span><span class=cF6>'Z'</span><span class=cF0>)
<a name="l227"></a> tmp1[i] = tmp1[i] + </span><span class=cFE>32</span><span class=cF0>;
<a name="l228"></a>
<a name="l229"></a> tmp2 = </span><span class=cF5>StrNew</span><span class=cF0>(tmp1);
<a name="l230"></a> tmp2[</span><span class=cFE>0</span><span class=cF0>] = </span><span class=cF5>ToUpper</span><span class=cF0>(tmp2[</span><span class=cFE>0</span><span class=cF0>]);
<a name="l231"></a>
<a name="l232"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc, </span><span class=cF6>&quot;public CBGR24 gr_palette_%s[COLORS_NUM] = {\n&quot;</span><span class=cF0>, tmp1);
<a name="l233"></a>
<a name="l234"></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=cF3>COLORS_NUM</span><span class=cF0>; i++)
<a name="l235"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l236"></a> </span><span class=cF1>if</span><span class=cF0> (i == </span><span class=cF3>COLORS_NUM</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>)
<a name="l237"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc, </span><span class=cF6>&quot;0x%X&quot;</span><span class=cF0>, </span><span class=cFB>gr_palette</span><span class=cF0>[i]);
<a name="l238"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l239"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc, </span><span class=cF6>&quot;0x%X, &quot;</span><span class=cF0>, </span><span class=cFB>gr_palette</span><span class=cF0>[i]);
<a name="l240"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l241"></a>
<a name="l242"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc, </span><span class=cF6>&quot;\n};\npublic U0 PaletteSet%s(Bool persistent=TRUE)\n{\n&quot;</span><span class=cF0>
<a name="l243"></a> </span><span class=cF6>&quot;\tGrPaletteSet(gr_palette_%s);\n&quot;</span><span class=cF0>
<a name="l244"></a> </span><span class=cF6>&quot;\tLFBFlush;\n&quot;</span><span class=cF0>
<a name="l245"></a> </span><span class=cF6>&quot;\tif (persistent)\n&quot;</span><span class=cF0>
<a name="l246"></a> </span><span class=cF6>&quot;\t\tfp_set_std_palette = &amp;PaletteSet%s;\n}&quot;</span><span class=cF0>, tmp2, tmp1, tmp2);
<a name="l247"></a>
<a name="l248"></a> </span><span class=cF5>DocWrite</span><span class=cF0>(doc);
<a name="l249"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc);
<a name="l250"></a>}
<a name="l251"></a>
<a name="l252"></a>
<a name="l253"></a></span><span class=cF1>U0</span><span class=cF0> PaletteSetTemp(</span><span class=cF1>Bool</span><span class=cF0> persistent=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l254"></a>{</span><span class=cF2>//Activate temp palette.</span><span class=cF0>
<a name="l255"></a> </span><span class=cF5>GrPaletteSet</span><span class=cF0>(</span><span class=cFB>gr_palette</span><span class=cF0>);
<a name="l256"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l257"></a> </span><span class=cF1>if</span><span class=cF0> (persistent)
<a name="l258"></a> </span><span class=cFB>fp_set_std_palette</span><span class=cF0> = &amp;PaletteSetTemp;
<a name="l259"></a>}
<a name="l260"></a>
<a name="l261"></a></span><span class=cF1>U0</span><span class=cF0> PalettePrint(){
<a name="l262"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l263"></a>
<a name="l264"></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=cF3>COLORS_NUM</span><span class=cF0>; i++)
<a name="l265"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l266"></a> </span><span class=cF6>&quot;%d: #%X\n&quot;</span><span class=cF0>, i, </span><span class=cFB>gr_palette</span><span class=cF0>[i];
<a name="l267"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l268"></a>}
<a name="l269"></a>
<a name="l270"></a></span><span class=cF1>U0</span><span class=cF0> SelectColor(</span><span class=cF9>I64</span><span class=cF0> color_number, </span><span class=cF9>CCtrl</span><span class=cF0> *c)
<a name="l271"></a>{
<a name="l272"></a> selected_color = color_number;
<a name="l273"></a> CSliderState *s = c-&gt;state;
<a name="l274"></a>
<a name="l275"></a> s-&gt;left_pos = </span><span class=cFB>gr_palette</span><span class=cF0>[selected_color].r;
<a name="l276"></a> s-&gt;middle_pos= </span><span class=cFB>gr_palette</span><span class=cF0>[selected_color].g;
<a name="l277"></a> s-&gt;right_pos = </span><span class=cFB>gr_palette</span><span class=cF0>[selected_color].b;
<a name="l278"></a>}
<a name="l279"></a>
<a name="l280"></a></span><span class=cF1>U0</span><span class=cF0> UpdateDerivedCtrlSlider(</span><span class=cF9>CCtrl</span><span class=cF0> *c)
<a name="l281"></a>{
<a name="l282"></a> CSliderState *s = c-&gt;state;
<a name="l283"></a>
<a name="l284"></a>
<a name="l285"></a> c-&gt;left = (c-&gt;win_task-&gt;pix_width / </span><span class=cFE>2</span><span class=cF0>) - (SLIDER_SPACING * </span><span class=cFE>3</span><span class=cF0> + </span><span class=cFE>2</span><span class=cF0>) / </span><span class=cFE>2</span><span class=cF0>;
<a name="l286"></a> c-&gt;right = c-&gt;left + </span><span class=cFE>3</span><span class=cF0> * SLIDER_SPACING + </span><span class=cFE>2</span><span class=cF0>;
<a name="l287"></a> c-&gt;top = c-&gt;win_task-&gt;pix_height / </span><span class=cFE>2</span><span class=cF0> - (SLIDER_SPACING * </span><span class=cFE>2</span><span class=cF0> + SLIDER_RANGE) / </span><span class=cFE>2</span><span class=cF0>;
<a name="l288"></a> c-&gt;bottom = c-&gt;top + SLIDER_SPACING * </span><span class=cFE>2</span><span class=cF0> + SLIDER_RANGE;
<a name="l289"></a>
<a name="l290"></a> </span><span class=cF2>// I used to clamp between 0 and 127 and do math but i changed it to 256 for now.</span><span class=cF0>
<a name="l291"></a> s-&gt;left_pos = </span><span class=cF5>ClampI64</span><span class=cF0>(s-&gt;left_pos, </span><span class=cFE>0</span><span class=cF0>, SLIDER_RANGE);
<a name="l292"></a> s-&gt;middle_pos = </span><span class=cF5>ClampI64</span><span class=cF0>(s-&gt;middle_pos, </span><span class=cFE>0</span><span class=cF0>, SLIDER_RANGE);
<a name="l293"></a> s-&gt;right_pos = </span><span class=cF5>ClampI64</span><span class=cF0>(s-&gt;right_pos, </span><span class=cFE>0</span><span class=cF0>, SLIDER_RANGE);
<a name="l294"></a>
<a name="l295"></a> </span><span class=cF2>// add the slider's RGB value to s-&gt;preview </span><span class=cF0> </span><span class=cF2>// opposite for BGR</span><span class=cF0>
<a name="l296"></a> s-&gt;preview = s-&gt;right_pos + s-&gt;middle_pos &lt;&lt; </span><span class=cFE>8</span><span class=cF0> + s-&gt;left_pos &lt;&lt; </span><span class=cFE>16</span><span class=cF0>; </span><span class=cF2>//s-&gt;left_pos + s-&gt;middle_pos &lt;&lt; 8 + s-&gt;right_pos &lt;&lt; 16;</span><span class=cF0>
<a name="l297"></a>
<a name="l298"></a> </span><span class=cF2>// cheap way to force redraw 32bit colors</span><span class=cF0>
<a name="l299"></a> </span><span class=cF2>// TODO: make this not stupid</span><span class=cF0>
<a name="l300"></a> </span><span class=cF2>// can I use *last_task?</span><span class=cF0>
<a name="l301"></a> </span><span class=cF1>if</span><span class=cF0> (c-&gt;win_task-&gt;pix_left != l ||
<a name="l302"></a> c-&gt;win_task-&gt;pix_right != r ||
<a name="l303"></a> c-&gt;win_task-&gt;pix_bottom != b ||
<a name="l304"></a> c-&gt;win_task-&gt;pix_top != t)
<a name="l305"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l306"></a> l = c-&gt;win_task-&gt;pix_left;
<a name="l307"></a> r = c-&gt;win_task-&gt;pix_right;
<a name="l308"></a> t = c-&gt;win_task-&gt;pix_top;
<a name="l309"></a> b = c-&gt;win_task-&gt;pix_bottom;
<a name="l310"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l311"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l312"></a>}
<a name="l313"></a>
<a name="l314"></a>
<a name="l315"></a></span><span class=cF1>U0</span><span class=cF0> LeftClickSlider(</span><span class=cF9>CCtrl</span><span class=cF0> *c, </span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y, </span><span class=cF1>Bool</span><span class=cF0>)
<a name="l316"></a>{
<a name="l317"></a> CSliderState *s = c-&gt;state;
<a name="l318"></a>
<a name="l319"></a> </span><span class=cF1>if</span><span class=cF0> (x &lt; c-&gt;left + </span><span class=cFE>1</span><span class=cF0> * SLIDER_SPACING + </span><span class=cFE>0</span><span class=cF0> + SLIDER_SPACING / </span><span class=cFE>3</span><span class=cF0>)
<a name="l320"></a> s-&gt;left_pos = SLIDER_RANGE - </span><span class=cFE>1</span><span class=cF0> - (y - </span><span class=cF7>(</span><span class=cF0>c-&gt;top + SLIDER_SPACING</span><span class=cF7>)</span><span class=cF0>);
<a name="l321"></a>
<a name="l322"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (x &lt; c-&gt;left + </span><span class=cFE>2</span><span class=cF0> * SLIDER_SPACING + </span><span class=cFE>1</span><span class=cF0> + SLIDER_SPACING / </span><span class=cFE>3</span><span class=cF0>)
<a name="l323"></a> s-&gt;middle_pos = SLIDER_RANGE - </span><span class=cFE>1</span><span class=cF0> - (y - </span><span class=cF7>(</span><span class=cF0>c-&gt;top + SLIDER_SPACING</span><span class=cF7>)</span><span class=cF0>);
<a name="l324"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l325"></a> s-&gt;right_pos = SLIDER_RANGE - </span><span class=cFE>1</span><span class=cF0> - (y - </span><span class=cF7>(</span><span class=cF0>c-&gt;top + SLIDER_SPACING</span><span class=cF7>)</span><span class=cF0>);
<a name="l326"></a>
<a name="l327"></a> </span><span class=cF1>if</span><span class=cF0> (c-&gt;update_derived_vals)
<a name="l328"></a> (*c-&gt;update_derived_vals)(c);
<a name="l329"></a>
<a name="l330"></a> </span><span class=cF2>// set palette</span><span class=cF0>
<a name="l331"></a> </span><span class=cFB>gr_palette</span><span class=cF0>[selected_color] = s-&gt;preview;
<a name="l332"></a> PaletteSetTemp(</span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l333"></a>
<a name="l334"></a> current_palette = </span><span class=cF6>&quot;*New Palette&quot;</span><span class=cF0>;
<a name="l335"></a>}
<a name="l336"></a>
<a name="l337"></a></span><span class=cF9>CCtrl</span><span class=cF0> *SliderNew()
<a name="l338"></a>{
<a name="l339"></a> </span><span class=cF9>CCtrl</span><span class=cF0> *c = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CCtrl</span><span class=cF7>)</span><span class=cF0>);
<a name="l340"></a> c-&gt;win_task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l341"></a> c-&gt;flags = </span><span class=cF3>CTRLF_SHOW</span><span class=cF0> | </span><span class=cF3>CTRLF_CAPTURE_LEFT_MS</span><span class=cF0>;
<a name="l342"></a> c-&gt;type = </span><span class=cF3>CTRLT_GENERIC</span><span class=cF0>;
<a name="l343"></a> c-&gt;state = &amp;sld;
<a name="l344"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&amp;sld,</span><span class=cFE>0</span><span class=cF0>,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CSliderState</span><span class=cF7>)</span><span class=cF0>);
<a name="l345"></a> c-&gt;draw_it = &amp;DrawCtrlSlider;
<a name="l346"></a> c-&gt;left_click = &amp;LeftClickSlider;
<a name="l347"></a> c-&gt;update_derived_vals = &amp;UpdateDerivedCtrlSlider;
<a name="l348"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(c, </span><span class=cF5>Fs</span><span class=cF0>-&gt;last_ctrl);
<a name="l349"></a> </span><span class=cF5>TaskDerivedValsUpdate</span><span class=cF0>;
<a name="l350"></a> </span><span class=cF1>return</span><span class=cF0> c;
<a name="l351"></a>}
<a name="l352"></a>
<a name="l353"></a></span><span class=cF1>U0</span><span class=cF0> SliderDel(</span><span class=cF9>CCtrl</span><span class=cF0> *c)
<a name="l354"></a>{
<a name="l355"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(c);
<a name="l356"></a> </span><span class=cF5>Free</span><span class=cF0>(c);
<a name="l357"></a>}
<a name="l358"></a>
<a name="l359"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> PaletteEditor()
<a name="l360"></a>{
<a name="l361"></a>
<a name="l362"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>;
<a name="l363"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
<a name="l364"></a> </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l365"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>Open(,CH_CTRLO);&quot;</span><span class=cF0>
<a name="l366"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>SaveAs(,CH_CTRLA);&quot;</span><span class=cF0>
<a name="l367"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l368"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l369"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l370"></a> </span><span class=cF6>&quot;Edit {&quot;</span><span class=cF0>
<a name="l371"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>Hex(,'#');&quot;</span><span class=cF0>
<a name="l372"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>PreviousColor(,,SC_CURSOR_LEFT);&quot;</span><span class=cF0>
<a name="l373"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>PreviousColor(,,SC_CURSOR_UP);&quot;</span><span class=cF0>
<a name="l374"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>NextColor(,,SC_CURSOR_RIGHT);&quot;</span><span class=cF0>
<a name="l375"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>NextColor(,,SC_CURSOR_DOWN);&quot;</span><span class=cF0>
<a name="l376"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l377"></a> </span><span class=cF6>&quot;About {&quot;</span><span class=cF0>
<a name="l378"></a> </span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>Info(,CH_CTRLI);&quot;</span><span class=cF0>
<a name="l379"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l380"></a> );
<a name="l381"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l382"></a> </span><span class=cF5>WinBorder</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l383"></a>
<a name="l384"></a> </span><span class=cF9>CCtrl</span><span class=cF0> *c = SliderNew;
<a name="l385"></a> </span><span class=cF9>I64</span><span class=cF0> </span><span class=cF2>/*arg1, arg2,*/</span><span class=cF0> sc = </span><span class=cFE>0</span><span class=cF0>,
<a name="l386"></a> original_left, original_right, original_top, original_bottom;
<a name="l387"></a> </span><span class=cF1>Bool</span><span class=cF0> is_done = </span><span class=cF3>FALSE</span><span class=cF0>, keep_palette = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l388"></a>
<a name="l389"></a> original_left = c-&gt;win_task-&gt;win_left;
<a name="l390"></a> original_right = c-&gt;win_task-&gt;win_right;
<a name="l391"></a> original_top = c-&gt;win_task-&gt;win_top;
<a name="l392"></a> original_bottom = c-&gt;win_task-&gt;win_bottom;
<a name="l393"></a>
<a name="l394"></a> </span><span class=cF2>// windowed</span><span class=cF0>
<a name="l395"></a> c-&gt;win_task-&gt;win_left = (</span><span class=cF3>GR_WIDTH</span><span class=cF0> / </span><span class=cFE>23</span><span class=cF0>);
<a name="l396"></a> c-&gt;win_task-&gt;win_right = (</span><span class=cF3>GR_WIDTH</span><span class=cF0> / </span><span class=cFE>13</span><span class=cF0>);
<a name="l397"></a> c-&gt;win_task-&gt;win_top = </span><span class=cF3>GR_HEIGHT</span><span class=cF0> / </span><span class=cFE>80</span><span class=cF0>;
<a name="l398"></a> c-&gt;win_task-&gt;win_bottom = </span><span class=cF3>GR_HEIGHT</span><span class=cF0> / </span><span class=cFE>10</span><span class=cF0>;
<a name="l399"></a>
<a name="l400"></a>
<a name="l401"></a> </span><span class=cF2>// init pos for 32bit redraw</span><span class=cF0>
<a name="l402"></a> l = c-&gt;win_task-&gt;pix_left;
<a name="l403"></a> r = c-&gt;win_task-&gt;pix_right;
<a name="l404"></a> t = c-&gt;win_task-&gt;pix_top;
<a name="l405"></a> b = c-&gt;win_task-&gt;pix_bottom;
<a name="l406"></a>
<a name="l407"></a>
<a name="l408"></a> SelectColor(</span><span class=cFE>0</span><span class=cF0>, c);
<a name="l409"></a>
<a name="l410"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l411"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l412"></a> </span><span class=cF1>while</span><span class=cF0> (!is_done)
<a name="l413"></a> {
<a name="l414"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>KeyGet</span><span class=cF7>(</span><span class=cF0>&amp;sc</span><span class=cF7>)</span><span class=cF0>)
<a name="l415"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l416"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'#'</span><span class=cF0>:
<a name="l417"></a> manual_value = </span><span class=cF5>StrGet</span><span class=cF0>(</span><span class=cF6>&quot; Hex Value: #&quot;</span><span class=cF0>);
<a name="l418"></a> </span><span class=cFB>gr_palette</span><span class=cF0>[selected_color] = </span><span class=cF5>Str2I64</span><span class=cF0>(manual_value, </span><span class=cFE>16</span><span class=cF0>);
<a name="l419"></a> </span><span class=cF5>Free</span><span class=cF0>(manual_value);
<a name="l420"></a> SelectColor(selected_color, c);
<a name="l421"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l422"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l423"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l424"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>:
<a name="l425"></a> </span><span class=cF1>switch</span><span class=cF0> (sc.u8[</span><span class=cFE>0</span><span class=cF0>])
<a name="l426"></a> {
<a name="l427"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>:
<a name="l428"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_LEFT</span><span class=cF0>:
<a name="l429"></a> </span><span class=cF1>if</span><span class=cF0> (selected_color == </span><span class=cFE>0</span><span class=cF0>)
<a name="l430"></a> selected_color = </span><span class=cFE>16</span><span class=cF0>;
<a name="l431"></a> SelectColor(selected_color - </span><span class=cFE>1</span><span class=cF0>, c);
<a name="l432"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l433"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>:
<a name="l434"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0>:
<a name="l435"></a> </span><span class=cF1>if</span><span class=cF0> (selected_color == </span><span class=cFE>15</span><span class=cF0>)
<a name="l436"></a> selected_color = -</span><span class=cFE>1</span><span class=cF0>;
<a name="l437"></a> SelectColor(selected_color + </span><span class=cFE>1</span><span class=cF0>, c);
<a name="l438"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l439"></a> }
<a name="l440"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l441"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_CTRLO</span><span class=cF0>:
<a name="l442"></a> current_palette = </span><span class=cF6>&quot;&quot;</span><span class=cF0>;
<a name="l443"></a> current_palette = PaletteSelect;
<a name="l444"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l445"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_CTRLI</span><span class=cF0>:
<a name="l446"></a> </span><span class=cF5>PopUpOk</span><span class=cF0>(</span><span class=cF6>&quot;\n\n Use the arrows to select color\n\n # to manually input hex value&quot;</span><span class=cF0>,</span><span class=cF6>&quot;\n\n\n\t\tMade by y4my4m\n\n&quot;</span><span class=cF0>);
<a name="l447"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l448"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_CTRLA</span><span class=cF0>:
<a name="l449"></a> PESave(</span><span class=cF3>TRUE</span><span class=cF0>, c);
<a name="l450"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l451"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
<a name="l452"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&amp;gr_temp_palette, </span><span class=cFB>gr_palette</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CBGR24</span><span class=cF7>)</span><span class=cF0> * </span><span class=cF3>COLORS_NUM</span><span class=cF0>);
<a name="l453"></a> keep_palette = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l454"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
<a name="l455"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l456"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l457"></a> is_done = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l458"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l459"></a> </span><span class=cF5>Refresh</span><span class=cF0>;
<a name="l460"></a> }
<a name="l461"></a>
<a name="l462"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l463"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l464"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l465"></a>
<a name="l466"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l467"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l468"></a>
<a name="l469"></a> </span><span class=cF1>if</span><span class=cF0> (keep_palette)
<a name="l470"></a> </span><span class=cF5>GrPaletteSet</span><span class=cF0>(gr_temp_palette);
<a name="l471"></a>
<a name="l472"></a> SliderDel(c);
<a name="l473"></a> </span><span class=cF5>DocBottom</span><span class=cF0>;
<a name="l474"></a>
<a name="l475"></a>
<a name="l476"></a> c-&gt;win_task-&gt;win_left = original_left;
<a name="l477"></a> c-&gt;win_task-&gt;win_right = original_right;
<a name="l478"></a> c-&gt;win_task-&gt;win_top = original_top;
<a name="l479"></a> c-&gt;win_task-&gt;win_bottom = original_bottom;
<a name="l480"></a>}
</span></pre></body>
</html>

View file

@ -0,0 +1,43 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF0>
<a name="l2"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> PaletteGodGenerate()
<a name="l3"></a>{
<a name="l4"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l5"></a> </span><span class=cF9>CBGR24</span><span class=cF0> palette;
<a name="l6"></a>
<a name="l7"></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>16</span><span class=cF0>; i++)
<a name="l8"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l9"></a> palette = </span><span class=cF5>GodPick</span><span class=cF0> &amp; </span><span class=cFE>0xFFFFFF</span><span class=cF0>;
<a name="l10"></a> </span><span class=cFB>gr_palette</span><span class=cF0>[i] = palette;
<a name="l11"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l12"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l13"></a>}
<a name="l14"></a>
<a name="l15"></a>PaletteGodGenerate;</span></pre></body>
</html>

View file

@ -0,0 +1,90 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF0>#</span><span class=cF1>ifndef</span><span class=cF0> PALETTES_PATH
<a name="l2"></a></span><span class=cF5>Cd</span><span class=cF0>(</span><span class=cF3>__DIR__</span><span class=cF0>);;
<a name="l3"></a>#</span><span class=cF1>include</span><span class=cF0> </span><span class=cF6>&quot;Load&quot;</span><span class=cF0>
<a name="l4"></a>#</span><span class=cF1>endif</span><span class=cF0>
<a name="l5"></a>
<a name="l6"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> PaletteSet(</span><span class=cF1>U8</span><span class=cF0> *palette_name=</span><span class=cF6>&quot;Slate&quot;</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> persistent=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l7"></a>{</span><span class=cF2>//Pass filename (without ext) as string to load palette</span><span class=cF0>
<a name="l8"></a> </span><span class=cF1>U8</span><span class=cF0> *dir = PALETTES_PATH,
<a name="l9"></a> *path = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>&quot;%Q%Q%Q&quot;</span><span class=cF0>, dir, palette_name, </span><span class=cF6>&quot;.CC&quot;</span><span class=cF0>);</span><span class=cF2>//,</span><span class=cF0>
<a name="l10"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>*file = FileRead(path);</span><span class=cF0>
<a name="l11"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>I64 temp_file, i;</span><span class=cF0>
<a name="l12"></a>
<a name="l13"></a></span><span class=cF2>/*</span><span class=cF0> </span><span class=cF2>for</span><span class=cF0> </span><span class=cF2>(i = 0; i &lt; COLORS_NUM; i++)</span><span class=cF0>
<a name="l14"></a> </span><span class=cF2>{</span><span class=cF0>
<a name="l15"></a> </span><span class=cF2>StrFirstRemove(file, &quot;,&quot;, temp_file);</span><span class=cF0>
<a name="l16"></a> </span><span class=cF2>gr_palette[i] = Str2I64(temp_file, 16);</span><span class=cF0>
<a name="l17"></a> </span><span class=cF2>}*/</span><span class=cF0>
<a name="l18"></a> </span><span class=cF5>ExeFile</span><span class=cF0>(path);
<a name="l19"></a> </span><span class=cF5>ExePrint</span><span class=cF0>(</span><span class=cF6>&quot;PaletteSet%s;;&quot;</span><span class=cF0>, palette_name);
<a name="l20"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l21"></a> </span><span class=cF1>if</span><span class=cF0> (persistent)
<a name="l22"></a> </span><span class=cF5>ExePrint</span><span class=cF0>(</span><span class=cF6>&quot;fp_set_std_palette = &amp;PaletteSet%s;;&quot;</span><span class=cF0>, palette_name);
<a name="l23"></a>}
<a name="l24"></a>
<a name="l25"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> PaletteSelect()
<a name="l26"></a>{
<a name="l27"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde1 = </span><span class=cF3>NULL</span><span class=cF0>, *tmpde2;
<a name="l28"></a>
<a name="l29"></a> </span><span class=cF9>CDoc</span><span class=cF0> *doc = </span><span class=cF5>DocNew</span><span class=cF0>;
<a name="l30"></a> </span><span class=cF9>I64</span><span class=cF0> res = </span><span class=cFE>0</span><span class=cF0>;
<a name="l31"></a> </span><span class=cF9>I64</span><span class=cF0> res2 = </span><span class=cFE>0</span><span class=cF0>;
<a name="l32"></a>
<a name="l33"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc, </span><span class=cF6>&quot;$LTBLUE$\n\n&quot;</span><span class=cF0>);
<a name="l34"></a>
<a name="l35"></a> tmpde1 = </span><span class=cF5>FilesFind</span><span class=cF0>(</span><span class=cF6>&quot;~/PaletteEditor/Palettes/*.CC&quot;</span><span class=cF0>);
<a name="l36"></a>
<a name="l37"></a> </span><span class=cF1>if</span><span class=cF0> (tmpde1)
<a name="l38"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l39"></a> </span><span class=cF1>while</span><span class=cF0> (tmpde1)
<a name="l40"></a> {
<a name="l41"></a> tmpde2 = tmpde1-&gt;next;
<a name="l42"></a> res++;
<a name="l43"></a>
<a name="l44"></a> </span><span class=cF5>FileExtRemove</span><span class=cF0>(tmpde1-&gt;name);
<a name="l45"></a>
<a name="l46"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc, </span><span class=cF6>&quot; $MU,\&quot;%d.%s\&quot;,LE=0x%X$\n&quot;</span><span class=cF0>, res, tmpde1-&gt;name, tmpde1-&gt;name);
<a name="l47"></a> </span><span class=cF5>DirEntryDel</span><span class=cF0>(tmpde1);
<a name="l48"></a>
<a name="l49"></a> tmpde1 = tmpde2;
<a name="l50"></a> }
<a name="l51"></a>
<a name="l52"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l53"></a>
<a name="l54"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc, </span><span class=cF6>&quot;\n\n$BT+CX,\&quot;CANCEL\&quot;,LE=0$\n\n&quot;</span><span class=cF0>);
<a name="l55"></a> res2 = </span><span class=cF5>PopUpMenu</span><span class=cF0>(doc);
<a name="l56"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc);
<a name="l57"></a>
<a name="l58"></a> </span><span class=cF1>if</span><span class=cF0> (res2 != </span><span class=cFE>0</span><span class=cF0>)
<a name="l59"></a> PaletteSet(res2, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l60"></a>
<a name="l61"></a> </span><span class=cF1>return</span><span class=cF0> res2;
<a name="l62"></a>}</span></pre></body>
</html>

View file

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF1>public</span><span class=cF0> </span><span class=cF9>CBGR24</span><span class=cF0> </span><span class=cFB>gr_palette_commander</span><span class=cF0>[</span><span class=cF3>COLORS_NUM</span><span class=cF0>] = {
<a name="l2"></a></span><span class=cFE>0xFFFFFF</span><span class=cF0>, </span><span class=cFE>0x867ADE</span><span class=cF0>, </span><span class=cFE>0xCC55</span><span class=cF0>, </span><span class=cFE>0x5A878B</span><span class=cF0>, </span><span class=cFE>0xB80000</span><span class=cF0>, </span><span class=cFE>0xCC44CC</span><span class=cF0>, </span><span class=cFE>0xDD8855</span><span class=cF0>, </span><span class=cFE>0xBBBBBB</span><span class=cF0>, </span><span class=cFE>0x777777</span><span class=cF0>, </span><span class=cFE>0x88FF</span><span class=cF0>, </span><span class=cFE>0xAAFF66</span><span class=cF0>, </span><span class=cFE>0xAAFFEE</span><span class=cF0>, </span><span class=cFE>0xFF7777</span><span class=cF0>, </span><span class=cFE>0xCA94E8</span><span class=cF0>, </span><span class=cFE>0xEEEE77</span><span class=cF0>, </span><span class=cFE>0x483AAA</span><span class=cF0>
<a name="l3"></a>};
<a name="l4"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>PaletteSetCommander</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> persistent=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l5"></a>{
<a name="l6"></a> </span><span class=cF5>GrPaletteSet</span><span class=cF0>(</span><span class=cFB>gr_palette_commander</span><span class=cF0>);
<a name="l7"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (persistent)
<a name="l9"></a> </span><span class=cFB>fp_set_std_palette</span><span class=cF0> = &amp;</span><span class=cF5>PaletteSetCommander</span><span class=cF0>;
<a name="l10"></a>}</span></pre></body>
</html>

View file

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF1>public</span><span class=cF0> </span><span class=cF9>CBGR24</span><span class=cF0> gr_palette_green[</span><span class=cF3>COLORS_NUM</span><span class=cF0>] = {
<a name="l2"></a></span><span class=cFE>0xEEFCD7</span><span class=cF0>, </span><span class=cFE>0x79824F</span><span class=cF0>, </span><span class=cFE>0x336019</span><span class=cF0>, </span><span class=cFE>0x297582</span><span class=cF0>, </span><span class=cFE>0xB34F4B</span><span class=cF0>, </span><span class=cFE>0x8F49</span><span class=cF0>, </span><span class=cFE>0xA24D1B</span><span class=cF0>, </span><span class=cFE>0x444444</span><span class=cF0>, </span><span class=cFE>0x6D6D6D</span><span class=cF0>, </span><span class=cFE>0x94BFDE</span><span class=cF0>, </span><span class=cFE>0xA1CE97</span><span class=cF0>, </span><span class=cFE>0x6DB4BE</span><span class=cF0>, </span><span class=cFE>0xE88E88</span><span class=cF0>, </span><span class=cFE>0xCA94E8</span><span class=cF0>, </span><span class=cFE>0xD4B475</span><span class=cF0>, </span><span class=cFE>0x142223</span><span class=cF0>
<a name="l3"></a>};
<a name="l4"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> PaletteSetGreen(</span><span class=cF1>Bool</span><span class=cF0> persistent=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l5"></a>{
<a name="l6"></a> </span><span class=cF5>GrPaletteSet</span><span class=cF0>(gr_palette_green);
<a name="l7"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (persistent)
<a name="l9"></a> </span><span class=cFB>fp_set_std_palette</span><span class=cF0> = &amp;PaletteSetGreen;
<a name="l10"></a>}</span></pre></body>
</html>

View file

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF1>public</span><span class=cF0> </span><span class=cF9>CBGR24</span><span class=cF0> gr_palette_marine[</span><span class=cF3>COLORS_NUM</span><span class=cF0>] = {
<a name="l2"></a></span><span class=cFE>0xE2E8EB</span><span class=cF0>, </span><span class=cFE>0x5BD2D4</span><span class=cF0>, </span><span class=cFE>0x496076</span><span class=cF0>, </span><span class=cFE>0x307AFF</span><span class=cF0>, </span><span class=cFE>0xD86D22</span><span class=cF0>, </span><span class=cFE>0xFFD91F</span><span class=cF0>, </span><span class=cFE>0xFFEF2F</span><span class=cF0>, </span><span class=cFE>0x4F8A97</span><span class=cF0>, </span><span class=cFE>0xA161C</span><span class=cF0>, </span><span class=cFE>0xE24594</span><span class=cF0>, </span><span class=cFE>0xA1CE97</span><span class=cF0>, </span><span class=cFE>0x6DB4BE</span><span class=cF0>, </span><span class=cFE>0xFF575B</span><span class=cF0>, </span><span class=cFE>0xB1AA9E</span><span class=cF0>, </span><span class=cFE>0xD53368</span><span class=cF0>, </span><span class=cFE>0xE2331</span><span class=cF0>
<a name="l3"></a>};
<a name="l4"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> PaletteSetMarine(</span><span class=cF1>Bool</span><span class=cF0> persistent=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l5"></a>{
<a name="l6"></a> </span><span class=cF5>GrPaletteSet</span><span class=cF0>(gr_palette_marine);
<a name="l7"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (persistent)
<a name="l9"></a> </span><span class=cFB>fp_set_std_palette</span><span class=cF0> = &amp;PaletteSetMarine;
<a name="l10"></a>}</span></pre></body>
</html>

View file

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF1>public</span><span class=cF0> </span><span class=cF9>CBGR24</span><span class=cF0> </span><span class=cFB>gr_palette_slate</span><span class=cF0>[</span><span class=cF3>COLORS_NUM</span><span class=cF0>] = {
<a name="l2"></a></span><span class=cFE>0xE3E3E3</span><span class=cF0>, </span><span class=cFE>0x4F84A6</span><span class=cF0>, </span><span class=cFE>0x73A255</span><span class=cF0>, </span><span class=cFE>0x297582</span><span class=cF0>, </span><span class=cFE>0xB34F4B</span><span class=cF0>, </span><span class=cFE>0x8A52C3</span><span class=cF0>, </span><span class=cFE>0xB7822F</span><span class=cF0>, </span><span class=cFE>0x444444</span><span class=cF0>, </span><span class=cFE>0x6D6D6D</span><span class=cF0>, </span><span class=cFE>0x94BFDE</span><span class=cF0>, </span><span class=cFE>0xA1CE97</span><span class=cF0>, </span><span class=cFE>0x6DB4BE</span><span class=cF0>, </span><span class=cFE>0xE88E88</span><span class=cF0>, </span><span class=cFE>0xCA94E8</span><span class=cF0>, </span><span class=cFE>0xD4B475</span><span class=cF0>, </span><span class=cFE>0x1F1F1F</span><span class=cF0>
<a name="l3"></a>};
<a name="l4"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>PaletteSetSlate</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> persistent=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l5"></a>{
<a name="l6"></a> </span><span class=cF5>GrPaletteSet</span><span class=cF0>(</span><span class=cFB>gr_palette_slate</span><span class=cF0>);
<a name="l7"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (persistent)
<a name="l9"></a> </span><span class=cFB>fp_set_std_palette</span><span class=cF0> = &amp;</span><span class=cF5>PaletteSetSlate</span><span class=cF0>;
<a name="l10"></a>}</span></pre></body>
</html>

View file

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF1>public</span><span class=cF0> </span><span class=cF9>CBGR24</span><span class=cF0> gr_palette_temple[</span><span class=cF3>COLORS_NUM</span><span class=cF0>] = {
<a name="l2"></a></span><span class=cFE>0x0</span><span class=cF0>, </span><span class=cFE>0xAA</span><span class=cF0>, </span><span class=cFE>0xAA00</span><span class=cF0>, </span><span class=cFE>0xAAAA</span><span class=cF0>, </span><span class=cFE>0xAA0000</span><span class=cF0>, </span><span class=cFE>0xAA00AA</span><span class=cF0>, </span><span class=cFE>0xAA5500</span><span class=cF0>, </span><span class=cFE>0xAAAAAA</span><span class=cF0>, </span><span class=cFE>0x555555</span><span class=cF0>, </span><span class=cFE>0x5555FF</span><span class=cF0>, </span><span class=cFE>0x55FF55</span><span class=cF0>, </span><span class=cFE>0x55FFFF</span><span class=cF0>, </span><span class=cFE>0xFF5555</span><span class=cF0>, </span><span class=cFE>0xFF55FF</span><span class=cF0>, </span><span class=cFE>0xFFFF55</span><span class=cF0>, </span><span class=cFE>0xFFFFFF</span><span class=cF0>
<a name="l3"></a>};
<a name="l4"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> PaletteSetTemple(</span><span class=cF1>Bool</span><span class=cF0> persistent=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l5"></a>{
<a name="l6"></a> </span><span class=cF5>GrPaletteSet</span><span class=cF0>(gr_palette_temple);
<a name="l7"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (persistent)
<a name="l9"></a> </span><span class=cFB>fp_set_std_palette</span><span class=cF0> = &amp;PaletteSetTemple;
<a name="l10"></a>}</span></pre></body>
</html>

View file

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF1>public</span><span class=cF0> </span><span class=cF9>CBGR24</span><span class=cF0> gr_palette_zsnes[</span><span class=cF3>COLORS_NUM</span><span class=cF0>] = {
<a name="l2"></a></span><span class=cFE>0xE8E8E9</span><span class=cF0>, </span><span class=cFE>0x374B88</span><span class=cF0>, </span><span class=cFE>0x6C84FC</span><span class=cF0>, </span><span class=cFE>0x297582</span><span class=cF0>, </span><span class=cFE>0x63D64E</span><span class=cF0>, </span><span class=cFE>0x397AFF</span><span class=cF0>, </span><span class=cFE>0xB7822F</span><span class=cF0>, </span><span class=cFE>0x25256E</span><span class=cF0>, </span><span class=cFE>0x712</span><span class=cF0>, </span><span class=cFE>0xFF2A76</span><span class=cF0>, </span><span class=cFE>0xA1CE97</span><span class=cF0>, </span><span class=cFE>0x6DB4BE</span><span class=cF0>, </span><span class=cFE>0x9FA6FF</span><span class=cF0>, </span><span class=cFE>0xCA94E8</span><span class=cF0>, </span><span class=cFE>0xFFCC00</span><span class=cF0>, </span><span class=cFE>0x132C</span><span class=cF0>
<a name="l3"></a>};
<a name="l4"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> PaletteSetZsnes(</span><span class=cF1>Bool</span><span class=cF0> persistent=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l5"></a>{
<a name="l6"></a> </span><span class=cF5>GrPaletteSet</span><span class=cF0>(gr_palette_zsnes);
<a name="l7"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (persistent)
<a name="l9"></a> </span><span class=cFB>fp_set_std_palette</span><span class=cF0> = &amp;PaletteSetZsnes;
<a name="l10"></a>}</span></pre></body>
</html>

View file

@ -0,0 +1,41 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cE4{color:#b34f4b;background-color:#d4b475;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF0>Directory of C:/Home/PaletteEditor/Palettes
<a name="l2"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/Palettes/index.html#l1"><span class=cE4>./</span></a><span class=cF0>
<a name="l3"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/index.html#l1"><span class=cE4>../</span></a><span class=cF4>
<a name="l4"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/Palettes/Commander.CC.html#l1"><span class=cF4>Commander.CC</span></a><span class=cF4>
<a name="l5"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/Palettes/Green.CC.html#l1"><span class=cF4>Green.CC</span></a><span class=cF4>
<a name="l6"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/Palettes/Marine.CC.html#l1"><span class=cF4>Marine.CC</span></a><span class=cF4>
<a name="l7"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/Palettes/Slate.CC.html#l1"><span class=cF4>Slate.CC</span></a><span class=cF4>
<a name="l8"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/Palettes/Temple.CC.html#l1"><span class=cF4>Temple.CC</span></a><span class=cF4>
<a name="l9"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/Palettes/Zsnes.CC.html#l1"><span class=cF4>Zsnes.CC</span></a><span class=cF0>
<a name="l10"></a>
<a name="l11"></a>
</span></pre></body>
</html>

View file

@ -0,0 +1,31 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF5>Cd</span><span class=cF0>(</span><span class=cF3>__DIR__</span><span class=cF0>);;
<a name="l2"></a>#</span><span class=cF1>include</span><span class=cF0> </span><span class=cF6>&quot;Load&quot;</span><span class=cF0>
<a name="l3"></a>PaletteEditor;</span></pre></body>
</html>

View file

@ -0,0 +1,41 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cE4{color:#b34f4b;background-color:#d4b475;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF0>Directory of C:/Home/PaletteEditor
<a name="l2"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/index.html#l1"><span class=cE4>./</span></a><span class=cF0>
<a name="l3"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/index.html#l1"><span class=cE4>../</span></a><span class=cF0>
<a name="l4"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/Palettes/index.html#l1"><span class=cE4>Palettes/</span></a><span class=cF4>
<a name="l5"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/Load.CC.html#l1"><span class=cF4>Load.CC</span></a><span class=cF4>
<a name="l6"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/PaletteEdit.CC.html#l1"><span class=cF4>PaletteEdit.CC</span></a><span class=cF4>
<a name="l7"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/PaletteGod.CC.html#l1"><span class=cF4>PaletteGod.CC</span></a><span class=cF4>
<a name="l8"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/PaletteSelect.CC.html#l1"><span class=cF4>PaletteSelect.CC</span></a><span class=cF4>
<a name="l9"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/Run.CC.html#l1"><span class=cF4>Run.CC</span></a><span class=cF0>
<a name="l10"></a>
<a name="l11"></a>
</span></pre></body>
</html>

View file

@ -29,17 +29,18 @@ body {background-color:#1f1f1f;}
<a name="l1"></a><span class=cF0>Directory of C:/Home
<a name="l2"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/index.html#l1"><span class=cE4>./</span></a><span class=cF0>
<a name="l3"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/index.html#l1"><span class=cE4>../</span></a><span class=cF0>
<a name="l4"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/Net/index.html#l1"><span class=cE4>Net/</span></a><span class=cF4>
<a name="l5"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/DoDistro.CC.html#l1"><span class=cF4>DoDistro.CC</span></a><span class=cF4>
<a name="l6"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/HtmlGen.CC.html#l1"><span class=cF4>HtmlGen.CC</span></a><span class=cF4>
<a name="l7"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/K.CC.html#l1"><span class=cF4>K.CC</span></a><span class=cF4>
<a name="l8"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/MakeHome.CC.html#l1"><span class=cF4>MakeHome.CC</span></a><span class=cF4>
<a name="l9"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/Registry.CC.html#l1"><span class=cF4>Registry.CC</span></a><span class=cF4>
<a name="l10"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/SSE.CC.html#l1"><span class=cF4>SSE.CC</span></a><span class=cF4>
<a name="l11"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/Basics.DD.html#l1"><span class=cF4>Basics.DD</span></a><span class=cF4>
<a name="l12"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/Roadmap.DD.html#l1"><span class=cF4>Roadmap.DD</span></a><span class=cF4>
<a name="l13"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/ASCII-ZEAL.TXT.html#l1"><span class=cF4>ASCII-ZEAL.TXT</span></a><span class=cF0>
<a name="l14"></a>
<a name="l4"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/Net/index.html#l1"><span class=cE4>Net/</span></a><span class=cF0>
<a name="l5"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/PaletteEditor/index.html#l1"><span class=cE4>PaletteEditor/</span></a><span class=cF4>
<a name="l6"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/DoDistro.CC.html#l1"><span class=cF4>DoDistro.CC</span></a><span class=cF4>
<a name="l7"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/HtmlGen.CC.html#l1"><span class=cF4>HtmlGen.CC</span></a><span class=cF4>
<a name="l8"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/K.CC.html#l1"><span class=cF4>K.CC</span></a><span class=cF4>
<a name="l9"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/MakeHome.CC.html#l1"><span class=cF4>MakeHome.CC</span></a><span class=cF4>
<a name="l10"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/Registry.CC.html#l1"><span class=cF4>Registry.CC</span></a><span class=cF4>
<a name="l11"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/SSE.CC.html#l1"><span class=cF4>SSE.CC</span></a><span class=cF4>
<a name="l12"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/Basics.DD.html#l1"><span class=cF4>Basics.DD</span></a><span class=cF4>
<a name="l13"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/Roadmap.DD.html#l1"><span class=cF4>Roadmap.DD</span></a><span class=cF4>
<a name="l14"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Home/rfc793.DD.html#l1"><span class=cF4>rfc793.DD</span></a><span class=cF0>
<a name="l15"></a>
<a name="l16"></a>
</span></pre></body>
</html>

View file

@ -116,6 +116,5 @@ body {background-color:#1f1f1f;}
<a name="l89"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l90"></a> </span><span class=cF1>if</span><span class=cF0> (persistent)
<a name="l91"></a> </span><span class=cFB>fp_set_std_palette</span><span class=cF0> = &amp;</span><span class=cF5>PaletteSetCommander</span><span class=cF0>;
<a name="l92"></a>}
</span></pre></body>
<a name="l92"></a>}</span></pre></body>
</html>

View file

@ -440,7 +440,7 @@ body {background-color:#1f1f1f;}
<a name="l413"></a> </span><span class=cF5>GrUpdateTasks</span><span class=cF0>;
<a name="l414"></a> </span><span class=cF5>DCBlotColor8</span><span class=cF0>(</span><span class=cFB>gr</span><span class=cF0>.dc2, </span><span class=cFB>gr</span><span class=cF0>.dc);
<a name="l415"></a>
<a name="l416"></a> dc=</span><span class=cF5>DCAlias</span><span class=cF0>(</span><span class=cFB>gr</span><span class=cF0>.dc2, </span><span class=cF5>Fs</span><span class=cF0>);
<a name="l416"></a> dc = </span><span class=cF5>DCAlias</span><span class=cF0>(</span><span class=cFB>gr</span><span class=cF0>.dc2, </span><span class=cF5>Fs</span><span class=cF0>);
<a name="l417"></a> dc-&gt;flags |= </span><span class=cF3>DCF_ON_TOP</span><span class=cF0>;
<a name="l418"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>gr</span><span class=cF0>.fp_final_screen_update)
<a name="l419"></a> (*</span><span class=cFB>gr</span><span class=cF0>.fp_final_screen_update)(dc);

View file

@ -89,12 +89,15 @@ body {background-color:#1f1f1f;}
<a name="l62"></a> </span><span class=cF5>Find</span><span class=cF0>(</span><span class=cF6>&quot;DrawStdMs&quot;</span><span class=cF0>, ff_mask, fu_flags, </span><span class=cF6>&quot;DrawStdMouse&quot;</span><span class=cF0>);
<a name="l63"></a> </span><span class=cF5>Find</span><span class=cF0>(</span><span class=cF6>&quot;WIG_TASK_DFT&quot;</span><span class=cF0>, ff_mask, fu_flags, </span><span class=cF6>&quot;WIG_TASK_DEFAULT&quot;</span><span class=cF0>);
<a name="l64"></a> </span><span class=cF5>Find</span><span class=cF0>(</span><span class=cF6>&quot;DirMk&quot;</span><span class=cF0>, ff_mask, fu_flags, </span><span class=cF6>&quot;DirMake&quot;</span><span class=cF0>);
<a name="l65"></a>
<a name="l66"></a>
<a name="l67"></a> </span><span class=cF6>&quot;\n$BK,1$$LTRED$Might want to go over these$FG$$BK,0$\n&quot;</span><span class=cF0>;
<a name="l68"></a> </span><span class=cF5>Find</span><span class=cF0>(</span><span class=cF6>&quot;MemSet&quot;</span><span class=cF0>, ff_mask, fu_flags);
<a name="l69"></a>}
<a name="l70"></a>
<a name="l71"></a></span><span class=cF2>//Cvt(&quot;Sup1/*&quot;);</span><span class=cF0>
<a name="l65"></a> </span><span class=cF5>Find</span><span class=cF0>(</span><span class=cF6>&quot;GetI64&quot;</span><span class=cF0>, ff_mask, fu_flags, </span><span class=cF6>&quot;I64Get&quot;</span><span class=cF0>);
<a name="l66"></a> </span><span class=cF5>Find</span><span class=cF0>(</span><span class=cF6>&quot;GetF64&quot;</span><span class=cF0>, ff_mask, fu_flags, </span><span class=cF6>&quot;F64Get&quot;</span><span class=cF0>);
<a name="l67"></a> </span><span class=cF5>Find</span><span class=cF0>(</span><span class=cF6>&quot;GetStr&quot;</span><span class=cF0>, ff_mask, fu_flags, </span><span class=cF6>&quot;StrGet&quot;</span><span class=cF0>);
<a name="l68"></a> </span><span class=cF5>Find</span><span class=cF0>(</span><span class=cF6>&quot;GetChar&quot;</span><span class=cF0>, ff_mask, fu_flags, </span><span class=cF6>&quot;CharGet&quot;</span><span class=cF0>);
<a name="l69"></a>
<a name="l70"></a> </span><span class=cF6>&quot;\n$BK,1$$LTRED$Might want to go over these$FG$$BK,0$\n&quot;</span><span class=cF0>;
<a name="l71"></a> </span><span class=cF5>Find</span><span class=cF0>(</span><span class=cF6>&quot;MemSet&quot;</span><span class=cF0>, ff_mask, fu_flags);
<a name="l72"></a>}
<a name="l73"></a>
<a name="l74"></a></span><span class=cF2>//Cvt(&quot;Sup1/*&quot;);</span><span class=cF0>
</span></pre></body>
</html>

File diff suppressed because it is too large Load diff

View file

@ -15,8 +15,8 @@ U0 LoadDocDefines()
//$LK,"DD_BOOT_HIGH_LOC_DVD",A="FF:::/System/Boot/BootDVD.CC,DD_BOOT_HIGH_LOC_DVD"$
$TR,"LineRep"$
$ID,2$DefinePrint("DD_ZEALOS_LOC","95,288");
$ID,-2$
$ID,2$DefinePrint("DD_ZEALOS_LOC","95,267");
$ID,-2$
DefinePrint("DD_MP_VECT", "%08X", MP_VECT_ADDR);
DefinePrint("DD_MP_VECT_END", "%08X", MP_VECT_ADDR + COREAP_16BIT_INIT_END - COREAP_16BIT_INIT - 1);