FORTH for every Atari

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

FORTH for every Atari

Post by Moulinaie »

Hello,

I worked again on my FORTH interpreter/editor/Compiler and finally wrote a page about it.
forth.gif
Features:
- binaries for 68030 and 68000
- available in french and english
- compiler to generate a standalone program (GEM, Auto, ACC)
- support for DMA sound (even with the SAGA system of the Vampire)
- support for the Supercharger as a coprocessor
- standard functions GEMDOS, Bios, Xbios, VDI, AES
- lots of data types (integers B, W, L, double precision reals, arrays, enumerated sets or numerical segments, structures, chained structures...)
- create menus within the source (without RSC)
- create dialogs within the source (without RSC)
- windowed dialogs are managed
- conditional compilation (according to the language, the CPU, etc)
- can include an external source sent to an external compiler (as an assembler for example)
- all written in assembly, speed and compacity! (the interpreter, editor, compiler in ram weights only 76KB including its debugging infos)

(english) https://gtello.pagesperso-orange.fr/forth_e.htm
(français) https://gtello.pagesperso-orange.fr/forth_f.htm (with full french PDF manual)

One last thing is to write the english version of the manual...

Guillaume.
You do not have the required permissions to view the files attached to this post.
User avatar
mrbombermillzy
Atari Super Hero
Atari Super Hero
Posts: 581
Joined: Tue Sep 13, 2016 9:24 am

Re: FORTH for every Atari

Post by mrbombermillzy »

Great work there! :cheers:

Never looked into FORTH, despite having two books on the subject (the first at the age of 15 years!)

The tutorial on your site makes the language look shockingly easy to manipulate the AES with.

How does it interface with assembly (passing data through registers or on the stack?) and run assembly code?

If any of the above is possible, I will be keeping a very close eye on this! :)
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

mrbombermillzy wrote: Tue Feb 15, 2022 8:02 pm Great work there! :cheers:

Never looked into FORTH, despite having two books on the subject (the first at the age of 15 years!)

The tutorial on your site makes the language look shockingly easy to manipulate the AES with.

How does it interface with assembly (passing data through registers or on the stack?) and run assembly code?

If any of the above is possible, I will be keeping a very close eye on this! :)
Inside FORTH, a6 points to the stack, so it's very easy to pass parameters to an assembly code.
I was thinking of adding a paragraph with an example interfacing ASM and FORTH...

There are several possibilities, the most powerful is to create FORTH words entirely in ASM : their names, codes are created in assembly and, when loaded during compilation, they appear as normal words that you can use.

Guillaume.
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

As a fast example, suppose you want to write a little word that tells you if a year is a leap year:

prepare in ASM:

Code: Select all

	text
leap:
	dc.w 437			; code for assembly word
	move.l (a6)+,d0		; take the year
	move.l d0,d1
	and #$0003,d1		; multiple of 4 ?
	bne.s .common		; no so it's a common year
	divs #100,d0		; else, we know it's multiple of 4
	swap d0
	tst d0			; multiple of 100?
	bne.s .leap		; no, so it's a leap year
	swap d0
	and #$0003,d0		; multiple of 400?
	beq.s .leap		; yes, so leap
common:
	moveq #0,d0
	bra.s .exit
.leap:
	moveq #1,d0
.exit:
	move.l d0,-(a6)
	rts
	
	data
	dc.b "ADD_DEFS"	; magic word
	dc.l leap,-1
	dc.b "isLeap",0
	
	end
	
Then you can assemble this source as, for example, "C:\LEAP.PRG"

Then in FORTH, just add:

Code: Select all

0 >include "C:\LEAP.PRG"
And you have the new word isLeap that returns 0 if it's a common year and 1 for a Leap year:

Code: Select all

2022 isLeap .	\will return 0
1900 isLeap . 	\will return 0
2000 isLeap .	\ will return 1
That's it !
So you see, FORTH uses the DATA section to tell the addresses and names of the new words. (there can be more than one).
You just have to preserve A4-A5, and use A6 as the stack pointer to get your parameters and return the results.

Guillaume.
User avatar
shoggoth
Nature
Nature
Posts: 1220
Joined: Tue Aug 01, 2006 9:21 am
Location: Halmstad, Sweden
Contact:

Re: FORTH for every Atari

Post by shoggoth »

Amazing :)
Ain't no space like PeP-space.
User avatar
mrbombermillzy
Atari Super Hero
Atari Super Hero
Posts: 581
Joined: Tue Sep 13, 2016 9:24 am

Re: FORTH for every Atari

Post by mrbombermillzy »

Sounds great.

The next thing I will ask (doesnt seem to be in the above example), is whether there is the option for parameter passing with these FORTH 'words', and if so, are they calculated/equated and compiled before, or on the same pass as the code (and therefore valid), or after?

What Im really looking for with the above, is the ability to use variable based arguments for the language 'words' which will be valid and not calculated on a later compile pass. Is this done? (This is the biggest drawback for making much more effective assembler MACROs IMHO; values that are not calculated/known before the actual code argument compile pass and therefore invalid).

Hope the above makes some sense, its getting a bit late in the day here! Yellow_Colorz_PDT_30 :lol:
arf
Captain Atari
Captain Atari
Posts: 258
Joined: Thu May 17, 2012 9:56 pm
Location: Germany

Re: FORTH for every Atari

Post by arf »

cool stuff, thanks for providing not only the binary but also the sources!
User avatar
christos
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2528
Joined: Tue Apr 13, 2004 8:24 pm
Location: Greece

Re: FORTH for every Atari

Post by christos »

Nice! Forth is a language I have absolutely no idea of how it works but I know it has inspired lots of modern languages.
User avatar
viking272
Atari Super Hero
Atari Super Hero
Posts: 705
Joined: Mon Oct 13, 2008 12:50 pm
Location: west of London, UK

Re: FORTH for every Atari

Post by viking272 »

Wow, there is such a lot here. Thank you Guillaume.

It's all very polished and like a commercial package that a whole team has worked on.

I noticed the French manual doesn't have page numbers on each page but it's very well indexed and obviously searchable in the PDF format.

How did you create the PDF document? Is it from LibreOffice?

Do you need help from the community for an English translation?
robdaemon
Atari freak
Atari freak
Posts: 57
Joined: Mon Jul 24, 2017 5:01 am

Re: FORTH for every Atari

Post by robdaemon »

Amazing! Thank you, Guillaume!
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

mrbombermillzy wrote: Tue Feb 15, 2022 10:07 pm Sounds great.

The next thing I will ask (doesnt seem to be in the above example), is whether there is the option for parameter passing with these FORTH 'words', and if so, are they calculated/equated and compiled before, or on the same pass as the code (and therefore valid), or after?

What Im really looking for with the above, is the ability to use variable based arguments for the language 'words' which will be valid and not calculated on a later compile pass. Is this done? (This is the biggest drawback for making much more effective assembler MACROs IMHO; values that are not calculated/known before the actual code argument compile pass and therefore invalid).

Hope the above makes some sense, its getting a bit late in the day here! Yellow_Colorz_PDT_30 :lol:
Hello!

I'm afraid I didn't understand the question...
I'm terribly sorry...

Guillaume.
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

arf wrote: Tue Feb 15, 2022 10:16 pm cool stuff, thanks for providing not only the binary but also the sources!
Thanks!
I've always been inspired by other's sources, so I hope they can help!

Guillaume.
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

viking272 wrote: Tue Feb 15, 2022 11:07 pm Wow, there is such a lot here. Thank you Guillaume.

It's all very polished and like a commercial package that a whole team has worked on.

I noticed the French manual doesn't have page numbers on each page but it's very well indexed and obviously searchable in the PDF format.

How did you create the PDF document? Is it from LibreOffice?

Do you need help from the community for an English translation?
Thanks! It looks polished... The FORTH window is a draft one, no redraws. Your programs can output text, drawings etc... and this is not memorized.
But, within your program, you can manage the redraws, and the FORTH provides some instructions to help.

I first wrote the manual using Atari Works ! Then, I just had to export it to RTF to be able to load it in Libre Office (as you guessed!).
Some help for translating would be appreciated! I can add the original ODT document to my page.

Guillaume.
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

christos wrote: Tue Feb 15, 2022 10:55 pm Nice! Forth is a language I have absolutely no idea of how it works but I know it has inspired lots of modern languages.
It works like a HP calculator. It uses a stack : every new parameter (a number a string address, ...) is pushed on the stack and every function (or word) pops its parameters from the stack and eventually returns values on the stack.

For example, to do the sum: 8+9 you write:

Code: Select all

8 9 +
8 goes on the stack, then 9 over 8 and the function "+" pops those two values and returns 17. Now your stack only contains 17.

Another example, if you want to open a file for output:

Code: Select all

" MYFILE.EXT" 1 fopen
The word " (notice that it is isolated at start) creates a temporary string and pushes its address on the stack
Then the value 1 is on the stack (1=write to file)
and fopen pops those two values and if successful, returns the file handle. You can save it to a variable or just use it from the stack.

Let's complete the example, you open the file, write the whole ST screen to it (32000 bytes starting at physbase) and close it:

Code: Select all

" BLOCK.BIN" 1 fopen
dup 32000 physbase fwrite .
fclose 
The first line opens the file and returns the handle
On the second line the handle is duplicated (because we'll need it for fclose), the screen is saved and fwrite returns the number of bytes actually saved, the period pops this value and displays it for checking.
On the last line the duplicated handle is used by fclose.

That's is, without any variable.

Guillaume.
User avatar
viking272
Atari Super Hero
Atari Super Hero
Posts: 705
Joined: Mon Oct 13, 2008 12:50 pm
Location: west of London, UK

Re: FORTH for every Atari

Post by viking272 »

I would like to help with translation but maybe a page at a time...then commit my edits. Some weeks I have very limited time. Is this possible? 😀
User avatar
mrbombermillzy
Atari Super Hero
Atari Super Hero
Posts: 581
Joined: Tue Sep 13, 2016 9:24 am

Re: FORTH for every Atari

Post by mrbombermillzy »

Moulinaie wrote: Wed Feb 16, 2022 7:36 am Hello!

I'm afraid I didn't understand the question...
I'm terribly sorry...

Guillaume.
Hey, no worries. I will try to explain better with an example scenario...

Lets say I wanted to make a language word 'Graphics' which took a variable 'Screenheight'; the variable being either of two values, so I could set my ST screen to LOW or MED res accordingly, in the language word 'Graphics' code.

Now, would this variable passing be possible, or would this cause an error on compilation because the variable 'Screenheight' is not defined?

Hope thats clearer to understand. :)
Last edited by mrbombermillzy on Wed Feb 16, 2022 8:50 am, edited 1 time in total.
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

viking272 wrote: Wed Feb 16, 2022 8:10 am I would like to help with translation but maybe a page at a time...then commit my edits. Some weeks I have very limited time. Is this possible? 😀
Many thanks ! I'll tell you when the ODT file is available.
I started programming this FORTH back in 1989... So there's no hurry.

Guillaume.
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

mrbombermillzy wrote: Wed Feb 16, 2022 8:47 am
Moulinaie wrote: Wed Feb 16, 2022 7:36 am Hello!

I'm afraid I didn't understand the question...
I'm terribly sorry...

Guillaume.
Hey, no worries. I will try to explain better with an example scenario...

Lets say I wanted to make a language word 'Graphics' which took a variable 'Screenheight'; the variable being either of two values, so I could set my ST screen to LOW or MED res accordingly, in the language word 'Graphics' code.

Now, would this variable passing be possible, or would this cause an error on compilation because the variable 'Screenheight' is not defined?

Hope thats clearer to understand. :)
That's clearer !

It is not possible, every word or variable used in a new word must be defined before. But what you can do is to use an argument from the stack:
Graphics takes a parameter on the stack (either 0 or 1 for example) and sets the screen mode.

Then, you can use

Code: Select all

0 Graphics 
1 Graphics
according to what you want.
So then if a variable is defined after, let's call it Screen, you can use:

Code: Select all

Screen @ Graphics
the word @ recalls the value of Screen on the stack.

Hope this is clear...

Guillaume.
User avatar
mrbombermillzy
Atari Super Hero
Atari Super Hero
Posts: 581
Joined: Tue Sep 13, 2016 9:24 am

Re: FORTH for every Atari

Post by mrbombermillzy »

Moulinaie wrote: Wed Feb 16, 2022 8:54 am Hope this is clear...
Yes.

Thank you so much for taking the time to explain. :)

Im guessing then, in this manner, that you can have as many parameters as you like (stack permitting)?

(Sorry for all the hardcore questions, but I need to know, as this could be something HUGE for me!)
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

mrbombermillzy wrote: Wed Feb 16, 2022 9:10 am
Moulinaie wrote: Wed Feb 16, 2022 8:54 am Hope this is clear...
Yes.

Thank you so much for taking the time to explain. :)

Im guessing then, in this manner, that you can have as many parameters as you like (stack permitting)?

(Sorry for all the hardcore questions, but I need to know, as this could be something HUGE for me!)
yes, you can have a huge piling of numbers.
I guess the stack is 1KB long, so this is 256 long values.

My Forth allows you to create other stacks, so if you really need 1 MB as a stack, you can have it and push many values to satisfy your gluttony !!

Example:

Code: Select all

2000 &stack MyStack
MyStack current
Creates a stack for 2000 longs (8000 bytes) and use it as a current stack

Code: Select all

stack0 current
back to the original stack.

Guillaume.
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

viking272 wrote: Tue Feb 15, 2022 11:07 pm
I noticed the French manual doesn't have page numbers on each page but it's very well indexed and obviously searchable in the PDF format.
This is fixed! thanks.
The numbers appear...

Guillaume.
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari (adding Assember Code)

Post by Moulinaie »

Hi,

I have added an example on how to mix Assembler and Forth, and this can be done in one and only source file! (at the bottom of the page)
forth_asm2.gif
I have added the ODT manual that you can edit for translation. (at the top of the page)

(english) https://gtello.pagesperso-orange.fr/forth_e.htm
(français) https://gtello.pagesperso-orange.fr/forth_f.htm

Guillaume.
You do not have the required permissions to view the files attached to this post.
User avatar
viking272
Atari Super Hero
Atari Super Hero
Posts: 705
Joined: Mon Oct 13, 2008 12:50 pm
Location: west of London, UK

Re: FORTH for every Atari

Post by viking272 »

I ran the French manual through Google Translate and it spat out an English version. (they can handle PDF/DOCX formats)

Clearly it will need proof reading plus re-arranging some literal translations etc but it may be a good place to start?

I emailed you this version too for comments.
User avatar
mrbombermillzy
Atari Super Hero
Atari Super Hero
Posts: 581
Joined: Tue Sep 13, 2016 9:24 am

Re: FORTH for every Atari

Post by mrbombermillzy »

Moulinaie wrote: Wed Feb 16, 2022 9:40 am My Forth allows you to create other stacks, so if you really need 1 MB as a stack, you can have it and push many values to satisfy your gluttony !!
lol. Thanks.

Apologies if I want clear.

It wasnt so much the stack that I was wanting to extend, but the no. of arguments to a max of about 4. (Would not need the whole stack of arguments!)

If we continue with the example maybe? :wink:

So...

Screen @ Graphics
Depth @ Graphics
Blah1 @ Graphics
Blah2 @ Graphics

etc.

Will place Screen,Depth,Blah1,Blah2 on the stack in this order; all accessible from the Graphics word.

Im guessing this is ok to do?
Moulinaie
Atari Super Hero
Atari Super Hero
Posts: 557
Joined: Wed Feb 01, 2012 9:34 pm

Re: FORTH for every Atari

Post by Moulinaie »

mrbombermillzy wrote: Wed Feb 16, 2022 11:34 am
Screen @ Graphics
Depth @ Graphics
Blah1 @ Graphics
Blah2 @ Graphics

etc.

Will place Screen,Depth,Blah1,Blah2 on the stack in this order; all accessible from the Graphics word.

Im guessing this is ok to do?
Actually, it's simpler:

Code: Select all

Screen @ Depth @ Blah1 @ Blah2 @ Graphics
You place four parameters on the stack and then call graphics.

Guillaume.
Post Reply

Return to “Coding”