Jump to content

fbForth—TI Forth with File-based Block I/O [Post #1 UPDATED: 06/09/2023]

Lee Stewart

Recommended Posts

13 hours ago, Lee Stewart said:


I wasted (I think) 8 bytes of bank#2 (where resides the code for COLD ) to also re-initialize R13 and R14 of SNDWS to 0, just in case. The reason I say, “wasted”, is that every time the sound queue is finished, both indices are the same. They may not be 0, but as long as they both point to the same place in the circular queue, I should only need to insure that the queue is all zeros. It is definitely safer, but I don’t think necessary. So far, I can afford the space, so I guess I should keep it—for now, at least.



You are correct that it is not necessary to initialize the queue. I have built RS232 communication queues using this method and they seem to run forever with no reset.

I remember reading in some textbook somewhere that it is tricky to tell how many items are in the queue with just the head/tail pointers but you can always tell if the queue is empty.

It's when the tail=head. 

So you should be able  do compare on R13,R14  on the ISR read side, to determine if there is something waiting. That gives you a quick ISR response when things are empty.

That's what I have done in the past. I will try and find that old text book see if there are any more tricks I have forgotten.

  • Like 1
Link to comment
Share on other sites

I found the text.  "Data Structures and Algorithms, Aho, Hopcroft, Ullman, 1983 Bell Telephone Labs. Inc"


The test for Empty queue in Pascal looks like this in the book.

function EMPTY (Q:QUEUE) : boolean 
	  if (Q.front=Q.rear then 
	end. { EMPTY }


It talks about the confusion of telling the difference between a full queue and an empty queue. One solution given is to never let the queue fill up.

The other is to provide a "bit" to indicate when the queue is full. I have done that in the past with a counter rather than a bit. 

And as you have done you can just ignore it and let the data overwrite. I have done that in most of my real world uses. 


It's fun to translate that function EMPTY to Forth, :) 


: EMPTY?    ( -- ?) Q.front @  Q.rear @ = ; 


If the entire program takes that much more source code which one should be easier to maintain? 🤔

  • Like 2
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.

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.

  • Recently Browsing   0 members

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