Added reference to Bibi-binary
[fifth.git] / doc / index.org
index 6096aba..6303947 100644 (file)
@@ -1,94 +1,89 @@
 #+TITLE: Fifth - virtual machine, operating system, programming language
 #+TITLE: Fifth - virtual machine, operating system, programming language
-* (document settings) :noexport:
-** use dark style for TWBS-HTML exporter
-#+HTML_HEAD: <link href="https://bootswatch.com/3/darkly/bootstrap.min.css" rel="stylesheet">
-#+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
-#+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
-#+HTML_HEAD: <style type="text/css">
-#+HTML_HEAD:   footer {background-color: #111 !important;}
-#+HTML_HEAD:   pre {background-color: #111; color: #ccc;}
-#+HTML_HEAD: </style>
 
 * General
 
 * 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
 
 - Program author:
   - Svjatoslav Agejenko
-  - Homepage: http://svjatoslav.eu
+  - Homepage: https://svjatoslav.eu
   - Email: mailto://svjatoslav@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
 ** 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:
 
 - 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
 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
 
 System is built many years ago when I was still using DOS as a primary
-operating system and not updated since.
+operating system.
 * Introduction
 * Introduction
-Fifth is programming lanquage & operating system, running on [[emulator.html][virtual
-CPU]], with custom instruction set. It is much like Charles Chunk
+Fifth is programming lanquage & operating system, running on [[id:9b251eb9-aff6-4025-94bf-25e89e26d54a][virtual
+machine]], 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.
 
 - [[file:5TH_ET.txt][Example Fifth source file - text editor]]
 ** screenshots
 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.
 
 - [[file:5TH_ET.txt][Example Fifth source file - text editor]]
 ** screenshots
-- [[file:screenshots/start.png]]
-  - Startup screen diplaying Fifth logo and full file list.
+[[file:screenshots/start.png]]
+
+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 command line or from file. When executed
+they can be selectively compiled or interpreted.
 
 
-- [[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/text editor.png]]
-  - Built in text editor.
+[[file:screenshots/text editor.png]]
+
+Built in text editor.
 
 * Installation
 Just unpack all files, witout altering original directory structure,
 
 * 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 ).
+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 [[id:0759f3e0-28bb-4901-9e4f-09ef41732173][Fifth distribution directory tree description]].
 
 
-Read more about [[files.txt][distribution directory layout]]
 * 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
 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
 
 #+END_VERSE
 
-* Software/Hardware/Human requirements
+* Requirements
 ** Software
 - MS-DOS 6.22, with HIMEM.SYS loaded.
 - Mouse driver if you have a mouse.
 ** Software
 - MS-DOS 6.22, with HIMEM.SYS loaded.
 - Mouse driver if you have a mouse.
@@ -106,32 +101,40 @@ emulator.com            - main executable.
 - Lots of enthusiasm.
 * Numbers representation within Fifth
 
 - Lots of enthusiasm.
 * 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]]
 
 [[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 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           |
 | 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 |
 ** 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              |
 | offset | length | description            |
 |--------+--------+------------------------|
 |      0 |      4 | extension              |
@@ -174,14 +177,17 @@ run through headers backwards and find needed entry.
 |      |                | with address to module     |
 |------+----------------+----------------------------|
 |    2 | imm. submodule | immediately call to module |
 |      |                | with address to module     |
 |------+----------------+----------------------------|
 |    2 | imm. submodule | immediately call to module |
-** Memory map (average)
-|   <loc> | <size> | <desc>                      |
-|---------+--------+-----------------------------|
-|       0 | ~4096  | core                        |
-| 1500000 | ~32000 | highlevel Fifth boot code   |
-| 200000h |        | core startup messages area  |
-| 5200000 |        | end of dynamic memory space |
+** 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 |
 * Virtual machine
 * Virtual machine
+:PROPERTIES:
+:ID:       9b251eb9-aff6-4025-94bf-25e89e26d54a
+:END:
 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
 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
@@ -203,103 +209,98 @@ CPU has following registers:
 | IP  | instruction pointer  |
 | DSP | data stack pointer   |
 | RSP | return stack pointer |
 | IP  | instruction pointer  |
 | DSP | data stack pointer   |
 | RSP | return stack pointer |
-
+** instruction set
+*** overview table
 Virtual CPU, commands (most of them are avaiable as ordinary commands
 Virtual CPU, commands (most of them are avaiable as ordinary commands
-in programming lanquage):
-
-#+BEGIN_VERSE
-
-code    mnemonic        description
-
-0       nop                     does notheing
-1       halt            halt CPU ( return to DOS on emulator )
-
-2       kbd@            ( -- c ) read scancode of pressed or released key.
-                                Returns 0, if no data avaiable.
-3       num <dword>     ( -- n ) put immidiate number into datastack
-
-4       jmp <dword>     jump to specified code
-5       call <dword>jump to specified code, save return address to
-                                return stack.
-
-6       1+                      ( n -- n+1 )
-7       1-                      ( n -- n-1 )
-
-8       dup                     ( n -- n n ) duplicate top of data stack
-9       drop            ( n -- ) drop last element in data stack
-
-10      if <dword>      ( n -- ) jump to addr if top element was 0
-11      ret                     jump to code, specified in return stack.
-
-12      c@                      ( addr -- n ) read byte from memory at specified address
-13      c!                      ( n addr -- ) store byte to specified memory
-
-14      push            ( DSTK -> RSTK ) move top of datastack to returnstack
-15      pop                     ( RSTK -> DSTK ) move top of returnstack to datastack
-
-16      <unused>
-17      rot                     ( n1 n2 n3 -- n2 n3 n1) rotate stack elements
-
-18      disk@           ( FromDiskSect ToMem -- ) read 1KB from disk into RAM
-19      disk!           ( FromMem ToDiskSect -- ) write 1KB to disk
-
-20      @                       ( addr -- n ) read 32 bit number from memory
-21      !                       ( n addr -- ) store 32 bit number to memory
-
-22      over            ( n1 n2 -- n1 n2 n1 ) self explaining ...
-23      swap            ( n1 n2 -- n2 n1 ) -,,-
-
-24      +                       ( n1 n2 -- n1+n2 ) -,,-
-25      -                       ( n1 n2 -- n1-n2 ) -,,-
-
-26      *                       ( n1 n2 -- n1*n2 ) -,,-
-27      /                       ( n1 n2 -- n1/n2 ) -,,-
-
-28      >                       ( n1 n2 -- result ) is true when n1 > n2
-29      <                       ( n1 n2 -- result ) is true when n1 < n2
-
-30      not                     ( n1 -- not_n1 ) logical not
-31      i                       ( -- n ) copies top of return stack into datastack
-
-32      cprt@           ( addr -- n ) read one byte from hardware port
-33      cprt!           ( n addr -- ) store one byte to hardware port
-
-34      i2                      ( -- n ) like "i" but takes socond top stack element.
-35      i3                      ( -- n ) like "i" but takes third top stack element.
-
-36      shl                     ( n amount -- n ) left bit shift
-37      shr                     ( n amount -- n ) right bit shift
-
-38      or                      ( n1 n2 -- n ) logical or
-39      xor                     ( n1 n2 -- n ) exclusive logical or
-
-40      vidmap          ( addr -- ) copy memory from "addr" to video memory.
-
-41      mouse@          ( -- x y button ) read mouse coordinates & buttons
-
-42      vidput          ( addr1 addr2 x y -- ) put image1 into image2, at
-                                location x, y. Does clipping, so part of a big image
-                                can be mapped into smaller one.
-
-43      cmove           ( addr1 addr2 amount ) move memory from addr1 to addr2
-                                if addr1 is greater than addr2 then count address
-                                foward while moving, elseway starts from end and
-                                counts backwards, so no data loss will occure on
-                                overlapping.
-
-44      cfill           ( c addr amount -- ) fill memory starting at "addr"
-                                with "c" bytes.
-
-45      tvidput         ( addr1 addr2 x y -- ) same as "vidput" but treats
-                                color 255 in source image as transparent.
-
-46      depth           ( -- depth ) returns current depth of data stack.
-
-47      charput         ( colorfg colorbg addrsrc addrdest x y )
-                                draw character to image buffer located at "addrdest"
-                                to specified x & y location. Decodes 8 bytes from
-                                source to bits, used to draw character.
-#+END_VERSE
+in programming language):
+
+
+|  # | name         | stack footprint                      | description                                                 |
+|----+--------------+--------------------------------------+-------------------------------------------------------------|
+|  0 | nop          | --                                   | does nothing                                                |
+|  1 | halt         | --                                   | halt CPU ( return to DOS on emulator )                      |
+|  2 | [[id:820b1b90-4f4c-4ab1-b49f-9b4a52ea2528][kbd@]]         | -- c                                 | read scancode of pressed or released key                    |
+|  3 | num <dword>  | -- n                                 | put immidiate number into datastack                         |
+|  4 | jmp <dword>  | --                                   | jump to specified code                                      |
+|  5 | call <dword> |                                      | jump to specified code, save return address to return stack |
+|  6 | 1+           | n -- n+1                             |                                                             |
+|  7 | 1-           | n -- n-1                             |                                                             |
+|  8 | dup          | n -- n n                             | duplicate top of data stack                                 |
+|  9 | drop         | n --                                 | drop last element in data stack                             |
+| 10 | if <dword>   | n --                                 | jump to addr if top element was 0                           |
+| 11 | ret          |                                      | jump to code, specified in return stack.                    |
+| 12 | c@           | addr -- n                            | read byte from memory at specified address                  |
+| 13 | c!           | n addr --                            | store byte to specified memory                              |
+| 14 | push         | DSTK -> RSTK                         | move top of datastack to returnstack                        |
+| 15 | pop          | RSTK -> DSTK                         | move top of returnstack to datastack                        |
+| 16 | <unused>     |                                      |                                                             |
+| 17 | rot          | n1 n2 n3 -- n2 n3 n1                 | rotate stack elements                                       |
+| 18 | disk@        | FromDiskSect ToMem --                | read 1KB from disk into RAM                                 |
+| 19 | disk!        | FromMem ToDiskSect --                | write 1KB to disk                                           |
+| 20 | @            | addr -- n                            | read 32 bit number from memory                              |
+| 21 | !            | n addr --                            | store 32 bit number to memory                               |
+| 22 | over         | n1 n2 -- n1 n2 n1                    |                                                             |
+| 23 | swap         | n1 n2 -- n2 n1                       |                                                             |
+| 24 | +            | n1 n2 -- n1+n2                       |                                                             |
+| 25 | -            | n1 n2 -- n1-n2                       |                                                             |
+| 26 | *            | n1 n2 -- n1*n2                       |                                                             |
+| 27 | /            | n1 n2 -- n1/n2                       |                                                             |
+| 28 | >            | n1 n2 -- result                      | is true when n1 > n2                                        |
+| 29 | <            | n1 n2 -- result                      | is true when n1 < n2                                        |
+| 30 | not          | n1 -- not_n1                         | logical not                                                 |
+| 31 | i            | -- n                                 | copies top of return stack into datastack                   |
+| 32 | cprt@        | addr -- n                            | read one byte from hardware port                            |
+| 33 | cprt!        | n addr --                            | store one byte to hardware port                             |
+| 34 | i2           | -- n                                 | like "i" but takes second top stack element                 |
+| 35 | i3           | -- n                                 | like "i" but takes third top stack element.                 |
+| 36 | shl          | n amount -- n                        | left bit shift                                              |
+| 37 | shr          | n amount -- n                        | right bit shift                                             |
+| 38 | or           | n1 n2 -- n                           | logical or                                                  |
+| 39 | xor          | n1 n2 -- n                           | exclusive logical or                                        |
+| 40 | vidmap       | addr --                              | copy memory from "addr" to video memory.                    |
+| 41 | mouse@       | -- x y button                        | read mouse coordinates & buttons                            |
+| 42 | [[id:238e8b03-57b6-424d-bfee-b6bb652cefbc][vidput]]       | addr1 addr2 x y --                   | put image1 into image2, at location x, y                    |
+| 43 | [[id:79e1916f-4103-42cc-ac10-bb1ee776ed50][cmove]]        | addr1 addr2 amount                   | move memory from addr1 to addr2                             |
+| 44 | cfill        | c addr amount --                     | fill memory starting at "addr" with "c" bytes.              |
+| 45 | [[id:ab45247c-44c3-464d-9e2a-337f483b4616][tvidput]]      | addr1 addr2 x y --                   | put image with transparency support                         |
+| 46 | depth        | -- depth                             | returns current depth of data stack.                        |
+| 47 | [[id:4bb479cf-aae0-4128-9868-f016c286a162][charput]]      | colorfg colorbg addrsrc addrdest x y | draw text character                                         |
+
+*** kbd@ - read scancode of pressed or released key
+:PROPERTIES:
+:ID:       820b1b90-4f4c-4ab1-b49f-9b4a52ea2528
+:END:
+Returns 0 if no data available.
+*** vidput - put image1 into image2, at location x, y
+:PROPERTIES:
+:ID:       238e8b03-57b6-424d-bfee-b6bb652cefbc
+:END:
+Does clipping, so part of a big image can be mapped into smaller one.
+*** cmove - copy memory array
+:PROPERTIES:
+:ID:       79e1916f-4103-42cc-ac10-bb1ee776ed50
+:END:
+Move memory from addr1 to addr2. If addr1 is greater than addr2 then
+count address foward while moving, elseway starts from end and counts
+backwards, so no data loss occurs when memory regions partially
+overlap.
+*** tvidput - put image with transparency support
+:PROPERTIES:
+:ID:       ab45247c-44c3-464d-9e2a-337f483b4616
+:END:
+Stack footprint
+: addr1 addr2 x y --
+
+Put image1 into image2, at location x, y with transparency support
+
+Color 255 in source image is treated as transparent.
+*** charput - draw text character
+:PROPERTIES:
+:ID:       4bb479cf-aae0-4128-9868-f016c286a162
+:END:
+Draw character to image buffer located at "addrdest" to specified x &
+y location. Decodes 8 bytes from source to bits, used to draw
+character.
 
 * Fifth source format
 Fifth uses a different character table and codes than ASCII (still
 
 * Fifth source format
 Fifth uses a different character table and codes than ASCII (still
@@ -926,30 +927,38 @@ mousedo         ( -- ) Updates mouse coordinates and keys. Parse mouse
                 click buffer, and draw mouse cursor to "screen".
 #+END_VERSE
 ** 2D graphic library
                 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.