4 <title>Fifth - virtual machine, operating system, programming language</title>
5 <!-- 2018-07-01 Sun 23:59 -->
7 <meta name="viewport" content="width=device-width, initial-scale=1">
8 <meta name="generator" content="Org-mode">
9 <meta name="author" content="Svjatoslav Agejenko">
10 <link href="https://bootswatch.com/3/darkly/bootstrap.min.css" rel="stylesheet">
11 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
12 <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
13 <style type="text/css">
14 footer {background-color: #111 !important;}
15 pre {background-color: #111; color: #ccc;}
17 <style type="text/css">
18 /* org mode styles on top of twbs */
35 background-color: #f5f5f5;
62 display: inline-block;
74 .bs-docs-sidebar.affix {
77 @media (min-width: 768px) {
83 /* All levels of nav */
84 .bs-docs-sidebar .nav > li > a {
91 .bs-docs-sidebar .nav > li > a:hover,
92 .bs-docs-sidebar .nav > li > a:focus {
95 text-decoration: none;
96 background-color: transparent;
97 border-left: 1px solid #A1283B;
99 .bs-docs-sidebar .nav > .active > a,
100 .bs-docs-sidebar .nav > .active:hover > a,
101 .bs-docs-sidebar .nav > .active:focus > a {
105 background-color: transparent;
106 border-left: 2px solid #A1283B;
109 /* Nav: second level (shown on .active) */
110 .bs-docs-sidebar .nav .nav {
111 display: none; /* Hide by default, but at >768px, show it */
112 padding-bottom: 10px;
114 .bs-docs-sidebar .nav .nav > li > a {
121 .bs-docs-sidebar .nav .nav > li > a:hover,
122 .bs-docs-sidebar .nav .nav > li > a:focus {
125 .bs-docs-sidebar .nav .nav > .active > a,
126 .bs-docs-sidebar .nav .nav > .active:hover > a,
127 .bs-docs-sidebar .nav .nav > .active:focus > a {
132 /* Nav: third level (shown on .active) */
133 .bs-docs-sidebar .nav .nav .nav {
134 padding-bottom: 10px;
136 .bs-docs-sidebar .nav .nav .nav > li > a {
143 .bs-docs-sidebar .nav .nav .nav > li > a:hover,
144 .bs-docs-sidebar .nav .nav .nav > li > a:focus {
147 .bs-docs-sidebar .nav .nav .nav > .active > a,
148 .bs-docs-sidebar .nav .nav .nav > .active:hover > a,
149 .bs-docs-sidebar .nav .nav .nav > .active:focus > a {
154 /* Show and affix the side nav when space allows it */
155 @media (min-width: 992px) {
156 .bs-docs-sidebar .nav > .active > ul {
159 /* Widen the fixed sidebar */
160 .bs-docs-sidebar.affix,
161 .bs-docs-sidebar.affix-bottom {
164 .bs-docs-sidebar.affix {
165 position: fixed; /* Undo the static from mobile first approach */
168 .bs-docs-sidebar.affix-bottom {
169 position: absolute; /* Undo the static from mobile first approach */
171 .bs-docs-sidebar.affix .bs-docs-sidenav,.bs-docs-sidebar.affix-bottom .bs-docs-sidenav {
176 @media (min-width: 1200px) {
177 /* Widen the fixed sidebar again */
178 .bs-docs-sidebar.affix-bottom,
179 .bs-docs-sidebar.affix {
184 <script type="text/javascript">
188 $('.bs-docs-sidebar li').first().addClass('active');
190 $(document.body).scrollspy({target: '.bs-docs-sidebar'});
192 $('.bs-docs-sidebar').affix();
196 <script type="text/x-mathjax-config">
198 displayAlign: "center",
199 displayIndent: "2em",
200 messageStyle: "none",
204 ".MathJax_Display": {
212 ".MathJax_SVG_Display": {
214 "margin-left": "-2.281em"
220 <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_SVG"></script>
223 <div id="content" class="container">
224 <div class="row"><div class="col-md-9"><h1 class="title">Fifth - virtual machine, operating system, programming language</h1>
225 <div id="outline-container-sec-1" class="outline-2">
226 <h2 id="sec-1"><span class="section-number-2">1</span> General</h2>
227 <div class="outline-text-2" id="text-1">
229 <li>This program is free software: you can redistribute it and/or modify
230 it under the terms of the <a href="https://www.gnu.org/licenses/lgpl.html">GNU Lesser General Public License</a> as
231 published by the Free Software Foundation, either version 3 of the
232 License, or (at your option) any later version.
237 <li>Svjatoslav Agejenko
239 <li>Homepage: <a href="http://svjatoslav.eu">http://svjatoslav.eu</a>
241 <li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a>
246 <li><a href="http://www.svjatoslav.eu/projects/">Other software projects hosted at svjatoslav.eu</a>
251 <div id="outline-container-sec-1-1" class="outline-3">
252 <h3 id="sec-1-1"><span class="section-number-3">1.1</span> Source code</h3>
253 <div class="outline-text-3" id="text-1-1">
255 <li><a href="http://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=snapshot;h=HEAD;sf=tgz">Download latest snapshot in TAR GZ format</a>
258 <li><a href="http://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=summary">Browse Git repository online</a>
261 <li>Clone Git repository using command:
262 <pre class="example">
263 git clone http://www2.svjatoslav.eu/git/fifth.git
271 <div id="outline-container-sec-2" class="outline-2">
272 <h2 id="sec-2"><span class="section-number-2">2</span> Warning</h2>
273 <div class="outline-text-2" id="text-2">
275 Current implementation does not support object oriented
276 programming. While working on Fifth I got lots of cool new ideas that
277 require reimplementation of everything.
281 Currently I try to implement those new ideas in the project called
282 <a href="http://www3.svjatoslav.eu/projects/sixth/">Sixth</a>
286 System is built many years ago when I was still using DOS as a primary
287 operating system and not updated since.
291 <div id="outline-container-sec-3" class="outline-2">
292 <h2 id="sec-3"><span class="section-number-2">3</span> Introduction</h2>
293 <div class="outline-text-2" id="text-3">
295 Fifth is programming lanquage & operating system, running on <i>virtual
296 CPU</i>, with custom instruction set. It is much like Charles Chunk
297 Moore's Forth, it also uses stack architecture, and many commands are
298 similar. Basically I got familiar with concepts of Forth, and being
299 inspired created my own system.
303 <li><a href="5TH_ET.txt">Example Fifth source file - text editor</a>
307 <div id="outline-container-sec-3-1" class="outline-3">
308 <h3 id="sec-3-1"><span class="section-number-3">3.1</span> screenshots</h3>
309 <div class="outline-text-3" id="text-3-1">
311 <li><img src="screenshots/start.png" class="img-responsive" alt="start.png">
313 <li>Startup screen diplaying Fifth logo and full file list.
318 <li><img src="screenshots/dictionary.png" class="img-responsive" alt="dictionary.png">
320 <li>Sample words defined. Most of the words are commands that can be
321 executed interactively from command line or from file. When
322 executed they can be selectively compiled or interpreted.
327 <li><img src="screenshots/text editor.png" class="img-responsive" alt="text editor.png">
329 <li>Built in text editor.
338 <div id="outline-container-sec-4" class="outline-2">
339 <h2 id="sec-4"><span class="section-number-2">4</span> Installation</h2>
340 <div class="outline-text-2" id="text-4">
342 Just unpack all files, witout altering original directory structure,
343 somewhere in your hard disk. For example:
345 <pre class="example">
349 To run fifth you need minimally just 2 files. emulator itself (
350 EMULATOR.EXE or EMULATOR.COM ), and virtual disk file ( DISK.RAW ).
354 Read more about <i>distribution directory layout</i>
358 <div id="outline-container-sec-5" class="outline-2">
359 <h2 id="sec-5"><span class="section-number-2">5</span> Fifth distribution directory tree description</h2>
360 <div class="outline-text-2" id="text-5">
362 After downloading and unpacking the ZIP file you shoud get directory
363 tree similar to this:
367 [DOC] - Fifth documentation<br >
368   [commands] - documentation on Fifth built-in commands<br >
369   [modules] - documentation on additional commands, realized as loadable modules<br >
370   [shots] - Fifth screenshots<br >
372 [imageFile] - files contained within 'disk.raw', just an extracted form.<br >
374 [source] - source files<br >
375   [emulator] - emulator source<br >
376   [util] - utilites<br >
378 disk.raw - Virtual disk file, has filesystem inside.<br >
379 emulator.com - main executable.<br >
384 <div id="outline-container-sec-6" class="outline-2">
385 <h2 id="sec-6"><span class="section-number-2">6</span> Software/Hardware/Human requirements</h2>
386 <div class="outline-text-2" id="text-6">
387 </div><div id="outline-container-sec-6-1" class="outline-3">
388 <h3 id="sec-6-1"><span class="section-number-3">6.1</span> Software</h3>
389 <div class="outline-text-3" id="text-6-1">
391 <li>MS-DOS 6.22, with HIMEM.SYS loaded.
393 <li>Mouse driver if you have a mouse.
395 <li>Does work only when CPU is in real mode.
397 <li>To recompile ASM sources I used FASM (Flat Assembler).
399 <li>I ran QBasic utilities on QB 4.5 .
401 <li>VESA support by BIOS, or external driver (UNIVBE).
406 <div id="outline-container-sec-6-2" class="outline-3">
407 <h3 id="sec-6-2"><span class="section-number-3">6.2</span> Hardware</h3>
408 <div class="outline-text-3" id="text-6-2">
412 <li>64 KB free RAM below 640KB,
414 <li>2 MB of free XMS.
416 <li>VESA compatible video card.
421 <div id="outline-container-sec-6-3" class="outline-3">
422 <h3 id="sec-6-3"><span class="section-number-3">6.3</span> Human</h3>
423 <div class="outline-text-3" id="text-6-3">
425 <li>Beginner level Forth knowledge is recommended.
427 <li>Lots of enthusiasm.
433 <div id="outline-container-sec-7" class="outline-2">
434 <h2 id="sec-7"><span class="section-number-2">7</span> Numbers representation within Fifth</h2>
435 <div class="outline-text-2" id="text-7">
438 <p><a href="numbers.png"><img src="numbers.png" class="img-responsive" alt="numbers.png"></a>
443 Because I can define everything, starting from CPU, why not try also
444 alternative and unique number representation ?
448 Fifth uses its hexdecimal number representation as primary. Numbers
449 shape is formed by dividing a square into four parts. And manipulating
450 their color (black or white).
454 <div id="outline-container-sec-8" class="outline-2">
455 <h2 id="sec-8"><span class="section-number-2">8</span> Disk file map, and it's data structures</h2>
456 <div class="outline-text-2" id="text-8">
458 Core and high-level boot code is stored outside of the filesystem to
459 allow easy access to it, at early booting time, when filesystem is not
463 <div id="outline-container-sec-8-1" class="outline-3">
464 <h3 id="sec-8-1"><span class="section-number-3">8.1</span> disk allocation</h3>
465 <div class="outline-text-3" id="text-8-1">
466 <table class="table table-striped table-bordered table-hover table-condensed">
478 <th scope="col" class="text-left">offset</th>
479 <th scope="col" class="text-left">length</th>
480 <th scope="col" class="text-left">description</th>
485 <td class="text-left">0</td>
486 <td class="text-left">~4 Kb</td>
487 <td class="text-left">Fifth core</td>
491 <td class="text-left">4 Kb</td>
492 <td class="text-left">~32Kb</td>
493 <td class="text-left">high-level boot code</td>
497 <td class="text-left">37 Kb</td>
498 <td class="text-left">~65Kb</td>
499 <td class="text-left">FAT</td>
503 <td class="text-left">101Kb</td>
504 <td class="text-left">~16MB</td>
505 <td class="text-left">filesystem data area</td>
511 <div id="outline-container-sec-8-2" class="outline-3">
512 <h3 id="sec-8-2"><span class="section-number-3">8.2</span> FAT entry format:</h3>
513 <div class="outline-text-3" id="text-8-2">
514 <table class="table table-striped table-bordered table-hover table-condensed">
524 <th scope="col" class="text-right">code</th>
525 <th scope="col" class="text-left">meaning</th>
530 <td class="text-right">-2</td>
531 <td class="text-left">last sector</td>
535 <td class="text-right">-1</td>
536 <td class="text-left">empty sector</td>
540 <td class="text-right">0 --</td>
541 <td class="text-left">.. pointer to next block</td>
547 <div id="outline-container-sec-8-3" class="outline-3">
548 <h3 id="sec-8-3"><span class="section-number-3">8.3</span> file entry format</h3>
549 <div class="outline-text-3" id="text-8-3">
550 <table class="table table-striped table-bordered table-hover table-condensed">
562 <th scope="col" class="text-right">offset</th>
563 <th scope="col" class="text-right">length</th>
564 <th scope="col" class="text-left">description</th>
569 <td class="text-right">0</td>
570 <td class="text-right">4</td>
571 <td class="text-left">extension</td>
575 <td class="text-right">4</td>
576 <td class="text-right">16</td>
577 <td class="text-left">name</td>
581 <td class="text-right">20</td>
582 <td class="text-right">4</td>
583 <td class="text-left">entry point</td>
587 <td class="text-right">24</td>
588 <td class="text-right">4</td>
589 <td class="text-left">size</td>
593 <td class="text-right">28</td>
594 <td class="text-right">4</td>
595 <td class="text-left">last modification time</td>
602 <div id="outline-container-sec-9" class="outline-2">
603 <h2 id="sec-9"><span class="section-number-2">9</span> Core architecture</h2>
604 <div class="outline-text-2" id="text-9">
606 Fifth core is simply some amount of already compiled into machine code
607 and linked together modules (entries in other words). In compilation
608 process modules is compiled one by one and simply stored on top of
609 already existing and growing core. Separately from core is kept
610 dictionary, this is special list that contain names of compiled
611 modules, variables etc. and they locations in core. Constants use
612 dictionary space only. Random word can be removed from dictionary at
613 any time. Currently dictionary can contain at most 1000 entries.
616 <div id="outline-container-sec-9-1" class="outline-3">
617 <h3 id="sec-9-1"><span class="section-number-3">9.1</span> Dictionary entry format</h3>
618 <div class="outline-text-3" id="text-9-1">
619 <table class="table table-striped table-bordered table-hover table-condensed">
631 <th scope="col" class="text-right">offset</th>
632 <th scope="col" class="text-right">length</th>
633 <th scope="col" class="text-left">description</th>
638 <td class="text-right">0</td>
639 <td class="text-right">4</td>
640 <td class="text-left">0 &lt; previous entry</td>
644 <td class="text-right"> </td>
645 <td class="text-right"> </td>
646 <td class="text-left">0 = last</td>
650 <td class="text-right"> </td>
651 <td class="text-right"> </td>
652 <td class="text-left">-1 = empty</td>
657 <td class="text-right">4</td>
658 <td class="text-right">15</td>
659 <td class="text-left">module name string</td>
664 <td class="text-right">19</td>
665 <td class="text-right">1</td>
666 <td class="text-left">entry type</td>
671 <td class="text-right">20</td>
672 <td class="text-right">4</td>
673 <td class="text-left">entry data</td>
679 Core headers as linked list of module names make up something like
680 dictionary. When some entry address is needed compiler can quickly
681 run through headers backwards and find needed entry.
685 <div id="outline-container-sec-9-2" class="outline-3">
686 <h3 id="sec-9-2"><span class="section-number-3">9.2</span> Possible module types</h3>
687 <div class="outline-text-3" id="text-9-2">
688 <table class="table table-striped table-bordered table-hover table-condensed">
700 <th scope="col" class="text-right">type</th>
701 <th scope="col" class="text-left">description</th>
702 <th scope="col" class="text-left">"execute" action</th>
707 <td class="text-right">0</td>
708 <td class="text-left">data</td>
709 <td class="text-left">compile "num" instruction</td>
713 <td class="text-right"> </td>
714 <td class="text-left"> </td>
715 <td class="text-left">with address to module</td>
720 <td class="text-right">1</td>
721 <td class="text-left">submodule</td>
722 <td class="text-left">compile "call" instruction</td>
726 <td class="text-right"> </td>
727 <td class="text-left"> </td>
728 <td class="text-left">with address to module</td>
733 <td class="text-right">2</td>
734 <td class="text-left">imm. submodule</td>
735 <td class="text-left">immediately call to module</td>
741 <div id="outline-container-sec-9-3" class="outline-3">
742 <h3 id="sec-9-3"><span class="section-number-3">9.3</span> Memory map (average)</h3>
743 <div class="outline-text-3" id="text-9-3">
744 <table class="table table-striped table-bordered table-hover table-condensed">
756 <th scope="col" class="text-right"><loc></th>
757 <th scope="col" class="text-left"><size></th>
758 <th scope="col" class="text-left"><desc></th>
763 <td class="text-right">0</td>
764 <td class="text-left">~4096</td>
765 <td class="text-left">core</td>
769 <td class="text-right">1500000</td>
770 <td class="text-left">~32000</td>
771 <td class="text-left">highlevel Fifth boot code</td>
775 <td class="text-right">200000h</td>
776 <td class="text-left"> </td>
777 <td class="text-left">core startup messages area</td>
781 <td class="text-right">5200000</td>
782 <td class="text-left"> </td>
783 <td class="text-left">end of dynamic memory space</td>
790 <div id="outline-container-sec-10" class="outline-2">
791 <h2 id="sec-10"><span class="section-number-2">10</span> Virtual machine</h2>
792 <div class="outline-text-2" id="text-10">
794 Using CPU emulator slows it down but I shouldn't now think too mutch
795 about, and waste my time on batteling with problems whitch results on
796 complex design of PC hardware. Also it allows me to use existing DOS
797 and resident drivers services in real mode. So I don't need to deal
798 with hardware too mutch. It also allows me to use all free XMS for
799 flat code & data storage.
803 Current emulator emulates 1 CPU. It has 2 stacks, ~50 instructions,
804 and 4GB flat address space (theoretically). I'm not sure that DOS
805 6.22 that I currently prefer can handle more than 64 MB of RAM. While
806 I tried to keep instructionset simple, I was forced to put in lot of
807 complex instructions to make it's performance acceptable on
808 emulator. On actual silicon ~20 instructions is enaugh (I think).
812 Maybe one day similar system will run directly on custom silicon chip :)
817 CPU has following registers:
819 <table class="table table-striped table-bordered table-hover table-condensed">
829 <td class="text-left">IP</td>
830 <td class="text-left">instruction pointer</td>
834 <td class="text-left">DSP</td>
835 <td class="text-left">data stack pointer</td>
839 <td class="text-left">RSP</td>
840 <td class="text-left">return stack pointer</td>
846 Virtual CPU, commands (most of them are avaiable as ordinary commands
847 in programming lanquage):
852 code mnemonic description<br >
854 0 nop does notheing<br >
855 1 halt halt CPU ( return to DOS on emulator )<br >
857 2 kbd@ ( – c ) read scancode of pressed or released key.<br >
858                                 Returns 0, if no data avaiable.<br >
859 3 num <dword> ( – n ) put immidiate number into datastack<br >
861 4 jmp <dword> jump to specified code<br >
862 5 call <dword>jump to specified code, save return address to<br >
863                                 return stack.<br >
865 6 1+ ( n – n+1 )<br >
866 7 1- ( n – n-1 )<br >
868 8 dup ( n – n n ) duplicate top of data stack<br >
869 9 drop ( n – ) drop last element in data stack<br >
871 10 if <dword> ( n – ) jump to addr if top element was 0<br >
872 11 ret jump to code, specified in return stack.<br >
874 12 c@ ( addr – n ) read byte from memory at specified address<br >
875 13 c! ( n addr – ) store byte to specified memory<br >
877 14 push ( DSTK -> RSTK ) move top of datastack to returnstack<br >
878 15 pop ( RSTK -> DSTK ) move top of returnstack to datastack<br >
880 16 <unused><br >
881 17 rot ( n1 n2 n3 – n2 n3 n1) rotate stack elements<br >
883 18 disk@ ( FromDiskSect ToMem – ) read 1KB from disk into RAM<br >
884 19 disk! ( FromMem ToDiskSect – ) write 1KB to disk<br >
886 20 @ ( addr – n ) read 32 bit number from memory<br >
887 21 ! ( n addr – ) store 32 bit number to memory<br >
889 22 over ( n1 n2 – n1 n2 n1 ) self explaining …<br >
890 23 swap ( n1 n2 – n2 n1 ) -,,-<br >
892 24 + ( n1 n2 – n1+n2 ) -,,-<br >
893 25 - ( n1 n2 – n1-n2 ) -,,-<br >
895 26 * ( n1 n2 – n1*n2 ) -,,-<br >
896 27 / ( n1 n2 – n1/n2 ) -,,-<br >
898 28 > ( n1 n2 – result ) is true when n1 > n2<br >
899 29 < ( n1 n2 – result ) is true when n1 < n2<br >
901 30 not ( n1 – not_n1 ) logical not<br >
902 31 i ( – n ) copies top of return stack into datastack<br >
904 32 cprt@ ( addr – n ) read one byte from hardware port<br >
905 33 cprt! ( n addr – ) store one byte to hardware port<br >
907 34 i2 ( – n ) like "i" but takes socond top stack element.<br >
908 35 i3 ( – n ) like "i" but takes third top stack element.<br >
910 36 shl ( n amount – n ) left bit shift<br >
911 37 shr ( n amount – n ) right bit shift<br >
913 38 or ( n1 n2 – n ) logical or<br >
914 39 xor ( n1 n2 – n ) exclusive logical or<br >
916 40 vidmap ( addr – ) copy memory from "addr" to video memory.<br >
918 41 mouse@ ( – x y button ) read mouse coordinates & buttons<br >
920 42 vidput ( addr1 addr2 x y – ) put image1 into image2, at<br >
921                                 location x, y. Does clipping, so part of a big image<br >
922                                 can be mapped into smaller one.<br >
924 43 cmove ( addr1 addr2 amount ) move memory from addr1 to addr2<br >
925                                 if addr1 is greater than addr2 then count address<br >
926                                 foward while moving, elseway starts from end and<br >
927                                 counts backwards, so no data loss will occure on<br >
928                                 overlapping.<br >
930 44 cfill ( c addr amount – ) fill memory starting at "addr"<br >
931                                 with "c" bytes.<br >
933 45 tvidput ( addr1 addr2 x y – ) same as "vidput" but treats<br >
934                                 color 255 in source image as transparent.<br >
936 46 depth ( – depth ) returns current depth of data stack.<br >
938 47 charput ( colorfg colorbg addrsrc addrdest x y )<br >
939                                 draw character to image buffer located at "addrdest"<br >
940                                 to specified x & y location. Decodes 8 bytes from<br >
941                                 source to bits, used to draw character.<br >
946 <div id="outline-container-sec-11" class="outline-2">
947 <h2 id="sec-11"><span class="section-number-2">11</span> Fifth source format</h2>
948 <div class="outline-text-2" id="text-11">
950 Fifth uses a different character table and codes than ASCII (still
951 almost similar). I call it FSCII (Fifth Standard Code for Information
952 Interchange) for example space character is not 32 but 255 instead. I
953 plan to use mainly HEX numbers, and create new characters to represent
954 numeric values. So typical nemric characters "0123…" is treated
955 like ordinary letters.
958 <div id="outline-container-sec-11-1" class="outline-3">
959 <h3 id="sec-11-1"><span class="section-number-3">11.1</span> FSCII</h3>
960 <div class="outline-text-3" id="text-11-1">
961 <table class="table table-striped table-bordered table-hover table-condensed">
973 <th scope="col" class="text-right">DEC</th>
974 <th scope="col" class="text-left">HEX</th>
975 <th scope="col" class="text-left">function</th>
980 <td class="text-right">0 - 15</td>
981 <td class="text-left">0 - F</td>
982 <td class="text-left">HEX numbers</td>
986 <td class="text-right">252</td>
987 <td class="text-left">FC</td>
988 <td class="text-left">backspace</td>
992 <td class="text-right">253</td>
993 <td class="text-left">FD</td>
994 <td class="text-left">tabulator (TAB)</td>
998 <td class="text-right">254</td>
999 <td class="text-left">FE</td>
1000 <td class="text-left">carriage return (CR)</td>
1004 <td class="text-right">255</td>
1005 <td class="text-left">FF</td>
1006 <td class="text-left">space</td>
1010 <td class="text-right">else</td>
1011 <td class="text-left"> </td>
1012 <td class="text-left">ordinary characters, same as in ASCII.</td>
1019 <div id="outline-container-sec-12" class="outline-2">
1020 <h2 id="sec-12"><span class="section-number-2">12</span> Fifth commands</h2>
1021 <div class="outline-text-2" id="text-12">
1022 </div><div id="outline-container-sec-12-1" class="outline-3">
1023 <h3 id="sec-12-1"><span class="section-number-3">12.1</span> Compilation & miscellaneous</h3>
1024 <div class="outline-text-3" id="text-12-1">
1026 init module ( – )<br >
1027                 First module, control is passed to on startup. Contains<br >
1028                 initialization routines. Also it is the last core module.<br >
1029                 All new modules on top of it comes as result of executing<br >
1030                 external source files.<br >
1032 head <name> ( – ) compiles new dictionary entry without specifying<br >
1033                 new module type.<br >
1034                 ex: head myentry<br >
1036 : <name> ( – ) creates new code module<br >
1037 ; ( – ) ends module (immideate)<br >
1038                 ex: : hello ." hi there" ;<br >
1040 const <name> ( n – ) defines new constant.<br >
1041                 ex: 2147483647 const max<br >
1043 :i <name> ( – ) same as ":" but this module will be executed<br >
1044                 immideately even in compile mode.<br >
1045                 ex: :i ( 41 scan ;<br >
1047 create <name> ( – ) same as "head" , but specify module type as data.<br >
1048                 ex: create LotoResults 5 , 13 , 52 , 12 , 11 , 3 ,<br >
1050 allot ( n – ) allocate n bytes in dictionary.<br >
1051                 ex: create MyArray 100 allot<br >
1053 " <string>" ( – ) compile string and its size into core.<br >
1054                 ex: create Mystring " This is it's contects"<br >
1056 str <name> <string>" ( – ) just shorter way for defining strings.<br >
1057                 ex: str Mystring This is it's contenc"<br >
1059 var <name> ( – ) define new 32 bit variable.<br >
1060                 ex: var result<br >
1062 ' <module> ( – n ) return memory address of given entry.<br >
1063                 ex: ' init<br >
1065 forget <name> ( – ) erases from RAM given entry and all entries what was<br >
1066                 defined after it.<br >
1067                 ex: forget myprog<br >
1069 [ ( – ) set interpret mode (immideate)<br >
1070 ] ( n – ) set compile mode and compile top stack element<br >
1071                 in as literal. Together [ …. ] cobination provides good<br >
1072                 way to compute some values only once, at compile time,<br >
1073                 rather than every time while program is running.<br >
1074                 ex: : calculate - [ 4 MyConst1 + MyConst2 * ] ;<br >
1076 defer <name> ( – ) creates new module, with jump instruction.<br >
1077                 Later address where to jump can be modified by "is" command.<br >
1078                 This provides method of foward referencing. So you can use<br >
1079                 modules what not jet exist.<br >
1080 is ( address1 address2 – ) address1 - where to jump, address2 -<br >
1081                 address of module created by defer command.<br >
1082                 ex: defer dispver<br >
1083                         : run dispver ." running …" ;<br >
1084                                … whatever …<br >
1085                         : (dispver ." Version 9.99 " ;<br >
1086                         ' (dispver ' dispver is<br >
1088                 Now if I type "run" on the screen appears:<br >
1089                         Version 9.99 running …<br >
1091 asc <char> ( – ) reads char ascii code and treats it as literal.<br >
1092                 (immideate)<br >
1093                 ex: : BreakLine 30 do asc - emit loop ;<br >
1094                                  same as:<br >
1095                     : BreakLine 30 do 45 emit loop ;<br >
1097 dyninc ( handle – ) execute code in dynamic memory handle.<br >
1098                 automatically deallocates it when done.<br >
1100 include ( filenumber – ) execute code in specified file.<br >
1102 words ( – ) display existing blocks in core.<br >
1104 bye ( – ) exit from Fifth<br >
1106 fkey ( – c )<br >
1107                 Read one byte from input stream.<br >
1109 sadd ( c addr – )<br >
1110                 Add one byte "c" to string located at "addr" and updates<br >
1111                 string length.<br >
1113 scan ( c – )<br >
1114                 Read input stream and store it to pad until it finds c .<br >
1115                 It ignores all "c" bytes until it finds any non "c" byte.<br >
1116                 in other words:<br >
1117                                 c is: "<br >
1118                          input stream: """"This is test !"aoeu idh<br >
1119                                result: This is test !<br >
1121                 Is useful for breaking text lines into words.<br >
1123 skey ( – c )<br >
1124                 So called safe "fkey". Reads data from input stream<br >
1125                 but converts characters with ASCII codes: 9 13 10<br >
1126                 to spaces.<br >
1128 str=str? ( adr1 adr2 – result )<br >
1129                 Compares string at "adr1" with string at "adr2", returns<br >
1130                 true flag if they are equal or false if they are not.<br >
1131                 true = -1<br >
1132                 false = 0<br >
1134 find ( – addr )<br >
1135                 Searches whole dictionary for word in "pad". If found,<br >
1136                 returns it address, if not, returns 0.<br >
1138 execute ( – )<br >
1139                 Execute word located in "pad". Depending on "mode".<br >
1141 dta ( addr – DataAddr )<br >
1142                 Calculates address of dictionary entry data area, from<br >
1143                 entry point.<br >
1145 2num ( – num result )<br >
1146                 Attempt to convert string located in "pad" into numeric<br >
1147                 value. If succeed returns number and true as result.<br >
1148                 If not, returns whatever and false as result.<br >
1150 dadd ( addr length – )<br >
1151                 Add to dictionary data located at "addr", with specified<br >
1152                 length.<br >
1154 lit ( n – )<br >
1155                 Act with number depending on "mode". When interpreting,<br >
1156                 leaves it in stack.<br >
1159 incmod ( addr – )<br >
1160                 Add to dictionary data located at "addr"+1 , length is taken<br >
1161                 from "addr".<br >
1163 here ( – n )<br >
1164                 return "h" contents.<br >
1167                 Holds input stream parser operation mode.<br >
1168                 0 = interpreting<br >
1169                 1 = compiling<br >
1171 pad var 128 bytes<br >
1172                 Holds temprorary strings.<br >
1175                 Pointer to free byte in memory, always at the end of the<br >
1176                 dictionary. Each time when something is stored<br >
1177                 by "c," command, pointer is incareased.<br >
1180                 Pointer to last dictionary word. Each time when new word is<br >
1181                 compiled or erased by "forget", this pointer is updated.<br >
1183 modulechk ( Dstr<filename> – ) check if module is loaded, if not<br >
1184                 immideately load it.<br >
1186 ne ( entrydata entrytype – ) Compile new dictionary entry.<br >
1187                 It's name must be in "pad".<br >
1191 <div id="outline-container-sec-12-2" class="outline-3">
1192 <h3 id="sec-12-2"><span class="section-number-3">12.2</span> Conditionals & control flow</h3>
1193 <div class="outline-text-3" id="text-12-2">
1195 if ( flag – ) (immideate)<br >
1196                 "if 1.. else 2.. then" or<br >
1197                 "if 1.. then" construction. Conditional execution.<br >
1198                 Performs "1.." if "flag" was true,<br >
1199                 elseway performs "2.." if exist. Execution continues after<br >
1200                 word "then".<br >
1201                 ex: 1 if ." nonzero" else ." zero" then<br >
1203 >= ( n1 n2 – result ) true if (n1 = n2) or (n1 > n2)<br >
1204                 ex: 5 3 >= if ." first number is greater or equal" then<br >
1206 <= ( n1 n2 – result ) true if (n1 = n2) or (n1 < n2)<br >
1207 = ( n1 n2 – result ) true if n1 = n2<br >
1209 do ( count – ) (immideate)<br >
1210                 "do .. loop" construction. Performs ".." "count" times.<br >
1211                 In every step "count" is decareased until it is 0.<br >
1212                 ex: : test 5 do i .d loop ;<br >
1213                 result: 4 3 2 1 0<br >
1215 doexit ( – ) exit from "do .. loop"<br >
1217 for ( count top – ) (immideate)<br >
1218                 "for .. loop" construction. Performs ".." (top - count) times.<br >
1219                 In every step "count" is incareased until it reaches "top" .<br >
1220                 ex: : test 4 10 for i .d loop ;<br >
1221                 result: 4 5 6 7 8 9<br >
1223 forexit ( – ) exit from "for .. loop"<br >
1225 until ( – ) (immideate)<br >
1226                 "until .. loop" construction. Performs ".." until flag become<br >
1227                 true. False by default. Top of return stack holds flag.<br >
1229 done ( – ) exit from "until .. loop"<br >
1234 <div id="outline-container-sec-12-3" class="outline-3">
1235 <h3 id="sec-12-3"><span class="section-number-3">12.3</span> Disk & file access</h3>
1236 <div class="outline-text-3" id="text-12-3">
1238 diskload ( FromDisk ToMem amount – )<br >
1239                 Load specified abount of bytes from disk into memory.<br >
1241 disksave ( FromMem ToDisk amount – )<br >
1242                 save specified abount of bytes from memory into disk.<br >
1244 format ( – ) Erase all files.<br >
1246 fsDfilesize@ ( handle – size )<br >
1247                 Return size of opened file.<br >
1249 fsDcurloc@ ( handle – location )<br >
1250                 Return current location in file.<br >
1252 fsDupdated@ ( handle – updated? )<br >
1253                 Return true if file was updated,<br >
1254                 ie. write operations occured.<br >
1256 fssave ( FromMem DestFileHandle amount – )<br >
1257                 Save data to file.<br >
1259 fsload ( SrcFileHandle ToMem amount – )<br >
1260                 Load data from file.<br >
1262 fseof ( handle – bytesLeft )<br >
1263                 Return amount of bytes left till end of file.<br >
1264                 Useful before read operation.<br >
1266 fsls ( – ) List all files and lists (directories,folders)<br >
1267                 in current path.<br >
1269 fslsr ( – ) Same as "fsls" but recursively scans also sub lists.<br >
1271 fscl ( DynStrHand – )<br >
1272                 Change list (path)<br >
1274 fscreate ( DynStrHand – DescPnt )<br >
1275                 Create new file or list. Can create multiple lists at once.<br >
1276                 ex: when creating:<br >
1277                     "\listGAMES\listSTRATEGY\listSIMWORLD\5th-runme"<br >
1278                 and only "\listGAMES\" already exist, then<br >
1279                 "listSTRATEGY" and "listSIMWORLD" lists will be created,<br >
1280                 and empty file "5th-runme" placed in there.<br >
1282 fsDsave ( DynHand<data> DynStrHand<filename> – )<br >
1283                 Create new file and save all data from dynamic memory<br >
1284                 block to it.<br >
1286 fsDload ( DynStr<SrcFileName> DynHand<DataDest> – )<br >
1287                 Load whole file into dynamic memory block.<br >
1289 fsDloadnew ( DynStr<SrcFileName> – DynHand<DataDest> )<br >
1290                 Load whole file into new dynamic memory block.<br >
1294 <div id="outline-container-sec-12-4" class="outline-3">
1295 <h3 id="sec-12-4"><span class="section-number-3">12.4</span> Dynamic memory</h3>
1296 <div class="outline-text-3" id="text-12-4">
1298 dynal ( size – handle )<br >
1299                 Allocate dynamic memory block and return it's handle.<br >
1301 dynde ( handle – )<br >
1302                 Deallocate dynamic memory block.<br >
1304 dynp ( handle – addr )<br >
1305                 Returns pointer to memory where dynamic block<br >
1306                 data begins.<br >
1308 dyns ( handle – size )<br >
1309                 Returns size of dynamic block.<br >
1311 dynresize ( NewSize handle – )<br >
1312                 Nondestructively resize dynamic block.<br >
1314 dync@ ( addr handle )<br >
1315                 Read one byte from dynamic block.<br >
1317 dync! ( byte addr dynhandle )<br >
1318                 Write one byte to dynamic block.<br >
1320 dyn@ ( addr handle )<br >
1321                 Read 32 bit number from dynamic block.<br >
1322                 Address will spacify, whitch number, not byte.<br >
1324 dyn! ( 32BitNum addr dynhandle )<br >
1325                 Write 32 bit number to dynamic block.<br >
1326                 Address will spacify, whitch number, not byte.<br >
1328 dyncon ( size "name" – )<br >
1329                 Allocate dynamic block with specified size, and<br >
1330                 create constant honding its handle.<br >
1331                 ex: 100 dyncon MyNewBlock<br >
1333 dyn. ( handle – )<br >
1334                 Write contenc of dynamic memory block to screen.<br >
1338 <div id="outline-container-sec-12-5" class="outline-3">
1339 <h3 id="sec-12-5"><span class="section-number-3">12.5</span> Graphics and text</h3>
1340 <div class="outline-text-3" id="text-12-5">
1342 . ( n – ) print number on screen<br >
1344 d. ( n – ) print number on screen in decimal<br >
1346 ? ( addr – ) print 32 bit value located at addr.<br >
1348 ." <string>" ( – ) print string into screen. Immideately<br >
1349                 compiles.<br >
1350                 ex: : greeting ." Hello, World" ;<br >
1352 tab. ( – ) print tabulator<br >
1354 calccol ( b g r – c ) calculate color what best matches given<br >
1355                 Blue Green & Red values. Values must be in range 0 - 255.<br >
1357 imgalloc ( xsize ysize – imgbuf ) allocate image buffer for<br >
1358                 specified size.<br >
1360 imgsize ( imgbuf – ) print on the screen X & Y size of image<br >
1361                 buffer.<br >
1363 point ( x y imgbuf – addr ) returns memory address for specified<br >
1364                 pixel.<br >
1366 pset ( color x y imgbuf – ) set graphic point<br >
1368 boxf ( x1 x2 y1 y2 imgbuf color – ) draw filled box<br >
1370 cls ( imgbuf – ) clear image buffer<br >
1372 setpal ( b g r color – ) set palette value for specified color.<br >
1373                 values bust be in size 0 - 63.<br >
1375 putchar ( char color x y imgbuf – ) put graphic character in<br >
1376                 imagebuffer to specified (x & y) location.<br >
1378 scroll ( x y imgbuf – ) scroll in imgbuf.<br >
1380 scrollf ( color x y screen – ) scroll and fill empty space with<br >
1381                 given color.<br >
1383 at! ( x y – ) set cursor location<br >
1384 curc! ( color – ) set text color<br >
1385 curb! ( solor – ) set backround color<br >
1387 colnorm ( – ) set text color to normal<br >
1388 colneg ( – ) set text color to negative (selected)<br >
1390 dyntype ( dynhandle – ) display contenc of dynamic memory on screen<br >
1391 fsdisp ( file – ) clear screen, display file, and wait for key<br >
1393 type ( addr length – )<br >
1394                 Types on the screen string, from memory at addr and<br >
1395                 specified length.<br >
1397 write ( addr – )<br >
1398                 Types on the screen string, from memory at "addr"+1<br >
1399                 length is taken from "addr" .<br >
1401 screen const 32 bit<br >
1402                 Holds handle of screen buffer.<br >
1404 copyscreen ( SrcImgHandle DestImgHandle – ) copy contenc of source<br >
1405                 image to destination image. Source and destination images<br >
1406                 must have same size.<br >
1410 <div id="outline-container-sec-12-6" class="outline-3">
1411 <h3 id="sec-12-6"><span class="section-number-3">12.6</span> Math, memory & stack manipulation</h3>
1412 <div class="outline-text-3" id="text-12-6">
1414 off ( n – ) writes 0 to given address, good for zeroing variable.<br >
1415                 ex: MyVariable off<br >
1416 on ( n – ) writes -1 (true flag) to given address.<br >
1417                 ex: MyVariable on<br >
1419 2dup ( n1 n2 – n1 n2 n1 n2 )<br >
1420 2drop ( n1 n2 – )<br >
1421 nip ( n1 n2 – n2 )<br >
1422 neg ( n1 – -n1 ) negotiate<br >
1423 bit@ ( n bit – result ) return specified bit from n.<br >
1424                 ex: 38 2 bit@ (result will be 1)<br >
1425 to32bit ( n1 n2 n3 n4 – n32 ) treat 4 last stack elements as bytes<br >
1426                 and unite them into 32 bit dword. Most significant byte<br >
1427                 on top.<br >
1428                 ex: 12 76 23 11 to32bit result: 186076172<br >
1430 to8bit ( n32 – n1 n2 n3 n4 ) break 32 bit number into 4 bytes.<br >
1431                 Useful if you need to send 32 bit numbers thru 8 bit COM<br >
1432                 port.<br >
1433                 ex: 186076172 to8bit result: 12 76 23 11<br >
1435 mod ( n1 n2 – reminder ) divide n1 by n2 and returns reminder.<br >
1436                 ex: 12 5 mod result: 2<br >
1438 bound ( low n high – n ) check if n is in given bounds,<br >
1439                 if not then incarease/decarease it to match bounds.<br >
1440                 ex: 5 80 15 bound result: 15<br >
1441                     5 10 15 bound result: 10<br >
1442                     5 -10 15 bound result: 5<br >
1444 bound? ( low n high – result ) returns true if n is in the<br >
1445                 given bounds.<br >
1447 tab ( col – spaces) calculate amount of spaces to add<br >
1448                 ta reach next tabulation from given column.<br >
1450 count ( addr – addr+1 n )<br >
1451                 Useful for returning bytes from constantly incareasing<br >
1452                 address. Module "type" is nice example.<br >
1454 c, ( n – )<br >
1455                 store one byte at memory specified by "h". And incarease<br >
1456                 "h" by 1.<br >
1458 , ( n – )<br >
1459                 store 32 bit number at memory specified by "h". And<br >
1460                 incarease "h" by 4.<br >
1462 cmove ( addr1 addr2 n – )<br >
1463                 copy "n" amount of bytes from memory at "addr1" to memory<br >
1464                 at "addr2".<br >
1466 rnd ( limit – result )<br >
1467                 generates random number in range 0 to "limit"-1.<br >
1469 abs ( n – |n| )<br >
1470                 returns absolute value of "n"<br >
1474 <div id="outline-container-sec-12-7" class="outline-3">
1475 <h3 id="sec-12-7"><span class="section-number-3">12.7</span> Dynamic & static strings</h3>
1476 <div class="outline-text-3" id="text-12-7">
1478 Fifth supports both static and dynamic strings. Static strings must
1479 have predefined space reserved, and string mustn't exceed this
1480 length. They manipulation is faster. But they use more memory. Static
1481 string memory address is used to refer to the string.
1485 Dynamic strings can have at any time length form 0 to 0FFh, They take
1486 up only memory they currently need. They are held in dynamic memory
1487 blocks, so dynamic block handle is used to refer to this string.
1491 Both types of strings are stored in the way, where first (0th) byte
1492 holds current string length, following bytes are string itself.
1499 Dstral ( – handle )<br >
1500                 Allocate new string.<br >
1502 Dstrlen ( handle – length )<br >
1503                 Return string length.<br >
1505 c+Dstr ( chr handle – )<br >
1506                 Add one byte to end of the string.<br >
1508 c+lDstr ( chr handle – )<br >
1509                 Add one byte to left side (beginning) of the string.<br >
1511 Dstr. ( handle – )<br >
1512                 Write contec of string into screen.<br >
1514 Dstrsure ( size Dstr – )<br >
1515                 Makes sure that at least rquested<br >
1516                 "size" (amount of characters) is allocated for given<br >
1517                 dynamic string.<br >
1519 Dstr2str ( handle address – )<br >
1520                 Copy dyamic string into static memory space.<br >
1522 str2Dstr ( address handle – )<br >
1523                 Copy static string into dyamic string.<br >
1525 Dstr+str ( Dstr addr – )<br >
1526                 Add contenc of dynamic string to static string.<br >
1528 D" any string" ( – Dstr )<br >
1529                 Moves specified string into dynamic string called "defDstr".<br >
1531 D> any_string ( – Dstr )<br >
1532                 Moves specified string into dynamic string called "defDstr".<br >
1533                 Space marks end of string!<br >
1535 D>2 any_string ( – Dstr )<br >
1536                 Moves specified string into dynamic string called "defDstr2".<br >
1537                 Space marks end of string!<br >
1539 Dstr+Dstr ( Dstr1 Dstr2 – )<br >
1540                 Adds "Dstr1" to "Dstr2" and places result into "Dstr2".<br >
1542 Dstrclear ( Dstr – )<br >
1543                 Clears contenc of dynamic string.<br >
1545 Dstr2Dstr ( Dstr1 Dstr2 – )<br >
1546                 Moves "Dstr1" to "Dstr2".<br >
1547 Dstr ( data" name – )<br >
1548                 Creates new dynamic string and moves specified data into it.<br >
1549                 Then creates new constant with given "name" holding created<br >
1550                 dynamic string handle.<br >
1552                 ex: Dstr Hello, my name is Sven!" message \ creates it<br >
1553                     message Dstr. \ tests it<br >
1555 Dstrlscan ( char Dstr – loc )<br >
1556                 Searches dynamic string for "char", from left to right,<br >
1557                 returns first found "char" location in string, or 0,<br >
1558                 if not found.<br >
1560 Dstrrscan ( char Dstr – loc )<br >
1561                 Searches dynamic string for "char", from right to left,<br >
1562                 returns first found "char" location in string, or 0,<br >
1563                 if not found.<br >
1565 Dstrlscane ( char Dstr – loc )<br >
1566                 Same as "Dstrlscan" buf returns string length+1 as location.<br >
1568 Dstrleft ( amo Dstr – )<br >
1569                 Only specified amount of characters from left remains<br >
1570                 in dynamic string. ie. cut right part out.<br >
1572 Dstrright ( amo Dstr – )<br >
1573                 Only specified amount of characters from right remains<br >
1574                 in dynamic string. ie. cut left part out.<br >
1576 Dstrcutl ( amo Dstr – )<br >
1577                 Cut specified amount of characters from left of dynamic<br >
1578                 string out.<br >
1580 Dstrsp ( char Dstr1 Dstr2 – )<br >
1581                 Separate dynamic string in Dstr1 into two parts,<br >
1582                 using "char" as separator. First part will be stored in<br >
1583                 "Dstr2", second part in "Dstr1".<br >
1584                 ex: asc \ \ ..separator<br >
1585                     D> listF\listLIB\5TH_DRVMOUSE \ ..separate from<br >
1586                     defDstr2 \ ..place result in<br >
1587                     Dstrsp \ separation command<br >
1588                     defDstr Dstr. \ will be: listLIB\5TH_DRVMOUSE<br >
1589                     defDstr2 Dstr. \ will be: listF<br >
1591 Dv ( addr – )<br >
1592                 Allocates empty dynamic string, and places it's handle<br >
1593                 into given address.<br >
1595 Df ( addr – )<br >
1596                 Reads dynamic string handle from given address and<br >
1597                 deallocates (frees) it.<br >
1599 ex: var mystring1<br >
1600         : testmodule<br >
1601         mystring1 Dv \ allocates string<br >
1603                 <whatever><br >
1605         mystring1 Df ; \ deallocates it again when no longer needed.<br >
1610 <div id="outline-container-sec-13" class="outline-2">
1611 <h2 id="sec-13"><span class="section-number-2">13</span> Dynamically loadable modules</h2>
1612 <div class="outline-text-2" id="text-13">
1613 </div><div id="outline-container-sec-13-1" class="outline-3">
1614 <h3 id="sec-13-1"><span class="section-number-3">13.1</span> Keyboard driver</h3>
1615 <div class="outline-text-3" id="text-13-1">
1618 KBD_@ ( – code ) get scancodes for pressed keys from keyboard.<br >
1619 KBD_down? ( key – result ) check is key with specified scancode<br >
1620                 currently pressed down.<br >
1621 KBD_SC2FSCII ( code – FSCII ) convert key scancode into FSCII code,<br >
1622                 or in FSK (Fifth standard keycode).<br >
1623 KBD_F@ ( – FSCII ) read pressed key FSCII or FSK, returns -1 if no<br >
1624                 keys are pressed.<br >
1625 KBD_FW@ ( – FSCII ) read pressed key FSCII or FSK, if no keys is<br >
1626                 are pressed then waits until there is.<br >
1628                 FSK<br >
1629                 —<br >
1638 401 … F1 …<br >
1652 <div id="outline-container-sec-13-2" class="outline-3">
1653 <h3 id="sec-13-2"><span class="section-number-3">13.2</span> Mouse driver</h3>
1654 <div class="outline-text-3" id="text-13-2">
1656 mousex var Mouse x coordinate.<br >
1657 mousey var Mouse y coordinate.<br >
1658 mousekeyl var Mouse left key.<br >
1659 mousekeym var Mouse middle key.<br >
1660 mousekeyr var Mouse right key.<br >
1661 mousec var Display current mouse coordinates in top left part of screen,<br >
1662                 if true. (good for debugging)<br >
1663 mousepointer var Image buffer, holding current mouse pointer.<br >
1664 mouseadd ( ModuleAddr x1 x2 y1 y2 – ) Add specified area on screen,<br >
1665                 into mause click buffer. If any mouse button is clicked on<br >
1666                 that area, module at "ModuleAddr" will be executed.<br >
1667 mousebe var Amount of buffer elements.<br >
1668 mousedo ( – ) Updates mouse coordinates and keys. Parse mouse<br >
1669                 click buffer, and draw mouse cursor to "screen".<br >
1673 <div id="outline-container-sec-13-3" class="outline-3">
1674 <h3 id="sec-13-3"><span class="section-number-3">13.3</span> 2D graphic library</h3>
1675 <div class="outline-text-3" id="text-13-3">
1677 lineh ( color len x y imgbuf – ) draws horisontal line<br >
1678                 from X,Y coordinates to right, with specified length.<br >
1679 linev ( color len x y imgbuf – ) draws vertical line<br >
1680                 down, from coordinates X,Y, with specified length.<br >
1681 box ( color x2 x1 y2 y1 imgbuf – ) draws rectangular<br >
1682                 box. x2 bust be >= x1, y2 must be >= y1.<br >
1683                         x1,y1–———+<br >
1684                           | |<br >
1685                           | |<br >
1686                           +–———x2,y2<br >
1688 flipv ( imgbuf – ) flip image vertically.<br >
1689 imgcoltrans ( ImgBuf Color ToColor – ) Translate all pixels in<br >
1690                 specified image with "Color" into "ToColor".<br >
1691 imgfill ( color x y imgbuf – ) Fill image region starting at location<br >
1692                 X & Y with specified color.<br >
1696 <div id="outline-container-sec-13-4" class="outline-3">
1697 <h3 id="sec-13-4"><span class="section-number-3">13.4</span> Trigonometry functions</h3>
1698 <div class="outline-text-3" id="text-13-4">
1700 sin ( a – result ) return sinus from given angle "a",<br >
1701                 360ø is 2000. So 1000 represents 180ø angle.<br >
1702                 Result will be in range -10'000 to 10'000, instead of ñ1.<br >
1704 cos ( a – result ) return cosinus from given angle.<br >
1705                 Parameters are like in "sin" function.<br >
1710 </div><div class="col-md-3"><nav id="table-of-contents">
1711 <div id="text-table-of-contents" class="bs-docs-sidebar">
1713 <li><a href="#sec-1">1. General</a>
1715 <li><a href="#sec-1-1">1.1. Source code</a></li>
1718 <li><a href="#sec-2">2. Warning</a></li>
1719 <li><a href="#sec-3">3. Introduction</a>
1721 <li><a href="#sec-3-1">3.1. screenshots</a></li>
1724 <li><a href="#sec-4">4. Installation</a></li>
1725 <li><a href="#sec-5">5. Fifth distribution directory tree description</a></li>
1726 <li><a href="#sec-6">6. Software/Hardware/Human requirements</a>
1728 <li><a href="#sec-6-1">6.1. Software</a></li>
1729 <li><a href="#sec-6-2">6.2. Hardware</a></li>
1730 <li><a href="#sec-6-3">6.3. Human</a></li>
1733 <li><a href="#sec-7">7. Numbers representation within Fifth</a></li>
1734 <li><a href="#sec-8">8. Disk file map, and it's data structures</a>
1736 <li><a href="#sec-8-1">8.1. disk allocation</a></li>
1737 <li><a href="#sec-8-2">8.2. FAT entry format:</a></li>
1738 <li><a href="#sec-8-3">8.3. file entry format</a></li>
1741 <li><a href="#sec-9">9. Core architecture</a>
1743 <li><a href="#sec-9-1">9.1. Dictionary entry format</a></li>
1744 <li><a href="#sec-9-2">9.2. Possible module types</a></li>
1745 <li><a href="#sec-9-3">9.3. Memory map (average)</a></li>
1748 <li><a href="#sec-10">10. Virtual machine</a></li>
1749 <li><a href="#sec-11">11. Fifth source format</a>
1751 <li><a href="#sec-11-1">11.1. FSCII</a></li>
1754 <li><a href="#sec-12">12. Fifth commands</a>
1756 <li><a href="#sec-12-1">12.1. Compilation & miscellaneous</a></li>
1757 <li><a href="#sec-12-2">12.2. Conditionals & control flow</a></li>
1758 <li><a href="#sec-12-3">12.3. Disk & file access</a></li>
1759 <li><a href="#sec-12-4">12.4. Dynamic memory</a></li>
1760 <li><a href="#sec-12-5">12.5. Graphics and text</a></li>
1761 <li><a href="#sec-12-6">12.6. Math, memory & stack manipulation</a></li>
1762 <li><a href="#sec-12-7">12.7. Dynamic & static strings</a></li>
1765 <li><a href="#sec-13">13. Dynamically loadable modules</a>
1767 <li><a href="#sec-13-1">13.1. Keyboard driver</a></li>
1768 <li><a href="#sec-13-2">13.2. Mouse driver</a></li>
1769 <li><a href="#sec-13-3">13.3. 2D graphic library</a></li>
1770 <li><a href="#sec-13-4">13.4. Trigonometry functions</a></li>
1777 <footer id="postamble" class="">
1778 <div><p class="author">Author: Svjatoslav Agejenko</p>
1779 <p class="date">Created: 2018-07-01 Sun 23:59</p>
1780 <p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.1.1 (<a href="http://orgmode.org">Org-mode</a> 8.2.10)</p>