Welcome, Guest. Please login or register.


Author Topic: FORTH (Read 63844 times)

Offline BruceTanner

  • EP lover
  • *
  • Posts: 609
  • Country: gb
FORTH
« on: 2013.February.25. 12:00:41 »
Following on from the brief discussion of the speed of FORTH vs zzzip here, 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
;

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14775
  • Country: hu
    • http://enterprise.iko.hu/
Re: FORTH
« Reply #1 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.)

Offline BruceTanner

  • EP lover
  • *
  • Posts: 609
  • Country: gb
Re: FORTH
« Reply #2 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:

Offline BruceTanner

  • EP lover
  • *
  • Posts: 609
  • Country: gb
Re: FORTH
« Reply #3 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


:smt001

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14775
  • Country: hu
    • http://enterprise.iko.hu/
Re: FORTH
« Reply #4 on: 2013.February.25. 16:40:14 »
Quote from: BruceTanner
http://www.forth.com/starting-forth/index.html
It looks great for beginners! (I also like the cartoons :-) )
« Last Edit: 2013.February.25. 20:31:16 by szipucsu »

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14775
  • Country: hu
    • http://enterprise.iko.hu/
Re: FORTH
« Reply #5 on: 2013.February.25. 20:06:06 »
I found something that I do not understand :oops:
[ Guests cannot view attachments ]
« Last Edit: 2013.February.25. 20:32:58 by szipucsu »

Offline BruceTanner

  • EP lover
  • *
  • Posts: 609
  • Country: gb
Re: FORTH
« Reply #6 on: 2013.February.25. 20:37:34 »
Quote from: Zozosoft
I found something what I not understood :oops:
(Attachment Link)
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.

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14775
  • Country: hu
    • http://enterprise.iko.hu/
Re: FORTH
« Reply #7 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:
[ Guests cannot view attachments ]
« Last Edit: 2013.February.25. 20:59:28 by szipucsu »

Offline BruceTanner

  • EP lover
  • *
  • Posts: 609
  • Country: gb
Re: FORTH
« Reply #8 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.)
« Last Edit: 2013.February.27. 14:35:29 by MrPrise »

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14775
  • Country: hu
    • http://enterprise.iko.hu/
Re: FORTH
« Reply #9 on: 2013.February.25. 21:43:08 »
:ds_icon_cheesygrin: [ Guests cannot view attachments ]

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14775
  • Country: hu
    • http://enterprise.iko.hu/
Re: FORTH
« Reply #10 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
[ Guests cannot view attachments ]

Offline BruceTanner

  • EP lover
  • *
  • Posts: 609
  • Country: gb
Re: FORTH
« Reply #11 on: 2013.February.25. 22:25:58 »
Quote from: Zozosoft
But funny if it is happened :-D
(Attachment Link)
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!

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14775
  • Country: hu
    • http://enterprise.iko.hu/
Re: FORTH
« Reply #12 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?

Offline BruceTanner

  • EP lover
  • *
  • Posts: 609
  • Country: gb
Re: FORTH
« Reply #13 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!

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14775
  • Country: hu
    • http://enterprise.iko.hu/
Re: FORTH
« Reply #14 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)