GDMike Posted February 18, 2022 Author Share Posted February 18, 2022 On 2/16/2022 at 8:09 PM, TheBF said: And I am a Fox.? But that's just plain cheating. Quote Link to comment Share on other sites More sharing options...
HOME AUTOMATION Posted February 18, 2022 Share Posted February 18, 2022 ? 1 1 Quote Link to comment Share on other sites More sharing options...
GDMike Posted February 18, 2022 Author Share Posted February 18, 2022 (edited) 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 February 18, 2022 by GDMike Quote Link to comment Share on other sites More sharing options...
Willsy Posted February 18, 2022 Share Posted February 18, 2022 (edited) 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. (99 is 63 in hex ) Edited February 18, 2022 by Willsy typos 4 Quote Link to comment Share on other sites More sharing options...
Willsy Posted February 18, 2022 Share Posted February 18, 2022 (edited) 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: Read this article, it'll help you: Arrays for TurboForth Edited February 18, 2022 by Willsy 4 Quote Link to comment Share on other sites More sharing options...
+TheBF Posted February 18, 2022 Share Posted February 18, 2022 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) _________________________________ 3 Quote Link to comment Share on other sites More sharing options...
GDMike Posted February 18, 2022 Author Share Posted February 18, 2022 (edited) 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 February 18, 2022 by GDMike Quote Link to comment Share on other sites More sharing options...
Willsy Posted February 18, 2022 Share Posted February 18, 2022 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. 3 Quote Link to comment Share on other sites More sharing options...
+TheBF Posted February 19, 2022 Share Posted February 19, 2022 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. 1 Quote Link to comment Share on other sites More sharing options...
GDMike Posted February 19, 2022 Author Share Posted February 19, 2022 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 Quote Link to comment Share on other sites More sharing options...
GDMike Posted February 19, 2022 Author Share Posted February 19, 2022 (edited) 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 February 19, 2022 by GDMike Quote Link to comment Share on other sites More sharing options...
+Lee Stewart Posted February 19, 2022 Share Posted February 19, 2022 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 3 Quote Link to comment Share on other sites More sharing options...
Willsy Posted February 19, 2022 Share Posted February 19, 2022 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! Mark 1 Quote Link to comment Share on other sites More sharing options...
GDMike Posted February 19, 2022 Author Share Posted February 19, 2022 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. Quote Link to comment Share on other sites More sharing options...
+TheBF Posted February 19, 2022 Share Posted February 19, 2022 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! 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 + ; 4 Quote Link to comment Share on other sites More sharing options...
Willsy Posted February 19, 2022 Share Posted February 19, 2022 ooh! Lovely stuff! Smooth like butter. Totally readable. I like it! It feels great to be doing a bit of Forth again! 2 1 Quote Link to comment Share on other sites More sharing options...
Willsy Posted February 19, 2022 Share Posted February 19, 2022 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 ; DUMP is on block 36 of the TF boot disk. Very useful for looking 'inside' memory to see what the hell is going on! 3 1 Quote Link to comment Share on other sites More sharing options...
GDMike Posted February 19, 2022 Author Share Posted February 19, 2022 (edited) 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 February 19, 2022 by GDMike Quote Link to comment Share on other sites More sharing options...
GDMike Posted February 19, 2022 Author Share Posted February 19, 2022 I'm supposed to be sleeping to prepare for my 12 hour workdays, but I find myself wide awake peeking at forth code. Hmm I've got a Forth problem and my name is Mike. 2 1 Quote Link to comment Share on other sites More sharing options...
+Lee Stewart Posted February 19, 2022 Share Posted February 19, 2022 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 TurboForth—TurboForth 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 4 Quote Link to comment Share on other sites More sharing options...
GDMike Posted February 19, 2022 Author Share Posted February 19, 2022 2 hours ago, Lee Stewart said: ' (“tick”) finds the pfa of a word in fbForth, but its cfa in TurboForth—TurboForth 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 Quote Link to comment Share on other sites More sharing options...
GDMike Posted February 22, 2022 Author Share Posted February 22, 2022 Well books came in. Hopefully my 18yo will take a gander at one sometime. But nice to add to my collection. 2 Quote Link to comment Share on other sites More sharing options...
Willsy Posted February 24, 2022 Share Posted February 24, 2022 Starting Forth is a truly brilliant book. A lot of the code in there will run in TF. 3 Quote Link to comment Share on other sites More sharing options...
+Lee Stewart Posted February 24, 2022 Share Posted February 24, 2022 The first edition of Starting FORTH goes pretty well with fbForth (differences are in an appendix of my manual), but the second edition (brought in line with Forth-83) goes better with TurboForth. ...lee 5 Quote Link to comment Share on other sites More sharing options...
Bill R Sullivan Posted February 24, 2022 Share Posted February 24, 2022 6 hours ago, Lee Stewart said: The first edition of Starting FORTH goes pretty well with fbForth (differences are in an appendix of my manual), but the second edition (brought in line with Forth-83) goes better with TurboForth. ...lee Once again Lee is RIGHT on target. 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.