1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
6 <!-- 2022-04-17 Sun 18:14 -->
7 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
8 <meta name="viewport" content="width=device-width, initial-scale=1" />
9 <title>Fifth - virtual machine, operating system, programming language</title>
10 <meta name="generator" content="Org mode" />
11 <meta name="author" content="Svjatoslav Agejenko" />
12 <style type="text/css">
13 <!--/*--><![CDATA[/*><!--*/
14 .title { text-align: center;
15 margin-bottom: .2em; }
16 .subtitle { text-align: center;
20 .todo { font-family: monospace; color: red; }
21 .done { font-family: monospace; color: green; }
22 .priority { font-family: monospace; color: orange; }
23 .tag { background-color: #eee; font-family: monospace;
24 padding: 2px; font-size: 80%; font-weight: normal; }
25 .timestamp { color: #bebebe; }
26 .timestamp-kwd { color: #5f9ea0; }
27 .org-right { margin-left: auto; margin-right: 0px; text-align: right; }
28 .org-left { margin-left: 0px; margin-right: auto; text-align: left; }
29 .org-center { margin-left: auto; margin-right: auto; text-align: center; }
30 .underline { text-decoration: underline; }
31 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
32 p.verse { margin-left: 3%; }
34 border: 1px solid #ccc;
35 box-shadow: 3px 3px 3px #eee;
37 font-family: monospace;
49 background-color: white;
53 border: 1px solid black;
55 pre.src:hover:before { display: inline;}
56 /* Languages per Org manual */
57 pre.src-asymptote:before { content: 'Asymptote'; }
58 pre.src-awk:before { content: 'Awk'; }
59 pre.src-C:before { content: 'C'; }
60 /* pre.src-C++ doesn't work in CSS */
61 pre.src-clojure:before { content: 'Clojure'; }
62 pre.src-css:before { content: 'CSS'; }
63 pre.src-D:before { content: 'D'; }
64 pre.src-ditaa:before { content: 'ditaa'; }
65 pre.src-dot:before { content: 'Graphviz'; }
66 pre.src-calc:before { content: 'Emacs Calc'; }
67 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
68 pre.src-fortran:before { content: 'Fortran'; }
69 pre.src-gnuplot:before { content: 'gnuplot'; }
70 pre.src-haskell:before { content: 'Haskell'; }
71 pre.src-hledger:before { content: 'hledger'; }
72 pre.src-java:before { content: 'Java'; }
73 pre.src-js:before { content: 'Javascript'; }
74 pre.src-latex:before { content: 'LaTeX'; }
75 pre.src-ledger:before { content: 'Ledger'; }
76 pre.src-lisp:before { content: 'Lisp'; }
77 pre.src-lilypond:before { content: 'Lilypond'; }
78 pre.src-lua:before { content: 'Lua'; }
79 pre.src-matlab:before { content: 'MATLAB'; }
80 pre.src-mscgen:before { content: 'Mscgen'; }
81 pre.src-ocaml:before { content: 'Objective Caml'; }
82 pre.src-octave:before { content: 'Octave'; }
83 pre.src-org:before { content: 'Org mode'; }
84 pre.src-oz:before { content: 'OZ'; }
85 pre.src-plantuml:before { content: 'Plantuml'; }
86 pre.src-processing:before { content: 'Processing.js'; }
87 pre.src-python:before { content: 'Python'; }
88 pre.src-R:before { content: 'R'; }
89 pre.src-ruby:before { content: 'Ruby'; }
90 pre.src-sass:before { content: 'Sass'; }
91 pre.src-scheme:before { content: 'Scheme'; }
92 pre.src-screen:before { content: 'Gnu Screen'; }
93 pre.src-sed:before { content: 'Sed'; }
94 pre.src-sh:before { content: 'shell'; }
95 pre.src-sql:before { content: 'SQL'; }
96 pre.src-sqlite:before { content: 'SQLite'; }
97 /* additional languages in org.el's org-babel-load-languages alist */
98 pre.src-forth:before { content: 'Forth'; }
99 pre.src-io:before { content: 'IO'; }
100 pre.src-J:before { content: 'J'; }
101 pre.src-makefile:before { content: 'Makefile'; }
102 pre.src-maxima:before { content: 'Maxima'; }
103 pre.src-perl:before { content: 'Perl'; }
104 pre.src-picolisp:before { content: 'Pico Lisp'; }
105 pre.src-scala:before { content: 'Scala'; }
106 pre.src-shell:before { content: 'Shell Script'; }
107 pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
108 /* additional language identifiers per "defun org-babel-execute"
110 pre.src-cpp:before { content: 'C++'; }
111 pre.src-abc:before { content: 'ABC'; }
112 pre.src-coq:before { content: 'Coq'; }
113 pre.src-groovy:before { content: 'Groovy'; }
114 /* additional language identifiers from org-babel-shell-names in
115 ob-shell.el: ob-shell is the only babel language using a lambda to put
116 the execution function name together. */
117 pre.src-bash:before { content: 'bash'; }
118 pre.src-csh:before { content: 'csh'; }
119 pre.src-ash:before { content: 'ash'; }
120 pre.src-dash:before { content: 'dash'; }
121 pre.src-ksh:before { content: 'ksh'; }
122 pre.src-mksh:before { content: 'mksh'; }
123 pre.src-posh:before { content: 'posh'; }
124 /* Additional Emacs modes also supported by the LaTeX listings package */
125 pre.src-ada:before { content: 'Ada'; }
126 pre.src-asm:before { content: 'Assembler'; }
127 pre.src-caml:before { content: 'Caml'; }
128 pre.src-delphi:before { content: 'Delphi'; }
129 pre.src-html:before { content: 'HTML'; }
130 pre.src-idl:before { content: 'IDL'; }
131 pre.src-mercury:before { content: 'Mercury'; }
132 pre.src-metapost:before { content: 'MetaPost'; }
133 pre.src-modula-2:before { content: 'Modula-2'; }
134 pre.src-pascal:before { content: 'Pascal'; }
135 pre.src-ps:before { content: 'PostScript'; }
136 pre.src-prolog:before { content: 'Prolog'; }
137 pre.src-simula:before { content: 'Simula'; }
138 pre.src-tcl:before { content: 'tcl'; }
139 pre.src-tex:before { content: 'TeX'; }
140 pre.src-plain-tex:before { content: 'Plain TeX'; }
141 pre.src-verilog:before { content: 'Verilog'; }
142 pre.src-vhdl:before { content: 'VHDL'; }
143 pre.src-xml:before { content: 'XML'; }
144 pre.src-nxml:before { content: 'XML'; }
145 /* add a generic configuration mode; LaTeX export needs an additional
146 (add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
147 pre.src-conf:before { content: 'Configuration File'; }
149 table { border-collapse:collapse; }
150 caption.t-above { caption-side: top; }
151 caption.t-bottom { caption-side: bottom; }
152 td, th { vertical-align:top; }
153 th.org-right { text-align: center; }
154 th.org-left { text-align: center; }
155 th.org-center { text-align: center; }
156 td.org-right { text-align: right; }
157 td.org-left { text-align: left; }
158 td.org-center { text-align: center; }
159 dt { font-weight: bold; }
160 .footpara { display: inline; }
161 .footdef { margin-bottom: 1em; }
162 .figure { padding: 1em; }
163 .figure p { text-align: center; }
164 .equation-container {
170 vertical-align: middle;
175 vertical-align: middle;
179 border: 2px solid gray;
184 { text-align: right; font-size: 70%; white-space: nowrap; }
185 textarea { overflow-x: auto; }
186 .linenr { font-size: smaller }
187 .code-highlighted { background-color: #ffff00; }
188 .org-info-js_info-navigation { border-style: none; }
189 #org-info-js_console-label
190 { font-size: 10px; font-weight: bold; white-space: nowrap; }
191 .org-info-js_search-highlight
192 { background-color: #ffff00; color: #000000; font-weight: bold; }
193 .org-svg { width: 90%; }
196 <link rel="stylesheet" type="text/css" href="https://thomasf.github.io/solarized-css/solarized-dark.min.css" />
197 <script type="text/javascript">
199 @licstart The following is the entire license notice for the
200 JavaScript code in this tag.
202 Copyright (C) 2012-2020 Free Software Foundation, Inc.
204 The JavaScript code in this tag is free software: you can
205 redistribute it and/or modify it under the terms of the GNU
206 General Public License (GNU GPL) as published by the Free Software
207 Foundation, either version 3 of the License, or (at your option)
208 any later version. The code is distributed WITHOUT ANY WARRANTY;
209 without even the implied warranty of MERCHANTABILITY or FITNESS
210 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
212 As additional permission under GNU GPL version 3 section 7, you
213 may distribute non-source (e.g., minimized or compacted) forms of
214 that code without the copy of the GNU GPL normally required by
215 section 4, provided you include this license notice and a URL
216 through which recipients can access the Corresponding Source.
219 @licend The above is the entire license notice
220 for the JavaScript code in this tag.
222 <!--/*--><![CDATA[/*><!--*/
223 function CodeHighlightOn(elem, id)
225 var target = document.getElementById(id);
227 elem.cacheClassElem = elem.className;
228 elem.cacheClassTarget = target.className;
229 target.className = "code-highlighted";
230 elem.className = "code-highlighted";
233 function CodeHighlightOff(elem, id)
235 var target = document.getElementById(id);
236 if(elem.cacheClassElem)
237 elem.className = elem.cacheClassElem;
238 if(elem.cacheClassTarget)
239 target.className = elem.cacheClassTarget;
243 <script type="text/x-mathjax-config">
245 displayAlign: "center",
246 displayIndent: "0em",
248 "HTML-CSS": { scale: 100,
249 linebreaks: { automatic: "false" },
253 linebreaks: { automatic: "false" },
255 NativeMML: {scale: 100},
256 TeX: { equationNumbers: {autoNumber: "AMS"},
257 MultLineWidth: "85%",
263 <script type="text/javascript"
264 src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
268 <h1 class="title">Fifth - virtual machine, operating system, programming language</h1>
269 <div id="table-of-contents">
270 <h2>Table of Contents</h2>
271 <div id="text-table-of-contents">
273 <li><a href="#org53aa659">1. General</a>
275 <li><a href="#org0222a82">1.1. Source code</a></li>
278 <li><a href="#org1ba4dab">2. !Project deprecated!</a></li>
279 <li><a href="#org27a9291">3. Introduction</a>
281 <li><a href="#org7b05666">3.1. screenshots</a></li>
284 <li><a href="#org5c0e3c1">4. Installation</a></li>
285 <li><a href="#org064502d">5. Fifth distribution directory tree description</a></li>
286 <li><a href="#orge5e54fa">6. Requirements</a>
288 <li><a href="#org6f95f4b">6.1. Software</a></li>
289 <li><a href="#org51eb820">6.2. Hardware</a></li>
290 <li><a href="#org5d390fa">6.3. Human</a></li>
293 <li><a href="#org05c7be5">7. Numbers representation within Fifth</a></li>
294 <li><a href="#org06c8993">8. Disk file map, and it's data structures</a>
296 <li><a href="#org84aa87e">8.1. Disk allocation</a></li>
297 <li><a href="#org524c276">8.2. FAT entry format:</a></li>
298 <li><a href="#org21c233b">8.3. File entry format</a></li>
301 <li><a href="#orga899cc5">9. Core architecture</a>
303 <li><a href="#org4df227c">9.1. Dictionary entry format</a></li>
304 <li><a href="#org3ba785a">9.2. Possible module types</a></li>
305 <li><a href="#org787b6e1">9.3. Memory map</a></li>
308 <li><a href="#org3debeac">10. Virtual machine</a>
310 <li><a href="#org85776a5">10.1. instruction set</a>
312 <li><a href="#org10947e1">10.1.1. overview table</a></li>
313 <li><a href="#org42eed2a">10.1.2. kbd@ - read scancode of pressed or released key</a></li>
314 <li><a href="#org3c170f3">10.1.3. vidput - put image1 into image2, at location x, y</a></li>
315 <li><a href="#org4c1b71f">10.1.4. cmove - copy memory array</a></li>
316 <li><a href="#org050fd93">10.1.5. tvidput - put image with transparency support</a></li>
317 <li><a href="#orgfcf732b">10.1.6. charput - draw text character</a></li>
322 <li><a href="#org3b7244d">11. Fifth source format</a>
324 <li><a href="#org3078f68">11.1. FSCII</a></li>
327 <li><a href="#org7ab9dd0">12. Fifth commands</a>
329 <li><a href="#orgc19ed00">12.1. Compilation & miscellaneous</a></li>
330 <li><a href="#org52d6182">12.2. Conditionals & control flow</a></li>
331 <li><a href="#org9a1c44e">12.3. Disk & file access</a></li>
332 <li><a href="#orgb7a0ec7">12.4. Dynamic memory</a></li>
333 <li><a href="#orgc2cfe7c">12.5. Graphics and text</a></li>
334 <li><a href="#org0644b6a">12.6. Math, memory & stack manipulation</a></li>
335 <li><a href="#org6965f88">12.7. Dynamic & static strings</a></li>
338 <li><a href="#orge322491">13. Dynamically loadable modules</a>
340 <li><a href="#orgc575c29">13.1. Keyboard driver</a></li>
341 <li><a href="#org7c5c975">13.2. Mouse driver</a></li>
342 <li><a href="#org7e9e6e4">13.3. 2D graphic library</a></li>
343 <li><a href="#org53b108e">13.4. Trigonometry functions</a>
345 <li><a href="#orga868964">13.4.1. sin ( a – result )</a></li>
346 <li><a href="#org7e217b7">13.4.2. cos ( a – result )</a></li>
355 <div id="outline-container-org53aa659" class="outline-2">
356 <h2 id="org53aa659"><span class="section-number-2">1</span> General</h2>
357 <div class="outline-text-2" id="text-1">
359 <li>This program is free software: released under Creative Commons Zero
364 <li>Svjatoslav Agejenko</li>
365 <li>Homepage: <a href="https://svjatoslav.eu">https://svjatoslav.eu</a></li>
366 <li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a></li>
369 <li><a href="https://www.svjatoslav.eu/projects/">Other software projects hosted at svjatoslav.eu</a></li>
372 <div id="outline-container-org0222a82" class="outline-3">
373 <h3 id="org0222a82"><span class="section-number-3">1.1</span> Source code</h3>
374 <div class="outline-text-3" id="text-1-1">
376 <li><a href="https://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=snapshot;h=HEAD;sf=tgz">Download latest snapshot in TAR GZ format</a></li>
378 <li><a href="https://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=summary">Browse Git repository online</a></li>
381 Clone Git repository using command:
383 <pre class="example">
384 git clone https://www2.svjatoslav.eu/git/fifth.git
391 <div id="outline-container-org1ba4dab" class="outline-2">
392 <h2 id="org1ba4dab"><span class="section-number-2">2</span> !Project deprecated!</h2>
393 <div class="outline-text-2" id="text-2">
395 Current implementation does not support object oriented
396 programming. While working on Fifth I got lots of cool new ideas that
397 require reimplementation of everything.
401 Currently I try to implement those new ideas in the project called
402 <a href="https://www3.svjatoslav.eu/projects/sixth/">Sixth</a>.
406 System is built many years ago when I was still using DOS as a primary
411 <div id="outline-container-org27a9291" class="outline-2">
412 <h2 id="org27a9291"><span class="section-number-2">3</span> Introduction</h2>
413 <div class="outline-text-2" id="text-3">
415 Fifth is programming lanquage & operating system, running on <a href="#org3debeac">virtual
416 machine</a>, with custom instruction set. It is much like Charles Chunk
417 Moore's Forth, it also uses stack architecture, and many commands are
418 similar. Basically I got familiar with concepts of Forth, and being
419 inspired created my own system.
423 <li><a href="5TH_ET.txt">Example Fifth source file - text editor</a></li>
426 <div id="outline-container-org7b05666" class="outline-3">
427 <h3 id="org7b05666"><span class="section-number-3">3.1</span> screenshots</h3>
428 <div class="outline-text-3" id="text-3-1">
431 <p><img src="screenshots/start.png" alt="start.png" />
436 Startup screen diplaying Fifth logo and full file list.
441 <p><img src="screenshots/dictionary.png" alt="dictionary.png" />
446 Sample words defined. Most of the words are commands that can be
447 executed interactively from command line or from file. When executed
448 they can be selectively compiled or interpreted.
454 <p><img src="screenshots/text editor.png" alt="text editor.png" />
459 Built in text editor.
465 <div id="outline-container-org5c0e3c1" class="outline-2">
466 <h2 id="org5c0e3c1"><span class="section-number-2">4</span> Installation</h2>
467 <div class="outline-text-2" id="text-4">
469 Just unpack all files, witout altering original directory structure,
470 somewhere in your hard disk. For example: C:\MISC\FIFTH\…. To run
471 fifth you need minimally just 2 files. emulator itself ( EMULATOR.EXE
472 or EMULATOR.COM ), and virtual disk file ( DISK.RAW ).
476 Read more about <a href="#org064502d">Fifth distribution directory tree description</a>.
481 <div id="outline-container-org064502d" class="outline-2">
482 <h2 id="org064502d"><span class="section-number-2">5</span> Fifth distribution directory tree description</h2>
483 <div class="outline-text-2" id="text-5">
485 After downloading and unpacking the ZIP file you shoud get directory
486 tree similar to this:
490 <b>DOC</b> - Fifth documentation<br />
491   <b>commands</b> - documentation on Fifth built-in commands<br />
492   <b>modules</b> - documentation on additional commands, realized as loadable modules<br />
493   <b>shots</b> - Fifth screenshots<br />
495 <b>imageFile</b> - files contained within 'disk.raw', just an extracted form.<br />
497 <b>source</b> - source files<br />
498   <b>emulator</b> - emulator source<br />
499   <b>util</b> - utilites<br />
501 <b>disk.raw</b> - Virtual disk file, has filesystem inside.<br />
502 <b>emulator.com</b> - main executable.<br />
507 <div id="outline-container-orge5e54fa" class="outline-2">
508 <h2 id="orge5e54fa"><span class="section-number-2">6</span> Requirements</h2>
509 <div class="outline-text-2" id="text-6">
511 <div id="outline-container-org6f95f4b" class="outline-3">
512 <h3 id="org6f95f4b"><span class="section-number-3">6.1</span> Software</h3>
513 <div class="outline-text-3" id="text-6-1">
515 <li>MS-DOS 6.22, with HIMEM.SYS loaded.</li>
516 <li>Mouse driver if you have a mouse.</li>
517 <li>Does work only when CPU is in real mode.</li>
518 <li>To recompile ASM sources I used FASM (Flat Assembler).</li>
519 <li>I ran QBasic utilities on QB 4.5 .</li>
520 <li>VESA support by BIOS, or external driver (UNIVBE).</li>
524 <div id="outline-container-org51eb820" class="outline-3">
525 <h3 id="org51eb820"><span class="section-number-3">6.2</span> Hardware</h3>
526 <div class="outline-text-3" id="text-6-2">
528 <li>Minimum CPU 386.</li>
529 <li>64 KB free RAM below 640KB,</li>
530 <li>2 MB of free XMS.</li>
531 <li>VESA compatible video card.</li>
535 <div id="outline-container-org5d390fa" class="outline-3">
536 <h3 id="org5d390fa"><span class="section-number-3">6.3</span> Human</h3>
537 <div class="outline-text-3" id="text-6-3">
539 <li>Beginner level Forth knowledge is recommended.</li>
540 <li>Lots of enthusiasm.</li>
545 <div id="outline-container-org05c7be5" class="outline-2">
546 <h2 id="org05c7be5"><span class="section-number-2">7</span> Numbers representation within Fifth</h2>
547 <div class="outline-text-2" id="text-7">
549 Because we are in full experimentation mode here (no regard for
550 compatibility whatsoever), why not to try also alternative number
555 Here alternative hexadecimal number representation format is devised:
560 <p><a href="numbers.png"><img src="numbers.png" alt="numbers.png" /></a>
565 Essentially square is split into 4 triangles. Each triangle represents
570 Fifth uses this hexadecimal format as primary throughout entire
575 See also: <a href="https://en.wikipedia.org/wiki/Bibi-binary">Bibi-binary</a>.
580 <div id="outline-container-org06c8993" class="outline-2">
581 <h2 id="org06c8993"><span class="section-number-2">8</span> Disk file map, and it's data structures</h2>
582 <div class="outline-text-2" id="text-8">
584 Core and high-level boot code is stored outside of the filesystem to
585 allow easy access to it, at early booting time, when filesystem is not
589 <div id="outline-container-org84aa87e" class="outline-3">
590 <h3 id="org84aa87e"><span class="section-number-3">8.1</span> Disk allocation</h3>
591 <div class="outline-text-3" id="text-8-1">
592 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
596 <col class="org-left" />
598 <col class="org-left" />
600 <col class="org-left" />
604 <th scope="col" class="org-left">offset</th>
605 <th scope="col" class="org-left">length</th>
606 <th scope="col" class="org-left">description</th>
611 <td class="org-left">0</td>
612 <td class="org-left">~4 Kb</td>
613 <td class="org-left">Fifth core</td>
617 <td class="org-left">4 Kb</td>
618 <td class="org-left">~32 Kb</td>
619 <td class="org-left">high-level boot code</td>
623 <td class="org-left">37 Kb</td>
624 <td class="org-left">~65 Kb</td>
625 <td class="org-left">FAT</td>
629 <td class="org-left">101 Kb</td>
630 <td class="org-left">~16 MB</td>
631 <td class="org-left">filesystem data area</td>
637 <div id="outline-container-org524c276" class="outline-3">
638 <h3 id="org524c276"><span class="section-number-3">8.2</span> FAT entry format:</h3>
639 <div class="outline-text-3" id="text-8-2">
640 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
644 <col class="org-right" />
646 <col class="org-left" />
650 <th scope="col" class="org-right">code</th>
651 <th scope="col" class="org-left">meaning</th>
656 <td class="org-right">-2</td>
657 <td class="org-left">last sector</td>
661 <td class="org-right">-1</td>
662 <td class="org-left">empty sector</td>
666 <td class="org-right">0 --</td>
667 <td class="org-left">.. pointer to next block</td>
673 <div id="outline-container-org21c233b" class="outline-3">
674 <h3 id="org21c233b"><span class="section-number-3">8.3</span> File entry format</h3>
675 <div class="outline-text-3" id="text-8-3">
676 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
680 <col class="org-right" />
682 <col class="org-right" />
684 <col class="org-left" />
688 <th scope="col" class="org-right">offset</th>
689 <th scope="col" class="org-right">length</th>
690 <th scope="col" class="org-left">description</th>
695 <td class="org-right">0</td>
696 <td class="org-right">4</td>
697 <td class="org-left">extension</td>
701 <td class="org-right">4</td>
702 <td class="org-right">16</td>
703 <td class="org-left">name</td>
707 <td class="org-right">20</td>
708 <td class="org-right">4</td>
709 <td class="org-left">entry point</td>
713 <td class="org-right">24</td>
714 <td class="org-right">4</td>
715 <td class="org-left">size</td>
719 <td class="org-right">28</td>
720 <td class="org-right">4</td>
721 <td class="org-left">last modification time</td>
728 <div id="outline-container-orga899cc5" class="outline-2">
729 <h2 id="orga899cc5"><span class="section-number-2">9</span> Core architecture</h2>
730 <div class="outline-text-2" id="text-9">
732 Fifth core is simply some amount of already compiled into machine code
733 and linked together modules (entries in other words). In compilation
734 process modules is compiled one by one and simply stored on top of
735 already existing and growing core. Separately from core is kept
736 dictionary, this is special list that contain names of compiled
737 modules, variables etc. and they locations in core. Constants use
738 dictionary space only. Random word can be removed from dictionary at
739 any time. Currently dictionary can contain at most 1000 entries.
742 <div id="outline-container-org4df227c" class="outline-3">
743 <h3 id="org4df227c"><span class="section-number-3">9.1</span> Dictionary entry format</h3>
744 <div class="outline-text-3" id="text-9-1">
745 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
749 <col class="org-right" />
751 <col class="org-right" />
753 <col class="org-left" />
757 <th scope="col" class="org-right">offset</th>
758 <th scope="col" class="org-right">length</th>
759 <th scope="col" class="org-left">description</th>
764 <td class="org-right">0</td>
765 <td class="org-right">4</td>
766 <td class="org-left">0 &lt; previous entry</td>
770 <td class="org-right"> </td>
771 <td class="org-right"> </td>
772 <td class="org-left">0 = last</td>
776 <td class="org-right"> </td>
777 <td class="org-right"> </td>
778 <td class="org-left">-1 = empty</td>
783 <td class="org-right">4</td>
784 <td class="org-right">15</td>
785 <td class="org-left">module name string</td>
790 <td class="org-right">19</td>
791 <td class="org-right">1</td>
792 <td class="org-left">entry type</td>
797 <td class="org-right">20</td>
798 <td class="org-right">4</td>
799 <td class="org-left">entry data</td>
805 Core headers as linked list of module names make up something like
806 dictionary. When some entry address is needed compiler can quickly
807 run through headers backwards and find needed entry.
811 <div id="outline-container-org3ba785a" class="outline-3">
812 <h3 id="org3ba785a"><span class="section-number-3">9.2</span> Possible module types</h3>
813 <div class="outline-text-3" id="text-9-2">
814 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
818 <col class="org-right" />
820 <col class="org-left" />
822 <col class="org-left" />
826 <th scope="col" class="org-right">type</th>
827 <th scope="col" class="org-left">description</th>
828 <th scope="col" class="org-left">"execute" action</th>
833 <td class="org-right">0</td>
834 <td class="org-left">data</td>
835 <td class="org-left">compile "num" instruction</td>
839 <td class="org-right"> </td>
840 <td class="org-left"> </td>
841 <td class="org-left">with address to module</td>
846 <td class="org-right">1</td>
847 <td class="org-left">submodule</td>
848 <td class="org-left">compile "call" instruction</td>
852 <td class="org-right"> </td>
853 <td class="org-left"> </td>
854 <td class="org-left">with address to module</td>
859 <td class="org-right">2</td>
860 <td class="org-left">imm. submodule</td>
861 <td class="org-left">immediately call to module</td>
867 <div id="outline-container-org787b6e1" class="outline-3">
868 <h3 id="org787b6e1"><span class="section-number-3">9.3</span> Memory map</h3>
869 <div class="outline-text-3" id="text-9-3">
870 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
874 <col class="org-right" />
876 <col class="org-left" />
878 <col class="org-left" />
882 <th scope="col" class="org-right">location</th>
883 <th scope="col" class="org-left">size</th>
884 <th scope="col" class="org-left">description</th>
889 <td class="org-right">0</td>
890 <td class="org-left">~4096</td>
891 <td class="org-left">core</td>
895 <td class="org-right">1500000</td>
896 <td class="org-left">~32000</td>
897 <td class="org-left">highlevel Fifth boot code</td>
901 <td class="org-right">200000h</td>
902 <td class="org-left"> </td>
903 <td class="org-left">core startup messages area</td>
907 <td class="org-right">5200000</td>
908 <td class="org-left"> </td>
909 <td class="org-left">end of dynamic memory space</td>
916 <div id="outline-container-org3debeac" class="outline-2">
917 <h2 id="org3debeac"><span class="section-number-2">10</span> Virtual machine</h2>
918 <div class="outline-text-2" id="text-10">
920 Using CPU emulator slows it down but I shouldn't now think too mutch
921 about, and waste my time on batteling with problems whitch results on
922 complex design of PC hardware. Also it allows me to use existing DOS
923 and resident drivers services in real mode. So I don't need to deal
924 with hardware too mutch. It also allows me to use all free XMS for
925 flat code & data storage.
929 Current emulator emulates 1 CPU. It has 2 stacks, ~50 instructions,
930 and 4GB flat address space (theoretically). I'm not sure that DOS
931 6.22 that I currently prefer can handle more than 64 MB of RAM. While
932 I tried to keep instructionset simple, I was forced to put in lot of
933 complex instructions to make it's performance acceptable on
934 emulator. On actual silicon ~20 instructions is enaugh (I think).
938 Maybe one day similar system will run directly on custom silicon chip :)
943 CPU has following registers:
945 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
949 <col class="org-left" />
951 <col class="org-left" />
955 <td class="org-left">IP</td>
956 <td class="org-left">instruction pointer</td>
960 <td class="org-left">DSP</td>
961 <td class="org-left">data stack pointer</td>
965 <td class="org-left">RSP</td>
966 <td class="org-left">return stack pointer</td>
971 <div id="outline-container-org85776a5" class="outline-3">
972 <h3 id="org85776a5"><span class="section-number-3">10.1</span> instruction set</h3>
973 <div class="outline-text-3" id="text-10-1">
975 <div id="outline-container-org10947e1" class="outline-4">
976 <h4 id="org10947e1"><span class="section-number-4">10.1.1</span> overview table</h4>
977 <div class="outline-text-4" id="text-10-1-1">
979 Virtual CPU, commands (most of them are avaiable as ordinary commands
980 in programming language):
984 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
988 <col class="org-right" />
990 <col class="org-left" />
992 <col class="org-left" />
994 <col class="org-left" />
998 <th scope="col" class="org-right">#</th>
999 <th scope="col" class="org-left">name</th>
1000 <th scope="col" class="org-left">stack footprint</th>
1001 <th scope="col" class="org-left">description</th>
1006 <td class="org-right">0</td>
1007 <td class="org-left">nop</td>
1008 <td class="org-left">--</td>
1009 <td class="org-left">does nothing</td>
1013 <td class="org-right">1</td>
1014 <td class="org-left">halt</td>
1015 <td class="org-left">--</td>
1016 <td class="org-left">halt CPU ( return to DOS on emulator )</td>
1020 <td class="org-right">2</td>
1021 <td class="org-left"><a href="#org42eed2a">kbd@</a></td>
1022 <td class="org-left">– c</td>
1023 <td class="org-left">read scancode of pressed or released key</td>
1027 <td class="org-right">3</td>
1028 <td class="org-left">num <dword></td>
1029 <td class="org-left">– n</td>
1030 <td class="org-left">put immidiate number into datastack</td>
1034 <td class="org-right">4</td>
1035 <td class="org-left">jmp <dword></td>
1036 <td class="org-left">--</td>
1037 <td class="org-left">jump to specified code</td>
1041 <td class="org-right">5</td>
1042 <td class="org-left">call <dword></td>
1043 <td class="org-left"> </td>
1044 <td class="org-left">jump to specified code, save return address to return stack</td>
1048 <td class="org-right">6</td>
1049 <td class="org-left">1+</td>
1050 <td class="org-left">n – n+1</td>
1051 <td class="org-left"> </td>
1055 <td class="org-right">7</td>
1056 <td class="org-left">1-</td>
1057 <td class="org-left">n – n-1</td>
1058 <td class="org-left"> </td>
1062 <td class="org-right">8</td>
1063 <td class="org-left">dup</td>
1064 <td class="org-left">n – n n</td>
1065 <td class="org-left">duplicate top of data stack</td>
1069 <td class="org-right">9</td>
1070 <td class="org-left">drop</td>
1071 <td class="org-left">n --</td>
1072 <td class="org-left">drop last element in data stack</td>
1076 <td class="org-right">10</td>
1077 <td class="org-left">if <dword></td>
1078 <td class="org-left">n --</td>
1079 <td class="org-left">jump to addr if top element was 0</td>
1083 <td class="org-right">11</td>
1084 <td class="org-left">ret</td>
1085 <td class="org-left"> </td>
1086 <td class="org-left">jump to code, specified in return stack.</td>
1090 <td class="org-right">12</td>
1091 <td class="org-left">c@</td>
1092 <td class="org-left">addr – n</td>
1093 <td class="org-left">read byte from memory at specified address</td>
1097 <td class="org-right">13</td>
1098 <td class="org-left">c!</td>
1099 <td class="org-left">n addr --</td>
1100 <td class="org-left">store byte to specified memory</td>
1104 <td class="org-right">14</td>
1105 <td class="org-left">push</td>
1106 <td class="org-left">DSTK -> RSTK</td>
1107 <td class="org-left">move top of datastack to returnstack</td>
1111 <td class="org-right">15</td>
1112 <td class="org-left">pop</td>
1113 <td class="org-left">RSTK -> DSTK</td>
1114 <td class="org-left">move top of returnstack to datastack</td>
1118 <td class="org-right">16</td>
1119 <td class="org-left"><unused></td>
1120 <td class="org-left"> </td>
1121 <td class="org-left"> </td>
1125 <td class="org-right">17</td>
1126 <td class="org-left">rot</td>
1127 <td class="org-left">n1 n2 n3 – n2 n3 n1</td>
1128 <td class="org-left">rotate stack elements</td>
1132 <td class="org-right">18</td>
1133 <td class="org-left">disk@</td>
1134 <td class="org-left">FromDiskSect ToMem --</td>
1135 <td class="org-left">read 1KB from disk into RAM</td>
1139 <td class="org-right">19</td>
1140 <td class="org-left">disk!</td>
1141 <td class="org-left">FromMem ToDiskSect --</td>
1142 <td class="org-left">write 1KB to disk</td>
1146 <td class="org-right">20</td>
1147 <td class="org-left">@</td>
1148 <td class="org-left">addr – n</td>
1149 <td class="org-left">read 32 bit number from memory</td>
1153 <td class="org-right">21</td>
1154 <td class="org-left">!</td>
1155 <td class="org-left">n addr --</td>
1156 <td class="org-left">store 32 bit number to memory</td>
1160 <td class="org-right">22</td>
1161 <td class="org-left">over</td>
1162 <td class="org-left">n1 n2 – n1 n2 n1</td>
1163 <td class="org-left"> </td>
1167 <td class="org-right">23</td>
1168 <td class="org-left">swap</td>
1169 <td class="org-left">n1 n2 – n2 n1</td>
1170 <td class="org-left"> </td>
1174 <td class="org-right">24</td>
1175 <td class="org-left">+</td>
1176 <td class="org-left">n1 n2 – n1+n2</td>
1177 <td class="org-left"> </td>
1181 <td class="org-right">25</td>
1182 <td class="org-left">-</td>
1183 <td class="org-left">n1 n2 – n1-n2</td>
1184 <td class="org-left"> </td>
1188 <td class="org-right">26</td>
1189 <td class="org-left">*</td>
1190 <td class="org-left">n1 n2 – n1*n2</td>
1191 <td class="org-left"> </td>
1195 <td class="org-right">27</td>
1196 <td class="org-left">/</td>
1197 <td class="org-left">n1 n2 – n1/n2</td>
1198 <td class="org-left"> </td>
1202 <td class="org-right">28</td>
1203 <td class="org-left">></td>
1204 <td class="org-left">n1 n2 – result</td>
1205 <td class="org-left">is true when n1 > n2</td>
1209 <td class="org-right">29</td>
1210 <td class="org-left"><</td>
1211 <td class="org-left">n1 n2 – result</td>
1212 <td class="org-left">is true when n1 < n2</td>
1216 <td class="org-right">30</td>
1217 <td class="org-left">not</td>
1218 <td class="org-left">n1 – not_n1</td>
1219 <td class="org-left">logical not</td>
1223 <td class="org-right">31</td>
1224 <td class="org-left">i</td>
1225 <td class="org-left">– n</td>
1226 <td class="org-left">copies top of return stack into datastack</td>
1230 <td class="org-right">32</td>
1231 <td class="org-left">cprt@</td>
1232 <td class="org-left">addr – n</td>
1233 <td class="org-left">read one byte from hardware port</td>
1237 <td class="org-right">33</td>
1238 <td class="org-left">cprt!</td>
1239 <td class="org-left">n addr --</td>
1240 <td class="org-left">store one byte to hardware port</td>
1244 <td class="org-right">34</td>
1245 <td class="org-left">i2</td>
1246 <td class="org-left">– n</td>
1247 <td class="org-left">like "i" but takes second top stack element</td>
1251 <td class="org-right">35</td>
1252 <td class="org-left">i3</td>
1253 <td class="org-left">– n</td>
1254 <td class="org-left">like "i" but takes third top stack element.</td>
1258 <td class="org-right">36</td>
1259 <td class="org-left">shl</td>
1260 <td class="org-left">n amount – n</td>
1261 <td class="org-left">left bit shift</td>
1265 <td class="org-right">37</td>
1266 <td class="org-left">shr</td>
1267 <td class="org-left">n amount – n</td>
1268 <td class="org-left">right bit shift</td>
1272 <td class="org-right">38</td>
1273 <td class="org-left">or</td>
1274 <td class="org-left">n1 n2 – n</td>
1275 <td class="org-left">logical or</td>
1279 <td class="org-right">39</td>
1280 <td class="org-left">xor</td>
1281 <td class="org-left">n1 n2 – n</td>
1282 <td class="org-left">exclusive logical or</td>
1286 <td class="org-right">40</td>
1287 <td class="org-left">vidmap</td>
1288 <td class="org-left">addr --</td>
1289 <td class="org-left">copy memory from "addr" to video memory.</td>
1293 <td class="org-right">41</td>
1294 <td class="org-left">mouse@</td>
1295 <td class="org-left">– x y button</td>
1296 <td class="org-left">read mouse coordinates & buttons</td>
1300 <td class="org-right">42</td>
1301 <td class="org-left"><a href="#org3c170f3">vidput</a></td>
1302 <td class="org-left">addr1 addr2 x y --</td>
1303 <td class="org-left">put image1 into image2, at location x, y</td>
1307 <td class="org-right">43</td>
1308 <td class="org-left"><a href="#org4c1b71f">cmove</a></td>
1309 <td class="org-left">addr1 addr2 amount</td>
1310 <td class="org-left">move memory from addr1 to addr2</td>
1314 <td class="org-right">44</td>
1315 <td class="org-left">cfill</td>
1316 <td class="org-left">c addr amount --</td>
1317 <td class="org-left">fill memory starting at "addr" with "c" bytes.</td>
1321 <td class="org-right">45</td>
1322 <td class="org-left"><a href="#org050fd93">tvidput</a></td>
1323 <td class="org-left">addr1 addr2 x y --</td>
1324 <td class="org-left">put image with transparency support</td>
1328 <td class="org-right">46</td>
1329 <td class="org-left">depth</td>
1330 <td class="org-left">– depth</td>
1331 <td class="org-left">returns current depth of data stack.</td>
1335 <td class="org-right">47</td>
1336 <td class="org-left"><a href="#orgfcf732b">charput</a></td>
1337 <td class="org-left">colorfg colorbg addrsrc addrdest x y</td>
1338 <td class="org-left">draw text character</td>
1345 <div id="outline-container-org42eed2a" class="outline-4">
1346 <h4 id="org42eed2a"><span class="section-number-4">10.1.2</span> kbd@ - read scancode of pressed or released key</h4>
1347 <div class="outline-text-4" id="text-10-1-2">
1349 Returns 0 if no data available.
1353 <div id="outline-container-org3c170f3" class="outline-4">
1354 <h4 id="org3c170f3"><span class="section-number-4">10.1.3</span> vidput - put image1 into image2, at location x, y</h4>
1355 <div class="outline-text-4" id="text-10-1-3">
1357 Does clipping, so part of a big image can be mapped into smaller one.
1361 <div id="outline-container-org4c1b71f" class="outline-4">
1362 <h4 id="org4c1b71f"><span class="section-number-4">10.1.4</span> cmove - copy memory array</h4>
1363 <div class="outline-text-4" id="text-10-1-4">
1365 Move memory from addr1 to addr2. If addr1 is greater than addr2 then
1366 count address foward while moving, elseway starts from end and counts
1367 backwards, so no data loss occurs when memory regions partially
1372 <div id="outline-container-org050fd93" class="outline-4">
1373 <h4 id="org050fd93"><span class="section-number-4">10.1.5</span> tvidput - put image with transparency support</h4>
1374 <div class="outline-text-4" id="text-10-1-5">
1378 <pre class="example">
1384 Put image1 into image2, at location x, y with transparency support
1388 Color 255 in source image is treated as transparent.
1392 <div id="outline-container-orgfcf732b" class="outline-4">
1393 <h4 id="orgfcf732b"><span class="section-number-4">10.1.6</span> charput - draw text character</h4>
1394 <div class="outline-text-4" id="text-10-1-6">
1396 Draw character to image buffer located at "addrdest" to specified x &
1397 y location. Decodes 8 bytes from source to bits, used to draw
1405 <div id="outline-container-org3b7244d" class="outline-2">
1406 <h2 id="org3b7244d"><span class="section-number-2">11</span> Fifth source format</h2>
1407 <div class="outline-text-2" id="text-11">
1409 Fifth uses a different character table and codes than ASCII (still
1410 almost similar). I call it FSCII (Fifth Standard Code for Information
1411 Interchange) for example space character is not 32 but 255 instead. I
1412 plan to use mainly HEX numbers, and create new characters to represent
1413 numeric values. So typical nemric characters "0123…" is treated
1414 like ordinary letters.
1417 <div id="outline-container-org3078f68" class="outline-3">
1418 <h3 id="org3078f68"><span class="section-number-3">11.1</span> FSCII</h3>
1419 <div class="outline-text-3" id="text-11-1">
1420 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
1424 <col class="org-right" />
1426 <col class="org-left" />
1428 <col class="org-left" />
1432 <th scope="col" class="org-right">DEC</th>
1433 <th scope="col" class="org-left">HEX</th>
1434 <th scope="col" class="org-left">function</th>
1439 <td class="org-right">0 - 15</td>
1440 <td class="org-left">0 - F</td>
1441 <td class="org-left">HEX numbers</td>
1445 <td class="org-right">252</td>
1446 <td class="org-left">FC</td>
1447 <td class="org-left">backspace</td>
1451 <td class="org-right">253</td>
1452 <td class="org-left">FD</td>
1453 <td class="org-left">tabulator (TAB)</td>
1457 <td class="org-right">254</td>
1458 <td class="org-left">FE</td>
1459 <td class="org-left">carriage return (CR)</td>
1463 <td class="org-right">255</td>
1464 <td class="org-left">FF</td>
1465 <td class="org-left">space</td>
1469 <td class="org-right">else</td>
1470 <td class="org-left"> </td>
1471 <td class="org-left">ordinary characters, same as in ASCII.</td>
1478 <div id="outline-container-org7ab9dd0" class="outline-2">
1479 <h2 id="org7ab9dd0"><span class="section-number-2">12</span> Fifth commands</h2>
1480 <div class="outline-text-2" id="text-12">
1482 <div id="outline-container-orgc19ed00" class="outline-3">
1483 <h3 id="orgc19ed00"><span class="section-number-3">12.1</span> Compilation & miscellaneous</h3>
1484 <div class="outline-text-3" id="text-12-1">
1486 init module ( – )<br />
1487                 First module, control is passed to on startup. Contains<br />
1488                 initialization routines. Also it is the last core module.<br />
1489                 All new modules on top of it comes as result of executing<br />
1490                 external source files.<br />
1492 head <name> ( – ) compiles new dictionary entry without specifying<br />
1493                 new module type.<br />
1494                 ex: head myentry<br />
1496 : <name> ( – ) creates new code module<br />
1497 ; ( – ) ends module (immideate)<br />
1498                 ex: : hello ." hi there" ;<br />
1500 const <name> ( n – ) defines new constant.<br />
1501                 ex: 2147483647 const max<br />
1503 :i <name> ( – ) same as ":" but this module will be executed<br />
1504                 immideately even in compile mode.<br />
1505                 ex: :i ( 41 scan ;<br />
1507 create <name> ( – ) same as "head" , but specify module type as data.<br />
1508                 ex: create LotoResults 5 , 13 , 52 , 12 , 11 , 3 ,<br />
1510 allot ( n – ) allocate n bytes in dictionary.<br />
1511                 ex: create MyArray 100 allot<br />
1513 " <string>" ( – ) compile string and its size into core.<br />
1514                 ex: create Mystring " This is it's contects"<br />
1516 str <name> <string>" ( – ) just shorter way for defining strings.<br />
1517                 ex: str Mystring This is it's contenc"<br />
1519 var <name> ( – ) define new 32 bit variable.<br />
1520                 ex: var result<br />
1522 ' <module> ( – n ) return memory address of given entry.<br />
1523                 ex: ' init<br />
1525 forget <name> ( – ) erases from RAM given entry and all entries what was<br />
1526                 defined after it.<br />
1527                 ex: forget myprog<br />
1529 [ ( – ) set interpret mode (immideate)<br />
1530 ] ( n – ) set compile mode and compile top stack element<br />
1531                 in as literal. Together [ …. ] cobination provides good<br />
1532                 way to compute some values only once, at compile time,<br />
1533                 rather than every time while program is running.<br />
1534                 ex: : calculate - [ 4 MyConst1 + MyConst2 * ] ;<br />
1536 defer <name> ( – ) creates new module, with jump instruction.<br />
1537                 Later address where to jump can be modified by "is" command.<br />
1538                 This provides method of foward referencing. So you can use<br />
1539                 modules what not jet exist.<br />
1540 is ( address1 address2 – ) address1 - where to jump, address2 -<br />
1541                 address of module created by defer command.<br />
1542                 ex: defer dispver<br />
1543                         : run dispver ." running …" ;<br />
1544                                … whatever …<br />
1545                         : (dispver ." Version 9.99 " ;<br />
1546                         ' (dispver ' dispver is<br />
1548                 Now if I type "run" on the screen appears:<br />
1549                         Version 9.99 running …<br />
1551 asc <char> ( – ) reads char ascii code and treats it as literal.<br />
1552                 (immideate)<br />
1553                 ex: : BreakLine 30 do asc - emit loop ;<br />
1554                                  same as:<br />
1555                     : BreakLine 30 do 45 emit loop ;<br />
1557 dyninc ( handle – ) execute code in dynamic memory handle.<br />
1558                 automatically deallocates it when done.<br />
1560 include ( filenumber – ) execute code in specified file.<br />
1562 words ( – ) display existing blocks in core.<br />
1564 bye ( – ) exit from Fifth<br />
1566 fkey ( – c )<br />
1567                 Read one byte from input stream.<br />
1569 sadd ( c addr – )<br />
1570                 Add one byte "c" to string located at "addr" and updates<br />
1571                 string length.<br />
1573 scan ( c – )<br />
1574                 Read input stream and store it to pad until it finds c .<br />
1575                 It ignores all "c" bytes until it finds any non "c" byte.<br />
1576                 in other words:<br />
1577                                 c is: "<br />
1578                          input stream: """"This is test !"aoeu idh<br />
1579                                result: This is test !<br />
1581                 Is useful for breaking text lines into words.<br />
1583 skey ( – c )<br />
1584                 So called safe "fkey". Reads data from input stream<br />
1585                 but converts characters with ASCII codes: 9 13 10<br />
1586                 to spaces.<br />
1588 str=str? ( adr1 adr2 – result )<br />
1589                 Compares string at "adr1" with string at "adr2", returns<br />
1590                 true flag if they are equal or false if they are not.<br />
1591                 true = -1<br />
1592                 false = 0<br />
1594 find ( – addr )<br />
1595                 Searches whole dictionary for word in "pad". If found,<br />
1596                 returns it address, if not, returns 0.<br />
1598 execute ( – )<br />
1599                 Execute word located in "pad". Depending on "mode".<br />
1601 dta ( addr – DataAddr )<br />
1602                 Calculates address of dictionary entry data area, from<br />
1603                 entry point.<br />
1605 2num ( – num result )<br />
1606                 Attempt to convert string located in "pad" into numeric<br />
1607                 value. If succeed returns number and true as result.<br />
1608                 If not, returns whatever and false as result.<br />
1610 dadd ( addr length – )<br />
1611                 Add to dictionary data located at "addr", with specified<br />
1612                 length.<br />
1614 lit ( n – )<br />
1615                 Act with number depending on "mode". When interpreting,<br />
1616                 leaves it in stack.<br />
1619 incmod ( addr – )<br />
1620                 Add to dictionary data located at "addr"+1 , length is taken<br />
1621                 from "addr".<br />
1623 here ( – n )<br />
1624                 return "h" contents.<br />
1626 mode var 8 bit<br />
1627                 Holds input stream parser operation mode.<br />
1628                 0 = interpreting<br />
1629                 1 = compiling<br />
1631 pad var 128 bytes<br />
1632                 Holds temprorary strings.<br />
1635                 Pointer to free byte in memory, always at the end of the<br />
1636                 dictionary. Each time when something is stored<br />
1637                 by "c," command, pointer is incareased.<br />
1640                 Pointer to last dictionary word. Each time when new word is<br />
1641                 compiled or erased by "forget", this pointer is updated.<br />
1643 modulechk ( Dstr<filename> – ) check if module is loaded, if not<br />
1644                 immideately load it.<br />
1646 ne ( entrydata entrytype – ) Compile new dictionary entry.<br />
1647                 It's name must be in "pad".<br />
1651 <div id="outline-container-org52d6182" class="outline-3">
1652 <h3 id="org52d6182"><span class="section-number-3">12.2</span> Conditionals & control flow</h3>
1653 <div class="outline-text-3" id="text-12-2">
1655 if ( flag – ) (immideate)<br />
1656                 "if 1.. else 2.. then" or<br />
1657                 "if 1.. then" construction. Conditional execution.<br />
1658                 Performs "1.." if "flag" was true,<br />
1659                 elseway performs "2.." if exist. Execution continues after<br />
1660                 word "then".<br />
1661                 ex: 1 if ." nonzero" else ." zero" then<br />
1663 >= ( n1 n2 – result ) true if (n1 = n2) or (n1 > n2)<br />
1664                 ex: 5 3 >= if ." first number is greater or equal" then<br />
1666 <= ( n1 n2 – result ) true if (n1 = n2) or (n1 < n2)<br />
1667 = ( n1 n2 – result ) true if n1 = n2<br />
1669 do ( count – ) (immideate)<br />
1670                 "do .. loop" construction. Performs ".." "count" times.<br />
1671                 In every step "count" is decareased until it is 0.<br />
1672                 ex: : test 5 do i .d loop ;<br />
1673                 result: 4 3 2 1 0<br />
1675 doexit ( – ) exit from "do .. loop"<br />
1677 for ( count top – ) (immideate)<br />
1678                 "for .. loop" construction. Performs ".." (top - count) times.<br />
1679                 In every step "count" is incareased until it reaches "top" .<br />
1680                 ex: : test 4 10 for i .d loop ;<br />
1681                 result: 4 5 6 7 8 9<br />
1683 forexit ( – ) exit from "for .. loop"<br />
1685 until ( – ) (immideate)<br />
1686                 "until .. loop" construction. Performs ".." until flag become<br />
1687                 true. False by default. Top of return stack holds flag.<br />
1689 done ( – ) exit from "until .. loop"<br />
1694 <div id="outline-container-org9a1c44e" class="outline-3">
1695 <h3 id="org9a1c44e"><span class="section-number-3">12.3</span> Disk & file access</h3>
1696 <div class="outline-text-3" id="text-12-3">
1698 diskload ( FromDisk ToMem amount – )<br />
1699                 Load specified abount of bytes from disk into memory.<br />
1701 disksave ( FromMem ToDisk amount – )<br />
1702                 save specified abount of bytes from memory into disk.<br />
1704 format ( – ) Erase all files.<br />
1706 fsDfilesize@ ( handle – size )<br />
1707                 Return size of opened file.<br />
1709 fsDcurloc@ ( handle – location )<br />
1710                 Return current location in file.<br />
1712 fsDupdated@ ( handle – updated? )<br />
1713                 Return true if file was updated,<br />
1714                 ie. write operations occured.<br />
1716 fssave ( FromMem DestFileHandle amount – )<br />
1717                 Save data to file.<br />
1719 fsload ( SrcFileHandle ToMem amount – )<br />
1720                 Load data from file.<br />
1722 fseof ( handle – bytesLeft )<br />
1723                 Return amount of bytes left till end of file.<br />
1724                 Useful before read operation.<br />
1726 fsls ( – ) List all files and lists (directories,folders)<br />
1727                 in current path.<br />
1729 fslsr ( – ) Same as "fsls" but recursively scans also sub lists.<br />
1731 fscl ( DynStrHand – )<br />
1732                 Change list (path)<br />
1734 fscreate ( DynStrHand – DescPnt )<br />
1735                 Create new file or list. Can create multiple lists at once.<br />
1736                 ex: when creating:<br />
1737                     "\listGAMES\listSTRATEGY\listSIMWORLD\5th-runme"<br />
1738                 and only "\listGAMES\" already exist, then<br />
1739                 "listSTRATEGY" and "listSIMWORLD" lists will be created,<br />
1740                 and empty file "5th-runme" placed in there.<br />
1742 fsDsave ( DynHand<data> DynStrHand<filename> – )<br />
1743                 Create new file and save all data from dynamic memory<br />
1744                 block to it.<br />
1746 fsDload ( DynStr<SrcFileName> DynHand<DataDest> – )<br />
1747                 Load whole file into dynamic memory block.<br />
1749 fsDloadnew ( DynStr<SrcFileName> – DynHand<DataDest> )<br />
1750                 Load whole file into new dynamic memory block.<br />
1754 <div id="outline-container-orgb7a0ec7" class="outline-3">
1755 <h3 id="orgb7a0ec7"><span class="section-number-3">12.4</span> Dynamic memory</h3>
1756 <div class="outline-text-3" id="text-12-4">
1758 dynal ( size – handle )<br />
1759                 Allocate dynamic memory block and return it's handle.<br />
1761 dynde ( handle – )<br />
1762                 Deallocate dynamic memory block.<br />
1764 dynp ( handle – addr )<br />
1765                 Returns pointer to memory where dynamic block<br />
1766                 data begins.<br />
1768 dyns ( handle – size )<br />
1769                 Returns size of dynamic block.<br />
1771 dynresize ( NewSize handle – )<br />
1772                 Nondestructively resize dynamic block.<br />
1774 dync@ ( addr handle )<br />
1775                 Read one byte from dynamic block.<br />
1777 dync! ( byte addr dynhandle )<br />
1778                 Write one byte to dynamic block.<br />
1780 dyn@ ( addr handle )<br />
1781                 Read 32 bit number from dynamic block.<br />
1782                 Address will spacify, whitch number, not byte.<br />
1784 dyn! ( 32BitNum addr dynhandle )<br />
1785                 Write 32 bit number to dynamic block.<br />
1786                 Address will spacify, whitch number, not byte.<br />
1788 dyncon ( size "name" – )<br />
1789                 Allocate dynamic block with specified size, and<br />
1790                 create constant honding its handle.<br />
1791                 ex: 100 dyncon MyNewBlock<br />
1793 dyn. ( handle – )<br />
1794                 Write contenc of dynamic memory block to screen.<br />
1798 <div id="outline-container-orgc2cfe7c" class="outline-3">
1799 <h3 id="orgc2cfe7c"><span class="section-number-3">12.5</span> Graphics and text</h3>
1800 <div class="outline-text-3" id="text-12-5">
1802 . ( n – ) print number on screen<br />
1804 d. ( n – ) print number on screen in decimal<br />
1806 ? ( addr – ) print 32 bit value located at addr.<br />
1808 ." <string>" ( – ) print string into screen. Immideately<br />
1809                 compiles.<br />
1810                 ex: : greeting ." Hello, World" ;<br />
1812 tab. ( – ) print tabulator<br />
1814 calccol ( b g r – c ) calculate color what best matches given<br />
1815                 Blue Green & Red values. Values must be in range 0 - 255.<br />
1817 imgalloc ( xsize ysize – imgbuf ) allocate image buffer for<br />
1818                 specified size.<br />
1820 imgsize ( imgbuf – ) print on the screen X & Y size of image<br />
1821                 buffer.<br />
1823 point ( x y imgbuf – addr ) returns memory address for specified<br />
1824                 pixel.<br />
1826 pset ( color x y imgbuf – ) set graphic point<br />
1828 boxf ( x1 x2 y1 y2 imgbuf color – ) draw filled box<br />
1830 cls ( imgbuf – ) clear image buffer<br />
1832 setpal ( b g r color – ) set palette value for specified color.<br />
1833                 values bust be in size 0 - 63.<br />
1835 putchar ( char color x y imgbuf – ) put graphic character in<br />
1836                 imagebuffer to specified (x & y) location.<br />
1838 scroll ( x y imgbuf – ) scroll in imgbuf.<br />
1840 scrollf ( color x y screen – ) scroll and fill empty space with<br />
1841                 given color.<br />
1843 at! ( x y – ) set cursor location<br />
1844 curc! ( color – ) set text color<br />
1845 curb! ( solor – ) set backround color<br />
1847 colnorm ( – ) set text color to normal<br />
1848 colneg ( – ) set text color to negative (selected)<br />
1850 dyntype ( dynhandle – ) display contenc of dynamic memory on screen<br />
1851 fsdisp ( file – ) clear screen, display file, and wait for key<br />
1853 type ( addr length – )<br />
1854                 Types on the screen string, from memory at addr and<br />
1855                 specified length.<br />
1857 write ( addr – )<br />
1858                 Types on the screen string, from memory at "addr"+1<br />
1859                 length is taken from "addr" .<br />
1861 screen const 32 bit<br />
1862                 Holds handle of screen buffer.<br />
1864 copyscreen ( SrcImgHandle DestImgHandle – ) copy contenc of source<br />
1865                 image to destination image. Source and destination images<br />
1866                 must have same size.<br />
1870 <div id="outline-container-org0644b6a" class="outline-3">
1871 <h3 id="org0644b6a"><span class="section-number-3">12.6</span> Math, memory & stack manipulation</h3>
1872 <div class="outline-text-3" id="text-12-6">
1874 off ( n – ) writes 0 to given address, good for zeroing variable.<br />
1875                 ex: MyVariable off<br />
1876 on ( n – ) writes -1 (true flag) to given address.<br />
1877                 ex: MyVariable on<br />
1879 2dup ( n1 n2 – n1 n2 n1 n2 )<br />
1880 2drop ( n1 n2 – )<br />
1881 nip ( n1 n2 – n2 )<br />
1882 neg ( n1 – -n1 ) negotiate<br />
1883 bit@ ( n bit – result ) return specified bit from n.<br />
1884                 ex: 38 2 bit@ (result will be 1)<br />
1885 to32bit ( n1 n2 n3 n4 – n32 ) treat 4 last stack elements as bytes<br />
1886                 and unite them into 32 bit dword. Most significant byte<br />
1887                 on top.<br />
1888                 ex: 12 76 23 11 to32bit result: 186076172<br />
1890 to8bit ( n32 – n1 n2 n3 n4 ) break 32 bit number into 4 bytes.<br />
1891                 Useful if you need to send 32 bit numbers thru 8 bit COM<br />
1892                 port.<br />
1893                 ex: 186076172 to8bit result: 12 76 23 11<br />
1895 mod ( n1 n2 – reminder ) divide n1 by n2 and returns reminder.<br />
1896                 ex: 12 5 mod result: 2<br />
1898 bound ( low n high – n ) check if n is in given bounds,<br />
1899                 if not then incarease/decarease it to match bounds.<br />
1900                 ex: 5 80 15 bound result: 15<br />
1901                     5 10 15 bound result: 10<br />
1902                     5 -10 15 bound result: 5<br />
1904 bound? ( low n high – result ) returns true if n is in the<br />
1905                 given bounds.<br />
1907 tab ( col – spaces) calculate amount of spaces to add<br />
1908                 ta reach next tabulation from given column.<br />
1910 count ( addr – addr+1 n )<br />
1911                 Useful for returning bytes from constantly incareasing<br />
1912                 address. Module "type" is nice example.<br />
1914 c, ( n – )<br />
1915                 store one byte at memory specified by "h". And incarease<br />
1916                 "h" by 1.<br />
1918 , ( n – )<br />
1919                 store 32 bit number at memory specified by "h". And<br />
1920                 incarease "h" by 4.<br />
1922 cmove ( addr1 addr2 n – )<br />
1923                 copy "n" amount of bytes from memory at "addr1" to memory<br />
1924                 at "addr2".<br />
1926 rnd ( limit – result )<br />
1927                 generates random number in range 0 to "limit"-1.<br />
1929 abs ( n – |n| )<br />
1930                 returns absolute value of "n"<br />
1934 <div id="outline-container-org6965f88" class="outline-3">
1935 <h3 id="org6965f88"><span class="section-number-3">12.7</span> Dynamic & static strings</h3>
1936 <div class="outline-text-3" id="text-12-7">
1938 Fifth supports both static and dynamic strings. Static strings must
1939 have predefined space reserved, and string mustn't exceed this
1940 length. They manipulation is faster. But they use more memory. Static
1941 string memory address is used to refer to the string.
1945 Dynamic strings can have at any time length form 0 to 0FFh, They take
1946 up only memory they currently need. They are held in dynamic memory
1947 blocks, so dynamic block handle is used to refer to this string.
1951 Both types of strings are stored in the way, where first (0th) byte
1952 holds current string length, following bytes are string itself.
1959 Dstral ( – handle )<br />
1960                 Allocate new string.<br />
1962 Dstrlen ( handle – length )<br />
1963                 Return string length.<br />
1965 c+Dstr ( chr handle – )<br />
1966                 Add one byte to end of the string.<br />
1968 c+lDstr ( chr handle – )<br />
1969                 Add one byte to left side (beginning) of the string.<br />
1971 Dstr. ( handle – )<br />
1972                 Write contec of string into screen.<br />
1974 Dstrsure ( size Dstr – )<br />
1975                 Makes sure that at least rquested<br />
1976                 "size" (amount of characters) is allocated for given<br />
1977                 dynamic string.<br />
1979 Dstr2str ( handle address – )<br />
1980                 Copy dyamic string into static memory space.<br />
1982 str2Dstr ( address handle – )<br />
1983                 Copy static string into dyamic string.<br />
1985 Dstr+str ( Dstr addr – )<br />
1986                 Add contenc of dynamic string to static string.<br />
1988 D" any string" ( – Dstr )<br />
1989                 Moves specified string into dynamic string called "defDstr".<br />
1991 D> any_string ( – Dstr )<br />
1992                 Moves specified string into dynamic string called "defDstr".<br />
1993                 Space marks end of string!<br />
1995 D>2 any_string ( – Dstr )<br />
1996                 Moves specified string into dynamic string called "defDstr2".<br />
1997                 Space marks end of string!<br />
1999 Dstr+Dstr ( Dstr1 Dstr2 – )<br />
2000                 Adds "Dstr1" to "Dstr2" and places result into "Dstr2".<br />
2002 Dstrclear ( Dstr – )<br />
2003                 Clears contenc of dynamic string.<br />
2005 Dstr2Dstr ( Dstr1 Dstr2 – )<br />
2006                 Moves "Dstr1" to "Dstr2".<br />
2007 Dstr ( data" name – )<br />
2008                 Creates new dynamic string and moves specified data into it.<br />
2009                 Then creates new constant with given "name" holding created<br />
2010                 dynamic string handle.<br />
2012                 ex: Dstr Hello, my name is Sven!" message \ creates it<br />
2013                     message Dstr. \ tests it<br />
2015 Dstrlscan ( char Dstr – loc )<br />
2016                 Searches dynamic string for "char", from left to right,<br />
2017                 returns first found "char" location in string, or 0,<br />
2018                 if not found.<br />
2020 Dstrrscan ( char Dstr – loc )<br />
2021                 Searches dynamic string for "char", from right to left,<br />
2022                 returns first found "char" location in string, or 0,<br />
2023                 if not found.<br />
2025 Dstrlscane ( char Dstr – loc )<br />
2026                 Same as "Dstrlscan" buf returns string length+1 as location.<br />
2028 Dstrleft ( amo Dstr – )<br />
2029                 Only specified amount of characters from left remains<br />
2030                 in dynamic string. ie. cut right part out.<br />
2032 Dstrright ( amo Dstr – )<br />
2033                 Only specified amount of characters from right remains<br />
2034                 in dynamic string. ie. cut left part out.<br />
2036 Dstrcutl ( amo Dstr – )<br />
2037                 Cut specified amount of characters from left of dynamic<br />
2038                 string out.<br />
2040 Dstrsp ( char Dstr1 Dstr2 – )<br />
2041                 Separate dynamic string in Dstr1 into two parts,<br />
2042                 using "char" as separator. First part will be stored in<br />
2043                 "Dstr2", second part in "Dstr1".<br />
2044                 ex: asc \ \ ..separator<br />
2045                     D> listF\listLIB\5TH_DRVMOUSE \ ..separate from<br />
2046                     defDstr2 \ ..place result in<br />
2047                     Dstrsp \ separation command<br />
2048                     defDstr Dstr. \ will be: listLIB\5TH_DRVMOUSE<br />
2049                     defDstr2 Dstr. \ will be: listF<br />
2051 Dv ( addr – )<br />
2052                 Allocates empty dynamic string, and places it's handle<br />
2053                 into given address.<br />
2055 Df ( addr – )<br />
2056                 Reads dynamic string handle from given address and<br />
2057                 deallocates (frees) it.<br />
2059 ex: var mystring1<br />
2060         : testmodule<br />
2061         mystring1 Dv \ allocates string<br />
2063                 <whatever><br />
2065         mystring1 Df ; \ deallocates it again when no longer needed.<br />
2070 <div id="outline-container-orge322491" class="outline-2">
2071 <h2 id="orge322491"><span class="section-number-2">13</span> Dynamically loadable modules</h2>
2072 <div class="outline-text-2" id="text-13">
2074 <div id="outline-container-orgc575c29" class="outline-3">
2075 <h3 id="orgc575c29"><span class="section-number-3">13.1</span> Keyboard driver</h3>
2076 <div class="outline-text-3" id="text-13-1">
2079 KBD_@ ( – code ) get scancodes for pressed keys from keyboard.<br />
2080 KBD_down? ( key – result ) check is key with specified scancode<br />
2081                 currently pressed down.<br />
2082 KBD_SC2FSCII ( code – FSCII ) convert key scancode into FSCII code,<br />
2083                 or in FSK (Fifth standard keycode).<br />
2084 KBD_F@ ( – FSCII ) read pressed key FSCII or FSK, returns -1 if no<br />
2085                 keys are pressed.<br />
2086 KBD_FW@ ( – FSCII ) read pressed key FSCII or FSK, if no keys is<br />
2087                 are pressed then waits until there is.<br />
2089                 FSK<br />
2090                 —<br />
2099 401 … F1 …<br />
2113 <div id="outline-container-org7c5c975" class="outline-3">
2114 <h3 id="org7c5c975"><span class="section-number-3">13.2</span> Mouse driver</h3>
2115 <div class="outline-text-3" id="text-13-2">
2117 mousex var Mouse x coordinate.<br />
2118 mousey var Mouse y coordinate.<br />
2119 mousekeyl var Mouse left key.<br />
2120 mousekeym var Mouse middle key.<br />
2121 mousekeyr var Mouse right key.<br />
2122 mousec var Display current mouse coordinates in top left part of screen,<br />
2123                 if true. (good for debugging)<br />
2124 mousepointer var Image buffer, holding current mouse pointer.<br />
2125 mouseadd ( ModuleAddr x1 x2 y1 y2 – ) Add specified area on screen,<br />
2126                 into mause click buffer. If any mouse button is clicked on<br />
2127                 that area, module at "ModuleAddr" will be executed.<br />
2128 mousebe var Amount of buffer elements.<br />
2129 mousedo ( – ) Updates mouse coordinates and keys. Parse mouse<br />
2130                 click buffer, and draw mouse cursor to "screen".<br />
2134 <div id="outline-container-org7e9e6e4" class="outline-3">
2135 <h3 id="org7e9e6e4"><span class="section-number-3">13.3</span> 2D graphic library</h3>
2136 <div class="outline-text-3" id="text-13-3">
2138 <dt>lineh ( color len x y imgbuf – )</dt><dd>draws horisontal line from X,Y
2139 coordinates to right, with specified length.</dd>
2141 <dt>linev ( color len x y imgbuf – )</dt><dd>draws vertical line down, from
2142 coordinates X,Y, with specified length.</dd>
2144 <dt>box ( color x2 x1 y2 y1 imgbuf – )</dt><dd><p>
2145 draws rectangular box. x2
2146 bust be >= x1, y2 must be >= y1.
2149 <pre class="example">
2156 <dt>flipv ( imgbuf – )</dt><dd>flip image vertically.</dd>
2158 <dt>imgcoltrans ( ImgBuf Color ToColor – )</dt><dd>Translate all pixels in
2159 specified image with "Color" into "ToColor".</dd>
2161 <dt>imgfill ( color x y imgbuf – )</dt><dd>Fill image region starting at
2162 location X & Y with specified color.</dd>
2168 <div id="outline-container-org53b108e" class="outline-3">
2169 <h3 id="org53b108e"><span class="section-number-3">13.4</span> Trigonometry functions</h3>
2170 <div class="outline-text-3" id="text-13-4">
2172 <div id="outline-container-orga868964" class="outline-4">
2173 <h4 id="orga868964"><span class="section-number-4">13.4.1</span> sin ( a – result )</h4>
2174 <div class="outline-text-4" id="text-13-4-1">
2176 Return sinus from given angle "a", 360ø is 2000. So 1000 represents
2177 180ø angle. Result will be in range -10'000 to 10'000, instead of ñ1.
2181 <div id="outline-container-org7e217b7" class="outline-4">
2182 <h4 id="org7e217b7"><span class="section-number-4">13.4.2</span> cos ( a – result )</h4>
2183 <div class="outline-text-4" id="text-13-4-2">
2185 Return cosinus from given angle. Parameters are like in <a href="#orga868964">sin</a> function.
2192 <div id="postamble" class="status">
2193 <p class="author">Author: Svjatoslav Agejenko</p>
2194 <p class="date">Created: 2022-04-17 Sun 18:14</p>
2195 <p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>