Saturday, June 3, 2023

🚧 In the works

New "View Code Issues" functionality

Details in this independent post: 

🚧 In the works: Code Issues Notification and Viewing


UrlQueryString$ function

This function returns the URL query string.

When a BAM program is exported as a stand-alone program, the URL to that HTML file can have a query string, providing us a way to pass any number of values to the BASIC program.

This is similar to command line parameters passed to an EXE.

This could also be a way of passing data to a BASIC program, via a URL to that program dynamically generated by something that wants to pass along data to the BASIC program.

Here's a sample program that shows and processes the query string:

PRINT "URL Query String: " + UrlQueryString$

 

UrlKey$ function

This is an include function (i.e. not built-into the interpreter, but rather a BASIC function meant to be included in programs if/when needed.)

Like this:

<<include "UrlKey$">>

The function as is currently implemented:

FUNCTION UrlKey$(key$)
  UrlKey$ = ""
  keyPos% = INSTR(ucase$(UrlQueryString$),{ucase$(key$) + "="})
  IF keyPos% THEN
    step1$ = RIGHT$(UrlQueryString$, LEN( UrlQueryString$ ) - keyPos% - LEN(key$) )
    step2% = INSTR(step1$, "&")
    UrlKey$ = IFF( step2%, LEFT$(step1$, step2% - 1 ), step1$)
  END IF
END FUNCTION


IFF function

Before IFF sample code:

FUNCTION GetUrlKey$(key$)
  GetUrlKey$=""
  keyPos%=INSTR(ucase$(UrlQueryString$),{ucase$(key$) + "="})
  IF keyPos% THEN
    step1$ = RIGHT$(UrlQueryString$, LEN( UrlQueryString$ ) - keyPos% - LEN(key$) )
    step2% = INSTR(step1$, "&")
    IF step2% THEN GetUrlKey$=LEFT$(step1$, step2% - 1 ) ELSE GetUrlKey$=step1$
  END IF
END FUNCTION

After IFF sample code:

FUNCTION GetUrlKey$(key$)
  GetUrlKey$ = ""
  keyPos% = INSTR(ucase$(UrlQueryString$),{ucase$(key$) + "="})
  IF keyPos% THEN
    step1$ = RIGHT$(UrlQueryString$, LEN( UrlQueryString$ ) - keyPos% - LEN(key$) )
    step2% = INSTR(step1$, "&")
    GetUrlKey$ = IFF( step2%, LEFT$(step1$, step2% - 1 ), step1$)
  END IF
END FUNCTION

Heads-up !!!  All three expressions in the function will all be evaluated every time that IFF function is executed.  So this function could be a performance hit (especially in a loop) if either or both TRUE and FALSE expressions are complex.  Best for these to be literals, constants, variables, or functions/expressions that are not complex (i.e. simple and quick to resolve.)  When dealing with complex expressions, better to go the traditional IF-THEN-ELSE route.

MIN and MAX functions

returnValue = MIN( expression1, expression2)
returnValue = MAX( expression1, expression2)

BIN$ function

BAM already had this function implemented as _BIN$ for compatibility with QB64/QB64pe.

Now:  if compatibility with QB64/QB64pe is not a concern, use either one you prefer.  Eventually, BIN$ will differ by having an optional second parameter: width.

DAY$ function

Returns the current day of the week in abbreviated form (SUN, MON, TUE, WED, THU, FRI, SAT)


DIV Operator

Integer division (an alternative to the already existing "\").

Whereas MOD returns the remainder after dividing two numbers, DIV returns the quotient after dividing two numbers.

FRAC function

returnValue = FRAC( numericExpression )

FRAC returns the fractional part of a number.


BETWEEN function

returnValue = BETWEEN( CheckedValue, MinValue, MaxValue)

CheckedValue, MinValue, and MaxValue can be any kind of expression that results in any one of the primitive data types (a string or any of the numeric data types).

If the CheckedValue is between MinValue and MaxValue, or equal to either MinValue or MaxValue, then BETWEEN returns -1 (i.e. TRUE);  Otherwise, BETWEEN returns 0 (i.e. FALSE).


CHOOSE function

returnValue = CHOOSE( ChoiceIndex%, ResultExpression1, ResultExpression2 [, ...])

  • ChoiceIndex% is any kind of expression that results in any integer inclusively between 1 and the number of ResultExpression* parameters specified; if the expression results in an invalid number, the CHOOSE function will return nothing (0 assigned to a numeric variable, empty string to a string variable)


DEFtype Statements: Improved Compatibility

BAM's syntax for the DEFtype statements, as per original wwwBASIC  code:

DEFtype letter - letter [, letter - letter]

Unlike classic BASIC implementations, BAM did not allow single letters, allowing only letter ranges.

Now, BAM allows letter ranges and single letters, and a mixture of those declarations in one statement.

So for all DEFtype statements, the syntax:

DEFtype letterExpression [, letterExpression]

  • type is one of the following: DBL, INT, LNG, SNG, STR
  • letterExpression can be one of:
    • a single letter
    • a letter range consisting of two letters separated by a dash (i.e. a minus sign)
      • startingLetter - endingLetter
      • the range is inclusive
    • this parameter is required
  •  [, letterExpression]
    • the square brackets says that more letterExpressions are optional: there can be none, one, or many. added after the first DEFtype parameter
    • each occurrence must be preceded by a comma


Improvements to BIN$, _BIN$, HEX$, OCT$

All were mishandling non-integer numbers.  Now, all functions round numbers to integers before converting those to the other numeric system.

HEX$ and OCT$ were not converting negative numbers to negative number representations of the other systems.  BAM was effectively stripping the negative sign, converting the number, and then adding the sign as a prefix to the number.  The functions in the new version of BAM returns converted numbers the same way as GW-BASIC and QB64.


SLEEP Improvement

The SLEEP statement now allows for no parameter.  When no parameter is provided, the  program will pause until a keyboard key is pressed.

For QBASIC compatibility: if the parameter = 0, that will also cause the program to pause until a keyboard key is pressed. 

 

INSTR Improvement

Previously allowed only two parameters.  Now allows two or three parameters.

Syntax Options:

INSTR(baseString$, searchString$)
INSTR(start%, baseString$, searchString$)


WIDTH improvement

Fixed issue with console window not being quite right after WIDTH and until the browser window gets resized.

Also, a note: the WIDTH statement effectively changes the width of the console not only for text, but for graphics too.  So WIDTH(numberOfColumns%) sets the width of the console to numberOfColumns% * 8.


RANDOMIZE compatibility improvement

BAM previously required a parameter for the RANDOMIZE statement.  Now, BAM also accepts the RANDOMIZE statement without a parameter.

Although BAM ignores the RANDOMIZE statement (BAM's RND function does not need to be seeded), BAM does recognise and validate the statement for compatibility with other BASIC implementations.

Typically, when RANDOMIZE has no parameter, the program will pause and ask for a value.  BAM skips this.  

HEIGHT statement

Since seemingly forever BASIC has had the WIDTH statement to set the number of character columns on a screen, why not have a statement to specify the number of character rows?


PUTSTRING statement

The statement places a string on the screen at the specified x and y pixel coordinates.


INTEGER data type

"INTEGER" was previously treated by BASIC Anywhere Machine as equivalent to a LONG integer.

"DEFINT" defines variables that begin with a specified letter as SHORT integer.

To be consistent with DEFINT, and to be consistent/compatible with GW-BASIC, QBASIC, and QB64, "INTEGER" has been changed to be treated as equivalent to  SHORT integer.


SCROLL statement

Scroll the entire screen, or part of the screen either vertically, horizontally, or both.

 

Documentation: Adding Syntax Diagrams






Saturday, May 6, 2023

✏ _MOUSEBUTTON and GETMOUSE

For both functions, "1" would be returned to indicate that a mouse button is pressed.

Now, both functions return "-1" (i.e. the system constant TRUE) to indicate that a mouse button is pressed.

Unchanged: a "0" (i.e. the system constant FALSE) is returned to indicate that a mouse button is NOT pressed.

In any previously created BAM programs, you will need to change things like "IF _MOUSEBUTTON = 1" to one of:

  • "IF _MOUSEBUTTON = TRUE"
  • "IF _MOUSEBUTTON = -1"
  • "IF _MOUSEBUTTON"

Thursday, April 27, 2023

🆕 _GETCHR$ to get a string representation of the 8x8 pixels for the character assigned to an ascii code

 The _GETCHR$ function does the reverse of the recently added _LETCHR$ statement.

Checkout a sample application:


The _GETCHR$ statement returns the string representation of the 8x8 pixel definition for a character that matches the specified ascii code.

Syntax

_GETCHR$( ASCII_code%)

  • return value: a 64-character string representing 8x8 pixels
    • an "X" represents an "on" pixel
    • a "." represents an "off" pixel

  • ASCII_code%
    • An integer number that represents an ASCII character.
    • As simple as a literal number, a constant/variable number, or a numeric expression of any complexity.
  • characterTemplate$

Wednesday, April 26, 2023

💩 Oh poop. Screen mode changes done 3 months ago.

About three months ago, I made changes to BASIC Anywhere Machine's screen modes, rolling out the update and completely forgetting to make any kind of heads-up announcement about it.

And I forgot to update a whole bunch of programs to use the new screen modes.

Surprise?

The previous screen modes were the as-is screen modes as implemented in wwwBASIC (as found on Github Dec 27, 2020.  I wanted something more to my liking, so I adjusted them to the ones described in this post.

You can still access the last version of BASIC Anywhere Machine with the old screen modes here (and the documentation for that version here.)

You can compare with the current version of BASIC Anywhere Machine here (and the current version of the documentation here.)  If you had noticed any programs not working: I updated these programs in BASIC Anywhere Machine yesterday to use the new screen modes.  (list of those further down below.)

Also, for your convenience, you can compare the previous screen modes (info below) to the current screen modes in this post.


ModeScreen
Width
Screen
Height
ColumnsRowsScreen
Aspect
Font
Height
Colour
Scheme
Bits
Per
Pixel

064020080252.48rgba4
Alternative width: 40(See the  statement)
132020040251.28screen12
264020080252.48monochrome1
732020040251.28rgba4
64020080252.48rgba4
6403508025480/35014rgba4
6403508025480/35014monochrome2
116404808030116monochrome2
126404808030116rgba4
13320200251.28undefined24
1432024015116undefined24
1540030018116undefined24
1651238424116undefined24
1764040080251.216undefined24
186404808030116undefined24
1980060010037116undefined24
20102476812848116undefined24
211280102416064116undefined24

List of programs updated with new screen modes (or simply checked to make sure they still work correctly):

2023-04-25
  • Barnsley Fern (Fractal)
  • Based on PRINT CHR$(205.5+RND(1)); : GOTO 10
  • Bouncing Circle and Square Screen Painter
  • BouncingBall
  • BouncingBall 2
  • Bubble Universe
  • CALCULATOR
  • Cannoneer
  • Catch 88
  • Chaotic Scatter
  • CIRCLE to Draw Pie Charts
  • Curve Stitching in a Circle
  • Cute 40-line-ish game
  • Cute 50-line-ish game
  • donkey.bas
  • Easy Spiral
  • Ever-Changing Mandala II (less CPU intensive)
  • File Open, Print, Close Tester
  • Flower Wheel
  • LINE remembers the last pen position
  • Mouse testing 1
  • Munching Squares
  • Pendulum
  • Rotating Lorenz Attractor
  • Semi-random PSET art
  • Ski Slope Challenge (Charlie's Version)
  • Snowflake
  • Sound Tester
  • Spheres
  • Tank
  • Tester: _DISPLAY and _AUTODISPLAY
  • Tester: DRAW commands A and TA
  • Tester: Logical Operators
  • Tester: PRINT, WRITE, PRINT#, WRITE#, OPEN, CLOSE
  • Tester: Screen Scrolling (Mirage Maker?)
  • Wumpus
  • Yahtzee

2023-04-24
  • Akalabeth
  • Akalabeth (BAM!)
  • Archimedean spiral
  • ASCII Character Set
  • Background Generator
  • Box Color Varied
  • circles
  • Conway's Game of Life
  • Diagonals on SCREEN 2
  • draw graphics test
  • DrawSquare
  • Easter Egg Decorating
  • Easter Egg Decorating 2
  • Ever-Changing Mandala
  • Fedora Hat
  • FLIPPER
  • Fractal Tree
  • GW-BASIC (Amiga) Get + Put Sample
  • GW-BASIC-3D
  • Hailstone sequence
  • Hello World Horizontal Marquis
  • INSTR tester
  • Julia set (GW-BASIC)
  • Julia set (Locomotive)
  • Julia set (QBasic)
  • line graphics test
  • lines.bas
  • Mandelbrot set
  • Mesmerizer 1
  • MID$ (statement) tester
  • mishka's clock
  • Polar Grapher.bas
  • Put - Get
  • PUT color action sample
  • PUT color action sample II
  • Qb64 Draw Example
  • Regeya's CIRCLES
  • Rotating Circle
  • Rotating Pyramid
  • Simple Animation XOR test
  • SimpleRandomHillsMaker
  • Sine Art 1
  • Spinny Cube
  • Summation of primes
  • Sunshine
  • Tester _width _height
  • Tester DRAW

Tuesday, April 25, 2023

📚 The SCREEN modes

ModeWidth
X Height
(Pixels)
Columns
X Rows
(Characters)
Screen
Aspect
Font
Height
Colour
Mode
Bits
Per
Pixel
0640 X 20080 X 252.48p164
1320 X 20040 X 251.28p42
2640 X 20080 X 252.48p21
7320 X 20040 X 251.28p164
8640 X 20080 X 252.48p164
9640 X 35080 X 25480/35014p164
10640 X 35080 X 25480/35014p21
11640 X 48080 X 30116p21
12640 X 48080 X 30116p164
13320 X 20040 X 251.28p2568
14320 X 20040 X 2518p2568
15320 X 20040 X 252.48p2568
16320 X 20040 X 251.216p2568
17320 X 20040 X 25116p2568
23640 X 40080 X 251.28pRGB24
24640 X 40080 X 2518pRGB24
25640 X 40080 X 252.48pRGB24
26640 X 40080 X 251.216pRGB24
27640 X 40080 X 25116pRGB24
ModeNumber
of
Colour
Attributes
Bits
Per
Pixel
p221
p442
p16164
p25625616
pRGBundefined24
  • Note: p2, p4, p16 and p256: references to colour attributes allow "Colour attribute looping".

About Colour Attribute Looping

In BASIC Anywhere Machine, when working with colour modes that have colour attributes, we normally refer to those attributes as attributes zero to whatever maximum for that colour mode. (For example, attributes 0 to 15 in colour mode p16.)

When we refer to attributes with numbers outside of the range, BASIC Anywhere Machine loops around (treating the list of attributes like a circle.) So in colour mode p16, attribute 16 means attribute 0, and attribute 17 means attribute 1.

The same works in the other direction. In colour mode p16, attribute -1 means attribute 15, and attribute -2 means attribute 14.

The following statements and functions have been tested to make sure that works:

  • COLOR
  • CIRCLE
  • LINE
  • PAING
  • PSET

Monday, April 24, 2023

🆕 _LETCHR$ to redefine 8x8 characters assigned to ascii codes

 The _LETCHR$ statement redefines the 8x8 character assigned to an ASCII code.

Syntax

_LETCHR$( ASCII_code%, characterTemplate$ )

  • ASCII_code%
    • An integer number that represents an ASCII character.
    • As simple as a literal number, a constant/variable number, or a numeric expression of any complexity.
  • characterTemplate$
    • A 64-character string that represents the "on" pixels of an 8x8 character
      • any "X" (must be uppercase) represents an "on" pixel
      • any other characters in the string represent "off" pixels
    • As simple as a literal string, a constant/variable number, or a numeric expression of any complexity.




A chess piece "knight" ?
A chess piece "knight" ?



🖥 Circular Sinusoidal Waves with DRAW and SIN

Run the program View the source code