90e87dd70a4e5366a98c00c556aeb217b490033c
[fifth.git] / doc / index.org
1 #+TITLE: Fifth - virtual machine, operating system, programming language
2
3 -----
4 - [[http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz][download latest snapshot]]
5
6 - This program is free software; you can redistribute it and/or modify it under
7   the terms of version 3 of the [[https://www.gnu.org/licenses/lgpl.html][GNU Lesser General Public License]] or later as
8   published by the Free Software Foundation.
9
10 - Program author:
11   - Svjatoslav Agejenko
12   - Homepage: http://svjatoslav.eu
13   - Email: mailto://svjatoslav@svjatoslav.eu
14
15 - [[http://svjatoslav.eu/programs.jsp][other applications hosted at svjatoslav.eu]]
16
17 * (document settings) :noexport:
18 ** use dark style for TWBS-HTML exporter
19 #+HTML_HEAD: <link href="https://bootswatch.com/darkly/bootstrap.min.css" rel="stylesheet">
20 #+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
21 #+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>"
22 #+HTML_HEAD: <style type="text/css">
23 #+HTML_HEAD:   footer {background-color: #111 !important;}
24 #+HTML_HEAD:   pre {background-color: #111; color: #ccc;}
25 #+HTML_HEAD: </style>
26 * !Project deprecated!
27 Current implementation does not support object oriented
28 programming. While working on Fifth I got lots of cool new ideas that
29 require reimplementation of everything.
30
31 Currently I try to implement those new ideas in the project called
32 [[http://www2.svjatoslav.eu/gitbrowse/sixth/doc/index.html][Sixth]]
33
34 System is built many years ago when I was still using DOS as a primary
35 operating system.
36 * Introduction
37 Fifth is programming lanquage & operating system, running on [[emulator.html][virtual
38 CPU]], with custom instruction set. It is much like Charles Chunk
39 Moore's Forth, it also uses stack architecture, and many commands are
40 similar. Basically I got familiar with concepts of Forth, and being
41 inspired created my own system.
42
43
44
45 [[shots/index.html][Screenshots]]
46
47 Read more about:
48 - [[file:emulator.html][Virtual CPU]]
49 - [[file:commands/index.html][Built-in commands]]
50 - [[file:modules/index.html][Additional commands, realized as loadable modules]]
51 - [[file:5TH_ET.txt][Example Fifth source file - text editor]]
52 * Installation
53 Just unpack all files, witout altering original directory structure,
54 somewhere in your hard disk. For example: C:\MISC\FIFTH\....  To run
55 fifth you need minimally just 2 files.  emulator itself ( EMULATOR.EXE
56 or EMULATOR.COM ), and virtual disk file ( DISK.RAW ).
57
58 Read more about [[files.txt][distribution directory layout]]
59 * Software/Hardware/Human requirements
60 ** Software:
61 - MS-DOS 6.22, with HIMEM.SYS loaded.
62 - Mouse driver if you have a mouse.
63 - Does work only when CPU is in real mode.
64 - To recompile ASM sources I used FASM (Flat Assembler).
65 - I ran QBasic utilities on QB 4.5 .
66 - VESA support by BIOS, or external driver (UNIVBE).
67 ** Hardware:
68 - Minimum CPU 386.
69 - 64 KB free RAM below 640KB,
70 - 2 MB of free XMS.
71 - VESA compatible video card.
72 ** Human:
73 - Beginner level Forth knowledge is recommended.
74 - Lots of enthusiasm.
75 * Numbers representation
76
77 [[file:numbers.png][file:numbers.png]]
78
79 Because I can define everything, starting from CPU, why not try also
80 alternative and unique number representation ?
81
82 Fifth uses its hexdecimal number representation as primary. Numbers
83 shape is formed by dividing a square into four parts. And manipulating
84 their color (black or white).
85 * Disk file map, and it's data structures
86
87
88 Core and high-level boot code is stored outside of the filesystem to
89 allow easy access to it, at early booting time, when filesystem is not
90 yet initialized.
91 ** disk allocation
92 | offset | length | description          |
93 |--------+--------+----------------------|
94 | 0      | ~4 Kb  | Fifth core           |
95 | 4 Kb   | ~32Kb  | high-level boot code |
96 | 37 Kb  | ~65Kb  | FAT                  |
97 | 101Kb  | ~16MB  | filesystem data area |
98 ** FAT entry format:
99 | code | meaning                  |
100 |------+--------------------------|
101 |   -2 | last sector              |
102 |   -1 | empty sector             |
103 | 0 -- | .. pointer to next block |
104 ** file entry format
105 | offset | length | description            |
106 |--------+--------+------------------------|
107 |      0 |      4 | extension              |
108 |      4 |     16 | name                   |
109 |     20 |      4 | entry point            |
110 |     24 |      4 | size                   |
111 |     28 |      4 | last modification time |
112 * Core architecture
113 Fifth core is simply some amount of already compiled into machine code
114 and linked together modules (entries in other words). In compilation
115 process modules is compiled one by one and simply stored on top of
116 already existing and growing core. Separately from core is kept
117 dictionary, this is special list that contain names of compiled
118 modules, variables etc. and they locations in core. Constants use
119 dictionary space only. Random word can be removed from dictionary at
120 any time. Currently dictionary can contain at most 1000 entries.
121 ** dictionary entry format
122 | offset | length | description           |
123 |--------+--------+-----------------------|
124 |      0 |      4 | 0 &lt; previous entry |
125 |        |        | 0 = last              |
126 |        |        | -1 = empty            |
127 |--------+--------+-----------------------|
128 |      4 |     15 | module name string    |
129 |--------+--------+-----------------------|
130 |     19 |      1 | entry type            |
131 |--------+--------+-----------------------|
132 |     20 |      4 | entry data            |
133
134 Core headers as linked list of module names make up something like
135 dictionary.  When some entry address is needed compiler can quickly
136 run through headers backwards and find needed entry.
137 ** Possible module types
138 | type | description    | "execute" action           |
139 |------+----------------+----------------------------|
140 |    0 | data           | compile "num" instruction  |
141 |      |                | with address to module     |
142 |------+----------------+----------------------------|
143 |    1 | submodule      | compile "call" instruction |
144 |      |                | with address to module     |
145 |------+----------------+----------------------------|
146 |    2 | imm. submodule | immediately call to module |
147 ** Memory map: (average)
148 |   <loc> | <size> | <desc>                      |
149 |---------+--------+-----------------------------|
150 |       0 | ~4096  | core                        |
151 | 1500000 | ~32000 | highlevel Fifth boot code   |
152 | 200000h |        | core startup messages area  |
153 | 5200000 |        | end of dynamic memory space |
154 * Fifth source format
155 Fifth uses a different character table and codes than ASCII (still
156 almost similar). I call it FSCII (Fifth Standard Code for Information
157 Interchange) for example space character is not 32 but 255 instead.  I
158 plan to use mainly HEX numbers, and create new characters to represent
159 numeric values. So typical nemric characters "0123..."  is treated
160 like ordinary letters.
161 ** FSCII:
162
163 |    DEC | HEX   | function                               |
164 |--------+-------+----------------------------------------|
165 | 0 - 15 | 0 - F | HEX numbers                            |
166 |    252 | FC    | backspace                              |
167 |    253 | FD    | tabulator (TAB)                        |
168 |    254 | FE    | carriage return (CR)                   |
169 |    255 | FF    | space                                  |
170 |   else |       | ordinary characters, same as in ASCII. |