Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Atari BASIC
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Advanced techniques== ===Strings as a way to manipulate memory=== The base addresses of a string is stored in a variable table. String addresses can be redirected to point to arbitrary areas of RAM. This allows the rapid memory-shifting routines underlying string and substring assignment can be applied from BASIC to the memory used for the screen or player/missile graphics. This is particularly useful for achieving rapid vertical movement of player/missile images directly from Atari BASIC. ===Random access via DATA/RESTORE=== Numeric variables and expressions can be used as the parameter for the <code>RESTORE</code> statement, allowing <code>DATA</code> statements to be randomly accessed through code such as {{code|2=basic|RESTORE ROOMBASE+ROOMNUMBER:READ DESCRIPTION$, TREASURE$, EXITS}}. This can also be used to emulate static string arrays: {{code|2=basic|RESTORE STRBASE+INDEX:READ A$:PRINT A$}}. ===Error handling with TRAP=== The <code>TRAP</code> statement jumps to a line number when an error occurs, and this reduces the need for manual error-checking. For example, when drawing graphics on the screen it is not necessary to check whether lines go beyond screen boundaries of the current graphics mode. This error state can be trapped, and the error handled if necessary. ===Includes=== The <code>ENTER</code> command reads source code from a device and merges it into the current program, as if the user had typed it in. This allows programs to be saved out in sections via <code>LIST</code>, reading them in using <code>ENTER</code> to merge or replace existing code. By using blocks of line numbers that do not overlap, programmers can build libraries of subroutines and merge them into new programs as needed. ===Self-modifying code=== The editor can be set-up to repeatedly read input from the screen until an EOF is reached. This allows a program to write new program code followed by a <code>CONT</code> statement to the screen then, positioning the screen cursor at the start of the new code, <code>STOP</code> the running program, causing the new code to be read in then execution be continued by the <code>CONT</code> statement. ===Embedded machine language=== Atari BASIC can call machine code subroutines stored in strings or <code>POKE</code>ed into memory. The 256 byte area starting at address 1536 ($0600) is often used for this purpose. Machine code is invoked with the <code>USR</code> function. The first parameter is the address of the subroutine and the following values are parameters. If the code is stored in a string named <code>ROUTINE$</code> it can be called with two parameters as {{code|2=cbmbas|1=ANSWER=USR(ADR(ROUTINE$),VAR1,VAR2)}}. Parameters are pushed onto the hardware stack as 16-bit integers in the order specified in the <code>USR</code> call in low byte, high byte order. A final byte is pushed indicating the number of arguments. The machine language code must remove these values before returning via the <code>RTS</code> instruction. A 16-bit value can be returned to BASIC by placing it in addresses 212 and 213 ($D4 and $D5).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)