Jump to content
IGNORED

Foxit - in progress


GDMike

Recommended Posts

Can someone explain.  "n CELLS ALLOT"

I did a 10 CELLS ALLOT and looked at

HERE with "."  And received -27587 or something like that.

I'm sure that's an address but is this saying, as this is my thinking, but am I seeing 16 BYTES * 10 from my last available address?

I'm confused. Am I reserving like I would a BSS?

That's what I'm looking for. I need to equ a word to an address and reserve so much memory for it and I don't want my program to run it over.

 

 

Edited by GDMike
Link to comment
Share on other sites

First off, when looking at HERE, use U. instead of . to display the address. It will make a lot more sense, trust me!

 

So, let us say, for the purposes of discussion, that HERE is pointing to address 50,000. In fact, screw it - let's just set HERE to 50,000 using the H variable:

50000 H !
HERE U.
50000

Lets now do a 10 CELLS ALLOT and see what happens to HERE:

10 CELLS ALLOT
HERE U.
50020

So, you have 'alloted' 10 cells, which is 20 bytes of dictionary space for your own use. That's it. CELLS just takes the top of the stack and multiplies it by 2, to get the number of bytes required to reserve that many cells. (A 'cell' in 16-bit Forth is a two bytes.)

 

The definition of CELLS is literally this:

: CELLS (n -- 2n) 2* ;

It's 'syntactic sugar' to make our code more readable.

 

ALLOT is often used with the word CREATE:

CREATE MYBUFFER 10 CELLS ALLOT

This creates a word, called MYBUFFER. When you execute MYBUFFER it just returns the address of the first reserved byte:

CREATE MYBUFFER 10 CELLS ALLOT
MYBUFFER U. 41684

Now, you can store stuff in this buffer by adding an offset to the address:

99 MYBUFFER 5 + !

We just stored 99 into the 5th byte of MYBUFFER.

Or we can do this:

$994A MYBUFFER 5 CELLS + !

We just stored the hexadecimal value 994A into the 5th cell (which is the 10th byte)of our buffer.

image.png.f5a5676362da3bba7b469b1918aaca39.png

 

(99 is 63 in hex ;-))

Edited by Willsy
typos
  • Like 4
Link to comment
Share on other sites

1 hour ago, GDMike said:

I'm confused. Am I reserving like I would a BSS?

That's what I'm looking for. I need to equ a word to an address and reserve so much memory for it and I don't want my program to run it over.

That's exactly what you're doing. If you use it in conjunction with CREATE, like this:

CREATE MYBUFFER 100 ALLOT

Then you have just BSS'd 100 bytes, and MYBUFFER is the 'label' which points to the start of those 100 bytes. Warning: don't do it in a colon definition. Do it outside, at the top of your program.

 

Also, be aware, that ALLOT just reserves dictionary space, so the ALLOTed memory lives in-between the words that you create. If you write past the end of your buffer, you're writing over the dictionary. You'll know when you've done it because TF suddenly can't find anything! It's bloody annoying. I do it all the time! You can see this using DUMP:

 

image.png.915a3f7b943dd8673aa0b23491400b82.png

 

Read this article, it'll help you: Arrays for TurboForth

Edited by Willsy
  • Like 4
Link to comment
Share on other sites

3 hours ago, GDMike said:

I need to equ a word to an address and reserve so much memory for it and I don't want my program to run it over.

After you are done learning about conventional arrays, think about this idea.

 

>> You don't have to assign space for data at the beginning or middle of the program code <<<

 

  After all your program has loaded into memory the word HERE points to the next available empty memory space.

 

So imagine when your program starts it points your arrays and other data to use the empty memory at HERE and beyond.

I will just leave it there for you noodle on. There are some things to watch out for.

Just wanted to explain this concept that is not available in BASIC. (At least I don't think it is)

 

 

 

(consult TF docs for where the "safe" end of memory really is) :) 

_____________________________

End of memory 

-

-

All this is free to use.  
-

-

Top of dictionary   <--- Called HERE 

      ^

      ^

      ^

Bottom of dictionary (First word in dictionary) 

_________________________________


 

  • Like 3
Link to comment
Share on other sites

2 hours ago, TheBF said:

After you are done learning about conventional arrays, think about this idea.

 

>> You don't have to assign space for data at the beginning or middle of the program code <<<

 

  After all your program has loaded into memory the word HERE points to the next available empty memory space.

 

So imagine when your program starts it points your arrays and other data to use the empty memory at HERE and beyond.

I will just leave it there for you noodle on. There are some things to watch out for.

Just wanted to explain this concept that is not available in BASIC. (At least I don't think it is)

 

 

 

(consult TF docs for where the "safe" end of memory really is) :) 


_____________________________

End of memory 

-

-

All this is free to use.  
-

-

Top of dictionary   <--- Called HERE 

      ^

      ^

      ^

Bottom of dictionary (First word in dictionary) 

_________________________________


 

Rt. That's why I mentioned, "without my program running into my reserved ram space". In assy, I know exactly my limits, but im worried here. I'm getting weird things already, for example, I can create new words on top of my last one and all is fine, but as soon as I Break out forth knows nothing, not even bye or cold, like it has a brain freeze. But because I can continue to create new words I'm pushing fwd, I've used SAMs wisely and am at Bank 7 in my coding.

I really only have going on is char re-defs, some graphics, I mean nothing crazy, and every dot is dotted and every T, teed.

 

Edited by GDMike
Link to comment
Share on other sites

Sounds like you're writing into dictionary space somewhere. That will blow it up every time. If it's any consolation, I do it about 10 times an hour when I'm developing forth code!

 

If you get frustrated post your code. Use BLK>FILE to get it in text format.

  • Like 3
Link to comment
Share on other sites

I think I should port my slightly smaller SAMS colon/semi-colon to TF.

That would save you some dictionary memory.

 

But... If you have already used 28K of SAMS I suspect your code could benefit from some re-factoring to do more re-use of common pieces.

In other words don't write the code in Forth, like the language is locked. (ie conventional)

First create the language that you need to make a database and write in that.

That is the secret of fitting lots of functionality into a Forth program. 

  • Like 1
Link to comment
Share on other sites

Thx all.

I'm doing some intro graphics then I do a forget on a word I have that I assume was safe  as I'm only forgetting a null word and all the graphics words I made and don't need. 

If I wanted I could just drop my intro.

 

I mean I'm ok, creation of new words is all fine and if I need the command line it's easy enough to get at. I'm fine, but I thought it might have been SAMs but it's not,  that I can tell anyway, because SAMs reports each time I create a word.

I'll be working tomorrow night. Fun 

 

 

 

Link to comment
Share on other sites

1 hour ago, TheBF said:

I think I should port my slightly smaller SAMS colon/semi-colon to TF.

That would save you some dictionary memory.

 

But... If you have already used 28K of SAMS I suspect your code could benefit from some re-factoring to do more re-use of common pieces.

In other words don't write the code in Forth, like the language is locked. (ie conventional)

First create the language that you need to make a database and write in that.

That is the secret of fitting lots of functionality into a Forth program. 

Right. I thought about that when starting with my graphics intro, and I've left myself wiggle room to drop it without harming Foxit. I'll just see how far I can push it until it's a burden, like I say, booting everything is smooth and everything runs. But detection of my BREAK? Breaks it. Lol

Edited by GDMike
Link to comment
Share on other sites

11 hours ago, Willsy said:

Now, you can store stuff in this buffer by adding an offset to the address:


99 MYBUFFER 5 + !

We just stored 99 into the 5th byte of MYBUFFER.

 

I don’t want to confuse @GDMike with nit-picking details, but I can’t pass this one up. |:) 

 

This is not storing 99 as the fifth byte but, rather, storing 99 in the cell starting at byte 4 (which does include byte 5) because ! stores 2 bytes and only at even address boundaries. This means that whatever was at byte 4 got clobbered with 0. Of course, 99 actually did wind up in byte 5, but not without the collateral damage mentioned.

 

C! , on the other hand, would store that byte properly in byte 5 without disturbing byte 4. :)

 

...lee

  • Like 3
Link to comment
Share on other sites

5 hours ago, Lee Stewart said:

 

I don’t want to confuse @GDMike with nit-picking details, but I can’t pass this one up. |:) 

 

This is not storing 99 as the fifth byte but, rather, storing 99 in the cell starting at byte 4 (which does include byte 5) because ! stores 2 bytes and only at even address boundaries. This means that whatever was at byte 4 got clobbered with 0. Of course, 99 actually did wind up in byte 5, but not without the collateral damage mentioned.

 

C! , on the other hand, would store that byte properly in byte 5 without disturbing byte 4. :)

 

...lee

Oh, that's not nit-picking, Lee. That is an excellent point and well worth bringing up! Thanks for pointing it out! :thumbsup::thumbsup:

 

Mark

  • Like 1
Link to comment
Share on other sites

Ok. I see that Lee.

But I forgot about  !  Storing 2 BYTES to an even address too, geez... yes I know.. nothing different than assy...it's just not sticking in my MSbrain side. I'll remember it from now on.

 

  Oh, I can't wait to try   ' n >LINK n DUMP 

I assume if it's not a word already, as I haven't seen it, it's probably in utilities disk. I'll find it, because it looks like I'll need that too,.

Thx all I'll make use of this.

 

Link to comment
Share on other sites

4 hours ago, Willsy said:

Oh, that's not nit-picking, Lee. That is an excellent point and well worth bringing up! Thanks for pointing it out! :thumbsup::thumbsup:

 

Mark

and it's an excellent example of what I am talking about , writing a FOXIT language to make things simple and reliable.

 

So IMHO that kind of phrase should never be used if it occurs more than once. 

99 MYBUFFER 5 + !

but rather something like this should be made: (  [] used to remind the programmer that this in an array)

: MYBUFFER[]    CELLS  MYBUFFER + ;
   99 5 MYBUFFER[] ! 

 

And then GDMIKE can test this and be certain that it works as expected as a zero based array.

 

And if we really want to be safe then he could add a line to protect index out of range and then remove it, if and when he thinks everything is safe.

: ?INDEX   ( n -- n)  DUP   0 MAXINDEX  WITHIN 0= ABORT" Index range error" ;

: MYBUFFER[]  
            ?INDEX
            CELLS  MYBUFFER + ;


 

  • Like 4
Link to comment
Share on other sites

41 minutes ago, GDMike said:

Ok. I see that Lee.

But I forgot about  !  Storing 2 BYTES to an even address too, geez... yes I know.. nothing different than assy...it's just not sticking in my MSbrain side. I'll remember it from now on.

 

  Oh, I can't wait to try   ' n >LINK n DUMP 

I assume if it's not a word already, as I haven't seen it, it's probably in utilities disk. I'll find it, because it looks like I'll need that too,.

Thx all I'll make use of this.

 

>LINK is built into TF

 

It takes the CFA (code field address) of a word, and converts it to the Link Field Address (LFA) of the same word. See this article on TF's dictionary format.

 

If you're wondering what a code field address does, it's the address of the executable code of a word. You can feed it to EXECUTE and it will, er, execute it:

 

' WORDS

 

Here, we are using the word ' (pronounced 'tick') to 'tick' the word WORDS. This leaves the CFA of WORDS on the stack. Then we can call EXECUTE which expects a CFA on the stack and executes it.

 

' WORDS EXECUTE

 

This is powerful, because you can place the address of words in variables, and execute them later:

 

VARIABLE THING
' 1+ THING !
: TEST ( n -- n+1) THING @ EXECUTE ;

image.png.225ae33e45e620d2407a0627a6aa4f9a.png

 

DUMP is on block 36 of the TF boot disk. Very useful for looking 'inside' memory to see what the hell is going on!

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

Sweet.. but what is meant by "TICK a WORD" ?

' WRD, sorry if it's in a book somewhere and I've just not come across yet.  Is it extract? Or like eval?  Or More like DUP?

 

Ahh. I found this... ' locates the PFA of a word.

Used in a stream BUT can be used in a definition with care.

 

Investigating

https://comp.lang.forth.narkive.com/o20KxEuR/pfa-and-body

Edited by GDMike
Link to comment
Share on other sites

1 hour ago, GDMike said:

Sweet.. but what is meant by "TICK a WORD" ?  ' WRD, sorry if it's in a book somewhere and I've just not come across yet.  Is it extract? Or like eval?  Or More like DUP?

 

Ahh. I found this... ' locates the PFA of a word.  Used in a stream BUT can be used in a definition with care.

 

' (“tick”) finds the pfa of a word in fbForth, but its cfa in TurboForthTurboForth is Forth-83, while fbForth is mostly figForth. ' can be used both when interpreting and when compiling in fbForth, but only when interpreting in TurboForth. When compiling in TurboForth, you must use ['] .

 

...lee

  • Like 4
Link to comment
Share on other sites

2 hours ago, Lee Stewart said:

 

' (“tick”) finds the pfa of a word in fbForth, but its cfa in TurboForthTurboForth is Forth-83, while fbForth is mostly figForth. ' can be used both when interpreting and when compiling in fbForth, but only when interpreting in TurboForth. When compiling in TurboForth, you must use ['] .

 

...lee

Thx lee

Link to comment
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...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...