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