BASIC-DOS

A PCjs Retro-Programming Project

BASIC-DOS is on Twitter Project maintained by jeffpar

BASIC-DOS Manual

BASIC Functions

Functions can be used in any expression, in BASIC programs or at the prompt (eg, PRINT SQR(2)). Functions whose names end with $ return strings; all others return numbers.

You can also define your own functions with DEF.

Numeric Functions

The trigonometric functions use radians, and all floating-point calculations use 64-bit (double-precision) values, with about 15 significant digits. If floating-point support is disabled (see Starting BASIC-DOS), numeric variables default to integers, and / and ^ are integer operations.

ABS

ABS(x)

Returns the absolute value of x.

ATN

ATN(x)

Returns the arctangent of x, in radians (eg, 4*ATN(1) is pi).

COS

COS(x)

Returns the cosine of x, where x is in radians.

EXP

EXP(x)

Returns e (2.71828…) raised to the power of x.

FIX

FIX(x)

Returns x truncated to an integer (eg, FIX(-2.5) is -2). See also INT.

INT

INT(x)

Returns the largest integer less than or equal to x (eg, INT(-2.5) is -3). See also FIX.

LOG

LOG(x)

Returns the natural logarithm of x, which must be greater than zero.

RND

RND[(n)]

Returns a random number from 0 up to (but not including) 1. n has the same effect as with RND%.

RND%

RND%[(n)]

Returns a random integer between 0 and MAXINT, inclusive. If n is negative, the generator is reseeded first, and if n is zero, the previous random integer is returned.

SIN

SIN(x)

Returns the sine of x, where x is in radians.

SQR

SQR(x)

Returns the square root of x, which must not be negative.

TAN

TAN(x)

Returns the tangent of x, where x is in radians.

String Functions

Strings can contain up to 255 characters. Character positions start at 1.

ASC

ASC(string)

Returns the character code (0-255) of the first character of string (or 0 if string is empty).

CHR$

CHR$(code)

Returns a one-character string containing the character with the specified code (0-255).

HEX$

HEX$(n)

Returns the hexadecimal representation of the integer n. Negative values are treated as unsigned 32-bit values (eg, HEX$(-1) is “FFFFFFFF”).

INSTR

INSTR([start,]string1,string2)

Returns the position of string2 within string1, searching from position start (default 1), or 0 if not found.

LCASE$

LCASE$(string)

Returns string with all upper-case letters converted to lower-case.

LEFT$

LEFT$(string,n)

Returns the leftmost n characters of string.

LEN

LEN(string)

Returns the number of characters in string (0-255).

MID$

MID$(string,start[,n])

Returns n characters of string, beginning at position start (or the rest of string if n is omitted). The MID$ statement (eg, MID$(A$,2) = "X") isn’t supported yet.

OCT$

OCT$(n)

Returns the octal representation of the integer n.

RIGHT$(string,n)

Returns the rightmost n characters of string.

SPACE$

SPACE$(n)

Returns a string of n spaces.

STR$

STR$(x)

Returns x as a string, with a leading space if x is not negative.

STRING$

STRING$(n,char)

Returns a string of n copies of char, which can be either a character code or a string (whose first character is used).

UCASE$

UCASE$(string)

Returns string with all lower-case letters converted to upper-case.

VAL

VAL(string)

Returns the numeric value of string, ignoring any blanks. If string does not begin with a number, the result is 0. The &H and &O prefixes aren’t supported yet.

System Functions

DATE$

DATE$

Returns the current date as a string in the form MM-DD-YYYY.

ERR

ERR

Returns the number of the last error (see ON ERROR).

FRE

FRE(x)

Compacts string memory and returns the number of bytes available. The argument is ignored.

INKEY$

INKEY$

Returns the next key pressed, without waiting (an empty string if no key was pressed). Extended keys (eg, cursor keys) return two characters: a null and the key’s scan code.

10 LET K$ = INKEY$:IF K$ = "" THEN GOTO 10
PRINT "You pressed "; K$

PEEK

PEEK(offset)

Returns the byte at offset in the segment set by DEF SEG. For example, this returns the low byte of the BIOS timer tick count:

DEF SEG=0:PRINT PEEK(&H46C)

TIME$

TIME$

Returns the current time as a string in the form HH:MM:SS.

Predefined Constants

ERRORLEVEL

Equal to the return code from the last program executed (eg, IF ERRORLEVEL = 1 THEN PRINT "Failed").

MAXINT

Equal to the largest positive integer (2147483647).

« RETURNDevice Commands »

Copyright (c) 2020-2026 Jeff Parsons Released under MIT License