From: Svjatoslav Agejenko Date: Fri, 25 Oct 2024 22:25:52 +0000 (+0300) Subject: Ignore IntelliJ project files X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;ds=sidebyside;h=HEAD;hp=56037f262c669df160a770aa54f9e35ac3f945ca;p=fifth.git Ignore IntelliJ project files --- diff --git a/.gitignore b/.gitignore index f0216fa..1099ea5 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ - +/.idea/ bin/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/COPYING b/COPYING index 10828e0..0e259d4 100644 --- a/COPYING +++ b/COPYING @@ -1,341 +1,121 @@ - - 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. - - 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.) - -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. - - 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. - - 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 - - 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. - - - Copyright (C) - - 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. - - , 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. diff --git a/doc/index.html b/doc/index.html index ab17bf9..174e5ec 100644 --- a/doc/index.html +++ b/doc/index.html @@ -1,275 +1,297 @@ - - + + + + + + Fifth - virtual machine, operating system, programming language - - - - - - - - - - - - - - + #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 { } + + -
-

Fifth - virtual machine, operating system, programming language

-
-

1 General

-
-
    -
  • This program is free software: you can redistribute it and/or modify -it under the terms of the 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. +
    +

    Fifth - virtual machine, operating system, programming language

    + -
    -

    1.1 Source code

    +
    +

    1. General

    +
    + +
    + +
    +

    1.1. Source code

    -
    -

    2 Warning

    +
    +

    2. !Project deprecated!

    Current implementation does not support object oriented @@ -279,84 +301,97 @@ require reimplementation of everything.

    Currently I try to implement those new ideas in the project called -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.

    -
    -

    3 Introduction

    +
    +

    3. Introduction

    -Fifth is programming lanquage & operating system, running on 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:

    -
    -
    -

    3.1 screenshots

    + +
    +

    3.1. Screenshots

    -
      -
    • start.png -
        -
      • Startup screen diplaying Fifth logo and full file list. -
      • -
      -
    • -
    • 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. -
      • -
      -
    • +
      +

      start.png +

      +
      -
    • text editor.png -
        -
      • Built in text editor. -
      • -
      -
    • -
    +

    +Startup screen diplaying Fifth logo and full file list. +

    + + +
    +

    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. +

    + + + +
    +

    text editor.png +

    +
    + +

    +Built in text editor. +

    -
    -

    4 Installation

    +
    +

    4. Installation

    Just unpack all files, witout altering original directory structure, somewhere in your hard disk. For example:

    +
    -C:\MISC\FIFTH\....
    +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 ). +To run fifth you need minimally just 2 files:

    +
    +
    EMULATOR.COM
    Virtual CPU emulator
    +
    DISK.RAW
    Virtual disk file
    +

    -Read more about distribution directory layout +For more information, please refer to Fifth distribution directory +tree description.

    -
    -

    5 Fifth distribution directory tree description

    + +
    +

    5. Fifth distribution directory tree description

    After downloading and unpacking the ZIP file you shoud get directory @@ -364,95 +399,91 @@ tree similar to this:

    -[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.
    -
    -[source] - source files
    -  [emulator] - emulator source
    -  [util] - utilites
    -
    -disk.raw - Virtual disk file, has filesystem inside.
    -emulator.com - main executable.
    +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.
    +
    +source - source files
    +  emulator - emulator source
    +  util - utilites
    +
    +disk.raw - Virtual disk file, has filesystem inside.
    +emulator.com - main executable.

    -
    -

    6 Software/Hardware/Human requirements

    +
    +

    6. Requirements

    -
    -

    6.1 Software

    +
    +
    +

    6.1. 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 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).
    -
    -

    6.2 Hardware

    + +
    +

    6.2. Hardware

      -
    • Minimum CPU 386. -
    • -
    • 64 KB free RAM below 640KB, -
    • -
    • 2 MB of free XMS. -
    • -
    • VESA compatible video card. -
    • +
    • A minimum of a i386 CPU.
    • +
    • 64 KB of free RAM below 640KB.
    • +
    • 2 MB of free extended memory.
    • +
    • A VESA-compatible video card.
    -
    -

    6.3 Human

    -
    -
      -
    • Beginner level Forth knowledge is recommended. -
    • -
    • Lots of enthusiasm. -
    • -
    -
    -
    -
    -

    7 Numbers representation within Fifth

    + +
    +

    7. 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: +

    + + +
    +

    numbers.png +

    +
    -
    -

    numbers.png +

    +Essentially square is split into 4 triangles. Each triangle represents +one bit.

    -

    -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.

    -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: Bibi-binary.

    -
    -

    8 Disk file map, and it's data structures

    + +
    +

    8. Disk file map, and it's data structures

    Core and high-level boot code is stored outside of the filesystem to @@ -460,147 +491,147 @@ allow easy access to it, at early booting time, when filesystem is not yet initialized.

    -
    -

    8.1 disk allocation

    +
    +

    8.1. Disk allocation

    - +
    -+-+-+ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + +
    offsetlengthdescriptionoffsetlengthdescription
    0~4 KbFifth core0~4 KbFifth core
    4 Kb~32Kbhigh-level boot code4 Kb~32 Kbhigh-level boot code
    37 Kb~65KbFAT37 Kb~65 KbFAT
    101Kb~16MBfilesystem data area101 Kb~16 MBfilesystem data area
    -
    -

    8.2 FAT entry format:

    +
    +

    8.2. FAT entry format:

    - +
    -+-+ - - + + - - + + - - + + - - + +
    codemeaningcodemeaning
    -2last sector-2last sector
    -1empty sector-1empty sector
    0 --.. pointer to next block0 --.. pointer to next block
    -
    -

    8.3 file entry format

    +
    +

    8.3. File entry format

    - +
    -+-+-+ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + +
    offsetlengthdescriptionoffsetlengthdescription
    04extension04extension
    416name416name
    204entry point204entry point
    244size244size
    284last modification time284last modification time
    -
    -

    9 Core architecture

    +
    +

    9. Core architecture

    Fifth core is simply some amount of already compiled into machine code @@ -613,64 +644,64 @@ dictionary space only. Random word can be removed from dictionary at any time. Currently dictionary can contain at most 1000 entries.

    -
    -

    9.1 Dictionary entry format

    +
    +

    9.1. Dictionary entry format

    - +
    -+-+-+ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + +
    offsetlengthdescriptionoffsetlengthdescription
    040 < previous entry040 < previous entry
      0 = last  0 = last
      -1 = empty  -1 = empty
    415module name string415module name string
    191entry type191entry type
    204entry data204entry data
    @@ -682,1103 +713,236 @@ run through headers backwards and find needed entry.

    -
    -

    9.2 Possible module types

    +
    +

    9.2. Possible module types

    - +
    -+-+-+ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + +
    typedescription"execute" actiontypedescription"execute" action
    0datacompile "num" instruction0datacompile "num" instruction
      with address to module  with address to module
    1submodulecompile "call" instruction1submodulecompile "call" instruction
      with address to module  with address to module
    2imm. submoduleimmediately call to module2imm. submoduleimmediately call to module
    -
    -

    9.3 Memory map (average)

    +
    +

    9.3. Memory map

    - +
    -+-+-+ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + +
    <loc><size><desc>locationsizedescription
    0~4096core0~4096core
    1500000~32000highlevel Fifth boot code1500000~32000highlevel Fifth boot code
    200000h core startup messages area200000h core startup messages area
    5200000 end of dynamic memory space5200000 end of dynamic memory space
    -
    -

    10 Virtual machine

    +
    +

    10. Dynamically loadable modules

    -

    -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: -

    - - - --- -- - - - - - - - - - - - - - - - - -
    IPinstruction pointer
    DSPdata stack pointer
    RSPreturn stack pointer
    - -

    -Virtual CPU, commands (most of them are avaiable as ordinary commands -in programming lanquage): -

    - -

    -
    -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.
    -

    -
    -
    - -
    -

    11 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. -

    -
    -

    11.1 FSCII

    -
    - - - --- -- -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    DECHEXfunction
    0 - 150 - FHEX numbers
    252FCbackspace
    253FDtabulator (TAB)
    254FEcarriage return (CR)
    255FFspace
    else ordinary characters, same as in ASCII.
    -
    -
    -
    -
    -

    12 Fifth commands

    -
    -
    -

    12.1 Compilation & miscellaneous

    -
    -

    -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".
    -

    -
    -
    -
    -

    12.2 Conditionals & control flow

    -
    -

    -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"
    -
    -

    -
    -
    -
    -

    12.3 Disk & file access

    -
    -

    -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.
    -

    -
    -
    -
    -

    12.4 Dynamic memory

    -
    +
    +

    10.1. Keyboard driver

    +

    -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.
    -

    -
    -
    -
    -

    12.5 Graphics and text

    -
    -

    -. ( 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.
    -

    -
    -
    -
    -

    12.6 Math, memory & stack manipulation

    -
    +
    +KBD_@ ( – code ) get scancodes for pressed keys from keyboard.
    +KBD_down? ( key – result ) check is key with specified scancode
    +                currently pressed down.
    +KBD_SC2FSCII ( code – FSCII ) convert key scancode into FSCII code,
    +                or in FSK (Fifth standard keycode).
    +KBD_F@ ( – FSCII ) read pressed key FSCII or FSK, returns -1 if no
    +                keys are pressed.
    +KBD_FW@ ( – FSCII ) read pressed key FSCII or FSK, if no keys is
    +                are pressed then waits until there is.
    +
    +                FSK
    +                —
    +In HEX.
    +
    +FC backspace
    +FD TAB
    +FE enter
    +FF space
    +
    +400 ESC
    +401 … F1 …
    +410 up
    +411 right
    +412 down
    +413 left
    +414 INS
    +415 DEL
    +416 home
    +417 end
    +418 PG/UP
    +419 PG/DN
    +

    +
    +
    +
    +

    10.2. Mouse driver

    +

    -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"
    +mousex var Mouse x coordinate.
    +mousey var Mouse y coordinate.
    +mousekeyl var Mouse left key.
    +mousekeym var Mouse middle key.
    +mousekeyr var Mouse right key.
    +mousec var Display current mouse coordinates in top left part of screen,
    +                if true. (good for debugging)
    +mousepointer var Image buffer, holding current mouse pointer.
    +mouseadd ( ModuleAddr x1 x2 y1 y2 – ) Add specified area on screen,
    +                into mause click buffer. If any mouse button is clicked on
    +                that area, module at "ModuleAddr" will be executed.
    +mousebe var Amount of buffer elements.
    +mousedo ( – ) Updates mouse coordinates and keys. Parse mouse
    +                click buffer, and draw mouse cursor to "screen".

    -
    -

    12.7 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. -

    +
    +

    10.3. 2D graphic library

    +
    +
    +
    lineh ( color len x y imgbuf – )
    draws horisontal line from X,Y +coordinates to right, with specified length.
    -

    -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. -

    +
    linev ( color len x y imgbuf – )
    draws vertical line down, from +coordinates X,Y, with specified length.
    -

    -Both types of strings are stored in the way, where first (0th) byte -holds current string length, following bytes are string itself. +

    box ( color x2 x1 y2 y1 imgbuf – )

    +draws rectangular box. x2 +bust be >= x1, y2 must be >= y1.

    +
    +x1,y1-----------+
    +  |             |
    +  |             |
    +  +-----------x2,y2
    +
    -

    -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.
    -

    -
    -
    +
    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.
    +
    -
    -

    13 Dynamically loadable modules

    -
    -
    -

    13.1 Keyboard driver

    -
    -

    -
    -KBD_@ ( – code ) get scancodes for pressed keys from keyboard.
    -KBD_down? ( key – result ) check is key with specified scancode
    -                currently pressed down.
    -KBD_SC2FSCII ( code – FSCII ) convert key scancode into FSCII code,
    -                or in FSK (Fifth standard keycode).
    -KBD_F@ ( – FSCII ) read pressed key FSCII or FSK, returns -1 if no
    -                keys are pressed.
    -KBD_FW@ ( – FSCII ) read pressed key FSCII or FSK, if no keys is
    -                are pressed then waits until there is.
    -
    -                FSK
    -                —
    -In HEX.
    -
    -FC backspace
    -FD TAB
    -FE enter
    -FF space
    -
    -400 ESC
    -401 … F1 …
    -410 up
    -411 right
    -412 down
    -413 left
    -414 INS
    -415 DEL
    -416 home
    -417 end
    -418 PG/UP
    -419 PG/DN
    -

    + +
    +

    10.4. Trigonometry functions

    +
    -
    -

    13.2 Mouse driver

    -
    -

    -mousex var Mouse x coordinate.
    -mousey var Mouse y coordinate.
    -mousekeyl var Mouse left key.
    -mousekeym var Mouse middle key.
    -mousekeyr var Mouse right key.
    -mousec var Display current mouse coordinates in top left part of screen,
    -                if true. (good for debugging)
    -mousepointer var Image buffer, holding current mouse pointer.
    -mouseadd ( ModuleAddr x1 x2 y1 y2 – ) Add specified area on screen,
    -                into mause click buffer. If any mouse button is clicked on
    -                that area, module at "ModuleAddr" will be executed.
    -mousebe var Amount of buffer elements.
    -mousedo ( – ) Updates mouse coordinates and keys. Parse mouse
    -                click buffer, and draw mouse cursor to "screen".
    +

    +

    10.4.1. 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.

    -
    -

    13.3 2D graphic library

    -
    -

    -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.
    +

    +

    10.4.2. cos ( a – result )

    +
    +

    +Return cosinus from given angle. Parameters are like in sin function.

    -
    -

    13.4 Trigonometry functions

    -
    -

    -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.
    -

    -
    -
    -

    Author: Svjatoslav Agejenko

    -

    Created: 2018-07-01 Sun 23:59

    -

    Emacs 25.1.1 (Org-mode 8.2.10)

    +
    +

    Author: Svjatoslav Agejenko

    +

    Created: 2023-09-19 Tue 18:07

    +

    Validate

    -
    diff --git a/doc/index.org b/doc/index.org index 6096aba..c370a29 100644 --- a/doc/index.org +++ b/doc/index.org @@ -1,137 +1,144 @@ #+TITLE: Fifth - virtual machine, operating system, programming language -* (document settings) :noexport: -** use dark style for TWBS-HTML exporter -#+HTML_HEAD: -#+HTML_HEAD: -#+HTML_HEAD: -#+HTML_HEAD: * 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 | @@ -174,704 +181,13 @@ run through headers backwards and find needed entry. | | | with address to module | |------+----------------+----------------------------| | 2 | imm. submodule | immediately call to module | -** Memory map (average) -| | | | -|---------+--------+-----------------------------| -| 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 ( -- n ) put immidiate number into datastack - -4 jmp jump to specified code -5 call 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 ( 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 -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 ( -- ) compiles new dictionary entry without specifying - new module type. - ex: head myentry - -: ( -- ) creates new code module -; ( -- ) ends module (immideate) - ex: : hello ." hi there" ; - -const ( n -- ) defines new constant. - ex: 2147483647 const max - -:i ( -- ) same as ":" but this module will be executed - immideately even in compile mode. - ex: :i ( 41 scan ; - -create ( -- ) 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 - -" " ( -- ) compile string and its size into core. - ex: create Mystring " This is it's contects" - -str " ( -- ) just shorter way for defining strings. - ex: str Mystring This is it's contenc" - -var ( -- ) define new 32 bit variable. - ex: var result - -' ( -- n ) return memory address of given entry. - ex: ' init - -forget ( -- ) 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 ( -- ) 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 ( -- ) 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 -- ) 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 DynStrHand -- ) - Create new file and save all data from dynamic memory - block to it. - -fsDload ( DynStr DynHand -- ) - Load whole file into dynamic memory block. - -fsDloadnew ( DynStr -- DynHand ) - 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. - -." " ( -- ) 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 - - - - 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 @@ -926,30 +242,37 @@ mousedo ( -- ) Updates mouse coordinates and keys. Parse mouse 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. diff --git a/doc/language.html b/doc/language.html new file mode 100644 index 0000000..ef8f0eb --- /dev/null +++ b/doc/language.html @@ -0,0 +1,921 @@ + + + + + + + +Fifth - language + + + + + + + + +
    +

    Fifth - language

    + + + +
    +

    1. 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. +

    +
    +
    +

    1.1. FSCII

    +
    + + + +++ ++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    DECHEXfunction
    0 - 150 - FHEX numbers
    252FCbackspace
    253FDtabulator (TAB)
    254FEcarriage return (CR)
    255FFspace
    else ordinary characters, same as in ASCII.
    +
    +
    +
    +
    +

    2. Fifth commands

    +
    +
    +
    +

    2.1. Compilation & miscellaneous

    +
    +

    +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".
    +

    +
    +
    +
    +

    2.2. Conditionals & control flow

    +
    +

    +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"
    +
    +

    +
    +
    +
    +

    2.3. Disk & file access

    +
    +

    +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.
    +

    +
    +
    +
    +

    2.4. Dynamic memory

    +
    +

    +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.
    +

    +
    +
    +
    +

    2.5. Graphics and text

    +
    +

    +. ( 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.
    +

    +
    +
    +
    +

    2.6. Math, memory & stack manipulation

    +
    +

    +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"
    +

    +
    +
    +
    +

    2.7. 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. +

    + + +

    +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.
    +

    +
    +
    +
    +
    +
    +

    Author: Svjatoslav Agejenko

    +

    Created: 2023-09-19 Tue 18:07

    +

    Validate

    +
    + + diff --git a/doc/language.org b/doc/language.org new file mode 100644 index 0000000..d64d0f6 --- /dev/null +++ b/doc/language.org @@ -0,0 +1,581 @@ +: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 ( -- ) compiles new dictionary entry without specifying + new module type. + ex: head myentry + +: ( -- ) creates new code module +; ( -- ) ends module (immideate) + ex: : hello ." hi there" ; + +const ( n -- ) defines new constant. + ex: 2147483647 const max + +:i ( -- ) same as ":" but this module will be executed + immideately even in compile mode. + ex: :i ( 41 scan ; + +create ( -- ) 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 + +" " ( -- ) compile string and its size into core. + ex: create Mystring " This is it's contects" + +str " ( -- ) just shorter way for defining strings. + ex: str Mystring This is it's contenc" + +var ( -- ) define new 32 bit variable. + ex: var result + +' ( -- n ) return memory address of given entry. + ex: ' init + +forget ( -- ) 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 ( -- ) 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 ( -- ) 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 -- ) 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 DynStrHand -- ) + Create new file and save all data from dynamic memory + block to it. + +fsDload ( DynStr DynHand -- ) + Load whole file into dynamic memory block. + +fsDloadnew ( DynStr -- DynHand ) + 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. + +." " ( -- ) 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 + + + + mystring1 Df ; \ deallocates it again when no longer needed. +#+END_VERSE diff --git a/doc/screenshots/index.html b/doc/screenshots/index.html deleted file mode 100644 index 2504418..0000000 --- a/doc/screenshots/index.html +++ /dev/null @@ -1,27 +0,0 @@ -FIFTH - - -
    -
    -    

    Screen shots

    - - - - - - - - -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. - - - - -Built in text editor. - - - -
    - diff --git a/doc/virtual machine.html b/doc/virtual machine.html new file mode 100644 index 0000000..fbf1f6c --- /dev/null +++ b/doc/virtual machine.html @@ -0,0 +1,677 @@ + + + + + + + +Fifth - virtual machine + + + + + + +
    +

    Fifth - virtual machine

    + +

    +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
    +
    + +
    +

    1. Instructions overview

    +
    +

    +Virtual CPU, commands (most of them are avaiable as ordinary commands +in programming language): +

    + + + + + +++ ++ ++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    #namestack footprintdescription
    0nop--does nothing
    1halt--halt CPU ( return to DOS on emulator )
    2kbd@– cread scancode of pressed or released key
    3num <dword>– nput immidiate number into datastack
    4jmp <dword>--jump to specified code
    5call <dword> jump to specified code, save return address to return stack
    61+n – n+1 
    71-n – n-1 
    8dupn – n nduplicate top of data stack
    9dropn --drop last element in data stack
    10if <dword>n --jump to addr if top element was 0
    11ret jump to code, specified in return stack.
    12c@addr – nread byte from memory at specified address
    13c!n addr --store byte to specified memory
    14pushDSTK -> RSTKmove top of datastack to returnstack
    15popRSTK -> DSTKmove top of returnstack to datastack
    16<unused>  
    17rotn1 n2 n3 – n2 n3 n1rotate stack elements
    18disk@FromDiskSect ToMem --read 1KB from disk into RAM
    19disk!FromMem ToDiskSect --write 1KB to disk
    20@addr – nread 32 bit number from memory
    21!n addr --store 32 bit number to memory
    22overn1 n2 – n1 n2 n1 
    23swapn1 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 – resultis true when n1 > n2
    29<n1 n2 – resultis true when n1 < n2
    30notn1 – not_n1logical not
    31i– ncopies top of return stack into datastack
    32cprt@addr – nread one byte from hardware port
    33cprt!n addr --store one byte to hardware port
    34i2– nlike "i" but takes second top stack element
    35i3– nlike "i" but takes third top stack element.
    36shln amount – nleft bit shift
    37shrn amount – nright bit shift
    38orn1 n2 – nlogical or
    39xorn1 n2 – nexclusive logical or
    40vidmapaddr --copy memory from "addr" to video memory.
    41mouse@– x y buttonread mouse coordinates & buttons
    42vidputaddr1 addr2 x y --put image1 into image2, at location x, y
    43cmoveaddr1 addr2 amountmove memory from addr1 to addr2
    44cfillc addr amount --fill memory starting at "addr" with "c" bytes.
    45tvidputaddr1 addr2 x y --put image with transparency support
    46depth– depthreturns current depth of data stack.
    47charputcolorfg colorbg addrsrc addrdest x ydraw text character
    +
    + +
    +

    1.1. kbd@ - read scancode of pressed or released key

    +
    +

    +Returns 0 if no data available. +

    +
    +
    +
    +

    1.2. vidput - put image1 into image2, at location x, y

    +
    +

    +Does clipping, so part of a big image can be mapped into smaller one. +

    +
    +
    +
    +

    1.3. cmove - copy memory array

    +
    +

    +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. +

    +
    +
    +
    +

    1.4. tvidput - put image with transparency support

    +
    +

    +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. +

    +
    +
    +
    +

    1.5. charput - draw text character

    +
    +

    +Draw character to image buffer located at "addrdest" to specified x & +y location. Decodes 8 bytes from source to bits, used to draw +character. +

    +
    +
    +
    +
    +
    +

    Author: Svjatoslav Agejenko

    +

    Created: 2023-09-18 Mon 01:46

    +

    Validate

    +
    + + diff --git a/doc/virtual machine.org b/doc/virtual machine.org new file mode 100644 index 0000000..262c414 --- /dev/null +++ b/doc/virtual machine.org @@ -0,0 +1,115 @@ +: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 | -- n | put immidiate number into datastack | +| 4 | jmp | -- | jump to specified code | +| 5 | call | | 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 | 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 | | | | +| 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. diff --git a/imageFile/f/5TH_AUTORUN b/imageFile/f/5TH_AUTORUN old mode 100755 new mode 100644 diff --git a/imageFile/f/5TH_QUICKPATH b/imageFile/f/5TH_QUICKPATH old mode 100755 new mode 100644 diff --git a/imageFile/f/5th_boot b/imageFile/f/5th_boot old mode 100755 new mode 100644 diff --git a/imageFile/f/5th_demo b/imageFile/f/5th_demo old mode 100755 new mode 100644 diff --git a/imageFile/f/5th_eg b/imageFile/f/5th_eg old mode 100755 new mode 100644 diff --git a/imageFile/f/5th_et b/imageFile/f/5th_et old mode 100755 new mode 100644 diff --git a/imageFile/f/5th_logo b/imageFile/f/5th_logo old mode 100755 new mode 100644 diff --git a/imageFile/f/FNT_SYSTEM b/imageFile/f/FNT_SYSTEM old mode 100755 new mode 100644 diff --git a/imageFile/f/I01_MCARROW b/imageFile/f/I01_MCARROW old mode 100755 new mode 100644 diff --git a/imageFile/f/lib/5TH_DRVKBD b/imageFile/f/lib/5TH_DRVKBD old mode 100755 new mode 100644 diff --git a/imageFile/f/lib/5TH_DRVMOUSE b/imageFile/f/lib/5TH_DRVMOUSE old mode 100755 new mode 100644 diff --git a/imageFile/f/lib/5TH_KBD_US b/imageFile/f/lib/5TH_KBD_US old mode 100755 new mode 100644 diff --git a/imageFile/f/lib/5TH_KBD_USDVORAK b/imageFile/f/lib/5TH_KBD_USDVORAK old mode 100755 new mode 100644 diff --git a/imageFile/f/lib/5TH_UICMD b/imageFile/f/lib/5TH_UICMD old mode 100755 new mode 100644 diff --git a/imageFile/f/lib/5th_gfx b/imageFile/f/lib/5th_gfx old mode 100755 new mode 100644 diff --git a/imageFile/f/lib/5th_gfx2 b/imageFile/f/lib/5th_gfx2 old mode 100755 new mode 100644 diff --git a/imageFile/f/lib/5th_trig b/imageFile/f/lib/5th_trig old mode 100755 new mode 100644 diff --git a/imageFile/f/txt_eg b/imageFile/f/txt_eg old mode 100755 new mode 100644 diff --git a/imageFile/f/txt_et b/imageFile/f/txt_et old mode 100755 new mode 100644 diff --git a/imageFile/f/txt_help b/imageFile/f/txt_help old mode 100755 new mode 100644 diff --git a/tools/5th2src.bas b/tools/5th2src.bas index 2943f06..7293f46 100755 --- a/tools/5th2src.bas +++ b/tools/5th2src.bas @@ -1,18 +1,23 @@ -DECLARE SUB getline (a$) -DECLARE SUB start () +' Utility to convert given file from special FSCII encoding to ASCII encoding. + +DECLARE SUB getline (line$) +DECLARE SUB initializeProgram () DIM SHARED byte AS STRING * 1 -DIM SHARED endf +DIM SHARED endOfFile -start +initializeProgram OPEN COMMAND$ + ".5th" FOR BINARY AS #1 OPEN COMMAND$ + ".src" FOR OUTPUT AS #2 +' Start reading lines from the file 1 -getline a$ -IF endf = 1 THEN GOTO 2 -PRINT #2, a$ +getline line$ +IF endOfFile = 1 THEN GOTO 2 +PRINT #2, line$ GOTO 1 + +' End of file reached 2 CLOSE #2 @@ -20,12 +25,16 @@ CLOSE #1 SYSTEM -SUB getline (a$) +SUB getline (line$) + +line$ = "" -a$ = "" +' Start reading bytes from the file 3 -IF EOF(1) <> 0 THEN endf = 1: GOTO 4 +IF EOF(1) <> 0 THEN endOfFile = 1: GOTO 4 GET #1, , byte + +' Convert non-printable characters to printable ones IF ASC(byte) <= 9 THEN byte = CHR$(48 + ASC(byte)) END IF @@ -39,15 +48,21 @@ IF ASC(byte) = 253 THEN byte = CHR$(9) END IF +' Check for end of line character IF byte = CHR$(254) THEN GOTO 4 -a$ = a$ + byte + +line$ = line$ + byte GOTO 3 + +' End of line reached 4 END SUB -SUB start -endf = 0 +SUB initializeProgram +endOfFile = 0 + +' Check if the command-line argument is empty IF COMMAND$ = "" THEN END -END SUB +END SUB diff --git a/tools/commit and push b/tools/commit and push deleted file mode 100755 index 057b511..0000000 --- a/tools/commit and push +++ /dev/null @@ -1,11 +0,0 @@ -#!/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 diff --git a/tools/insert.bas b/tools/insert.bas deleted file mode 100755 index b167c16..0000000 --- a/tools/insert.bas +++ /dev/null @@ -1,50 +0,0 @@ -DECLARE SUB getson (a$) -DECLARE SUB start () -DIM SHARED mitus, sona$(1 TO 50) -DIM SHARED byte AS STRING * 1 - -start - -OPEN sona$(1) FOR BINARY AS #1 -PRINT "Seeking to:" + sona$(3) -SEEK #1, VAL(sona$(3)) + 1 -OPEN sona$(2) FOR BINARY AS #2 -2 -IF EOF(2) <> 0 THEN GOTO 1 -GET #2, , byte -PUT #1, , byte -GOTO 2 -1 -CLOSE #2 -CLOSE #1 - -SYSTEM - -SUB getson (a$) -mitus = 0 - -d = 1 -FOR b = 1 TO LEN(a$) -c$ = RIGHT$(LEFT$(a$, b), 1) -IF c$ = " " THEN -d = 1 -ELSE -IF d = 1 THEN -mitus = mitus + 1 -sona$(mitus) = "" -d = 0 -END IF -sona$(mitus) = sona$(mitus) + c$ -END IF -NEXT b -END SUB - -SUB start - -IF COMMAND$ = "" THEN END - -getson COMMAND$ - - -END SUB - diff --git a/tools/open with IntelliJ IDEA b/tools/open with IntelliJ IDEA new file mode 100755 index 0000000..304bf94 --- /dev/null +++ b/tools/open with IntelliJ IDEA @@ -0,0 +1,54 @@ +#!/bin/bash + +# This script launches IntelliJ IDEA with the current project +# directory. The script is designed to be run by double-clicking it in +# the GNOME Nautilus file manager. + +# First, we change the current working directory to the directory of +# the script. + +# "${0%/*}" gives us the path of the script itself, without the +# script's filename. + +# This command basically tells the system "change the current +# directory to the directory containing this script". + +cd "${0%/*}" + +# Then, we move up one directory level. +# The ".." tells the system to go to the parent directory of the current directory. +# This is done because we assume that the project directory is one level up from the script. +cd .. + +# Now, we use the 'setsid' command to start a new session and run +# IntelliJ IDEA in the background. 'setsid' is a UNIX command that +# runs a program in a new session. + +# The command 'idea .' opens IntelliJ IDEA with the current directory +# as the project directory. The '&' at the end is a UNIX command that +# runs the process in the background. The '> /dev/null' part tells +# the system to redirect all output (both stdout and stderr, denoted +# by '&') that would normally go to the terminal to go to /dev/null +# instead, which is a special file that discards all data written to +# it. + +setsid idea . &>/dev/null & + +# The 'disown' command is a shell built-in that removes a shell job +# from the shell's active list. Therefore, the shell will not send a +# SIGHUP to this particular job when the shell session is terminated. + +# '-h' option specifies that if the shell receives a SIGHUP, it also +# doesn't send a SIGHUP to the job. + +# '$!' is a shell special parameter that expands to the process ID of +# the most recent background job. +disown -h $! + + +sleep 2 + +# Finally, we use the 'exit' command to terminate the shell script. +# This command tells the system to close the terminal window after +# IntelliJ IDEA has been opened. +exit diff --git a/tools/src25th.bas b/tools/src25th.bas index 8d79e0c..afab7df 100755 --- a/tools/src25th.bas +++ b/tools/src25th.bas @@ -1,65 +1,66 @@ -DECLARE SUB chl (a$, b$) -DECLARE SUB getline (a$) -DECLARE SUB start () -DIM SHARED byte AS STRING * 1 -DIM SHARED er +DECLARE SUB processLine (lineContent$, encodedString$) +DECLARE SUB readLine (fileLine$) +DECLARE SUB initializeProgram () +DIM SHARED byte AS STRING * 1 +DIM SHARED errorFlag -start +initializeProgram OPEN COMMAND$ + ".src" FOR INPUT AS #1 -IF er = 0 THEN KILL COMMAND$ + ".5th" +IF errorFlag = 0 THEN KILL COMMAND$ + ".5th" OPEN COMMAND$ + ".5th" FOR BINARY AS #2 -1 -IF EOF(1) <> 0 THEN GOTO 2 -LINE INPUT #1, a$ +ReadLoop: +IF EOF(1) <> 0 THEN GOTO EndOfFile +LINE INPUT #1, fileLine$ + +encodedString$ = "" +tempString$ = "" +FOR charIndex = 1 TO LEN(fileLine$) + currentChar$ = RIGHT$(LEFT$(fileLine$, charIndex), 1) + IF currentChar$ = " " THEN processLine tempString$, encodedString$: encodedString$ = encodedString$ + CHR$(255): GOTO NextChar + IF currentChar$ = CHR$(9) THEN processLine tempString$, encodedString$: encodedString$ = encodedString$ + CHR$(253): GOTO NextChar + tempString$ = tempString$ + currentChar$ + NextChar: +NEXT charIndex -c$ = "" -e$ = "" -FOR b = 1 TO LEN(a$) -d$ = RIGHT$(LEFT$(a$, b), 1) -IF d$ = " " THEN chl e$, c$: c$ = c$ + CHR$(255): GOTO 3 -IF d$ = CHR$(9) THEN chl e$, c$: c$ = c$ + CHR$(253): GOTO 3 -e$ = e$ + d$ -3 -NEXT b -chl e$, c$ -c$ = c$ + CHR$(254) -FOR b = 1 TO LEN(c$) - byte = RIGHT$(LEFT$(c$, b), 1) +processLine tempString$, encodedString$ +encodedString$ = encodedString$ + CHR$(254) + +FOR charIndex = 1 TO LEN(encodedString$) + byte = RIGHT$(LEFT$(encodedString$, charIndex), 1) PUT #2, , byte -NEXT b -GOTO 1 -2 +NEXT charIndex +GOTO ReadLoop +EndOfFile: CLOSE #2 CLOSE #1 SYSTEM +SUB processLine (lineContent$, encodedString$) -SUB chl (a$, b$) +tempEncoded$ = "" +FOR charPosition = 1 TO LEN(lineContent$) + asciiValue = ASC(RIGHT$(LEFT$(lineContent$, charPosition), 1)) + IF (asciiValue >= 48) AND (asciiValue <= 57) THEN asciiValue = asciiValue - 48: GOTO ValidChar + IF (asciiValue >= 65) AND (asciiValue <= 70) THEN asciiValue = asciiValue - 55: GOTO ValidChar + IF (asciiValue = 45) AND (charPosition = 1) THEN GOTO ValidChar + GOTO InvalidChar + ValidChar: + tempEncoded$ = tempEncoded$ + CHR$(asciiValue) +NEXT charPosition -e$ = "" -FOR c = 1 TO LEN(a$) -d = ASC(RIGHT$(LEFT$(a$, c), 1)) -IF (d >= 48) AND (d <= 57) THEN d = d - 48: GOTO 4 -IF (d >= 65) AND (d <= 70) THEN d = d - 55: GOTO 4 -IF (d = 45) AND (c = 1) THEN GOTO 4 -GOTO 5 -4 -e$ = e$ + CHR$(d) -NEXT c -a$ = e$ -5 +lineContent$ = tempEncoded$ +InvalidChar: -b$ = b$ + a$ -a$ = "" +encodedString$ = encodedString$ + lineContent$ +lineContent$ = "" END SUB -SUB start +SUB initializeProgram IF COMMAND$ = "" THEN END -er = 0 +errorFlag = 0 END SUB - diff --git a/tools/synchronize b/tools/synchronize new file mode 100755 index 0000000..bbc8d16 --- /dev/null +++ b/tools/synchronize @@ -0,0 +1,21 @@ +#!/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 diff --git a/tools/update web site b/tools/update web site index 20a52bc..a4d0fd0 100755 --- a/tools/update web site +++ b/tools/update web site @@ -1,5 +1,5 @@ #!/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 ..