Getting Started
Introduction
Sample Programs
QBasic IDEs
History
Advice
Tools
Mini-Tutorial
Tutorial
Code Snippets

Resources
Web Sites
More Tutorials
Vendors
Books
Magazines
NewsLetters
NewsGroups
Forums
User Groups
Talk Shows
Blogs

GBIC >> QBasic >> Tutorial >> System Calls

QBasic Information Center Tutorials - System Calls
These tutorials were written to help you get a quick, but thorough, understanding of QBasic - the scope of the language as well as it's specific capabilities.

System Calls
QBasic includes a fairly wide range of features which allow it to access/edit information in system memory and to transfer control to other programs.

    • Environmental
     environ, environ$
    • String Space
     fre 
    • Port Access
     inp, out 
    • Memory Access
     peek, poke 
    • App Execution
     shell, chain, common, run 
    • Pointers
     varptr, varptr$, varseg 
    • Assembly Language  
     call absolute 

System Calls Functions Reference
Here's a quick reference of the available system call functions, in alphabetical order.

  • call absolute - transfers control to a machine-language procedure
        call absolute (varlist, offset%)
        

    The address% is relative to the current segment address as set by DEF SEG. Allowed values are 0-65535. byte% is a value of 0-255.

  • chain - transfer control to another QBasic program
        chain filespec$
        chain "c:\temp\test.bas"
        

    Note: chain does not close open files

  • common - defines global variables to be shared throughout a program or between chained programs
        common shared a$, b%, c#          # 3 variables made COMMON
        common a as string, b as integer  # AS defines variable types
        

    Note: unless it has been declared as a static array in a preceeding DIM statement, an array variable in a COMMON statement is a dynamic array. Its dimensions must be set in a later DIM or REDIM statement.

  • environ - changes/adds a DOS environment string
        environ var$    # if not present adds var$
                        # if present, changes value
        environ "path=test"   # adds/assigns Path variable
        

  • environ$ - returns a DOS environment string
        result$ = environ$ var$   # returns value of var$ 
        result$ = environ$ (n%)   # returns nth environment string
        print environ$("path")    # returns value of "path"
        

    Note: The environmental variable string must be of one of two forms:

        var$=string$
        var$ string$
        

    Note: changes made by environ are temporary. QBasic erases the changes when the program ends.

  • fre - returns amount of available or unused memory
        result& = fre(-1)    # returns size of largest array
                               you can create
        result& = fre(-2)    # returns unused stack space
        result& = fre(n%)    # any other number returns available
                               string space
        result$ = fre("any") # compacts free string space/returns 
                               available space
        

  • inp - returns a byte from a hardware I/O port
        result% = inp(port%)
        

  • ioctl - sends control string to a device driver
        ioctl(#1, var$)   # var$ is sent to device #1
        
    The device number is that assigned using the Open statement.

  • ioctl$ - returns status information from a device driver
        result$ = ioctl$(#1)   # requests status from device #1
        
    The device number is that assigned using the Open statement.

  • out - sends a byte to a hardware I/O port
        out port%, data%
        
  • peek - returns byte value from specified memory location
        result& = peek (address%)
        

    The address% is relative to the current segment address as set by DEF SEG. Allowed values are 0-65535.

  • poke - writes a byte to a specified memory location
        poke address, byte%
        

    The address% is relative to the current segment address as set by DEF SEG. Allowed values are 0-65535. byte% is a value of 0-255.

  • run - runs the current program or a specified program
        run               # executes current program at first line
        run (line%)       # executes current program at line%
        run ("c:\temp\test.bas")   # runs a QBasic source file
        

    Run closes all file and clears program memory before loading a program. Use the CHAIN program to run a program without closing open files.

  • shell - suspends execution to run a DOS command or batch file
        shell var$   # var$ is name of DOS command/batch file
        

    The QBasic program continues when the DOS command or batch file completes. With no var$, a DOS window is displayed (use EXIT in the DOS window to resume your program)

  • varptr - returns offset address of a variable
        result% = varptr(var$)   # returns offset address of var$
        

  • varptr$ - returns string representation of variables address for use in DRAW/PLAY statements
        result$ = varptr$(var$)  # var$ contains DRAW/PLAY statements
        

  • varseg - returns segment address of a variable
        result% = varseg(var$)   # returns segment address of var$
        

If you have any suggestions or corrections, please let me know.