6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun May 12, 2024 12:01 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Mar 01, 2022 12:20 am 
Offline

Joined: Thu May 13, 2021 12:53 pm
Posts: 16
Location: Fargo, North Dakota
Hello,

I have Fig-FORTH running and booting from a serial EEPROM on my own circuit board.
I write code in Notepad and then 'send' it from TeraTerm (thanks to a tip on this forum).
As I write more and more words the load time is getting to be longer, and this unproductive time is killing me.
I would like to be able to save/restore the current state of the system so I don't have to do a complete reload of my code after each reboot.

My FORTH system setup is pretty standard for Fig I believe:
ORIG $400
MEM $7800
UAREA = MEM - $80

I wrote some code to copy the memory block $400-HERE to a serial EEPROM.
Before writing to the EEPROM, I copy $7780-$7796 to $40C-$422. This appears to be for bootup literals.

I am able to boot from this saved image, but the new words I defined do not show up with VLIST.
I manually stuffed a calculated value into CONTEXT and then the new words show up in VLIST.

I can't figure out how/where CONTEXT gets initialized.
Vocabularies, CONTEXT, CURRENT etc. are rather confusing for me at this point.

Am I on the right track or is there a better way?
Any advice would be appreciated.

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 01, 2022 5:13 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Rooster wrote:
Hello,

I have Fig-FORTH running and booting from a serial EEPROM on my own circuit board.
I write code in Notepad and then 'send' it from TeraTerm (thanks to a tip on this forum).
As I write more and more words the load time is getting to be longer, and this unproductive time is killing me.
I would like to be able to save/restore the current state of the system so I don't have to do a complete reload of my code after each reboot.

My FORTH system setup is pretty standard for Fig I believe:
ORIG $400
MEM $7800
UAREA = MEM - $80

I wrote some code to copy the memory block $400-HERE to a serial EEPROM.
Before writing to the EEPROM, I copy $7780-$7796 to $40C-$422. This appears to be for bootup literals.

I am able to boot from this saved image, but the new words I defined do not show up with VLIST.
I manually stuffed a calculated value into CONTEXT and then the new words show up in VLIST.

I can't figure out how/where CONTEXT gets initialized.
Vocabularies, CONTEXT, CURRENT etc. are rather confusing for me at this point.

Am I on the right track or is there a better way?
Any advice would be appreciated.

Thanks

I have yet to come across a really good explanation of Vocabularies, Definitions, Context, Current: and it was a struggle to follow the code through and through.

But I finally came to to the realization that it basically acts the very same as a directory structure of an Operating System but with a continuation link to the parent directory's file names. In the root directory header you can create directories. These directories are known as the Context directories as their contents are linked to its parent directory, which presently is the CURRENT directory (or root directory). The last word in this current Directory (Vocabulary, which is currently the root) is pointed at with the definition of Latest (which is CURRENT @ @).

Now if we were to enter a directory (or one of the Context Vocabularies) by doing the command DIRECTORY DEFINITIONS, this makes the Directory now the current directory and we can see all of the contents of the this directory as well as its parent directory, but not the contents of one of the other directories. This is done by swapping the CONTEXT links with the previous CURRENT links (which was the root directory). And now the CURRENT directory (Vocabulary) is the one we just entered. And now we can see its dictionary of words, starting at CURRENT @ @, plus the words that are in its parent directory.

Then basically we can relate some of the words with OS commands.

VOCABULARIES is the same as CREATE, as in create directories.
DEFINITIONS is the same as Change Directory (CD) and enters the named Vocabulary.
CURRENT is a pointer to the header of the Current Directory which points to the last word in the CURRENT vocabulary. Thus we have to do CURRENT @ @ to get the last word in the Current Directory (Vocabulary)
CONTEXT is a pointer to its parent vocabulary when a new Vocabulary is created, but have not yet entered the new Vocabulary.

This is only way I can make reasonable sense of it all, and is probably why it is so tough to explain in words.


To answer your question:
CONTEXT is initialized when you create a Vocabulary with the word VOCABULARY.
CURRENT is initialized during the launch of the Forth System from a previously saved table of some User Variables.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 01, 2022 11:36 pm 
Offline

Joined: Thu May 13, 2021 12:53 pm
Posts: 16
Location: Fargo, North Dakota
Thank you, that analogy helps make the water a little less murky.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 03, 2022 5:29 pm 
Offline

Joined: Thu May 13, 2021 12:53 pm
Posts: 16
Location: Fargo, North Dakota
I believe I found what I was missing.
In the Fig-FORTH source for COLD start there is this initialization:

Code:
COLD:           .word    *+2   
                lda   ORIG+$0C              //from cold start area
                sta   FORTH+6           
                lda   ORIG+$0D         
                sta   FORTH+7           
                ldy   #$15             
                bne   L2433             
WARM:           ldy   #$0F             
L2433:          lda   ORIG+$10         
                sta   UP               
                lda   ORIG+$11                   
                sta   UP+1             
L2437:          lda   ORIG+$0C,y       
                sta   (UP),y           
                dey                     
                bpl   L2437             
                lda   #>ABORT           
                sta   IP+1             
                lda   #<ABORT+2         
                sta   IP             
                cld                     
                lda   #$6C                  //Find jump opcode
                sta   W-1     
                jmp   RPSTO+2               //And off we go !


The first few lines were the key to my issue.
Code:
                lda   ORIG+$0C              //from cold start area
                sta   FORTH+6           
                lda   ORIG+$0D         
                sta   FORTH+7   


FORTH+6, FORTH+7 ends up to be at $1330 on my system.
ORIG+$0C, ORIG+$0D is at $40C,$40D for me.
This apparently gets the current value of CONTEXT.

So, I modified my SAVE-SYS word to copy $1330 down to $40C before saving.
Now when the new image boots, all of the newly defined words show up in VLIST.

HOORAH!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: