1 #+TITLE: Fifth - virtual machine, operating system, programming language
4 - This program is free software: released under Creative Commons Zero
9 - Homepage: https://svjatoslav.eu
10 - Email: mailto://svjatoslav@svjatoslav.eu
12 - [[https://www.svjatoslav.eu/projects/][Other software projects hosted at svjatoslav.eu]]
15 - [[https://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=snapshot;h=HEAD;sf=tgz][Download latest snapshot in TAR GZ format]]
17 - [[https://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=summary][Browse Git repository online]]
19 - Clone Git repository using command:
20 : git clone https://www2.svjatoslav.eu/git/fifth.git
22 * !Project deprecated!
23 Current implementation does not support object oriented
24 programming. While working on Fifth I got lots of cool new ideas that
25 require reimplementation of everything.
27 Currently I try to implement those new ideas in the project called
28 [[https://www3.svjatoslav.eu/projects/sixth/][Sixth]].
30 System is built many years ago when I was still using DOS as a primary
33 Fifth is a combination of:
34 - [[id:da7fff9b-0b67-4843-828a-52a404d7f401][Programming language]] (inspired by Forth).
36 - [[id:9b251eb9-aff6-4025-94bf-25e89e26d54a][Virtual machine]] with custom instruction set.
37 - [[file:5TH_ET.txt][Example Fifth source file - text editor]]
39 [[file:screenshots/start.png]]
41 Startup screen diplaying Fifth logo and full file list.
43 [[file:screenshots/dictionary.png]]
45 Sample words defined. Most of the words are commands that can be
46 executed interactively from command line or from file. When executed
47 they can be selectively compiled or interpreted.
50 [[file:screenshots/text editor.png]]
55 Just unpack all files, witout altering original directory structure,
56 somewhere in your hard disk. For example: C:\MISC\FIFTH\.... To run
57 fifth you need minimally just 2 files. emulator itself ( EMULATOR.EXE
58 or EMULATOR.COM ), and virtual disk file ( DISK.RAW ).
60 Read more about [[id:0759f3e0-28bb-4901-9e4f-09ef41732173][Fifth distribution directory tree description]].
62 * Fifth distribution directory tree description
64 :ID: 0759f3e0-28bb-4901-9e4f-09ef41732173
66 After downloading and unpacking the ZIP file you shoud get directory
70 *DOC* - Fifth documentation
71 *commands* - documentation on Fifth built-in commands
72 *modules* - documentation on additional commands, realized as loadable modules
73 *shots* - Fifth screenshots
75 *imageFile* - files contained within 'disk.raw', just an extracted form.
77 *source* - source files
78 *emulator* - emulator source
81 *disk.raw* - Virtual disk file, has filesystem inside.
82 *emulator.com* - main executable.
87 - MS-DOS 6.22, with HIMEM.SYS loaded.
88 - Mouse driver if you have a mouse.
89 - Does work only when CPU is in real mode.
90 - To recompile ASM sources I used FASM (Flat Assembler).
91 - I ran QBasic utilities on QB 4.5 .
92 - VESA support by BIOS, or external driver (UNIVBE).
95 - 64 KB free RAM below 640KB,
97 - VESA compatible video card.
99 - Beginner level Forth knowledge is recommended.
100 - Lots of enthusiasm.
101 * Numbers representation within Fifth
103 Because we are in full experimentation mode here (no regard for
104 compatibility whatsoever), why not to try also alternative number
107 Here alternative hexadecimal number representation format is devised:
109 [[file:numbers.png][file:numbers.png]]
111 Essentially square is split into 4 triangles. Each triangle represents
114 Fifth uses this hexadecimal format as primary throughout entire
117 See also: [[https://en.wikipedia.org/wiki/Bibi-binary][Bibi-binary]].
119 * Disk file map, and it's data structures
120 Core and high-level boot code is stored outside of the filesystem to
121 allow easy access to it, at early booting time, when filesystem is not
124 | offset | length | description |
125 |--------+--------+----------------------|
126 | 0 | ~4 Kb | Fifth core |
127 | 4 Kb | ~32 Kb | high-level boot code |
128 | 37 Kb | ~65 Kb | FAT |
129 | 101 Kb | ~16 MB | filesystem data area |
132 |------+--------------------------|
134 | -1 | empty sector |
135 | 0 -- | .. pointer to next block |
137 | offset | length | description |
138 |--------+--------+------------------------|
139 | 0 | 4 | extension |
141 | 20 | 4 | entry point |
143 | 28 | 4 | last modification time |
145 Fifth core is simply some amount of already compiled into machine code
146 and linked together modules (entries in other words). In compilation
147 process modules is compiled one by one and simply stored on top of
148 already existing and growing core. Separately from core is kept
149 dictionary, this is special list that contain names of compiled
150 modules, variables etc. and they locations in core. Constants use
151 dictionary space only. Random word can be removed from dictionary at
152 any time. Currently dictionary can contain at most 1000 entries.
153 ** Dictionary entry format
154 | offset | length | description |
155 |--------+--------+-----------------------|
156 | 0 | 4 | 0 < previous entry |
159 |--------+--------+-----------------------|
160 | 4 | 15 | module name string |
161 |--------+--------+-----------------------|
162 | 19 | 1 | entry type |
163 |--------+--------+-----------------------|
164 | 20 | 4 | entry data |
166 Core headers as linked list of module names make up something like
167 dictionary. When some entry address is needed compiler can quickly
168 run through headers backwards and find needed entry.
169 ** Possible module types
170 | type | description | "execute" action |
171 |------+----------------+----------------------------|
172 | 0 | data | compile "num" instruction |
173 | | | with address to module |
174 |------+----------------+----------------------------|
175 | 1 | submodule | compile "call" instruction |
176 | | | with address to module |
177 |------+----------------+----------------------------|
178 | 2 | imm. submodule | immediately call to module |
180 | location | size | description |
181 |----------+--------+-----------------------------|
183 | 1500000 | ~32000 | highlevel Fifth boot code |
184 | 200000h | | core startup messages area |
185 | 5200000 | | end of dynamic memory space |
186 * Dynamically loadable modules
190 KBD_@ ( -- code ) get scancodes for pressed keys from keyboard.
191 KBD_down? ( key -- result ) check is key with specified scancode
192 currently pressed down.
193 KBD_SC2FSCII ( code -- FSCII ) convert key scancode into FSCII code,
194 or in FSK (Fifth standard keycode).
195 KBD_F@ ( -- FSCII ) read pressed key FSCII or FSK, returns -1 if no
197 KBD_FW@ ( -- FSCII ) read pressed key FSCII or FSK, if no keys is
198 are pressed then waits until there is.
224 mousex var Mouse x coordinate.
225 mousey var Mouse y coordinate.
226 mousekeyl var Mouse left key.
227 mousekeym var Mouse middle key.
228 mousekeyr var Mouse right key.
229 mousec var Display current mouse coordinates in top left part of screen,
230 if true. (good for debugging)
231 mousepointer var Image buffer, holding current mouse pointer.
232 mouseadd ( ModuleAddr x1 x2 y1 y2 -- ) Add specified area on screen,
233 into mause click buffer. If any mouse button is clicked on
234 that area, module at "ModuleAddr" will be executed.
235 mousebe var Amount of buffer elements.
236 mousedo ( -- ) Updates mouse coordinates and keys. Parse mouse
237 click buffer, and draw mouse cursor to "screen".
239 ** 2D graphic library
241 + lineh ( color len x y imgbuf -- ) :: draws horisontal line from X,Y
242 coordinates to right, with specified length.
244 + linev ( color len x y imgbuf -- ) :: draws vertical line down, from
245 coordinates X,Y, with specified length.
247 + box ( color x2 x1 y2 y1 imgbuf -- ) :: draws rectangular box. x2
248 bust be >= x1, y2 must be >= y1.
257 + flipv ( imgbuf -- ) :: flip image vertically.
259 + imgcoltrans ( ImgBuf Color ToColor -- ) :: Translate all pixels in
260 specified image with "Color" into "ToColor".
262 + imgfill ( color x y imgbuf -- ) :: Fill image region starting at
263 location X & Y with specified color.
265 ** Trigonometry functions
266 *** sin ( a -- result )
268 :ID: 9a66ca9c-eb5f-45aa-8116-71763081f2fb
270 Return sinus from given angle "a", 360ø is 2000. So 1000 represents
271 180ø angle. Result will be in range -10'000 to 10'000, instead of ñ1.
272 *** cos ( a -- result )
273 Return cosinus from given angle. Parameters are like in [[id:9a66ca9c-eb5f-45aa-8116-71763081f2fb][sin]] function.