1 #+TITLE: Fifth - virtual machine, operating system, programming language
2 * (document settings) :noexport:
3 ** use dark style for TWBS-HTML exporter
4 #+HTML_HEAD: <link href="https://bootswatch.com/3/darkly/bootstrap.min.css" rel="stylesheet">
5 #+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
6 #+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
7 #+HTML_HEAD: <style type="text/css">
8 #+HTML_HEAD: footer {background-color: #111 !important;}
9 #+HTML_HEAD: pre {background-color: #111; color: #ccc;}
13 - This program is free software: you can redistribute it and/or modify
14 it under the terms of the [[https://www.gnu.org/licenses/lgpl.html][GNU Lesser General Public License]] as
15 published by the Free Software Foundation, either version 3 of the
16 License, or (at your option) any later version.
20 - Homepage: http://svjatoslav.eu
21 - Email: mailto://svjatoslav@svjatoslav.eu
23 - [[http://www.svjatoslav.eu/projects/][Other software projects hosted at svjatoslav.eu]]
26 - [[http://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=snapshot;h=HEAD;sf=tgz][Download latest snapshot in TAR GZ format]]
28 - [[http://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=summary][Browse Git repository online]]
30 - Clone Git repository using command:
31 : git clone http://www2.svjatoslav.eu/git/fifth.git
34 Current implementation does not support object oriented
35 programming. While working on Fifth I got lots of cool new ideas that
36 require reimplementation of everything.
38 Currently I try to implement those new ideas in the project called
39 [[http://www3.svjatoslav.eu/projects/sixth/][Sixth]]
41 System is built many years ago when I was still using DOS as a primary
42 operating system and not updated since.
44 Fifth is programming lanquage & operating system, running on [[emulator.html][virtual
45 CPU]], with custom instruction set. It is much like Charles Chunk
46 Moore's Forth, it also uses stack architecture, and many commands are
47 similar. Basically I got familiar with concepts of Forth, and being
48 inspired created my own system.
50 - [[file:5TH_ET.txt][Example Fifth source file - text editor]]
52 - [[file:screenshots/start.png]]
53 - Startup screen diplaying Fifth logo and full file list.
55 - [[file:screenshots/dictionary.png]]
56 - Sample words defined. Most of the words are commands that can be
57 executed interactively from command line or from file. When
58 executed they can be selectively compiled or interpreted.
60 - [[file:screenshots/text editor.png]]
61 - Built in text editor.
64 Just unpack all files, witout altering original directory structure,
65 somewhere in your hard disk. For example:
67 To run fifth you need minimally just 2 files. emulator itself (
68 EMULATOR.EXE or EMULATOR.COM ), and virtual disk file ( DISK.RAW ).
70 Read more about [[files.txt][distribution directory layout]]
71 * Fifth distribution directory tree description
72 After downloading and unpacking the ZIP file you shoud get directory
76 [DOC] - Fifth documentation
77 [commands] - documentation on Fifth built-in commands
78 [modules] - documentation on additional commands, realized as loadable modules
79 [shots] - Fifth screenshots
81 [imageFile] - files contained within 'disk.raw', just an extracted form.
83 [source] - source files
84 [emulator] - emulator source
87 disk.raw - Virtual disk file, has filesystem inside.
88 emulator.com - main executable.
91 * Software/Hardware/Human requirements
93 - MS-DOS 6.22, with HIMEM.SYS loaded.
94 - Mouse driver if you have a mouse.
95 - Does work only when CPU is in real mode.
96 - To recompile ASM sources I used FASM (Flat Assembler).
97 - I ran QBasic utilities on QB 4.5 .
98 - VESA support by BIOS, or external driver (UNIVBE).
101 - 64 KB free RAM below 640KB,
103 - VESA compatible video card.
105 - Beginner level Forth knowledge is recommended.
106 - Lots of enthusiasm.
107 * Numbers representation within Fifth
109 [[file:numbers.png][file:numbers.png]]
111 Because I can define everything, starting from CPU, why not try also
112 alternative and unique number representation ?
114 Fifth uses its hexdecimal number representation as primary. Numbers
115 shape is formed by dividing a square into four parts. And manipulating
116 their color (black or white).
117 * Disk file map, and it's data structures
118 Core and high-level boot code is stored outside of the filesystem to
119 allow easy access to it, at early booting time, when filesystem is not
122 | offset | length | description |
123 |--------+--------+----------------------|
124 | 0 | ~4 Kb | Fifth core |
125 | 4 Kb | ~32Kb | high-level boot code |
126 | 37 Kb | ~65Kb | FAT |
127 | 101Kb | ~16MB | filesystem data area |
130 |------+--------------------------|
132 | -1 | empty sector |
133 | 0 -- | .. pointer to next block |
135 | offset | length | description |
136 |--------+--------+------------------------|
137 | 0 | 4 | extension |
139 | 20 | 4 | entry point |
141 | 28 | 4 | last modification time |
143 Fifth core is simply some amount of already compiled into machine code
144 and linked together modules (entries in other words). In compilation
145 process modules is compiled one by one and simply stored on top of
146 already existing and growing core. Separately from core is kept
147 dictionary, this is special list that contain names of compiled
148 modules, variables etc. and they locations in core. Constants use
149 dictionary space only. Random word can be removed from dictionary at
150 any time. Currently dictionary can contain at most 1000 entries.
151 ** Dictionary entry format
152 | offset | length | description |
153 |--------+--------+-----------------------|
154 | 0 | 4 | 0 < previous entry |
157 |--------+--------+-----------------------|
158 | 4 | 15 | module name string |
159 |--------+--------+-----------------------|
160 | 19 | 1 | entry type |
161 |--------+--------+-----------------------|
162 | 20 | 4 | entry data |
164 Core headers as linked list of module names make up something like
165 dictionary. When some entry address is needed compiler can quickly
166 run through headers backwards and find needed entry.
167 ** Possible module types
168 | type | description | "execute" action |
169 |------+----------------+----------------------------|
170 | 0 | data | compile "num" instruction |
171 | | | with address to module |
172 |------+----------------+----------------------------|
173 | 1 | submodule | compile "call" instruction |
174 | | | with address to module |
175 |------+----------------+----------------------------|
176 | 2 | imm. submodule | immediately call to module |
177 ** Memory map (average)
178 | <loc> | <size> | <desc> |
179 |---------+--------+-----------------------------|
181 | 1500000 | ~32000 | highlevel Fifth boot code |
182 | 200000h | | core startup messages area |
183 | 5200000 | | end of dynamic memory space |
185 Using CPU emulator slows it down but I shouldn't now think too mutch
186 about, and waste my time on batteling with problems whitch results on
187 complex design of PC hardware. Also it allows me to use existing DOS
188 and resident drivers services in real mode. So I don't need to deal
189 with hardware too mutch. It also allows me to use all free XMS for
190 flat code & data storage.
192 Current emulator emulates 1 CPU. It has 2 stacks, ~50 instructions,
193 and 4GB flat address space (theoretically). I'm not sure that DOS
194 6.22 that I currently prefer can handle more than 64 MB of RAM. While
195 I tried to keep instructionset simple, I was forced to put in lot of
196 complex instructions to make it's performance acceptable on
197 emulator. On actual silicon ~20 instructions is enaugh (I think).
199 Maybe one day similar system will run directly on custom silicon chip :)
202 CPU has following registers:
203 | IP | instruction pointer |
204 | DSP | data stack pointer |
205 | RSP | return stack pointer |
207 Virtual CPU, commands (most of them are avaiable as ordinary commands
208 in programming lanquage):
212 code mnemonic description
215 1 halt halt CPU ( return to DOS on emulator )
217 2 kbd@ ( -- c ) read scancode of pressed or released key.
218 Returns 0, if no data avaiable.
219 3 num <dword> ( -- n ) put immidiate number into datastack
221 4 jmp <dword> jump to specified code
222 5 call <dword>jump to specified code, save return address to
228 8 dup ( n -- n n ) duplicate top of data stack
229 9 drop ( n -- ) drop last element in data stack
231 10 if <dword> ( n -- ) jump to addr if top element was 0
232 11 ret jump to code, specified in return stack.
234 12 c@ ( addr -- n ) read byte from memory at specified address
235 13 c! ( n addr -- ) store byte to specified memory
237 14 push ( DSTK -> RSTK ) move top of datastack to returnstack
238 15 pop ( RSTK -> DSTK ) move top of returnstack to datastack
241 17 rot ( n1 n2 n3 -- n2 n3 n1) rotate stack elements
243 18 disk@ ( FromDiskSect ToMem -- ) read 1KB from disk into RAM
244 19 disk! ( FromMem ToDiskSect -- ) write 1KB to disk
246 20 @ ( addr -- n ) read 32 bit number from memory
247 21 ! ( n addr -- ) store 32 bit number to memory
249 22 over ( n1 n2 -- n1 n2 n1 ) self explaining ...
250 23 swap ( n1 n2 -- n2 n1 ) -,,-
252 24 + ( n1 n2 -- n1+n2 ) -,,-
253 25 - ( n1 n2 -- n1-n2 ) -,,-
255 26 * ( n1 n2 -- n1*n2 ) -,,-
256 27 / ( n1 n2 -- n1/n2 ) -,,-
258 28 > ( n1 n2 -- result ) is true when n1 > n2
259 29 < ( n1 n2 -- result ) is true when n1 < n2
261 30 not ( n1 -- not_n1 ) logical not
262 31 i ( -- n ) copies top of return stack into datastack
264 32 cprt@ ( addr -- n ) read one byte from hardware port
265 33 cprt! ( n addr -- ) store one byte to hardware port
267 34 i2 ( -- n ) like "i" but takes socond top stack element.
268 35 i3 ( -- n ) like "i" but takes third top stack element.
270 36 shl ( n amount -- n ) left bit shift
271 37 shr ( n amount -- n ) right bit shift
273 38 or ( n1 n2 -- n ) logical or
274 39 xor ( n1 n2 -- n ) exclusive logical or
276 40 vidmap ( addr -- ) copy memory from "addr" to video memory.
278 41 mouse@ ( -- x y button ) read mouse coordinates & buttons
280 42 vidput ( addr1 addr2 x y -- ) put image1 into image2, at
281 location x, y. Does clipping, so part of a big image
282 can be mapped into smaller one.
284 43 cmove ( addr1 addr2 amount ) move memory from addr1 to addr2
285 if addr1 is greater than addr2 then count address
286 foward while moving, elseway starts from end and
287 counts backwards, so no data loss will occure on
290 44 cfill ( c addr amount -- ) fill memory starting at "addr"
293 45 tvidput ( addr1 addr2 x y -- ) same as "vidput" but treats
294 color 255 in source image as transparent.
296 46 depth ( -- depth ) returns current depth of data stack.
298 47 charput ( colorfg colorbg addrsrc addrdest x y )
299 draw character to image buffer located at "addrdest"
300 to specified x & y location. Decodes 8 bytes from
301 source to bits, used to draw character.
304 * Fifth source format
305 Fifth uses a different character table and codes than ASCII (still
306 almost similar). I call it FSCII (Fifth Standard Code for Information
307 Interchange) for example space character is not 32 but 255 instead. I
308 plan to use mainly HEX numbers, and create new characters to represent
309 numeric values. So typical nemric characters "0123..." is treated
310 like ordinary letters.
313 | DEC | HEX | function |
314 |--------+-------+----------------------------------------|
315 | 0 - 15 | 0 - F | HEX numbers |
316 | 252 | FC | backspace |
317 | 253 | FD | tabulator (TAB) |
318 | 254 | FE | carriage return (CR) |
320 | else | | ordinary characters, same as in ASCII. |
322 ** Compilation & miscellaneous
325 First module, control is passed to on startup. Contains
326 initialization routines. Also it is the last core module.
327 All new modules on top of it comes as result of executing
328 external source files.
330 head <name> ( -- ) compiles new dictionary entry without specifying
334 : <name> ( -- ) creates new code module
335 ; ( -- ) ends module (immideate)
336 ex: : hello ." hi there" ;
338 const <name> ( n -- ) defines new constant.
339 ex: 2147483647 const max
341 :i <name> ( -- ) same as ":" but this module will be executed
342 immideately even in compile mode.
345 create <name> ( -- ) same as "head" , but specify module type as data.
346 ex: create LotoResults 5 , 13 , 52 , 12 , 11 , 3 ,
348 allot ( n -- ) allocate n bytes in dictionary.
349 ex: create MyArray 100 allot
351 " <string>" ( -- ) compile string and its size into core.
352 ex: create Mystring " This is it's contects"
354 str <name> <string>" ( -- ) just shorter way for defining strings.
355 ex: str Mystring This is it's contenc"
357 var <name> ( -- ) define new 32 bit variable.
360 ' <module> ( -- n ) return memory address of given entry.
363 forget <name> ( -- ) erases from RAM given entry and all entries what was
367 [ ( -- ) set interpret mode (immideate)
368 ] ( n -- ) set compile mode and compile top stack element
369 in as literal. Together [ .... ] cobination provides good
370 way to compute some values only once, at compile time,
371 rather than every time while program is running.
372 ex: : calculate - [ 4 MyConst1 + MyConst2 * ] ;
374 defer <name> ( -- ) creates new module, with jump instruction.
375 Later address where to jump can be modified by "is" command.
376 This provides method of foward referencing. So you can use
377 modules what not jet exist.
378 is ( address1 address2 -- ) address1 - where to jump, address2 -
379 address of module created by defer command.
381 : run dispver ." running ..." ;
383 : (dispver ." Version 9.99 " ;
384 ' (dispver ' dispver is
386 Now if I type "run" on the screen appears:
387 Version 9.99 running ...
389 asc <char> ( -- ) reads char ascii code and treats it as literal.
391 ex: : BreakLine 30 do asc - emit loop ;
393 : BreakLine 30 do 45 emit loop ;
395 dyninc ( handle -- ) execute code in dynamic memory handle.
396 automatically deallocates it when done.
398 include ( filenumber -- ) execute code in specified file.
400 words ( -- ) display existing blocks in core.
402 bye ( -- ) exit from Fifth
405 Read one byte from input stream.
408 Add one byte "c" to string located at "addr" and updates
412 Read input stream and store it to pad until it finds c .
413 It ignores all "c" bytes until it finds any non "c" byte.
416 input stream: """"This is test !"aoeu idh
417 result: This is test !
419 Is useful for breaking text lines into words.
422 So called safe "fkey". Reads data from input stream
423 but converts characters with ASCII codes: 9 13 10
426 str=str? ( adr1 adr2 -- result )
427 Compares string at "adr1" with string at "adr2", returns
428 true flag if they are equal or false if they are not.
433 Searches whole dictionary for word in "pad". If found,
434 returns it address, if not, returns 0.
437 Execute word located in "pad". Depending on "mode".
439 dta ( addr -- DataAddr )
440 Calculates address of dictionary entry data area, from
443 2num ( -- num result )
444 Attempt to convert string located in "pad" into numeric
445 value. If succeed returns number and true as result.
446 If not, returns whatever and false as result.
448 dadd ( addr length -- )
449 Add to dictionary data located at "addr", with specified
453 Act with number depending on "mode". When interpreting,
458 Add to dictionary data located at "addr"+1 , length is taken
465 Holds input stream parser operation mode.
470 Holds temprorary strings.
473 Pointer to free byte in memory, always at the end of the
474 dictionary. Each time when something is stored
475 by "c," command, pointer is incareased.
478 Pointer to last dictionary word. Each time when new word is
479 compiled or erased by "forget", this pointer is updated.
481 modulechk ( Dstr<filename> -- ) check if module is loaded, if not
484 ne ( entrydata entrytype -- ) Compile new dictionary entry.
485 It's name must be in "pad".
487 ** Conditionals & control flow
489 if ( flag -- ) (immideate)
490 "if 1.. else 2.. then" or
491 "if 1.. then" construction. Conditional execution.
492 Performs "1.." if "flag" was true,
493 elseway performs "2.." if exist. Execution continues after
495 ex: 1 if ." nonzero" else ." zero" then
497 >= ( n1 n2 -- result ) true if (n1 = n2) or (n1 > n2)
498 ex: 5 3 >= if ." first number is greater or equal" then
500 <= ( n1 n2 -- result ) true if (n1 = n2) or (n1 < n2)
501 = ( n1 n2 -- result ) true if n1 = n2
503 do ( count -- ) (immideate)
504 "do .. loop" construction. Performs ".." "count" times.
505 In every step "count" is decareased until it is 0.
506 ex: : test 5 do i .d loop ;
509 doexit ( -- ) exit from "do .. loop"
511 for ( count top -- ) (immideate)
512 "for .. loop" construction. Performs ".." (top - count) times.
513 In every step "count" is incareased until it reaches "top" .
514 ex: : test 4 10 for i .d loop ;
517 forexit ( -- ) exit from "for .. loop"
519 until ( -- ) (immideate)
520 "until .. loop" construction. Performs ".." until flag become
521 true. False by default. Top of return stack holds flag.
523 done ( -- ) exit from "until .. loop"
526 ** Disk & file access
528 diskload ( FromDisk ToMem amount -- )
529 Load specified abount of bytes from disk into memory.
531 disksave ( FromMem ToDisk amount -- )
532 save specified abount of bytes from memory into disk.
534 format ( -- ) Erase all files.
536 fsDfilesize@ ( handle -- size )
537 Return size of opened file.
539 fsDcurloc@ ( handle -- location )
540 Return current location in file.
542 fsDupdated@ ( handle -- updated? )
543 Return true if file was updated,
544 ie. write operations occured.
546 fssave ( FromMem DestFileHandle amount -- )
549 fsload ( SrcFileHandle ToMem amount -- )
552 fseof ( handle -- bytesLeft )
553 Return amount of bytes left till end of file.
554 Useful before read operation.
556 fsls ( -- ) List all files and lists (directories,folders)
559 fslsr ( -- ) Same as "fsls" but recursively scans also sub lists.
561 fscl ( DynStrHand -- )
564 fscreate ( DynStrHand -- DescPnt )
565 Create new file or list. Can create multiple lists at once.
567 "\listGAMES\listSTRATEGY\listSIMWORLD\5th-runme"
568 and only "\listGAMES\" already exist, then
569 "listSTRATEGY" and "listSIMWORLD" lists will be created,
570 and empty file "5th-runme" placed in there.
572 fsDsave ( DynHand<data> DynStrHand<filename> -- )
573 Create new file and save all data from dynamic memory
576 fsDload ( DynStr<SrcFileName> DynHand<DataDest> -- )
577 Load whole file into dynamic memory block.
579 fsDloadnew ( DynStr<SrcFileName> -- DynHand<DataDest> )
580 Load whole file into new dynamic memory block.
584 dynal ( size -- handle )
585 Allocate dynamic memory block and return it's handle.
588 Deallocate dynamic memory block.
590 dynp ( handle -- addr )
591 Returns pointer to memory where dynamic block
594 dyns ( handle -- size )
595 Returns size of dynamic block.
597 dynresize ( NewSize handle -- )
598 Nondestructively resize dynamic block.
600 dync@ ( addr handle )
601 Read one byte from dynamic block.
603 dync! ( byte addr dynhandle )
604 Write one byte to dynamic block.
607 Read 32 bit number from dynamic block.
608 Address will spacify, whitch number, not byte.
610 dyn! ( 32BitNum addr dynhandle )
611 Write 32 bit number to dynamic block.
612 Address will spacify, whitch number, not byte.
614 dyncon ( size "name" -- )
615 Allocate dynamic block with specified size, and
616 create constant honding its handle.
617 ex: 100 dyncon MyNewBlock
620 Write contenc of dynamic memory block to screen.
624 . ( n -- ) print number on screen
626 d. ( n -- ) print number on screen in decimal
628 ? ( addr -- ) print 32 bit value located at addr.
630 ." <string>" ( -- ) print string into screen. Immideately
632 ex: : greeting ." Hello, World" ;
634 tab. ( -- ) print tabulator
636 calccol ( b g r -- c ) calculate color what best matches given
637 Blue Green & Red values. Values must be in range 0 - 255.
639 imgalloc ( xsize ysize -- imgbuf ) allocate image buffer for
642 imgsize ( imgbuf -- ) print on the screen X & Y size of image
645 point ( x y imgbuf -- addr ) returns memory address for specified
648 pset ( color x y imgbuf -- ) set graphic point
650 boxf ( x1 x2 y1 y2 imgbuf color -- ) draw filled box
652 cls ( imgbuf -- ) clear image buffer
654 setpal ( b g r color -- ) set palette value for specified color.
655 values bust be in size 0 - 63.
657 putchar ( char color x y imgbuf -- ) put graphic character in
658 imagebuffer to specified (x & y) location.
660 scroll ( x y imgbuf -- ) scroll in imgbuf.
662 scrollf ( color x y screen -- ) scroll and fill empty space with
665 at! ( x y -- ) set cursor location
666 curc! ( color -- ) set text color
667 curb! ( solor -- ) set backround color
669 colnorm ( -- ) set text color to normal
670 colneg ( -- ) set text color to negative (selected)
672 dyntype ( dynhandle -- ) display contenc of dynamic memory on screen
673 fsdisp ( file -- ) clear screen, display file, and wait for key
675 type ( addr length -- )
676 Types on the screen string, from memory at addr and
680 Types on the screen string, from memory at "addr"+1
681 length is taken from "addr" .
684 Holds handle of screen buffer.
686 copyscreen ( SrcImgHandle DestImgHandle -- ) copy contenc of source
687 image to destination image. Source and destination images
690 ** Math, memory & stack manipulation
692 off ( n -- ) writes 0 to given address, good for zeroing variable.
694 on ( n -- ) writes -1 (true flag) to given address.
697 2dup ( n1 n2 -- n1 n2 n1 n2 )
700 neg ( n1 -- -n1 ) negotiate
701 bit@ ( n bit -- result ) return specified bit from n.
702 ex: 38 2 bit@ (result will be 1)
703 to32bit ( n1 n2 n3 n4 -- n32 ) treat 4 last stack elements as bytes
704 and unite them into 32 bit dword. Most significant byte
706 ex: 12 76 23 11 to32bit result: 186076172
708 to8bit ( n32 -- n1 n2 n3 n4 ) break 32 bit number into 4 bytes.
709 Useful if you need to send 32 bit numbers thru 8 bit COM
711 ex: 186076172 to8bit result: 12 76 23 11
713 mod ( n1 n2 -- reminder ) divide n1 by n2 and returns reminder.
714 ex: 12 5 mod result: 2
716 bound ( low n high -- n ) check if n is in given bounds,
717 if not then incarease/decarease it to match bounds.
718 ex: 5 80 15 bound result: 15
719 5 10 15 bound result: 10
720 5 -10 15 bound result: 5
722 bound? ( low n high -- result ) returns true if n is in the
725 tab ( col -- spaces) calculate amount of spaces to add
726 ta reach next tabulation from given column.
728 count ( addr -- addr+1 n )
729 Useful for returning bytes from constantly incareasing
730 address. Module "type" is nice example.
733 store one byte at memory specified by "h". And incarease
737 store 32 bit number at memory specified by "h". And
740 cmove ( addr1 addr2 n -- )
741 copy "n" amount of bytes from memory at "addr1" to memory
744 rnd ( limit -- result )
745 generates random number in range 0 to "limit"-1.
748 returns absolute value of "n"
750 ** Dynamic & static strings
751 Fifth supports both static and dynamic strings. Static strings must
752 have predefined space reserved, and string mustn't exceed this
753 length. They manipulation is faster. But they use more memory. Static
754 string memory address is used to refer to the string.
756 Dynamic strings can have at any time length form 0 to 0FFh, They take
757 up only memory they currently need. They are held in dynamic memory
758 blocks, so dynamic block handle is used to refer to this string.
760 Both types of strings are stored in the way, where first (0th) byte
761 holds current string length, following bytes are string itself.
770 Dstrlen ( handle -- length )
771 Return string length.
773 c+Dstr ( chr handle -- )
774 Add one byte to end of the string.
776 c+lDstr ( chr handle -- )
777 Add one byte to left side (beginning) of the string.
780 Write contec of string into screen.
782 Dstrsure ( size Dstr -- )
783 Makes sure that at least rquested
784 "size" (amount of characters) is allocated for given
787 Dstr2str ( handle address -- )
788 Copy dyamic string into static memory space.
790 str2Dstr ( address handle -- )
791 Copy static string into dyamic string.
793 Dstr+str ( Dstr addr -- )
794 Add contenc of dynamic string to static string.
796 D" any string" ( -- Dstr )
797 Moves specified string into dynamic string called "defDstr".
799 D> any_string ( -- Dstr )
800 Moves specified string into dynamic string called "defDstr".
801 Space marks end of string!
803 D>2 any_string ( -- Dstr )
804 Moves specified string into dynamic string called "defDstr2".
805 Space marks end of string!
807 Dstr+Dstr ( Dstr1 Dstr2 -- )
808 Adds "Dstr1" to "Dstr2" and places result into "Dstr2".
810 Dstrclear ( Dstr -- )
811 Clears contenc of dynamic string.
813 Dstr2Dstr ( Dstr1 Dstr2 -- )
814 Moves "Dstr1" to "Dstr2".
815 Dstr ( data" name -- )
816 Creates new dynamic string and moves specified data into it.
817 Then creates new constant with given "name" holding created
818 dynamic string handle.
820 ex: Dstr Hello, my name is Sven!" message \ creates it
821 message Dstr. \ tests it
823 Dstrlscan ( char Dstr -- loc )
824 Searches dynamic string for "char", from left to right,
825 returns first found "char" location in string, or 0,
828 Dstrrscan ( char Dstr -- loc )
829 Searches dynamic string for "char", from right to left,
830 returns first found "char" location in string, or 0,
833 Dstrlscane ( char Dstr -- loc )
834 Same as "Dstrlscan" buf returns string length+1 as location.
836 Dstrleft ( amo Dstr -- )
837 Only specified amount of characters from left remains
838 in dynamic string. ie. cut right part out.
840 Dstrright ( amo Dstr -- )
841 Only specified amount of characters from right remains
842 in dynamic string. ie. cut left part out.
844 Dstrcutl ( amo Dstr -- )
845 Cut specified amount of characters from left of dynamic
848 Dstrsp ( char Dstr1 Dstr2 -- )
849 Separate dynamic string in Dstr1 into two parts,
850 using "char" as separator. First part will be stored in
851 "Dstr2", second part in "Dstr1".
852 ex: asc \ \ ..separator
853 D> listF\listLIB\5TH_DRVMOUSE \ ..separate from
854 defDstr2 \ ..place result in
855 Dstrsp \ separation command
856 defDstr Dstr. \ will be: listLIB\5TH_DRVMOUSE
857 defDstr2 Dstr. \ will be: listF
860 Allocates empty dynamic string, and places it's handle
864 Reads dynamic string handle from given address and
865 deallocates (frees) it.
869 mystring1 Dv \ allocates string
873 mystring1 Df ; \ deallocates it again when no longer needed.
875 * Dynamically loadable modules
879 KBD_@ ( -- code ) get scancodes for pressed keys from keyboard.
880 KBD_down? ( key -- result ) check is key with specified scancode
881 currently pressed down.
882 KBD_SC2FSCII ( code -- FSCII ) convert key scancode into FSCII code,
883 or in FSK (Fifth standard keycode).
884 KBD_F@ ( -- FSCII ) read pressed key FSCII or FSK, returns -1 if no
886 KBD_FW@ ( -- FSCII ) read pressed key FSCII or FSK, if no keys is
887 are pressed then waits until there is.
913 mousex var Mouse x coordinate.
914 mousey var Mouse y coordinate.
915 mousekeyl var Mouse left key.
916 mousekeym var Mouse middle key.
917 mousekeyr var Mouse right key.
918 mousec var Display current mouse coordinates in top left part of screen,
919 if true. (good for debugging)
920 mousepointer var Image buffer, holding current mouse pointer.
921 mouseadd ( ModuleAddr x1 x2 y1 y2 -- ) Add specified area on screen,
922 into mause click buffer. If any mouse button is clicked on
923 that area, module at "ModuleAddr" will be executed.
924 mousebe var Amount of buffer elements.
925 mousedo ( -- ) Updates mouse coordinates and keys. Parse mouse
926 click buffer, and draw mouse cursor to "screen".
928 ** 2D graphic library
930 lineh ( color len x y imgbuf -- ) draws horisontal line
931 from X,Y coordinates to right, with specified length.
932 linev ( color len x y imgbuf -- ) draws vertical line
933 down, from coordinates X,Y, with specified length.
934 box ( color x2 x1 y2 y1 imgbuf -- ) draws rectangular
935 box. x2 bust be >= x1, y2 must be >= y1.
941 flipv ( imgbuf -- ) flip image vertically.
942 imgcoltrans ( ImgBuf Color ToColor -- ) Translate all pixels in
943 specified image with "Color" into "ToColor".
944 imgfill ( color x y imgbuf -- ) Fill image region starting at location
945 X & Y with specified color.
947 ** Trigonometry functions
949 sin ( a -- result ) return sinus from given angle "a",
950 360ø is 2000. So 1000 represents 180ø angle.
951 Result will be in range -10'000 to 10'000, instead of ñ1.
953 cos ( a -- result ) return cosinus from given angle.
954 Parameters are like in "sin" function.