Thursday, August 18, 2022

πŸ†• πŸŽ‰Version 5.2.3 πŸ†• HZ# function πŸͺ²"Preprocessing Phase"

I follow a "release early, release often" release management philosophy, and a "small/incremental" change management philosophy for every new version of BASIC Anywhere Machine.

Although I've found upgrades of TiddlyWiki from one version to a newer one smooth no-brainers, I consider an upgrade of BASIC Anywhere Machine from one version of TiddlyWiki to a newer version as a noteworthy upgrade.

Changes to be found in today's new version of BASIC Anywhere Machine has the following worth:

  • Upgrade from TiddlyWiki 5.2.0 to TiddlyWiki 5.2.3
  • New Hz#(note$) function
    • This function takes a string represention of a musical note (a named note at a specified octave) and returns the matching frequency number
  • Improvements to BASIC Anywhere Machine's "Preprocessing Phase"

About BASIC Anywhere Machine TiddlyWiki upgrades.

On the rare occasion that an upgrade causes an issue, it can take a long time to discover the problem.  So just to play it safe, I will be keeping the previous version available in an archive.  I will continue archiving versions of BASIC Anywhere Machine (and the matching Programming Reference) whenever BAM undergoes any significant change.

About the version number scheme

All BASIC Anywhere Machine instances will have version numbers that match the TiddlyWiki version number.  The current version of BASIC Anywhere Machine will also include the date of the last edit made to that version of Anywhere Machine.

To find the version number of any version fo BASIC Anywhere Machine, click on BAM's "Help" menu, and click on the "About BASIC Anywhere Machine" menu item.  A first iteration of the feature in today's new version of BASIC Anywhere Machine:



About the HZ#(note$) function

I recently added a "_SNDWAVE" statement to set the sound wave pattern (sine, square, sawtooth, triangle) for all subsequent SOUND statements.  (Syntax:  SOUND frequency, duration)

After I posted a sound demo on reddit, "zxdunny" suggested consider an imrpovement: allow the option of specifying a note instead of a frequency.

Hence the HZ#(note$) function.

Instead of coding:
SOUND 587.33, 3

We can now code:
SOUND "D5",3
  • "D5" means the note D in octave 5

About the implementation of HZ#

I didn't feel like implementing the function in the interpreter (i.e write the javascript back-end for the function), and I decided to instead showcase BASIC Anywhere Machine's dynamic code generation features (TiddlyWiki's transclusion and "wikification" capabilities) that happen in the "preprocessing phase" or BASIC program execution.

(Bear with me: I'm still trying to figure out how to properly word all of this.)

Here's what I did:

First, I did was created a musical notes dictionary tiddler consisting of name-value pairs:  notes (concatenation of note name and note octave) and frequency values.  This is single-source multipurpose content which can be used to dynamically generate BASIC code in the preprocessing phase and to generate formatted documentation.

Next, I created a BASIC module that defines the HZ# function, but also has TiddlyWiki scripting to generate BASIC code.  The script uses as input the content of the musical notes dictionary tiddler, generating "SetLocalStorageItem()" lines of code to store each name-value pair in browser local storage.  When called, the HZ# function looks up frequencies for notes with GetLocalStorageItem().

To test everything out, I created the "Amazing Grace" program which plays a crude rendition of the melody:


About the "Preprocessing Phase" and Improvements

Preprocessing phase?  Macro/scripting process?

Not sure what to call it, but BASIC Anywhere Machine uses this "thing" in multiple places:
  • at run time to resolve all TiddlyWiki syntax, if any, and generate the BASIC program that will get merged with the HTML and wwwBASIC javascript code to run the program in an iframe
  • to view a BASIC program as it would appear after the preprocessing phase
  • to export a BASIC program from BASIC Anywhere Machine
    • as a .BAS file
    • as a .BAS.HTML file
    • as a .RUN.HTML file
Today's new version of BASIC Anywhere Machine attempts to fix a problem with the interpreter getting  confused about line positions (not BASIC line numbers, but rather the positions of code lines), reporting the wrong positions of coding errors when adding code to a BASIC program with the include metacommand.

Sunday, August 14, 2022

πŸ†• _RGB and _RGB32

_RGB and _RGB32 added for partial compatibility with QB64/QB64PE (i.e. make it quicker/easier to get QB64/QB64PE programs working in BASIC Anywhere Machine, and make it easier to create programs in BASIC Anywhere Machine intended for QB64/QB64PE.

In BASIC Anywhere Machine, _RGB and _RGB32 are 100% duplicates of each other.

_RGB

The _RGB function returns the LONG 32-bit color value (32-bit screens).

Syntax: returnValue = _RGB(red%, green%, blue%)

  • QB64: The _RGB function returns the closest palette attribute index (legacy SCREEN modes) OR the LONG 32-bit color value (32-bit screens).
  • BAM: The _RGB function returns the LONG 32-bit color value (32-bit screens).

_RGB32

The _RGB32 function returns the 32-bit RGB color value with specified red, green and blue component intensities.

Syntax: returnValue = _RGB32(red%, green%, blue%)

  • QB64: Has three additional syntax, and other parameters.


❇ COLOR: background parameter

In the original version of wwwBASIC (the BASIC interpreter used in BASIC Anywhere Machine), the background color parameter is ignored for all screen modes greater than zero.

This has been changed in BASIC Anywhere Machine: the background color parameter is applied in all screen modes.

About the COLOR statement

The COLOR statement is used to change the foreground and background colors for printing text.

Syntax:  COLOR foreground%, background%

  • both parameters,
  • or just the first,
  • or just the second (preceded by the comma)

foreground%An integer number code identifying the color of the text.
background%An integer number code identifying the color of the text background.

Friday, August 12, 2022

πŸ†• _SNDWAVE and _TOUCHDEVICE

_SNDWAVE

The _SNDWAVE statement sets the soundwave pattern for all subsequent sounds produced by the SOUND  and BEEP  statements.

Syntax: _SNDWAVE waveform

waveformA literal string, a string variable, or the result of a string expression. Can be any one of the following values: sine (system default)squaresawtoothtriangle.

 _TOUCHDEVICE

The _TOUCHDEVICE function returns, TRUE (-1) or FALSE (0), whether or not the user's device is a touchscreen device. The result of this function can be used to decide how to get input from the user:

  • if the user has a physical keyboard, the program can get keyboard input from either or both of:
    • The Console Keyboard Input Functions 
    • The "Popup Box" Functions 
  • if the user has a touchscreen keyboard, the progam can get "virtual keyboard" input from:
    • The "Popup Box" Functions 
  • (touching the console window has the same effect as mouse-clicks)

Syntax: _TOUCHDEVICE

Return value: TRUE (-1) or FALSE (0)


SOUND TESTER:



πŸ“š FUNCTION (and SUB): variable arguments, by default, are "passed by reference"

Preamble A primer on "call-by-reference" vs "call-by-value" BAM HOWTO (BTW:  "call-by-reference" aka "pas...