What came out of the zoom meeting about TAQOZ was the need for simple code examples that anyone can try and then learn from. TAQOZ is an amazing "tool" that anyone can access on their P2 because it is already built into the ROM and very useful for sanity checking hardware but also very useful for rapid prototyping of code without any kind of IDE or external tools, although I recommend Visual Studio Code as an excellent code editor from which I also run minicom as my serial terminal emulator within one of its terminal windows.
What I'd like to do with this thread is to continue with a new code snippet each day and depending upon feedback find out what I can write about in some ongoing online tutorials.
One of the simple things I was showing was a one-liner, that is all the code fits onto one line and executes immediately when you hit enter. These are useful for quick tests.
Then I took one line and defined a new word to be added to the Forth dictionary. Normally any word you type in a Forth command line is delimited by spaces or tabs or CR and Forth will search its dictionary for an exact match which if found will normally then execute the code associated with that dictionary entry. If it doesn't find a match it then tries to convert it to a number if possible and if so, it then pushes that number onto the top of the data stack. All parameters and pointers and results are passed back and forth by means of the data stack.
Anyway, I called this word DEMO which when typed or implicitly called from any other code, will run its code and return. Here is that code except I call it NOTES and instead of embedding the pin number for audio output, I allow that to be passed via the stack:
pub NOTES ( pin -- ) PIN 3000 100 DO I HZ 50 ms 100 +LOOP MUTE ;
Now I have an amplified speaker connected to P6 and P7 so that when I type 6 NOTES<CR> it produces a series of gliding notes starting at 100Hz, holding it for 50 ms before stepping up another 100Hz until it reaches the limit of 3000 where it then exits the loop and in this case MUTEs the audio output.
You can try this in the TAQOZ ROM, just connect any serial terminal at any baud rate, typically 115200 baud, type the two character auto-baud sequence " > space " followed by an escape to enter TAQOZ in ROM. (The P2 goes to sleep after a few minutes if it doesn't boot anything, so you might have to press the reset again to wake it up).
This is what I see:
Parallax P2 .:.:--TAQOZ--:.:. V1.1--v33h 190219-1900
Hit the enter key and TAQOZ will respond with "--- ok" and reprompt on a new line (CR+LF). This simply indicates TAQOZ is responding to your input.
Now copy and paste the NOTES line of code shown above and perhaps hit enter if necessary and then you will see the "--- ok" response. If you have a speaker or transducer connected to P6 then type "6 NOTES" and you will hear the gliding tone.
Perhaps it said "6NOTES ???" which means there is no such word in the dictionary. Make sure you have at least one space between the 6 and NOTES.
Still didn't work?
If it says "NOTES ???" then it is quite possible that you made a mistake typing in NOTES if you didn't paste it, or that TAQOZ has been reset since and lost it.
If you want to save this for next time you boot up then type BACKUP which will backup the whole TAQOZ image into Flash. Although TAQOZ in ROM is not designed to automatically boot, you can restore the Flash image once you are back into TAQOZ using RESTORE or simply a ^R (control R) which also restarts TAQOZ from this restored image. Btw, the image is saved in the $F.0000 area of the Flash chip as a 64kB binary.
HOW DOES IT WORK:
( Edit - I just made this code copy&pastable by adding --- comment directives )
pub NOTES --- Create a new public word called NOTES, and start compiling the following code
( pin -- ) --- ( is a comment up to the matching ), in this case a stack effects comment
--- with "pin" as value on the stack when entering, without returning any results.
PIN --- Latches the value supplied as the destination for any further PIN type operations.
3000 --- Not a word, but recognized as the number 3000 which is pushed onto the stack
100 --- The number 100 is pushed onto the stack over the top of the 3000
DO --- Marks the beginning of a loop and takes a starting index (100) and a stop limit (3000)
I --- Returns the value of the current Index starting from 100 (on top of the stack)
HZ --- HZ takes the value from the stack and sets the current PIN to output a matching NCO frequency
50 --- 50
ms --- will delay 50ms before continuing, long enough to hear a distinct note.
100 --- the Hz value we want to step up each time through the loop (100Hz)
+LOOP --- Increment the index by the value supplied and loop again until the limit is reached
MUTE --- Now to stop that infernal racket, MUTE will simply reset the smartpin function of the pin
; --- Exit and return (also completes this word when it is first being created)
You can also do exactly the same with TAQOZ RELOADED, the version that you can boot from on SD or load serially. Also, don't forget I have lots and lots of wiki pages talking about all things TAQOZ and Tachyon and P2 and P1 on my SourceForge site.
EXTRA: If you are using TAQOZ RELOADED and want NOTES to automatically execute on power-up/reset then simply change NOTES to include the pin number before PIN such as "6 PIN" etc and type "AUTO NOTES" and then "BACKUP BIX" to save your TAQOZ image back to the SD card.
MORE FUN: Here are two simple classic arcade sound effects that you can even build into a game.
pub ZAP ( use PIN ) 3000 100 DO I HZ 15 I 300 / - ms 200 +LOOP MUTE ;
pub SAUCER ( use PIN ) 10 FOR 600 Hz 50 ms 580 Hz 50 ms NEXT MUTE ;
Remember to set the PIN once beforehand and you can even have repeat ZAPs:
pub ZAPS ( cnt -- ) FOR ZAP 50 ms NEXT ;