Jump to content
Sign in to follow this  
Willsy

Forth: A Brief Primer (#2)

Recommended Posts

TF should have said "ERROR: TOM. not found" - that would have helped you.

 

There's a bug in TF somewhere.

Share this post


Link to post
Share on other sites

You typed a word that does not exist in the dictionary: TOM.

 

What you intended was: TOM .

 

...lee

 

 

I see - Spaces are gonna kill me.

Thanks.

  • Like 1

Share this post


Link to post
Share on other sites

No they won't. The space is really the only bit of syntax in Forth. It's what separates words, same as English. Unlike basic you don't need to learn which things need parenthesis or commas or semi-colons or colons. And if you don't like how a word works you can change it!

Share this post


Link to post
Share on other sites

I have a bunch of questions specific to Turboforth so I'm going to ask here instead of going on a wild goose chase.

I need to learn the base system before I can move ahead with programs.

 

Am I to understand that a block is a disk file area where words get stored for multiple programs?

And using the EDIT function allows me to see the currently loaded BLOCK?

 

I read notes on how to change the default block and manually load one you want. What about listing available blocks and seeing the contents?

Is it OK to assume that each new block contains no words except the default definitions that come with TF?

Or is the only thing available being the built in functions that define words?

How do I save programs? (Words) So that after a power cycle I can get back to TF with TOM Dick Harry And Dice-Roll still available?

Where can I find a list of all the syntax. For instance ! , . : ; etc...
Where can I find a list of words that come with TF (if any) and how can I see and view the functions of all words currently available (including ones I wrote etc..)?

Am I to understand that a finished program will in essence become a word?

Right now my biggest challenge is picturing all this in my head and not knowing how to see it on the screen, the stack, the words, the word definitions etc...
I'm wanting a way to visualize or see the stack so I can better understand everything that is going into it and how it changes when needed.

Am I to understand that TF only ever works from the top of the stack ever? That variables are the only things that need the stack to get reorganized (search the stack, move to top work from there)?

How big can the stack get and are there trimming functions to minimize the stack size? Which in turn I think will save ram.

How do I know how much ram I'm using?

 

So many more but that's it for now.

 

I know, I'm over thinking this. i can't help it. This is so strange. Oh wait, is there a compiler for forth so that others can run forth created programs without forth?
What about forth programs to Cartridge? How does that work?

Share this post


Link to post
Share on other sites

Please start here for blocks info:

 

http://turboforth.net/tutorials/blocks.html

 

There is a *ton* of info on the TurboForth web site.

 

To find out how much memory you have type MEM on the command line. It displays three numbers:

 

1) amount of free memory in 8k expansion

2) amount of free memory in 24k expansion

3) total amount of free memory

 

To see all the words that TF has type WORDS

 

Also go to the language reference on the TF website. They are all documented.

 

That should keep you going for a while.

 

I'll try and post a YouTube video about blocks when I have a chance. In the meantime heres an old one I did back in 2011 with TF V1.0

 

  • Like 2

Share this post


Link to post
Share on other sites

Just to put it out there, my interest is to see if i can rewrite my Zombi game in Forth and compare the final compiled version performance against what I currently have. I'm hopeful I can save a lot of ram AND get much better performance in TF. And since I'm using TidBit, the elimination of line numbers should make it easier to breakdown and convert. But I do define and use a lot of variables. So I'll be exploring ways to eliminate the need to do so. I've gotten side tracked from other projects so this week I'll allocate the proper time for each. TF will probably be limited to a few hours a week as I've started a self paced Computer Science course (non degree course) to learn other languages as well. First course is SQL. Something I've been meaning to learn for many years, then Java then C etc.. All while keeping the TI relevant and trying to get my side business off the ground while keeping my day job..

Edited by Sinphaltimus

Share this post


Link to post
Share on other sites

Post me a link to your zombie game. I'll take a look at it.

Share this post


Link to post
Share on other sites

Post me a link to your zombie game. I'll take a look at it.

http://atariage.com/forums/topic/255837-new-32k-xb-gamezombi-work-in-progress/?fromsearch=1

 

There's also the "gotcha" in that I'm merging in compressed graphics from Wilhelm's tools. But I can probably return to pure code for that when the time comes.

Share this post


Link to post
Share on other sites

My 2 cents for Sinpahltimus is to get a text editor or word processor and try writing what the different parts of the game do in your own words.
Try not to think in basic, but chop the game up into the different sections of code that need to do specific stuff and say it in English.

The secret to good Forth programs is very well demonstrated by Willsy's Primer #3.
It takes some practice to stop thinking the way that BASIC forces us to think.

For example I re-did a version of the denile program the way I would do it and here is the main routine called RUN:

: RUN        ( -- )
             2 SCREEN
             CHANGE-CHARS
             CLEAR  .PYRAMID .STARS .MOON .RIVER
             HONK RESTORE-CHARSET 
             ;

2 SCREEN is CALL SCREEN(2). So you know I changed it to a night scene.

The Forth word '.' (dot) prints a number so some people put a DOT in front of words that put stuff on the screen.
Now you understand what this program does pretty much right away. And it's because it was "factored" into small pieces.

Oh and I had to add the stars and a moon in a night scene. :-)


And the .RIVER word is actually a loop that does all the action with the water and star twinkling and exits if you hit a key.
It looks like this:

Hope this helps.

: .RIVER     ( -- )
             INIT-WAVES  
             BEGIN
               100 MS
               .WAVES
               3 TWINKLES
               KEY?
             UNTIL ;

post-50750-0-48743700-1494895280.jpg

Edited by TheBF

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...