Tuesday, November 29, 2022

🆕 _AUDIODONE and 🆕 _ENDAUDIO

 Check out the latest version of the BASIC Anywhere Machine "Amazing Grace" program:

BTW: at the end of the song, or after you stop the song, you'll have the option to play the song again.  Choose "Y", and then you can alter the tempo of the song and the waveform applied to the sounds.

_AUDIODONE

Description:

The _AUDIODONE function returns -1 (TRUE) if there are no sounds left to play in the sound queue, and returns 0 (FALSE) otherwise.

Syntax

_AUDIODONE


_ENDAUDIO

Description:

The _ENDAUDIO statement flushes the sound queue in order to stop playing currently queued sounds. There may be a few sounds in the queue that have gone past the point of no return, so there may be a slight delay before all sounds stop playing.

Syntax

_ENDAUDIO

Monday, November 28, 2022

🪲 Subroutine invocation without the CALL statement : NOW IT REALLY WORKS !!!

In an earlier post,  I describe undoing a problem I introduced into wwwBASIC.  I had broken wwwBASIC's ability to handle subroutine invocation without using the CALL statement.

Just when I got it working again, I discover that wwwBASIC's code for handling subroutine invocations without the use of CALL is broken: if the subroutine has more than one parameter, none of the parameters beyond the first one actually get passed to the subroutine.

Now, BAM's embedded version of wwwBASIC can handle subroutine invocations without CALL just as well as subroutine invocations with CALL.

Sample code used to discover the issue:

sub hey(a$, d%, c$)

    print "a$: " + a$

    print "d%: " + d%

    print "c$: " + c$

end sub

 

call hey("howdy", 5, "later") ' this works no problem

hey("hello", 6, "bye-bye")    ' this, all parameters except the first are "lost"

Before today's fix, the subroutine invocation without CALL would only pass a value for the first parameter, and ignore all parameters beyond the first one.


❇ HZ# function, all notes for all octaves are now setup and 🆕 documented

You'll find a "Musical Pitch Notes and Frequencies Matrix" in both BASIC Anywhere Machine and in the Programming Reference.

In BASIC Anywhere Machine: look for the "Lookups" menu item in the "Tools" menu.

In the Programming Reference: lookup "HZ#" in the keywords reference, and you'll find the matrix in that page.

For a quick peek, click on this link to view the HZ# documentation in "Wiki" mode.

Sunday, November 27, 2022

🆕 _INITAUDIO and 🆕 _FINISHAUDIO and ❇ SOUND

The SOUND statement was previously totally synchronous (i.e the sound had to finish before the program would process any subsequent statements.)  This behaviour is now very different.  (see further below for how SOUND now behaves.)

Also, please refer to the Amazing Grace sample program (it uses all of these statements):


Documentation about _INITAUDIO, _FINISHAUDIO, and SOUND (it kind of ties everything together:

_INITAUDIO

Description:

The _INITAUDIO statement initialises the web audio api for subsequent calls to  and  statements.

Syntax

_INITAUDIO


_FINISHAUDIO

Description:

The _FINISHAUDIO statement delays further execution of the program (including end of the program) until all queued sounds have played. See the  statement for more info.

Syntax

_FINISHAUDIO


SOUND

Description:

SOUND plays a sound of a specified frequency for the specified duration (measured in "ticks").

  • NOTES
    • Sounds in a BASIC Anywhere Machine program will not happen unless the program console window has the "focus"
      • Program Execution Properties: Remove the checkbox on "Autostart this program?"
        • The program will not commence until the user clicks on the program console window
      • Recommended: consider calling the  statement at the beginning of your program
        • This will initialize (a one second delay) the web audio api such that the first instance of SOUND will sound correctly
    • Synchronous and asynchronous behaviour of the SOUND statement
      • A SOUND statement, vis-à-vis other statements in the program flow, is asynchronous: after a program executes a SOUND statement, the program does not wait for completion of the SOUND statement before executing the statements after the SOUND statement
      • A SOUND statement, vis-à-vis other SOUND statements in the program flow, is synchronous: if a previous SOUND statement is still being played, the current SOUND statement will wait for the previous SOUND statement to finish; all SOUND statements go into a queue, and each sound will only happen after the previous sound is done playing
      • Because sounds are asynchronous vis-à-vis the rest of a program, it is very possible for a program to end before all of the sounds in a sound queue are processed. If we want the sound queue to finish playing before program end (or before further program execution), call the  statement
    • To alter the waveform of sound, call the _SNDWAVE statement.

SOUND 0,0 will end any on-going sound.

Syntax

SOUND frequency!, ticks!







Saturday, November 26, 2022

🪲 Subroutine invocation without the CALL statement

I added some code to wwwBASIC very early this year to overcome a problem in wwwBASIC, and wound up unwittingly breaking wwwBASIC's code that allows a subroutine to be invoked without using the CALL statement.

It took some digging to figure out that wwwBASIC does some token readjustments when a subroutine is invoked without the CALL statement.

Without getting into the weeds, here are the (now working again) options for invoking a subroutine:

Branch to Subroutine Syntax

With CALL

With parameters:

CALL subroutine_name( expr , expr🔁 )

Without parameters:

CALL subroutine_name

Without CALL

With parameters:

subroutine_name( expr , expr🔁 )

Without parameters:

subroutine_name


Friday, November 25, 2022

❇ PSET and ❇ PRESET

 Added the STEP keyword as an option for both statements.

The PSET graphics SCREEN statement sets a pixel at a specified coordinate to a specified color attribute, or the current foreground color if a color attribute is not specified. When the STEP keyword is included, then PSET sets a pixel at a coordinate that is relative to the most recently referenced point.

PSET (column%, row%)[, colorAttribute]

PSET STEP (column%, row%)[, colorAttribute]


The PRESET graphics SCREEN statement sets a pixel at a specified coordinate to a specified color attribute, or the current background color if a color attribute is not specified. When the STEP keyword is included, then PRESET sets a pixel at a coordinate that is relative to the most recently referenced point.

PRESET (column%, row%)[, colorAttribute]

PRESET STEP (column%, row%)[, colorAttribute]



❇ READ

The READ statement did not give any error message when trying to read beyond the available DATA values.

Now, a program will report an error when a program tries to read beyond the available values.

🖥 Swirling Circles

This strange animation is the result of me wondering: What if I drew circles at each end of a piston, and that piston moved up and down a fi...