6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed Jun 05, 2024 1:17 pm

All times are UTC




Post new topic Reply to topic  [ 57 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
PostPosted: Thu Dec 30, 2021 3:20 am 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 865
GARTHWILSON wrote:
JimBoyd wrote:
Storing arrays at PAD? Whenever anything is added to the dictionary, be it a new definition or just adding data to an existing data structure with comma and c-comma, PAD will move but its contents will not.

No; what I'm doing is putting temporary software buffers out at the end of RAM. So yes, the pad still floats above the dictionary, but beyond that, there will normally be still-available RAM between the top of the pad and the bottom of the newest buffer.


Sorry, I think there's been a slight misunderstanding. I wasn't thinking about your RAM buffers, although I do remember reading about them. I was responding to IamRob's remark about putting anything persistent, like an array, at PAD.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 30, 2021 6:03 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
JimBoyd wrote:
Sorry, I think there's been a slight misunderstanding. I wasn't thinking about your RAM buffers, although I do remember reading about them. I was responding to IamRob's remark about putting anything persistent, like an array, at PAD.

Although Garth seems to avoid the main question, he does bring up a really good point of buffers and arrays being put in available memory between PAD and LIMIT.

I think we can all agree that the space between HERE and PAD is basically strictly for creating numeric expressions and has nothing to do with WORD copying entire lines at HERE. From what I can see, ." only puts text at HERE during compiling, and <# #> only puts a numeric string below PAD during Run time, there should be no conflict. For personal use I think the space between HERE and PAD can be safely reduced to about 32 as that more than covers the longest DATE/TIME string most will ever create, or more if the need requires it. Maybe the space separation between HERE and PAD should be put into a variable to make it easier to adjust.

As for PAD itself, which is mostly used for temporary strings being compared to text within a buffer, should itself have a restricted cap on it. And that restriction would be the C/L line length. So then a check should be made when using PAD so that PAD + C/L, does not interfere with the buffers or array storage.

I took a use-case from Applesoft which uses a HIMEM pointer. Whenever I assign a buffer or array, I move HIMEM pointer to the beginning of that memory to protect it, and if I use PAD, I compare PAD + C/L with HIMEM for an Out-of-Memory condition.

These are my words for testing for Out-of-Memory. All values given in HEX

73 constant himem ( Applesoft uses $73.74 of zero-page and I use $73.74 of Direct Page )
first himem !
: addbufr ( -- bufadr ) himem @ 400 - dup himem ! ;
: rmvbufr himem @ 400 + first max himem ! ;
: mem himem @ pad c/l + - dup u. ." (" decimal u. hex 8 emit ." ) bytes free" cr ;

Notice I left the new bufadr on the stack when adding a buffer. This helps when I need that value to know where to store arrays or copy data to be protected. But removing a buffer does not require that value.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 31, 2021 5:25 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
As I was converting WORD to a primitive, I noticed it only clears 34 bytes to spaces at HERE. I think this is all the room it thinks it will need.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 31, 2021 6:05 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8454
Location: Southern California
IamRob wrote:
Although Garth seems to avoid the main question [...]

I thought you were asking why there's so much space left between HERE and PAD; so in the Forth I've been using, the answer is that WORD has to be able to move a whole source-code line there if the delimiter is something other than the space.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 31, 2021 7:11 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
GARTHWILSON wrote:
IamRob wrote:
Although Garth seems to avoid the main question [...]

I thought you were asking why there's so much space left between HERE and PAD; so in the Forth I've been using, the answer is that WORD has to be able to move a whole source-code line there if the delimiter is something other than the space.

From what I gather WORD only moves the text to HERE only for temporary use for printing a line or skipping a comment or compiling a word, which does not affect either the numeric data area or PAD at that time, as they are only temporary storage spaces.

For the most part from what I can see, it is ok if WORD tramps on the numerical data area or PAD if the space were smaller, as they are never used at the same time. WORD can still move a 64 or 128 character line to HERE with the gap between HERE and PAD set to 32 bytes and still not hurt anything.

When I was asking, Why, I was looking for a response that showed me a way that WORD was being used that might interfere or conflict with the numerical data area or PAD. I still don't see any conflict, because I still have not seen WORD being used at the same time as the numeric data constructs and/or PAD.

About the only way I can see WORD trouncing on the numeric data area while it is being used is if there is a comment or print statement between the numeric construct statements <# and #>. Of all the examples using the numeric constructs, I have not seen any on their own line with a comment following them. But I suppose it is possible, and it would have to be a long comment to do any damage.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 31, 2021 7:54 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8454
Location: Southern California
IamRob wrote:
For the most part from what I can see, it is ok if WORD tramps on the numerical data area or PAD if the space were smaller, as they are never used at the same time. WORD can still move a 64 or 128 character line to HERE with the gap between HERE and PAD set to 32 bytes and still not hurt anything.

Oh, ok. Thanks for the clarification. The pad area is small enough though that even pushing it out past the longest line that WORD might collect won't make much of a difference in the amount of available RAM remaining. I haven't experienced any problem in that way myself. It is convenient that WORD puts the collection starting at HERE though, because then very little modification is needed to fix up the name field when a header is being formed.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 03, 2022 10:26 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 865

Actually, I think Fleet Forth's PAD gap of 85 bytes might be cutting it close. I'll explain.
I ported Scott Ballantyne's trace words to Fleet Forth and modified them so even pictured numeric output can be traced. The trace displays the next word to be executed and the stack contents. It waits for a key-press to continue. Pressing the control and 'P' keys pauses the trace and runs a version of the quit loop. This allows a programmer to pause a trace and enter commands from the keyboard. Since the longest possible name is 31 bytes, there needs to be 33 bytes available at HERE. 31 bytes for the name, one for the count and one for the trailing blank. There also needs to be 33 bytes below pad for the minimal pictured numeric output for the signed output of $8000 in binary. That is a total of 66 bytes for the bare minimum pictured numeric output for this case. 85 bytes between HERE and PAD leaves an additional 19 bytes for a more elaborate pictured numeric output for this case.
Here is a log from a trace of pictured numeric output.
Code:
 OK
TRACE #S  OK
1.234.567.890 UD.
#           722 18838
2DUP      52501  1883
OR        52501  1883 52501  1883
0EXIT     52501  1883 53087
BRANCH    52501  1883
#         52501  1883
2DUP      24910   188
OR        24910   188 24910   188
0EXIT     24910   188 25086
BRANCH    24910   188
#         24910   188
2DUP      54919    18
OR        54919    18 54919    18
0EXIT     54919    18 54935
BRANCH    54919    18
#         54919    18
P?
BASE @ H. A
P?
HLD ? 32024
P?
CONT
2DUP      57920     1
OR        57920     1 57920     1
0EXIT     57920     1 57921
BRANCH    57920     1
#         57920     1
2DUP      12345     0
OR        12345     0 12345     0
0EXIT     12345     0 12345
BRANCH    12345     0
#         12345     0
2DUP       1234     0
OR         1234     0  1234     0
0EXIT      1234     0  1234
BRANCH     1234     0
#          1234     0
2DUP        123     0
OR          123     0   123     0
0EXIT       123     0   123
BRANCH      123     0
#           123     0
2DUP         12     0
OR           12     0    12     0
0EXIT        12     0    12
BRANCH       12     0
#            12     0
2DUP          1     0
OR            1     0     1     0
0EXIT         1     0     1
BRANCH        1     0
#             1     0
2DUP          0     0
OR            0     0     0     0
0EXIT         0     0     0 1234567890  OK
   OK
CONSOLE



Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 10, 2022 6:29 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
After some testing and a few memory dumps later, I have come to the conclusion that the max space between HERE and PAD need only be 24 bytes and has nothing to do with a word being defined, but has to do with the longest decimal number that can be entered. A word definition that is copied to HERE that is 25-31 characters is compiled separately and does not interfere with the numeric data area or PAD.

As for numeric expressions, the longest entered number is a 32-bit hex "FFFF 7FFF" or its decimal equivalent (-2147483648) which is only 11 characters for the decimal word. To print the decimal number requires it to be entered as a word to HERE, then NUMBER deciphers it. Then 13 characters at HERE (1 for the length byte and 1 for the space at the end of the word) and 11 for the numeric output only uses 24 characters.

If your Forth can handle 64-bit, then the largest 64-bit decimal number is -9223372036854780000 requires 22 + 20 = 42 space gap required at HERE. My Forth doesn't do that.

The only test I haven't done much with is building a numeric expression as the only example I have to go off of is the one at D.R. But for the most part, doing a DUMP of the memory at HERE definitely shows what is going on.

Attachment:
Forth numeric output.png
Forth numeric output.png [ 88.19 KiB | Viewed 586 times ]

On another note, during testing I found a bug in which a 32 character word will crash my FigForth.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 11, 2022 3:32 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
I wrote a better description for WORD for FigForth. Instead of it clearing 34 spaces after HERE every time, it just stores one space after the enclosing the word and copying it to HERE, whether it be a definition word or a number

Change from this:
Code:
* : WORD ( delimiterchar -- ) BLK @ IF BLK @ BLOCK ELSE TIB @ THEN IN @ +
SWAP ENCLOSE HERE CLIT [ 22 C, ] BLANKS IN +! OVER - >R R HERE C! + HERE 1+ R> CMOVE ;
to this:
Code:
: stream ( -- adr ) blk @ ?dup if block else tib @ then in @ + ;
: word stream swap enclose >R R > if R> ddrop ddrop 0 here ! else R in +! bl R> HERE + 1+ c! over - HERE C! + HERE count cmove then ;
This one also does some error checking if no word or number is copied to HERE but stores a zero instead. INTERPRET could then read the zero at HERE to see if there is a valid word or number at HERE and exit cleanly if not.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 21, 2022 11:22 pm 
Offline

Joined: Wed Aug 21, 2019 6:10 pm
Posts: 217
IamRob wrote:
I still haven't found the reason for the 68 byte gap between the DP and PAD. Can someone please enlighten me?


[1] The size of the region identified by Word shall be at least 33 characters.
[2] The size of the PNO string buffer shall be at least (2*n)+2 where n is the number of bits per cell (double number when BASE=2, plus . plus sign).

For a 16bit Forth, that is 34+33=67.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 22, 2022 1:16 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
BruceRMcF wrote:
IamRob wrote:
I still haven't found the reason for the 68 byte gap between the DP and PAD. Can someone please enlighten me?


[1] The size of the region identified by Word shall be at least 33 characters.
[2] The size of the PNO string buffer shall be at least (2*n)+2 where n is the number of bits per cell (double number when BASE=2, plus . plus sign).

For a 16bit Forth, that is 34+33=67.

You are close. 67 is almost 68. So I have to commend you for that.

But in what computer world does a bit equal 2 bytes? Even in binary, a 0 or 1, would still only need 1 byte per bit to make a printable character to screen. 32-bits + length byte + space char. But your example does give me some more testing ideas.

As for step [1], identifying a Word is still only done during compiling and will not conflict with any numerical expressions be done as they are only done during run-time. For me, allotting any space for a word during compiling is still redundant.

I am now convinced a minimum of 34 bytes are needed as a buffer between HERE and PAD for Forths that can print a 32-bit binary number and 66 bytes would be needed for Forths that can print a 64-bit binary number. A Forth that can print a binary number of 128 bits would need 130 bytes between HERE and PAD.

We are getting there. Some things are starting to make more sense.


Last edited by IamRob on Sat Jan 22, 2022 1:34 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 22, 2022 1:22 am 
Offline

Joined: Wed Aug 21, 2019 6:10 pm
Posts: 217
IamRob wrote:
BruceRMcF wrote:
IamRob wrote:
I still haven't found the reason for the 68 byte gap between the DP and PAD. Can someone please enlighten me?


[1] The size of the region identified by Word shall be at least 33 characters.
[2] The size of the PNO string buffer shall be at least (2*n)+2 where n is the number of bits per cell (double number when BASE=2, plus . plus sign).

For a 16bit Forth, that is 34+33=67.

You are close. 67 is almost 68. So I have to commend you for that.

But in what computer world does a bit equal 2 bytes?


It doesn't ... if you have a 16bit forth, than a double number in binary has 32bits, which can be 32 characters.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 22, 2022 1:35 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
BruceRMcF wrote:
It doesn't ... if you have a 16bit forth, than a double number in binary has 32bits, which can be 32 characters.

Yep, gotcha. You were talking printable double binary numbers.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 22, 2022 1:17 pm 
Offline

Joined: Wed Aug 21, 2019 6:10 pm
Posts: 217
IamRob wrote:
BruceRMcF wrote:
It doesn't ... if you have a 16bit forth, than a double number in binary has 32bits, which can be 32 characters.

Yep, gotcha. You were talking printable double binary numbers.


And WORD can be used in command line utility words as well as being used by the interpreter (as long as it's done with the text by the time the next word is interpreted), so the WORD buffer shouldn't overlap the PNO buffer. So allow two characters to be added to the pictured numeric buffer ( , $ . - etc.), the chars that WORD needs, there's the required space.

It's been a while since I programmed in fig Forth ... is the WORD count byte at HERE, or two bytes above HERE? If the WORD count byte is two chars above HERE, WORD might need 34 spaces (two plus count byte plus up to 31 chars).


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 22, 2022 6:45 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
BruceRMcF wrote:
IamRob wrote:
BruceRMcF wrote:
It doesn't ... if you have a 16bit forth, than a double number in binary has 32bits, which can be 32 characters.

Yep, gotcha. You were talking printable double binary numbers.


And WORD can be used in command line utility words as well as being used by the interpreter (as long as it's done with the text by the time the next word is interpreted), so the WORD buffer shouldn't overlap the PNO buffer. So allow two characters to be added to the pictured numeric buffer ( , $ . - etc.), the chars that WORD needs, there's the required space.

Thanks for bringing some new light to how Forth can be used. This is in uncharted territory for me.

But still looking from the perspective of creating a numeric string. The only words in FigForth that use the PNO buffer are (. D. D.R and ?), which use the <# #> constructs to form a numeric output in the PNO buffer. This is a closed command loop which means the numeric output is formed, closed and printed before moving on to interpreting the next word. And since the PNO buffer is no longer needed after the numeric print out, it should be available for use again even when the next word comes along for interpreting, whether by the interpreter or by a command line utility. Therefore, it still shouldn't be necessary to reserve that space for a WORD that is copied to HERE, since it would not harm anything if it over-lapped into the PNO buffer.

From what I can see, the only time that the PNO buffer would be used at the same time as any type of word interpretation is if something was being created between the <# #> constructs. D.R uses the TYPE command to immediately print the contents of the buffer, and like I have said before, I haven't done much with the numeric constructs to know if something might be created in the buffer, but held there for a later printing or handling of it, and then might possibly interfere with a word being interpreted.

I am still convinced, for the most part, that words being copied to HERE have nothing to do with the gap space between HERE and [b]PAD[/b], mostly because I have not seen any examples showing both areas used at the same time, where they might interfere with each other.

And I am still wondering if anyone came across any use case that might require a larger PNO buffer. Printing a double binary number is the largest use-case I have been shown so far at 34 bytes for a 16-bit printed double word (66 bytes for 32-bit dbl words and 130 bytes for 64-bit dbl words). FigForth is based on 16-bit, so all calculations are done with that in mind. I also mentioned one earlier where a newspaper prints the date line in long format, could be pretty long. I don't think I have ever seen any real-world examples where numeric output would need to span a full line of 64 characters, like a newspaper or book.

Are there any others?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 57 posts ]  Go to page Previous  1, 2, 3, 4  Next

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: