V-FORTH - Forth-83 for the VIC

Basic and Machine Language

Moderator: Moderators

Forbidden64
Vic 20 Hobbyist
Posts: 109
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: V-FORTH - Forth-83 for the VIC

Postby Forbidden64 » Tue Apr 04, 2017 12:56 pm

:shock: You just made my year..s...!

Mystery solved, and I can use my good old commodore 16k cart! 8k is plenty for me...and for forth.

So what do some of those sys-xxxx commands do then. Some are self evident, but that one, sys-writeb, what is that, and why did it make text invisible? What if I mistake other words? Any chance you could whip up a short manual to help out us newbs to V-FORTH? Because this is now going to be my main language on the vic by far, short of load/run basic games. namely because it is fast, and extremely concise...and now I can use it lol.

[edit while I was asking, you had already answered my next questions... :lol:]

User avatar
Mike
Herr VC
Posts: 2993
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: V-FORTH - Forth-83 for the VIC

Postby Mike » Tue Apr 04, 2017 1:09 pm

Forbidden64 wrote:Yes, Vice doesn't support writing .TAP files. At least according to their instruction manual, and what I have found in practice:
section 5.5 of VICE manual paragraph 4:

Supported formats are D64 and X64 for disk images (devices 8, 9 and 10) and T64 for tape images. Notice that T64 support is read-only, and that the cassette is automatically rewound when you reach its end.

TAP != T64

Forbidden64
Vic 20 Hobbyist
Posts: 109
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: V-FORTH - Forth-83 for the VIC

Postby Forbidden64 » Tue Apr 04, 2017 1:22 pm

Ill call the output of that statement -1 :D

There is an easy way to test this...Ill just write a program, and attempt to record it. *types 'basic' on his forth computer :D*

Well holy crap! I love it when I'm wrong! Datasette functions work perfectly for recording .TAPs! Well, that is probably the first and last time that reading the manual actually did more harm than good.

Forbidden64
Vic 20 Hobbyist
Posts: 109
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: V-FORTH - Forth-83 for the VIC

Postby Forbidden64 » Tue Apr 04, 2017 1:40 pm

Srowe, the documentation for V-FORTH, quite the contrary to VICE, is sublime! I am now figuring out how to make a TSAVE word hehe. I'll finish that when I wake up.

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Postby srowe » Tue Apr 04, 2017 2:06 pm

Forbidden64 wrote:Any chance you could whip up a short manual to help out us newbs to V-FORTH?


I've added quite a few more examples recently, I think they help explain as much as a document. I don't think I've made a build of the latest version public, I'll try and do that tomorrow.

Forbidden64
Vic 20 Hobbyist
Posts: 109
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: V-FORTH - Forth-83 for the VIC

Postby Forbidden64 » Tue Apr 04, 2017 7:25 pm

: csave ( sa da lfn addr count -- ) sys-setnam 2dup sys-setlfs 1 sys-open 1 sys-close ;

It did something to the tape that resembles saving lol...I'm really not sure how to "view" anything in this editor though.
Here is a question:
When I write some words, where are they? and how would I even know short of a freezer/monitor how much space it took up? Is there a tracker or byte marker in there somewhere at the end like basic? perhaps a vector in memory somewhere?

Forbidden64
Vic 20 Hobbyist
Posts: 109
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: V-FORTH - Forth-83 for the VIC

Postby Forbidden64 » Tue Apr 04, 2017 9:12 pm

I guess a better way to phrase that question, is how do I delineate between the base words and additional words? It would be convenient to have both. For example, if I wanted to be able to load the base library of words, and then switch between applications, or load in small groups of words that I like to use and merge them on top, but not exclusively all or nothing. This would be useful for merging commonly used words for things like graphics and sound, or even RS232 support which could be added in as a small group of words. I noticed you recently made a wedge patch for rs232 on Bobbi's project for instance, but I might not need that in every single program, as it would waste memory in a game for instance.

Conversely, for distributed software, combining the entire thing and saving the whole thing might be beneficial, as you can make a application for other users which already has forth in the save file, and eliminates a secondary loading procedure. Thing is, even if the editor is just cut and paste, saving the code onto a storage media device is still crucial for a real machine to run it.

I tried to run this with the 16k expansion in VICE, and I cut and pasted some stuff in there. It got stuck in an infinite loop, and never comes back. It only happens after you press the return key, and I placed in the same word from the previous post. I did try typing in direct commands, and that worked. I then tried defining another word,

Code: Select all

: ad 4 4 + cr ;

same thing it died :<

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Postby srowe » Wed Apr 05, 2017 1:23 am

Forbidden64 wrote:Here is a question:
When I write some words, where are they? and how would I even know short of a freezer/monitor how much space it took up? Is there a tracker or byte marker in there somewhere at the end like basic? perhaps a vector in memory somewhere?


They're compiled into the dictionary. There isn't a standard word but the remaining space in the dictionary can be printed with

Code: Select all

>TIB HERE - U.


This takes the address of the user variable store and subtracts the next free dictionary address.

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Postby srowe » Wed Apr 05, 2017 1:36 am

Forbidden64 wrote:I guess a better way to phrase that question, is how do I delineate between the base words and additional words? It would be convenient to have both. For example, if I wanted to be able to load the base library of words, and then switch between applications, or load in small groups of words that I like to use and merge them on top, but not exclusively all or nothing. This would be useful for merging commonly used words for things like graphics and sound, or even RS232 support which could be added in as a small group of words. I noticed you recently made a wedge patch for rs232 on Bobbi's project for instance, but I might not need that in every single program, as it would waste memory in a game for instance.


Normally FORTH uses screens to achieve what you say, but they're clunky and very different from the file-based approach that other languages typically use. V-FORTH can load and compile definitions from text (SEQ) files and (with the latest release) one file can include another. So, for example, a game file (bluemeanies.fs) could have at the top of it

Code: Select all

INCLUDE GRAPHICS.FS
INCLUDE SOUND.FS
INCLUDE GAMEIO.FS


to pull in common definitions.

Conversely, for distributed software, combining the entire thing and saving the whole thing might be beneficial, as you can make a application for other users which already has forth in the save file, and eliminates a secondary loading procedure. Thing is, even if the editor is just cut and paste, saving the code onto a storage media device is still crucial for a real machine to run it.


Once compiled the whole dictionary can be save to disk (or tape) using

Code: Select all

DSAVE BLUEMEANIES


and then loaded back later with

Code: Select all

DLOAD BLUEMEANIES


I tried to run this with the 16k expansion in VICE, and I cut and pasted some stuff in there. It got stuck in an infinite loop, and never comes back. It only happens after you press the return key, and I placed in the same word from the previous post. I did try typing in direct commands, and that worked. I then tried defining another word,

Code: Select all

: ad 4 4 + cr ;

same thing it died :<


Odd, which version are you using? I'll post the latest build now, there were a number of bugs fixed but I don't recall one like that.

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Postby srowe » Wed Apr 05, 2017 1:46 am

Here is the latest version of V-FORTH (3.4). There have been quite a lot of improvements and fixes, take a look at the README for a summary. There are quite a few more modules (graphics, sound etc) which provide functionality. There are also docs which describe memory layout and most of the system interface words.
Attachments
vforth.zip
(86.5 KiB) Downloaded 13 times

Forbidden64
Vic 20 Hobbyist
Posts: 109
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: V-FORTH - Forth-83 for the VIC

Postby Forbidden64 » Wed Apr 05, 2017 1:52 am

srowe wrote:They're compiled into the dictionary. There isn't a standard word but the remaining space in the dictionary can be printed with

Code: Select all

>TIB HERE - U.



This takes the address of the user variable store and subtracts the next free dictionary address.


[edit: my second word then is:

Code: Select all

: free >tib here - cr u. ;

16339 bytes free!


I guess the answer of 8076 explains why it was crashing with 8 less K...
[edit: I read what you wrote more carefully, and the new version does indeed have a smaller 6k prg that I can run on my real vic!! :D]
which would leave be plenty for most applications, especially where one char words are used...I'm glad you left most of them free for us!

I found the memory map, I don't quite understand what this means, where it says user area is 0x40 and the Dictionary is the next byte...is that a one byte kind of pointer with the other one inferred? Kind of like the graphics chip's scheme?

Is it essentially fixed to that 4000 range like 4000-4FFF? which would imply that the pointer is at location 201F? It can't be because then the dictionary would be 99% of that memory...

Code: Select all

  47 | 0x2000  COLD entry     |
  48 | 0x2004  WARM entry     |
  49 | 0x2010  Initial IP     |
  50 | 0x2012  Initial user   |
  51 |         values         |
  52 +------------------------+
  53 | 0x201E                 |
  54 |         Dictionary     |
  55 | MEMHIGH-0x41           |
  56 +------------------------+
  57 | MEMHIGH-0x40           |
  58 |         User area      |
  59 | MEMHIGH-1              |
  60 +------------------------+


[edit: I think I get it now...0x2012h is the actual start vector for user programs, hence program start...not the start of the forth program, because the program itself technically is just more forth... and this would indeed provide for both segmented word selection, and the entirety of the thing to be saved into storage media. Then the program length could be my third word...]

Code: Select all

: prglen free 16339 - cr . ;

grrr, see what I did wrong there??? Some bad FORTHing. Empties the stack, gives a stack error, and is also backwards.


Code: Select all

: free >tib here - ;
: prglen 16339 free - ;
prglen cr .



which would indeed make a very versatile save and/or transmission of a length of data rather easy! I am loving this! I feel like FORTH tends to make me into a temporary severely bipolar person...perhaps it will teach me patience.




OH THANK GOD THERE IS A MANUAL!

I'm still playing with this non-stop lol I only have a few more hours of day off

User avatar
orion70
Meteo VIC
Posts: 3287
Joined: Thu Feb 02, 2006 4:45 am
Location: Piacenza, Italy
Occupation: Biologist

Re: V-FORTH - Forth-83 for the VIC

Postby orion70 » Wed Apr 05, 2017 7:34 am

Mike wrote:
Forbidden64 wrote:[...] VICE doesn't support writing .TAP files.

Eh, what? :?:

Creating, attaching and using TAP files in VICE is easy:

Code: Select all

FILE --> ATTACH TAPE IMAGE...
(name TAPIMAGE.TAP)
click CREATE IMAGE
(click on TAPIMAGE.TAP)
click OK
(now, you can operate files as usual, eg. from BASIC type:)
SAVE"PROGRAM"
FILE --> DATASSETTE CONTROL --> RECORD
FILE --> DATASSETTE CONTROL --> REWIND
(now you can load the program:)
LOAD"PROGRAM"
FILE --> DATASSETTE CONTROL --> PLAY
(...and so on)

:wink:

Forbidden64
Vic 20 Hobbyist
Posts: 109
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: V-FORTH - Forth-83 for the VIC

Postby Forbidden64 » Wed Apr 05, 2017 8:13 am

Wow, I just saw that other post as well
so between reading the file-io, and inferring the word device# sets the default device#
I can then say:

Code: Select all

9 device# (I presume the default is 8 or perhaps 0)
dsave bluemeanies.fs


The INCLUDE is a real bonus! I can see how that works as well!

You also mention in the file-io a rather godsmackingly cool command... an auto-load command which, upon loading is checked in the dictionary, and if present, automatically goes from cold start to running the software! That was a very good addition!

What is that command out of interest?

Do I simply define autoload myself, and then it automatically executes what is in that word?

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Postby srowe » Wed Apr 05, 2017 12:57 pm

Forbidden64 wrote:I found the memory map, I don't quite understand what this means, where it says user area is 0x40 and the Dictionary is the next byte...is that a one byte kind of pointer with the other one inferred? Kind of like the graphics chip's scheme?


The memory map runs like this:

The built-in part of the dictionary runs from $201E to $3FE0 (for the latest version). User variables occupy $40 bytes at the end of memory (MEMHIGH). With 16K expansion that is at $5FFF. User-defined words can therefore run between $3FE0 and $5FBF, 8159 bytes. With 24K expansion you gain another 8K.

Memory from $1000 to $1FFF is left free, it's precious because it's addressable by the VIC.

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Postby srowe » Wed Apr 05, 2017 1:20 pm

Forbidden64 wrote:Wow, I just saw that other post as well
so between reading the file-io, and inferring the word device# sets the default device#
I can then say:

Code: Select all

9 device# (I presume the default is 8 or perhaps 0)
dsave bluemeanies.fs



Nearly, changing variables in FORTH needs an explict store so

Code: Select all

9 device# !


The default is set to 8.

The INCLUDE is a real bonus! I can see how that works as well!


I actually took this a step further. Because the same modules are used in multiple files having a conditional include is also useful. So you can also do

Code: Select all

?include dos dos.fs


This tests if the word "dos" is defined, if it isn't it includes "dos.fs". If it's already defined it's an no-op.

You also mention in the file-io a rather godsmackingly cool command... an auto-load command which, upon loading is checked in the dictionary, and if present, automatically goes from cold start to running the software! That was a very good addition!

What is that command out of interest?

Do I simply define autoload myself, and then it automatically executes what is in that word?


Simplest to give an example: load the words you want to run followed by "autosave.fs". The AUTOSAVE word takes the CFA of the word to automatically start and the filename to save to.

Code: Select all

INCLUDE DEMO.FS
INCLUDE AUTOSAVE.FS
' MAZE AUTOSAVE MAZE.PRG


Now reset to BASIC and type

Code: Select all

LOAD"MAZE.PRG",8,1
SYS8192


and your FORTH program will run.


Return to “Programming”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests