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 <!-- 2021-12-21 T 20:02 -->
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; margin-top: 14px;}
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 href="https://bootswatch.com/3/darkly/bootstrap.min.css" rel="stylesheet">
197 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
198 <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
199 <style type="text/css">
200 footer {background-color: #111 !important;}
201 pre {background-color: #111; color: #ccc;}
203 <link rel="stylesheet" type="text/css" href="https://thomasf.github.io/solarized-css/solarized-dark.min.css" />
204 <script type="text/javascript">
205 // @license magnet:?xt=urn:btih:e95b018ef3580986a04669f1b5879592219e2a7a&dn=public-domain.txt Public Domain
206 <!--/*--><![CDATA[/*><!--*/
207 function CodeHighlightOn(elem, id)
209 var target = document.getElementById(id);
211 elem.classList.add("code-highlighted");
212 target.classList.add("code-highlighted");
215 function CodeHighlightOff(elem, id)
217 var target = document.getElementById(id);
219 elem.classList.remove("code-highlighted");
220 target.classList.remove("code-highlighted");
226 <script type="text/x-mathjax-config">
228 displayAlign: "center",
229 displayIndent: "0em",
231 "HTML-CSS": { scale: 100,
232 linebreaks: { automatic: "false" },
236 linebreaks: { automatic: "false" },
238 NativeMML: {scale: 100},
239 TeX: { equationNumbers: {autoNumber: "AMS"},
240 MultLineWidth: "85%",
246 <script type="text/javascript"
247 src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
251 <h1 class="title">Fifth - virtual machine, operating system, programming language</h1>
252 <div id="table-of-contents">
253 <h2>Table of Contents</h2>
254 <div id="text-table-of-contents">
256 <li><a href="#orga1937e0">1. General</a>
258 <li><a href="#org4ccb678">1.1. Source code</a></li>
261 <li><a href="#org02e49e6">2. !Project deprecated!</a></li>
262 <li><a href="#orgdc8dd24">3. Introduction</a>
264 <li><a href="#org040189a">3.1. screenshots</a></li>
267 <li><a href="#org3c7b2e9">4. Installation</a></li>
268 <li><a href="#org1b662d2">5. Fifth distribution directory tree description</a></li>
269 <li><a href="#org1ffd5e0">6. Requirements</a>
271 <li><a href="#org83bdd27">6.1. Software</a></li>
272 <li><a href="#orgad4b565">6.2. Hardware</a></li>
273 <li><a href="#org32cb851">6.3. Human</a></li>
276 <li><a href="#org9413aba">7. Numbers representation within Fifth</a></li>
277 <li><a href="#orgebb1600">8. Disk file map, and it's data structures</a>
279 <li><a href="#org8ff9302">8.1. Disk allocation</a></li>
280 <li><a href="#org022023f">8.2. FAT entry format:</a></li>
281 <li><a href="#orgfcf638a">8.3. File entry format</a></li>
284 <li><a href="#orgbd93844">9. Core architecture</a>
286 <li><a href="#org625be09">9.1. Dictionary entry format</a></li>
287 <li><a href="#orged89e76">9.2. Possible module types</a></li>
288 <li><a href="#orgd8943d6">9.3. Memory map</a></li>
291 <li><a href="#orgd9ae054">10. Virtual machine</a>
293 <li><a href="#orgb69fbe0">10.1. instruction set</a>
295 <li><a href="#org52968fa">10.1.1. overview table</a></li>
296 <li><a href="#org5d14c50">10.1.2. kbd@ - read scancode of pressed or released key</a></li>
297 <li><a href="#org997aa8a">10.1.3. vidput - put image1 into image2, at location x, y</a></li>
298 <li><a href="#org7d2145d">10.1.4. cmove - copy memory array</a></li>
299 <li><a href="#org3dae1d1">10.1.5. tvidput - put image with transparency support</a></li>
300 <li><a href="#orgd6f6733">10.1.6. charput - draw text character</a></li>
305 <li><a href="#org8550cb7">11. Fifth source format</a>
307 <li><a href="#orgd5e3f59">11.1. FSCII</a></li>
310 <li><a href="#orgc3ae776">12. Fifth commands</a>
312 <li><a href="#org5369ba9">12.1. Compilation & miscellaneous</a></li>
313 <li><a href="#org20c4a54">12.2. Conditionals & control flow</a></li>
314 <li><a href="#org94aecc7">12.3. Disk & file access</a></li>
315 <li><a href="#orge7846ad">12.4. Dynamic memory</a></li>
316 <li><a href="#org0749970">12.5. Graphics and text</a></li>
317 <li><a href="#org31ff701">12.6. Math, memory & stack manipulation</a></li>
318 <li><a href="#org81063af">12.7. Dynamic & static strings</a></li>
321 <li><a href="#org02f7fb3">13. Dynamically loadable modules</a>
323 <li><a href="#orgbae286f">13.1. Keyboard driver</a></li>
324 <li><a href="#org3255f4e">13.2. Mouse driver</a></li>
325 <li><a href="#org64d1a45">13.3. 2D graphic library</a></li>
326 <li><a href="#org3bd5475">13.4. Trigonometry functions</a>
328 <li><a href="#orge23e698">13.4.1. sin ( a – result )</a></li>
329 <li><a href="#orgfa790a4">13.4.2. cos ( a – result )</a></li>
338 <div id="outline-container-orga1937e0" class="outline-2">
339 <h2 id="orga1937e0"><span class="section-number-2">1</span> General</h2>
340 <div class="outline-text-2" id="text-1">
342 <li>This program is free software: released under Creative Commons Zero
347 <li>Svjatoslav Agejenko</li>
348 <li>Homepage: <a href="https://svjatoslav.eu">https://svjatoslav.eu</a></li>
349 <li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a></li>
352 <li><a href="https://www.svjatoslav.eu/projects/">Other software projects hosted at svjatoslav.eu</a></li>
355 <div id="outline-container-org4ccb678" class="outline-3">
356 <h3 id="org4ccb678"><span class="section-number-3">1.1</span> Source code</h3>
357 <div class="outline-text-3" id="text-1-1">
359 <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>
361 <li><a href="https://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=summary">Browse Git repository online</a></li>
364 Clone Git repository using command:
366 <pre class="example">
367 git clone https://www2.svjatoslav.eu/git/fifth.git
374 <div id="outline-container-org02e49e6" class="outline-2">
375 <h2 id="org02e49e6"><span class="section-number-2">2</span> !Project deprecated!</h2>
376 <div class="outline-text-2" id="text-2">
378 Current implementation does not support object oriented
379 programming. While working on Fifth I got lots of cool new ideas that
380 require reimplementation of everything.
384 Currently I try to implement those new ideas in the project called
385 <a href="https://www3.svjatoslav.eu/projects/sixth/">Sixth</a>.
389 System is built many years ago when I was still using DOS as a primary
394 <div id="outline-container-orgdc8dd24" class="outline-2">
395 <h2 id="orgdc8dd24"><span class="section-number-2">3</span> Introduction</h2>
396 <div class="outline-text-2" id="text-3">
398 Fifth is programming lanquage & operating system, running on <a href="#orgd9ae054">virtual
399 machine</a>, with custom instruction set. It is much like Charles Chunk
400 Moore's Forth, it also uses stack architecture, and many commands are
401 similar. Basically I got familiar with concepts of Forth, and being
402 inspired created my own system.
406 <li><a href="5TH_ET.txt">Example Fifth source file - text editor</a></li>
409 <div id="outline-container-org040189a" class="outline-3">
410 <h3 id="org040189a"><span class="section-number-3">3.1</span> screenshots</h3>
411 <div class="outline-text-3" id="text-3-1">
413 <div id="orga3588d5" class="figure">
414 <p><img src="screenshots/start.png" alt="start.png" />
419 Startup screen diplaying Fifth logo and full file list.
423 <div id="orgdb75c0b" class="figure">
424 <p><img src="screenshots/dictionary.png" alt="dictionary.png" />
429 Sample words defined. Most of the words are commands that can be
430 executed interactively from command line or from file. When executed
431 they can be selectively compiled or interpreted.
436 <div id="org5be1eaf" class="figure">
437 <p><img src="screenshots/text editor.png" alt="text editor.png" />
442 Built in text editor.
448 <div id="outline-container-org3c7b2e9" class="outline-2">
449 <h2 id="org3c7b2e9"><span class="section-number-2">4</span> Installation</h2>
450 <div class="outline-text-2" id="text-4">
452 Just unpack all files, witout altering original directory structure,
453 somewhere in your hard disk. For example: C:\MISC\FIFTH\…. To run
454 fifth you need minimally just 2 files. emulator itself ( EMULATOR.EXE
455 or EMULATOR.COM ), and virtual disk file ( DISK.RAW ).
459 Read more about <a href="#org1b662d2">Fifth distribution directory tree description</a>.
464 <div id="outline-container-org1b662d2" class="outline-2">
465 <h2 id="org1b662d2"><span class="section-number-2">5</span> Fifth distribution directory tree description</h2>
466 <div class="outline-text-2" id="text-5">
468 After downloading and unpacking the ZIP file you shoud get directory
469 tree similar to this:
473 <b>DOC</b> - Fifth documentation<br />
474   <b>commands</b> - documentation on Fifth built-in commands<br />
475   <b>modules</b> - documentation on additional commands, realized as loadable modules<br />
476   <b>shots</b> - Fifth screenshots<br />
478 <b>imageFile</b> - files contained within 'disk.raw', just an extracted form.<br />
480 <b>source</b> - source files<br />
481   <b>emulator</b> - emulator source<br />
482   <b>util</b> - utilites<br />
484 <b>disk.raw</b> - Virtual disk file, has filesystem inside.<br />
485 <b>emulator.com</b> - main executable.<br />
490 <div id="outline-container-org1ffd5e0" class="outline-2">
491 <h2 id="org1ffd5e0"><span class="section-number-2">6</span> Requirements</h2>
492 <div class="outline-text-2" id="text-6">
494 <div id="outline-container-org83bdd27" class="outline-3">
495 <h3 id="org83bdd27"><span class="section-number-3">6.1</span> Software</h3>
496 <div class="outline-text-3" id="text-6-1">
498 <li>MS-DOS 6.22, with HIMEM.SYS loaded.</li>
499 <li>Mouse driver if you have a mouse.</li>
500 <li>Does work only when CPU is in real mode.</li>
501 <li>To recompile ASM sources I used FASM (Flat Assembler).</li>
502 <li>I ran QBasic utilities on QB 4.5 .</li>
503 <li>VESA support by BIOS, or external driver (UNIVBE).</li>
507 <div id="outline-container-orgad4b565" class="outline-3">
508 <h3 id="orgad4b565"><span class="section-number-3">6.2</span> Hardware</h3>
509 <div class="outline-text-3" id="text-6-2">
511 <li>Minimum CPU 386.</li>
512 <li>64 KB free RAM below 640KB,</li>
513 <li>2 MB of free XMS.</li>
514 <li>VESA compatible video card.</li>
518 <div id="outline-container-org32cb851" class="outline-3">
519 <h3 id="org32cb851"><span class="section-number-3">6.3</span> Human</h3>
520 <div class="outline-text-3" id="text-6-3">
522 <li>Beginner level Forth knowledge is recommended.</li>
523 <li>Lots of enthusiasm.</li>
528 <div id="outline-container-org9413aba" class="outline-2">
529 <h2 id="org9413aba"><span class="section-number-2">7</span> Numbers representation within Fifth</h2>
530 <div class="outline-text-2" id="text-7">
532 <div id="org2023443" class="figure">
533 <p><a href="numbers.png"><img src="numbers.png" alt="numbers.png" /></a>
538 Because I can define everything, starting from CPU, why not try also
539 alternative and unique number representation ?
543 Fifth uses its hexdecimal number representation as primary. Numbers
544 shape is formed by dividing a square into four parts. And manipulating
545 their color (black or white).
549 <div id="outline-container-orgebb1600" class="outline-2">
550 <h2 id="orgebb1600"><span class="section-number-2">8</span> Disk file map, and it's data structures</h2>
551 <div class="outline-text-2" id="text-8">
553 Core and high-level boot code is stored outside of the filesystem to
554 allow easy access to it, at early booting time, when filesystem is not
558 <div id="outline-container-org8ff9302" class="outline-3">
559 <h3 id="org8ff9302"><span class="section-number-3">8.1</span> Disk allocation</h3>
560 <div class="outline-text-3" id="text-8-1">
561 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
565 <col class="org-left" />
567 <col class="org-left" />
569 <col class="org-left" />
573 <th scope="col" class="org-left">offset</th>
574 <th scope="col" class="org-left">length</th>
575 <th scope="col" class="org-left">description</th>
580 <td class="org-left">0</td>
581 <td class="org-left">~4 Kb</td>
582 <td class="org-left">Fifth core</td>
586 <td class="org-left">4 Kb</td>
587 <td class="org-left">~32 Kb</td>
588 <td class="org-left">high-level boot code</td>
592 <td class="org-left">37 Kb</td>
593 <td class="org-left">~65 Kb</td>
594 <td class="org-left">FAT</td>
598 <td class="org-left">101 Kb</td>
599 <td class="org-left">~16 MB</td>
600 <td class="org-left">filesystem data area</td>
606 <div id="outline-container-org022023f" class="outline-3">
607 <h3 id="org022023f"><span class="section-number-3">8.2</span> FAT entry format:</h3>
608 <div class="outline-text-3" id="text-8-2">
609 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
613 <col class="org-right" />
615 <col class="org-left" />
619 <th scope="col" class="org-right">code</th>
620 <th scope="col" class="org-left">meaning</th>
625 <td class="org-right">-2</td>
626 <td class="org-left">last sector</td>
630 <td class="org-right">-1</td>
631 <td class="org-left">empty sector</td>
635 <td class="org-right">0 --</td>
636 <td class="org-left">.. pointer to next block</td>
642 <div id="outline-container-orgfcf638a" class="outline-3">
643 <h3 id="orgfcf638a"><span class="section-number-3">8.3</span> File entry format</h3>
644 <div class="outline-text-3" id="text-8-3">
645 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
649 <col class="org-right" />
651 <col class="org-right" />
653 <col class="org-left" />
657 <th scope="col" class="org-right">offset</th>
658 <th scope="col" class="org-right">length</th>
659 <th scope="col" class="org-left">description</th>
664 <td class="org-right">0</td>
665 <td class="org-right">4</td>
666 <td class="org-left">extension</td>
670 <td class="org-right">4</td>
671 <td class="org-right">16</td>
672 <td class="org-left">name</td>
676 <td class="org-right">20</td>
677 <td class="org-right">4</td>
678 <td class="org-left">entry point</td>
682 <td class="org-right">24</td>
683 <td class="org-right">4</td>
684 <td class="org-left">size</td>
688 <td class="org-right">28</td>
689 <td class="org-right">4</td>
690 <td class="org-left">last modification time</td>
697 <div id="outline-container-orgbd93844" class="outline-2">
698 <h2 id="orgbd93844"><span class="section-number-2">9</span> Core architecture</h2>
699 <div class="outline-text-2" id="text-9">
701 Fifth core is simply some amount of already compiled into machine code
702 and linked together modules (entries in other words). In compilation
703 process modules is compiled one by one and simply stored on top of
704 already existing and growing core. Separately from core is kept
705 dictionary, this is special list that contain names of compiled
706 modules, variables etc. and they locations in core. Constants use
707 dictionary space only. Random word can be removed from dictionary at
708 any time. Currently dictionary can contain at most 1000 entries.
711 <div id="outline-container-org625be09" class="outline-3">
712 <h3 id="org625be09"><span class="section-number-3">9.1</span> Dictionary entry format</h3>
713 <div class="outline-text-3" id="text-9-1">
714 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
718 <col class="org-right" />
720 <col class="org-right" />
722 <col class="org-left" />
726 <th scope="col" class="org-right">offset</th>
727 <th scope="col" class="org-right">length</th>
728 <th scope="col" class="org-left">description</th>
733 <td class="org-right">0</td>
734 <td class="org-right">4</td>
735 <td class="org-left">0 &lt; previous entry</td>
739 <td class="org-right"> </td>
740 <td class="org-right"> </td>
741 <td class="org-left">0 = last</td>
745 <td class="org-right"> </td>
746 <td class="org-right"> </td>
747 <td class="org-left">-1 = empty</td>
752 <td class="org-right">4</td>
753 <td class="org-right">15</td>
754 <td class="org-left">module name string</td>
759 <td class="org-right">19</td>
760 <td class="org-right">1</td>
761 <td class="org-left">entry type</td>
766 <td class="org-right">20</td>
767 <td class="org-right">4</td>
768 <td class="org-left">entry data</td>
774 Core headers as linked list of module names make up something like
775 dictionary. When some entry address is needed compiler can quickly
776 run through headers backwards and find needed entry.
780 <div id="outline-container-orged89e76" class="outline-3">
781 <h3 id="orged89e76"><span class="section-number-3">9.2</span> Possible module types</h3>
782 <div class="outline-text-3" id="text-9-2">
783 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
787 <col class="org-right" />
789 <col class="org-left" />
791 <col class="org-left" />
795 <th scope="col" class="org-right">type</th>
796 <th scope="col" class="org-left">description</th>
797 <th scope="col" class="org-left">"execute" action</th>
802 <td class="org-right">0</td>
803 <td class="org-left">data</td>
804 <td class="org-left">compile "num" instruction</td>
808 <td class="org-right"> </td>
809 <td class="org-left"> </td>
810 <td class="org-left">with address to module</td>
815 <td class="org-right">1</td>
816 <td class="org-left">submodule</td>
817 <td class="org-left">compile "call" instruction</td>
821 <td class="org-right"> </td>
822 <td class="org-left"> </td>
823 <td class="org-left">with address to module</td>
828 <td class="org-right">2</td>
829 <td class="org-left">imm. submodule</td>
830 <td class="org-left">immediately call to module</td>
836 <div id="outline-container-orgd8943d6" class="outline-3">
837 <h3 id="orgd8943d6"><span class="section-number-3">9.3</span> Memory map</h3>
838 <div class="outline-text-3" id="text-9-3">
839 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
843 <col class="org-right" />
845 <col class="org-left" />
847 <col class="org-left" />
851 <th scope="col" class="org-right">location</th>
852 <th scope="col" class="org-left">size</th>
853 <th scope="col" class="org-left">description</th>
858 <td class="org-right">0</td>
859 <td class="org-left">~4096</td>
860 <td class="org-left">core</td>
864 <td class="org-right">1500000</td>
865 <td class="org-left">~32000</td>
866 <td class="org-left">highlevel Fifth boot code</td>
870 <td class="org-right">200000h</td>
871 <td class="org-left"> </td>
872 <td class="org-left">core startup messages area</td>
876 <td class="org-right">5200000</td>
877 <td class="org-left"> </td>
878 <td class="org-left">end of dynamic memory space</td>
885 <div id="outline-container-orgd9ae054" class="outline-2">
886 <h2 id="orgd9ae054"><span class="section-number-2">10</span> Virtual machine</h2>
887 <div class="outline-text-2" id="text-10">
889 Using CPU emulator slows it down but I shouldn't now think too mutch
890 about, and waste my time on batteling with problems whitch results on
891 complex design of PC hardware. Also it allows me to use existing DOS
892 and resident drivers services in real mode. So I don't need to deal
893 with hardware too mutch. It also allows me to use all free XMS for
894 flat code & data storage.
898 Current emulator emulates 1 CPU. It has 2 stacks, ~50 instructions,
899 and 4GB flat address space (theoretically). I'm not sure that DOS
900 6.22 that I currently prefer can handle more than 64 MB of RAM. While
901 I tried to keep instructionset simple, I was forced to put in lot of
902 complex instructions to make it's performance acceptable on
903 emulator. On actual silicon ~20 instructions is enaugh (I think).
907 Maybe one day similar system will run directly on custom silicon chip :)
912 CPU has following registers:
914 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
918 <col class="org-left" />
920 <col class="org-left" />
924 <td class="org-left">IP</td>
925 <td class="org-left">instruction pointer</td>
929 <td class="org-left">DSP</td>
930 <td class="org-left">data stack pointer</td>
934 <td class="org-left">RSP</td>
935 <td class="org-left">return stack pointer</td>
940 <div id="outline-container-orgb69fbe0" class="outline-3">
941 <h3 id="orgb69fbe0"><span class="section-number-3">10.1</span> instruction set</h3>
942 <div class="outline-text-3" id="text-10-1">
944 <div id="outline-container-org52968fa" class="outline-4">
945 <h4 id="org52968fa"><span class="section-number-4">10.1.1</span> overview table</h4>
946 <div class="outline-text-4" id="text-10-1-1">
948 Virtual CPU, commands (most of them are avaiable as ordinary commands
949 in programming language):
953 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
957 <col class="org-right" />
959 <col class="org-left" />
961 <col class="org-left" />
963 <col class="org-left" />
967 <th scope="col" class="org-right">#</th>
968 <th scope="col" class="org-left">name</th>
969 <th scope="col" class="org-left">stack footprint</th>
970 <th scope="col" class="org-left">description</th>
975 <td class="org-right">0</td>
976 <td class="org-left">nop</td>
977 <td class="org-left">--</td>
978 <td class="org-left">does nothing</td>
982 <td class="org-right">1</td>
983 <td class="org-left">halt</td>
984 <td class="org-left">--</td>
985 <td class="org-left">halt CPU ( return to DOS on emulator )</td>
989 <td class="org-right">2</td>
990 <td class="org-left"><a href="#org5d14c50">kbd@</a></td>
991 <td class="org-left">– c</td>
992 <td class="org-left">read scancode of pressed or released key</td>
996 <td class="org-right">3</td>
997 <td class="org-left">num <dword></td>
998 <td class="org-left">– n</td>
999 <td class="org-left">put immidiate number into datastack</td>
1003 <td class="org-right">4</td>
1004 <td class="org-left">jmp <dword></td>
1005 <td class="org-left">--</td>
1006 <td class="org-left">jump to specified code</td>
1010 <td class="org-right">5</td>
1011 <td class="org-left">call <dword></td>
1012 <td class="org-left"> </td>
1013 <td class="org-left">jump to specified code, save return address to return stack</td>
1017 <td class="org-right">6</td>
1018 <td class="org-left">1+</td>
1019 <td class="org-left">n – n+1</td>
1020 <td class="org-left"> </td>
1024 <td class="org-right">7</td>
1025 <td class="org-left">1-</td>
1026 <td class="org-left">n – n-1</td>
1027 <td class="org-left"> </td>
1031 <td class="org-right">8</td>
1032 <td class="org-left">dup</td>
1033 <td class="org-left">n – n n</td>
1034 <td class="org-left">duplicate top of data stack</td>
1038 <td class="org-right">9</td>
1039 <td class="org-left">drop</td>
1040 <td class="org-left">n --</td>
1041 <td class="org-left">drop last element in data stack</td>
1045 <td class="org-right">10</td>
1046 <td class="org-left">if <dword></td>
1047 <td class="org-left">n --</td>
1048 <td class="org-left">jump to addr if top element was 0</td>
1052 <td class="org-right">11</td>
1053 <td class="org-left">ret</td>
1054 <td class="org-left"> </td>
1055 <td class="org-left">jump to code, specified in return stack.</td>
1059 <td class="org-right">12</td>
1060 <td class="org-left">c@</td>
1061 <td class="org-left">addr – n</td>
1062 <td class="org-left">read byte from memory at specified address</td>
1066 <td class="org-right">13</td>
1067 <td class="org-left">c!</td>
1068 <td class="org-left">n addr --</td>
1069 <td class="org-left">store byte to specified memory</td>
1073 <td class="org-right">14</td>
1074 <td class="org-left">push</td>
1075 <td class="org-left">DSTK -> RSTK</td>
1076 <td class="org-left">move top of datastack to returnstack</td>
1080 <td class="org-right">15</td>
1081 <td class="org-left">pop</td>
1082 <td class="org-left">RSTK -> DSTK</td>
1083 <td class="org-left">move top of returnstack to datastack</td>
1087 <td class="org-right">16</td>
1088 <td class="org-left"><unused></td>
1089 <td class="org-left"> </td>
1090 <td class="org-left"> </td>
1094 <td class="org-right">17</td>
1095 <td class="org-left">rot</td>
1096 <td class="org-left">n1 n2 n3 – n2 n3 n1</td>
1097 <td class="org-left">rotate stack elements</td>
1101 <td class="org-right">18</td>
1102 <td class="org-left">disk@</td>
1103 <td class="org-left">FromDiskSect ToMem --</td>
1104 <td class="org-left">read 1KB from disk into RAM</td>
1108 <td class="org-right">19</td>
1109 <td class="org-left">disk!</td>
1110 <td class="org-left">FromMem ToDiskSect --</td>
1111 <td class="org-left">write 1KB to disk</td>
1115 <td class="org-right">20</td>
1116 <td class="org-left">@</td>
1117 <td class="org-left">addr – n</td>
1118 <td class="org-left">read 32 bit number from memory</td>
1122 <td class="org-right">21</td>
1123 <td class="org-left">!</td>
1124 <td class="org-left">n addr --</td>
1125 <td class="org-left">store 32 bit number to memory</td>
1129 <td class="org-right">22</td>
1130 <td class="org-left">over</td>
1131 <td class="org-left">n1 n2 – n1 n2 n1</td>
1132 <td class="org-left"> </td>
1136 <td class="org-right">23</td>
1137 <td class="org-left">swap</td>
1138 <td class="org-left">n1 n2 – n2 n1</td>
1139 <td class="org-left"> </td>
1143 <td class="org-right">24</td>
1144 <td class="org-left">+</td>
1145 <td class="org-left">n1 n2 – n1+n2</td>
1146 <td class="org-left"> </td>
1150 <td class="org-right">25</td>
1151 <td class="org-left">-</td>
1152 <td class="org-left">n1 n2 – n1-n2</td>
1153 <td class="org-left"> </td>
1157 <td class="org-right">26</td>
1158 <td class="org-left">*</td>
1159 <td class="org-left">n1 n2 – n1*n2</td>
1160 <td class="org-left"> </td>
1164 <td class="org-right">27</td>
1165 <td class="org-left">/</td>
1166 <td class="org-left">n1 n2 – n1/n2</td>
1167 <td class="org-left"> </td>
1171 <td class="org-right">28</td>
1172 <td class="org-left">></td>
1173 <td class="org-left">n1 n2 – result</td>
1174 <td class="org-left">is true when n1 > n2</td>
1178 <td class="org-right">29</td>
1179 <td class="org-left"><</td>
1180 <td class="org-left">n1 n2 – result</td>
1181 <td class="org-left">is true when n1 < n2</td>
1185 <td class="org-right">30</td>
1186 <td class="org-left">not</td>
1187 <td class="org-left">n1 – not_n1</td>
1188 <td class="org-left">logical not</td>
1192 <td class="org-right">31</td>
1193 <td class="org-left">i</td>
1194 <td class="org-left">– n</td>
1195 <td class="org-left">copies top of return stack into datastack</td>
1199 <td class="org-right">32</td>
1200 <td class="org-left">cprt@</td>
1201 <td class="org-left">addr – n</td>
1202 <td class="org-left">read one byte from hardware port</td>
1206 <td class="org-right">33</td>
1207 <td class="org-left">cprt!</td>
1208 <td class="org-left">n addr --</td>
1209 <td class="org-left">store one byte to hardware port</td>
1213 <td class="org-right">34</td>
1214 <td class="org-left">i2</td>
1215 <td class="org-left">– n</td>
1216 <td class="org-left">like "i" but takes second top stack element</td>
1220 <td class="org-right">35</td>
1221 <td class="org-left">i3</td>
1222 <td class="org-left">– n</td>
1223 <td class="org-left">like "i" but takes third top stack element.</td>
1227 <td class="org-right">36</td>
1228 <td class="org-left">shl</td>
1229 <td class="org-left">n amount – n</td>
1230 <td class="org-left">left bit shift</td>
1234 <td class="org-right">37</td>
1235 <td class="org-left">shr</td>
1236 <td class="org-left">n amount – n</td>
1237 <td class="org-left">right bit shift</td>
1241 <td class="org-right">38</td>
1242 <td class="org-left">or</td>
1243 <td class="org-left">n1 n2 – n</td>
1244 <td class="org-left">logical or</td>
1248 <td class="org-right">39</td>
1249 <td class="org-left">xor</td>
1250 <td class="org-left">n1 n2 – n</td>
1251 <td class="org-left">exclusive logical or</td>
1255 <td class="org-right">40</td>
1256 <td class="org-left">vidmap</td>
1257 <td class="org-left">addr --</td>
1258 <td class="org-left">copy memory from "addr" to video memory.</td>
1262 <td class="org-right">41</td>
1263 <td class="org-left">mouse@</td>
1264 <td class="org-left">– x y button</td>
1265 <td class="org-left">read mouse coordinates & buttons</td>
1269 <td class="org-right">42</td>
1270 <td class="org-left"><a href="#org997aa8a">vidput</a></td>
1271 <td class="org-left">addr1 addr2 x y --</td>
1272 <td class="org-left">put image1 into image2, at location x, y</td>
1276 <td class="org-right">43</td>
1277 <td class="org-left"><a href="#org7d2145d">cmove</a></td>
1278 <td class="org-left">addr1 addr2 amount</td>
1279 <td class="org-left">move memory from addr1 to addr2</td>
1283 <td class="org-right">44</td>
1284 <td class="org-left">cfill</td>
1285 <td class="org-left">c addr amount --</td>
1286 <td class="org-left">fill memory starting at "addr" with "c" bytes.</td>
1290 <td class="org-right">45</td>
1291 <td class="org-left"><a href="#org3dae1d1">tvidput</a></td>
1292 <td class="org-left">addr1 addr2 x y --</td>
1293 <td class="org-left">put image with transparency support</td>
1297 <td class="org-right">46</td>
1298 <td class="org-left">depth</td>
1299 <td class="org-left">– depth</td>
1300 <td class="org-left">returns current depth of data stack.</td>
1304 <td class="org-right">47</td>
1305 <td class="org-left"><a href="#orgd6f6733">charput</a></td>
1306 <td class="org-left">colorfg colorbg addrsrc addrdest x y</td>
1307 <td class="org-left">draw text character</td>
1314 <div id="outline-container-org5d14c50" class="outline-4">
1315 <h4 id="org5d14c50"><span class="section-number-4">10.1.2</span> kbd@ - read scancode of pressed or released key</h4>
1316 <div class="outline-text-4" id="text-10-1-2">
1318 Returns 0 if no data available.
1322 <div id="outline-container-org997aa8a" class="outline-4">
1323 <h4 id="org997aa8a"><span class="section-number-4">10.1.3</span> vidput - put image1 into image2, at location x, y</h4>
1324 <div class="outline-text-4" id="text-10-1-3">
1326 Does clipping, so part of a big image can be mapped into smaller one.
1330 <div id="outline-container-org7d2145d" class="outline-4">
1331 <h4 id="org7d2145d"><span class="section-number-4">10.1.4</span> cmove - copy memory array</h4>
1332 <div class="outline-text-4" id="text-10-1-4">
1334 Move memory from addr1 to addr2. If addr1 is greater than addr2 then
1335 count address foward while moving, elseway starts from end and counts
1336 backwards, so no data loss occurs when memory regions partially
1341 <div id="outline-container-org3dae1d1" class="outline-4">
1342 <h4 id="org3dae1d1"><span class="section-number-4">10.1.5</span> tvidput - put image with transparency support</h4>
1343 <div class="outline-text-4" id="text-10-1-5">
1347 <pre class="example">
1353 Put image1 into image2, at location x, y with transparency support
1357 Color 255 in source image is treated as transparent.
1361 <div id="outline-container-orgd6f6733" class="outline-4">
1362 <h4 id="orgd6f6733"><span class="section-number-4">10.1.6</span> charput - draw text character</h4>
1363 <div class="outline-text-4" id="text-10-1-6">
1365 Draw character to image buffer located at "addrdest" to specified x &
1366 y location. Decodes 8 bytes from source to bits, used to draw
1374 <div id="outline-container-org8550cb7" class="outline-2">
1375 <h2 id="org8550cb7"><span class="section-number-2">11</span> Fifth source format</h2>
1376 <div class="outline-text-2" id="text-11">
1378 Fifth uses a different character table and codes than ASCII (still
1379 almost similar). I call it FSCII (Fifth Standard Code for Information
1380 Interchange) for example space character is not 32 but 255 instead. I
1381 plan to use mainly HEX numbers, and create new characters to represent
1382 numeric values. So typical nemric characters "0123…" is treated
1383 like ordinary letters.
1386 <div id="outline-container-orgd5e3f59" class="outline-3">
1387 <h3 id="orgd5e3f59"><span class="section-number-3">11.1</span> FSCII</h3>
1388 <div class="outline-text-3" id="text-11-1">
1389 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
1393 <col class="org-right" />
1395 <col class="org-left" />
1397 <col class="org-left" />
1401 <th scope="col" class="org-right">DEC</th>
1402 <th scope="col" class="org-left">HEX</th>
1403 <th scope="col" class="org-left">function</th>
1408 <td class="org-right">0 - 15</td>
1409 <td class="org-left">0 - F</td>
1410 <td class="org-left">HEX numbers</td>
1414 <td class="org-right">252</td>
1415 <td class="org-left">FC</td>
1416 <td class="org-left">backspace</td>
1420 <td class="org-right">253</td>
1421 <td class="org-left">FD</td>
1422 <td class="org-left">tabulator (TAB)</td>
1426 <td class="org-right">254</td>
1427 <td class="org-left">FE</td>
1428 <td class="org-left">carriage return (CR)</td>
1432 <td class="org-right">255</td>
1433 <td class="org-left">FF</td>
1434 <td class="org-left">space</td>
1438 <td class="org-right">else</td>
1439 <td class="org-left"> </td>
1440 <td class="org-left">ordinary characters, same as in ASCII.</td>
1447 <div id="outline-container-orgc3ae776" class="outline-2">
1448 <h2 id="orgc3ae776"><span class="section-number-2">12</span> Fifth commands</h2>
1449 <div class="outline-text-2" id="text-12">
1451 <div id="outline-container-org5369ba9" class="outline-3">
1452 <h3 id="org5369ba9"><span class="section-number-3">12.1</span> Compilation & miscellaneous</h3>
1453 <div class="outline-text-3" id="text-12-1">
1455 init module ( – )<br />
1456                 First module, control is passed to on startup. Contains<br />
1457                 initialization routines. Also it is the last core module.<br />
1458                 All new modules on top of it comes as result of executing<br />
1459                 external source files.<br />
1461 head <name> ( – ) compiles new dictionary entry without specifying<br />
1462                 new module type.<br />
1463                 ex: head myentry<br />
1465 : <name> ( – ) creates new code module<br />
1466 ; ( – ) ends module (immideate)<br />
1467                 ex: : hello ." hi there" ;<br />
1469 const <name> ( n – ) defines new constant.<br />
1470                 ex: 2147483647 const max<br />
1472 :i <name> ( – ) same as ":" but this module will be executed<br />
1473                 immideately even in compile mode.<br />
1474                 ex: :i ( 41 scan ;<br />
1476 create <name> ( – ) same as "head" , but specify module type as data.<br />
1477                 ex: create LotoResults 5 , 13 , 52 , 12 , 11 , 3 ,<br />
1479 allot ( n – ) allocate n bytes in dictionary.<br />
1480                 ex: create MyArray 100 allot<br />
1482 " <string>" ( – ) compile string and its size into core.<br />
1483                 ex: create Mystring " This is it's contects"<br />
1485 str <name> <string>" ( – ) just shorter way for defining strings.<br />
1486                 ex: str Mystring This is it's contenc"<br />
1488 var <name> ( – ) define new 32 bit variable.<br />
1489                 ex: var result<br />
1491 ' <module> ( – n ) return memory address of given entry.<br />
1492                 ex: ' init<br />
1494 forget <name> ( – ) erases from RAM given entry and all entries what was<br />
1495                 defined after it.<br />
1496                 ex: forget myprog<br />
1498 [ ( – ) set interpret mode (immideate)<br />
1499 ] ( n – ) set compile mode and compile top stack element<br />
1500                 in as literal. Together [ …. ] cobination provides good<br />
1501                 way to compute some values only once, at compile time,<br />
1502                 rather than every time while program is running.<br />
1503                 ex: : calculate - [ 4 MyConst1 + MyConst2 * ] ;<br />
1505 defer <name> ( – ) creates new module, with jump instruction.<br />
1506                 Later address where to jump can be modified by "is" command.<br />
1507                 This provides method of foward referencing. So you can use<br />
1508                 modules what not jet exist.<br />
1509 is ( address1 address2 – ) address1 - where to jump, address2 -<br />
1510                 address of module created by defer command.<br />
1511                 ex: defer dispver<br />
1512                         : run dispver ." running …" ;<br />
1513                                … whatever …<br />
1514                         : (dispver ." Version 9.99 " ;<br />
1515                         ' (dispver ' dispver is<br />
1517                 Now if I type "run" on the screen appears:<br />
1518                         Version 9.99 running …<br />
1520 asc <char> ( – ) reads char ascii code and treats it as literal.<br />
1521                 (immideate)<br />
1522                 ex: : BreakLine 30 do asc - emit loop ;<br />
1523                                  same as:<br />
1524                     : BreakLine 30 do 45 emit loop ;<br />
1526 dyninc ( handle – ) execute code in dynamic memory handle.<br />
1527                 automatically deallocates it when done.<br />
1529 include ( filenumber – ) execute code in specified file.<br />
1531 words ( – ) display existing blocks in core.<br />
1533 bye ( – ) exit from Fifth<br />
1535 fkey ( – c )<br />
1536                 Read one byte from input stream.<br />
1538 sadd ( c addr – )<br />
1539                 Add one byte "c" to string located at "addr" and updates<br />
1540                 string length.<br />
1542 scan ( c – )<br />
1543                 Read input stream and store it to pad until it finds c .<br />
1544                 It ignores all "c" bytes until it finds any non "c" byte.<br />
1545                 in other words:<br />
1546                                 c is: "<br />
1547                          input stream: """"This is test !"aoeu idh<br />
1548                                result: This is test !<br />
1550                 Is useful for breaking text lines into words.<br />
1552 skey ( – c )<br />
1553                 So called safe "fkey". Reads data from input stream<br />
1554                 but converts characters with ASCII codes: 9 13 10<br />
1555                 to spaces.<br />
1557 str=str? ( adr1 adr2 – result )<br />
1558                 Compares string at "adr1" with string at "adr2", returns<br />
1559                 true flag if they are equal or false if they are not.<br />
1560                 true = -1<br />
1561                 false = 0<br />
1563 find ( – addr )<br />
1564                 Searches whole dictionary for word in "pad". If found,<br />
1565                 returns it address, if not, returns 0.<br />
1567 execute ( – )<br />
1568                 Execute word located in "pad". Depending on "mode".<br />
1570 dta ( addr – DataAddr )<br />
1571                 Calculates address of dictionary entry data area, from<br />
1572                 entry point.<br />
1574 2num ( – num result )<br />
1575                 Attempt to convert string located in "pad" into numeric<br />
1576                 value. If succeed returns number and true as result.<br />
1577                 If not, returns whatever and false as result.<br />
1579 dadd ( addr length – )<br />
1580                 Add to dictionary data located at "addr", with specified<br />
1581                 length.<br />
1583 lit ( n – )<br />
1584                 Act with number depending on "mode". When interpreting,<br />
1585                 leaves it in stack.<br />
1588 incmod ( addr – )<br />
1589                 Add to dictionary data located at "addr"+1 , length is taken<br />
1590                 from "addr".<br />
1592 here ( – n )<br />
1593                 return "h" contents.<br />
1595 mode var 8 bit<br />
1596                 Holds input stream parser operation mode.<br />
1597                 0 = interpreting<br />
1598                 1 = compiling<br />
1600 pad var 128 bytes<br />
1601                 Holds temprorary strings.<br />
1604                 Pointer to free byte in memory, always at the end of the<br />
1605                 dictionary. Each time when something is stored<br />
1606                 by "c," command, pointer is incareased.<br />
1609                 Pointer to last dictionary word. Each time when new word is<br />
1610                 compiled or erased by "forget", this pointer is updated.<br />
1612 modulechk ( Dstr<filename> – ) check if module is loaded, if not<br />
1613                 immideately load it.<br />
1615 ne ( entrydata entrytype – ) Compile new dictionary entry.<br />
1616                 It's name must be in "pad".<br />
1620 <div id="outline-container-org20c4a54" class="outline-3">
1621 <h3 id="org20c4a54"><span class="section-number-3">12.2</span> Conditionals & control flow</h3>
1622 <div class="outline-text-3" id="text-12-2">
1624 if ( flag – ) (immideate)<br />
1625                 "if 1.. else 2.. then" or<br />
1626                 "if 1.. then" construction. Conditional execution.<br />
1627                 Performs "1.." if "flag" was true,<br />
1628                 elseway performs "2.." if exist. Execution continues after<br />
1629                 word "then".<br />
1630                 ex: 1 if ." nonzero" else ." zero" then<br />
1632 >= ( n1 n2 – result ) true if (n1 = n2) or (n1 > n2)<br />
1633                 ex: 5 3 >= if ." first number is greater or equal" then<br />
1635 <= ( n1 n2 – result ) true if (n1 = n2) or (n1 < n2)<br />
1636 = ( n1 n2 – result ) true if n1 = n2<br />
1638 do ( count – ) (immideate)<br />
1639                 "do .. loop" construction. Performs ".." "count" times.<br />
1640                 In every step "count" is decareased until it is 0.<br />
1641                 ex: : test 5 do i .d loop ;<br />
1642                 result: 4 3 2 1 0<br />
1644 doexit ( – ) exit from "do .. loop"<br />
1646 for ( count top – ) (immideate)<br />
1647                 "for .. loop" construction. Performs ".." (top - count) times.<br />
1648                 In every step "count" is incareased until it reaches "top" .<br />
1649                 ex: : test 4 10 for i .d loop ;<br />
1650                 result: 4 5 6 7 8 9<br />
1652 forexit ( – ) exit from "for .. loop"<br />
1654 until ( – ) (immideate)<br />
1655                 "until .. loop" construction. Performs ".." until flag become<br />
1656                 true. False by default. Top of return stack holds flag.<br />
1658 done ( – ) exit from "until .. loop"<br />
1663 <div id="outline-container-org94aecc7" class="outline-3">
1664 <h3 id="org94aecc7"><span class="section-number-3">12.3</span> Disk & file access</h3>
1665 <div class="outline-text-3" id="text-12-3">
1667 diskload ( FromDisk ToMem amount – )<br />
1668                 Load specified abount of bytes from disk into memory.<br />
1670 disksave ( FromMem ToDisk amount – )<br />
1671                 save specified abount of bytes from memory into disk.<br />
1673 format ( – ) Erase all files.<br />
1675 fsDfilesize@ ( handle – size )<br />
1676                 Return size of opened file.<br />
1678 fsDcurloc@ ( handle – location )<br />
1679                 Return current location in file.<br />
1681 fsDupdated@ ( handle – updated? )<br />
1682                 Return true if file was updated,<br />
1683                 ie. write operations occured.<br />
1685 fssave ( FromMem DestFileHandle amount – )<br />
1686                 Save data to file.<br />
1688 fsload ( SrcFileHandle ToMem amount – )<br />
1689                 Load data from file.<br />
1691 fseof ( handle – bytesLeft )<br />
1692                 Return amount of bytes left till end of file.<br />
1693                 Useful before read operation.<br />
1695 fsls ( – ) List all files and lists (directories,folders)<br />
1696                 in current path.<br />
1698 fslsr ( – ) Same as "fsls" but recursively scans also sub lists.<br />
1700 fscl ( DynStrHand – )<br />
1701                 Change list (path)<br />
1703 fscreate ( DynStrHand – DescPnt )<br />
1704                 Create new file or list. Can create multiple lists at once.<br />
1705                 ex: when creating:<br />
1706                     "\listGAMES\listSTRATEGY\listSIMWORLD\5th-runme"<br />
1707                 and only "\listGAMES\" already exist, then<br />
1708                 "listSTRATEGY" and "listSIMWORLD" lists will be created,<br />
1709                 and empty file "5th-runme" placed in there.<br />
1711 fsDsave ( DynHand<data> DynStrHand<filename> – )<br />
1712                 Create new file and save all data from dynamic memory<br />
1713                 block to it.<br />
1715 fsDload ( DynStr<SrcFileName> DynHand<DataDest> – )<br />
1716                 Load whole file into dynamic memory block.<br />
1718 fsDloadnew ( DynStr<SrcFileName> – DynHand<DataDest> )<br />
1719                 Load whole file into new dynamic memory block.<br />
1723 <div id="outline-container-orge7846ad" class="outline-3">
1724 <h3 id="orge7846ad"><span class="section-number-3">12.4</span> Dynamic memory</h3>
1725 <div class="outline-text-3" id="text-12-4">
1727 dynal ( size – handle )<br />
1728                 Allocate dynamic memory block and return it's handle.<br />
1730 dynde ( handle – )<br />
1731                 Deallocate dynamic memory block.<br />
1733 dynp ( handle – addr )<br />
1734                 Returns pointer to memory where dynamic block<br />
1735                 data begins.<br />
1737 dyns ( handle – size )<br />
1738                 Returns size of dynamic block.<br />
1740 dynresize ( NewSize handle – )<br />
1741                 Nondestructively resize dynamic block.<br />
1743 dync@ ( addr handle )<br />
1744                 Read one byte from dynamic block.<br />
1746 dync! ( byte addr dynhandle )<br />
1747                 Write one byte to dynamic block.<br />
1749 dyn@ ( addr handle )<br />
1750                 Read 32 bit number from dynamic block.<br />
1751                 Address will spacify, whitch number, not byte.<br />
1753 dyn! ( 32BitNum addr dynhandle )<br />
1754                 Write 32 bit number to dynamic block.<br />
1755                 Address will spacify, whitch number, not byte.<br />
1757 dyncon ( size "name" – )<br />
1758                 Allocate dynamic block with specified size, and<br />
1759                 create constant honding its handle.<br />
1760                 ex: 100 dyncon MyNewBlock<br />
1762 dyn. ( handle – )<br />
1763                 Write contenc of dynamic memory block to screen.<br />
1767 <div id="outline-container-org0749970" class="outline-3">
1768 <h3 id="org0749970"><span class="section-number-3">12.5</span> Graphics and text</h3>
1769 <div class="outline-text-3" id="text-12-5">
1771 . ( n – ) print number on screen<br />
1773 d. ( n – ) print number on screen in decimal<br />
1775 ? ( addr – ) print 32 bit value located at addr.<br />
1777 ." <string>" ( – ) print string into screen. Immideately<br />
1778                 compiles.<br />
1779                 ex: : greeting ." Hello, World" ;<br />
1781 tab. ( – ) print tabulator<br />
1783 calccol ( b g r – c ) calculate color what best matches given<br />
1784                 Blue Green & Red values. Values must be in range 0 - 255.<br />
1786 imgalloc ( xsize ysize – imgbuf ) allocate image buffer for<br />
1787                 specified size.<br />
1789 imgsize ( imgbuf – ) print on the screen X & Y size of image<br />
1790                 buffer.<br />
1792 point ( x y imgbuf – addr ) returns memory address for specified<br />
1793                 pixel.<br />
1795 pset ( color x y imgbuf – ) set graphic point<br />
1797 boxf ( x1 x2 y1 y2 imgbuf color – ) draw filled box<br />
1799 cls ( imgbuf – ) clear image buffer<br />
1801 setpal ( b g r color – ) set palette value for specified color.<br />
1802                 values bust be in size 0 - 63.<br />
1804 putchar ( char color x y imgbuf – ) put graphic character in<br />
1805                 imagebuffer to specified (x & y) location.<br />
1807 scroll ( x y imgbuf – ) scroll in imgbuf.<br />
1809 scrollf ( color x y screen – ) scroll and fill empty space with<br />
1810                 given color.<br />
1812 at! ( x y – ) set cursor location<br />
1813 curc! ( color – ) set text color<br />
1814 curb! ( solor – ) set backround color<br />
1816 colnorm ( – ) set text color to normal<br />
1817 colneg ( – ) set text color to negative (selected)<br />
1819 dyntype ( dynhandle – ) display contenc of dynamic memory on screen<br />
1820 fsdisp ( file – ) clear screen, display file, and wait for key<br />
1822 type ( addr length – )<br />
1823                 Types on the screen string, from memory at addr and<br />
1824                 specified length.<br />
1826 write ( addr – )<br />
1827                 Types on the screen string, from memory at "addr"+1<br />
1828                 length is taken from "addr" .<br />
1830 screen const 32 bit<br />
1831                 Holds handle of screen buffer.<br />
1833 copyscreen ( SrcImgHandle DestImgHandle – ) copy contenc of source<br />
1834                 image to destination image. Source and destination images<br />
1835                 must have same size.<br />
1839 <div id="outline-container-org31ff701" class="outline-3">
1840 <h3 id="org31ff701"><span class="section-number-3">12.6</span> Math, memory & stack manipulation</h3>
1841 <div class="outline-text-3" id="text-12-6">
1843 off ( n – ) writes 0 to given address, good for zeroing variable.<br />
1844                 ex: MyVariable off<br />
1845 on ( n – ) writes -1 (true flag) to given address.<br />
1846                 ex: MyVariable on<br />
1848 2dup ( n1 n2 – n1 n2 n1 n2 )<br />
1849 2drop ( n1 n2 – )<br />
1850 nip ( n1 n2 – n2 )<br />
1851 neg ( n1 – -n1 ) negotiate<br />
1852 bit@ ( n bit – result ) return specified bit from n.<br />
1853                 ex: 38 2 bit@ (result will be 1)<br />
1854 to32bit ( n1 n2 n3 n4 – n32 ) treat 4 last stack elements as bytes<br />
1855                 and unite them into 32 bit dword. Most significant byte<br />
1856                 on top.<br />
1857                 ex: 12 76 23 11 to32bit result: 186076172<br />
1859 to8bit ( n32 – n1 n2 n3 n4 ) break 32 bit number into 4 bytes.<br />
1860                 Useful if you need to send 32 bit numbers thru 8 bit COM<br />
1861                 port.<br />
1862                 ex: 186076172 to8bit result: 12 76 23 11<br />
1864 mod ( n1 n2 – reminder ) divide n1 by n2 and returns reminder.<br />
1865                 ex: 12 5 mod result: 2<br />
1867 bound ( low n high – n ) check if n is in given bounds,<br />
1868                 if not then incarease/decarease it to match bounds.<br />
1869                 ex: 5 80 15 bound result: 15<br />
1870                     5 10 15 bound result: 10<br />
1871                     5 -10 15 bound result: 5<br />
1873 bound? ( low n high – result ) returns true if n is in the<br />
1874                 given bounds.<br />
1876 tab ( col – spaces) calculate amount of spaces to add<br />
1877                 ta reach next tabulation from given column.<br />
1879 count ( addr – addr+1 n )<br />
1880                 Useful for returning bytes from constantly incareasing<br />
1881                 address. Module "type" is nice example.<br />
1883 c, ( n – )<br />
1884                 store one byte at memory specified by "h". And incarease<br />
1885                 "h" by 1.<br />
1887 , ( n – )<br />
1888                 store 32 bit number at memory specified by "h". And<br />
1889                 incarease "h" by 4.<br />
1891 cmove ( addr1 addr2 n – )<br />
1892                 copy "n" amount of bytes from memory at "addr1" to memory<br />
1893                 at "addr2".<br />
1895 rnd ( limit – result )<br />
1896                 generates random number in range 0 to "limit"-1.<br />
1898 abs ( n – |n| )<br />
1899                 returns absolute value of "n"<br />
1903 <div id="outline-container-org81063af" class="outline-3">
1904 <h3 id="org81063af"><span class="section-number-3">12.7</span> Dynamic & static strings</h3>
1905 <div class="outline-text-3" id="text-12-7">
1907 Fifth supports both static and dynamic strings. Static strings must
1908 have predefined space reserved, and string mustn't exceed this
1909 length. They manipulation is faster. But they use more memory. Static
1910 string memory address is used to refer to the string.
1914 Dynamic strings can have at any time length form 0 to 0FFh, They take
1915 up only memory they currently need. They are held in dynamic memory
1916 blocks, so dynamic block handle is used to refer to this string.
1920 Both types of strings are stored in the way, where first (0th) byte
1921 holds current string length, following bytes are string itself.
1928 Dstral ( – handle )<br />
1929                 Allocate new string.<br />
1931 Dstrlen ( handle – length )<br />
1932                 Return string length.<br />
1934 c+Dstr ( chr handle – )<br />
1935                 Add one byte to end of the string.<br />
1937 c+lDstr ( chr handle – )<br />
1938                 Add one byte to left side (beginning) of the string.<br />
1940 Dstr. ( handle – )<br />
1941                 Write contec of string into screen.<br />
1943 Dstrsure ( size Dstr – )<br />
1944                 Makes sure that at least rquested<br />
1945                 "size" (amount of characters) is allocated for given<br />
1946                 dynamic string.<br />
1948 Dstr2str ( handle address – )<br />
1949                 Copy dyamic string into static memory space.<br />
1951 str2Dstr ( address handle – )<br />
1952                 Copy static string into dyamic string.<br />
1954 Dstr+str ( Dstr addr – )<br />
1955                 Add contenc of dynamic string to static string.<br />
1957 D" any string" ( – Dstr )<br />
1958                 Moves specified string into dynamic string called "defDstr".<br />
1960 D> any_string ( – Dstr )<br />
1961                 Moves specified string into dynamic string called "defDstr".<br />
1962                 Space marks end of string!<br />
1964 D>2 any_string ( – Dstr )<br />
1965                 Moves specified string into dynamic string called "defDstr2".<br />
1966                 Space marks end of string!<br />
1968 Dstr+Dstr ( Dstr1 Dstr2 – )<br />
1969                 Adds "Dstr1" to "Dstr2" and places result into "Dstr2".<br />
1971 Dstrclear ( Dstr – )<br />
1972                 Clears contenc of dynamic string.<br />
1974 Dstr2Dstr ( Dstr1 Dstr2 – )<br />
1975                 Moves "Dstr1" to "Dstr2".<br />
1976 Dstr ( data" name – )<br />
1977                 Creates new dynamic string and moves specified data into it.<br />
1978                 Then creates new constant with given "name" holding created<br />
1979                 dynamic string handle.<br />
1981                 ex: Dstr Hello, my name is Sven!" message \ creates it<br />
1982                     message Dstr. \ tests it<br />
1984 Dstrlscan ( char Dstr – loc )<br />
1985                 Searches dynamic string for "char", from left to right,<br />
1986                 returns first found "char" location in string, or 0,<br />
1987                 if not found.<br />
1989 Dstrrscan ( char Dstr – loc )<br />
1990                 Searches dynamic string for "char", from right to left,<br />
1991                 returns first found "char" location in string, or 0,<br />
1992                 if not found.<br />
1994 Dstrlscane ( char Dstr – loc )<br />
1995                 Same as "Dstrlscan" buf returns string length+1 as location.<br />
1997 Dstrleft ( amo Dstr – )<br />
1998                 Only specified amount of characters from left remains<br />
1999                 in dynamic string. ie. cut right part out.<br />
2001 Dstrright ( amo Dstr – )<br />
2002                 Only specified amount of characters from right remains<br />
2003                 in dynamic string. ie. cut left part out.<br />
2005 Dstrcutl ( amo Dstr – )<br />
2006                 Cut specified amount of characters from left of dynamic<br />
2007                 string out.<br />
2009 Dstrsp ( char Dstr1 Dstr2 – )<br />
2010                 Separate dynamic string in Dstr1 into two parts,<br />
2011                 using "char" as separator. First part will be stored in<br />
2012                 "Dstr2", second part in "Dstr1".<br />
2013                 ex: asc \ \ ..separator<br />
2014                     D> listF\listLIB\5TH_DRVMOUSE \ ..separate from<br />
2015                     defDstr2 \ ..place result in<br />
2016                     Dstrsp \ separation command<br />
2017                     defDstr Dstr. \ will be: listLIB\5TH_DRVMOUSE<br />
2018                     defDstr2 Dstr. \ will be: listF<br />
2020 Dv ( addr – )<br />
2021                 Allocates empty dynamic string, and places it's handle<br />
2022                 into given address.<br />
2024 Df ( addr – )<br />
2025                 Reads dynamic string handle from given address and<br />
2026                 deallocates (frees) it.<br />
2028 ex: var mystring1<br />
2029         : testmodule<br />
2030         mystring1 Dv \ allocates string<br />
2032                 <whatever><br />
2034         mystring1 Df ; \ deallocates it again when no longer needed.<br />
2039 <div id="outline-container-org02f7fb3" class="outline-2">
2040 <h2 id="org02f7fb3"><span class="section-number-2">13</span> Dynamically loadable modules</h2>
2041 <div class="outline-text-2" id="text-13">
2043 <div id="outline-container-orgbae286f" class="outline-3">
2044 <h3 id="orgbae286f"><span class="section-number-3">13.1</span> Keyboard driver</h3>
2045 <div class="outline-text-3" id="text-13-1">
2048 KBD_@ ( – code ) get scancodes for pressed keys from keyboard.<br />
2049 KBD_down? ( key – result ) check is key with specified scancode<br />
2050                 currently pressed down.<br />
2051 KBD_SC2FSCII ( code – FSCII ) convert key scancode into FSCII code,<br />
2052                 or in FSK (Fifth standard keycode).<br />
2053 KBD_F@ ( – FSCII ) read pressed key FSCII or FSK, returns -1 if no<br />
2054                 keys are pressed.<br />
2055 KBD_FW@ ( – FSCII ) read pressed key FSCII or FSK, if no keys is<br />
2056                 are pressed then waits until there is.<br />
2058                 FSK<br />
2059                 —<br />
2068 401 … F1 …<br />
2082 <div id="outline-container-org3255f4e" class="outline-3">
2083 <h3 id="org3255f4e"><span class="section-number-3">13.2</span> Mouse driver</h3>
2084 <div class="outline-text-3" id="text-13-2">
2086 mousex var Mouse x coordinate.<br />
2087 mousey var Mouse y coordinate.<br />
2088 mousekeyl var Mouse left key.<br />
2089 mousekeym var Mouse middle key.<br />
2090 mousekeyr var Mouse right key.<br />
2091 mousec var Display current mouse coordinates in top left part of screen,<br />
2092                 if true. (good for debugging)<br />
2093 mousepointer var Image buffer, holding current mouse pointer.<br />
2094 mouseadd ( ModuleAddr x1 x2 y1 y2 – ) Add specified area on screen,<br />
2095                 into mause click buffer. If any mouse button is clicked on<br />
2096                 that area, module at "ModuleAddr" will be executed.<br />
2097 mousebe var Amount of buffer elements.<br />
2098 mousedo ( – ) Updates mouse coordinates and keys. Parse mouse<br />
2099                 click buffer, and draw mouse cursor to "screen".<br />
2103 <div id="outline-container-org64d1a45" class="outline-3">
2104 <h3 id="org64d1a45"><span class="section-number-3">13.3</span> 2D graphic library</h3>
2105 <div class="outline-text-3" id="text-13-3">
2107 lineh ( color len x y imgbuf – ) draws horisontal line<br />
2108                 from X,Y coordinates to right, with specified length.<br />
2109 linev ( color len x y imgbuf – ) draws vertical line<br />
2110                 down, from coordinates X,Y, with specified length.<br />
2111 box ( color x2 x1 y2 y1 imgbuf – ) draws rectangular<br />
2112                 box. x2 bust be >= x1, y2 must be >= y1.<br />
2113                         x1,y1------–—+<br />
2114                           | |<br />
2115                           | |<br />
2116                           +------–—x2,y2<br />
2118 flipv ( imgbuf – ) flip image vertically.<br />
2119 imgcoltrans ( ImgBuf Color ToColor – ) Translate all pixels in<br />
2120                 specified image with "Color" into "ToColor".<br />
2121 imgfill ( color x y imgbuf – ) Fill image region starting at location<br />
2122                 X & Y with specified color.<br />
2126 <div id="outline-container-org3bd5475" class="outline-3">
2127 <h3 id="org3bd5475"><span class="section-number-3">13.4</span> Trigonometry functions</h3>
2128 <div class="outline-text-3" id="text-13-4">
2130 <div id="outline-container-orge23e698" class="outline-4">
2131 <h4 id="orge23e698"><span class="section-number-4">13.4.1</span> sin ( a – result )</h4>
2132 <div class="outline-text-4" id="text-13-4-1">
2134 Return sinus from given angle "a", 360ø is 2000. So 1000 represents
2135 180ø angle. Result will be in range -10'000 to 10'000, instead of ñ1.
2139 <div id="outline-container-orgfa790a4" class="outline-4">
2140 <h4 id="orgfa790a4"><span class="section-number-4">13.4.2</span> cos ( a – result )</h4>
2141 <div class="outline-text-4" id="text-13-4-2">
2143 Return cosinus from given angle. Parameters are like in <a href="#orge23e698">sin</a> function.
2150 <div id="postamble" class="status">
2151 <p class="author">Author: Svjatoslav Agejenko</p>
2152 <p class="date">Created: 2021-12-21 T 20:02</p>
2153 <p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>