Skip to content

BASIC Variable and Memory Statements and Functions

Curtis F Kaylor edited this page Jan 26, 2025 · 7 revisions

CLEAR

TYPE: BASIC memory statement


FORMAT: CLEAR

Action: Clears BASIC workspace.

  • All simple variable and array definitions are discarded, freeing the variable space.
  • The machine stack is reset, clearing all FOR loops and active GOSUBs.
  • All string string refences are discarding, freeing string space.
  • ON ERROR error traps are cleared and ERR and ERRLINE are set to 0.
  • The BASIC program is preserved.

FORMAT: CLEAR integer

Action: As above but sets the amount of string space.

  • integer is the new size of string space bytes.
  • The default string space size is 1024 bytes.

FORMAT: CLEAR integer , address

Action: As above but sets the top of BASIC memory

  • The end of BASIC memory is set to 1 less than address.
  • The default top of memory is address 49152.

plusBASIC v0.22v enhancement

TYPE: plusBASIC system statement

FORMAT: CLEAR array_list

Action: Clears the data in the specified array(s)

  • array_list is one or more array reference in the form *var or *var$ seperated by commas.
  • All the bytes in the array data are set to 0, setting all elements of a numeric array to 0, and all elements of a string array to "".
  • A garbge collection is done when a string array is specfied.

COMPARE

TYPE: plusBASIC relational function


FORMAT: COMPARE ( * array1, * array2 )

Action: Compares two arrays.

  • array1 and array2 are array variable names with no parentheses after them.
    • Undimensioned array error if either array has not be defined with the DIM statement.
  • Returns:
    • -1 (True) if both arrays contain identical data.
    • 0 (False) if the array contents differ or the array sizes are not the same.
Examples:
DIM A(1),B(1),C(2)
PRINT COMPARE(*A,*B)
PRINT COMPARE(*A,*C)
A(1)=9
PRINT COMPARE(*A,*B)

Prints -1, 0, and 0


FORMAT: COMPARE ( address1 , address2 , length )

Action: Compares two sections of memory.

  • address1 is the address to start comparing from, in any of the following formats:
    • address to copy from main memory.
    • @ page , offset to copy from paged memory.
    • ! ext_addr to copy from extended memory.
  • address1 is the address to start comparing against, in any of the following formats:
    • address to copy to main memory.
    • @ page , offset to copy to paged memory.
    • ! ext_addr to copy to extended memory.
  • length is the number of bytes to compare.
  • Different formats may be used for address1 and address2.
Examples:

PRINT COMPARE(15000,32000,256)

Returns -1 if the 256 bytes starting at address 15000 match the 256 bytes starting at address 32000.

PRINT COMPARE(@40,100,20000,200)

Compares 200 bytes at address 100 of page 40 with 200 bytes at address 20000 in main memory.

PRINT COMPARE(12288,@41,0,1024)

Compares 1024 bytes of memory at address 12288 in main memory with 1024 bytes at address 0 of page 41.

PRINT COMPARE(@50,500,@51,1000,500)

Compares 200 bytes at address 50 of page 50 with 1024 bytes at address 0 of page 51.


COPY

TYPE: plusBASIC Memory Statement

FORMAT: COPY source , length TO destination

Action: Copies bytes from one part of main memory to another.

  • source is the address to start copying from, in any of the following formats:
    • address to copy from main memory.
    • @ page , offset to copy from paged memory.
    • ! ext_addr to copy from extended memory.
  • length is the number of bytes to copy.
  • destination is the address to copy to, in any of the following formats:
    • address to copy to main memory.
    • @ page , offset to copy to paged memory.
    • ! ext_addr to copy to extended memory.
  • Different formats may be used for source and destination.
  • If the blocks of memory overlap, COPY will handle it correctly.

Advanced: Main memory to main memory copy uses the LDIR or LDDR machine language instruction, making it faster than copies to and from paged memory.

Examples:

COPY $3000,1000 TO $8000

Copies screen RAM to main memory addresses 32768 through 33667.

COPY 36,$F800,2048 TO $3000

COPY @20,$2000,1000 TO @37,$2000

Copies the 1bpp bitmap color RAM to the video RAM buffer.


FORMAT: COPY @ src_page TO @ dest_page

Action: Copies an entire page of memory to another page of memory.

  • src_page is the page to copy from and must be in the range 0 through 63.
  • source is the starting address in the page to copy from and must be in the range 0 to 16383.
  • An Illegal Quantity error occurs if any argument is out of its respective range.

Advanced: Whole page copy uses the LDIR machine language instruction, making it faster than paged memory address to address copies.

Examples: ` COPY @20 TO @37 `

Copies Video RAM to RAM page 37.

COPY @37 TO @20

Copies RAM page 37 to Video RAM.

LEN

TYPE: BASIC Variable Function

FORMAT: LEN ( string )

Action: Returns the number of characters in the specified string expression.

  • string is the string expression to be evaluated.
  • Non-printed characters and blanks are counted.
Examples:
CC$ = "AQUARIUS+ COMPUTER": PRINT LEN(CC$)

  18

FORMAT: LEN ( * array )

Action: Returns the length in bytes of the data portion of the specified array.

Clone this wiki locally