Enterprise Forever

:UK => Programming => Topic started by: BruceTanner on 2013.February.25. 12:00:41

Title: FORTH
Post by: BruceTanner on 2013.February.25. 12:00:41
Following on from the brief discussion of the speed of FORTH vs zzzip here (http://enterpriseforever.com/hall-of-fame/en-vagyok-a-hibas-im-to-blame/150/), I have continued here in a new topic.

I have written a version of the zzzip speed test in FORTH. It does exactly the same thing - gets a screen memory pointer from EXOS and fills the screen with As, then Bs, ... Z. I have attached a file saved using EPFILEIO in case anyone wants to load it into IS-FORTH themselves. Or you can just type it in from the listing below. It is only the screen test part of the BASIC test.

To load it, save the attachment to your PC and in IS-FORTH type LOAD-BUFFERS. You should then be able to choose the file.

To type it in, in IS-FORTH type 1 EDIT and then type it in and press ESC when finished. To save it using EPFILEIO type SAVE-BUFFERS.

You don't need the comments between ( and ), but if you do have them you will want to use 80 column mode. To do this type 80 -TEXT before you type 1 EDIT. You will have to return to 40 column mode before you run it (with 40 -TEXT) because the video memory map is different in 80 column mode.

Either way once you have it in memory you then have to "compile" it with 1 LOAD. Then to run it type TEST4.

There is an odd problem that I have not bothered to get to the bottom of: it fills the first row of the screen and then starts on another row further down the screen, filling in the "gap" last. 

DECIMAL


: GET_SCREEN_MEM ( -- addr )
  0 0 3 102 SPFUNC          ( Special func Get Video Memory on chan 102 )
  0 <> ABORT" SPFUNC ERROR" ( EXOS error )
  SWAP DROP                 ( Do not need value returned in C )
;


VARIABLE INK


: TEST4
  102 #GRAPHICS             ( So PALETTE uses text chan )
  GREEN INK !
  GET_SCREEN_MEM            ( Screen ptr on stack throughout )
  91 65 DO                  ( Letters A to Z )
    DUP
    960 0 DO                ( One screenful )
      DUP J SWAP 255 S!     ( SPOKE letter { J }, assume seg is FF !  )
      1+                    ( Next screen pos )
    LOOP
    DROP
    25 INK +!               ( Next colour )
    0 0 0 0 0 0             ( Ready for PALETTE - unused colours )
    INK @ 0 PALETTE         ( Set new ink & background )
  LOOP
  DROP
;
Title: Re: FORTH
Post by: Zozosoft on 2013.February.25. 12:29:03
For the comparision, there is the original BASIC code:
  410 CODE FINDMEM=HEX$("7d,6,3,f7,b,21,0,80,eb,b7,ed,52,c9")

 2040 LET SCREEN_MEM=REM(USR(FINDMEM,102),16384)
 2045 LET INK_COLOUR=GREEN
 2050 FOR CHAR=65 TO 90
 2060   FOR POSITION=0 TO 959
 2070     SPOKE 255,SCREEN_MEM+POSITION,CHAR
 2080   NEXT
 2082   LET INK_COLOUR=(INK_COLOUR+25) BAND 255
 2084   SET #102:PALETTE 0,INK_COLOUR
 2090 NEXT

It is running for about 6 minutes. The FORTH version is only about 10 seconds! Good demonstrate the speed difference between the two language! Impressive!
(And the FORTH have support for the EXOS Special Function call, no machine code needed for ask the video address.)
Title: Re: FORTH
Post by: BruceTanner on 2013.February.25. 12:47:23
Quote from: Zozosoft
For the comparision, there is the original BASIC code:
  410 CODE FINDMEM=HEX$("7d,6,3,f7,b,21,0,80,eb,b7,ed,52,c9")

 2040 LET SCREEN_MEM=REM(USR(FINDMEM,102),16384)
 2045 LET INK_COLOUR=GREEN
 2050 FOR CHAR=65 TO 90
 2060   FOR POSITION=0 TO 959
 2070     SPOKE 255,SCREEN_MEM+POSITION,CHAR
 2080   NEXT
 2082   LET INK_COLOUR=(INK_COLOUR+25) BAND 255
 2084   SET #102:PALETTE 0,INK_COLOUR
 2090 NEXT

It is running for about 6 minutes. The FORTH version is only about 10 seconds! Good demonstrate the speed difference between the two language! Impressive!
(And the FORTH have support for the EXOS Special Function call, no machine code needed for ask the video address.)
:smt023

Just to demonstrate how rusty my memory is, I spent a long time finding out how to get the machine code part running using IS-FORTH's built-in assembler, only to then discover the built-in support for the EXOS Special Function Call! :roll:
Title: Re: FORTH
Post by: BruceTanner on 2013.February.25. 13:40:57
At it's peak in the '80s, the FORTH bible was a book called Starting Forth by Leo Brodie. Ignore the cartoons - it's a serious book!

Here is online:

http://www.forth.com/starting-forth/index.html (http://www.forth.com/starting-forth/index.html)


:smt001
Title: Re: FORTH
Post by: Zozosoft on 2013.February.25. 16:40:14
Quote from: BruceTanner
http://www.forth.com/starting-forth/index.html (http://www.forth.com/starting-forth/index.html)
It looks great for beginners! (I also like the cartoons :-) )
Title: Re: FORTH
Post by: Zozosoft on 2013.February.25. 20:06:06
I found something that I do not understand :oops:
[attach=1]
Title: Re: FORTH
Post by: BruceTanner on 2013.February.25. 20:37:34
Quote from: Zozosoft
I found something what I not understood :oops:
(Attachment)
If you put BINARY before : ABC ... it will work as expected.

BINARY
: ABC BINARY 11111111 DECIMAL . ;
DECIMAL

As you have it, 11111111 is being read as a big decimal number and then the bottom 16 bits are printed out as a signed decimal number.

It does not work as you expected because as ABC is compiled, FORTH is compiling a call to BINARY to happen at run time, not calling BINARY there and then (you could make it do that, but that discussion is probably best left for another day!)

FORTH can be quite confusing with execution time and compile time until you can get your brain around it! ":" is just an ordinary FORTH word that is executing, but as it is executing it is compiling another word...! It is worth persevering though because once you "get it" you will see a lot of power comes very simply, which is really the essence of FORTH and applications written in FORTH.
Title: Re: FORTH
Post by: Zozosoft on 2013.February.25. 20:51:38
Thanks! Now working what I wanted!
I wanted to compare "WYSWYG" character definition, there is the BASIC version:
Code: [Select]
  10 PROGRAM "cdef.bas"
   20 NUMERIC C(9)
   30 RESTORE 1000
   40 FOR I=1 TO 9
   50   READ A
   60   LET C(I)=BIN(A)
   70 NEXT
   80 SET CHARACTER 32,C(1),C(2),C(3),C(4),C(5),C(6),C(7),C(8),C(9)
 1000 DATA 10000001
 1010 DATA 01000010
 1020 DATA 00100100
 1030 DATA 00011000
 1040 DATA 00011000
 1050 DATA 00100100
 1060 DATA 01000010
 1070 DATA 10000001
 1080 DATA 11111111
And the FORTH:
[attach=1]
Title: Re: FORTH
Post by: BruceTanner on 2013.February.25. 21:10:52
:smt023 You have hit upon an example which is far simpler in FORTH than BASIC!

At the risk of confusing it, in your ABC example you could write it:

: ABC [ BINARY ] 11111111 [ DECIMAL ] . ;

which would then print 255. The [ DECIMAL ] part is only so we don't end up in binary at the command line.

[ turns compiling off so that BINARY is executed there and then rather than being compiled, and ] turns compiling on again! (If you are paying attention you might be wondering why [ and ] themselves are not compiled...the answer is that they are marked as "immediate" words, ie. they are executed even when in compiling mode. Any word can be marked as IMMEDIATE, and when they are executed in this way they can themselves compile something.)
Title: Re: FORTH
Post by: Zozosoft on 2013.February.25. 21:43:08
:ds_icon_cheesygrin:[attach=1]
Title: Re: FORTH
Post by: Zozosoft on 2013.February.25. 22:06:38
Quote from: BruceTanner
 The [ DECIMAL ] part is only so we don't end up in binary at the command line.
But funny if it is happened :-D
[attach=1]
Title: Re: FORTH
Post by: BruceTanner on 2013.February.25. 22:25:58
Quote from: Zozosoft
But funny if it is happened :-D
(Attachment)
All DECIMAL, BINARY etc do is store 10, 2 etc in a variable called BASE. So even more confusing:

36 BASE !

Thankfully you can still get back to DECIMAL as words are looked up before attempting to read as a number. I have heard of programs that store pairs of letters that way!
Title: Re: FORTH
Post by: Zozosoft on 2013.February.26. 12:47:14
The manual talking separately about the IS-FORTH and then the Enterprise specific FORTH things.
The IS-FORTH is released for other systems? Or it is planned for later but not happened because the collapse? The Videoton not interested about the FORTH?
Title: Re: FORTH
Post by: BruceTanner on 2013.February.26. 13:07:44
Quote from: Zozosoft
The manual talking separately about the IS-FORTH and then the Enterprise specific FORTH things.
The IS-FORTH is released for other systems? Or it is planned for later but not happened because the collapse? The Videoton not interested about the FORTH?
I don't think it was ever planned for release on other systems, but it was written first on another system and then the Enterprise bits added. There was a new standard at the time, FORTH-83, which IS-FORTH was written to, and then the Enterprise extensions added - I think that might be why the manual is written the way it is. I never heard about Videoton being interested in FORTH but, as a mere meek and mild programmer,  I was not involved in any discussions with them myself!
Title: Re: FORTH
Post by: Zozosoft on 2013.February.26. 15:10:57
How can Load/Save programs?
The description of the "NAME" not fully clear for me :oops:
Can you write some examples? (for Tape and Disk)
Title: Re: FORTH
Post by: BruceTanner on 2013.February.26. 15:54:21
Quote from: Zozosoft
How can Load/Save programs?
The description of the "NAME" not fully clear for me :oops:
Can you write some examples? (for Tape and Disk)
I was reading the IS-FORTH manual on this and it is very confused!

For historical reasons FORTH does not handle "files" as we know them very well! When it was created on the simple systems of the 1970s, you entered your code in 1k blocks (or screens) of 16 lines x 64 characters (= 1k). So you could go "100 EDIT" or "203 EDIT" etc and the entire block would be displayed on the screen. After editing, you would then go "100 LOAD" and your code would be read in as though you had typed it at the command line. If your code spanned more than one block you put "-->" at the bottom and it would load the next screen, etc. Or you could have a master index block which loaded lots of others. There would be a number of 1k buffers in memory just to prevent excessive (slow) disk access. In typical FORTH style this was very simple and efficient as the 1k FORTH blocks could correspond directly to a group of sectors on the disk!

When it came to using the EXOS editor it was a bit tricky to display the entire block in this way, so you can type any number of lines of any length but each block must still be less than 1k (I think the editor status line displays the number of characters left when you get close).

So when I came to do something with cassette tapes it was a bit tricky! So I decided to have enough buffers to keep all the user's source code in memory at once in the "disk" buffers. Then you type

" filename" NAME    to name your program (the space after the first " is important but not included in the name), and
SAVE-BUFFERS      to save all the buffers as a file, and
LOAD-BUFFERS      to load them again. (I'm not sure off the top of my head if loading them on a freshly-booted system sets the NAME...will have to try it).

Once you have loaded a new set you will still have to LOAD them with 203 LOAD or whatever.

This is what I was using the other day with EPFILEIO and it seemed to work ok. If you don't do the " filename" NAME it prompts you with a Windows window. :)

IS-FORTH is supposed to handle disks too, making up filenames out of the block numbers (and possibly the NAME, & can't remember!) I had a very quick go the other day and nothing seemed to happen, but there was some confusion about where EPFILEIO was putting files (as it turned out, a hidden directory called C:\Users\Bruce\Appdata\Local\VirtualStore\Program Files (x86)\ep128emu\files) so I need to give that another go!

In summary I'd suggest you use EPFILEIO at the moment and I'll try and work out how to make it use disks properly later.
Title: Re: FORTH
Post by: BruceTanner on 2013.February.26. 16:10:45
Having had a quick play I think it will always use the NAME, and if you go eg " A:\TEST" NAME and then SAVE-BUFFERS (or FLUSH) will write out all the buffers in a file on drive A:, so you don't need to reply on EPFILEIO.

I'm not sure where the bit about making up filenames came from...will have to play a bit more. Or maybe that was a scheme I abandoned but got left in the manual!
Title: Re: FORTH
Post by: Zozosoft on 2013.February.26. 16:25:34
Quote from: BruceTanner
" filename" NAME
This is more simple than the manual say on the page 47 :-)
Title: Re: FORTH
Post by: Zozosoft on 2013.February.26. 16:43:29
I played at Tape config then can see in the status line what currently saving.
Without NAME specification then saving null filename. With NAME then the specified filename.
After the BUFFERS OFF then numbered .4TH files saved.
For example 1,2,10 buffers used then 10.4TH, 2.4TH, 1.4TH, NAME not used.
Title: Re: FORTH
Post by: BruceTanner on 2013.February.26. 17:01:45
Quote from: Zozosoft
I played at Tape config then can see in the status line what currently saving.
Without NAME specification then saving null filename. With NAME then the specified filename.
After the BUFFERS OFF then numbered .4TH files saved.
For example 1,2,10 buffers used then 10.4TH, 2.4TH, 1.4TH, NAME not used.
:smt023 I don't know how you found that! I was wondering how it would know which system to use. :smt017
Title: Re: FORTH
Post by: BruceTanner on 2013.February.26. 17:10:53
As well as the book I mentioned before called Starting Forth, there is another good (but more advanced) book by the same author called Thinking Forth. Downloadable as a .pdf from a link on this page http://www.forth.com/forth/forth-books.html (http://www.forth.com/forth/forth-books.html) (near the bottom right hand corner). Good discussion from p136 onwards about managing the blocks in a largish application!
Title: Re: FORTH
Post by: Zozosoft on 2013.February.27. 09:31:28
Now I played in EXDOS mode:
Without NAME null filename used. For loading this is translated by the EXDOS to filename "START", if a FORTH program saved with this name then the LOAD-BUFFERS (pressing F1 key) can load it.

Important default: BUFFERS OFF
At this mode, the SAVE-BUFFERS not use the the NAME! Saving separate numbered .4TH files.
At the LOAD or EDIT command if not in the memory the speccified block the try load from the disk, if not exist then create new empty block.
For example 10 LOAD automaticaly load and compile the 10.4TH file.
If switched BUFFERS ON then SAVE-BUFFERS use NAME and save all blocks to one file.

The "all blocks" and the "numbered" files are different format.
The "numbered" are simple 1024 bytes text files, the "all blocks" is a EXOS module, started 16 bytes header with 01h type byte, after all blocks saved: first 16 bit block number, then the 1024 ASCII characters.

One trick how to easy transfer examples from the net to IS-FORTH: Copy+Paste to text file, then save as 1.4TH
Then 1 LOAD. *** End of file error displayed (because it is shorter than 1024 bytes), but don't care with them, the text is in the buffer, can be edited, or with the next 1 LOAD compile it.
Title: Re: FORTH
Post by: BruceTanner on 2013.February.27. 09:53:29
:smt023 Good work zozo, you've got that cracked!

I think the intention was that if you have disks, you use BUFFERS OFF mode. If you only have tape you use BUFFERS ON mode and NAME. Shame it did not say that in the manual :oops:!
Title: Re: FORTH
Post by: Zozosoft on 2013.February.27. 09:59:27
The FORTH detects the EXDOS at the start and switched the BUFFERS OFF (and left ON if there is no EXDOS).
Title: Re: FORTH
Post by: BruceTanner on 2013.February.27. 10:27:16
Quote from: Zozosoft
The FORTH detect the EXDOS at the start and switch the BUFFERS OFF (and left ON if no EXDOS).
But not with ep128emu! :ds_icon_frown:
Title: Re: FORTH
Post by: Zozosoft on 2013.February.27. 10:28:33
I think right the BUFFERS OFF mode are the native FORTH mode, the other is developed only for the Enterprise without disks?
The original FORTH systems have less memory but disks as fast storage. The Enterprise has a lot of memory, then possible simulate the fast storage without disk, this is the BUFFERS ON mode?

In BUFFERS OFF mode with disks also can be used the lot of memory for caching the blocks avoid the disk access?
And for example if written a 80K program then it can be run fully in memory in EP128? But also run on EP64 with EXDOS, just sometimes disk access needed for changing the block in the memory?
Title: Re: FORTH
Post by: BruceTanner on 2013.February.27. 10:30:21
Quote from: Zozosoft
Now I played in EXDOS mode:
Without NAME null filename used. For loading this is translated by the EXDOS to filename "START", if a FORTH program saved with this name then the LOAD-BUFFERS (pressing F1 key) can load it.

Important default: BUFFERS OFF
At this mode, the SAVE-BUFFERS not use the the NAME! Saving separate numbered .4TH files.
At the LOAD or EDIT command if not in the memory the speccified block the try load from the disk, if not exist then create new empty block.
For example 10 LOAD automaticaly load and compile the 10.4TH file.
If switched BUFFERS ON then SAVE-BUFFERS use NAME and save all blocks to one file.

The "all blocks" and the "numbered" files are different format.
The "numbered" are simple 1024 bytes text files, the "all blocks" is a EXOS module, started 16 bytes header with 01h type byte, after all blocks saved: first 16 bit block number, then the 1024 ASCII characters.

One trick how to easy transfer examples from the net to IS-FORTH: Copy+Paste to text file, then save as 1.4TH
Then 1 LOAD. *** End of file error displayed (because it is shorter than 1024 bytes), but don't care with them, the text is in the buffer, can be edited, or with the next 1 LOAD compile it.
It is worth adding to this that if you EDIT in disk mode, the changes may not be written to the disk file until you FLUSH, which writes all modified blocks to disk.
Title: Re: FORTH
Post by: Zozosoft on 2013.February.27. 11:27:59
Quote from: BruceTanner
But not with ep128emu! :ds_icon_frown:
Only with FileIO config. (Becuse it is not a random access file handler, just Load/Save as the tape. Then not set the "Default device is file handler" flag to the EXOS.)
Title: Re: FORTH
Post by: BruceTanner on 2013.February.27. 12:17:54
Quote from: Zozosoft
I think right the BUFFERS OFF mode are the native FORTH mode, the other is developed only for the Enterprise without disks?
The original FORTH systems have less memory but disks as fast storage. The Enterprise has a lot of memory, then possible simulate the fast storage without disk, this is the BUFFERS ON mode?

In BUFFERS OFF mode with disks also can be used the lot of memory for caching the blocks avoid the disk access?
And for example if written a 80K program then it can be run fully in memory in EP128? But also run on EP64 with EXDOS, just sometimes disk access needed for changing the block in the memory?
Yes, exactly right!
Title: Re: FORTH
Post by: Zozosoft on 2013.March.02. 12:55:57
How is possible character <-> character code conversion in FORTH?
Example in BASIC: CHR$(65) or ORD("A")
(For only printing the EMIT do the code->chr conversion.)
Title: Re: FORTH
Post by: BruceTanner on 2013.March.02. 21:58:39
Quote from: Zozosoft
How is possible character <-> character code conversion in FORTH?
Example in BASIC: CHR$(65) or ORD("A")
(For only printing the EMIT do the code->chr conversion.)
For converting from a character to a number, ASCII is what you want - it reads the very next character and leaves its ASCII value on the stack. Thus:

ASCII A . 65 ok

For going the other way, look at Starting Forth, Chapter 7 "A Number of Kinds of Numbers", about half way through, for <# # #s #> etc - basically EMIT into a buffer.

Is that what you meant?
Title: Re: FORTH
Post by: lgb on 2013.March.04. 11:34:00
How can I "print" (well, dump) the (output of) vlist into a file (eg using FILEIO with ep128emu), so I can examine it later outside of IS-FORTH too?

Btw, did you know, that an about Sinclair ZX81 class of machine - the Jupiter ACE, released in 1982 - used forth as the "default language" (unlike most of other 8 bit computers using BASIC)?
Title: Re: FORTH
Post by: BruceTanner on 2013.March.04. 12:22:18
Quote from: lgb
How can I "print" (well, dump) the (output of) vlist into a file (eg using FILEIO with ep128emu), so I can examine it later outside of IS-FORTH too?

Btw, did you know, that an about Sinclair ZX81 class of machine - the Jupiter ACE, released in 1982 - used forth as the "default language" (unlike most of other 8 bit computers using BASIC)?
Probably the easiest way is with EXOS channels:

" A:\VLIST" 10 OPENOUT   10 #EDITOR   VLIST   100 #EDITOR   10 CLOSE

You will have to type this on one line because the editor channel is redirected in the middle.

Bit by bit:

" A:\VLIST" 10 OPENOUTcreates the file on channel 10
10 #EDITORsets the channel used for the editor (ie. VLIST's output) to the file on channel 10
VLISTlists all the words to the editor channel, ie your new file
100 #EDITORsets the editor channel back to the default of 100
10 CLOSEcloses the new channel and your file

I notice in modern FORTHs VLIST has been renamed as WORDS, which is a much cleaner name.

Yes I remember seeing the Jupiter ACE being advertised but I never got to "have a go" on it. There seems to have been a surge in popularity in FORTH in the early 1980s which then declined. :(
Title: Re: FORTH
Post by: BruceTanner on 2013.March.04. 12:31:28
Quote from: BruceTanner
I have written a version of the zzzip speed test in FORTH. It does exactly the same thing - gets a screen memory pointer from EXOS and fills the screen with As, then Bs, ... Z.

...

: GET_SCREEN_MEM ( -- addr )
 0 0 3 102 SPFUNC          ( Special func Get Video Memory on chan 102 )
 0 <> ABORT" SPFUNC ERROR" ( EXOS error )
 SWAP DROP                 ( Do not need value returned in C )
;
Quote
zozosoft

(And the FORTH have support for the EXOS Special Function call, no machine code needed for ask the video address.)

I have just noticed in the IS-FORTH manual there is an even easier way of doing this. VADDR gives you a pointer to the video memory!
Title: Re: FORTH
Post by: Zozosoft on 2013.March.07. 23:00:00
Is recursion possible in Forth?
Title: Re: FORTH
Post by: BruceTanner on 2013.March.07. 23:39:56
Quote from: Zozosoft
Is recursion possible in Forth?
Yes, being stack based anyway it is quite natural. There is a ‘normal‘ infix (not reverse polish) expression evaluater example in the IS-FORTH manual. [When evaluating eg 3*2+(6-4), when ( is encountered you recurse to evaluate the expression between ( and ).]
Title: Re: FORTH
Post by: lgb on 2013.March.08. 09:02:08
forth looks like a very interesting piece of language ... I am using gforth now (on Linux) to understand the basics, however I don't know how to figure out the differences: I guess gforth is a more modern dialect of forth than is-forth (which is pre-forth-83 afaik, eg it uses VLIST, which is words in later forth'es as you've written too some msgs earlier in this thread), so things can be different. Eg: I can use "see" to view the definition of a word. It's really interesting with gforth, either I can see the forth definition or even assembly fragment used to implement that word. Is it possible to use something like "see" in IS-FORTH? It does not seem to understand this word at least. Also, how is it possible to define something in assembly? Hmm, maybe I should read the manual (RTFM) and not asking these? :) And btw, thanks for the "save the output of vlist" help, I did the usual beginner's fault at first: forgetting the space after " :)
Title: Re: FORTH
Post by: BruceTanner on 2013.March.08. 09:44:54
Yes I find FORTH a fascinating language & operating system, completely different from anything else. Very simple yet very powerful and without the bloat and fat that comes with modern OSs.

As far as I know IS-FORTH is forth-83 (it was supposed to be!) but it is possible I missed something. I am not sure about WORDS - I thought that came later but I might be wrong. Of course you can always enter

: WORDS   VLIST ; :)

There is no SEE in IS-FORTH. I have often wondered if it would be possible to "disassemble" a forth word but I didn't realise someone had actually done it! I will think about that one and see if I can come up with anything. Yes it has a built-in assembler but that too is reverse polish eg DE PUSH - RTFM! - but I acknowledge TFM is not always as clear or in deapth as it could be :oops:

I have not used gforth or indeed any other modern forth - I expect there have been some advances over the last 30 years!
Title: Re: FORTH
Post by: lgb on 2013.March.08. 10:09:28
Quote from: BruceTanner
Yes I find FORTH a fascinating language & operating system, completely different from anything else. Very simple yet very powerful and without the bloat and fat that comes with modern OSs.
I must agree with these, even with the fact that I know _some_ forth only since a day or so :)

Quote
As far as I know IS-FORTH is forth-83 (it was supposed to be!) but it is possible I missed something. I am not sure about WORDS - I thought that came later but I might be wrong. Of course you can always enter

: WORDS   VLIST ; :)

There is no SEE in IS-FORTH. I have often wondered if it would be possible to "disassemble" a forth word but I didn't realise someone had actually done it! I will think about that one and see if I can come up with anything. Yes it has a built-in assembler but that too is reverse polish eg DE PUSH - RTFM! - but I acknowledge TFM is not always as clear or in deapth as it could be :oops:
Hehe, cool, WORDS defined as VLIST :)

Afaik forth of Jupiter ACE can do it. As far as I can see, it really shows the strength of forth, as ACE only has 8K ROM which includes the forth, basic word definitions, character set definition and also the elementary (tape oriented) I/O routines:

"The ACE had an 8 KB ROM containing the Forth kernel and operating system, and the predefined dictionary of Forth words in about 5KB. The remaining 3KB of ROM were used for tape control, floating point numbers library and character definitions table. Some of the ROM was written in Z80 machine code, but some was also coded in Forth."

What I've found:

"The ACE's Forth could decompile its programs, unlike usual Forth systems. This decompiling ability had several advantages as a solution to the absence of the more flexible disk system used by Forth. It did not store the text of a Forth program, instead it compiled the code after editing and stored it in ready-to-run format. While this saved computer memory it also saved time in reading and writing programs from cassette tape. This tape-friendly and RAM-saving solution was unique to the Jupiter ACE Forth."
Title: Re: FORTH
Post by: lgb on 2013.March.08. 11:37:28
Bruce, if you have some time/mood to bother with my madnesses, I would be happy to recieve some help :)

I'm working on a general Enteprise EXOS file analyzer/lister/disassembler, now it supports IS-FORTH too (type-1 EXOS header).


Now, only about the IS-FORTH part of the functionality ...

If you examine example for IS-FORTH listing output, you can see, that almost  every words are red.  This is because I use the "default" vlist to colourize words in that list as red.  That was also the reason I've asked the "save the output of VLIST" so I could include it in my program :) Later, user defined words are tracked too (you can see at words after : and the usage of those words are converted into HTML links).  Anyway, what is interesting: you can see number 0 or 3 as red, while eg 91 or 65 are blue (numeric constants used to be pushed onto the stack).  Now that's interesting for me: what's the purpose to have forth word 3 defined?  Afaik forth's default rule is to try to interpret word as a number and push on the stack if it's not in the vlist.  Was it a performance reason?  Eg, was it faster to implement common numbers like 0 or 3 as forth words, and leaving other numbers as-is?

Another questions are about the on-disk file format (the basics told by Zozo btw): before every 1024 buffer there are two bytes.  The first - it seems - is the "buffer sequence number" starting to be counted from 1.  Is it always true to have these sequences as 1, 2, 3, ...  etc (always from number 1,  always a strict sequence of numbers without gaps, repeats, etc), or there can be cases when it is not true?  Currently, my program requires this, that's why I am asking.  I would be also interested in the other byte before each buffer, according to Zozo it's the "type".  It seems to be always zero, and I have no idea what it's used for ...

Thanks a lot in advance!
Title: Re: FORTH
Post by: Zozosoft on 2013.March.08. 11:53:03
Quote from: lgb
Another questions are about the on-disk file format (the basics told by Zozo btw): before every 1024 buffer there are two bytes.
You ask the type-1 EXOS module? I think the right name for this "on-tape" format.


Quote
 The first - it seems - is the "buffer sequence number" starting to be counted from
Later I found: the buffer number is on 16 bits! Valid from 1 to 32767.
The sequence is "random", last edited first, see this example:
Title: Re: FORTH
Post by: lgb on 2013.March.08. 12:14:31
Quote from: Zozosoft
Later I found: the buffer number is on 16 bits! Valid from 1 to 32767.
The sequence is "random", last edited first, see this example:
Nice spot, I had some feeling before it can be the case somehow :) Btw, then in the EXOS header too, the byte after type type byte telling the number of buffers should be interpreted as word, eg the next byte then is the high-byte of the buffer counter? If it's not true, the format would be limited to have max of 255 buffers only ... However as every buffer is 1K, I guess it can be enough, as files with more buffers would be longer than 255K which is not so practical on an averge Enteprise system (unless IS-FORTH can load only a given buffer, and not the whole file, of course).
Title: Re: FORTH
Post by: Zozosoft on 2013.March.08. 12:30:32
Quote from: lgb
If it's not true, the format would be limited to have max of 255 buffers only ... However as every buffer is 1K, I guess it can be enough, as files with more buffers would be longer than 255K which is not so practical on an averge Enteprise system
From the manual: at the start 8 buffers used. Can be added more with the CREATE-BUFFERS which is allocating full segment for more 16 buffers. It is can be used 16 times, then the total buffers is 8+16*16=264.
But now I tried and after 13 CREATEs it is frozen :oops:
Title: Re: FORTH
Post by: lgb on 2013.March.08. 16:29:51
Quote from: Zozosoft
From the manual: at the start 8 buffers used. Can be added more with the CREATE-BUFFERS which is allocating full segment for more 16 buffers. It is can be used 16 times, then the total buffers is 8+16*16=264.
Ok, but 264 cannot fit within a single byte, so the EXOS header should contain not only a byte for describing the number of forth buffers, if I am correct. That's why I thought the byte in the EXOS header after the type byte is not enough, and maybe the byte after it (which is usually zero) is the high byte of the word sized buffer counter for real. But I should create a file with more than 255 (and less than 264, if you are right?) buffers in it :) Honestly, I feel lost a bit with forth, especially with the storage methods. As far as I can understand the "difficulties" is because forth is old and run on systems without "real" OS (other than forth) having only block I/O without real filesystem etc ...
Title: Re: FORTH
Post by: BruceTanner on 2013.March.08. 22:14:26
Quote from: lgb
Was it a performance reason?  Eg, was it faster to implement common numbers like 0 or 3 as forth words, and leaving other numbers as-is?

Yes, spot on - you have discovered a little secret! (Actually, not so secret - they are in the manual). Not a major performance increase but slightly quicker nonetheless. I think it's worth it for 0 and 1 which occur in programs very commonly; I'm not so convinced by 2 and 3!

Quote
Honestly, I feel lost a bit with forth, especially with the storage methods. As far as I can understand the "difficulties" is because forth is old and run on systems without "real" OS (other than forth) having only block I/O without real filesystem etc ...

Yes, FORTH can sit rather uncomfortably on other OSs, particularly with file I/O, and especially with tape storage! I was reading the word list of a modern FORTH the other day and it included a set of words very similar to C's fopen(), fread() etc.. Of course of the Enterprise you can use EXOS :)

Quote
From the manual: at the start 8 buffers used. Can be added more with the CREATE-BUFFERS which is allocating full segment for more 16 buffers. It is can be used 16 times, then the total buffers is 8+16*16=264.
But now I tried and after 13 CREATEs it is frozen (http://enterpriseforever.com/Smileys/phpbb/ds_icon_redface.gif)
Trust you to try that zozo!! ;-) :oops: I was not able to test that 30 years ago - that much memory was just a distant dream! This system of saving the buffers to a file was really a way of getting around the lack of disks which standard FORTH relies on (it is my invention, not standard). In my defence nobody would want to save 264k to a tape file :smt015 If you were writing a serious program on a real Enterprise with disks you would not use this method at all - you would use the random access .4th files to hold your FORTH blocks.

lgb I think you and zozo now have more information than my memory about the file format! In FORTH You can create whatever block numbers you like, eg 10 EDIT followed by 10000 EDIT so when they are written to the file there is no way they could be sequential. I expect the order is whatever the order in internal memory.

One point I have just noticed is that trailing spaces are not removed; thus even the smallest program takes up 1k :oops: and if you have 16 small program fragments each in their own block it will take up 16k :oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops: which is not good on tape systems that this is aimed at!
Title: Re: FORTH
Post by: Zozosoft on 2013.March.09. 00:22:53
Quote from: BruceTanner

One point I have just noticed is that trailing spaces are not removed; thus even the smallest program takes up 1k :oops: and if you have 16 small program fragments each in their own block it will take up 16k :oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops::oops: which is not good on tape systems that this is aimed at!
There is a Turbo Pack Tape (http://ep128.hu/Ep_Util/TPT.htm) extension which compresses the saved bytes on the fly  :-) (and higher baud rate also can be used)
Title: Re: FORTH
Post by: lgb on 2013.March.10. 11:12:46
Quote from: BruceTanner
Yes, spot on - you have discovered a little secret! (Actually, not so secret - they are in the manual). Not a major performance increase but slightly quicker nonetheless. I think it's worth it for 0 and 1 which occur in programs very commonly; I'm not so convinced by 2 and 3!
I've just checked the output of vlist out again. It seems there are four words defined whose names are consist of only numbers: 0, 1, 2 and 3. Interesting to have defined words for 2 and 3 too, if it's not worth as much as for 0, 1 because then some may think that eg 4 and 5 should be handled this way as well :)
Title: Re: FORTH
Post by: BruceTanner on 2013.March.10. 11:28:57
Quote from: lgb
...some may think that eg 4 and 5 should be handled this way as well :)
It's FORTH so they can if they want to :smt003 (will require use of assembler if it is to be exactly the same)
Title: Re: FORTH
Post by: BruceTanner on 2013.March.10. 11:54:16
Quote from: BruceTanner
It's FORTH so they can if they want to :smt003 (will require use of assembler if it is to be exactly the same)
So before someone asks:

CODE 4   DE PUSH,  HL DE EX,  4 HL LD,  IX JP(),  END-CODE
CODE 5   DE PUSH,  HL DE EX,  5 HL LD,  IX JP(),  END-CODE

The top two items on the stack are held in registers DE and HL. So PUSH DE puts the current second item on the actual stack to make it the third, EX DE,HL puts the current top of stack in HL into DE to make it the second on the stack, and LD HL,4 makes 4 the new top item on the stack. JP (IX) is how all IS-FORTH machine code words end.
Title: Re: FORTH
Post by: Zozosoft on 2013.March.12. 21:20:40
Lacika wrote prime search program (http://enterpriseforever.com/programozas/basic/msg30973/?topicseen#msg30973) for comparing BASIC and FORTH speed.
Title: Re: FORTH
Post by: Zozosoft on 2019.September.24. 12:10:13
ExcaliburGER's machine at the Classic Computing exhibition :-)
[attach=1]
Title: Re: FORTH
Post by: ExcaliburGER on 2019.November.25. 17:19:08
Hi together,

I like Forth for a long time ago now, not so experienced but try my very best. This year I met a guy from the VCFe at HNF in Paderborn and we started three benchmarks on my old Sinclair QL at the very beginning of the site below. So yesterday it was time to reprogram the tests in IS-Forth and send him the results.

Enterprise 128 - Ultimate Forth Benchmark (https://theultimatebenchmark.org/#sec-8) (must rolled down a bit)

Don't take a look at the results over the Ent ;) Thanks to Zozo about his examination to work with "BUFFERS ON " File.4TH" NAME. It's much more easier than working with the 1k-Blocks!

Greetings, Carsten
Title: Re: FORTH
Post by: Zozosoft on 2019.November.26. 10:20:18
Can you upload the Enterprise program files?
Title: Re: FORTH
Post by: Ep128 on 2019.November.26. 23:47:12
ExcaliburGER's machine at the Classic Computing exhibition :-)
(Attachment Link)

Enterprise monitor, Enterprise printer... Hmmmmm... :-)
Title: Re: FORTH
Post by: ExcaliburGER on 2019.November.27. 17:56:14
So attached is the file, which is produced by the following steps

Change Drive and Directory in EXDOS
Afterwards start Forth

Code: [Select]
BUFFERS ON " DORECO.4TH" NAME
LOAD-BUFFERS
1 LOAD 2 LOAD 3 LOAD
DOINT
FIB2-BENCH
GCD1-BENCH

After LOAD-BUFFERS you can take a look into the pages of the file via 1 EDIT..3 EDIT.
To compile 1 LOAD..3 LOAD. After that DOINT, FIB2-BENCH, GCD1-BENCH are available to run. These tests are not exactly the same as on the benchmark site. NIP is replaced by SWAP DROP and U> by simple >.

If you modify the different pages LOAD them again.... AND don't forget the SAVE-BUFFERS at the end of the session :)
Title: Re: FORTH
Post by: ExcaliburGER on 2021.April.04. 08:53:43
Time to get this thread back to the active ones :) I've tried myself in finding an algorythm to draw the Sierpinski triangle. In a modern BASIC it's not really a problem, because the parameter variables are stored automatically and restored at procedures/functions end. Because it was a nice skill exercise, I ported it to IS-FORTH. Takes me hours of lifetime :ds_icon_cheesygrin:

But to the history, found this original tweet at Twitter (https://twitter.com/6502nerd/status/1351653374677176322?s=20) on an ORIC. So, let the work begin. And here is my IS-Forth result (https://twitter.com/Rp12Biker/status/1352339572840128518?s=20) - first time I ever used the word RECURSE. And to see how fast the ARM processor is... on an Acorn 3020 (https://twitter.com/Rp12Biker/status/1352724150398414848?s=20).

Maybe the program can be more compact, my FORTH skills are really at beginners level. And it wasn't so easy for me to deal with four stack values at the same time. But I want to avoid variables, there is no "stackable" variant of them ;-)
I want to share it with you, so here is the listing for a first view:
Code: [Select]
( Drawing Sierpinsky triangle )

: TRIANGLE ( X Y L S -- )
  2SWAP 2DUP MOVE ( STARTPOINT )
  2SWAP SWAP DUP
  0 > IF
    SWAP 2SWAP 2DUP
    4 PICK + DRAW
    2DUP SWAP 4 PICK + SWAP DRAW
    2DUP DRAW 2SWAP
    2 / SWAP 1 - SWAP
    ( SHOULD BE X Y L-1 S/2 )
    3 PICK 3 PICK 3 PICK 3 PICK
    RECURSE
    3 PICK 1 PICK + 3 PICK 3 PICK 3 PICK
    RECURSE
    3 PICK 3 PICK 2 PICK + 3 PICK 3 PICK
    RECURSE
    2SWAP SWAP
  THEN
  2DROP 2DROP ;

As attachment it is added as a FORTH editor file, which you can put into file system in EP128emu (Set working directory). And then use
Code: [Select]
BUFFERS ON " triangle.4th" NAME
LOAD-BUFFERS 1 LOAD
-- Switch to HIRES graphic mode
4 HIRES
-- to run it after loading
0 0 6 700 TRIANGLE
Title: Re: FORTH
Post by: Lacika on 2021.April.04. 09:35:04
What am I doing wrong?
*** Channel does not exist.
Title: Re: FORTH
Post by: ExcaliburGER on 2021.April.04. 09:50:59
Before you start it, you have to switch the graphics mode. I have corrected that 2 minutes later in the post and did not thought, that someone is such incredible fast :)
Code: [Select]
4 HIRES
-- after that - only 4 lines at the bottom for input
0 0 6 700 TRIANGLE
Hope it helps
Title: Re: FORTH
Post by: Tutus on 2021.July.07. 14:46:52
I interpret the question of our club member Zoltán Horváth.
How to compile FORTH program? So make it executable?
Title: Re: FORTH
Post by: ExcaliburGER on 2021.July.15. 20:55:33
How to compile FORTH program? So make it executable?
Hi, I try to answer your question from my basic FORTH understanding at all. Most of the FORTH systems can't make an executable out of a given source code, because they need their inner core. Maybe there is a way to do this in IS-FORTH, but I haven't found anything about it in the manual yet.

That's because of how the kernel works. FORTH is an interpreter when you type in space separated words or numbers. They are looked up inside a dictionary with their name resulting in an address for executing this single word or a number is stacked. When you type in a declaration (starting with : ) - defining a new word - the system looks up all the addresses inside the new declaration and compiles them (the bunch of sub word addresses) to a new executable block and adds a dictionary entry with the start address.

I know, that's a very simplified view and description. For a deeper understanding of the language the FORTH-bible "Starting FORTH" by Leo Brodie explains it much better than I can. The book gives a good background from start to deeper knowledge. It is nowadays freely available, take a look here (https://www.forth.com/starting-forth/). IS-FORTH implements a huge kind of words of the inner core, so it's a good starting point. Some specialities about graphics you have to lookup in it's documentation (http://enterprise.iko.hu/books.htm).
Title: Re: FORTH
Post by: BruceTanner on 2021.July.15. 22:47:44
I second that book recommendation - it was *the* forth book back in the mid-1980s when IS-FORTH was written. It looks a bit cartoon-y at first glance but all the information is there in a readable format.
Title: Re: FORTH
Post by: BruceTanner on 2021.July.15. 22:49:41
But perhaps less useful to some of my Hungarian friends. :(
Title: Re: FORTH
Post by: ExcaliburGER on 2022.October.16. 16:49:19
I have implemented Conway's Game of life with a nice example (https://rosettacode.org/wiki/Conway's_Game_of_Life#Forth) found at rosettacode.org. In lack of some commands in IS-FORTH I looked for ways around, most of a times the chance to find another way is good in Forth. VALUE / TO is replaced by a normal variable with @ and !. The other point is the at-xy, which is only AT in IS. And last the S" StringValue" is replaced by " StringValue" COUNT, which also leaves the count and the address on the stack.

It's loadable with the known procedure:
BUFFERS ON " A:GOL.4TH" NAME
LOAD-BUFFERS

After that the first 6 blocks have to be loaded (1 LOAD CR, 2 LOAD CR...6 LOAD CR). After all six pages are loaded the examples like "CLEAR 0 GLIDER SHOW CR" are working. But don't count rocket speed in execution ;)

I wanted to use "->" to load the next block automatically, as described in the manual of IS-Forth. But it does not work -> "not found" :(
Title: Re: FORTH
Post by: gflorez on 2022.October.17. 16:08:23
Hello Hexcaliburger.

I have tried to load the file, but Forth doesn't find it. What is your configuration?

[attachimg=1]
Title: Re: FORTH
Post by: Lacika on 2022.October.17. 16:44:23
Hello Hexcaliburger.

I have tried to load the file, but Forth doesn't find it. What is your configuration?


BUFFERS ON " A:GOL.4TH" NAME
BUFFERS ON[space]"[space]A:GOL.4TH" NAME
Title: Re: FORTH
Post by: ExcaliburGER on 2022.October.17. 17:36:16
Yes, the space after the first " is important to seperate the String for FORTH. After the LOAD-BUFFERS you can look inside the sources with
BlkNo. (i.e. 1) EDIT ENTER - Esc ends the editor
Mostly it equals the code from rosettacode.org.