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]]
14 - [[https://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=snapshot;h=HEAD;sf=tgz][Download latest snapshot in TAR GZ format]]
16 - [[https://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=summary][Browse Git repository online]]
18 - Clone Git repository using command:
19 : git clone https://www2.svjatoslav.eu/git/fifth.git
21 * !Project deprecated!
22 Current implementation does not support object oriented
23 programming. While working on Fifth I got lots of cool new ideas that
24 require reimplementation of everything.
26 Currently I try to implement those new ideas in the project called
27 [[https://www3.svjatoslav.eu/projects/sixth/][Sixth]].
29 System is built many years ago when I was still using DOS as a primary
32 Fifth is programming lanquage & operating system, running on [[id:9b251eb9-aff6-4025-94bf-25e89e26d54a][virtual
33 machine]], with custom instruction set. It is much like Charles Chunk
34 Moore's Forth, it also uses stack architecture, and many commands are
35 similar. Basically I got familiar with concepts of Forth, and being
36 inspired created my own system.
38 - [[file:5TH_ET.txt][Example Fifth source file - text editor]]
40 [[file:screenshots/start.png]]
42 Startup screen diplaying Fifth logo and full file list.
44 [[file:screenshots/dictionary.png]]
46 Sample words defined. Most of the words are commands that can be
47 executed interactively from command line or from file. When executed
48 they can be selectively compiled or interpreted.
51 [[file:screenshots/text editor.png]]
56 Just unpack all files, witout altering original directory structure,
57 somewhere in your hard disk. For example: C:\MISC\FIFTH\.... To run
58 fifth you need minimally just 2 files. emulator itself ( EMULATOR.EXE
59 or EMULATOR.COM ), and virtual disk file ( DISK.RAW ).
61 Read more about [[id:0759f3e0-28bb-4901-9e4f-09ef41732173][Fifth distribution directory tree description]].
63 * Fifth distribution directory tree description
65 :ID: 0759f3e0-28bb-4901-9e4f-09ef41732173
67 After downloading and unpacking the ZIP file you shoud get directory
71 *DOC* - Fifth documentation
72 *commands* - documentation on Fifth built-in commands
73 *modules* - documentation on additional commands, realized as loadable modules
74 *shots* - Fifth screenshots
76 *imageFile* - files contained within 'disk.raw', just an extracted form.
78 *source* - source files
79 *emulator* - emulator source
82 *disk.raw* - Virtual disk file, has filesystem inside.
83 *emulator.com* - main executable.
88 - MS-DOS 6.22, with HIMEM.SYS loaded.
89 - Mouse driver if you have a mouse.
90 - Does work only when CPU is in real mode.
91 - To recompile ASM sources I used FASM (Flat Assembler).
92 - I ran QBasic utilities on QB 4.5 .
93 - VESA support by BIOS, or external driver (UNIVBE).
96 - 64 KB free RAM below 640KB,
98 - VESA compatible video card.
100 - Beginner level Forth knowledge is recommended.
101 - Lots of enthusiasm.
102 * Numbers representation within Fifth
104 Because we are in full experimentation mode here (no regard for
105 compatibility whatsoever), why not to try also alternative number
108 Here alternative hexadecimal number representation format is devised:
110 [[file:numbers.png][file:numbers.png]]
112 Essentially square is split into 4 triangles. Each triangle represents
115 Fifth uses this hexadecimal format as primary throughout entire
118 See also: [[https://en.wikipedia.org/wiki/Bibi-binary][Bibi-binary]].
120 * Disk file map, and it's data structures
121 Core and high-level boot code is stored outside of the filesystem to
122 allow easy access to it, at early booting time, when filesystem is not
125 | offset | length | description |
126 |--------+--------+----------------------|
127 | 0 | ~4 Kb | Fifth core |
128 | 4 Kb | ~32 Kb | high-level boot code |
129 | 37 Kb | ~65 Kb | FAT |
130 | 101 Kb | ~16 MB | filesystem data area |
133 |------+--------------------------|
135 | -1 | empty sector |
136 | 0 -- | .. pointer to next block |
138 | offset | length | description |
139 |--------+--------+------------------------|
140 | 0 | 4 | extension |
142 | 20 | 4 | entry point |
144 | 28 | 4 | last modification time |
146 Fifth core is simply some amount of already compiled into machine code
147 and linked together modules (entries in other words). In compilation
148 process modules is compiled one by one and simply stored on top of
149 already existing and growing core. Separately from core is kept
150 dictionary, this is special list that contain names of compiled
151 modules, variables etc. and they locations in core. Constants use
152 dictionary space only. Random word can be removed from dictionary at
153 any time. Currently dictionary can contain at most 1000 entries.
154 ** Dictionary entry format
155 | offset | length | description |
156 |--------+--------+-----------------------|
157 | 0 | 4 | 0 < previous entry |
160 |--------+--------+-----------------------|
161 | 4 | 15 | module name string |
162 |--------+--------+-----------------------|
163 | 19 | 1 | entry type |
164 |--------+--------+-----------------------|
165 | 20 | 4 | entry data |
167 Core headers as linked list of module names make up something like
168 dictionary. When some entry address is needed compiler can quickly
169 run through headers backwards and find needed entry.
170 ** Possible module types
171 | type | description | "execute" action |
172 |------+----------------+----------------------------|
173 | 0 | data | compile "num" instruction |
174 | | | with address to module |
175 |------+----------------+----------------------------|
176 | 1 | submodule | compile "call" instruction |
177 | | | with address to module |
178 |------+----------------+----------------------------|
179 | 2 | imm. submodule | immediately call to module |
181 | location | size | description |
182 |----------+--------+-----------------------------|
184 | 1500000 | ~32000 | highlevel Fifth boot code |
185 | 200000h | | core startup messages area |
186 | 5200000 | | end of dynamic memory space |
189 :ID: 9b251eb9-aff6-4025-94bf-25e89e26d54a
191 Using CPU emulator slows it down but I shouldn't now think too mutch
192 about, and waste my time on batteling with problems whitch results on
193 complex design of PC hardware. Also it allows me to use existing DOS
194 and resident drivers services in real mode. So I don't need to deal
195 with hardware too mutch. It also allows me to use all free XMS for
196 flat code & data storage.
198 Current emulator emulates 1 CPU. It has 2 stacks, ~50 instructions,
199 and 4GB flat address space (theoretically). I'm not sure that DOS
200 6.22 that I currently prefer can handle more than 64 MB of RAM. While
201 I tried to keep instructionset simple, I was forced to put in lot of
202 complex instructions to make it's performance acceptable on
203 emulator. On actual silicon ~20 instructions is enaugh (I think).
205 Maybe one day similar system will run directly on custom silicon chip :)
208 CPU has following registers:
209 | IP | instruction pointer |
210 | DSP | data stack pointer |
211 | RSP | return stack pointer |
214 Virtual CPU, commands (most of them are avaiable as ordinary commands
215 in programming language):
218 | # | name | stack footprint | description |
219 |----+--------------+--------------------------------------+-------------------------------------------------------------|
220 | 0 | nop | -- | does nothing |
221 | 1 | halt | -- | halt CPU ( return to DOS on emulator ) |
222 | 2 | [[id:820b1b90-4f4c-4ab1-b49f-9b4a52ea2528][kbd@]] | -- c | read scancode of pressed or released key |
223 | 3 | num <dword> | -- n | put immidiate number into datastack |
224 | 4 | jmp <dword> | -- | jump to specified code |
225 | 5 | call <dword> | | jump to specified code, save return address to return stack |
226 | 6 | 1+ | n -- n+1 | |
227 | 7 | 1- | n -- n-1 | |
228 | 8 | dup | n -- n n | duplicate top of data stack |
229 | 9 | drop | n -- | drop last element in data stack |
230 | 10 | if <dword> | n -- | jump to addr if top element was 0 |
231 | 11 | ret | | jump to code, specified in return stack. |
232 | 12 | c@ | addr -- n | read byte from memory at specified address |
233 | 13 | c! | n addr -- | store byte to specified memory |
234 | 14 | push | DSTK -> RSTK | move top of datastack to returnstack |
235 | 15 | pop | RSTK -> DSTK | move top of returnstack to datastack |
236 | 16 | <unused> | | |
237 | 17 | rot | n1 n2 n3 -- n2 n3 n1 | rotate stack elements |
238 | 18 | disk@ | FromDiskSect ToMem -- | read 1KB from disk into RAM |
239 | 19 | disk! | FromMem ToDiskSect -- | write 1KB to disk |
240 | 20 | @ | addr -- n | read 32 bit number from memory |
241 | 21 | ! | n addr -- | store 32 bit number to memory |
242 | 22 | over | n1 n2 -- n1 n2 n1 | |
243 | 23 | swap | n1 n2 -- n2 n1 | |
244 | 24 | + | n1 n2 -- n1+n2 | |
245 | 25 | - | n1 n2 -- n1-n2 | |
246 | 26 | * | n1 n2 -- n1*n2 | |
247 | 27 | / | n1 n2 -- n1/n2 | |
248 | 28 | > | n1 n2 -- result | is true when n1 > n2 |
249 | 29 | < | n1 n2 -- result | is true when n1 < n2 |
250 | 30 | not | n1 -- not_n1 | logical not |
251 | 31 | i | -- n | copies top of return stack into datastack |
252 | 32 | cprt@ | addr -- n | read one byte from hardware port |
253 | 33 | cprt! | n addr -- | store one byte to hardware port |
254 | 34 | i2 | -- n | like "i" but takes second top stack element |
255 | 35 | i3 | -- n | like "i" but takes third top stack element. |
256 | 36 | shl | n amount -- n | left bit shift |
257 | 37 | shr | n amount -- n | right bit shift |
258 | 38 | or | n1 n2 -- n | logical or |
259 | 39 | xor | n1 n2 -- n | exclusive logical or |
260 | 40 | vidmap | addr -- | copy memory from "addr" to video memory. |
261 | 41 | mouse@ | -- x y button | read mouse coordinates & buttons |
262 | 42 | [[id:238e8b03-57b6-424d-bfee-b6bb652cefbc][vidput]] | addr1 addr2 x y -- | put image1 into image2, at location x, y |
263 | 43 | [[id:79e1916f-4103-42cc-ac10-bb1ee776ed50][cmove]] | addr1 addr2 amount | move memory from addr1 to addr2 |
264 | 44 | cfill | c addr amount -- | fill memory starting at "addr" with "c" bytes. |
265 | 45 | [[id:ab45247c-44c3-464d-9e2a-337f483b4616][tvidput]] | addr1 addr2 x y -- | put image with transparency support |
266 | 46 | depth | -- depth | returns current depth of data stack. |
267 | 47 | [[id:4bb479cf-aae0-4128-9868-f016c286a162][charput]] | colorfg colorbg addrsrc addrdest x y | draw text character |
269 *** kbd@ - read scancode of pressed or released key
271 :ID: 820b1b90-4f4c-4ab1-b49f-9b4a52ea2528
273 Returns 0 if no data available.
274 *** vidput - put image1 into image2, at location x, y
276 :ID: 238e8b03-57b6-424d-bfee-b6bb652cefbc
278 Does clipping, so part of a big image can be mapped into smaller one.
279 *** cmove - copy memory array
281 :ID: 79e1916f-4103-42cc-ac10-bb1ee776ed50
283 Move memory from addr1 to addr2. If addr1 is greater than addr2 then
284 count address foward while moving, elseway starts from end and counts
285 backwards, so no data loss occurs when memory regions partially
287 *** tvidput - put image with transparency support
289 :ID: ab45247c-44c3-464d-9e2a-337f483b4616
294 Put image1 into image2, at location x, y with transparency support
296 Color 255 in source image is treated as transparent.
297 *** charput - draw text character
299 :ID: 4bb479cf-aae0-4128-9868-f016c286a162
301 Draw character to image buffer located at "addrdest" to specified x &
302 y location. Decodes 8 bytes from source to bits, used to draw
305 * Fifth source format
306 Fifth uses a different character table and codes than ASCII (still
307 almost similar). I call it FSCII (Fifth Standard Code for Information
308 Interchange) for example space character is not 32 but 255 instead. I
309 plan to use mainly HEX numbers, and create new characters to represent
310 numeric values. So typical nemric characters "0123..." is treated
311 like ordinary letters.
314 | DEC | HEX | function |
315 |--------+-------+----------------------------------------|
316 | 0 - 15 | 0 - F | HEX numbers |
317 | 252 | FC | backspace |
318 | 253 | FD | tabulator (TAB) |
319 | 254 | FE | carriage return (CR) |
321 | else | | ordinary characters, same as in ASCII. |
323 ** Compilation & miscellaneous
326 First module, control is passed to on startup. Contains
327 initialization routines. Also it is the last core module.
328 All new modules on top of it comes as result of executing
329 external source files.
331 head <name> ( -- ) compiles new dictionary entry without specifying
335 : <name> ( -- ) creates new code module
336 ; ( -- ) ends module (immideate)
337 ex: : hello ." hi there" ;
339 const <name> ( n -- ) defines new constant.
340 ex: 2147483647 const max
342 :i <name> ( -- ) same as ":" but this module will be executed
343 immideately even in compile mode.
346 create <name> ( -- ) same as "head" , but specify module type as data.
347 ex: create LotoResults 5 , 13 , 52 , 12 , 11 , 3 ,
349 allot ( n -- ) allocate n bytes in dictionary.
350 ex: create MyArray 100 allot
352 " <string>" ( -- ) compile string and its size into core.
353 ex: create Mystring " This is it's contects"
355 str <name> <string>" ( -- ) just shorter way for defining strings.
356 ex: str Mystring This is it's contenc"
358 var <name> ( -- ) define new 32 bit variable.
361 ' <module> ( -- n ) return memory address of given entry.
364 forget <name> ( -- ) erases from RAM given entry and all entries what was
368 [ ( -- ) set interpret mode (immideate)
369 ] ( n -- ) set compile mode and compile top stack element
370 in as literal. Together [ .... ] cobination provides good
371 way to compute some values only once, at compile time,
372 rather than every time while program is running.
373 ex: : calculate - [ 4 MyConst1 + MyConst2 * ] ;
375 defer <name> ( -- ) creates new module, with jump instruction.
376 Later address where to jump can be modified by "is" command.
377 This provides method of foward referencing. So you can use
378 modules what not jet exist.
379 is ( address1 address2 -- ) address1 - where to jump, address2 -
380 address of module created by defer command.
382 : run dispver ." running ..." ;
384 : (dispver ." Version 9.99 " ;
385 ' (dispver ' dispver is
387 Now if I type "run" on the screen appears:
388 Version 9.99 running ...
390 asc <char> ( -- ) reads char ascii code and treats it as literal.
392 ex: : BreakLine 30 do asc - emit loop ;
394 : BreakLine 30 do 45 emit loop ;
396 dyninc ( handle -- ) execute code in dynamic memory handle.
397 automatically deallocates it when done.
399 include ( filenumber -- ) execute code in specified file.
401 words ( -- ) display existing blocks in core.
403 bye ( -- ) exit from Fifth
406 Read one byte from input stream.
409 Add one byte "c" to string located at "addr" and updates
413 Read input stream and store it to pad until it finds c .
414 It ignores all "c" bytes until it finds any non "c" byte.
417 input stream: """"This is test !"aoeu idh
418 result: This is test !
420 Is useful for breaking text lines into words.
423 So called safe "fkey". Reads data from input stream
424 but converts characters with ASCII codes: 9 13 10
427 str=str? ( adr1 adr2 -- result )
428 Compares string at "adr1" with string at "adr2", returns
429 true flag if they are equal or false if they are not.
434 Searches whole dictionary for word in "pad". If found,
435 returns it address, if not, returns 0.
438 Execute word located in "pad". Depending on "mode".
440 dta ( addr -- DataAddr )
441 Calculates address of dictionary entry data area, from
444 2num ( -- num result )
445 Attempt to convert string located in "pad" into numeric
446 value. If succeed returns number and true as result.
447 If not, returns whatever and false as result.
449 dadd ( addr length -- )
450 Add to dictionary data located at "addr", with specified
454 Act with number depending on "mode". When interpreting,
459 Add to dictionary data located at "addr"+1 , length is taken
466 Holds input stream parser operation mode.
471 Holds temprorary strings.
474 Pointer to free byte in memory, always at the end of the
475 dictionary. Each time when something is stored
476 by "c," command, pointer is incareased.
479 Pointer to last dictionary word. Each time when new word is
480 compiled or erased by "forget", this pointer is updated.
482 modulechk ( Dstr<filename> -- ) check if module is loaded, if not
485 ne ( entrydata entrytype -- ) Compile new dictionary entry.
486 It's name must be in "pad".
488 ** Conditionals & control flow
490 if ( flag -- ) (immideate)
491 "if 1.. else 2.. then" or
492 "if 1.. then" construction. Conditional execution.
493 Performs "1.." if "flag" was true,
494 elseway performs "2.." if exist. Execution continues after
496 ex: 1 if ." nonzero" else ." zero" then
498 >= ( n1 n2 -- result ) true if (n1 = n2) or (n1 > n2)
499 ex: 5 3 >= if ." first number is greater or equal" then
501 <= ( n1 n2 -- result ) true if (n1 = n2) or (n1 < n2)
502 = ( n1 n2 -- result ) true if n1 = n2
504 do ( count -- ) (immideate)
505 "do .. loop" construction. Performs ".." "count" times.
506 In every step "count" is decareased until it is 0.
507 ex: : test 5 do i .d loop ;
510 doexit ( -- ) exit from "do .. loop"
512 for ( count top -- ) (immideate)
513 "for .. loop" construction. Performs ".." (top - count) times.
514 In every step "count" is incareased until it reaches "top" .
515 ex: : test 4 10 for i .d loop ;
518 forexit ( -- ) exit from "for .. loop"
520 until ( -- ) (immideate)
521 "until .. loop" construction. Performs ".." until flag become
522 true. False by default. Top of return stack holds flag.
524 done ( -- ) exit from "until .. loop"
527 ** Disk & file access
529 diskload ( FromDisk ToMem amount -- )
530 Load specified abount of bytes from disk into memory.
532 disksave ( FromMem ToDisk amount -- )
533 save specified abount of bytes from memory into disk.
535 format ( -- ) Erase all files.
537 fsDfilesize@ ( handle -- size )
538 Return size of opened file.
540 fsDcurloc@ ( handle -- location )
541 Return current location in file.
543 fsDupdated@ ( handle -- updated? )
544 Return true if file was updated,
545 ie. write operations occured.
547 fssave ( FromMem DestFileHandle amount -- )
550 fsload ( SrcFileHandle ToMem amount -- )
553 fseof ( handle -- bytesLeft )
554 Return amount of bytes left till end of file.
555 Useful before read operation.
557 fsls ( -- ) List all files and lists (directories,folders)
560 fslsr ( -- ) Same as "fsls" but recursively scans also sub lists.
562 fscl ( DynStrHand -- )
565 fscreate ( DynStrHand -- DescPnt )
566 Create new file or list. Can create multiple lists at once.
568 "\listGAMES\listSTRATEGY\listSIMWORLD\5th-runme"
569 and only "\listGAMES\" already exist, then
570 "listSTRATEGY" and "listSIMWORLD" lists will be created,
571 and empty file "5th-runme" placed in there.
573 fsDsave ( DynHand<data> DynStrHand<filename> -- )
574 Create new file and save all data from dynamic memory
577 fsDload ( DynStr<SrcFileName> DynHand<DataDest> -- )
578 Load whole file into dynamic memory block.
580 fsDloadnew ( DynStr<SrcFileName> -- DynHand<DataDest> )
581 Load whole file into new dynamic memory block.
585 dynal ( size -- handle )
586 Allocate dynamic memory block and return it's handle.
589 Deallocate dynamic memory block.
591 dynp ( handle -- addr )
592 Returns pointer to memory where dynamic block
595 dyns ( handle -- size )
596 Returns size of dynamic block.
598 dynresize ( NewSize handle -- )
599 Nondestructively resize dynamic block.
601 dync@ ( addr handle )
602 Read one byte from dynamic block.
604 dync! ( byte addr dynhandle )
605 Write one byte to dynamic block.
608 Read 32 bit number from dynamic block.
609 Address will spacify, whitch number, not byte.
611 dyn! ( 32BitNum addr dynhandle )
612 Write 32 bit number to dynamic block.
613 Address will spacify, whitch number, not byte.
615 dyncon ( size "name" -- )
616 Allocate dynamic block with specified size, and
617 create constant honding its handle.
618 ex: 100 dyncon MyNewBlock
621 Write contenc of dynamic memory block to screen.
625 . ( n -- ) print number on screen
627 d. ( n -- ) print number on screen in decimal
629 ? ( addr -- ) print 32 bit value located at addr.
631 ." <string>" ( -- ) print string into screen. Immideately
633 ex: : greeting ." Hello, World" ;
635 tab. ( -- ) print tabulator
637 calccol ( b g r -- c ) calculate color what best matches given
638 Blue Green & Red values. Values must be in range 0 - 255.
640 imgalloc ( xsize ysize -- imgbuf ) allocate image buffer for
643 imgsize ( imgbuf -- ) print on the screen X & Y size of image
646 point ( x y imgbuf -- addr ) returns memory address for specified
649 pset ( color x y imgbuf -- ) set graphic point
651 boxf ( x1 x2 y1 y2 imgbuf color -- ) draw filled box
653 cls ( imgbuf -- ) clear image buffer
655 setpal ( b g r color -- ) set palette value for specified color.
656 values bust be in size 0 - 63.
658 putchar ( char color x y imgbuf -- ) put graphic character in
659 imagebuffer to specified (x & y) location.
661 scroll ( x y imgbuf -- ) scroll in imgbuf.
663 scrollf ( color x y screen -- ) scroll and fill empty space with
666 at! ( x y -- ) set cursor location
667 curc! ( color -- ) set text color
668 curb! ( solor -- ) set backround color
670 colnorm ( -- ) set text color to normal
671 colneg ( -- ) set text color to negative (selected)
673 dyntype ( dynhandle -- ) display contenc of dynamic memory on screen
674 fsdisp ( file -- ) clear screen, display file, and wait for key
676 type ( addr length -- )
677 Types on the screen string, from memory at addr and
681 Types on the screen string, from memory at "addr"+1
682 length is taken from "addr" .
685 Holds handle of screen buffer.
687 copyscreen ( SrcImgHandle DestImgHandle -- ) copy contenc of source
688 image to destination image. Source and destination images
691 ** Math, memory & stack manipulation
693 off ( n -- ) writes 0 to given address, good for zeroing variable.
695 on ( n -- ) writes -1 (true flag) to given address.
698 2dup ( n1 n2 -- n1 n2 n1 n2 )
701 neg ( n1 -- -n1 ) negotiate
702 bit@ ( n bit -- result ) return specified bit from n.
703 ex: 38 2 bit@ (result will be 1)
704 to32bit ( n1 n2 n3 n4 -- n32 ) treat 4 last stack elements as bytes
705 and unite them into 32 bit dword. Most significant byte
707 ex: 12 76 23 11 to32bit result: 186076172
709 to8bit ( n32 -- n1 n2 n3 n4 ) break 32 bit number into 4 bytes.
710 Useful if you need to send 32 bit numbers thru 8 bit COM
712 ex: 186076172 to8bit result: 12 76 23 11
714 mod ( n1 n2 -- reminder ) divide n1 by n2 and returns reminder.
715 ex: 12 5 mod result: 2
717 bound ( low n high -- n ) check if n is in given bounds,
718 if not then incarease/decarease it to match bounds.
719 ex: 5 80 15 bound result: 15
720 5 10 15 bound result: 10
721 5 -10 15 bound result: 5
723 bound? ( low n high -- result ) returns true if n is in the
726 tab ( col -- spaces) calculate amount of spaces to add
727 ta reach next tabulation from given column.
729 count ( addr -- addr+1 n )
730 Useful for returning bytes from constantly incareasing
731 address. Module "type" is nice example.
734 store one byte at memory specified by "h". And incarease
738 store 32 bit number at memory specified by "h". And
741 cmove ( addr1 addr2 n -- )
742 copy "n" amount of bytes from memory at "addr1" to memory
745 rnd ( limit -- result )
746 generates random number in range 0 to "limit"-1.
749 returns absolute value of "n"
751 ** Dynamic & static strings
752 Fifth supports both static and dynamic strings. Static strings must
753 have predefined space reserved, and string mustn't exceed this
754 length. They manipulation is faster. But they use more memory. Static
755 string memory address is used to refer to the string.
757 Dynamic strings can have at any time length form 0 to 0FFh, They take
758 up only memory they currently need. They are held in dynamic memory
759 blocks, so dynamic block handle is used to refer to this string.
761 Both types of strings are stored in the way, where first (0th) byte
762 holds current string length, following bytes are string itself.
771 Dstrlen ( handle -- length )
772 Return string length.
774 c+Dstr ( chr handle -- )
775 Add one byte to end of the string.
777 c+lDstr ( chr handle -- )
778 Add one byte to left side (beginning) of the string.
781 Write contec of string into screen.
783 Dstrsure ( size Dstr -- )
784 Makes sure that at least rquested
785 "size" (amount of characters) is allocated for given
788 Dstr2str ( handle address -- )
789 Copy dyamic string into static memory space.
791 str2Dstr ( address handle -- )
792 Copy static string into dyamic string.
794 Dstr+str ( Dstr addr -- )
795 Add contenc of dynamic string to static string.
797 D" any string" ( -- Dstr )
798 Moves specified string into dynamic string called "defDstr".
800 D> any_string ( -- Dstr )
801 Moves specified string into dynamic string called "defDstr".
802 Space marks end of string!
804 D>2 any_string ( -- Dstr )
805 Moves specified string into dynamic string called "defDstr2".
806 Space marks end of string!
808 Dstr+Dstr ( Dstr1 Dstr2 -- )
809 Adds "Dstr1" to "Dstr2" and places result into "Dstr2".
811 Dstrclear ( Dstr -- )
812 Clears contenc of dynamic string.
814 Dstr2Dstr ( Dstr1 Dstr2 -- )
815 Moves "Dstr1" to "Dstr2".
816 Dstr ( data" name -- )
817 Creates new dynamic string and moves specified data into it.
818 Then creates new constant with given "name" holding created
819 dynamic string handle.
821 ex: Dstr Hello, my name is Sven!" message \ creates it
822 message Dstr. \ tests it
824 Dstrlscan ( char Dstr -- loc )
825 Searches dynamic string for "char", from left to right,
826 returns first found "char" location in string, or 0,
829 Dstrrscan ( char Dstr -- loc )
830 Searches dynamic string for "char", from right to left,
831 returns first found "char" location in string, or 0,
834 Dstrlscane ( char Dstr -- loc )
835 Same as "Dstrlscan" buf returns string length+1 as location.
837 Dstrleft ( amo Dstr -- )
838 Only specified amount of characters from left remains
839 in dynamic string. ie. cut right part out.
841 Dstrright ( amo Dstr -- )
842 Only specified amount of characters from right remains
843 in dynamic string. ie. cut left part out.
845 Dstrcutl ( amo Dstr -- )
846 Cut specified amount of characters from left of dynamic
849 Dstrsp ( char Dstr1 Dstr2 -- )
850 Separate dynamic string in Dstr1 into two parts,
851 using "char" as separator. First part will be stored in
852 "Dstr2", second part in "Dstr1".
853 ex: asc \ \ ..separator
854 D> listF\listLIB\5TH_DRVMOUSE \ ..separate from
855 defDstr2 \ ..place result in
856 Dstrsp \ separation command
857 defDstr Dstr. \ will be: listLIB\5TH_DRVMOUSE
858 defDstr2 Dstr. \ will be: listF
861 Allocates empty dynamic string, and places it's handle
865 Reads dynamic string handle from given address and
866 deallocates (frees) it.
870 mystring1 Dv \ allocates string
874 mystring1 Df ; \ deallocates it again when no longer needed.
876 * Dynamically loadable modules
880 KBD_@ ( -- code ) get scancodes for pressed keys from keyboard.
881 KBD_down? ( key -- result ) check is key with specified scancode
882 currently pressed down.
883 KBD_SC2FSCII ( code -- FSCII ) convert key scancode into FSCII code,
884 or in FSK (Fifth standard keycode).
885 KBD_F@ ( -- FSCII ) read pressed key FSCII or FSK, returns -1 if no
887 KBD_FW@ ( -- FSCII ) read pressed key FSCII or FSK, if no keys is
888 are pressed then waits until there is.
914 mousex var Mouse x coordinate.
915 mousey var Mouse y coordinate.
916 mousekeyl var Mouse left key.
917 mousekeym var Mouse middle key.
918 mousekeyr var Mouse right key.
919 mousec var Display current mouse coordinates in top left part of screen,
920 if true. (good for debugging)
921 mousepointer var Image buffer, holding current mouse pointer.
922 mouseadd ( ModuleAddr x1 x2 y1 y2 -- ) Add specified area on screen,
923 into mause click buffer. If any mouse button is clicked on
924 that area, module at "ModuleAddr" will be executed.
925 mousebe var Amount of buffer elements.
926 mousedo ( -- ) Updates mouse coordinates and keys. Parse mouse
927 click buffer, and draw mouse cursor to "screen".
929 ** 2D graphic library
931 + lineh ( color len x y imgbuf -- ) :: draws horisontal line from X,Y
932 coordinates to right, with specified length.
934 + linev ( color len x y imgbuf -- ) :: draws vertical line down, from
935 coordinates X,Y, with specified length.
937 + box ( color x2 x1 y2 y1 imgbuf -- ) :: draws rectangular box. x2
938 bust be >= x1, y2 must be >= y1.
947 + flipv ( imgbuf -- ) :: flip image vertically.
949 + imgcoltrans ( ImgBuf Color ToColor -- ) :: Translate all pixels in
950 specified image with "Color" into "ToColor".
952 + imgfill ( color x y imgbuf -- ) :: Fill image region starting at
953 location X & Y with specified color.
956 ** Trigonometry functions
957 *** sin ( a -- result )
959 :ID: 9a66ca9c-eb5f-45aa-8116-71763081f2fb
961 Return sinus from given angle "a", 360ø is 2000. So 1000 represents
962 180ø angle. Result will be in range -10'000 to 10'000, instead of ñ1.
963 *** cos ( a -- result )
964 Return cosinus from given angle. Parameters are like in [[id:9a66ca9c-eb5f-45aa-8116-71763081f2fb][sin]] function.