-
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-\f
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-\f
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-\f
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-\f
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-\f
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General
-Public License instead of this License.
+Creative Commons Legal Code
+
+CC0 1.0 Universal
+
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
+ HEREUNDER.
+
+Statement of Purpose
+
+The laws of most jurisdictions throughout the world automatically confer
+exclusive Copyright and Related Rights (defined below) upon the creator
+and subsequent owner(s) (each and all, an "owner") of an original work of
+authorship and/or a database (each, a "Work").
+
+Certain owners wish to permanently relinquish those rights to a Work for
+the purpose of contributing to a commons of creative, cultural and
+scientific works ("Commons") that the public can reliably and without fear
+of later claims of infringement build upon, modify, incorporate in other
+works, reuse and redistribute as freely as possible in any form whatsoever
+and for any purposes, including without limitation commercial purposes.
+These owners may contribute to the Commons to promote the ideal of a free
+culture and the further production of creative, cultural and scientific
+works, or to gain reputation or greater distribution for their Work in
+part through the use and efforts of others.
+
+For these and/or other purposes and motivations, and without any
+expectation of additional consideration or compensation, the person
+associating CC0 with a Work (the "Affirmer"), to the extent that he or she
+is an owner of Copyright and Related Rights in the Work, voluntarily
+elects to apply CC0 to the Work and publicly distribute the Work under its
+terms, with knowledge of his or her Copyright and Related Rights in the
+Work and the meaning and intended legal effect of CC0 on those rights.
+
+1. Copyright and Related Rights. A Work made available under CC0 may be
+protected by copyright and related or neighboring rights ("Copyright and
+Related Rights"). Copyright and Related Rights include, but are not
+limited to, the following:
+
+ i. the right to reproduce, adapt, distribute, perform, display,
+ communicate, and translate a Work;
+ ii. moral rights retained by the original author(s) and/or performer(s);
+iii. publicity and privacy rights pertaining to a person's image or
+ likeness depicted in a Work;
+ iv. rights protecting against unfair competition in regards to a Work,
+ subject to the limitations in paragraph 4(a), below;
+ v. rights protecting the extraction, dissemination, use and reuse of data
+ in a Work;
+ vi. database rights (such as those arising under Directive 96/9/EC of the
+ European Parliament and of the Council of 11 March 1996 on the legal
+ protection of databases, and under any national implementation
+ thereof, including any amended or successor version of such
+ directive); and
+vii. other similar, equivalent or corresponding rights throughout the
+ world based on applicable law or treaty, and any national
+ implementations thereof.
+
+2. Waiver. To the greatest extent permitted by, but not in contravention
+of, applicable law, Affirmer hereby overtly, fully, permanently,
+irrevocably and unconditionally waives, abandons, and surrenders all of
+Affirmer's Copyright and Related Rights and associated claims and causes
+of action, whether now known or unknown (including existing as well as
+future claims and causes of action), in the Work (i) in all territories
+worldwide, (ii) for the maximum duration provided by applicable law or
+treaty (including future time extensions), (iii) in any current or future
+medium and for any number of copies, and (iv) for any purpose whatsoever,
+including without limitation commercial, advertising or promotional
+purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
+member of the public at large and to the detriment of Affirmer's heirs and
+successors, fully intending that such Waiver shall not be subject to
+revocation, rescission, cancellation, termination, or any other legal or
+equitable action to disrupt the quiet enjoyment of the Work by the public
+as contemplated by Affirmer's express Statement of Purpose.
+
+3. Public License Fallback. Should any part of the Waiver for any reason
+be judged legally invalid or ineffective under applicable law, then the
+Waiver shall be preserved to the maximum extent permitted taking into
+account Affirmer's express Statement of Purpose. In addition, to the
+extent the Waiver is so judged Affirmer hereby grants to each affected
+person a royalty-free, non transferable, non sublicensable, non exclusive,
+irrevocable and unconditional license to exercise Affirmer's Copyright and
+Related Rights in the Work (i) in all territories worldwide, (ii) for the
+maximum duration provided by applicable law or treaty (including future
+time extensions), (iii) in any current or future medium and for any number
+of copies, and (iv) for any purpose whatsoever, including without
+limitation commercial, advertising or promotional purposes (the
+"License"). The License shall be deemed effective as of the date CC0 was
+applied by Affirmer to the Work. Should any part of the License for any
+reason be judged legally invalid or ineffective under applicable law, such
+partial invalidity or ineffectiveness shall not invalidate the remainder
+of the License, and in such case Affirmer hereby affirms that he or she
+will not (i) exercise any of his or her remaining Copyright and Related
+Rights in the Work or (ii) assert any associated claims and causes of
+action with respect to the Work, in either case contrary to Affirmer's
+express Statement of Purpose.
+
+4. Limitations and Disclaimers.
+
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
+ surrendered, licensed or otherwise affected by this document.
+ b. Affirmer offers the Work as-is and makes no representations or
+ warranties of any kind concerning the Work, express, implied,
+ statutory or otherwise, including without limitation warranties of
+ title, merchantability, fitness for a particular purpose, non
+ infringement, or the absence of latent or other defects, accuracy, or
+ the present or absence of errors, whether or not discoverable, all to
+ the greatest extent permissible under applicable law.
+ c. Affirmer disclaims responsibility for clearing rights of other persons
+ that may apply to the Work or any use thereof, including without
+ limitation any person's Copyright and Related Rights in the Work.
+ Further, Affirmer disclaims responsibility for obtaining any necessary
+ consents, permissions or other rights required for any use of the
+ Work.
+ d. Affirmer understands and acknowledges that Creative Commons is not a
+ party to this document and has no duty or obligation with respect to
+ this CC0 or use of the Work.
-<!doctype html>
-<html lang="en">
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
+<!-- 2023-09-19 Tue 18:07 -->
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Fifth - virtual machine, operating system, programming language</title>
-<!-- 2018-07-01 Sun 23:59 -->
-<meta charset="utf-8">
-<meta name="viewport" content="width=device-width, initial-scale=1">
-<meta name="generator" content="Org-mode">
-<meta name="author" content="Svjatoslav Agejenko">
-<link href="https://bootswatch.com/3/darkly/bootstrap.min.css" rel="stylesheet">
-<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
-<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
-<style type="text/css">
-footer {background-color: #111 !important;}
-pre {background-color: #111; color: #ccc;}
-</style>
-<style type="text/css">
-/* org mode styles on top of twbs */
-
-html {
+<meta name="author" content="Svjatoslav Agejenko" />
+<meta name="generator" content="Org Mode" />
+<style>
+ #content { max-width: 60em; margin: auto; }
+ .title { text-align: center;
+ margin-bottom: .2em; }
+ .subtitle { text-align: center;
+ font-size: medium;
+ font-weight: bold;
+ margin-top:0; }
+ .todo { font-family: monospace; color: red; }
+ .done { font-family: monospace; color: green; }
+ .priority { font-family: monospace; color: orange; }
+ .tag { background-color: #eee; font-family: monospace;
+ padding: 2px; font-size: 80%; font-weight: normal; }
+ .timestamp { color: #bebebe; }
+ .timestamp-kwd { color: #5f9ea0; }
+ .org-right { margin-left: auto; margin-right: 0px; text-align: right; }
+ .org-left { margin-left: 0px; margin-right: auto; text-align: left; }
+ .org-center { margin-left: auto; margin-right: auto; text-align: center; }
+ .underline { text-decoration: underline; }
+ #postamble p, #preamble p { font-size: 90%; margin: .2em; }
+ p.verse { margin-left: 3%; }
+ pre {
+ border: 1px solid #e6e6e6;
+ border-radius: 3px;
+ background-color: #f2f2f2;
+ padding: 8pt;
+ font-family: monospace;
+ overflow: auto;
+ margin: 1.2em;
+ }
+ pre.src {
position: relative;
- min-height: 100%;
-}
-
-body {
- font-size: 18px;
- margin-bottom: 105px;
-}
-
-footer {
+ overflow: auto;
+ }
+ pre.src:before {
+ display: none;
position: absolute;
- bottom: 0;
+ top: -8px;
+ right: 12px;
+ padding: 3px;
+ color: #555;
+ background-color: #f2f2f299;
+ }
+ pre.src:hover:before { display: inline; margin-top: 14px;}
+ /* Languages per Org manual */
+ pre.src-asymptote:before { content: 'Asymptote'; }
+ pre.src-awk:before { content: 'Awk'; }
+ pre.src-authinfo::before { content: 'Authinfo'; }
+ pre.src-C:before { content: 'C'; }
+ /* pre.src-C++ doesn't work in CSS */
+ pre.src-clojure:before { content: 'Clojure'; }
+ pre.src-css:before { content: 'CSS'; }
+ pre.src-D:before { content: 'D'; }
+ pre.src-ditaa:before { content: 'ditaa'; }
+ pre.src-dot:before { content: 'Graphviz'; }
+ pre.src-calc:before { content: 'Emacs Calc'; }
+ pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
+ pre.src-fortran:before { content: 'Fortran'; }
+ pre.src-gnuplot:before { content: 'gnuplot'; }
+ pre.src-haskell:before { content: 'Haskell'; }
+ pre.src-hledger:before { content: 'hledger'; }
+ pre.src-java:before { content: 'Java'; }
+ pre.src-js:before { content: 'Javascript'; }
+ pre.src-latex:before { content: 'LaTeX'; }
+ pre.src-ledger:before { content: 'Ledger'; }
+ pre.src-lisp:before { content: 'Lisp'; }
+ pre.src-lilypond:before { content: 'Lilypond'; }
+ pre.src-lua:before { content: 'Lua'; }
+ pre.src-matlab:before { content: 'MATLAB'; }
+ pre.src-mscgen:before { content: 'Mscgen'; }
+ pre.src-ocaml:before { content: 'Objective Caml'; }
+ pre.src-octave:before { content: 'Octave'; }
+ pre.src-org:before { content: 'Org mode'; }
+ pre.src-oz:before { content: 'OZ'; }
+ pre.src-plantuml:before { content: 'Plantuml'; }
+ pre.src-processing:before { content: 'Processing.js'; }
+ pre.src-python:before { content: 'Python'; }
+ pre.src-R:before { content: 'R'; }
+ pre.src-ruby:before { content: 'Ruby'; }
+ pre.src-sass:before { content: 'Sass'; }
+ pre.src-scheme:before { content: 'Scheme'; }
+ pre.src-screen:before { content: 'Gnu Screen'; }
+ pre.src-sed:before { content: 'Sed'; }
+ pre.src-sh:before { content: 'shell'; }
+ pre.src-sql:before { content: 'SQL'; }
+ pre.src-sqlite:before { content: 'SQLite'; }
+ /* additional languages in org.el's org-babel-load-languages alist */
+ pre.src-forth:before { content: 'Forth'; }
+ pre.src-io:before { content: 'IO'; }
+ pre.src-J:before { content: 'J'; }
+ pre.src-makefile:before { content: 'Makefile'; }
+ pre.src-maxima:before { content: 'Maxima'; }
+ pre.src-perl:before { content: 'Perl'; }
+ pre.src-picolisp:before { content: 'Pico Lisp'; }
+ pre.src-scala:before { content: 'Scala'; }
+ pre.src-shell:before { content: 'Shell Script'; }
+ pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
+ /* additional language identifiers per "defun org-babel-execute"
+ in ob-*.el */
+ pre.src-cpp:before { content: 'C++'; }
+ pre.src-abc:before { content: 'ABC'; }
+ pre.src-coq:before { content: 'Coq'; }
+ pre.src-groovy:before { content: 'Groovy'; }
+ /* additional language identifiers from org-babel-shell-names in
+ ob-shell.el: ob-shell is the only babel language using a lambda to put
+ the execution function name together. */
+ pre.src-bash:before { content: 'bash'; }
+ pre.src-csh:before { content: 'csh'; }
+ pre.src-ash:before { content: 'ash'; }
+ pre.src-dash:before { content: 'dash'; }
+ pre.src-ksh:before { content: 'ksh'; }
+ pre.src-mksh:before { content: 'mksh'; }
+ pre.src-posh:before { content: 'posh'; }
+ /* Additional Emacs modes also supported by the LaTeX listings package */
+ pre.src-ada:before { content: 'Ada'; }
+ pre.src-asm:before { content: 'Assembler'; }
+ pre.src-caml:before { content: 'Caml'; }
+ pre.src-delphi:before { content: 'Delphi'; }
+ pre.src-html:before { content: 'HTML'; }
+ pre.src-idl:before { content: 'IDL'; }
+ pre.src-mercury:before { content: 'Mercury'; }
+ pre.src-metapost:before { content: 'MetaPost'; }
+ pre.src-modula-2:before { content: 'Modula-2'; }
+ pre.src-pascal:before { content: 'Pascal'; }
+ pre.src-ps:before { content: 'PostScript'; }
+ pre.src-prolog:before { content: 'Prolog'; }
+ pre.src-simula:before { content: 'Simula'; }
+ pre.src-tcl:before { content: 'tcl'; }
+ pre.src-tex:before { content: 'TeX'; }
+ pre.src-plain-tex:before { content: 'Plain TeX'; }
+ pre.src-verilog:before { content: 'Verilog'; }
+ pre.src-vhdl:before { content: 'VHDL'; }
+ pre.src-xml:before { content: 'XML'; }
+ pre.src-nxml:before { content: 'XML'; }
+ /* add a generic configuration mode; LaTeX export needs an additional
+ (add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
+ pre.src-conf:before { content: 'Configuration File'; }
+
+ table { border-collapse:collapse; }
+ caption.t-above { caption-side: top; }
+ caption.t-bottom { caption-side: bottom; }
+ td, th { vertical-align:top; }
+ th.org-right { text-align: center; }
+ th.org-left { text-align: center; }
+ th.org-center { text-align: center; }
+ td.org-right { text-align: right; }
+ td.org-left { text-align: left; }
+ td.org-center { text-align: center; }
+ dt { font-weight: bold; }
+ .footpara { display: inline; }
+ .footdef { margin-bottom: 1em; }
+ .figure { padding: 1em; }
+ .figure p { text-align: center; }
+ .equation-container {
+ display: table;
+ text-align: center;
width: 100%;
- height: 101px;
- background-color: #f5f5f5;
-}
-
-footer > div {
+ }
+ .equation {
+ vertical-align: middle;
+ }
+ .equation-label {
+ display: table-cell;
+ text-align: right;
+ vertical-align: middle;
+ }
+ .inlinetask {
padding: 10px;
-}
-
-footer p {
- margin: 0 0 5px;
- text-align: center;
- font-size: 16px;
-}
-
-#table-of-contents {
- margin-top: 20px;
- margin-bottom: 20px;
-}
-
-blockquote p {
- font-size: 18px;
-}
-
-pre {
- font-size: 16px;
-}
-
-.footpara {
- display: inline-block;
-}
-
-figcaption {
- font-size: 16px;
- color: #666;
- font-style: italic;
- padding-bottom: 15px;
-}
-
-/* from twbs docs */
-
-.bs-docs-sidebar.affix {
- position: static;
-}
-@media (min-width: 768px) {
- .bs-docs-sidebar {
- padding-left: 20px;
- }
-}
-
-/* All levels of nav */
-.bs-docs-sidebar .nav > li > a {
- display: block;
- padding: 4px 20px;
- font-size: 14px;
- font-weight: 500;
- color: #999;
-}
-.bs-docs-sidebar .nav > li > a:hover,
-.bs-docs-sidebar .nav > li > a:focus {
- padding-left: 19px;
- color: #A1283B;
- text-decoration: none;
- background-color: transparent;
- border-left: 1px solid #A1283B;
-}
-.bs-docs-sidebar .nav > .active > a,
-.bs-docs-sidebar .nav > .active:hover > a,
-.bs-docs-sidebar .nav > .active:focus > a {
- padding-left: 18px;
- font-weight: bold;
- color: #A1283B;
- background-color: transparent;
- border-left: 2px solid #A1283B;
-}
-
-/* Nav: second level (shown on .active) */
-.bs-docs-sidebar .nav .nav {
- display: none; /* Hide by default, but at >768px, show it */
- padding-bottom: 10px;
-}
-.bs-docs-sidebar .nav .nav > li > a {
- padding-top: 1px;
- padding-bottom: 1px;
- padding-left: 30px;
- font-size: 12px;
- font-weight: normal;
-}
-.bs-docs-sidebar .nav .nav > li > a:hover,
-.bs-docs-sidebar .nav .nav > li > a:focus {
- padding-left: 29px;
-}
-.bs-docs-sidebar .nav .nav > .active > a,
-.bs-docs-sidebar .nav .nav > .active:hover > a,
-.bs-docs-sidebar .nav .nav > .active:focus > a {
- padding-left: 28px;
- font-weight: 500;
-}
-
-/* Nav: third level (shown on .active) */
-.bs-docs-sidebar .nav .nav .nav {
- padding-bottom: 10px;
-}
-.bs-docs-sidebar .nav .nav .nav > li > a {
- padding-top: 1px;
- padding-bottom: 1px;
- padding-left: 40px;
- font-size: 12px;
- font-weight: normal;
-}
-.bs-docs-sidebar .nav .nav .nav > li > a:hover,
-.bs-docs-sidebar .nav .nav .nav > li > a:focus {
- padding-left: 39px;
-}
-.bs-docs-sidebar .nav .nav .nav > .active > a,
-.bs-docs-sidebar .nav .nav .nav > .active:hover > a,
-.bs-docs-sidebar .nav .nav .nav > .active:focus > a {
- padding-left: 38px;
- font-weight: 500;
-}
-
-/* Show and affix the side nav when space allows it */
-@media (min-width: 992px) {
- .bs-docs-sidebar .nav > .active > ul {
- display: block;
- }
- /* Widen the fixed sidebar */
- .bs-docs-sidebar.affix,
- .bs-docs-sidebar.affix-bottom {
- width: 213px;
- }
- .bs-docs-sidebar.affix {
- position: fixed; /* Undo the static from mobile first approach */
- top: 20px;
- }
- .bs-docs-sidebar.affix-bottom {
- position: absolute; /* Undo the static from mobile first approach */
- }
- .bs-docs-sidebar.affix .bs-docs-sidenav,.bs-docs-sidebar.affix-bottom .bs-docs-sidenav {
- margin-top: 0;
- margin-bottom: 0
- }
-}
-@media (min-width: 1200px) {
- /* Widen the fixed sidebar again */
- .bs-docs-sidebar.affix-bottom,
- .bs-docs-sidebar.affix {
- width: 263px;
- }
-}
-</style>
-<script type="text/javascript">
-$(function() {
- 'use strict';
-
- $('.bs-docs-sidebar li').first().addClass('active');
-
- $(document.body).scrollspy({target: '.bs-docs-sidebar'});
-
- $('.bs-docs-sidebar').affix();
-});
-</script>
-
-<script type="text/x-mathjax-config">
-MathJax.Hub.Config({
- displayAlign: "center",
- displayIndent: "2em",
- messageStyle: "none",
- "HTML-CSS": {
- scale: 100,
- styles: {
- ".MathJax_Display": {
- "font-size": "100%"
- }
- }
- },
- "SVG": {
- scale: 100,
- styles: {
- ".MathJax_SVG_Display": {
- "font-size": "100%",
- "margin-left": "-2.281em"
- }
- }
+ border: 2px solid gray;
+ margin: 10px;
+ background: #ffffcc;
}
-});
-</script>
-<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_SVG"></script>
+ #org-div-home-and-up
+ { text-align: right; font-size: 70%; white-space: nowrap; }
+ textarea { overflow-x: auto; }
+ .linenr { font-size: smaller }
+ .code-highlighted { background-color: #ffff00; }
+ .org-info-js_info-navigation { border-style: none; }
+ #org-info-js_console-label
+ { font-size: 10px; font-weight: bold; white-space: nowrap; }
+ .org-info-js_search-highlight
+ { background-color: #ffff00; color: #000000; font-weight: bold; }
+ .org-svg { }
+</style>
+<link rel="stylesheet" type="text/css" href="https://thomasf.github.io/solarized-css/solarized-dark.min.css" />
</head>
<body>
-<div id="content" class="container">
-<div class="row"><div class="col-md-9"><h1 class="title">Fifth - virtual machine, operating system, programming language</h1>
-<div id="outline-container-sec-1" class="outline-2">
-<h2 id="sec-1"><span class="section-number-2">1</span> General</h2>
-<div class="outline-text-2" id="text-1">
-<ul class="org-ul">
-<li>This program is free software: you can redistribute it and/or modify
-it under the terms of the <a href="https://www.gnu.org/licenses/lgpl.html">GNU Lesser General Public License</a> as
-published by the Free Software Foundation, either version 3 of the
-License, or (at your option) any later version.
+<div id="content" class="content">
+<h1 class="title">Fifth - virtual machine, operating system, programming language</h1>
+<div id="table-of-contents" role="doc-toc">
+<h2>Table of Contents</h2>
+<div id="text-table-of-contents" role="doc-toc">
+<ul>
+<li><a href="#orgdd8d5a0">1. General</a>
+<ul>
+<li><a href="#org11b4b95">1.1. Source code</a></li>
+</ul>
</li>
-
-<li>Program author:
-<ul class="org-ul">
-<li>Svjatoslav Agejenko
+<li><a href="#org0a3946b">2. !Project deprecated!</a></li>
+<li><a href="#org74c9861">3. Introduction</a>
+<ul>
+<li><a href="#orge8b459e">3.1. Screenshots</a></li>
+</ul>
</li>
-<li>Homepage: <a href="http://svjatoslav.eu">http://svjatoslav.eu</a>
+<li><a href="#orga9dfaee">4. Installation</a></li>
+<li><a href="#orgefa2f79">5. Fifth distribution directory tree description</a></li>
+<li><a href="#org751040b">6. Requirements</a>
+<ul>
+<li><a href="#org32f0917">6.1. Software</a></li>
+<li><a href="#orgd6ecfe1">6.2. Hardware</a></li>
+</ul>
</li>
-<li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a>
+<li><a href="#orgeb3cbc2">7. Numbers representation within Fifth</a></li>
+<li><a href="#orga8a8f37">8. Disk file map, and it's data structures</a>
+<ul>
+<li><a href="#org4eb67fc">8.1. Disk allocation</a></li>
+<li><a href="#org5fcae51">8.2. FAT entry format:</a></li>
+<li><a href="#org811dc5b">8.3. File entry format</a></li>
+</ul>
</li>
+<li><a href="#orga49dca9">9. Core architecture</a>
+<ul>
+<li><a href="#org75e80d5">9.1. Dictionary entry format</a></li>
+<li><a href="#org12381ef">9.2. Possible module types</a></li>
+<li><a href="#org33be039">9.3. Memory map</a></li>
</ul>
</li>
-
-<li><a href="http://www.svjatoslav.eu/projects/">Other software projects hosted at svjatoslav.eu</a>
+<li><a href="#org81fd544">10. Dynamically loadable modules</a>
+<ul>
+<li><a href="#org79d1c84">10.1. Keyboard driver</a></li>
+<li><a href="#org99b4378">10.2. Mouse driver</a></li>
+<li><a href="#org0aa9e1f">10.3. 2D graphic library</a></li>
+<li><a href="#orgff6cdef">10.4. Trigonometry functions</a>
+<ul>
+<li><a href="#org868f7c6">10.4.1. sin ( a – result )</a></li>
+<li><a href="#orgc3f161e">10.4.2. cos ( a – result )</a></li>
+</ul>
</li>
</ul>
+</li>
+</ul>
+</div>
</div>
-<div id="outline-container-sec-1-1" class="outline-3">
-<h3 id="sec-1-1"><span class="section-number-3">1.1</span> Source code</h3>
+<div id="outline-container-orgdd8d5a0" class="outline-2">
+<h2 id="orgdd8d5a0"><span class="section-number-2">1.</span> General</h2>
+<div class="outline-text-2" id="text-1">
+<ul class="org-ul">
+<li>This program is free software: released under Creative Commons Zero
+(CC0) license</li>
+
+<li>Program author:
+<ul class="org-ul">
+<li>Svjatoslav Agejenko</li>
+<li>Homepage: <a href="https://svjatoslav.eu">https://svjatoslav.eu</a></li>
+<li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a></li>
+</ul></li>
+
+<li><a href="https://www.svjatoslav.eu/projects/">Other software projects hosted at svjatoslav.eu</a></li>
+</ul>
+</div>
+
+<div id="outline-container-org11b4b95" class="outline-3">
+<h3 id="org11b4b95"><span class="section-number-3">1.1.</span> Source code</h3>
<div class="outline-text-3" id="text-1-1">
<ul class="org-ul">
-<li><a href="http://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=snapshot;h=HEAD;sf=tgz">Download latest snapshot in TAR GZ format</a>
-</li>
+<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>
-<li><a href="http://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=summary">Browse Git repository online</a>
-</li>
+<li><a href="https://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=summary">Browse Git repository online</a></li>
-<li>Clone Git repository using command:
+<li><p>
+Clone Git repository using command:
+</p>
<pre class="example">
-git clone http://www2.svjatoslav.eu/git/fifth.git
-</pre>
-</li>
+git clone https://www2.svjatoslav.eu/git/fifth.git
+</pre></li>
</ul>
</div>
</div>
</div>
-<div id="outline-container-sec-2" class="outline-2">
-<h2 id="sec-2"><span class="section-number-2">2</span> Warning</h2>
+<div id="outline-container-org0a3946b" class="outline-2">
+<h2 id="org0a3946b"><span class="section-number-2">2.</span> !Project deprecated!</h2>
<div class="outline-text-2" id="text-2">
<p>
Current implementation does not support object oriented
<p>
Currently I try to implement those new ideas in the project called
-<a href="http://www3.svjatoslav.eu/projects/sixth/">Sixth</a>
+<a href="https://www3.svjatoslav.eu/projects/sixth/">Sixth</a>.
</p>
<p>
System is built many years ago when I was still using DOS as a primary
-operating system and not updated since.
+operating system.
</p>
</div>
</div>
-<div id="outline-container-sec-3" class="outline-2">
-<h2 id="sec-3"><span class="section-number-2">3</span> Introduction</h2>
+<div id="outline-container-org74c9861" class="outline-2">
+<h2 id="org74c9861"><span class="section-number-2">3.</span> Introduction</h2>
<div class="outline-text-2" id="text-3">
<p>
-Fifth is programming lanquage & operating system, running on <i>virtual
-CPU</i>, with custom instruction set. It is much like Charles Chunk
-Moore's Forth, it also uses stack architecture, and many commands are
-similar. Basically I got familiar with concepts of Forth, and being
-inspired created my own system.
+Fifth is a combination of:
</p>
-
<ul class="org-ul">
-<li><a href="5TH_ET.txt">Example Fifth source file - text editor</a>
-</li>
+<li><a href="language.html#ID-da7fff9b-0b67-4843-828a-52a404d7f401">Programming language</a> (inspired by Forth).</li>
+<li>Operating system.</li>
+<li><a href="virtual machine.html#ID-9b251eb9-aff6-4025-94bf-25e89e26d54a">Virtual machine</a> with custom instruction set.</li>
</ul>
</div>
-<div id="outline-container-sec-3-1" class="outline-3">
-<h3 id="sec-3-1"><span class="section-number-3">3.1</span> screenshots</h3>
+
+<div id="outline-container-orge8b459e" class="outline-3">
+<h3 id="orge8b459e"><span class="section-number-3">3.1.</span> Screenshots</h3>
<div class="outline-text-3" id="text-3-1">
-<ul class="org-ul">
-<li><img src="screenshots/start.png" class="img-responsive" alt="start.png">
-<ul class="org-ul">
-<li>Startup screen diplaying Fifth logo and full file list.
-</li>
-</ul>
-</li>
-<li><img src="screenshots/dictionary.png" class="img-responsive" alt="dictionary.png">
-<ul class="org-ul">
-<li>Sample words defined. Most of the words are commands that can be
-executed interactively from command line or from file. When
-executed they can be selectively compiled or interpreted.
-</li>
-</ul>
-</li>
+<div id="org76cf04c" class="figure">
+<p><img src="screenshots/start.png" alt="start.png" />
+</p>
+</div>
-<li><img src="screenshots/text editor.png" class="img-responsive" alt="text editor.png">
-<ul class="org-ul">
-<li>Built in text editor.
-</li>
-</ul>
-</li>
-</ul>
+<p>
+Startup screen diplaying Fifth logo and full file list.
+</p>
+
+
+<div id="org7579242" class="figure">
+<p><img src="screenshots/dictionary.png" alt="dictionary.png" />
+</p>
+</div>
+
+<p>
+Sample words defined. Most of the words are commands that can be
+executed interactively from the command line or from a file. When
+executed, they can be selectively compiled or interpreted.
+</p>
+
+
+
+<div id="org17f3e64" class="figure">
+<p><img src="screenshots/text editor.png" alt="text editor.png" />
+</p>
+</div>
+
+<p>
+Built in text editor.
+</p>
</div>
</div>
</div>
-<div id="outline-container-sec-4" class="outline-2">
-<h2 id="sec-4"><span class="section-number-2">4</span> Installation</h2>
+<div id="outline-container-orga9dfaee" class="outline-2">
+<h2 id="orga9dfaee"><span class="section-number-2">4.</span> Installation</h2>
<div class="outline-text-2" id="text-4">
<p>
Just unpack all files, witout altering original directory structure,
somewhere in your hard disk. For example:
</p>
+
<pre class="example">
-C:\MISC\FIFTH\....
+C:\MISC\FIFTH\
</pre>
+
+
<p>
-To run fifth you need minimally just 2 files. emulator itself (
-EMULATOR.EXE or EMULATOR.COM ), and virtual disk file ( DISK.RAW ).
+To run fifth you need minimally just 2 files:
</p>
+<dl class="org-dl">
+<dt>EMULATOR.COM</dt><dd>Virtual CPU emulator</dd>
+<dt>DISK.RAW</dt><dd>Virtual disk file</dd>
+</dl>
<p>
-Read more about <i>distribution directory layout</i>
+For more information, please refer to <a href="#orgefa2f79">Fifth distribution directory
+tree description</a>.
</p>
</div>
</div>
-<div id="outline-container-sec-5" class="outline-2">
-<h2 id="sec-5"><span class="section-number-2">5</span> Fifth distribution directory tree description</h2>
+
+<div id="outline-container-orgefa2f79" class="outline-2">
+<h2 id="orgefa2f79"><span class="section-number-2">5.</span> Fifth distribution directory tree description</h2>
<div class="outline-text-2" id="text-5">
<p>
After downloading and unpacking the ZIP file you shoud get directory
</p>
<p class="verse">
-[DOC] - Fifth documentation<br >
-  [commands] - documentation on Fifth built-in commands<br >
-  [modules] - documentation on additional commands, realized as loadable modules<br >
-  [shots] - Fifth screenshots<br >
-<br >
-[imageFile] - files contained within 'disk.raw', just an extracted form.<br >
-<br >
-[source] - source files<br >
-  [emulator] - emulator source<br >
-  [util] - utilites<br >
-<br >
-disk.raw - Virtual disk file, has filesystem inside.<br >
-emulator.com - main executable.<br >
+<b>DOC</b> - Fifth documentation<br />
+  <b>commands</b> - documentation on Fifth built-in commands<br />
+  <b>modules</b> - documentation on additional commands, realized as loadable modules<br />
+  <b>shots</b> - Fifth screenshots<br />
+<br />
+<b>imageFile</b> - files contained within 'disk.raw', just an extracted form.<br />
+<br />
+<b>source</b> - source files<br />
+  <b>emulator</b> - emulator source<br />
+  <b>util</b> - utilites<br />
+<br />
+<b>disk.raw</b> - Virtual disk file, has filesystem inside.<br />
+<b>emulator.com</b> - main executable.<br />
</p>
</div>
</div>
-<div id="outline-container-sec-6" class="outline-2">
-<h2 id="sec-6"><span class="section-number-2">6</span> Software/Hardware/Human requirements</h2>
+<div id="outline-container-org751040b" class="outline-2">
+<h2 id="org751040b"><span class="section-number-2">6.</span> Requirements</h2>
<div class="outline-text-2" id="text-6">
-</div><div id="outline-container-sec-6-1" class="outline-3">
-<h3 id="sec-6-1"><span class="section-number-3">6.1</span> Software</h3>
+</div>
+<div id="outline-container-org32f0917" class="outline-3">
+<h3 id="org32f0917"><span class="section-number-3">6.1.</span> Software</h3>
<div class="outline-text-3" id="text-6-1">
<ul class="org-ul">
-<li>MS-DOS 6.22, with HIMEM.SYS loaded.
-</li>
-<li>Mouse driver if you have a mouse.
-</li>
-<li>Does work only when CPU is in real mode.
-</li>
-<li>To recompile ASM sources I used FASM (Flat Assembler).
-</li>
-<li>I ran QBasic utilities on QB 4.5 .
-</li>
-<li>VESA support by BIOS, or external driver (UNIVBE).
-</li>
+<li>MS-DOS 6.22 with HIMEM.SYS loaded.</li>
+<li>Mouse driver (optional, if you have a mouse).</li>
+<li>CPU is initialized into <a href="https://en.wikipedia.org/wiki/Unreal_mode">Unreal Mode</a> during operation.</li>
+<li>To recompile ASM sources, you can use FASM (Flat Assembler).</li>
+<li>To run Quick Basic utilities, use Microsoft Quick Basic 4.5.</li>
+<li>VESA support through BIOS or external driver (UNIVBE).</li>
</ul>
</div>
</div>
-<div id="outline-container-sec-6-2" class="outline-3">
-<h3 id="sec-6-2"><span class="section-number-3">6.2</span> Hardware</h3>
+
+<div id="outline-container-orgd6ecfe1" class="outline-3">
+<h3 id="orgd6ecfe1"><span class="section-number-3">6.2.</span> Hardware</h3>
<div class="outline-text-3" id="text-6-2">
<ul class="org-ul">
-<li>Minimum CPU 386.
-</li>
-<li>64 KB free RAM below 640KB,
-</li>
-<li>2 MB of free XMS.
-</li>
-<li>VESA compatible video card.
-</li>
+<li>A minimum of a i386 CPU.</li>
+<li>64 KB of free RAM below 640KB.</li>
+<li>2 MB of free <a href="https://en.wikipedia.org/wiki/Extended_memory">extended memory</a>.</li>
+<li>A VESA-compatible video card.</li>
</ul>
</div>
</div>
-<div id="outline-container-sec-6-3" class="outline-3">
-<h3 id="sec-6-3"><span class="section-number-3">6.3</span> Human</h3>
-<div class="outline-text-3" id="text-6-3">
-<ul class="org-ul">
-<li>Beginner level Forth knowledge is recommended.
-</li>
-<li>Lots of enthusiasm.
-</li>
-</ul>
</div>
-</div>
-</div>
-<div id="outline-container-sec-7" class="outline-2">
-<h2 id="sec-7"><span class="section-number-2">7</span> Numbers representation within Fifth</h2>
+
+<div id="outline-container-orgeb3cbc2" class="outline-2">
+<h2 id="orgeb3cbc2"><span class="section-number-2">7.</span> Numbers representation within Fifth</h2>
<div class="outline-text-2" id="text-7">
+<p>
+Because we are in full experimentation mode here (no regard for
+compatibility whatsoever), why not to try also alternative number
+representation ?
+</p>
+
+<p>
+Here alternative hexadecimal number representation format is devised:
+</p>
+
+
+<div id="org67795e4" class="figure">
+<p><a href="numbers.png"><img src="numbers.png" alt="numbers.png" /></a>
+</p>
+</div>
-<figure>
-<p><a href="numbers.png"><img src="numbers.png" class="img-responsive" alt="numbers.png"></a>
+<p>
+Essentially square is split into 4 triangles. Each triangle represents
+one bit.
</p>
-</figure>
<p>
-Because I can define everything, starting from CPU, why not try also
-alternative and unique number representation ?
+Fifth uses this hexadecimal format as primary throughout entire
+system.
</p>
<p>
-Fifth uses its hexdecimal number representation as primary. Numbers
-shape is formed by dividing a square into four parts. And manipulating
-their color (black or white).
+See also: <a href="https://en.wikipedia.org/wiki/Bibi-binary">Bibi-binary</a>.
</p>
</div>
</div>
-<div id="outline-container-sec-8" class="outline-2">
-<h2 id="sec-8"><span class="section-number-2">8</span> Disk file map, and it's data structures</h2>
+
+<div id="outline-container-orga8a8f37" class="outline-2">
+<h2 id="orga8a8f37"><span class="section-number-2">8.</span> Disk file map, and it's data structures</h2>
<div class="outline-text-2" id="text-8">
<p>
Core and high-level boot code is stored outside of the filesystem to
yet initialized.
</p>
</div>
-<div id="outline-container-sec-8-1" class="outline-3">
-<h3 id="sec-8-1"><span class="section-number-3">8.1</span> disk allocation</h3>
+<div id="outline-container-org4eb67fc" class="outline-3">
+<h3 id="org4eb67fc"><span class="section-number-3">8.1.</span> Disk allocation</h3>
<div class="outline-text-3" id="text-8-1">
-<table class="table table-striped table-bordered table-hover table-condensed">
+<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
-<col class="left">
+<col class="org-left" />
-<col class="left">
+<col class="org-left" />
-<col class="left">
+<col class="org-left" />
</colgroup>
<thead>
<tr>
-<th scope="col" class="text-left">offset</th>
-<th scope="col" class="text-left">length</th>
-<th scope="col" class="text-left">description</th>
+<th scope="col" class="org-left">offset</th>
+<th scope="col" class="org-left">length</th>
+<th scope="col" class="org-left">description</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="text-left">0</td>
-<td class="text-left">~4 Kb</td>
-<td class="text-left">Fifth core</td>
+<td class="org-left">0</td>
+<td class="org-left">~4 Kb</td>
+<td class="org-left">Fifth core</td>
</tr>
<tr>
-<td class="text-left">4 Kb</td>
-<td class="text-left">~32Kb</td>
-<td class="text-left">high-level boot code</td>
+<td class="org-left">4 Kb</td>
+<td class="org-left">~32 Kb</td>
+<td class="org-left">high-level boot code</td>
</tr>
<tr>
-<td class="text-left">37 Kb</td>
-<td class="text-left">~65Kb</td>
-<td class="text-left">FAT</td>
+<td class="org-left">37 Kb</td>
+<td class="org-left">~65 Kb</td>
+<td class="org-left">FAT</td>
</tr>
<tr>
-<td class="text-left">101Kb</td>
-<td class="text-left">~16MB</td>
-<td class="text-left">filesystem data area</td>
+<td class="org-left">101 Kb</td>
+<td class="org-left">~16 MB</td>
+<td class="org-left">filesystem data area</td>
</tr>
</tbody>
</table>
</div>
</div>
-<div id="outline-container-sec-8-2" class="outline-3">
-<h3 id="sec-8-2"><span class="section-number-3">8.2</span> FAT entry format:</h3>
+<div id="outline-container-org5fcae51" class="outline-3">
+<h3 id="org5fcae51"><span class="section-number-3">8.2.</span> FAT entry format:</h3>
<div class="outline-text-3" id="text-8-2">
-<table class="table table-striped table-bordered table-hover table-condensed">
+<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
-<col class="right">
+<col class="org-right" />
-<col class="left">
+<col class="org-left" />
</colgroup>
<thead>
<tr>
-<th scope="col" class="text-right">code</th>
-<th scope="col" class="text-left">meaning</th>
+<th scope="col" class="org-right">code</th>
+<th scope="col" class="org-left">meaning</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="text-right">-2</td>
-<td class="text-left">last sector</td>
+<td class="org-right">-2</td>
+<td class="org-left">last sector</td>
</tr>
<tr>
-<td class="text-right">-1</td>
-<td class="text-left">empty sector</td>
+<td class="org-right">-1</td>
+<td class="org-left">empty sector</td>
</tr>
<tr>
-<td class="text-right">0 --</td>
-<td class="text-left">.. pointer to next block</td>
+<td class="org-right">0 --</td>
+<td class="org-left">.. pointer to next block</td>
</tr>
</tbody>
</table>
</div>
</div>
-<div id="outline-container-sec-8-3" class="outline-3">
-<h3 id="sec-8-3"><span class="section-number-3">8.3</span> file entry format</h3>
+<div id="outline-container-org811dc5b" class="outline-3">
+<h3 id="org811dc5b"><span class="section-number-3">8.3.</span> File entry format</h3>
<div class="outline-text-3" id="text-8-3">
-<table class="table table-striped table-bordered table-hover table-condensed">
+<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
-<col class="right">
+<col class="org-right" />
-<col class="right">
+<col class="org-right" />
-<col class="left">
+<col class="org-left" />
</colgroup>
<thead>
<tr>
-<th scope="col" class="text-right">offset</th>
-<th scope="col" class="text-right">length</th>
-<th scope="col" class="text-left">description</th>
+<th scope="col" class="org-right">offset</th>
+<th scope="col" class="org-right">length</th>
+<th scope="col" class="org-left">description</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="text-right">0</td>
-<td class="text-right">4</td>
-<td class="text-left">extension</td>
+<td class="org-right">0</td>
+<td class="org-right">4</td>
+<td class="org-left">extension</td>
</tr>
<tr>
-<td class="text-right">4</td>
-<td class="text-right">16</td>
-<td class="text-left">name</td>
+<td class="org-right">4</td>
+<td class="org-right">16</td>
+<td class="org-left">name</td>
</tr>
<tr>
-<td class="text-right">20</td>
-<td class="text-right">4</td>
-<td class="text-left">entry point</td>
+<td class="org-right">20</td>
+<td class="org-right">4</td>
+<td class="org-left">entry point</td>
</tr>
<tr>
-<td class="text-right">24</td>
-<td class="text-right">4</td>
-<td class="text-left">size</td>
+<td class="org-right">24</td>
+<td class="org-right">4</td>
+<td class="org-left">size</td>
</tr>
<tr>
-<td class="text-right">28</td>
-<td class="text-right">4</td>
-<td class="text-left">last modification time</td>
+<td class="org-right">28</td>
+<td class="org-right">4</td>
+<td class="org-left">last modification time</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
-<div id="outline-container-sec-9" class="outline-2">
-<h2 id="sec-9"><span class="section-number-2">9</span> Core architecture</h2>
+<div id="outline-container-orga49dca9" class="outline-2">
+<h2 id="orga49dca9"><span class="section-number-2">9.</span> Core architecture</h2>
<div class="outline-text-2" id="text-9">
<p>
Fifth core is simply some amount of already compiled into machine code
any time. Currently dictionary can contain at most 1000 entries.
</p>
</div>
-<div id="outline-container-sec-9-1" class="outline-3">
-<h3 id="sec-9-1"><span class="section-number-3">9.1</span> Dictionary entry format</h3>
+<div id="outline-container-org75e80d5" class="outline-3">
+<h3 id="org75e80d5"><span class="section-number-3">9.1.</span> Dictionary entry format</h3>
<div class="outline-text-3" id="text-9-1">
-<table class="table table-striped table-bordered table-hover table-condensed">
+<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
-<col class="right">
+<col class="org-right" />
-<col class="right">
+<col class="org-right" />
-<col class="left">
+<col class="org-left" />
</colgroup>
<thead>
<tr>
-<th scope="col" class="text-right">offset</th>
-<th scope="col" class="text-right">length</th>
-<th scope="col" class="text-left">description</th>
+<th scope="col" class="org-right">offset</th>
+<th scope="col" class="org-right">length</th>
+<th scope="col" class="org-left">description</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="text-right">0</td>
-<td class="text-right">4</td>
-<td class="text-left">0 &lt; previous entry</td>
+<td class="org-right">0</td>
+<td class="org-right">4</td>
+<td class="org-left">0 &lt; previous entry</td>
</tr>
<tr>
-<td class="text-right"> </td>
-<td class="text-right"> </td>
-<td class="text-left">0 = last</td>
+<td class="org-right"> </td>
+<td class="org-right"> </td>
+<td class="org-left">0 = last</td>
</tr>
<tr>
-<td class="text-right"> </td>
-<td class="text-right"> </td>
-<td class="text-left">-1 = empty</td>
+<td class="org-right"> </td>
+<td class="org-right"> </td>
+<td class="org-left">-1 = empty</td>
</tr>
</tbody>
<tbody>
<tr>
-<td class="text-right">4</td>
-<td class="text-right">15</td>
-<td class="text-left">module name string</td>
+<td class="org-right">4</td>
+<td class="org-right">15</td>
+<td class="org-left">module name string</td>
</tr>
</tbody>
<tbody>
<tr>
-<td class="text-right">19</td>
-<td class="text-right">1</td>
-<td class="text-left">entry type</td>
+<td class="org-right">19</td>
+<td class="org-right">1</td>
+<td class="org-left">entry type</td>
</tr>
</tbody>
<tbody>
<tr>
-<td class="text-right">20</td>
-<td class="text-right">4</td>
-<td class="text-left">entry data</td>
+<td class="org-right">20</td>
+<td class="org-right">4</td>
+<td class="org-left">entry data</td>
</tr>
</tbody>
</table>
</p>
</div>
</div>
-<div id="outline-container-sec-9-2" class="outline-3">
-<h3 id="sec-9-2"><span class="section-number-3">9.2</span> Possible module types</h3>
+<div id="outline-container-org12381ef" class="outline-3">
+<h3 id="org12381ef"><span class="section-number-3">9.2.</span> Possible module types</h3>
<div class="outline-text-3" id="text-9-2">
-<table class="table table-striped table-bordered table-hover table-condensed">
+<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
-<col class="right">
+<col class="org-right" />
-<col class="left">
+<col class="org-left" />
-<col class="left">
+<col class="org-left" />
</colgroup>
<thead>
<tr>
-<th scope="col" class="text-right">type</th>
-<th scope="col" class="text-left">description</th>
-<th scope="col" class="text-left">"execute" action</th>
+<th scope="col" class="org-right">type</th>
+<th scope="col" class="org-left">description</th>
+<th scope="col" class="org-left">"execute" action</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="text-right">0</td>
-<td class="text-left">data</td>
-<td class="text-left">compile "num" instruction</td>
+<td class="org-right">0</td>
+<td class="org-left">data</td>
+<td class="org-left">compile "num" instruction</td>
</tr>
<tr>
-<td class="text-right"> </td>
-<td class="text-left"> </td>
-<td class="text-left">with address to module</td>
+<td class="org-right"> </td>
+<td class="org-left"> </td>
+<td class="org-left">with address to module</td>
</tr>
</tbody>
<tbody>
<tr>
-<td class="text-right">1</td>
-<td class="text-left">submodule</td>
-<td class="text-left">compile "call" instruction</td>
+<td class="org-right">1</td>
+<td class="org-left">submodule</td>
+<td class="org-left">compile "call" instruction</td>
</tr>
<tr>
-<td class="text-right"> </td>
-<td class="text-left"> </td>
-<td class="text-left">with address to module</td>
+<td class="org-right"> </td>
+<td class="org-left"> </td>
+<td class="org-left">with address to module</td>
</tr>
</tbody>
<tbody>
<tr>
-<td class="text-right">2</td>
-<td class="text-left">imm. submodule</td>
-<td class="text-left">immediately call to module</td>
+<td class="org-right">2</td>
+<td class="org-left">imm. submodule</td>
+<td class="org-left">immediately call to module</td>
</tr>
</tbody>
</table>
</div>
</div>
-<div id="outline-container-sec-9-3" class="outline-3">
-<h3 id="sec-9-3"><span class="section-number-3">9.3</span> Memory map (average)</h3>
+<div id="outline-container-org33be039" class="outline-3">
+<h3 id="org33be039"><span class="section-number-3">9.3.</span> Memory map</h3>
<div class="outline-text-3" id="text-9-3">
-<table class="table table-striped table-bordered table-hover table-condensed">
+<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
-<col class="right">
+<col class="org-right" />
-<col class="left">
+<col class="org-left" />
-<col class="left">
+<col class="org-left" />
</colgroup>
<thead>
<tr>
-<th scope="col" class="text-right"><loc></th>
-<th scope="col" class="text-left"><size></th>
-<th scope="col" class="text-left"><desc></th>
+<th scope="col" class="org-right">location</th>
+<th scope="col" class="org-left">size</th>
+<th scope="col" class="org-left">description</th>
</tr>
</thead>
<tbody>
<tr>
-<td class="text-right">0</td>
-<td class="text-left">~4096</td>
-<td class="text-left">core</td>
+<td class="org-right">0</td>
+<td class="org-left">~4096</td>
+<td class="org-left">core</td>
</tr>
<tr>
-<td class="text-right">1500000</td>
-<td class="text-left">~32000</td>
-<td class="text-left">highlevel Fifth boot code</td>
+<td class="org-right">1500000</td>
+<td class="org-left">~32000</td>
+<td class="org-left">highlevel Fifth boot code</td>
</tr>
<tr>
-<td class="text-right">200000h</td>
-<td class="text-left"> </td>
-<td class="text-left">core startup messages area</td>
+<td class="org-right">200000h</td>
+<td class="org-left"> </td>
+<td class="org-left">core startup messages area</td>
</tr>
<tr>
-<td class="text-right">5200000</td>
-<td class="text-left"> </td>
-<td class="text-left">end of dynamic memory space</td>
+<td class="org-right">5200000</td>
+<td class="org-left"> </td>
+<td class="org-left">end of dynamic memory space</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
-<div id="outline-container-sec-10" class="outline-2">
-<h2 id="sec-10"><span class="section-number-2">10</span> Virtual machine</h2>
+<div id="outline-container-org81fd544" class="outline-2">
+<h2 id="org81fd544"><span class="section-number-2">10.</span> Dynamically loadable modules</h2>
<div class="outline-text-2" id="text-10">
-<p>
-Using CPU emulator slows it down but I shouldn't now think too mutch
-about, and waste my time on batteling with problems whitch results on
-complex design of PC hardware. Also it allows me to use existing DOS
-and resident drivers services in real mode. So I don't need to deal
-with hardware too mutch. It also allows me to use all free XMS for
-flat code & data storage.
-</p>
-
-<p>
-Current emulator emulates 1 CPU. It has 2 stacks, ~50 instructions,
-and 4GB flat address space (theoretically). I'm not sure that DOS
-6.22 that I currently prefer can handle more than 64 MB of RAM. While
-I tried to keep instructionset simple, I was forced to put in lot of
-complex instructions to make it's performance acceptable on
-emulator. On actual silicon ~20 instructions is enaugh (I think).
-</p>
-
-<p>
-Maybe one day similar system will run directly on custom silicon chip :)
-</p>
-
-
-<p>
-CPU has following registers:
-</p>
-<table class="table table-striped table-bordered table-hover table-condensed">
-
-
-<colgroup>
-<col class="left">
-
-<col class="left">
-</colgroup>
-<tbody>
-<tr>
-<td class="text-left">IP</td>
-<td class="text-left">instruction pointer</td>
-</tr>
-
-<tr>
-<td class="text-left">DSP</td>
-<td class="text-left">data stack pointer</td>
-</tr>
-
-<tr>
-<td class="text-left">RSP</td>
-<td class="text-left">return stack pointer</td>
-</tr>
-</tbody>
-</table>
-
-<p>
-Virtual CPU, commands (most of them are avaiable as ordinary commands
-in programming lanquage):
-</p>
-
-<p class="verse">
-<br >
-code mnemonic description<br >
-<br >
-0 nop does notheing<br >
-1 halt halt CPU ( return to DOS on emulator )<br >
-<br >
-2 kbd@ ( – c ) read scancode of pressed or released key.<br >
-                                Returns 0, if no data avaiable.<br >
-3 num <dword> ( – n ) put immidiate number into datastack<br >
-<br >
-4 jmp <dword> jump to specified code<br >
-5 call <dword>jump to specified code, save return address to<br >
-                                return stack.<br >
-<br >
-6 1+ ( n – n+1 )<br >
-7 1- ( n – n-1 )<br >
-<br >
-8 dup ( n – n n ) duplicate top of data stack<br >
-9 drop ( n – ) drop last element in data stack<br >
-<br >
-10 if <dword> ( n – ) jump to addr if top element was 0<br >
-11 ret jump to code, specified in return stack.<br >
-<br >
-12 c@ ( addr – n ) read byte from memory at specified address<br >
-13 c! ( n addr – ) store byte to specified memory<br >
-<br >
-14 push ( DSTK -> RSTK ) move top of datastack to returnstack<br >
-15 pop ( RSTK -> DSTK ) move top of returnstack to datastack<br >
-<br >
-16 <unused><br >
-17 rot ( n1 n2 n3 – n2 n3 n1) rotate stack elements<br >
-<br >
-18 disk@ ( FromDiskSect ToMem – ) read 1KB from disk into RAM<br >
-19 disk! ( FromMem ToDiskSect – ) write 1KB to disk<br >
-<br >
-20 @ ( addr – n ) read 32 bit number from memory<br >
-21 ! ( n addr – ) store 32 bit number to memory<br >
-<br >
-22 over ( n1 n2 – n1 n2 n1 ) self explaining …<br >
-23 swap ( n1 n2 – n2 n1 ) -,,-<br >
-<br >
-24 + ( n1 n2 – n1+n2 ) -,,-<br >
-25 - ( n1 n2 – n1-n2 ) -,,-<br >
-<br >
-26 * ( n1 n2 – n1*n2 ) -,,-<br >
-27 / ( n1 n2 – n1/n2 ) -,,-<br >
-<br >
-28 > ( n1 n2 – result ) is true when n1 > n2<br >
-29 < ( n1 n2 – result ) is true when n1 < n2<br >
-<br >
-30 not ( n1 – not_n1 ) logical not<br >
-31 i ( – n ) copies top of return stack into datastack<br >
-<br >
-32 cprt@ ( addr – n ) read one byte from hardware port<br >
-33 cprt! ( n addr – ) store one byte to hardware port<br >
-<br >
-34 i2 ( – n ) like "i" but takes socond top stack element.<br >
-35 i3 ( – n ) like "i" but takes third top stack element.<br >
-<br >
-36 shl ( n amount – n ) left bit shift<br >
-37 shr ( n amount – n ) right bit shift<br >
-<br >
-38 or ( n1 n2 – n ) logical or<br >
-39 xor ( n1 n2 – n ) exclusive logical or<br >
-<br >
-40 vidmap ( addr – ) copy memory from "addr" to video memory.<br >
-<br >
-41 mouse@ ( – x y button ) read mouse coordinates & buttons<br >
-<br >
-42 vidput ( addr1 addr2 x y – ) put image1 into image2, at<br >
-                                location x, y. Does clipping, so part of a big image<br >
-                                can be mapped into smaller one.<br >
-<br >
-43 cmove ( addr1 addr2 amount ) move memory from addr1 to addr2<br >
-                                if addr1 is greater than addr2 then count address<br >
-                                foward while moving, elseway starts from end and<br >
-                                counts backwards, so no data loss will occure on<br >
-                                overlapping.<br >
-<br >
-44 cfill ( c addr amount – ) fill memory starting at "addr"<br >
-                                with "c" bytes.<br >
-<br >
-45 tvidput ( addr1 addr2 x y – ) same as "vidput" but treats<br >
-                                color 255 in source image as transparent.<br >
-<br >
-46 depth ( – depth ) returns current depth of data stack.<br >
-<br >
-47 charput ( colorfg colorbg addrsrc addrdest x y )<br >
-                                draw character to image buffer located at "addrdest"<br >
-                                to specified x & y location. Decodes 8 bytes from<br >
-                                source to bits, used to draw character.<br >
-</p>
-</div>
-</div>
-
-<div id="outline-container-sec-11" class="outline-2">
-<h2 id="sec-11"><span class="section-number-2">11</span> Fifth source format</h2>
-<div class="outline-text-2" id="text-11">
-<p>
-Fifth uses a different character table and codes than ASCII (still
-almost similar). I call it FSCII (Fifth Standard Code for Information
-Interchange) for example space character is not 32 but 255 instead. I
-plan to use mainly HEX numbers, and create new characters to represent
-numeric values. So typical nemric characters "0123…" is treated
-like ordinary letters.
-</p>
</div>
-<div id="outline-container-sec-11-1" class="outline-3">
-<h3 id="sec-11-1"><span class="section-number-3">11.1</span> FSCII</h3>
-<div class="outline-text-3" id="text-11-1">
-<table class="table table-striped table-bordered table-hover table-condensed">
-
-
-<colgroup>
-<col class="right">
-
-<col class="left">
-
-<col class="left">
-</colgroup>
-<thead>
-<tr>
-<th scope="col" class="text-right">DEC</th>
-<th scope="col" class="text-left">HEX</th>
-<th scope="col" class="text-left">function</th>
-</tr>
-</thead>
-<tbody>
-<tr>
-<td class="text-right">0 - 15</td>
-<td class="text-left">0 - F</td>
-<td class="text-left">HEX numbers</td>
-</tr>
-
-<tr>
-<td class="text-right">252</td>
-<td class="text-left">FC</td>
-<td class="text-left">backspace</td>
-</tr>
-
-<tr>
-<td class="text-right">253</td>
-<td class="text-left">FD</td>
-<td class="text-left">tabulator (TAB)</td>
-</tr>
-
-<tr>
-<td class="text-right">254</td>
-<td class="text-left">FE</td>
-<td class="text-left">carriage return (CR)</td>
-</tr>
-
-<tr>
-<td class="text-right">255</td>
-<td class="text-left">FF</td>
-<td class="text-left">space</td>
-</tr>
-
-<tr>
-<td class="text-right">else</td>
-<td class="text-left"> </td>
-<td class="text-left">ordinary characters, same as in ASCII.</td>
-</tr>
-</tbody>
-</table>
-</div>
-</div>
-</div>
-<div id="outline-container-sec-12" class="outline-2">
-<h2 id="sec-12"><span class="section-number-2">12</span> Fifth commands</h2>
-<div class="outline-text-2" id="text-12">
-</div><div id="outline-container-sec-12-1" class="outline-3">
-<h3 id="sec-12-1"><span class="section-number-3">12.1</span> Compilation & miscellaneous</h3>
-<div class="outline-text-3" id="text-12-1">
-<p class="verse">
-init module ( – )<br >
-                First module, control is passed to on startup. Contains<br >
-                initialization routines. Also it is the last core module.<br >
-                All new modules on top of it comes as result of executing<br >
-                external source files.<br >
-<br >
-head <name> ( – ) compiles new dictionary entry without specifying<br >
-                new module type.<br >
-                ex: head myentry<br >
-<br >
-: <name> ( – ) creates new code module<br >
-; ( – ) ends module (immideate)<br >
-                ex: : hello ." hi there" ;<br >
-<br >
-const <name> ( n – ) defines new constant.<br >
-                ex: 2147483647 const max<br >
-<br >
-:i <name> ( – ) same as ":" but this module will be executed<br >
-                immideately even in compile mode.<br >
-                ex: :i ( 41 scan ;<br >
-<br >
-create <name> ( – ) same as "head" , but specify module type as data.<br >
-                ex: create LotoResults 5 , 13 , 52 , 12 , 11 , 3 ,<br >
-<br >
-allot ( n – ) allocate n bytes in dictionary.<br >
-                ex: create MyArray 100 allot<br >
-<br >
-" <string>" ( – ) compile string and its size into core.<br >
-                ex: create Mystring " This is it's contects"<br >
-<br >
-str <name> <string>" ( – ) just shorter way for defining strings.<br >
-                ex: str Mystring This is it's contenc"<br >
-<br >
-var <name> ( – ) define new 32 bit variable.<br >
-                ex: var result<br >
-<br >
-' <module> ( – n ) return memory address of given entry.<br >
-                ex: ' init<br >
-<br >
-forget <name> ( – ) erases from RAM given entry and all entries what was<br >
-                defined after it.<br >
-                ex: forget myprog<br >
-<br >
-[ ( – ) set interpret mode (immideate)<br >
-] ( n – ) set compile mode and compile top stack element<br >
-                in as literal. Together [ …. ] cobination provides good<br >
-                way to compute some values only once, at compile time,<br >
-                rather than every time while program is running.<br >
-                ex: : calculate - [ 4 MyConst1 + MyConst2 * ] ;<br >
-<br >
-defer <name> ( – ) creates new module, with jump instruction.<br >
-                Later address where to jump can be modified by "is" command.<br >
-                This provides method of foward referencing. So you can use<br >
-                modules what not jet exist.<br >
-is ( address1 address2 – ) address1 - where to jump, address2 -<br >
-                address of module created by defer command.<br >
-                ex: defer dispver<br >
-                        : run dispver ." running …" ;<br >
-                               … whatever …<br >
-                        : (dispver ." Version 9.99 " ;<br >
-                        ' (dispver ' dispver is<br >
-<br >
-                Now if I type "run" on the screen appears:<br >
-                        Version 9.99 running …<br >
-<br >
-asc <char> ( – ) reads char ascii code and treats it as literal.<br >
-                (immideate)<br >
-                ex: : BreakLine 30 do asc - emit loop ;<br >
-                                 same as:<br >
-                    : BreakLine 30 do 45 emit loop ;<br >
-<br >
-dyninc ( handle – ) execute code in dynamic memory handle.<br >
-                automatically deallocates it when done.<br >
-<br >
-include ( filenumber – ) execute code in specified file.<br >
-<br >
-words ( – ) display existing blocks in core.<br >
-<br >
-bye ( – ) exit from Fifth<br >
-<br >
-fkey ( – c )<br >
-                Read one byte from input stream.<br >
-<br >
-sadd ( c addr – )<br >
-                Add one byte "c" to string located at "addr" and updates<br >
-                string length.<br >
-<br >
-scan ( c – )<br >
-                Read input stream and store it to pad until it finds c .<br >
-                It ignores all "c" bytes until it finds any non "c" byte.<br >
-                in other words:<br >
-                                c is: "<br >
-                         input stream: """"This is test !"aoeu idh<br >
-                               result: This is test !<br >
-<br >
-                Is useful for breaking text lines into words.<br >
-<br >
-skey ( – c )<br >
-                So called safe "fkey". Reads data from input stream<br >
-                but converts characters with ASCII codes: 9 13 10<br >
-                to spaces.<br >
-<br >
-str=str? ( adr1 adr2 – result )<br >
-                Compares string at "adr1" with string at "adr2", returns<br >
-                true flag if they are equal or false if they are not.<br >
-                true = -1<br >
-                false = 0<br >
-<br >
-find ( – addr )<br >
-                Searches whole dictionary for word in "pad". If found,<br >
-                returns it address, if not, returns 0.<br >
-<br >
-execute ( – )<br >
-                Execute word located in "pad". Depending on "mode".<br >
-<br >
-dta ( addr – DataAddr )<br >
-                Calculates address of dictionary entry data area, from<br >
-                entry point.<br >
-<br >
-2num ( – num result )<br >
-                Attempt to convert string located in "pad" into numeric<br >
-                value. If succeed returns number and true as result.<br >
-                If not, returns whatever and false as result.<br >
-<br >
-dadd ( addr length – )<br >
-                Add to dictionary data located at "addr", with specified<br >
-                length.<br >
-<br >
-lit ( n – )<br >
-                Act with number depending on "mode". When interpreting,<br >
-                leaves it in stack.<br >
-<br >
-<br >
-incmod ( addr – )<br >
-                Add to dictionary data located at "addr"+1 , length is taken<br >
-                from "addr".<br >
-<br >
-here ( – n )<br >
-                return "h" contents.<br >
-<br >
-mode var 8 bit<br >
-                Holds input stream parser operation mode.<br >
-                0 = interpreting<br >
-                1 = compiling<br >
-<br >
-pad var 128 bytes<br >
-                Holds temprorary strings.<br >
-<br >
-h var 32 bit<br >
-                Pointer to free byte in memory, always at the end of the<br >
-                dictionary. Each time when something is stored<br >
-                by "c," command, pointer is incareased.<br >
-<br >
-lp var 32 bit<br >
-                Pointer to last dictionary word. Each time when new word is<br >
-                compiled or erased by "forget", this pointer is updated.<br >
-<br >
-modulechk ( Dstr<filename> – ) check if module is loaded, if not<br >
-                immideately load it.<br >
-<br >
-ne ( entrydata entrytype – ) Compile new dictionary entry.<br >
-                It's name must be in "pad".<br >
-</p>
-</div>
-</div>
-<div id="outline-container-sec-12-2" class="outline-3">
-<h3 id="sec-12-2"><span class="section-number-3">12.2</span> Conditionals & control flow</h3>
-<div class="outline-text-3" id="text-12-2">
-<p class="verse">
-if ( flag – ) (immideate)<br >
-                "if 1.. else 2.. then" or<br >
-                "if 1.. then" construction. Conditional execution.<br >
-                Performs "1.." if "flag" was true,<br >
-                elseway performs "2.." if exist. Execution continues after<br >
-                word "then".<br >
-                ex: 1 if ." nonzero" else ." zero" then<br >
-<br >
->= ( n1 n2 – result ) true if (n1 = n2) or (n1 > n2)<br >
-                ex: 5 3 >= if ." first number is greater or equal" then<br >
-<br >
-<= ( n1 n2 – result ) true if (n1 = n2) or (n1 < n2)<br >
-= ( n1 n2 – result ) true if n1 = n2<br >
-<br >
-do ( count – ) (immideate)<br >
-                "do .. loop" construction. Performs ".." "count" times.<br >
-                In every step "count" is decareased until it is 0.<br >
-                ex: : test 5 do i .d loop ;<br >
-                result: 4 3 2 1 0<br >
-<br >
-doexit ( – ) exit from "do .. loop"<br >
-<br >
-for ( count top – ) (immideate)<br >
-                "for .. loop" construction. Performs ".." (top - count) times.<br >
-                In every step "count" is incareased until it reaches "top" .<br >
-                ex: : test 4 10 for i .d loop ;<br >
-                result: 4 5 6 7 8 9<br >
-<br >
-forexit ( – ) exit from "for .. loop"<br >
-<br >
-until ( – ) (immideate)<br >
-                "until .. loop" construction. Performs ".." until flag become<br >
-                true. False by default. Top of return stack holds flag.<br >
-<br >
-done ( – ) exit from "until .. loop"<br >
-<br >
-</p>
-</div>
-</div>
-<div id="outline-container-sec-12-3" class="outline-3">
-<h3 id="sec-12-3"><span class="section-number-3">12.3</span> Disk & file access</h3>
-<div class="outline-text-3" id="text-12-3">
-<p class="verse">
-diskload ( FromDisk ToMem amount – )<br >
-                Load specified abount of bytes from disk into memory.<br >
-<br >
-disksave ( FromMem ToDisk amount – )<br >
-                save specified abount of bytes from memory into disk.<br >
-<br >
-format ( – ) Erase all files.<br >
-<br >
-fsDfilesize@ ( handle – size )<br >
-                Return size of opened file.<br >
-<br >
-fsDcurloc@ ( handle – location )<br >
-                Return current location in file.<br >
-<br >
-fsDupdated@ ( handle – updated? )<br >
-                Return true if file was updated,<br >
-                ie. write operations occured.<br >
-<br >
-fssave ( FromMem DestFileHandle amount – )<br >
-                Save data to file.<br >
-<br >
-fsload ( SrcFileHandle ToMem amount – )<br >
-                Load data from file.<br >
-<br >
-fseof ( handle – bytesLeft )<br >
-                Return amount of bytes left till end of file.<br >
-                Useful before read operation.<br >
-<br >
-fsls ( – ) List all files and lists (directories,folders)<br >
-                in current path.<br >
-<br >
-fslsr ( – ) Same as "fsls" but recursively scans also sub lists.<br >
-<br >
-fscl ( DynStrHand – )<br >
-                Change list (path)<br >
-<br >
-fscreate ( DynStrHand – DescPnt )<br >
-                Create new file or list. Can create multiple lists at once.<br >
-                ex: when creating:<br >
-                    "\listGAMES\listSTRATEGY\listSIMWORLD\5th-runme"<br >
-                and only "\listGAMES\" already exist, then<br >
-                "listSTRATEGY" and "listSIMWORLD" lists will be created,<br >
-                and empty file "5th-runme" placed in there.<br >
-<br >
-fsDsave ( DynHand<data> DynStrHand<filename> – )<br >
-                Create new file and save all data from dynamic memory<br >
-                block to it.<br >
-<br >
-fsDload ( DynStr<SrcFileName> DynHand<DataDest> – )<br >
-                Load whole file into dynamic memory block.<br >
-<br >
-fsDloadnew ( DynStr<SrcFileName> – DynHand<DataDest> )<br >
-                Load whole file into new dynamic memory block.<br >
-</p>
-</div>
-</div>
-<div id="outline-container-sec-12-4" class="outline-3">
-<h3 id="sec-12-4"><span class="section-number-3">12.4</span> Dynamic memory</h3>
-<div class="outline-text-3" id="text-12-4">
+<div id="outline-container-org79d1c84" class="outline-3">
+<h3 id="org79d1c84"><span class="section-number-3">10.1.</span> Keyboard driver</h3>
+<div class="outline-text-3" id="text-10-1">
<p class="verse">
-dynal ( size – handle )<br >
-                Allocate dynamic memory block and return it's handle.<br >
-<br >
-dynde ( handle – )<br >
-                Deallocate dynamic memory block.<br >
-<br >
-dynp ( handle – addr )<br >
-                Returns pointer to memory where dynamic block<br >
-                data begins.<br >
-<br >
-dyns ( handle – size )<br >
-                Returns size of dynamic block.<br >
-<br >
-dynresize ( NewSize handle – )<br >
-                Nondestructively resize dynamic block.<br >
-<br >
-dync@ ( addr handle )<br >
-                Read one byte from dynamic block.<br >
-<br >
-dync! ( byte addr dynhandle )<br >
-                Write one byte to dynamic block.<br >
-<br >
-dyn@ ( addr handle )<br >
-                Read 32 bit number from dynamic block.<br >
-                Address will spacify, whitch number, not byte.<br >
-<br >
-dyn! ( 32BitNum addr dynhandle )<br >
-                Write 32 bit number to dynamic block.<br >
-                Address will spacify, whitch number, not byte.<br >
-<br >
-dyncon ( size "name" – )<br >
-                Allocate dynamic block with specified size, and<br >
-                create constant honding its handle.<br >
-                ex: 100 dyncon MyNewBlock<br >
-<br >
-dyn. ( handle – )<br >
-                Write contenc of dynamic memory block to screen.<br >
-</p>
-</div>
-</div>
-<div id="outline-container-sec-12-5" class="outline-3">
-<h3 id="sec-12-5"><span class="section-number-3">12.5</span> Graphics and text</h3>
-<div class="outline-text-3" id="text-12-5">
-<p class="verse">
-. ( n – ) print number on screen<br >
-<br >
-d. ( n – ) print number on screen in decimal<br >
-<br >
-? ( addr – ) print 32 bit value located at addr.<br >
-<br >
-." <string>" ( – ) print string into screen. Immideately<br >
-                compiles.<br >
-                ex: : greeting ." Hello, World" ;<br >
-<br >
-tab. ( – ) print tabulator<br >
-<br >
-calccol ( b g r – c ) calculate color what best matches given<br >
-                Blue Green & Red values. Values must be in range 0 - 255.<br >
-<br >
-imgalloc ( xsize ysize – imgbuf ) allocate image buffer for<br >
-                specified size.<br >
-<br >
-imgsize ( imgbuf – ) print on the screen X & Y size of image<br >
-                buffer.<br >
-<br >
-point ( x y imgbuf – addr ) returns memory address for specified<br >
-                pixel.<br >
-<br >
-pset ( color x y imgbuf – ) set graphic point<br >
-<br >
-boxf ( x1 x2 y1 y2 imgbuf color – ) draw filled box<br >
-<br >
-cls ( imgbuf – ) clear image buffer<br >
-<br >
-setpal ( b g r color – ) set palette value for specified color.<br >
-                values bust be in size 0 - 63.<br >
-<br >
-putchar ( char color x y imgbuf – ) put graphic character in<br >
-                imagebuffer to specified (x & y) location.<br >
-<br >
-scroll ( x y imgbuf – ) scroll in imgbuf.<br >
-<br >
-scrollf ( color x y screen – ) scroll and fill empty space with<br >
-                given color.<br >
-<br >
-at! ( x y – ) set cursor location<br >
-curc! ( color – ) set text color<br >
-curb! ( solor – ) set backround color<br >
-<br >
-colnorm ( – ) set text color to normal<br >
-colneg ( – ) set text color to negative (selected)<br >
-<br >
-dyntype ( dynhandle – ) display contenc of dynamic memory on screen<br >
-fsdisp ( file – ) clear screen, display file, and wait for key<br >
-<br >
-type ( addr length – )<br >
-                Types on the screen string, from memory at addr and<br >
-                specified length.<br >
-<br >
-write ( addr – )<br >
-                Types on the screen string, from memory at "addr"+1<br >
-                length is taken from "addr" .<br >
-<br >
-screen const 32 bit<br >
-                Holds handle of screen buffer.<br >
-<br >
-copyscreen ( SrcImgHandle DestImgHandle – ) copy contenc of source<br >
-                image to destination image. Source and destination images<br >
-                must have same size.<br >
-</p>
-</div>
-</div>
-<div id="outline-container-sec-12-6" class="outline-3">
-<h3 id="sec-12-6"><span class="section-number-3">12.6</span> Math, memory & stack manipulation</h3>
-<div class="outline-text-3" id="text-12-6">
+<br />
+KBD_@ ( – code ) get scancodes for pressed keys from keyboard.<br />
+KBD_down? ( key – result ) check is key with specified scancode<br />
+                currently pressed down.<br />
+KBD_SC2FSCII ( code – FSCII ) convert key scancode into FSCII code,<br />
+                or in FSK (Fifth standard keycode).<br />
+KBD_F@ ( – FSCII ) read pressed key FSCII or FSK, returns -1 if no<br />
+                keys are pressed.<br />
+KBD_FW@ ( – FSCII ) read pressed key FSCII or FSK, if no keys is<br />
+                are pressed then waits until there is.<br />
+<br />
+                FSK<br />
+                —<br />
+In HEX.<br />
+<br />
+FC backspace<br />
+FD TAB<br />
+FE enter<br />
+FF space<br />
+<br />
+400 ESC<br />
+401 … F1 …<br />
+410 up<br />
+411 right<br />
+412 down<br />
+413 left<br />
+414 INS<br />
+415 DEL<br />
+416 home<br />
+417 end<br />
+418 PG/UP<br />
+419 PG/DN<br />
+</p>
+</div>
+</div>
+<div id="outline-container-org99b4378" class="outline-3">
+<h3 id="org99b4378"><span class="section-number-3">10.2.</span> Mouse driver</h3>
+<div class="outline-text-3" id="text-10-2">
<p class="verse">
-off ( n – ) writes 0 to given address, good for zeroing variable.<br >
-                ex: MyVariable off<br >
-on ( n – ) writes -1 (true flag) to given address.<br >
-                ex: MyVariable on<br >
-<br >
-2dup ( n1 n2 – n1 n2 n1 n2 )<br >
-2drop ( n1 n2 – )<br >
-nip ( n1 n2 – n2 )<br >
-neg ( n1 – -n1 ) negotiate<br >
-bit@ ( n bit – result ) return specified bit from n.<br >
-                ex: 38 2 bit@ (result will be 1)<br >
-to32bit ( n1 n2 n3 n4 – n32 ) treat 4 last stack elements as bytes<br >
-                and unite them into 32 bit dword. Most significant byte<br >
-                on top.<br >
-                ex: 12 76 23 11 to32bit result: 186076172<br >
-<br >
-to8bit ( n32 – n1 n2 n3 n4 ) break 32 bit number into 4 bytes.<br >
-                Useful if you need to send 32 bit numbers thru 8 bit COM<br >
-                port.<br >
-                ex: 186076172 to8bit result: 12 76 23 11<br >
-<br >
-mod ( n1 n2 – reminder ) divide n1 by n2 and returns reminder.<br >
-                ex: 12 5 mod result: 2<br >
-<br >
-bound ( low n high – n ) check if n is in given bounds,<br >
-                if not then incarease/decarease it to match bounds.<br >
-                ex: 5 80 15 bound result: 15<br >
-                    5 10 15 bound result: 10<br >
-                    5 -10 15 bound result: 5<br >
-<br >
-bound? ( low n high – result ) returns true if n is in the<br >
-                given bounds.<br >
-<br >
-tab ( col – spaces) calculate amount of spaces to add<br >
-                ta reach next tabulation from given column.<br >
-<br >
-count ( addr – addr+1 n )<br >
-                Useful for returning bytes from constantly incareasing<br >
-                address. Module "type" is nice example.<br >
-<br >
-c, ( n – )<br >
-                store one byte at memory specified by "h". And incarease<br >
-                "h" by 1.<br >
-<br >
-, ( n – )<br >
-                store 32 bit number at memory specified by "h". And<br >
-                incarease "h" by 4.<br >
-<br >
-cmove ( addr1 addr2 n – )<br >
-                copy "n" amount of bytes from memory at "addr1" to memory<br >
-                at "addr2".<br >
-<br >
-rnd ( limit – result )<br >
-                generates random number in range 0 to "limit"-1.<br >
-<br >
-abs ( n – |n| )<br >
-                returns absolute value of "n"<br >
+mousex var Mouse x coordinate.<br />
+mousey var Mouse y coordinate.<br />
+mousekeyl var Mouse left key.<br />
+mousekeym var Mouse middle key.<br />
+mousekeyr var Mouse right key.<br />
+mousec var Display current mouse coordinates in top left part of screen,<br />
+                if true. (good for debugging)<br />
+mousepointer var Image buffer, holding current mouse pointer.<br />
+mouseadd ( ModuleAddr x1 x2 y1 y2 – ) Add specified area on screen,<br />
+                into mause click buffer. If any mouse button is clicked on<br />
+                that area, module at "ModuleAddr" will be executed.<br />
+mousebe var Amount of buffer elements.<br />
+mousedo ( – ) Updates mouse coordinates and keys. Parse mouse<br />
+                click buffer, and draw mouse cursor to "screen".<br />
</p>
</div>
</div>
-<div id="outline-container-sec-12-7" class="outline-3">
-<h3 id="sec-12-7"><span class="section-number-3">12.7</span> Dynamic & static strings</h3>
-<div class="outline-text-3" id="text-12-7">
-<p>
-Fifth supports both static and dynamic strings. Static strings must
-have predefined space reserved, and string mustn't exceed this
-length. They manipulation is faster. But they use more memory. Static
-string memory address is used to refer to the string.
-</p>
+<div id="outline-container-org0aa9e1f" class="outline-3">
+<h3 id="org0aa9e1f"><span class="section-number-3">10.3.</span> 2D graphic library</h3>
+<div class="outline-text-3" id="text-10-3">
+<dl class="org-dl">
+<dt>lineh ( color len x y imgbuf – )</dt><dd>draws horisontal line from X,Y
+coordinates to right, with specified length.</dd>
-<p>
-Dynamic strings can have at any time length form 0 to 0FFh, They take
-up only memory they currently need. They are held in dynamic memory
-blocks, so dynamic block handle is used to refer to this string.
-</p>
+<dt>linev ( color len x y imgbuf – )</dt><dd>draws vertical line down, from
+coordinates X,Y, with specified length.</dd>
-<p>
-Both types of strings are stored in the way, where first (0th) byte
-holds current string length, following bytes are string itself.
+<dt>box ( color x2 x1 y2 y1 imgbuf – )</dt><dd><p>
+draws rectangular box. x2
+bust be >= x1, y2 must be >= y1.
</p>
+<pre class="example" id="orgfea073c">
+x1,y1-----------+
+ | |
+ | |
+ +-----------x2,y2
+</pre></dd>
-<p class="verse">
-Dynamic:<br >
-<br >
-Dstral ( – handle )<br >
-                Allocate new string.<br >
-<br >
-Dstrlen ( handle – length )<br >
-                Return string length.<br >
-<br >
-c+Dstr ( chr handle – )<br >
-                Add one byte to end of the string.<br >
-<br >
-c+lDstr ( chr handle – )<br >
-                Add one byte to left side (beginning) of the string.<br >
-<br >
-Dstr. ( handle – )<br >
-                Write contec of string into screen.<br >
-<br >
-Dstrsure ( size Dstr – )<br >
-                Makes sure that at least rquested<br >
-                "size" (amount of characters) is allocated for given<br >
-                dynamic string.<br >
-<br >
-Dstr2str ( handle address – )<br >
-                Copy dyamic string into static memory space.<br >
-<br >
-str2Dstr ( address handle – )<br >
-                Copy static string into dyamic string.<br >
-<br >
-Dstr+str ( Dstr addr – )<br >
-                Add contenc of dynamic string to static string.<br >
-<br >
-D" any string" ( – Dstr )<br >
-                Moves specified string into dynamic string called "defDstr".<br >
-<br >
-D> any_string ( – Dstr )<br >
-                Moves specified string into dynamic string called "defDstr".<br >
-                Space marks end of string!<br >
-<br >
-D>2 any_string ( – Dstr )<br >
-                Moves specified string into dynamic string called "defDstr2".<br >
-                Space marks end of string!<br >
-<br >
-Dstr+Dstr ( Dstr1 Dstr2 – )<br >
-                Adds "Dstr1" to "Dstr2" and places result into "Dstr2".<br >
-<br >
-Dstrclear ( Dstr – )<br >
-                Clears contenc of dynamic string.<br >
-<br >
-Dstr2Dstr ( Dstr1 Dstr2 – )<br >
-                Moves "Dstr1" to "Dstr2".<br >
-Dstr ( data" name – )<br >
-                Creates new dynamic string and moves specified data into it.<br >
-                Then creates new constant with given "name" holding created<br >
-                dynamic string handle.<br >
-<br >
-                ex: Dstr Hello, my name is Sven!" message \ creates it<br >
-                    message Dstr. \ tests it<br >
-<br >
-Dstrlscan ( char Dstr – loc )<br >
-                Searches dynamic string for "char", from left to right,<br >
-                returns first found "char" location in string, or 0,<br >
-                if not found.<br >
-<br >
-Dstrrscan ( char Dstr – loc )<br >
-                Searches dynamic string for "char", from right to left,<br >
-                returns first found "char" location in string, or 0,<br >
-                if not found.<br >
-<br >
-Dstrlscane ( char Dstr – loc )<br >
-                Same as "Dstrlscan" buf returns string length+1 as location.<br >
-ÿ<br >
-Dstrleft ( amo Dstr – )<br >
-                Only specified amount of characters from left remains<br >
-                in dynamic string. ie. cut right part out.<br >
-<br >
-Dstrright ( amo Dstr – )<br >
-                Only specified amount of characters from right remains<br >
-                in dynamic string. ie. cut left part out.<br >
-<br >
-Dstrcutl ( amo Dstr – )<br >
-                Cut specified amount of characters from left of dynamic<br >
-                string out.<br >
-<br >
-Dstrsp ( char Dstr1 Dstr2 – )<br >
-                Separate dynamic string in Dstr1 into two parts,<br >
-                using "char" as separator. First part will be stored in<br >
-                "Dstr2", second part in "Dstr1".<br >
-                ex: asc \ \ ..separator<br >
-                    D> listF\listLIB\5TH_DRVMOUSE \ ..separate from<br >
-                    defDstr2 \ ..place result in<br >
-                    Dstrsp \ separation command<br >
-                    defDstr Dstr. \ will be: listLIB\5TH_DRVMOUSE<br >
-                    defDstr2 Dstr. \ will be: listF<br >
-<br >
-Dv ( addr – )<br >
-                Allocates empty dynamic string, and places it's handle<br >
-                into given address.<br >
-<br >
-Df ( addr – )<br >
-                Reads dynamic string handle from given address and<br >
-                deallocates (frees) it.<br >
-<br >
-ex: var mystring1<br >
-        : testmodule<br >
-        mystring1 Dv \ allocates string<br >
-<br >
-                <whatever><br >
-<br >
-        mystring1 Df ; \ deallocates it again when no longer needed.<br >
-</p>
-</div>
-</div>
+<dt>flipv ( imgbuf – )</dt><dd>flip image vertically.</dd>
+
+<dt>imgcoltrans ( ImgBuf Color ToColor – )</dt><dd>Translate all pixels in
+specified image with "Color" into "ToColor".</dd>
+
+<dt>imgfill ( color x y imgbuf – )</dt><dd>Fill image region starting at
+location X & Y with specified color.</dd>
+</dl>
</div>
-<div id="outline-container-sec-13" class="outline-2">
-<h2 id="sec-13"><span class="section-number-2">13</span> Dynamically loadable modules</h2>
-<div class="outline-text-2" id="text-13">
-</div><div id="outline-container-sec-13-1" class="outline-3">
-<h3 id="sec-13-1"><span class="section-number-3">13.1</span> Keyboard driver</h3>
-<div class="outline-text-3" id="text-13-1">
-<p class="verse">
-<br >
-KBD_@ ( – code ) get scancodes for pressed keys from keyboard.<br >
-KBD_down? ( key – result ) check is key with specified scancode<br >
-                currently pressed down.<br >
-KBD_SC2FSCII ( code – FSCII ) convert key scancode into FSCII code,<br >
-                or in FSK (Fifth standard keycode).<br >
-KBD_F@ ( – FSCII ) read pressed key FSCII or FSK, returns -1 if no<br >
-                keys are pressed.<br >
-KBD_FW@ ( – FSCII ) read pressed key FSCII or FSK, if no keys is<br >
-                are pressed then waits until there is.<br >
-<br >
-                FSK<br >
-                —<br >
-In HEX.<br >
-<br >
-FC backspace<br >
-FD TAB<br >
-FE enter<br >
-FF space<br >
-<br >
-400 ESC<br >
-401 … F1 …<br >
-410 up<br >
-411 right<br >
-412 down<br >
-413 left<br >
-414 INS<br >
-415 DEL<br >
-416 home<br >
-417 end<br >
-418 PG/UP<br >
-419 PG/DN<br >
-</p>
</div>
+
+<div id="outline-container-orgff6cdef" class="outline-3">
+<h3 id="orgff6cdef"><span class="section-number-3">10.4.</span> Trigonometry functions</h3>
+<div class="outline-text-3" id="text-10-4">
</div>
-<div id="outline-container-sec-13-2" class="outline-3">
-<h3 id="sec-13-2"><span class="section-number-3">13.2</span> Mouse driver</h3>
-<div class="outline-text-3" id="text-13-2">
-<p class="verse">
-mousex var Mouse x coordinate.<br >
-mousey var Mouse y coordinate.<br >
-mousekeyl var Mouse left key.<br >
-mousekeym var Mouse middle key.<br >
-mousekeyr var Mouse right key.<br >
-mousec var Display current mouse coordinates in top left part of screen,<br >
-                if true. (good for debugging)<br >
-mousepointer var Image buffer, holding current mouse pointer.<br >
-mouseadd ( ModuleAddr x1 x2 y1 y2 – ) Add specified area on screen,<br >
-                into mause click buffer. If any mouse button is clicked on<br >
-                that area, module at "ModuleAddr" will be executed.<br >
-mousebe var Amount of buffer elements.<br >
-mousedo ( – ) Updates mouse coordinates and keys. Parse mouse<br >
-                click buffer, and draw mouse cursor to "screen".<br >
+<div id="outline-container-org868f7c6" class="outline-4">
+<h4 id="org868f7c6"><span class="section-number-4">10.4.1.</span> sin ( a – result )</h4>
+<div class="outline-text-4" id="text-10-4-1">
+<p>
+Return sinus from given angle "a", 360ø is 2000. So 1000 represents
+180ø angle. Result will be in range -10'000 to 10'000, instead of ñ1.
</p>
</div>
</div>
-<div id="outline-container-sec-13-3" class="outline-3">
-<h3 id="sec-13-3"><span class="section-number-3">13.3</span> 2D graphic library</h3>
-<div class="outline-text-3" id="text-13-3">
-<p class="verse">
-lineh ( color len x y imgbuf – ) draws horisontal line<br >
-                from X,Y coordinates to right, with specified length.<br >
-linev ( color len x y imgbuf – ) draws vertical line<br >
-                down, from coordinates X,Y, with specified length.<br >
-box ( color x2 x1 y2 y1 imgbuf – ) draws rectangular<br >
-                box. x2 bust be >= x1, y2 must be >= y1.<br >
-                        x1,y1–———+<br >
-                          | |<br >
-                          | |<br >
-                          +–———x2,y2<br >
-<br >
-flipv ( imgbuf – ) flip image vertically.<br >
-imgcoltrans ( ImgBuf Color ToColor – ) Translate all pixels in<br >
-                specified image with "Color" into "ToColor".<br >
-imgfill ( color x y imgbuf – ) Fill image region starting at location<br >
-                X & Y with specified color.<br >
+<div id="outline-container-orgc3f161e" class="outline-4">
+<h4 id="orgc3f161e"><span class="section-number-4">10.4.2.</span> cos ( a – result )</h4>
+<div class="outline-text-4" id="text-10-4-2">
+<p>
+Return cosinus from given angle. Parameters are like in <a href="#org868f7c6">sin</a> function.
</p>
</div>
</div>
-<div id="outline-container-sec-13-4" class="outline-3">
-<h3 id="sec-13-4"><span class="section-number-3">13.4</span> Trigonometry functions</h3>
-<div class="outline-text-3" id="text-13-4">
-<p class="verse">
-sin ( a – result ) return sinus from given angle "a",<br >
-                360ø is 2000. So 1000 represents 180ø angle.<br >
-                Result will be in range -10'000 to 10'000, instead of ñ1.<br >
-<br >
-cos ( a – result ) return cosinus from given angle.<br >
-                Parameters are like in "sin" function.<br >
-</p>
</div>
</div>
</div>
-</div><div class="col-md-3"><nav id="table-of-contents">
-<div id="text-table-of-contents" class="bs-docs-sidebar">
-<ul class="nav">
-<li><a href="#sec-1">1. General</a>
-<ul class="nav">
-<li><a href="#sec-1-1">1.1. Source code</a></li>
-</ul>
-</li>
-<li><a href="#sec-2">2. Warning</a></li>
-<li><a href="#sec-3">3. Introduction</a>
-<ul class="nav">
-<li><a href="#sec-3-1">3.1. screenshots</a></li>
-</ul>
-</li>
-<li><a href="#sec-4">4. Installation</a></li>
-<li><a href="#sec-5">5. Fifth distribution directory tree description</a></li>
-<li><a href="#sec-6">6. Software/Hardware/Human requirements</a>
-<ul class="nav">
-<li><a href="#sec-6-1">6.1. Software</a></li>
-<li><a href="#sec-6-2">6.2. Hardware</a></li>
-<li><a href="#sec-6-3">6.3. Human</a></li>
-</ul>
-</li>
-<li><a href="#sec-7">7. Numbers representation within Fifth</a></li>
-<li><a href="#sec-8">8. Disk file map, and it's data structures</a>
-<ul class="nav">
-<li><a href="#sec-8-1">8.1. disk allocation</a></li>
-<li><a href="#sec-8-2">8.2. FAT entry format:</a></li>
-<li><a href="#sec-8-3">8.3. file entry format</a></li>
-</ul>
-</li>
-<li><a href="#sec-9">9. Core architecture</a>
-<ul class="nav">
-<li><a href="#sec-9-1">9.1. Dictionary entry format</a></li>
-<li><a href="#sec-9-2">9.2. Possible module types</a></li>
-<li><a href="#sec-9-3">9.3. Memory map (average)</a></li>
-</ul>
-</li>
-<li><a href="#sec-10">10. Virtual machine</a></li>
-<li><a href="#sec-11">11. Fifth source format</a>
-<ul class="nav">
-<li><a href="#sec-11-1">11.1. FSCII</a></li>
-</ul>
-</li>
-<li><a href="#sec-12">12. Fifth commands</a>
-<ul class="nav">
-<li><a href="#sec-12-1">12.1. Compilation & miscellaneous</a></li>
-<li><a href="#sec-12-2">12.2. Conditionals & control flow</a></li>
-<li><a href="#sec-12-3">12.3. Disk & file access</a></li>
-<li><a href="#sec-12-4">12.4. Dynamic memory</a></li>
-<li><a href="#sec-12-5">12.5. Graphics and text</a></li>
-<li><a href="#sec-12-6">12.6. Math, memory & stack manipulation</a></li>
-<li><a href="#sec-12-7">12.7. Dynamic & static strings</a></li>
-</ul>
-</li>
-<li><a href="#sec-13">13. Dynamically loadable modules</a>
-<ul class="nav">
-<li><a href="#sec-13-1">13.1. Keyboard driver</a></li>
-<li><a href="#sec-13-2">13.2. Mouse driver</a></li>
-<li><a href="#sec-13-3">13.3. 2D graphic library</a></li>
-<li><a href="#sec-13-4">13.4. Trigonometry functions</a></li>
-</ul>
-</li>
-</ul>
-</div>
-</nav>
-</div></div></div>
-<footer id="postamble" class="">
-<div><p class="author">Author: Svjatoslav Agejenko</p>
-<p class="date">Created: 2018-07-01 Sun 23:59</p>
-<p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.1.1 (<a href="http://orgmode.org">Org-mode</a> 8.2.10)</p>
+<div id="postamble" class="status">
+<p class="author">Author: Svjatoslav Agejenko</p>
+<p class="date">Created: 2023-09-19 Tue 18:07</p>
+<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
-</footer>
</body>
</html>
#+TITLE: Fifth - virtual machine, operating system, programming language
-* (document settings) :noexport:
-** use dark style for TWBS-HTML exporter
-#+HTML_HEAD: <link href="https://bootswatch.com/3/darkly/bootstrap.min.css" rel="stylesheet">
-#+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
-#+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
-#+HTML_HEAD: <style type="text/css">
-#+HTML_HEAD: footer {background-color: #111 !important;}
-#+HTML_HEAD: pre {background-color: #111; color: #ccc;}
-#+HTML_HEAD: </style>
* General
-- This program is free software: you can redistribute it and/or modify
- it under the terms of the [[https://www.gnu.org/licenses/lgpl.html][GNU Lesser General Public License]] as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
+- This program is free software: released under Creative Commons Zero
+ (CC0) license
- Program author:
- Svjatoslav Agejenko
- - Homepage: http://svjatoslav.eu
+ - Homepage: https://svjatoslav.eu
- Email: mailto://svjatoslav@svjatoslav.eu
-- [[http://www.svjatoslav.eu/projects/][Other software projects hosted at svjatoslav.eu]]
+- [[https://www.svjatoslav.eu/projects/][Other software projects hosted at svjatoslav.eu]]
** Source code
-- [[http://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=snapshot;h=HEAD;sf=tgz][Download latest snapshot in TAR GZ format]]
+- [[https://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=snapshot;h=HEAD;sf=tgz][Download latest snapshot in TAR GZ format]]
-- [[http://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=summary][Browse Git repository online]]
+- [[https://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=summary][Browse Git repository online]]
- Clone Git repository using command:
- : git clone http://www2.svjatoslav.eu/git/fifth.git
+ : git clone https://www2.svjatoslav.eu/git/fifth.git
-* Warning
+* !Project deprecated!
Current implementation does not support object oriented
programming. While working on Fifth I got lots of cool new ideas that
require reimplementation of everything.
Currently I try to implement those new ideas in the project called
-[[http://www3.svjatoslav.eu/projects/sixth/][Sixth]]
+[[https://www3.svjatoslav.eu/projects/sixth/][Sixth]].
System is built many years ago when I was still using DOS as a primary
-operating system and not updated since.
+operating system.
* Introduction
-Fifth is programming lanquage & operating system, running on [[emulator.html][virtual
-CPU]], with custom instruction set. It is much like Charles Chunk
-Moore's Forth, it also uses stack architecture, and many commands are
-similar. Basically I got familiar with concepts of Forth, and being
-inspired created my own system.
+Fifth is a combination of:
+- [[id:da7fff9b-0b67-4843-828a-52a404d7f401][Programming language]] (inspired by Forth).
+- Operating system.
+- [[id:9b251eb9-aff6-4025-94bf-25e89e26d54a][Virtual machine]] with custom instruction set.
-- [[file:5TH_ET.txt][Example Fifth source file - text editor]]
-** screenshots
-- [[file:screenshots/start.png]]
- - Startup screen diplaying Fifth logo and full file list.
+** Screenshots
-- [[file:screenshots/dictionary.png]]
- - Sample words defined. Most of the words are commands that can be
- executed interactively from command line or from file. When
- executed they can be selectively compiled or interpreted.
+[[file:screenshots/start.png]]
-- [[file:screenshots/text editor.png]]
- - Built in text editor.
+Startup screen diplaying Fifth logo and full file list.
+
+[[file:screenshots/dictionary.png]]
+
+Sample words defined. Most of the words are commands that can be
+executed interactively from the command line or from a file. When
+executed, they can be selectively compiled or interpreted.
+
+
+[[file:screenshots/text editor.png]]
+
+Built in text editor.
* Installation
Just unpack all files, witout altering original directory structure,
somewhere in your hard disk. For example:
-: C:\MISC\FIFTH\....
-To run fifth you need minimally just 2 files. emulator itself (
-EMULATOR.EXE or EMULATOR.COM ), and virtual disk file ( DISK.RAW ).
-Read more about [[files.txt][distribution directory layout]]
+: C:\MISC\FIFTH\
+
+To run fifth you need minimally just 2 files:
+- EMULATOR.COM :: Virtual CPU emulator
+- DISK.RAW :: Virtual disk file
+
+For more information, please refer to [[id:0759f3e0-28bb-4901-9e4f-09ef41732173][Fifth distribution directory
+tree description]].
+
* Fifth distribution directory tree description
+:PROPERTIES:
+:ID: 0759f3e0-28bb-4901-9e4f-09ef41732173
+:END:
After downloading and unpacking the ZIP file you shoud get directory
tree similar to this:
#+BEGIN_VERSE
-[DOC] - Fifth documentation
- [commands] - documentation on Fifth built-in commands
- [modules] - documentation on additional commands, realized as loadable modules
- [shots] - Fifth screenshots
+*DOC* - Fifth documentation
+ *commands* - documentation on Fifth built-in commands
+ *modules* - documentation on additional commands, realized as loadable modules
+ *shots* - Fifth screenshots
-[imageFile] - files contained within 'disk.raw', just an extracted form.
+*imageFile* - files contained within 'disk.raw', just an extracted form.
-[source] - source files
- [emulator] - emulator source
- [util] - utilites
+*source* - source files
+ *emulator* - emulator source
+ *util* - utilites
-disk.raw - Virtual disk file, has filesystem inside.
-emulator.com - main executable.
+*disk.raw* - Virtual disk file, has filesystem inside.
+*emulator.com* - main executable.
#+END_VERSE
-* Software/Hardware/Human requirements
+* Requirements
** Software
-- MS-DOS 6.22, with HIMEM.SYS loaded.
-- Mouse driver if you have a mouse.
-- Does work only when CPU is in real mode.
-- To recompile ASM sources I used FASM (Flat Assembler).
-- I ran QBasic utilities on QB 4.5 .
-- VESA support by BIOS, or external driver (UNIVBE).
+- MS-DOS 6.22 with HIMEM.SYS loaded.
+- Mouse driver (optional, if you have a mouse).
+- CPU is initialized into [[https://en.wikipedia.org/wiki/Unreal_mode][Unreal Mode]] during operation.
+- To recompile ASM sources, you can use FASM (Flat Assembler).
+- To run Quick Basic utilities, use Microsoft Quick Basic 4.5.
+- VESA support through BIOS or external driver (UNIVBE).
+
** Hardware
-- Minimum CPU 386.
-- 64 KB free RAM below 640KB,
-- 2 MB of free XMS.
-- VESA compatible video card.
-** Human
-- Beginner level Forth knowledge is recommended.
-- Lots of enthusiasm.
+- A minimum of a i386 CPU.
+- 64 KB of free RAM below 640KB.
+- 2 MB of free [[https://en.wikipedia.org/wiki/Extended_memory][extended memory]].
+- A VESA-compatible video card.
+
* Numbers representation within Fifth
+Because we are in full experimentation mode here (no regard for
+compatibility whatsoever), why not to try also alternative number
+representation ?
+
+Here alternative hexadecimal number representation format is devised:
+
[[file:numbers.png][file:numbers.png]]
-Because I can define everything, starting from CPU, why not try also
-alternative and unique number representation ?
+Essentially square is split into 4 triangles. Each triangle represents
+one bit.
+
+Fifth uses this hexadecimal format as primary throughout entire
+system.
+
+See also: [[https://en.wikipedia.org/wiki/Bibi-binary][Bibi-binary]].
-Fifth uses its hexdecimal number representation as primary. Numbers
-shape is formed by dividing a square into four parts. And manipulating
-their color (black or white).
* Disk file map, and it's data structures
Core and high-level boot code is stored outside of the filesystem to
allow easy access to it, at early booting time, when filesystem is not
yet initialized.
-** disk allocation
+** Disk allocation
| offset | length | description |
|--------+--------+----------------------|
| 0 | ~4 Kb | Fifth core |
-| 4 Kb | ~32Kb | high-level boot code |
-| 37 Kb | ~65Kb | FAT |
-| 101Kb | ~16MB | filesystem data area |
+| 4 Kb | ~32 Kb | high-level boot code |
+| 37 Kb | ~65 Kb | FAT |
+| 101 Kb | ~16 MB | filesystem data area |
** FAT entry format:
| code | meaning |
|------+--------------------------|
| -2 | last sector |
| -1 | empty sector |
| 0 -- | .. pointer to next block |
-** file entry format
+** File entry format
| offset | length | description |
|--------+--------+------------------------|
| 0 | 4 | extension |
| | | with address to module |
|------+----------------+----------------------------|
| 2 | imm. submodule | immediately call to module |
-** Memory map (average)
-| <loc> | <size> | <desc> |
-|---------+--------+-----------------------------|
-| 0 | ~4096 | core |
-| 1500000 | ~32000 | highlevel Fifth boot code |
-| 200000h | | core startup messages area |
-| 5200000 | | end of dynamic memory space |
-* Virtual machine
-Using CPU emulator slows it down but I shouldn't now think too mutch
-about, and waste my time on batteling with problems whitch results on
-complex design of PC hardware. Also it allows me to use existing DOS
-and resident drivers services in real mode. So I don't need to deal
-with hardware too mutch. It also allows me to use all free XMS for
-flat code & data storage.
-
-Current emulator emulates 1 CPU. It has 2 stacks, ~50 instructions,
-and 4GB flat address space (theoretically). I'm not sure that DOS
-6.22 that I currently prefer can handle more than 64 MB of RAM. While
-I tried to keep instructionset simple, I was forced to put in lot of
-complex instructions to make it's performance acceptable on
-emulator. On actual silicon ~20 instructions is enaugh (I think).
-
-Maybe one day similar system will run directly on custom silicon chip :)
-
-
-CPU has following registers:
-| IP | instruction pointer |
-| DSP | data stack pointer |
-| RSP | return stack pointer |
-
-Virtual CPU, commands (most of them are avaiable as ordinary commands
-in programming lanquage):
-
-#+BEGIN_VERSE
-
-code mnemonic description
-
-0 nop does notheing
-1 halt halt CPU ( return to DOS on emulator )
-
-2 kbd@ ( -- c ) read scancode of pressed or released key.
- Returns 0, if no data avaiable.
-3 num <dword> ( -- n ) put immidiate number into datastack
-
-4 jmp <dword> jump to specified code
-5 call <dword>jump to specified code, save return address to
- return stack.
-
-6 1+ ( n -- n+1 )
-7 1- ( n -- n-1 )
-
-8 dup ( n -- n n ) duplicate top of data stack
-9 drop ( n -- ) drop last element in data stack
-
-10 if <dword> ( n -- ) jump to addr if top element was 0
-11 ret jump to code, specified in return stack.
-
-12 c@ ( addr -- n ) read byte from memory at specified address
-13 c! ( n addr -- ) store byte to specified memory
-
-14 push ( DSTK -> RSTK ) move top of datastack to returnstack
-15 pop ( RSTK -> DSTK ) move top of returnstack to datastack
-
-16 <unused>
-17 rot ( n1 n2 n3 -- n2 n3 n1) rotate stack elements
-
-18 disk@ ( FromDiskSect ToMem -- ) read 1KB from disk into RAM
-19 disk! ( FromMem ToDiskSect -- ) write 1KB to disk
-
-20 @ ( addr -- n ) read 32 bit number from memory
-21 ! ( n addr -- ) store 32 bit number to memory
-
-22 over ( n1 n2 -- n1 n2 n1 ) self explaining ...
-23 swap ( n1 n2 -- n2 n1 ) -,,-
-
-24 + ( n1 n2 -- n1+n2 ) -,,-
-25 - ( n1 n2 -- n1-n2 ) -,,-
-
-26 * ( n1 n2 -- n1*n2 ) -,,-
-27 / ( n1 n2 -- n1/n2 ) -,,-
-
-28 > ( n1 n2 -- result ) is true when n1 > n2
-29 < ( n1 n2 -- result ) is true when n1 < n2
-
-30 not ( n1 -- not_n1 ) logical not
-31 i ( -- n ) copies top of return stack into datastack
-
-32 cprt@ ( addr -- n ) read one byte from hardware port
-33 cprt! ( n addr -- ) store one byte to hardware port
-
-34 i2 ( -- n ) like "i" but takes socond top stack element.
-35 i3 ( -- n ) like "i" but takes third top stack element.
-
-36 shl ( n amount -- n ) left bit shift
-37 shr ( n amount -- n ) right bit shift
-
-38 or ( n1 n2 -- n ) logical or
-39 xor ( n1 n2 -- n ) exclusive logical or
-
-40 vidmap ( addr -- ) copy memory from "addr" to video memory.
-
-41 mouse@ ( -- x y button ) read mouse coordinates & buttons
-
-42 vidput ( addr1 addr2 x y -- ) put image1 into image2, at
- location x, y. Does clipping, so part of a big image
- can be mapped into smaller one.
-
-43 cmove ( addr1 addr2 amount ) move memory from addr1 to addr2
- if addr1 is greater than addr2 then count address
- foward while moving, elseway starts from end and
- counts backwards, so no data loss will occure on
- overlapping.
-
-44 cfill ( c addr amount -- ) fill memory starting at "addr"
- with "c" bytes.
-
-45 tvidput ( addr1 addr2 x y -- ) same as "vidput" but treats
- color 255 in source image as transparent.
-
-46 depth ( -- depth ) returns current depth of data stack.
-
-47 charput ( colorfg colorbg addrsrc addrdest x y )
- draw character to image buffer located at "addrdest"
- to specified x & y location. Decodes 8 bytes from
- source to bits, used to draw character.
-#+END_VERSE
-
-* Fifth source format
-Fifth uses a different character table and codes than ASCII (still
-almost similar). I call it FSCII (Fifth Standard Code for Information
-Interchange) for example space character is not 32 but 255 instead. I
-plan to use mainly HEX numbers, and create new characters to represent
-numeric values. So typical nemric characters "0123..." is treated
-like ordinary letters.
-** FSCII
-
-| DEC | HEX | function |
-|--------+-------+----------------------------------------|
-| 0 - 15 | 0 - F | HEX numbers |
-| 252 | FC | backspace |
-| 253 | FD | tabulator (TAB) |
-| 254 | FE | carriage return (CR) |
-| 255 | FF | space |
-| else | | ordinary characters, same as in ASCII. |
-* Fifth commands
-** Compilation & miscellaneous
-#+BEGIN_VERSE
-init module ( -- )
- First module, control is passed to on startup. Contains
- initialization routines. Also it is the last core module.
- All new modules on top of it comes as result of executing
- external source files.
-
-head <name> ( -- ) compiles new dictionary entry without specifying
- new module type.
- ex: head myentry
-
-: <name> ( -- ) creates new code module
-; ( -- ) ends module (immideate)
- ex: : hello ." hi there" ;
-
-const <name> ( n -- ) defines new constant.
- ex: 2147483647 const max
-
-:i <name> ( -- ) same as ":" but this module will be executed
- immideately even in compile mode.
- ex: :i ( 41 scan ;
-
-create <name> ( -- ) same as "head" , but specify module type as data.
- ex: create LotoResults 5 , 13 , 52 , 12 , 11 , 3 ,
-
-allot ( n -- ) allocate n bytes in dictionary.
- ex: create MyArray 100 allot
-
-" <string>" ( -- ) compile string and its size into core.
- ex: create Mystring " This is it's contects"
-
-str <name> <string>" ( -- ) just shorter way for defining strings.
- ex: str Mystring This is it's contenc"
-
-var <name> ( -- ) define new 32 bit variable.
- ex: var result
-
-' <module> ( -- n ) return memory address of given entry.
- ex: ' init
-
-forget <name> ( -- ) erases from RAM given entry and all entries what was
- defined after it.
- ex: forget myprog
-
-[ ( -- ) set interpret mode (immideate)
-] ( n -- ) set compile mode and compile top stack element
- in as literal. Together [ .... ] cobination provides good
- way to compute some values only once, at compile time,
- rather than every time while program is running.
- ex: : calculate - [ 4 MyConst1 + MyConst2 * ] ;
-
-defer <name> ( -- ) creates new module, with jump instruction.
- Later address where to jump can be modified by "is" command.
- This provides method of foward referencing. So you can use
- modules what not jet exist.
-is ( address1 address2 -- ) address1 - where to jump, address2 -
- address of module created by defer command.
- ex: defer dispver
- : run dispver ." running ..." ;
- ... whatever ...
- : (dispver ." Version 9.99 " ;
- ' (dispver ' dispver is
-
- Now if I type "run" on the screen appears:
- Version 9.99 running ...
-
-asc <char> ( -- ) reads char ascii code and treats it as literal.
- (immideate)
- ex: : BreakLine 30 do asc - emit loop ;
- same as:
- : BreakLine 30 do 45 emit loop ;
-
-dyninc ( handle -- ) execute code in dynamic memory handle.
- automatically deallocates it when done.
-
-include ( filenumber -- ) execute code in specified file.
-
-words ( -- ) display existing blocks in core.
-
-bye ( -- ) exit from Fifth
-
-fkey ( -- c )
- Read one byte from input stream.
-
-sadd ( c addr -- )
- Add one byte "c" to string located at "addr" and updates
- string length.
-
-scan ( c -- )
- Read input stream and store it to pad until it finds c .
- It ignores all "c" bytes until it finds any non "c" byte.
- in other words:
- c is: "
- input stream: """"This is test !"aoeu idh
- result: This is test !
-
- Is useful for breaking text lines into words.
-
-skey ( -- c )
- So called safe "fkey". Reads data from input stream
- but converts characters with ASCII codes: 9 13 10
- to spaces.
-
-str=str? ( adr1 adr2 -- result )
- Compares string at "adr1" with string at "adr2", returns
- true flag if they are equal or false if they are not.
- true = -1
- false = 0
-
-find ( -- addr )
- Searches whole dictionary for word in "pad". If found,
- returns it address, if not, returns 0.
-
-execute ( -- )
- Execute word located in "pad". Depending on "mode".
-
-dta ( addr -- DataAddr )
- Calculates address of dictionary entry data area, from
- entry point.
-
-2num ( -- num result )
- Attempt to convert string located in "pad" into numeric
- value. If succeed returns number and true as result.
- If not, returns whatever and false as result.
-
-dadd ( addr length -- )
- Add to dictionary data located at "addr", with specified
- length.
-
-lit ( n -- )
- Act with number depending on "mode". When interpreting,
- leaves it in stack.
-
-
-incmod ( addr -- )
- Add to dictionary data located at "addr"+1 , length is taken
- from "addr".
-
-here ( -- n )
- return "h" contents.
-
-mode var 8 bit
- Holds input stream parser operation mode.
- 0 = interpreting
- 1 = compiling
-
-pad var 128 bytes
- Holds temprorary strings.
-
-h var 32 bit
- Pointer to free byte in memory, always at the end of the
- dictionary. Each time when something is stored
- by "c," command, pointer is incareased.
-
-lp var 32 bit
- Pointer to last dictionary word. Each time when new word is
- compiled or erased by "forget", this pointer is updated.
-
-modulechk ( Dstr<filename> -- ) check if module is loaded, if not
- immideately load it.
-
-ne ( entrydata entrytype -- ) Compile new dictionary entry.
- It's name must be in "pad".
-#+END_VERSE
-** Conditionals & control flow
-#+BEGIN_VERSE
-if ( flag -- ) (immideate)
- "if 1.. else 2.. then" or
- "if 1.. then" construction. Conditional execution.
- Performs "1.." if "flag" was true,
- elseway performs "2.." if exist. Execution continues after
- word "then".
- ex: 1 if ." nonzero" else ." zero" then
-
->= ( n1 n2 -- result ) true if (n1 = n2) or (n1 > n2)
- ex: 5 3 >= if ." first number is greater or equal" then
-
-<= ( n1 n2 -- result ) true if (n1 = n2) or (n1 < n2)
-= ( n1 n2 -- result ) true if n1 = n2
-
-do ( count -- ) (immideate)
- "do .. loop" construction. Performs ".." "count" times.
- In every step "count" is decareased until it is 0.
- ex: : test 5 do i .d loop ;
- result: 4 3 2 1 0
-
-doexit ( -- ) exit from "do .. loop"
-
-for ( count top -- ) (immideate)
- "for .. loop" construction. Performs ".." (top - count) times.
- In every step "count" is incareased until it reaches "top" .
- ex: : test 4 10 for i .d loop ;
- result: 4 5 6 7 8 9
-
-forexit ( -- ) exit from "for .. loop"
-
-until ( -- ) (immideate)
- "until .. loop" construction. Performs ".." until flag become
- true. False by default. Top of return stack holds flag.
-
-done ( -- ) exit from "until .. loop"
-
-#+END_VERSE
-** Disk & file access
-#+BEGIN_VERSE
-diskload ( FromDisk ToMem amount -- )
- Load specified abount of bytes from disk into memory.
-
-disksave ( FromMem ToDisk amount -- )
- save specified abount of bytes from memory into disk.
-
-format ( -- ) Erase all files.
-
-fsDfilesize@ ( handle -- size )
- Return size of opened file.
-
-fsDcurloc@ ( handle -- location )
- Return current location in file.
-
-fsDupdated@ ( handle -- updated? )
- Return true if file was updated,
- ie. write operations occured.
-
-fssave ( FromMem DestFileHandle amount -- )
- Save data to file.
-
-fsload ( SrcFileHandle ToMem amount -- )
- Load data from file.
-
-fseof ( handle -- bytesLeft )
- Return amount of bytes left till end of file.
- Useful before read operation.
-
-fsls ( -- ) List all files and lists (directories,folders)
- in current path.
-
-fslsr ( -- ) Same as "fsls" but recursively scans also sub lists.
-
-fscl ( DynStrHand -- )
- Change list (path)
-
-fscreate ( DynStrHand -- DescPnt )
- Create new file or list. Can create multiple lists at once.
- ex: when creating:
- "\listGAMES\listSTRATEGY\listSIMWORLD\5th-runme"
- and only "\listGAMES\" already exist, then
- "listSTRATEGY" and "listSIMWORLD" lists will be created,
- and empty file "5th-runme" placed in there.
-
-fsDsave ( DynHand<data> DynStrHand<filename> -- )
- Create new file and save all data from dynamic memory
- block to it.
-
-fsDload ( DynStr<SrcFileName> DynHand<DataDest> -- )
- Load whole file into dynamic memory block.
-
-fsDloadnew ( DynStr<SrcFileName> -- DynHand<DataDest> )
- Load whole file into new dynamic memory block.
-#+END_VERSE
-** Dynamic memory
-#+BEGIN_VERSE
-dynal ( size -- handle )
- Allocate dynamic memory block and return it's handle.
-
-dynde ( handle -- )
- Deallocate dynamic memory block.
-
-dynp ( handle -- addr )
- Returns pointer to memory where dynamic block
- data begins.
-
-dyns ( handle -- size )
- Returns size of dynamic block.
-
-dynresize ( NewSize handle -- )
- Nondestructively resize dynamic block.
-
-dync@ ( addr handle )
- Read one byte from dynamic block.
-
-dync! ( byte addr dynhandle )
- Write one byte to dynamic block.
-
-dyn@ ( addr handle )
- Read 32 bit number from dynamic block.
- Address will spacify, whitch number, not byte.
-
-dyn! ( 32BitNum addr dynhandle )
- Write 32 bit number to dynamic block.
- Address will spacify, whitch number, not byte.
-
-dyncon ( size "name" -- )
- Allocate dynamic block with specified size, and
- create constant honding its handle.
- ex: 100 dyncon MyNewBlock
-
-dyn. ( handle -- )
- Write contenc of dynamic memory block to screen.
-#+END_VERSE
-** Graphics and text
-#+BEGIN_VERSE
-. ( n -- ) print number on screen
-
-d. ( n -- ) print number on screen in decimal
-
-? ( addr -- ) print 32 bit value located at addr.
-
-." <string>" ( -- ) print string into screen. Immideately
- compiles.
- ex: : greeting ." Hello, World" ;
-
-tab. ( -- ) print tabulator
-
-calccol ( b g r -- c ) calculate color what best matches given
- Blue Green & Red values. Values must be in range 0 - 255.
-
-imgalloc ( xsize ysize -- imgbuf ) allocate image buffer for
- specified size.
-
-imgsize ( imgbuf -- ) print on the screen X & Y size of image
- buffer.
-
-point ( x y imgbuf -- addr ) returns memory address for specified
- pixel.
-
-pset ( color x y imgbuf -- ) set graphic point
-
-boxf ( x1 x2 y1 y2 imgbuf color -- ) draw filled box
-
-cls ( imgbuf -- ) clear image buffer
-
-setpal ( b g r color -- ) set palette value for specified color.
- values bust be in size 0 - 63.
-
-putchar ( char color x y imgbuf -- ) put graphic character in
- imagebuffer to specified (x & y) location.
-
-scroll ( x y imgbuf -- ) scroll in imgbuf.
-
-scrollf ( color x y screen -- ) scroll and fill empty space with
- given color.
-
-at! ( x y -- ) set cursor location
-curc! ( color -- ) set text color
-curb! ( solor -- ) set backround color
-
-colnorm ( -- ) set text color to normal
-colneg ( -- ) set text color to negative (selected)
-
-dyntype ( dynhandle -- ) display contenc of dynamic memory on screen
-fsdisp ( file -- ) clear screen, display file, and wait for key
-
-type ( addr length -- )
- Types on the screen string, from memory at addr and
- specified length.
-
-write ( addr -- )
- Types on the screen string, from memory at "addr"+1
- length is taken from "addr" .
-
-screen const 32 bit
- Holds handle of screen buffer.
-
-copyscreen ( SrcImgHandle DestImgHandle -- ) copy contenc of source
- image to destination image. Source and destination images
- must have same size.
-#+END_VERSE
-** Math, memory & stack manipulation
-#+BEGIN_VERSE
-off ( n -- ) writes 0 to given address, good for zeroing variable.
- ex: MyVariable off
-on ( n -- ) writes -1 (true flag) to given address.
- ex: MyVariable on
-
-2dup ( n1 n2 -- n1 n2 n1 n2 )
-2drop ( n1 n2 -- )
-nip ( n1 n2 -- n2 )
-neg ( n1 -- -n1 ) negotiate
-bit@ ( n bit -- result ) return specified bit from n.
- ex: 38 2 bit@ (result will be 1)
-to32bit ( n1 n2 n3 n4 -- n32 ) treat 4 last stack elements as bytes
- and unite them into 32 bit dword. Most significant byte
- on top.
- ex: 12 76 23 11 to32bit result: 186076172
-
-to8bit ( n32 -- n1 n2 n3 n4 ) break 32 bit number into 4 bytes.
- Useful if you need to send 32 bit numbers thru 8 bit COM
- port.
- ex: 186076172 to8bit result: 12 76 23 11
-
-mod ( n1 n2 -- reminder ) divide n1 by n2 and returns reminder.
- ex: 12 5 mod result: 2
-
-bound ( low n high -- n ) check if n is in given bounds,
- if not then incarease/decarease it to match bounds.
- ex: 5 80 15 bound result: 15
- 5 10 15 bound result: 10
- 5 -10 15 bound result: 5
-
-bound? ( low n high -- result ) returns true if n is in the
- given bounds.
-
-tab ( col -- spaces) calculate amount of spaces to add
- ta reach next tabulation from given column.
-
-count ( addr -- addr+1 n )
- Useful for returning bytes from constantly incareasing
- address. Module "type" is nice example.
-
-c, ( n -- )
- store one byte at memory specified by "h". And incarease
- "h" by 1.
-
-, ( n -- )
- store 32 bit number at memory specified by "h". And
- incarease "h" by 4.
-
-cmove ( addr1 addr2 n -- )
- copy "n" amount of bytes from memory at "addr1" to memory
- at "addr2".
-
-rnd ( limit -- result )
- generates random number in range 0 to "limit"-1.
-
-abs ( n -- |n| )
- returns absolute value of "n"
-#+END_VERSE
-** Dynamic & static strings
-Fifth supports both static and dynamic strings. Static strings must
-have predefined space reserved, and string mustn't exceed this
-length. They manipulation is faster. But they use more memory. Static
-string memory address is used to refer to the string.
-
-Dynamic strings can have at any time length form 0 to 0FFh, They take
-up only memory they currently need. They are held in dynamic memory
-blocks, so dynamic block handle is used to refer to this string.
-
-Both types of strings are stored in the way, where first (0th) byte
-holds current string length, following bytes are string itself.
-
-
-#+BEGIN_VERSE
-Dynamic:
-
-Dstral ( -- handle )
- Allocate new string.
-
-Dstrlen ( handle -- length )
- Return string length.
-
-c+Dstr ( chr handle -- )
- Add one byte to end of the string.
-
-c+lDstr ( chr handle -- )
- Add one byte to left side (beginning) of the string.
-
-Dstr. ( handle -- )
- Write contec of string into screen.
-
-Dstrsure ( size Dstr -- )
- Makes sure that at least rquested
- "size" (amount of characters) is allocated for given
- dynamic string.
-
-Dstr2str ( handle address -- )
- Copy dyamic string into static memory space.
-
-str2Dstr ( address handle -- )
- Copy static string into dyamic string.
-
-Dstr+str ( Dstr addr -- )
- Add contenc of dynamic string to static string.
-
-D" any string" ( -- Dstr )
- Moves specified string into dynamic string called "defDstr".
-
-D> any_string ( -- Dstr )
- Moves specified string into dynamic string called "defDstr".
- Space marks end of string!
-
-D>2 any_string ( -- Dstr )
- Moves specified string into dynamic string called "defDstr2".
- Space marks end of string!
-
-Dstr+Dstr ( Dstr1 Dstr2 -- )
- Adds "Dstr1" to "Dstr2" and places result into "Dstr2".
-
-Dstrclear ( Dstr -- )
- Clears contenc of dynamic string.
-
-Dstr2Dstr ( Dstr1 Dstr2 -- )
- Moves "Dstr1" to "Dstr2".
-Dstr ( data" name -- )
- Creates new dynamic string and moves specified data into it.
- Then creates new constant with given "name" holding created
- dynamic string handle.
-
- ex: Dstr Hello, my name is Sven!" message \ creates it
- message Dstr. \ tests it
-
-Dstrlscan ( char Dstr -- loc )
- Searches dynamic string for "char", from left to right,
- returns first found "char" location in string, or 0,
- if not found.
-
-Dstrrscan ( char Dstr -- loc )
- Searches dynamic string for "char", from right to left,
- returns first found "char" location in string, or 0,
- if not found.
-
-Dstrlscane ( char Dstr -- loc )
- Same as "Dstrlscan" buf returns string length+1 as location.
-ÿ
-Dstrleft ( amo Dstr -- )
- Only specified amount of characters from left remains
- in dynamic string. ie. cut right part out.
-
-Dstrright ( amo Dstr -- )
- Only specified amount of characters from right remains
- in dynamic string. ie. cut left part out.
-
-Dstrcutl ( amo Dstr -- )
- Cut specified amount of characters from left of dynamic
- string out.
-
-Dstrsp ( char Dstr1 Dstr2 -- )
- Separate dynamic string in Dstr1 into two parts,
- using "char" as separator. First part will be stored in
- "Dstr2", second part in "Dstr1".
- ex: asc \ \ ..separator
- D> listF\listLIB\5TH_DRVMOUSE \ ..separate from
- defDstr2 \ ..place result in
- Dstrsp \ separation command
- defDstr Dstr. \ will be: listLIB\5TH_DRVMOUSE
- defDstr2 Dstr. \ will be: listF
-
-Dv ( addr -- )
- Allocates empty dynamic string, and places it's handle
- into given address.
-
-Df ( addr -- )
- Reads dynamic string handle from given address and
- deallocates (frees) it.
-
-ex: var mystring1
- : testmodule
- mystring1 Dv \ allocates string
-
- <whatever>
-
- mystring1 Df ; \ deallocates it again when no longer needed.
-#+END_VERSE
+** Memory map
+| location | size | description |
+|----------+--------+-----------------------------|
+| 0 | ~4096 | core |
+| 1500000 | ~32000 | highlevel Fifth boot code |
+| 200000h | | core startup messages area |
+| 5200000 | | end of dynamic memory space |
* Dynamically loadable modules
** Keyboard driver
#+BEGIN_VERSE
click buffer, and draw mouse cursor to "screen".
#+END_VERSE
** 2D graphic library
-#+BEGIN_VERSE
-lineh ( color len x y imgbuf -- ) draws horisontal line
- from X,Y coordinates to right, with specified length.
-linev ( color len x y imgbuf -- ) draws vertical line
- down, from coordinates X,Y, with specified length.
-box ( color x2 x1 y2 y1 imgbuf -- ) draws rectangular
- box. x2 bust be >= x1, y2 must be >= y1.
- x1,y1-----------+
- | |
- | |
- +-----------x2,y2
-
-flipv ( imgbuf -- ) flip image vertically.
-imgcoltrans ( ImgBuf Color ToColor -- ) Translate all pixels in
- specified image with "Color" into "ToColor".
-imgfill ( color x y imgbuf -- ) Fill image region starting at location
- X & Y with specified color.
-#+END_VERSE
-** Trigonometry functions
-#+BEGIN_VERSE
-sin ( a -- result ) return sinus from given angle "a",
- 360ø is 2000. So 1000 represents 180ø angle.
- Result will be in range -10'000 to 10'000, instead of ñ1.
-cos ( a -- result ) return cosinus from given angle.
- Parameters are like in "sin" function.
-#+END_VERSE
++ lineh ( color len x y imgbuf -- ) :: draws horisontal line from X,Y
+ coordinates to right, with specified length.
+
++ linev ( color len x y imgbuf -- ) :: draws vertical line down, from
+ coordinates X,Y, with specified length.
+
++ box ( color x2 x1 y2 y1 imgbuf -- ) :: draws rectangular box. x2
+ bust be >= x1, y2 must be >= y1.
+
+ #+begin_example
+ x1,y1-----------+
+ | |
+ | |
+ +-----------x2,y2
+ #+end_example
+
++ flipv ( imgbuf -- ) :: flip image vertically.
+
++ imgcoltrans ( ImgBuf Color ToColor -- ) :: Translate all pixels in
+ specified image with "Color" into "ToColor".
+
++ imgfill ( color x y imgbuf -- ) :: Fill image region starting at
+ location X & Y with specified color.
+
+** Trigonometry functions
+*** sin ( a -- result )
+:PROPERTIES:
+:ID: 9a66ca9c-eb5f-45aa-8116-71763081f2fb
+:END:
+Return sinus from given angle "a", 360ø is 2000. So 1000 represents
+180ø angle. Result will be in range -10'000 to 10'000, instead of ñ1.
+*** cos ( a -- result )
+Return cosinus from given angle. Parameters are like in [[id:9a66ca9c-eb5f-45aa-8116-71763081f2fb][sin]] function.
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+<!-- 2023-09-19 Tue 18:07 -->
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1" />
+<title>Fifth - language</title>
+<meta name="author" content="Svjatoslav Agejenko" />
+<meta name="generator" content="Org Mode" />
+<style>
+ #content { max-width: 60em; margin: auto; }
+ .title { text-align: center;
+ margin-bottom: .2em; }
+ .subtitle { text-align: center;
+ font-size: medium;
+ font-weight: bold;
+ margin-top:0; }
+ .todo { font-family: monospace; color: red; }
+ .done { font-family: monospace; color: green; }
+ .priority { font-family: monospace; color: orange; }
+ .tag { background-color: #eee; font-family: monospace;
+ padding: 2px; font-size: 80%; font-weight: normal; }
+ .timestamp { color: #bebebe; }
+ .timestamp-kwd { color: #5f9ea0; }
+ .org-right { margin-left: auto; margin-right: 0px; text-align: right; }
+ .org-left { margin-left: 0px; margin-right: auto; text-align: left; }
+ .org-center { margin-left: auto; margin-right: auto; text-align: center; }
+ .underline { text-decoration: underline; }
+ #postamble p, #preamble p { font-size: 90%; margin: .2em; }
+ p.verse { margin-left: 3%; }
+ pre {
+ border: 1px solid #e6e6e6;
+ border-radius: 3px;
+ background-color: #f2f2f2;
+ padding: 8pt;
+ font-family: monospace;
+ overflow: auto;
+ margin: 1.2em;
+ }
+ pre.src {
+ position: relative;
+ overflow: auto;
+ }
+ pre.src:before {
+ display: none;
+ position: absolute;
+ top: -8px;
+ right: 12px;
+ padding: 3px;
+ color: #555;
+ background-color: #f2f2f299;
+ }
+ pre.src:hover:before { display: inline; margin-top: 14px;}
+ /* Languages per Org manual */
+ pre.src-asymptote:before { content: 'Asymptote'; }
+ pre.src-awk:before { content: 'Awk'; }
+ pre.src-authinfo::before { content: 'Authinfo'; }
+ pre.src-C:before { content: 'C'; }
+ /* pre.src-C++ doesn't work in CSS */
+ pre.src-clojure:before { content: 'Clojure'; }
+ pre.src-css:before { content: 'CSS'; }
+ pre.src-D:before { content: 'D'; }
+ pre.src-ditaa:before { content: 'ditaa'; }
+ pre.src-dot:before { content: 'Graphviz'; }
+ pre.src-calc:before { content: 'Emacs Calc'; }
+ pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
+ pre.src-fortran:before { content: 'Fortran'; }
+ pre.src-gnuplot:before { content: 'gnuplot'; }
+ pre.src-haskell:before { content: 'Haskell'; }
+ pre.src-hledger:before { content: 'hledger'; }
+ pre.src-java:before { content: 'Java'; }
+ pre.src-js:before { content: 'Javascript'; }
+ pre.src-latex:before { content: 'LaTeX'; }
+ pre.src-ledger:before { content: 'Ledger'; }
+ pre.src-lisp:before { content: 'Lisp'; }
+ pre.src-lilypond:before { content: 'Lilypond'; }
+ pre.src-lua:before { content: 'Lua'; }
+ pre.src-matlab:before { content: 'MATLAB'; }
+ pre.src-mscgen:before { content: 'Mscgen'; }
+ pre.src-ocaml:before { content: 'Objective Caml'; }
+ pre.src-octave:before { content: 'Octave'; }
+ pre.src-org:before { content: 'Org mode'; }
+ pre.src-oz:before { content: 'OZ'; }
+ pre.src-plantuml:before { content: 'Plantuml'; }
+ pre.src-processing:before { content: 'Processing.js'; }
+ pre.src-python:before { content: 'Python'; }
+ pre.src-R:before { content: 'R'; }
+ pre.src-ruby:before { content: 'Ruby'; }
+ pre.src-sass:before { content: 'Sass'; }
+ pre.src-scheme:before { content: 'Scheme'; }
+ pre.src-screen:before { content: 'Gnu Screen'; }
+ pre.src-sed:before { content: 'Sed'; }
+ pre.src-sh:before { content: 'shell'; }
+ pre.src-sql:before { content: 'SQL'; }
+ pre.src-sqlite:before { content: 'SQLite'; }
+ /* additional languages in org.el's org-babel-load-languages alist */
+ pre.src-forth:before { content: 'Forth'; }
+ pre.src-io:before { content: 'IO'; }
+ pre.src-J:before { content: 'J'; }
+ pre.src-makefile:before { content: 'Makefile'; }
+ pre.src-maxima:before { content: 'Maxima'; }
+ pre.src-perl:before { content: 'Perl'; }
+ pre.src-picolisp:before { content: 'Pico Lisp'; }
+ pre.src-scala:before { content: 'Scala'; }
+ pre.src-shell:before { content: 'Shell Script'; }
+ pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
+ /* additional language identifiers per "defun org-babel-execute"
+ in ob-*.el */
+ pre.src-cpp:before { content: 'C++'; }
+ pre.src-abc:before { content: 'ABC'; }
+ pre.src-coq:before { content: 'Coq'; }
+ pre.src-groovy:before { content: 'Groovy'; }
+ /* additional language identifiers from org-babel-shell-names in
+ ob-shell.el: ob-shell is the only babel language using a lambda to put
+ the execution function name together. */
+ pre.src-bash:before { content: 'bash'; }
+ pre.src-csh:before { content: 'csh'; }
+ pre.src-ash:before { content: 'ash'; }
+ pre.src-dash:before { content: 'dash'; }
+ pre.src-ksh:before { content: 'ksh'; }
+ pre.src-mksh:before { content: 'mksh'; }
+ pre.src-posh:before { content: 'posh'; }
+ /* Additional Emacs modes also supported by the LaTeX listings package */
+ pre.src-ada:before { content: 'Ada'; }
+ pre.src-asm:before { content: 'Assembler'; }
+ pre.src-caml:before { content: 'Caml'; }
+ pre.src-delphi:before { content: 'Delphi'; }
+ pre.src-html:before { content: 'HTML'; }
+ pre.src-idl:before { content: 'IDL'; }
+ pre.src-mercury:before { content: 'Mercury'; }
+ pre.src-metapost:before { content: 'MetaPost'; }
+ pre.src-modula-2:before { content: 'Modula-2'; }
+ pre.src-pascal:before { content: 'Pascal'; }
+ pre.src-ps:before { content: 'PostScript'; }
+ pre.src-prolog:before { content: 'Prolog'; }
+ pre.src-simula:before { content: 'Simula'; }
+ pre.src-tcl:before { content: 'tcl'; }
+ pre.src-tex:before { content: 'TeX'; }
+ pre.src-plain-tex:before { content: 'Plain TeX'; }
+ pre.src-verilog:before { content: 'Verilog'; }
+ pre.src-vhdl:before { content: 'VHDL'; }
+ pre.src-xml:before { content: 'XML'; }
+ pre.src-nxml:before { content: 'XML'; }
+ /* add a generic configuration mode; LaTeX export needs an additional
+ (add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
+ pre.src-conf:before { content: 'Configuration File'; }
+
+ table { border-collapse:collapse; }
+ caption.t-above { caption-side: top; }
+ caption.t-bottom { caption-side: bottom; }
+ td, th { vertical-align:top; }
+ th.org-right { text-align: center; }
+ th.org-left { text-align: center; }
+ th.org-center { text-align: center; }
+ td.org-right { text-align: right; }
+ td.org-left { text-align: left; }
+ td.org-center { text-align: center; }
+ dt { font-weight: bold; }
+ .footpara { display: inline; }
+ .footdef { margin-bottom: 1em; }
+ .figure { padding: 1em; }
+ .figure p { text-align: center; }
+ .equation-container {
+ display: table;
+ text-align: center;
+ width: 100%;
+ }
+ .equation {
+ vertical-align: middle;
+ }
+ .equation-label {
+ display: table-cell;
+ text-align: right;
+ vertical-align: middle;
+ }
+ .inlinetask {
+ padding: 10px;
+ border: 2px solid gray;
+ margin: 10px;
+ background: #ffffcc;
+ }
+ #org-div-home-and-up
+ { text-align: right; font-size: 70%; white-space: nowrap; }
+ textarea { overflow-x: auto; }
+ .linenr { font-size: smaller }
+ .code-highlighted { background-color: #ffff00; }
+ .org-info-js_info-navigation { border-style: none; }
+ #org-info-js_console-label
+ { font-size: 10px; font-weight: bold; white-space: nowrap; }
+ .org-info-js_search-highlight
+ { background-color: #ffff00; color: #000000; font-weight: bold; }
+ .org-svg { }
+</style>
+<link rel="stylesheet" type="text/css" href="https://thomasf.github.io/solarized-css/solarized-dark.min.css" />
+<script type="text/x-mathjax-config">
+ MathJax.Hub.Config({
+ displayAlign: "center",
+ displayIndent: "0em",
+
+ "HTML-CSS": { scale: 100,
+ linebreaks: { automatic: "false" },
+ webFont: "TeX"
+ },
+ SVG: {scale: 100,
+ linebreaks: { automatic: "false" },
+ font: "TeX"},
+ NativeMML: {scale: 100},
+ TeX: { equationNumbers: {autoNumber: "AMS"},
+ MultLineWidth: "85%",
+ TagSide: "right",
+ TagIndent: ".8em"
+ }
+});
+</script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
+</head>
+<body>
+<div id="content" class="content">
+<h1 class="title">Fifth - language</h1>
+<div id="table-of-contents" role="doc-toc">
+<h2>Table of Contents</h2>
+<div id="text-table-of-contents" role="doc-toc">
+<ul>
+<li><a href="#orgfe5302c">1. Fifth source format</a>
+<ul>
+<li><a href="#orge4e9f7d">1.1. FSCII</a></li>
+</ul>
+</li>
+<li><a href="#orge63cf49">2. Fifth commands</a>
+<ul>
+<li><a href="#org25bc695">2.1. Compilation & miscellaneous</a></li>
+<li><a href="#orgc47a7bb">2.2. Conditionals & control flow</a></li>
+<li><a href="#org572f33f">2.3. Disk & file access</a></li>
+<li><a href="#org89deb72">2.4. Dynamic memory</a></li>
+<li><a href="#orgea457a7">2.5. Graphics and text</a></li>
+<li><a href="#orge721086">2.6. Math, memory & stack manipulation</a></li>
+<li><a href="#orgf17027f">2.7. Dynamic & static strings</a></li>
+</ul>
+</li>
+</ul>
+</div>
+</div>
+<ul class="org-ul">
+<li><a href="5TH_ET.txt">Example Fifth source file - text editor</a></li>
+</ul>
+
+<div id="outline-container-orgfe5302c" class="outline-2">
+<h2 id="orgfe5302c"><span class="section-number-2">1.</span> Fifth source format</h2>
+<div class="outline-text-2" id="text-1">
+<p>
+Fifth uses a different character table and codes than ASCII (still
+almost similar). I call it FSCII (Fifth Standard Code for Information
+Interchange) for example space character is not 32 but 255 instead. I
+plan to use mainly HEX numbers, and create new characters to represent
+numeric values. So typical nemric characters "0123…" is treated
+like ordinary letters.
+</p>
+</div>
+<div id="outline-container-orge4e9f7d" class="outline-3">
+<h3 id="orge4e9f7d"><span class="section-number-3">1.1.</span> FSCII</h3>
+<div class="outline-text-3" id="text-1-1">
+<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
+
+
+<colgroup>
+<col class="org-right" />
+
+<col class="org-left" />
+
+<col class="org-left" />
+</colgroup>
+<thead>
+<tr>
+<th scope="col" class="org-right">DEC</th>
+<th scope="col" class="org-left">HEX</th>
+<th scope="col" class="org-left">function</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td class="org-right">0 - 15</td>
+<td class="org-left">0 - F</td>
+<td class="org-left">HEX numbers</td>
+</tr>
+
+<tr>
+<td class="org-right">252</td>
+<td class="org-left">FC</td>
+<td class="org-left">backspace</td>
+</tr>
+
+<tr>
+<td class="org-right">253</td>
+<td class="org-left">FD</td>
+<td class="org-left">tabulator (TAB)</td>
+</tr>
+
+<tr>
+<td class="org-right">254</td>
+<td class="org-left">FE</td>
+<td class="org-left">carriage return (CR)</td>
+</tr>
+
+<tr>
+<td class="org-right">255</td>
+<td class="org-left">FF</td>
+<td class="org-left">space</td>
+</tr>
+
+<tr>
+<td class="org-right">else</td>
+<td class="org-left"> </td>
+<td class="org-left">ordinary characters, same as in ASCII.</td>
+</tr>
+</tbody>
+</table>
+</div>
+</div>
+</div>
+<div id="outline-container-orge63cf49" class="outline-2">
+<h2 id="orge63cf49"><span class="section-number-2">2.</span> Fifth commands</h2>
+<div class="outline-text-2" id="text-2">
+</div>
+<div id="outline-container-org25bc695" class="outline-3">
+<h3 id="org25bc695"><span class="section-number-3">2.1.</span> Compilation & miscellaneous</h3>
+<div class="outline-text-3" id="text-2-1">
+<p class="verse">
+init module ( – )<br />
+                First module, control is passed to on startup. Contains<br />
+                initialization routines. Also it is the last core module.<br />
+                All new modules on top of it comes as result of executing<br />
+                external source files.<br />
+<br />
+head <name> ( – ) compiles new dictionary entry without specifying<br />
+                new module type.<br />
+                ex: head myentry<br />
+<br />
+: <name> ( – ) creates new code module<br />
+; ( – ) ends module (immideate)<br />
+                ex: : hello ." hi there" ;<br />
+<br />
+const <name> ( n – ) defines new constant.<br />
+                ex: 2147483647 const max<br />
+<br />
+:i <name> ( – ) same as ":" but this module will be executed<br />
+                immideately even in compile mode.<br />
+                ex: :i ( 41 scan ;<br />
+<br />
+create <name> ( – ) same as "head" , but specify module type as data.<br />
+                ex: create LotoResults 5 , 13 , 52 , 12 , 11 , 3 ,<br />
+<br />
+allot ( n – ) allocate n bytes in dictionary.<br />
+                ex: create MyArray 100 allot<br />
+<br />
+" <string>" ( – ) compile string and its size into core.<br />
+                ex: create Mystring " This is it's contects"<br />
+<br />
+str <name> <string>" ( – ) just shorter way for defining strings.<br />
+                ex: str Mystring This is it's contenc"<br />
+<br />
+var <name> ( – ) define new 32 bit variable.<br />
+                ex: var result<br />
+<br />
+' <module> ( – n ) return memory address of given entry.<br />
+                ex: ' init<br />
+<br />
+forget <name> ( – ) erases from RAM given entry and all entries what was<br />
+                defined after it.<br />
+                ex: forget myprog<br />
+<br />
+[ ( – ) set interpret mode (immideate)<br />
+] ( n – ) set compile mode and compile top stack element<br />
+                in as literal. Together [ …. ] cobination provides good<br />
+                way to compute some values only once, at compile time,<br />
+                rather than every time while program is running.<br />
+                ex: : calculate - [ 4 MyConst1 + MyConst2 * ] ;<br />
+<br />
+defer <name> ( – ) creates new module, with jump instruction.<br />
+                Later address where to jump can be modified by "is" command.<br />
+                This provides method of foward referencing. So you can use<br />
+                modules what not jet exist.<br />
+is ( address1 address2 – ) address1 - where to jump, address2 -<br />
+                address of module created by defer command.<br />
+                ex: defer dispver<br />
+                        : run dispver ." running …" ;<br />
+                               … whatever …<br />
+                        : (dispver ." Version 9.99 " ;<br />
+                        ' (dispver ' dispver is<br />
+<br />
+                Now if I type "run" on the screen appears:<br />
+                        Version 9.99 running …<br />
+<br />
+asc <char> ( – ) reads char ascii code and treats it as literal.<br />
+                (immideate)<br />
+                ex: : BreakLine 30 do asc - emit loop ;<br />
+                                 same as:<br />
+                    : BreakLine 30 do 45 emit loop ;<br />
+<br />
+dyninc ( handle – ) execute code in dynamic memory handle.<br />
+                automatically deallocates it when done.<br />
+<br />
+include ( filenumber – ) execute code in specified file.<br />
+<br />
+words ( – ) display existing blocks in core.<br />
+<br />
+bye ( – ) exit from Fifth<br />
+<br />
+fkey ( – c )<br />
+                Read one byte from input stream.<br />
+<br />
+sadd ( c addr – )<br />
+                Add one byte "c" to string located at "addr" and updates<br />
+                string length.<br />
+<br />
+scan ( c – )<br />
+                Read input stream and store it to pad until it finds c .<br />
+                It ignores all "c" bytes until it finds any non "c" byte.<br />
+                in other words:<br />
+                                c is: "<br />
+                         input stream: """"This is test !"aoeu idh<br />
+                               result: This is test !<br />
+<br />
+                Is useful for breaking text lines into words.<br />
+<br />
+skey ( – c )<br />
+                So called safe "fkey". Reads data from input stream<br />
+                but converts characters with ASCII codes: 9 13 10<br />
+                to spaces.<br />
+<br />
+str=str? ( adr1 adr2 – result )<br />
+                Compares string at "adr1" with string at "adr2", returns<br />
+                true flag if they are equal or false if they are not.<br />
+                true = -1<br />
+                false = 0<br />
+<br />
+find ( – addr )<br />
+                Searches whole dictionary for word in "pad". If found,<br />
+                returns it address, if not, returns 0.<br />
+<br />
+execute ( – )<br />
+                Execute word located in "pad". Depending on "mode".<br />
+<br />
+dta ( addr – DataAddr )<br />
+                Calculates address of dictionary entry data area, from<br />
+                entry point.<br />
+<br />
+2num ( – num result )<br />
+                Attempt to convert string located in "pad" into numeric<br />
+                value. If succeed returns number and true as result.<br />
+                If not, returns whatever and false as result.<br />
+<br />
+dadd ( addr length – )<br />
+                Add to dictionary data located at "addr", with specified<br />
+                length.<br />
+<br />
+lit ( n – )<br />
+                Act with number depending on "mode". When interpreting,<br />
+                leaves it in stack.<br />
+<br />
+<br />
+incmod ( addr – )<br />
+                Add to dictionary data located at "addr"+1 , length is taken<br />
+                from "addr".<br />
+<br />
+here ( – n )<br />
+                return "h" contents.<br />
+<br />
+mode var 8 bit<br />
+                Holds input stream parser operation mode.<br />
+                0 = interpreting<br />
+                1 = compiling<br />
+<br />
+pad var 128 bytes<br />
+                Holds temprorary strings.<br />
+<br />
+h var 32 bit<br />
+                Pointer to free byte in memory, always at the end of the<br />
+                dictionary. Each time when something is stored<br />
+                by "c," command, pointer is incareased.<br />
+<br />
+lp var 32 bit<br />
+                Pointer to last dictionary word. Each time when new word is<br />
+                compiled or erased by "forget", this pointer is updated.<br />
+<br />
+modulechk ( Dstr<filename> – ) check if module is loaded, if not<br />
+                immideately load it.<br />
+<br />
+ne ( entrydata entrytype – ) Compile new dictionary entry.<br />
+                It's name must be in "pad".<br />
+</p>
+</div>
+</div>
+<div id="outline-container-orgc47a7bb" class="outline-3">
+<h3 id="orgc47a7bb"><span class="section-number-3">2.2.</span> Conditionals & control flow</h3>
+<div class="outline-text-3" id="text-2-2">
+<p class="verse">
+if ( flag – ) (immideate)<br />
+                "if 1.. else 2.. then" or<br />
+                "if 1.. then" construction. Conditional execution.<br />
+                Performs "1.." if "flag" was true,<br />
+                elseway performs "2.." if exist. Execution continues after<br />
+                word "then".<br />
+                ex: 1 if ." nonzero" else ." zero" then<br />
+<br />
+>= ( n1 n2 – result ) true if (n1 = n2) or (n1 > n2)<br />
+                ex: 5 3 >= if ." first number is greater or equal" then<br />
+<br />
+<= ( n1 n2 – result ) true if (n1 = n2) or (n1 < n2)<br />
+= ( n1 n2 – result ) true if n1 = n2<br />
+<br />
+do ( count – ) (immideate)<br />
+                "do .. loop" construction. Performs ".." "count" times.<br />
+                In every step "count" is decareased until it is 0.<br />
+                ex: : test 5 do i .d loop ;<br />
+                result: 4 3 2 1 0<br />
+<br />
+doexit ( – ) exit from "do .. loop"<br />
+<br />
+for ( count top – ) (immideate)<br />
+                "for .. loop" construction. Performs ".." (top - count) times.<br />
+                In every step "count" is incareased until it reaches "top" .<br />
+                ex: : test 4 10 for i .d loop ;<br />
+                result: 4 5 6 7 8 9<br />
+<br />
+forexit ( – ) exit from "for .. loop"<br />
+<br />
+until ( – ) (immideate)<br />
+                "until .. loop" construction. Performs ".." until flag become<br />
+                true. False by default. Top of return stack holds flag.<br />
+<br />
+done ( – ) exit from "until .. loop"<br />
+<br />
+</p>
+</div>
+</div>
+<div id="outline-container-org572f33f" class="outline-3">
+<h3 id="org572f33f"><span class="section-number-3">2.3.</span> Disk & file access</h3>
+<div class="outline-text-3" id="text-2-3">
+<p class="verse">
+diskload ( FromDisk ToMem amount – )<br />
+                Load specified abount of bytes from disk into memory.<br />
+<br />
+disksave ( FromMem ToDisk amount – )<br />
+                save specified abount of bytes from memory into disk.<br />
+<br />
+format ( – ) Erase all files.<br />
+<br />
+fsDfilesize@ ( handle – size )<br />
+                Return size of opened file.<br />
+<br />
+fsDcurloc@ ( handle – location )<br />
+                Return current location in file.<br />
+<br />
+fsDupdated@ ( handle – updated? )<br />
+                Return true if file was updated,<br />
+                ie. write operations occured.<br />
+<br />
+fssave ( FromMem DestFileHandle amount – )<br />
+                Save data to file.<br />
+<br />
+fsload ( SrcFileHandle ToMem amount – )<br />
+                Load data from file.<br />
+<br />
+fseof ( handle – bytesLeft )<br />
+                Return amount of bytes left till end of file.<br />
+                Useful before read operation.<br />
+<br />
+fsls ( – ) List all files and lists (directories,folders)<br />
+                in current path.<br />
+<br />
+fslsr ( – ) Same as "fsls" but recursively scans also sub lists.<br />
+<br />
+fscl ( DynStrHand – )<br />
+                Change list (path)<br />
+<br />
+fscreate ( DynStrHand – DescPnt )<br />
+                Create new file or list. Can create multiple lists at once.<br />
+                ex: when creating:<br />
+                    "\listGAMES\listSTRATEGY\listSIMWORLD\5th-runme"<br />
+                and only "\listGAMES\" already exist, then<br />
+                "listSTRATEGY" and "listSIMWORLD" lists will be created,<br />
+                and empty file "5th-runme" placed in there.<br />
+<br />
+fsDsave ( DynHand<data> DynStrHand<filename> – )<br />
+                Create new file and save all data from dynamic memory<br />
+                block to it.<br />
+<br />
+fsDload ( DynStr<SrcFileName> DynHand<DataDest> – )<br />
+                Load whole file into dynamic memory block.<br />
+<br />
+fsDloadnew ( DynStr<SrcFileName> – DynHand<DataDest> )<br />
+                Load whole file into new dynamic memory block.<br />
+</p>
+</div>
+</div>
+<div id="outline-container-org89deb72" class="outline-3">
+<h3 id="org89deb72"><span class="section-number-3">2.4.</span> Dynamic memory</h3>
+<div class="outline-text-3" id="text-2-4">
+<p class="verse">
+dynal ( size – handle )<br />
+                Allocate dynamic memory block and return it's handle.<br />
+<br />
+dynde ( handle – )<br />
+                Deallocate dynamic memory block.<br />
+<br />
+dynp ( handle – addr )<br />
+                Returns pointer to memory where dynamic block<br />
+                data begins.<br />
+<br />
+dyns ( handle – size )<br />
+                Returns size of dynamic block.<br />
+<br />
+dynresize ( NewSize handle – )<br />
+                Nondestructively resize dynamic block.<br />
+<br />
+dync@ ( addr handle )<br />
+                Read one byte from dynamic block.<br />
+<br />
+dync! ( byte addr dynhandle )<br />
+                Write one byte to dynamic block.<br />
+<br />
+dyn@ ( addr handle )<br />
+                Read 32 bit number from dynamic block.<br />
+                Address will spacify, whitch number, not byte.<br />
+<br />
+dyn! ( 32BitNum addr dynhandle )<br />
+                Write 32 bit number to dynamic block.<br />
+                Address will spacify, whitch number, not byte.<br />
+<br />
+dyncon ( size "name" – )<br />
+                Allocate dynamic block with specified size, and<br />
+                create constant honding its handle.<br />
+                ex: 100 dyncon MyNewBlock<br />
+<br />
+dyn. ( handle – )<br />
+                Write contenc of dynamic memory block to screen.<br />
+</p>
+</div>
+</div>
+<div id="outline-container-orgea457a7" class="outline-3">
+<h3 id="orgea457a7"><span class="section-number-3">2.5.</span> Graphics and text</h3>
+<div class="outline-text-3" id="text-2-5">
+<p class="verse">
+. ( n – ) print number on screen<br />
+<br />
+d. ( n – ) print number on screen in decimal<br />
+<br />
+? ( addr – ) print 32 bit value located at addr.<br />
+<br />
+." <string>" ( – ) print string into screen. Immideately<br />
+                compiles.<br />
+                ex: : greeting ." Hello, World" ;<br />
+<br />
+tab. ( – ) print tabulator<br />
+<br />
+calccol ( b g r – c ) calculate color what best matches given<br />
+                Blue Green & Red values. Values must be in range 0 - 255.<br />
+<br />
+imgalloc ( xsize ysize – imgbuf ) allocate image buffer for<br />
+                specified size.<br />
+<br />
+imgsize ( imgbuf – ) print on the screen X & Y size of image<br />
+                buffer.<br />
+<br />
+point ( x y imgbuf – addr ) returns memory address for specified<br />
+                pixel.<br />
+<br />
+pset ( color x y imgbuf – ) set graphic point<br />
+<br />
+boxf ( x1 x2 y1 y2 imgbuf color – ) draw filled box<br />
+<br />
+cls ( imgbuf – ) clear image buffer<br />
+<br />
+setpal ( b g r color – ) set palette value for specified color.<br />
+                values bust be in size 0 - 63.<br />
+<br />
+putchar ( char color x y imgbuf – ) put graphic character in<br />
+                imagebuffer to specified (x & y) location.<br />
+<br />
+scroll ( x y imgbuf – ) scroll in imgbuf.<br />
+<br />
+scrollf ( color x y screen – ) scroll and fill empty space with<br />
+                given color.<br />
+<br />
+at! ( x y – ) set cursor location<br />
+curc! ( color – ) set text color<br />
+curb! ( solor – ) set backround color<br />
+<br />
+colnorm ( – ) set text color to normal<br />
+colneg ( – ) set text color to negative (selected)<br />
+<br />
+dyntype ( dynhandle – ) display contenc of dynamic memory on screen<br />
+fsdisp ( file – ) clear screen, display file, and wait for key<br />
+<br />
+type ( addr length – )<br />
+                Types on the screen string, from memory at addr and<br />
+                specified length.<br />
+<br />
+write ( addr – )<br />
+                Types on the screen string, from memory at "addr"+1<br />
+                length is taken from "addr" .<br />
+<br />
+screen const 32 bit<br />
+                Holds handle of screen buffer.<br />
+<br />
+copyscreen ( SrcImgHandle DestImgHandle – ) copy contenc of source<br />
+                image to destination image. Source and destination images<br />
+                must have same size.<br />
+</p>
+</div>
+</div>
+<div id="outline-container-orge721086" class="outline-3">
+<h3 id="orge721086"><span class="section-number-3">2.6.</span> Math, memory & stack manipulation</h3>
+<div class="outline-text-3" id="text-2-6">
+<p class="verse">
+off ( n – ) writes 0 to given address, good for zeroing variable.<br />
+                ex: MyVariable off<br />
+on ( n – ) writes -1 (true flag) to given address.<br />
+                ex: MyVariable on<br />
+<br />
+2dup ( n1 n2 – n1 n2 n1 n2 )<br />
+2drop ( n1 n2 – )<br />
+nip ( n1 n2 – n2 )<br />
+neg ( n1 – -n1 ) negotiate<br />
+bit@ ( n bit – result ) return specified bit from n.<br />
+                ex: 38 2 bit@ (result will be 1)<br />
+to32bit ( n1 n2 n3 n4 – n32 ) treat 4 last stack elements as bytes<br />
+                and unite them into 32 bit dword. Most significant byte<br />
+                on top.<br />
+                ex: 12 76 23 11 to32bit result: 186076172<br />
+<br />
+to8bit ( n32 – n1 n2 n3 n4 ) break 32 bit number into 4 bytes.<br />
+                Useful if you need to send 32 bit numbers thru 8 bit COM<br />
+                port.<br />
+                ex: 186076172 to8bit result: 12 76 23 11<br />
+<br />
+mod ( n1 n2 – reminder ) divide n1 by n2 and returns reminder.<br />
+                ex: 12 5 mod result: 2<br />
+<br />
+bound ( low n high – n ) check if n is in given bounds,<br />
+                if not then incarease/decarease it to match bounds.<br />
+                ex: 5 80 15 bound result: 15<br />
+                    5 10 15 bound result: 10<br />
+                    5 -10 15 bound result: 5<br />
+<br />
+bound? ( low n high – result ) returns true if n is in the<br />
+                given bounds.<br />
+<br />
+tab ( col – spaces) calculate amount of spaces to add<br />
+                ta reach next tabulation from given column.<br />
+<br />
+count ( addr – addr+1 n )<br />
+                Useful for returning bytes from constantly incareasing<br />
+                address. Module "type" is nice example.<br />
+<br />
+c, ( n – )<br />
+                store one byte at memory specified by "h". And incarease<br />
+                "h" by 1.<br />
+<br />
+, ( n – )<br />
+                store 32 bit number at memory specified by "h". And<br />
+                incarease "h" by 4.<br />
+<br />
+cmove ( addr1 addr2 n – )<br />
+                copy "n" amount of bytes from memory at "addr1" to memory<br />
+                at "addr2".<br />
+<br />
+rnd ( limit – result )<br />
+                generates random number in range 0 to "limit"-1.<br />
+<br />
+abs ( n – |n| )<br />
+                returns absolute value of "n"<br />
+</p>
+</div>
+</div>
+<div id="outline-container-orgf17027f" class="outline-3">
+<h3 id="orgf17027f"><span class="section-number-3">2.7.</span> Dynamic & static strings</h3>
+<div class="outline-text-3" id="text-2-7">
+<p>
+Fifth supports both static and dynamic strings. Static strings must
+have predefined space reserved, and string mustn't exceed this
+length. They manipulation is faster. But they use more memory. Static
+string memory address is used to refer to the string.
+</p>
+
+<p>
+Dynamic strings can have at any time length form 0 to 0FFh, They take
+up only memory they currently need. They are held in dynamic memory
+blocks, so dynamic block handle is used to refer to this string.
+</p>
+
+<p>
+Both types of strings are stored in the way, where first (0th) byte
+holds current string length, following bytes are string itself.
+</p>
+
+
+<p class="verse">
+Dynamic:<br />
+<br />
+Dstral ( – handle )<br />
+                Allocate new string.<br />
+<br />
+Dstrlen ( handle – length )<br />
+                Return string length.<br />
+<br />
+c+Dstr ( chr handle – )<br />
+                Add one byte to end of the string.<br />
+<br />
+c+lDstr ( chr handle – )<br />
+                Add one byte to left side (beginning) of the string.<br />
+<br />
+Dstr. ( handle – )<br />
+                Write contec of string into screen.<br />
+<br />
+Dstrsure ( size Dstr – )<br />
+                Makes sure that at least rquested<br />
+                "size" (amount of characters) is allocated for given<br />
+                dynamic string.<br />
+<br />
+Dstr2str ( handle address – )<br />
+                Copy dyamic string into static memory space.<br />
+<br />
+str2Dstr ( address handle – )<br />
+                Copy static string into dyamic string.<br />
+<br />
+Dstr+str ( Dstr addr – )<br />
+                Add contenc of dynamic string to static string.<br />
+<br />
+D" any string" ( – Dstr )<br />
+                Moves specified string into dynamic string called "defDstr".<br />
+<br />
+D> any_string ( – Dstr )<br />
+                Moves specified string into dynamic string called "defDstr".<br />
+                Space marks end of string!<br />
+<br />
+D>2 any_string ( – Dstr )<br />
+                Moves specified string into dynamic string called "defDstr2".<br />
+                Space marks end of string!<br />
+<br />
+Dstr+Dstr ( Dstr1 Dstr2 – )<br />
+                Adds "Dstr1" to "Dstr2" and places result into "Dstr2".<br />
+<br />
+Dstrclear ( Dstr – )<br />
+                Clears contenc of dynamic string.<br />
+<br />
+Dstr2Dstr ( Dstr1 Dstr2 – )<br />
+                Moves "Dstr1" to "Dstr2".<br />
+Dstr ( data" name – )<br />
+                Creates new dynamic string and moves specified data into it.<br />
+                Then creates new constant with given "name" holding created<br />
+                dynamic string handle.<br />
+<br />
+                ex: Dstr Hello, my name is Sven!" message \ creates it<br />
+                    message Dstr. \ tests it<br />
+<br />
+Dstrlscan ( char Dstr – loc )<br />
+                Searches dynamic string for "char", from left to right,<br />
+                returns first found "char" location in string, or 0,<br />
+                if not found.<br />
+<br />
+Dstrrscan ( char Dstr – loc )<br />
+                Searches dynamic string for "char", from right to left,<br />
+                returns first found "char" location in string, or 0,<br />
+                if not found.<br />
+<br />
+Dstrlscane ( char Dstr – loc )<br />
+                Same as "Dstrlscan" buf returns string length+1 as location.<br />
+ÿ<br />
+Dstrleft ( amo Dstr – )<br />
+                Only specified amount of characters from left remains<br />
+                in dynamic string. ie. cut right part out.<br />
+<br />
+Dstrright ( amo Dstr – )<br />
+                Only specified amount of characters from right remains<br />
+                in dynamic string. ie. cut left part out.<br />
+<br />
+Dstrcutl ( amo Dstr – )<br />
+                Cut specified amount of characters from left of dynamic<br />
+                string out.<br />
+<br />
+Dstrsp ( char Dstr1 Dstr2 – )<br />
+                Separate dynamic string in Dstr1 into two parts,<br />
+                using "char" as separator. First part will be stored in<br />
+                "Dstr2", second part in "Dstr1".<br />
+                ex: asc \ \ ..separator<br />
+                    D> listF\listLIB\5TH_DRVMOUSE \ ..separate from<br />
+                    defDstr2 \ ..place result in<br />
+                    Dstrsp \ separation command<br />
+                    defDstr Dstr. \ will be: listLIB\5TH_DRVMOUSE<br />
+                    defDstr2 Dstr. \ will be: listF<br />
+<br />
+Dv ( addr – )<br />
+                Allocates empty dynamic string, and places it's handle<br />
+                into given address.<br />
+<br />
+Df ( addr – )<br />
+                Reads dynamic string handle from given address and<br />
+                deallocates (frees) it.<br />
+<br />
+ex: var mystring1<br />
+        : testmodule<br />
+        mystring1 Dv \ allocates string<br />
+<br />
+                <whatever><br />
+<br />
+        mystring1 Df ; \ deallocates it again when no longer needed.<br />
+</p>
+</div>
+</div>
+</div>
+</div>
+<div id="postamble" class="status">
+<p class="author">Author: Svjatoslav Agejenko</p>
+<p class="date">Created: 2023-09-19 Tue 18:07</p>
+<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
+</div>
+</body>
+</html>
--- /dev/null
+:PROPERTIES:
+:ID: da7fff9b-0b67-4843-828a-52a404d7f401
+:END:
+
+#+TITLE: Fifth - language
+#+AUTHOR: Svjatoslav Agejenko
+#+LANGUAGE: en
+
+- [[file:5TH_ET.txt][Example Fifth source file - text editor]]
+
+* Fifth source format
+Fifth uses a different character table and codes than ASCII (still
+almost similar). I call it FSCII (Fifth Standard Code for Information
+Interchange) for example space character is not 32 but 255 instead. I
+plan to use mainly HEX numbers, and create new characters to represent
+numeric values. So typical nemric characters "0123..." is treated
+like ordinary letters.
+** FSCII
+
+| DEC | HEX | function |
+|--------+-------+----------------------------------------|
+| 0 - 15 | 0 - F | HEX numbers |
+| 252 | FC | backspace |
+| 253 | FD | tabulator (TAB) |
+| 254 | FE | carriage return (CR) |
+| 255 | FF | space |
+| else | | ordinary characters, same as in ASCII. |
+* Fifth commands
+** Compilation & miscellaneous
+#+BEGIN_VERSE
+init module ( -- )
+ First module, control is passed to on startup. Contains
+ initialization routines. Also it is the last core module.
+ All new modules on top of it comes as result of executing
+ external source files.
+
+head <name> ( -- ) compiles new dictionary entry without specifying
+ new module type.
+ ex: head myentry
+
+: <name> ( -- ) creates new code module
+; ( -- ) ends module (immideate)
+ ex: : hello ." hi there" ;
+
+const <name> ( n -- ) defines new constant.
+ ex: 2147483647 const max
+
+:i <name> ( -- ) same as ":" but this module will be executed
+ immideately even in compile mode.
+ ex: :i ( 41 scan ;
+
+create <name> ( -- ) same as "head" , but specify module type as data.
+ ex: create LotoResults 5 , 13 , 52 , 12 , 11 , 3 ,
+
+allot ( n -- ) allocate n bytes in dictionary.
+ ex: create MyArray 100 allot
+
+" <string>" ( -- ) compile string and its size into core.
+ ex: create Mystring " This is it's contects"
+
+str <name> <string>" ( -- ) just shorter way for defining strings.
+ ex: str Mystring This is it's contenc"
+
+var <name> ( -- ) define new 32 bit variable.
+ ex: var result
+
+' <module> ( -- n ) return memory address of given entry.
+ ex: ' init
+
+forget <name> ( -- ) erases from RAM given entry and all entries what was
+ defined after it.
+ ex: forget myprog
+
+[ ( -- ) set interpret mode (immideate)
+] ( n -- ) set compile mode and compile top stack element
+ in as literal. Together [ .... ] cobination provides good
+ way to compute some values only once, at compile time,
+ rather than every time while program is running.
+ ex: : calculate - [ 4 MyConst1 + MyConst2 * ] ;
+
+defer <name> ( -- ) creates new module, with jump instruction.
+ Later address where to jump can be modified by "is" command.
+ This provides method of foward referencing. So you can use
+ modules what not jet exist.
+is ( address1 address2 -- ) address1 - where to jump, address2 -
+ address of module created by defer command.
+ ex: defer dispver
+ : run dispver ." running ..." ;
+ ... whatever ...
+ : (dispver ." Version 9.99 " ;
+ ' (dispver ' dispver is
+
+ Now if I type "run" on the screen appears:
+ Version 9.99 running ...
+
+asc <char> ( -- ) reads char ascii code and treats it as literal.
+ (immideate)
+ ex: : BreakLine 30 do asc - emit loop ;
+ same as:
+ : BreakLine 30 do 45 emit loop ;
+
+dyninc ( handle -- ) execute code in dynamic memory handle.
+ automatically deallocates it when done.
+
+include ( filenumber -- ) execute code in specified file.
+
+words ( -- ) display existing blocks in core.
+
+bye ( -- ) exit from Fifth
+
+fkey ( -- c )
+ Read one byte from input stream.
+
+sadd ( c addr -- )
+ Add one byte "c" to string located at "addr" and updates
+ string length.
+
+scan ( c -- )
+ Read input stream and store it to pad until it finds c .
+ It ignores all "c" bytes until it finds any non "c" byte.
+ in other words:
+ c is: "
+ input stream: """"This is test !"aoeu idh
+ result: This is test !
+
+ Is useful for breaking text lines into words.
+
+skey ( -- c )
+ So called safe "fkey". Reads data from input stream
+ but converts characters with ASCII codes: 9 13 10
+ to spaces.
+
+str=str? ( adr1 adr2 -- result )
+ Compares string at "adr1" with string at "adr2", returns
+ true flag if they are equal or false if they are not.
+ true = -1
+ false = 0
+
+find ( -- addr )
+ Searches whole dictionary for word in "pad". If found,
+ returns it address, if not, returns 0.
+
+execute ( -- )
+ Execute word located in "pad". Depending on "mode".
+
+dta ( addr -- DataAddr )
+ Calculates address of dictionary entry data area, from
+ entry point.
+
+2num ( -- num result )
+ Attempt to convert string located in "pad" into numeric
+ value. If succeed returns number and true as result.
+ If not, returns whatever and false as result.
+
+dadd ( addr length -- )
+ Add to dictionary data located at "addr", with specified
+ length.
+
+lit ( n -- )
+ Act with number depending on "mode". When interpreting,
+ leaves it in stack.
+
+
+incmod ( addr -- )
+ Add to dictionary data located at "addr"+1 , length is taken
+ from "addr".
+
+here ( -- n )
+ return "h" contents.
+
+mode var 8 bit
+ Holds input stream parser operation mode.
+ 0 = interpreting
+ 1 = compiling
+
+pad var 128 bytes
+ Holds temprorary strings.
+
+h var 32 bit
+ Pointer to free byte in memory, always at the end of the
+ dictionary. Each time when something is stored
+ by "c," command, pointer is incareased.
+
+lp var 32 bit
+ Pointer to last dictionary word. Each time when new word is
+ compiled or erased by "forget", this pointer is updated.
+
+modulechk ( Dstr<filename> -- ) check if module is loaded, if not
+ immideately load it.
+
+ne ( entrydata entrytype -- ) Compile new dictionary entry.
+ It's name must be in "pad".
+#+END_VERSE
+** Conditionals & control flow
+#+BEGIN_VERSE
+if ( flag -- ) (immideate)
+ "if 1.. else 2.. then" or
+ "if 1.. then" construction. Conditional execution.
+ Performs "1.." if "flag" was true,
+ elseway performs "2.." if exist. Execution continues after
+ word "then".
+ ex: 1 if ." nonzero" else ." zero" then
+
+>= ( n1 n2 -- result ) true if (n1 = n2) or (n1 > n2)
+ ex: 5 3 >= if ." first number is greater or equal" then
+
+<= ( n1 n2 -- result ) true if (n1 = n2) or (n1 < n2)
+= ( n1 n2 -- result ) true if n1 = n2
+
+do ( count -- ) (immideate)
+ "do .. loop" construction. Performs ".." "count" times.
+ In every step "count" is decareased until it is 0.
+ ex: : test 5 do i .d loop ;
+ result: 4 3 2 1 0
+
+doexit ( -- ) exit from "do .. loop"
+
+for ( count top -- ) (immideate)
+ "for .. loop" construction. Performs ".." (top - count) times.
+ In every step "count" is incareased until it reaches "top" .
+ ex: : test 4 10 for i .d loop ;
+ result: 4 5 6 7 8 9
+
+forexit ( -- ) exit from "for .. loop"
+
+until ( -- ) (immideate)
+ "until .. loop" construction. Performs ".." until flag become
+ true. False by default. Top of return stack holds flag.
+
+done ( -- ) exit from "until .. loop"
+
+#+END_VERSE
+** Disk & file access
+#+BEGIN_VERSE
+diskload ( FromDisk ToMem amount -- )
+ Load specified abount of bytes from disk into memory.
+
+disksave ( FromMem ToDisk amount -- )
+ save specified abount of bytes from memory into disk.
+
+format ( -- ) Erase all files.
+
+fsDfilesize@ ( handle -- size )
+ Return size of opened file.
+
+fsDcurloc@ ( handle -- location )
+ Return current location in file.
+
+fsDupdated@ ( handle -- updated? )
+ Return true if file was updated,
+ ie. write operations occured.
+
+fssave ( FromMem DestFileHandle amount -- )
+ Save data to file.
+
+fsload ( SrcFileHandle ToMem amount -- )
+ Load data from file.
+
+fseof ( handle -- bytesLeft )
+ Return amount of bytes left till end of file.
+ Useful before read operation.
+
+fsls ( -- ) List all files and lists (directories,folders)
+ in current path.
+
+fslsr ( -- ) Same as "fsls" but recursively scans also sub lists.
+
+fscl ( DynStrHand -- )
+ Change list (path)
+
+fscreate ( DynStrHand -- DescPnt )
+ Create new file or list. Can create multiple lists at once.
+ ex: when creating:
+ "\listGAMES\listSTRATEGY\listSIMWORLD\5th-runme"
+ and only "\listGAMES\" already exist, then
+ "listSTRATEGY" and "listSIMWORLD" lists will be created,
+ and empty file "5th-runme" placed in there.
+
+fsDsave ( DynHand<data> DynStrHand<filename> -- )
+ Create new file and save all data from dynamic memory
+ block to it.
+
+fsDload ( DynStr<SrcFileName> DynHand<DataDest> -- )
+ Load whole file into dynamic memory block.
+
+fsDloadnew ( DynStr<SrcFileName> -- DynHand<DataDest> )
+ Load whole file into new dynamic memory block.
+#+END_VERSE
+** Dynamic memory
+#+BEGIN_VERSE
+dynal ( size -- handle )
+ Allocate dynamic memory block and return it's handle.
+
+dynde ( handle -- )
+ Deallocate dynamic memory block.
+
+dynp ( handle -- addr )
+ Returns pointer to memory where dynamic block
+ data begins.
+
+dyns ( handle -- size )
+ Returns size of dynamic block.
+
+dynresize ( NewSize handle -- )
+ Nondestructively resize dynamic block.
+
+dync@ ( addr handle )
+ Read one byte from dynamic block.
+
+dync! ( byte addr dynhandle )
+ Write one byte to dynamic block.
+
+dyn@ ( addr handle )
+ Read 32 bit number from dynamic block.
+ Address will spacify, whitch number, not byte.
+
+dyn! ( 32BitNum addr dynhandle )
+ Write 32 bit number to dynamic block.
+ Address will spacify, whitch number, not byte.
+
+dyncon ( size "name" -- )
+ Allocate dynamic block with specified size, and
+ create constant honding its handle.
+ ex: 100 dyncon MyNewBlock
+
+dyn. ( handle -- )
+ Write contenc of dynamic memory block to screen.
+#+END_VERSE
+** Graphics and text
+#+BEGIN_VERSE
+. ( n -- ) print number on screen
+
+d. ( n -- ) print number on screen in decimal
+
+? ( addr -- ) print 32 bit value located at addr.
+
+." <string>" ( -- ) print string into screen. Immideately
+ compiles.
+ ex: : greeting ." Hello, World" ;
+
+tab. ( -- ) print tabulator
+
+calccol ( b g r -- c ) calculate color what best matches given
+ Blue Green & Red values. Values must be in range 0 - 255.
+
+imgalloc ( xsize ysize -- imgbuf ) allocate image buffer for
+ specified size.
+
+imgsize ( imgbuf -- ) print on the screen X & Y size of image
+ buffer.
+
+point ( x y imgbuf -- addr ) returns memory address for specified
+ pixel.
+
+pset ( color x y imgbuf -- ) set graphic point
+
+boxf ( x1 x2 y1 y2 imgbuf color -- ) draw filled box
+
+cls ( imgbuf -- ) clear image buffer
+
+setpal ( b g r color -- ) set palette value for specified color.
+ values bust be in size 0 - 63.
+
+putchar ( char color x y imgbuf -- ) put graphic character in
+ imagebuffer to specified (x & y) location.
+
+scroll ( x y imgbuf -- ) scroll in imgbuf.
+
+scrollf ( color x y screen -- ) scroll and fill empty space with
+ given color.
+
+at! ( x y -- ) set cursor location
+curc! ( color -- ) set text color
+curb! ( solor -- ) set backround color
+
+colnorm ( -- ) set text color to normal
+colneg ( -- ) set text color to negative (selected)
+
+dyntype ( dynhandle -- ) display contenc of dynamic memory on screen
+fsdisp ( file -- ) clear screen, display file, and wait for key
+
+type ( addr length -- )
+ Types on the screen string, from memory at addr and
+ specified length.
+
+write ( addr -- )
+ Types on the screen string, from memory at "addr"+1
+ length is taken from "addr" .
+
+screen const 32 bit
+ Holds handle of screen buffer.
+
+copyscreen ( SrcImgHandle DestImgHandle -- ) copy contenc of source
+ image to destination image. Source and destination images
+ must have same size.
+#+END_VERSE
+** Math, memory & stack manipulation
+#+BEGIN_VERSE
+off ( n -- ) writes 0 to given address, good for zeroing variable.
+ ex: MyVariable off
+on ( n -- ) writes -1 (true flag) to given address.
+ ex: MyVariable on
+
+2dup ( n1 n2 -- n1 n2 n1 n2 )
+2drop ( n1 n2 -- )
+nip ( n1 n2 -- n2 )
+neg ( n1 -- -n1 ) negotiate
+bit@ ( n bit -- result ) return specified bit from n.
+ ex: 38 2 bit@ (result will be 1)
+to32bit ( n1 n2 n3 n4 -- n32 ) treat 4 last stack elements as bytes
+ and unite them into 32 bit dword. Most significant byte
+ on top.
+ ex: 12 76 23 11 to32bit result: 186076172
+
+to8bit ( n32 -- n1 n2 n3 n4 ) break 32 bit number into 4 bytes.
+ Useful if you need to send 32 bit numbers thru 8 bit COM
+ port.
+ ex: 186076172 to8bit result: 12 76 23 11
+
+mod ( n1 n2 -- reminder ) divide n1 by n2 and returns reminder.
+ ex: 12 5 mod result: 2
+
+bound ( low n high -- n ) check if n is in given bounds,
+ if not then incarease/decarease it to match bounds.
+ ex: 5 80 15 bound result: 15
+ 5 10 15 bound result: 10
+ 5 -10 15 bound result: 5
+
+bound? ( low n high -- result ) returns true if n is in the
+ given bounds.
+
+tab ( col -- spaces) calculate amount of spaces to add
+ ta reach next tabulation from given column.
+
+count ( addr -- addr+1 n )
+ Useful for returning bytes from constantly incareasing
+ address. Module "type" is nice example.
+
+c, ( n -- )
+ store one byte at memory specified by "h". And incarease
+ "h" by 1.
+
+, ( n -- )
+ store 32 bit number at memory specified by "h". And
+ incarease "h" by 4.
+
+cmove ( addr1 addr2 n -- )
+ copy "n" amount of bytes from memory at "addr1" to memory
+ at "addr2".
+
+rnd ( limit -- result )
+ generates random number in range 0 to "limit"-1.
+
+abs ( n -- |n| )
+ returns absolute value of "n"
+#+END_VERSE
+** Dynamic & static strings
+Fifth supports both static and dynamic strings. Static strings must
+have predefined space reserved, and string mustn't exceed this
+length. They manipulation is faster. But they use more memory. Static
+string memory address is used to refer to the string.
+
+Dynamic strings can have at any time length form 0 to 0FFh, They take
+up only memory they currently need. They are held in dynamic memory
+blocks, so dynamic block handle is used to refer to this string.
+
+Both types of strings are stored in the way, where first (0th) byte
+holds current string length, following bytes are string itself.
+
+
+#+BEGIN_VERSE
+Dynamic:
+
+Dstral ( -- handle )
+ Allocate new string.
+
+Dstrlen ( handle -- length )
+ Return string length.
+
+c+Dstr ( chr handle -- )
+ Add one byte to end of the string.
+
+c+lDstr ( chr handle -- )
+ Add one byte to left side (beginning) of the string.
+
+Dstr. ( handle -- )
+ Write contec of string into screen.
+
+Dstrsure ( size Dstr -- )
+ Makes sure that at least rquested
+ "size" (amount of characters) is allocated for given
+ dynamic string.
+
+Dstr2str ( handle address -- )
+ Copy dyamic string into static memory space.
+
+str2Dstr ( address handle -- )
+ Copy static string into dyamic string.
+
+Dstr+str ( Dstr addr -- )
+ Add contenc of dynamic string to static string.
+
+D" any string" ( -- Dstr )
+ Moves specified string into dynamic string called "defDstr".
+
+D> any_string ( -- Dstr )
+ Moves specified string into dynamic string called "defDstr".
+ Space marks end of string!
+
+D>2 any_string ( -- Dstr )
+ Moves specified string into dynamic string called "defDstr2".
+ Space marks end of string!
+
+Dstr+Dstr ( Dstr1 Dstr2 -- )
+ Adds "Dstr1" to "Dstr2" and places result into "Dstr2".
+
+Dstrclear ( Dstr -- )
+ Clears contenc of dynamic string.
+
+Dstr2Dstr ( Dstr1 Dstr2 -- )
+ Moves "Dstr1" to "Dstr2".
+Dstr ( data" name -- )
+ Creates new dynamic string and moves specified data into it.
+ Then creates new constant with given "name" holding created
+ dynamic string handle.
+
+ ex: Dstr Hello, my name is Sven!" message \ creates it
+ message Dstr. \ tests it
+
+Dstrlscan ( char Dstr -- loc )
+ Searches dynamic string for "char", from left to right,
+ returns first found "char" location in string, or 0,
+ if not found.
+
+Dstrrscan ( char Dstr -- loc )
+ Searches dynamic string for "char", from right to left,
+ returns first found "char" location in string, or 0,
+ if not found.
+
+Dstrlscane ( char Dstr -- loc )
+ Same as "Dstrlscan" buf returns string length+1 as location.
+ÿ
+Dstrleft ( amo Dstr -- )
+ Only specified amount of characters from left remains
+ in dynamic string. ie. cut right part out.
+
+Dstrright ( amo Dstr -- )
+ Only specified amount of characters from right remains
+ in dynamic string. ie. cut left part out.
+
+Dstrcutl ( amo Dstr -- )
+ Cut specified amount of characters from left of dynamic
+ string out.
+
+Dstrsp ( char Dstr1 Dstr2 -- )
+ Separate dynamic string in Dstr1 into two parts,
+ using "char" as separator. First part will be stored in
+ "Dstr2", second part in "Dstr1".
+ ex: asc \ \ ..separator
+ D> listF\listLIB\5TH_DRVMOUSE \ ..separate from
+ defDstr2 \ ..place result in
+ Dstrsp \ separation command
+ defDstr Dstr. \ will be: listLIB\5TH_DRVMOUSE
+ defDstr2 Dstr. \ will be: listF
+
+Dv ( addr -- )
+ Allocates empty dynamic string, and places it's handle
+ into given address.
+
+Df ( addr -- )
+ Reads dynamic string handle from given address and
+ deallocates (frees) it.
+
+ex: var mystring1
+ : testmodule
+ mystring1 Dv \ allocates string
+
+ <whatever>
+
+ mystring1 Df ; \ deallocates it again when no longer needed.
+#+END_VERSE
+++ /dev/null
-<html><head><title>FIFTH</title></head>
-<body>
-
-<pre>
-
- <h2>Screen shots</h2>
-
-
-<img src="start.png">
-
-
-
-
-<img src="words.png">
-Sample words defined. Most of the words are commands that can be executed
-interactively from command line or from file. When executed they can be
-selectively compiled or interpreted.
-
-
-
-<img src="textEditor.png">
-Built in text editor.
-
-
-
-</pre>
-</html>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+<!-- 2023-09-18 Mon 01:46 -->
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1" />
+<title>Fifth - virtual machine</title>
+<meta name="author" content="Svjatoslav Agejenko" />
+<meta name="generator" content="Org Mode" />
+<style>
+ #content { max-width: 60em; margin: auto; }
+ .title { text-align: center;
+ margin-bottom: .2em; }
+ .subtitle { text-align: center;
+ font-size: medium;
+ font-weight: bold;
+ margin-top:0; }
+ .todo { font-family: monospace; color: red; }
+ .done { font-family: monospace; color: green; }
+ .priority { font-family: monospace; color: orange; }
+ .tag { background-color: #eee; font-family: monospace;
+ padding: 2px; font-size: 80%; font-weight: normal; }
+ .timestamp { color: #bebebe; }
+ .timestamp-kwd { color: #5f9ea0; }
+ .org-right { margin-left: auto; margin-right: 0px; text-align: right; }
+ .org-left { margin-left: 0px; margin-right: auto; text-align: left; }
+ .org-center { margin-left: auto; margin-right: auto; text-align: center; }
+ .underline { text-decoration: underline; }
+ #postamble p, #preamble p { font-size: 90%; margin: .2em; }
+ p.verse { margin-left: 3%; }
+ pre {
+ border: 1px solid #e6e6e6;
+ border-radius: 3px;
+ background-color: #f2f2f2;
+ padding: 8pt;
+ font-family: monospace;
+ overflow: auto;
+ margin: 1.2em;
+ }
+ pre.src {
+ position: relative;
+ overflow: auto;
+ }
+ pre.src:before {
+ display: none;
+ position: absolute;
+ top: -8px;
+ right: 12px;
+ padding: 3px;
+ color: #555;
+ background-color: #f2f2f299;
+ }
+ pre.src:hover:before { display: inline; margin-top: 14px;}
+ /* Languages per Org manual */
+ pre.src-asymptote:before { content: 'Asymptote'; }
+ pre.src-awk:before { content: 'Awk'; }
+ pre.src-authinfo::before { content: 'Authinfo'; }
+ pre.src-C:before { content: 'C'; }
+ /* pre.src-C++ doesn't work in CSS */
+ pre.src-clojure:before { content: 'Clojure'; }
+ pre.src-css:before { content: 'CSS'; }
+ pre.src-D:before { content: 'D'; }
+ pre.src-ditaa:before { content: 'ditaa'; }
+ pre.src-dot:before { content: 'Graphviz'; }
+ pre.src-calc:before { content: 'Emacs Calc'; }
+ pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
+ pre.src-fortran:before { content: 'Fortran'; }
+ pre.src-gnuplot:before { content: 'gnuplot'; }
+ pre.src-haskell:before { content: 'Haskell'; }
+ pre.src-hledger:before { content: 'hledger'; }
+ pre.src-java:before { content: 'Java'; }
+ pre.src-js:before { content: 'Javascript'; }
+ pre.src-latex:before { content: 'LaTeX'; }
+ pre.src-ledger:before { content: 'Ledger'; }
+ pre.src-lisp:before { content: 'Lisp'; }
+ pre.src-lilypond:before { content: 'Lilypond'; }
+ pre.src-lua:before { content: 'Lua'; }
+ pre.src-matlab:before { content: 'MATLAB'; }
+ pre.src-mscgen:before { content: 'Mscgen'; }
+ pre.src-ocaml:before { content: 'Objective Caml'; }
+ pre.src-octave:before { content: 'Octave'; }
+ pre.src-org:before { content: 'Org mode'; }
+ pre.src-oz:before { content: 'OZ'; }
+ pre.src-plantuml:before { content: 'Plantuml'; }
+ pre.src-processing:before { content: 'Processing.js'; }
+ pre.src-python:before { content: 'Python'; }
+ pre.src-R:before { content: 'R'; }
+ pre.src-ruby:before { content: 'Ruby'; }
+ pre.src-sass:before { content: 'Sass'; }
+ pre.src-scheme:before { content: 'Scheme'; }
+ pre.src-screen:before { content: 'Gnu Screen'; }
+ pre.src-sed:before { content: 'Sed'; }
+ pre.src-sh:before { content: 'shell'; }
+ pre.src-sql:before { content: 'SQL'; }
+ pre.src-sqlite:before { content: 'SQLite'; }
+ /* additional languages in org.el's org-babel-load-languages alist */
+ pre.src-forth:before { content: 'Forth'; }
+ pre.src-io:before { content: 'IO'; }
+ pre.src-J:before { content: 'J'; }
+ pre.src-makefile:before { content: 'Makefile'; }
+ pre.src-maxima:before { content: 'Maxima'; }
+ pre.src-perl:before { content: 'Perl'; }
+ pre.src-picolisp:before { content: 'Pico Lisp'; }
+ pre.src-scala:before { content: 'Scala'; }
+ pre.src-shell:before { content: 'Shell Script'; }
+ pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
+ /* additional language identifiers per "defun org-babel-execute"
+ in ob-*.el */
+ pre.src-cpp:before { content: 'C++'; }
+ pre.src-abc:before { content: 'ABC'; }
+ pre.src-coq:before { content: 'Coq'; }
+ pre.src-groovy:before { content: 'Groovy'; }
+ /* additional language identifiers from org-babel-shell-names in
+ ob-shell.el: ob-shell is the only babel language using a lambda to put
+ the execution function name together. */
+ pre.src-bash:before { content: 'bash'; }
+ pre.src-csh:before { content: 'csh'; }
+ pre.src-ash:before { content: 'ash'; }
+ pre.src-dash:before { content: 'dash'; }
+ pre.src-ksh:before { content: 'ksh'; }
+ pre.src-mksh:before { content: 'mksh'; }
+ pre.src-posh:before { content: 'posh'; }
+ /* Additional Emacs modes also supported by the LaTeX listings package */
+ pre.src-ada:before { content: 'Ada'; }
+ pre.src-asm:before { content: 'Assembler'; }
+ pre.src-caml:before { content: 'Caml'; }
+ pre.src-delphi:before { content: 'Delphi'; }
+ pre.src-html:before { content: 'HTML'; }
+ pre.src-idl:before { content: 'IDL'; }
+ pre.src-mercury:before { content: 'Mercury'; }
+ pre.src-metapost:before { content: 'MetaPost'; }
+ pre.src-modula-2:before { content: 'Modula-2'; }
+ pre.src-pascal:before { content: 'Pascal'; }
+ pre.src-ps:before { content: 'PostScript'; }
+ pre.src-prolog:before { content: 'Prolog'; }
+ pre.src-simula:before { content: 'Simula'; }
+ pre.src-tcl:before { content: 'tcl'; }
+ pre.src-tex:before { content: 'TeX'; }
+ pre.src-plain-tex:before { content: 'Plain TeX'; }
+ pre.src-verilog:before { content: 'Verilog'; }
+ pre.src-vhdl:before { content: 'VHDL'; }
+ pre.src-xml:before { content: 'XML'; }
+ pre.src-nxml:before { content: 'XML'; }
+ /* add a generic configuration mode; LaTeX export needs an additional
+ (add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
+ pre.src-conf:before { content: 'Configuration File'; }
+
+ table { border-collapse:collapse; }
+ caption.t-above { caption-side: top; }
+ caption.t-bottom { caption-side: bottom; }
+ td, th { vertical-align:top; }
+ th.org-right { text-align: center; }
+ th.org-left { text-align: center; }
+ th.org-center { text-align: center; }
+ td.org-right { text-align: right; }
+ td.org-left { text-align: left; }
+ td.org-center { text-align: center; }
+ dt { font-weight: bold; }
+ .footpara { display: inline; }
+ .footdef { margin-bottom: 1em; }
+ .figure { padding: 1em; }
+ .figure p { text-align: center; }
+ .equation-container {
+ display: table;
+ text-align: center;
+ width: 100%;
+ }
+ .equation {
+ vertical-align: middle;
+ }
+ .equation-label {
+ display: table-cell;
+ text-align: right;
+ vertical-align: middle;
+ }
+ .inlinetask {
+ padding: 10px;
+ border: 2px solid gray;
+ margin: 10px;
+ background: #ffffcc;
+ }
+ #org-div-home-and-up
+ { text-align: right; font-size: 70%; white-space: nowrap; }
+ textarea { overflow-x: auto; }
+ .linenr { font-size: smaller }
+ .code-highlighted { background-color: #ffff00; }
+ .org-info-js_info-navigation { border-style: none; }
+ #org-info-js_console-label
+ { font-size: 10px; font-weight: bold; white-space: nowrap; }
+ .org-info-js_search-highlight
+ { background-color: #ffff00; color: #000000; font-weight: bold; }
+ .org-svg { }
+</style>
+<link rel="stylesheet" type="text/css" href="https://thomasf.github.io/solarized-css/solarized-dark.min.css" />
+</head>
+<body>
+<div id="content" class="content">
+<h1 class="title">Fifth - virtual machine</h1>
+<div id="table-of-contents" role="doc-toc">
+<h2>Table of Contents</h2>
+<div id="text-table-of-contents" role="doc-toc">
+<ul>
+<li><a href="#org5215c98">1. Instructions overview</a>
+<ul>
+<li><a href="#orgad315b0">1.1. kbd@ - read scancode of pressed or released key</a></li>
+<li><a href="#org944323a">1.2. vidput - put image1 into image2, at location x, y</a></li>
+<li><a href="#org5b4d781">1.3. cmove - copy memory array</a></li>
+<li><a href="#orgb1e3963">1.4. tvidput - put image with transparency support</a></li>
+<li><a href="#orgac6e38a">1.5. charput - draw text character</a></li>
+</ul>
+</li>
+</ul>
+</div>
+</div>
+<p>
+Current emulator emulates:
+</p>
+<ul class="org-ul">
+<li>1 CPU.</li>
+<li>It has 2 stacks</li>
+<li>~50 instructions</li>
+<li>4GB flat address space (theoretically).</li>
+</ul>
+
+
+<p>
+While I tried to keep instruction set simple, I was forced to put in
+some complex instructions to make performance acceptable on
+emulator.
+</p>
+
+<p>
+CPU has following registers:
+</p>
+<dl class="org-dl">
+<dt>IP</dt><dd>instruction pointer</dd>
+<dt>DSP</dt><dd>data stack pointer</dd>
+<dt>RSP</dt><dd>return stack pointer</dd>
+</dl>
+
+<div id="outline-container-org5215c98" class="outline-2">
+<h2 id="org5215c98"><span class="section-number-2">1.</span> Instructions overview</h2>
+<div class="outline-text-2" id="text-1">
+<p>
+Virtual CPU, commands (most of them are avaiable as ordinary commands
+in programming language):
+</p>
+
+
+<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
+
+
+<colgroup>
+<col class="org-right" />
+
+<col class="org-left" />
+
+<col class="org-left" />
+
+<col class="org-left" />
+</colgroup>
+<thead>
+<tr>
+<th scope="col" class="org-right">#</th>
+<th scope="col" class="org-left">name</th>
+<th scope="col" class="org-left">stack footprint</th>
+<th scope="col" class="org-left">description</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td class="org-right">0</td>
+<td class="org-left">nop</td>
+<td class="org-left">--</td>
+<td class="org-left">does nothing</td>
+</tr>
+
+<tr>
+<td class="org-right">1</td>
+<td class="org-left">halt</td>
+<td class="org-left">--</td>
+<td class="org-left">halt CPU ( return to DOS on emulator )</td>
+</tr>
+
+<tr>
+<td class="org-right">2</td>
+<td class="org-left"><a href="#orgad315b0">kbd@</a></td>
+<td class="org-left">– c</td>
+<td class="org-left">read scancode of pressed or released key</td>
+</tr>
+
+<tr>
+<td class="org-right">3</td>
+<td class="org-left">num <dword></td>
+<td class="org-left">– n</td>
+<td class="org-left">put immidiate number into datastack</td>
+</tr>
+
+<tr>
+<td class="org-right">4</td>
+<td class="org-left">jmp <dword></td>
+<td class="org-left">--</td>
+<td class="org-left">jump to specified code</td>
+</tr>
+
+<tr>
+<td class="org-right">5</td>
+<td class="org-left">call <dword></td>
+<td class="org-left"> </td>
+<td class="org-left">jump to specified code, save return address to return stack</td>
+</tr>
+
+<tr>
+<td class="org-right">6</td>
+<td class="org-left">1+</td>
+<td class="org-left">n – n+1</td>
+<td class="org-left"> </td>
+</tr>
+
+<tr>
+<td class="org-right">7</td>
+<td class="org-left">1-</td>
+<td class="org-left">n – n-1</td>
+<td class="org-left"> </td>
+</tr>
+
+<tr>
+<td class="org-right">8</td>
+<td class="org-left">dup</td>
+<td class="org-left">n – n n</td>
+<td class="org-left">duplicate top of data stack</td>
+</tr>
+
+<tr>
+<td class="org-right">9</td>
+<td class="org-left">drop</td>
+<td class="org-left">n --</td>
+<td class="org-left">drop last element in data stack</td>
+</tr>
+
+<tr>
+<td class="org-right">10</td>
+<td class="org-left">if <dword></td>
+<td class="org-left">n --</td>
+<td class="org-left">jump to addr if top element was 0</td>
+</tr>
+
+<tr>
+<td class="org-right">11</td>
+<td class="org-left">ret</td>
+<td class="org-left"> </td>
+<td class="org-left">jump to code, specified in return stack.</td>
+</tr>
+
+<tr>
+<td class="org-right">12</td>
+<td class="org-left">c@</td>
+<td class="org-left">addr – n</td>
+<td class="org-left">read byte from memory at specified address</td>
+</tr>
+
+<tr>
+<td class="org-right">13</td>
+<td class="org-left">c!</td>
+<td class="org-left">n addr --</td>
+<td class="org-left">store byte to specified memory</td>
+</tr>
+
+<tr>
+<td class="org-right">14</td>
+<td class="org-left">push</td>
+<td class="org-left">DSTK -> RSTK</td>
+<td class="org-left">move top of datastack to returnstack</td>
+</tr>
+
+<tr>
+<td class="org-right">15</td>
+<td class="org-left">pop</td>
+<td class="org-left">RSTK -> DSTK</td>
+<td class="org-left">move top of returnstack to datastack</td>
+</tr>
+
+<tr>
+<td class="org-right">16</td>
+<td class="org-left"><unused></td>
+<td class="org-left"> </td>
+<td class="org-left"> </td>
+</tr>
+
+<tr>
+<td class="org-right">17</td>
+<td class="org-left">rot</td>
+<td class="org-left">n1 n2 n3 – n2 n3 n1</td>
+<td class="org-left">rotate stack elements</td>
+</tr>
+
+<tr>
+<td class="org-right">18</td>
+<td class="org-left">disk@</td>
+<td class="org-left">FromDiskSect ToMem --</td>
+<td class="org-left">read 1KB from disk into RAM</td>
+</tr>
+
+<tr>
+<td class="org-right">19</td>
+<td class="org-left">disk!</td>
+<td class="org-left">FromMem ToDiskSect --</td>
+<td class="org-left">write 1KB to disk</td>
+</tr>
+
+<tr>
+<td class="org-right">20</td>
+<td class="org-left">@</td>
+<td class="org-left">addr – n</td>
+<td class="org-left">read 32 bit number from memory</td>
+</tr>
+
+<tr>
+<td class="org-right">21</td>
+<td class="org-left">!</td>
+<td class="org-left">n addr --</td>
+<td class="org-left">store 32 bit number to memory</td>
+</tr>
+
+<tr>
+<td class="org-right">22</td>
+<td class="org-left">over</td>
+<td class="org-left">n1 n2 – n1 n2 n1</td>
+<td class="org-left"> </td>
+</tr>
+
+<tr>
+<td class="org-right">23</td>
+<td class="org-left">swap</td>
+<td class="org-left">n1 n2 – n2 n1</td>
+<td class="org-left"> </td>
+</tr>
+
+<tr>
+<td class="org-right">24</td>
+<td class="org-left">+</td>
+<td class="org-left">n1 n2 – n1+n2</td>
+<td class="org-left"> </td>
+</tr>
+
+<tr>
+<td class="org-right">25</td>
+<td class="org-left">-</td>
+<td class="org-left">n1 n2 – n1-n2</td>
+<td class="org-left"> </td>
+</tr>
+
+<tr>
+<td class="org-right">26</td>
+<td class="org-left">*</td>
+<td class="org-left">n1 n2 – n1*n2</td>
+<td class="org-left"> </td>
+</tr>
+
+<tr>
+<td class="org-right">27</td>
+<td class="org-left">/</td>
+<td class="org-left">n1 n2 – n1/n2</td>
+<td class="org-left"> </td>
+</tr>
+
+<tr>
+<td class="org-right">28</td>
+<td class="org-left">></td>
+<td class="org-left">n1 n2 – result</td>
+<td class="org-left">is true when n1 > n2</td>
+</tr>
+
+<tr>
+<td class="org-right">29</td>
+<td class="org-left"><</td>
+<td class="org-left">n1 n2 – result</td>
+<td class="org-left">is true when n1 < n2</td>
+</tr>
+
+<tr>
+<td class="org-right">30</td>
+<td class="org-left">not</td>
+<td class="org-left">n1 – not_n1</td>
+<td class="org-left">logical not</td>
+</tr>
+
+<tr>
+<td class="org-right">31</td>
+<td class="org-left">i</td>
+<td class="org-left">– n</td>
+<td class="org-left">copies top of return stack into datastack</td>
+</tr>
+
+<tr>
+<td class="org-right">32</td>
+<td class="org-left">cprt@</td>
+<td class="org-left">addr – n</td>
+<td class="org-left">read one byte from hardware port</td>
+</tr>
+
+<tr>
+<td class="org-right">33</td>
+<td class="org-left">cprt!</td>
+<td class="org-left">n addr --</td>
+<td class="org-left">store one byte to hardware port</td>
+</tr>
+
+<tr>
+<td class="org-right">34</td>
+<td class="org-left">i2</td>
+<td class="org-left">– n</td>
+<td class="org-left">like "i" but takes second top stack element</td>
+</tr>
+
+<tr>
+<td class="org-right">35</td>
+<td class="org-left">i3</td>
+<td class="org-left">– n</td>
+<td class="org-left">like "i" but takes third top stack element.</td>
+</tr>
+
+<tr>
+<td class="org-right">36</td>
+<td class="org-left">shl</td>
+<td class="org-left">n amount – n</td>
+<td class="org-left">left bit shift</td>
+</tr>
+
+<tr>
+<td class="org-right">37</td>
+<td class="org-left">shr</td>
+<td class="org-left">n amount – n</td>
+<td class="org-left">right bit shift</td>
+</tr>
+
+<tr>
+<td class="org-right">38</td>
+<td class="org-left">or</td>
+<td class="org-left">n1 n2 – n</td>
+<td class="org-left">logical or</td>
+</tr>
+
+<tr>
+<td class="org-right">39</td>
+<td class="org-left">xor</td>
+<td class="org-left">n1 n2 – n</td>
+<td class="org-left">exclusive logical or</td>
+</tr>
+
+<tr>
+<td class="org-right">40</td>
+<td class="org-left">vidmap</td>
+<td class="org-left">addr --</td>
+<td class="org-left">copy memory from "addr" to video memory.</td>
+</tr>
+
+<tr>
+<td class="org-right">41</td>
+<td class="org-left">mouse@</td>
+<td class="org-left">– x y button</td>
+<td class="org-left">read mouse coordinates & buttons</td>
+</tr>
+
+<tr>
+<td class="org-right">42</td>
+<td class="org-left"><a href="#org944323a">vidput</a></td>
+<td class="org-left">addr1 addr2 x y --</td>
+<td class="org-left">put image1 into image2, at location x, y</td>
+</tr>
+
+<tr>
+<td class="org-right">43</td>
+<td class="org-left"><a href="#org5b4d781">cmove</a></td>
+<td class="org-left">addr1 addr2 amount</td>
+<td class="org-left">move memory from addr1 to addr2</td>
+</tr>
+
+<tr>
+<td class="org-right">44</td>
+<td class="org-left">cfill</td>
+<td class="org-left">c addr amount --</td>
+<td class="org-left">fill memory starting at "addr" with "c" bytes.</td>
+</tr>
+
+<tr>
+<td class="org-right">45</td>
+<td class="org-left"><a href="#orgb1e3963">tvidput</a></td>
+<td class="org-left">addr1 addr2 x y --</td>
+<td class="org-left">put image with transparency support</td>
+</tr>
+
+<tr>
+<td class="org-right">46</td>
+<td class="org-left">depth</td>
+<td class="org-left">– depth</td>
+<td class="org-left">returns current depth of data stack.</td>
+</tr>
+
+<tr>
+<td class="org-right">47</td>
+<td class="org-left"><a href="#orgac6e38a">charput</a></td>
+<td class="org-left">colorfg colorbg addrsrc addrdest x y</td>
+<td class="org-left">draw text character</td>
+</tr>
+</tbody>
+</table>
+</div>
+
+<div id="outline-container-orgad315b0" class="outline-3">
+<h3 id="orgad315b0"><span class="section-number-3">1.1.</span> kbd@ - read scancode of pressed or released key</h3>
+<div class="outline-text-3" id="text-1-1">
+<p>
+Returns 0 if no data available.
+</p>
+</div>
+</div>
+<div id="outline-container-org944323a" class="outline-3">
+<h3 id="org944323a"><span class="section-number-3">1.2.</span> vidput - put image1 into image2, at location x, y</h3>
+<div class="outline-text-3" id="text-1-2">
+<p>
+Does clipping, so part of a big image can be mapped into smaller one.
+</p>
+</div>
+</div>
+<div id="outline-container-org5b4d781" class="outline-3">
+<h3 id="org5b4d781"><span class="section-number-3">1.3.</span> cmove - copy memory array</h3>
+<div class="outline-text-3" id="text-1-3">
+<p>
+Move memory from addr1 to addr2. If addr1 is greater than addr2 then
+count address foward while moving, elseway starts from end and counts
+backwards, so no data loss occurs when memory regions partially
+overlap.
+</p>
+</div>
+</div>
+<div id="outline-container-orgb1e3963" class="outline-3">
+<h3 id="orgb1e3963"><span class="section-number-3">1.4.</span> tvidput - put image with transparency support</h3>
+<div class="outline-text-3" id="text-1-4">
+<p>
+Stack footprint
+</p>
+<pre class="example">
+addr1 addr2 x y --
+</pre>
+
+
+<p>
+Put image1 into image2, at location x, y with transparency support
+</p>
+
+<p>
+Color 255 in source image is treated as transparent.
+</p>
+</div>
+</div>
+<div id="outline-container-orgac6e38a" class="outline-3">
+<h3 id="orgac6e38a"><span class="section-number-3">1.5.</span> charput - draw text character</h3>
+<div class="outline-text-3" id="text-1-5">
+<p>
+Draw character to image buffer located at "addrdest" to specified x &
+y location. Decodes 8 bytes from source to bits, used to draw
+character.
+</p>
+</div>
+</div>
+</div>
+</div>
+<div id="postamble" class="status">
+<p class="author">Author: Svjatoslav Agejenko</p>
+<p class="date">Created: 2023-09-18 Mon 01:46</p>
+<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
+</div>
+</body>
+</html>
--- /dev/null
+:PROPERTIES:
+:ID: 9b251eb9-aff6-4025-94bf-25e89e26d54a
+:END:
+
+#+TITLE: Fifth - virtual machine
+#+AUTHOR: Svjatoslav Agejenko
+#+LANGUAGE: en
+
+Current emulator emulates:
+- 1 CPU.
+- It has 2 stacks
+- ~50 instructions
+- 4GB flat address space (theoretically).
+
+
+While I tried to keep instruction set simple, I was forced to put in
+some complex instructions to make performance acceptable on
+emulator.
+
+CPU has following registers:
+- IP :: instruction pointer
+- DSP :: data stack pointer
+- RSP :: return stack pointer
+
+* Instructions overview
+Virtual CPU, commands (most of them are avaiable as ordinary commands
+in programming language):
+
+
+| # | name | stack footprint | description |
+|----+--------------+--------------------------------------+-------------------------------------------------------------|
+| 0 | nop | -- | does nothing |
+| 1 | halt | -- | halt CPU ( return to DOS on emulator ) |
+| 2 | [[id:820b1b90-4f4c-4ab1-b49f-9b4a52ea2528][kbd@]] | -- c | read scancode of pressed or released key |
+| 3 | num <dword> | -- n | put immidiate number into datastack |
+| 4 | jmp <dword> | -- | jump to specified code |
+| 5 | call <dword> | | jump to specified code, save return address to return stack |
+| 6 | 1+ | n -- n+1 | |
+| 7 | 1- | n -- n-1 | |
+| 8 | dup | n -- n n | duplicate top of data stack |
+| 9 | drop | n -- | drop last element in data stack |
+| 10 | if <dword> | n -- | jump to addr if top element was 0 |
+| 11 | ret | | jump to code, specified in return stack. |
+| 12 | c@ | addr -- n | read byte from memory at specified address |
+| 13 | c! | n addr -- | store byte to specified memory |
+| 14 | push | DSTK -> RSTK | move top of datastack to returnstack |
+| 15 | pop | RSTK -> DSTK | move top of returnstack to datastack |
+| 16 | <unused> | | |
+| 17 | rot | n1 n2 n3 -- n2 n3 n1 | rotate stack elements |
+| 18 | disk@ | FromDiskSect ToMem -- | read 1KB from disk into RAM |
+| 19 | disk! | FromMem ToDiskSect -- | write 1KB to disk |
+| 20 | @ | addr -- n | read 32 bit number from memory |
+| 21 | ! | n addr -- | store 32 bit number to memory |
+| 22 | over | n1 n2 -- n1 n2 n1 | |
+| 23 | swap | n1 n2 -- n2 n1 | |
+| 24 | + | n1 n2 -- n1+n2 | |
+| 25 | - | n1 n2 -- n1-n2 | |
+| 26 | * | n1 n2 -- n1*n2 | |
+| 27 | / | n1 n2 -- n1/n2 | |
+| 28 | > | n1 n2 -- result | is true when n1 > n2 |
+| 29 | < | n1 n2 -- result | is true when n1 < n2 |
+| 30 | not | n1 -- not_n1 | logical not |
+| 31 | i | -- n | copies top of return stack into datastack |
+| 32 | cprt@ | addr -- n | read one byte from hardware port |
+| 33 | cprt! | n addr -- | store one byte to hardware port |
+| 34 | i2 | -- n | like "i" but takes second top stack element |
+| 35 | i3 | -- n | like "i" but takes third top stack element. |
+| 36 | shl | n amount -- n | left bit shift |
+| 37 | shr | n amount -- n | right bit shift |
+| 38 | or | n1 n2 -- n | logical or |
+| 39 | xor | n1 n2 -- n | exclusive logical or |
+| 40 | vidmap | addr -- | copy memory from "addr" to video memory. |
+| 41 | mouse@ | -- x y button | read mouse coordinates & buttons |
+| 42 | [[id:238e8b03-57b6-424d-bfee-b6bb652cefbc][vidput]] | addr1 addr2 x y -- | put image1 into image2, at location x, y |
+| 43 | [[id:79e1916f-4103-42cc-ac10-bb1ee776ed50][cmove]] | addr1 addr2 amount | move memory from addr1 to addr2 |
+| 44 | cfill | c addr amount -- | fill memory starting at "addr" with "c" bytes. |
+| 45 | [[id:ab45247c-44c3-464d-9e2a-337f483b4616][tvidput]] | addr1 addr2 x y -- | put image with transparency support |
+| 46 | depth | -- depth | returns current depth of data stack. |
+| 47 | [[id:4bb479cf-aae0-4128-9868-f016c286a162][charput]] | colorfg colorbg addrsrc addrdest x y | draw text character |
+
+** kbd@ - read scancode of pressed or released key
+:PROPERTIES:
+:ID: 820b1b90-4f4c-4ab1-b49f-9b4a52ea2528
+:END:
+Returns 0 if no data available.
+** vidput - put image1 into image2, at location x, y
+:PROPERTIES:
+:ID: 238e8b03-57b6-424d-bfee-b6bb652cefbc
+:END:
+Does clipping, so part of a big image can be mapped into smaller one.
+** cmove - copy memory array
+:PROPERTIES:
+:ID: 79e1916f-4103-42cc-ac10-bb1ee776ed50
+:END:
+Move memory from addr1 to addr2. If addr1 is greater than addr2 then
+count address foward while moving, elseway starts from end and counts
+backwards, so no data loss occurs when memory regions partially
+overlap.
+** tvidput - put image with transparency support
+:PROPERTIES:
+:ID: ab45247c-44c3-464d-9e2a-337f483b4616
+:END:
+Stack footprint
+: addr1 addr2 x y --
+
+Put image1 into image2, at location x, y with transparency support
+
+Color 255 in source image is treated as transparent.
+** charput - draw text character
+:PROPERTIES:
+:ID: 4bb479cf-aae0-4128-9868-f016c286a162
+:END:
+Draw character to image buffer located at "addrdest" to specified x &
+y location. Decodes 8 bytes from source to bits, used to draw
+character.
+++ /dev/null
-#!/bin/bash
-cd "${0%/*}"; if [ "$1" != "T" ]; then gnome-terminal -e "'$0' T"; exit; fi;
-
-cd ..
-
-cola
-git push
-
-echo ""
-echo "Press ENTER to close this window."
-read
--- /dev/null
+#!/bin/bash
+cd "${0%/*}"; if [ "$1" != "T" ]; then gnome-terminal -- "$0" T; exit; fi
+
+cd ..
+
+# pull latest content from repository
+git pull
+
+# stage all changes
+git add --all
+
+# open GUI to confirm/revert/commit changes
+cola
+
+# push changes to remote repository
+git push
+
+
+echo ""
+echo "Press ENTER to close this window."
+read
#!/bin/bash
-cd "${0%/*}"; if [ "$1" != "T" ]; then gnome-terminal -e "'$0' T"; exit; fi;
+cd "${0%/*}"; if [ "$1" != "T" ]; then gnome-terminal -- "$0" T; exit; fi;
cd ..