-
Notifications
You must be signed in to change notification settings - Fork 0
Supported functions and statements
Notes:
- Numeric values are 16-bit integer-style values.
- Strings are counted runtime strings with a maximum payload length of 255 bytes.
- File channels are 1 to 9.
- Array indexes are 1-based.
- REM and apostrophe comments:
REM This is a comment
' This is also a comment- LET and implicit assignment without LET:
LET A = 10
A = A + 1
A$ = "HELLO"- INPUT ["prompt"], var
- INPUT ["prompt"], var$
- ! var as shorthand for INPUT var
INPUT "NAME", N$
INPUT "VALUE", A
! A- LINE INPUT #channel, var$
LINE INPUT #1, A$- ? as shorthand for PRINT
- PRINT #channel, ...
PRINT "HELLO"
? A
PRINT #2, "VALUE="; A- IF ... THEN ... ELSE ...
- multi-line IF ... THEN, ELSEIF ... THEN, ELSE, END IF
- GOTO
- GOSUB + RETURN
- ON expression GOTO ... — available since BASCOMP 2.1
- ON expression GOSUB ... — available since BASCOMP 2.1
ON A GOTO START, MIDDLE, FINISH
ON A GOSUB SUB1, SUB2, SUB3- FOR ... TO ... [STEP ...] / NEXT
- END FOR
- EXIT FOR — available since BASCOMP 2.1
- WHILE ... / WEND
- DIM for integer arrays
- DIM name$ AS STRING * length — available since BASCOMP 2.1
- DIM name$(count) AS STRING * maxLength — available since BASCOMP 2.1
- OPEN ... FOR INPUT AS #channel
- OPEN ... FOR OUTPUT AS #channel
- CLOSE #channel
- KILL
- GET #channel, [position,] variable
- PUT #channel, [position,] variable
- CHDIR path$ — available since BASCOMP 2.1
- MKDIR path$ — available since BASCOMP 2.1
- RMDIR path$ — available since BASCOMP 2.1
- FILES [filespec$] — available since BASCOMP 2.1
- CLS
- LOCATE row, column
- COLOR foreground, background
- SCREEN mode — available since BASCOMP 2.1
- PSET x, y, color — available since BASCOMP 2.1
- LINE (x1,y1)-(x2,y2), color [,B|BF] — available since BASCOMP 2.1
- CIRCLE (x,y), radius [,color] — available since BASCOMP 2.1
- BEEP — available since BASCOMP 2.1
- DEF SEG
- DEF SEG = expression
- POKE offset, value
- POKE segment, offset, value — available since BASCOMP 2.1
- OUT port, value — available since BASCOMP 2.1
- CALLINT interruptNumber, registerArray — available since BASCOMP 2.1
- SELECT CASE, CASE, CASE ELSE, END SELECT
- RANDOMIZE
- RANDOMIZE TIMER / numeric-expression
- RANDOMIZE TIMER() — available since BASCOMP 2.1
- DATA — available since BASCOMP 2.1
- READ — available since BASCOMP 2.1
- RESTORE — available since BASCOMP 2.1
- DATAB — available since BASCOMP 2.1
- CALLDATA lineNumber — available since BASCOMP 2.1
- XSET handle, index, string-expression
- XFREE handle
- END / STOP / . as shorthand
BASCOMP supports single-line and multi-line IF forms in both traditional numbered BASIC mode and QB-style unnumbered mode.
Single-line form:
IF A > 10 THEN PRINT "HIGH" ELSE PRINT "LOW"Multi-line form:
IF A > 10 THEN
PRINT "HIGH"
ELSEIF A = 10 THEN
PRINT "TEN"
ELSE
PRINT "LOW"
END IFBoolean IF expressions support AND, OR, and NOT in supported comparison contexts.
IF A > 0 AND B > 0 THEN PRINT "BOTH POSITIVE"
IF NOT A = 0 THEN PRINT "A IS NOT ZERO"SELECT CASE supports numeric selection logic.
SELECT CASE A
CASE 1
PRINT "ONE"
CASE 2
PRINT "TWO"
CASE ELSE
PRINT "OTHER"
END SELECTCurrent CASE handling is based on individual numeric case values and CASE ELSE.
Counted loops are supported, including nested loops and optional STEP values.
FOR I = 1 TO 10 STEP 2
PRINT I
NEXT IEND FOR is recognized as an explicit loop terminator form.
EXIT FOR leaves the innermost active FOR loop. EXIT FOR is available since BASCOMP 2.1.
FOR I = 1 TO 10
IF I = 5 THEN EXIT FOR
PRINT I
END FORA = 0
WHILE A < 10
A = A + 1
WENDON expression GOTO and ON expression GOSUB are available since BASCOMP 2.1. They use a 1-based target index.
A = 2
ON A GOTO ONE, TWO, THREE
ONE:
PRINT "ONE"
END
TWO:
PRINT "TWO"
END
THREE:
PRINT "THREE"
ENDA = 1
ON A GOSUB SUB1, SUB2
END
SUB1:
PRINT "SUB1"
RETURN
SUB2:
PRINT "SUB2"
RETURNSubroutines are supported through GOSUB and RETURN.
GOSUB HELLO
END
HELLO:
PRINT "HELLO"
RETURNNumeric variables store signed 16-bit integer-style values.
A = 123
B = -10
C = A + BString identifiers end with $ and use counted string representation in the runtime.
A$ = "HELLO"
B$ = A$ + " WORLD"Fixed-length string storage is available since BASCOMP 2.1:
DIM NAME$ AS STRING * 40
NAME$ = "BASCOMP"DIM creates indexed numeric arrays using syntax such as A(I). Array indexes are 1-based in the runtime.
DIM A(10)
A(1) = 5
A(2) = A(1) + 10
PRINT A(2)Small arrays are stored internally. Larger numeric arrays are backed by external DOS memory through the runtime array support.
External string arrays are available through XALLOC and through the DIM syntax introduced in BASCOMP 2.1.
Be careful: The maximum size of any individual array is 65535 Bytes (one segment). In the case of strings, this means you need to calculate: (stringlen+1)*stringnums <= 65535.
DIM NAMES$(10) AS STRING * 40
NAMES$(1) = "ALICE"
NAMES$(2) = "BOB"
PRINT NAMES$(1)H = XALLOC(10, 40)
XSET H, 1, "ALICE"
XSET H, 2, "BOB"
PRINT XGET$(H, 1)
XFREE HXALLOC(count) uses the default maximum string length. XALLOC(count, maxLength) specifies the per-entry maximum payload length.
Numeric expressions support:
- decimal constants
- hexadecimal constants with &H...
- numeric variables
- numeric array elements such as A(I)
- parentheses
- unary +
- unary -
- unary NOT
- "+"
- "-"
- "*"
- "/"
- "\"
- MOD
- XOR
- AND
- OR
- exponentiation with ^
- numeric function calls
Examples:
A = 10 + 20 * 3
B = (A - 5) \ 2
C = A MOD 7
D = &HFF
E = NOT 0
F = 2 ^ 8String expressions support:
- string variables
- string literals
- string concatenation with +
- string function calls
- indexed external string array access
- DATE$
- TIME$
- INKEY$
- INPUT$
Examples:
A$ = "HELLO"
B$ = A$ + " WORLD"
C$ = LEFT$(B$, 5)
D$ = STR$(123)
E$ = DATE$
F$ = TIME$Nested string expressions and concatenations are supported through the internal string-expression parser and temporary string buffers.
The following comparison operators are supported in IF expressions:
- "="
- "<>"
- "<"
- ">"
- "<="
- ">="
Comparisons work for both numeric values and supported string expressions, depending on context.
IF A = 10 THEN PRINT "TEN"
IF A$ = "OK" THEN PRINT "MATCH"
IF LEFT$(A$, 1) = "Y" THEN PRINT "YES"Returns the length of a string.
A$ = "HELLO"
PRINT LEN(A$)Converts a string to a numeric value.
A$ = "123"
A = VAL(A$)Returns the character code of the first character.
A = ASC("A")
PRINT AReturns the end-of-file state for a file channel.
OPEN "TEST.TXT" FOR INPUT AS #1
WHILE EOF(1) = 0
LINE INPUT #1, A$
PRINT A$
WEND
CLOSE #1Tests whether a file exists.
IF EXIST("TEST.TXT") THEN PRINT "FILE EXISTS"Searches for a substring and returns its position.
P = INSTR("ABCDEF", "CD")
PRINT PSearches for a substring starting at a specific position.
P = INSTR(3, "ABABAB", "AB")
PRINT PReturns the absolute value.
PRINT ABS(-10)Returns -1, 0, or 1 depending on the sign of the value.
PRINT SGN(-20)
PRINT SGN(0)
PRINT SGN(20)Returns a pseudo-random number in the supported runtime range.
RANDOMIZE TIMER
A = RND(100)
PRINT AReturns the integer value. Since BASCOMP numeric values are already integer-style values, this is mainly useful for compatibility.
A = INT(123)Returns the integer square root.
PRINT SQR(100)Returns the smaller value.
PRINT MIN(10, 20)Returns the larger value.
PRINT MAX(10, 20)Returns the number of seconds since midnight modulo 65536.
T = TIMER()
PRINT TStarts a DOS child program and returns 0 on success or a DOS error code.
R = EXEC("CHILD", "")
IF R <> 0 THEN PRINT "EXEC ERROR "; RExample with arguments:
R = EXEC("TOOL", "INPUT.TXT OUTPUT.TXT")
PRINT RDetects the CPU class and returns the runtime CPU identifier.
Typical return values include:
- 86 for 8086/8088 class
- 120 for NEC V20/V30 class
- 186 for 80186/80188 class
- 286
- 386
- 486
- 586
- 686
- 1500 for CPUID family F
- 999 for CPUID-present but otherwise unmapped family
C = CPUID()
PRINT "CPU="; CReads a byte from the active DEF SEG segment.
DEF SEG = &HB800
A = PEEK(0)
DEF SEGReads a byte from an explicit segment and offset. This form is available since BASCOMP 2.1.
A = PEEK(&HB800, 0)
PRINT AReads a byte from an I/O port. INP() is available since BASCOMP 2.1.
A = INP(&H60)
PRINT AAllocates an external string array with default maximum string length and returns a handle.
H = XALLOC(10)Allocates an external string array with a specific maximum string length.
H = XALLOC(10, 40)
XSET H, 1, "HELLO"
PRINT XGET$(H, 1)
XFREE HBuilds a one-character string from a character code.
A$ = CHR$(65)
PRINT A$Returns the left part of a string.
PRINT LEFT$("HELLO", 2)Returns a substring.
PRINT MID$("HELLO", 2, 3)Returns the right part of a string.
PRINT RIGHT$("HELLO", 2)Removes leading spaces.
PRINT LTRIM$(" HELLO")Removes trailing spaces.
PRINT RTRIM$("HELLO ")Removes leading and trailing spaces.
PRINT TRIM$(" HELLO ")Converts ASCII lowercase letters a to z to uppercase.
PRINT UCASE$("Hello")Converts a numeric value to a string.
A$ = STR$(123)
PRINT A$Reads a string from an external string array.
H = XALLOC(5, 20)
XSET H, 1, "ONE"
PRINT XGET$(H, 1)
XFREE HReturns the DOS date in mm-dd-yyyy format.
PRINT DATE$Returns the DOS time in hh:mm:ss format.
PRINT TIME$Returns a non-blocking keyboard input string.
K$ = INKEY$
IF LEN(K$) <> 0 THEN PRINT "KEY PRESSED"Special keys may return a two-character string where the first byte is zero and the second byte is the scan code, depending on BIOS behavior.
Reads a string from standard input.
A$ = INPUT$
PRINT A$DATA, READ, RESTORE, DATAB, and CALLDATA are available since BASCOMP 2.1.
Defines numeric word data.
DATA 10,20,30
READ A
READ B
READ C
PRINT A; B; CReads the next numeric word from DATA.
DATA 100,200
READ A
READ BResets the runtime data pointer to the first DATA record.
DATA 1,2,3
READ A
READ B
RESTORE
READ C
PRINT CDefines raw byte data in the generated assembly.
100 DATAB 65,66,67Calls the byte block generated by DATAB at the given BASIC source line number.
This is an advanced low-level feature. The byte block is treated as machine code and must return correctly, typically with RET, decimal opcode 195, if it is called as a subroutine.
Minimal safe example:
100 DATAB 195
110 CALLDATA 100
120 PRINT "RETURNED"Text file I/O is supported through:
- OPEN
- CLOSE
- PRINT #
- LINE INPUT #
OPEN "OUT.TXT" FOR OUTPUT AS #1
PRINT #1, "HELLO"
CLOSE #1OPEN "OUT.TXT" FOR INPUT AS #1
LINE INPUT #1, A$
PRINT A$
CLOSE #1Binary file I/O is supported through:
- GET
- PUT
OPEN "DATA.BIN" FOR OUTPUT AS #1
A = 65
PUT #1, 1, A
CLOSE #1OPEN "DATA.BIN" FOR INPUT AS #1
GET #1, 1, A
PRINT A
CLOSE #1File channels 1 to 9 are supported.
OPEN supports:
- FOR INPUT
- FOR OUTPUT
KILL deletes a file:
KILL "OLD.TXT"EXIST() checks whether a file is present:
IF EXIST("OLD.TXT") THEN KILL "OLD.TXT"The runtime retains buffered byte output for PUT; buffered binary output is flushed when required by handle changes, seek operations, close operations, and mixed text/binary output paths.
Directory and file listing statements are available since BASCOMP 2.1.
Changes the current directory.
CHDIR "C:\TEMP"Creates a directory.
MKDIR "TESTDIR"Removes a directory.
RMDIR "TESTDIR"Lists matching files.
FILES
FILES "*.BAS"Directory entries are printed in brackets by the runtime.
Standard text output is supported through PRINT.
Additional screen control is provided by:
- CLS
- LOCATE
- COLOR
CLS
COLOR 14, 1
LOCATE 10, 20
PRINT "HELLO"COLOR foreground, background sets the active text attribute used by BIOS-style console output when screen output support is active.
Graphics statements are available since BASCOMP 2.1.
SCREEN selects a BIOS video mode through the runtime.
Known mappings:
- SCREEN 0 maps to BIOS text mode 03h
- SCREEN 1 maps to BIOS mode 04h
- SCREEN 2 maps to BIOS mode 06h
- Other values are passed as BIOS mode numbers in AL; for example, SCREEN 13 selects BIOS mode 13h on systems that support it.
Examples:
SCREEN 0
PRINT "TEXT MODE"SCREEN 13
PSET 160, 100, 12Plots one pixel using BIOS graphics output.
SCREEN 13
PSET 160, 100, 15Draws a line.
SCREEN 13
LINE (10,10)-(200,100), 15Draws a rectangle outline.
SCREEN 13
LINE (20,20)-(120,80), 14, BDraws a filled rectangle.
SCREEN 13
LINE (30,30)-(100,70), 4, BFDraws an outline circle.
SCREEN 13
CIRCLE (160,100), 50, 15If the color is omitted, the compiler/runtime path uses the default color handling implemented by the graphics parser.
BEEP is available since BASCOMP 2.1. It outputs the bell character.
BEEPBASCOMP 2.1 supports a compact BASIC-style memory access subset.
Sets the active segment used by PEEK(offset) and POKE offset,value.
DEF SEG = &HB800
A = PEEK(0)
DEF SEGResets the active segment to the program segment.
DEF SEGReads a byte from the active DEF SEG segment.
DEF SEG = &HB800
A = PEEK(0)Reads a byte from an explicit segment and offset. This form is available since BASCOMP 2.1.
A = PEEK(&HB800, 0)Writes a byte to the active DEF SEG segment and offset.
DEF SEG = &HB800
POKE 0, 65
DEF SEGWrites a byte to an explicit segment and offset. This form is available since BASCOMP 2.1.
POKE &HB800, 0, 65Values written by POKE must fit into a byte, 0..255; otherwise the runtime raises a byte value error.
Port I/O is available since BASCOMP 2.1.
Reads one byte from an I/O port.
A = INP(&H60)
PRINT AWrites one byte to an I/O port.
OUT &H61, 0The output value must fit into a byte, 0..255.
CALLINT is available since BASCOMP 2.1. It calls a real-mode interrupt using a numeric register array.
The array layout is:
- regs(1) = AX
- regs(2) = BX
- regs(3) = CX
- regs(4) = DX
- regs(5) = SI
- regs(6) = DI
- regs(7) = FLAGS output only
Segment registers are not user-settable in this minimal runtime interface.
Example: call BIOS keyboard interrupt 16h, function 00h, to wait for and read a key.
DIM R(7)
R(1) = &H0000
R(2) = 0
R(3) = 0
R(4) = 0
R(5) = 0
R(6) = 0
CALLINT &H16, R
PRINT "AX="; R(1)
PRINT "FLAGS="; R(7)Example: BIOS keyboard status, interrupt 16h, function 01h.
DIM R(7)
R(1) = &H0100
CALLINT &H16, R
IF R(7) AND &H40 THEN
PRINT "NO KEY AVAILABLE"
ELSE
PRINT "KEY AVAILABLE"
END IF&H40 checks the zero flag bit in the returned FLAGS word.
BASCOMP 2.1 includes runtime support for:
- DATE$ using DOS date services
- TIME$ using DOS time services
- TIMER() using DOS time services
- INKEY$ using BIOS keyboard calls
- EXEC() for launching DOS child programs
- CPUID() for CPU-class detection
Examples:
PRINT DATE$
PRINT TIME$
PRINT TIMER()K$ = INKEY$
IF LEN(K$) <> 0 THEN PRINT "KEY"R = EXEC("CHILD", "")
IF R <> 0 THEN PRINT "EXEC ERROR "; RPRINT CPUID()- BASCOMP supports both numbered BASIC source mode and QB-style unnumbered source mode.
- Numeric values are 16-bit integer-style values.
- File channels are 1..9.
- Array indexes are 1-based.
- FOR/WHILE nesting depth is limited.
- Block IF nesting depth is limited.
- String expression and context nesting depth is limited by the compiler's internal context stacks.