BASIC IV ROM Routines
Memory usage
Submitted by Steve Fewell
This page contains a listing of the main memory locations used by the BASIC ROM. Some of the addresses listed on this page will have multiple uses - in this case, only the most common usage will be given.
The listing is in address order (zero page first):
Address (in hex) | Description of usage |
00 | LOMEM [Pointer to start of BASIC variables] LSB |
01 | LOMEM [Pointer to start of BASIC variables] MSB |
02 | VARTOP [Pointer to end of BASIC variables] LSB |
03 | VARTOP [Pointer to end of BASIC variables] MSB |
04 | BASIC Stack Pointer [Pointer to latest entry in BASIC Stack] LSB |
05 | BASIC Stack Pointer [Pointer to latest entry in BASIC Stack] MSB |
06 | HIMEM [Pointer to start of memory-mapped screen area] LSB |
07 | HIMEM [Pointer to start of memory-mapped screen area] MSB |
08 | ERL [Address of the BASIC line in which the last error occurred] LSB |
09 | ERL [Address of the BASIC line in which the last error occurred] MSB |
0A | BASIC Text Pointer offset (offset to the current byte being processed from the address pointed to by (&B, &C)) |
0B | BASIC Text Pointer LSB [Pointer to start of BASIC text line] |
0C | BASIC Text Pointer MSB [Pointer to start of BASIC text line] |
0D | Random Number working area |
0E | Random Number working area |
0F | Random Number working area |
10 | Random Number working area |
11 | Random Number working area |
12 | TOP [Pointer to the end of the BASIC program - not including variables] LSB |
13 | TOP [Pointer to the end of the BASIC program - not including variables] MSB |
14 | PRINT BYTES - The number of bytes to include in a print output field |
15 | PRINT FLAG - 0 = Decimal, N = Hexadecimal |
16 | Pointer to BASIC Error routine code [either the default, or the code which occurs after an ON ERROR statement] LSB |
17 | Pointer to BASIC Error routine code [either the
default, or the code which occurs after an ON ERROR statement] MSB The default value of (&16, &17) is &B2AF. |
18 | PAGE (DIV by 256). The page number where the BASIC program starts. The page offset is always 00. |
19 | BASIC Second Text Pointer LSB [Pointer to start of BASIC text line] |
1A | BASIC Second Text Pointer MSB [Pointer to start of BASIC text line] |
1B | BASIC Second Text Pointer offset (offset to the current byte being processed from the address pointed to by (&19, &1A)) |
1C | BASIC PROGRAM START [Pointer to start of BASIC
program] LSB (when program is not running) / Next DATA Location LSB (when program is running) |
1D | BASIC PROGRAM START [Pointer to start of BASIC
program] MSB (when program is not running) / Next DATA Location MSB (when program is running) |
1E | COUNT - The number of bytes printed since the last new line |
1F | LISTO flag (0 = off, 1 = a space after each line number, 2 = Indent FOR, 4 = Indent REPEAT), the top bit is also set for *EDIT mode |
20 | TRACE flag (0 = off, 1 = on) |
21 | Maximum TRACE LINE number (LSB) |
22 | Maximum TRACE LINE number (MSB) |
23 | WIDTH |
24 | Current REPEAT level |
25 | Current GOSUB level |
26 | 15* Current FOR level |
27 | Variable type (00 = byte, 04 = integer, 05 = floating-point, &81 = String, &A4 = Function, &F2 = Procedure) |
28 | OPT flag (0 - list, 1 - errors, 2 = relocate) |
29 | |
2A | IWA - Integer working area -> LSB |
2B | IWA - Integer working area -> byte 2 |
2C | IWA - Integer working area -> byte 3 |
2D | IWA - Integer working area -> MSB |
2E | FWA - Floating-point working area A -> Sign byte |
2F | FWA - Floating-point working area A -> Exponent overflow byte |
30 | FWA - Floating-point working area A -> Exponent byte |
31 | FWA - Floating-point working area A -> Mantissa byte 1 |
32 | FWA - Floating-point working area A -> Mantissa byte 2 |
33 | FWA - Floating-point working area A -> Mantissa byte 3 |
34 | FWA - Floating-point working area A -> Mantissa byte 4 |
35 | FWA - Floating-point working area A -> Mantissa rounding byte |
36 | Current length of String in the String working area buffer (&600 - &6FF) |
37 | Pointer to next BASIC character [LSB] Also: Pointer to Integer variable. |
38 | Pointer to next BASIC character [MSB] Also: Pointer to Integer variable. |
39 | |
3A | |
3B | FWB - Floating-point working area B -> Sign byte |
3C | FWB - Floating-point working area B -> Exponent byte |
3D | FWB - Floating-point working area B -> Mantissa byte 1 |
3E | FWB - Floating-point working area B -> Mantissa byte 2 |
3F | FWB - Floating-point working area B -> Mantissa byte 3 |
40 | FWB - Floating-point working area B -> Mantissa byte 4 |
41 | FWB - Floating-point working area B -> Mantissa rounding byte |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | Number of decimal points found in number [used by ASCII to binary number routine] |
48 | |
49 | |
4A | argp - pointer to Floating-Point variable LSB |
4B | argp - pointer to Floating-Point variable MSB |
4C | |
4D | |
4E | |
4F | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
5A | |
5B | |
5C | |
5D | |
5E | |
5F | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
6A | |
6B | |
6C | |
6D | |
6E | |
6F | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
7A | |
7B | |
7C | |
7D | |
7E | |
7F | |
... | |
F9 | |
FA | |
FB | |
FC | |
FD | MOS Error Message pointer LSB [Error Number, Error String] |
FE | MOS Error Message pointer MSB [Error Number, Error String] |
FF | MOS Error Byte (Top bit set if error occurred?) |
... | |
The following locations contain the values that BASIC assigns to any MOS vectors: |
|
0202-0203 | BASIC assigns the address &B278 to the BRK vector, as this points to the BASIC ROM code which BASIC wants to be executed every time an error condition occurs (generated by a BRK command in assembly language). |
... | |
The following locations contain the values of the resident integer variables: |
|
400-403 | @% value LSB first |
404-407 | A% value LSB first |
408-40B | B% value LSB first |
40C-40F | C% value LSB first |
410-413 | D% value LSB first |
414-417 | E% value LSB first |
418-41B | F% value LSB first |
41C-41F | G% value LSB first |
420-423 | H% value LSB first |
424-427 | I% value LSB first |
428-42B | J% value LSB first |
42C-42F | K% value LSB first |
430-433 | L% value LSB first |
434-437 | M% value LSB first |
438-43B | N% value LSB first |
43C-43F | O% value LSB first |
440-443 | P% value LSB first |
444-447 | Q% value LSB first |
448-44B | R% value LSB first |
44C-44F | S% value LSB first |
450-453 | T% value LSB first |
454-457 | U% value LSB first |
458-45B | V% value LSB first |
45C-45F | W% value LSB first |
460-463 | X% value LSB first |
464-467 | Y% value LSB first |
468-46B | Z% value LSB first |
The following locations contain the values of some temporary Floating-Point variables, in packed (variable) form: |
|
46C-470 | Temporary Floating-Point variable area 1 |
471-475 | Temporary Floating-Point variable area 2 |
476-47A | Temporary Floating-Point variable area 3 |
47B-47F | Temporary Floating-Point variable area 4 |
The following locations contain the variable pointer tables. [from Colin Pharo] There is a variable look-up table for each character with which a variable name in BASIC can start. Each pair of addresses is a pointer (low byte, high byte) to the variables whose names start with that particular character. The "variable look-up" table pointed to by each set of 2-bytes is stored in the variable area above the program TOP and has the following format: * 2-byte pointer to the next variable (Low byte, high byte] [&0000 specifies the last variable in the table] * The name of the variable (without the first character - which is already known, as it was used to find this table) * End of name marker -> &00 * Variable details/variable contents. The variable details/variable contents have the following formats: * for Integer variables -->The value of the integer (in 4-byte format) * for Floating-Point variables -->The value of the Floating-Point number (in 5-byte packed floating-point format) * for String variables --> A pointer to the value of the string [Low byte, high byte], followed by the maximum size allocated to the string [1 byte], and the current size of the string [1 byte]. Note: The String value is stored without the &00 terminator byte. * for Arrays --> 2 * The number of dimensions + 1 [1 byte], The number of elements in the first dimension, The number of elements in the second dimension. Followed by the contents of each array element (in the format described above [That is 4-bytes for Integer, 5-bytes for Floating-point number or 4-bytes for String]). |
|
480-481 | Variable Pointer table address [Low byte, high byte] for variables beginning with @ |
482-483 | Variable Pointer table address [Low byte, high byte] for variables beginning with A |
484-485 | Variable Pointer table address [Low byte, high byte] for variables beginning with B |
486-487 | Variable Pointer table address [Low byte, high byte] for variables beginning with C |
488-489 | Variable Pointer table address [Low byte, high byte] for variables beginning with D |
48A-48B | Variable Pointer table address [Low byte, high byte] for variables beginning with E |
48C-48D | Variable Pointer table address [Low byte, high byte] for variables beginning with F |
48E-48F | Variable Pointer table address [Low byte, high byte] for variables beginning with G |
490-491 | Variable Pointer table address [Low byte, high byte] for variables beginning with H |
492-493 | Variable Pointer table address [Low byte, high byte] for variables beginning with I |
494-495 | Variable Pointer table address [Low byte, high byte] for variables beginning with J |
496-497 | Variable Pointer table address [Low byte, high byte] for variables beginning with K |
498-499 | Variable Pointer table address [Low byte, high byte] for variables beginning with L |
49A-49B | Variable Pointer table address [Low byte, high byte] for variables beginning with M |
49C-49D | Variable Pointer table address [Low byte, high byte] for variables beginning with N |
49E-49F | Variable Pointer table address [Low byte, high byte] for variables beginning with O |
4A0-4A1 | Variable Pointer table address [Low byte, high byte] for variables beginning with P |
4A2-4A3 | Variable Pointer table address [Low byte, high byte] for variables beginning with Q |
4A4-4A5 | Variable Pointer table address [Low byte, high byte] for variables beginning with R |
4A6-4A7 | Variable Pointer table address [Low byte, high byte] for variables beginning with S |
4A8-4A9 | Variable Pointer table address [Low byte, high byte] for variables beginning with T |
4AA-4AB | Variable Pointer table address [Low byte, high byte] for variables beginning with U |
4AC-4AD | Variable Pointer table address [Low byte, high byte] for variables beginning with V |
4AE-4AF | Variable Pointer table address [Low byte, high byte] for variables beginning with W |
4B0-4B1 | Variable Pointer table address [Low byte, high byte] for variables beginning with X |
4B2-4B3 | Variable Pointer table address [Low byte, high byte] for variables beginning with Y |
4B4-4B5 | Variable Pointer table address [Low byte, high byte] for variables beginning with Z |
4B6-4B7 | Variable Pointer table address [Low byte, high byte] for variables beginning with [ |
4B8-4B9 | Variable Pointer table address [Low byte, high byte] for variables beginning with \ |
4BA-4BB | Variable Pointer table address [Low byte, high byte] for variables beginning with ] |
4BC-4BD | Variable Pointer table address [Low byte, high byte] for variables beginning with ^ |
4BE-4BF | Variable Pointer table address [Low byte, high byte] for variables beginning with _ |
4C0-4C1 | Variable Pointer table address [Low byte, high byte] for variables beginning with ' |
4C2-4C3 | Variable Pointer table address [Low byte, high byte] for variables beginning with a |
4C4-4C5 | Variable Pointer table address [Low byte, high byte] for variables beginning with b |
4C6-4C7 | Variable Pointer table address [Low byte, high byte] for variables beginning with c |
4C8-4C9 | Variable Pointer table address [Low byte, high byte] for variables beginning with d |
4CA-4CB | Variable Pointer table address [Low byte, high byte] for variables beginning with e |
4CC-4CD | Variable Pointer table address [Low byte, high byte] for variables beginning with f |
4CE-4CF | Variable Pointer table address [Low byte, high byte] for variables beginning with g |
4D0-4D1 | Variable Pointer table address [Low byte, high byte] for variables beginning with h |
4D2-4D3 | Variable Pointer table address [Low byte, high byte] for variables beginning with i |
4D4-4D5 | Variable Pointer table address [Low byte, high byte] for variables beginning with j |
4D6-4D7 | Variable Pointer table address [Low byte, high byte] for variables beginning with k |
4D8-4D9 | Variable Pointer table address [Low byte, high byte] for variables beginning with l |
4DA-4DB | Variable Pointer table address [Low byte, high byte] for variables beginning with m |
4DC-4DD | Variable Pointer table address [Low byte, high byte] for variables beginning with n |
4DE-4DF | Variable Pointer table address [Low byte, high byte] for variables beginning with o |
4E0-4E1 | Variable Pointer table address [Low byte, high byte] for variables beginning with p |
4E2-4E3 | Variable Pointer table address [Low byte, high byte] for variables beginning with q |
4E4-4E5 | Variable Pointer table address [Low byte, high byte] for variables beginning with r |
4E6-4E7 | Variable Pointer table address [Low byte, high byte] for variables beginning with s |
4E8-4E9 | Variable Pointer table address [Low byte, high byte] for variables beginning with t |
4EA-4EB | Variable Pointer table address [Low byte, high byte] for variables beginning with u |
4EC-4ED | Variable Pointer table address [Low byte, high byte] for variables beginning with v |
4EE-4EF | Variable Pointer table address [Low byte, high byte] for variables beginning with w |
4F0-4F1 | Variable Pointer table address [Low byte, high byte] for variables beginning with x |
4F2-4F3 | Variable Pointer table address [Low byte, high byte] for variables beginning with y |
4F4-4F5 | Variable Pointer table address [Low byte, high byte] for variables beginning with z |
4F6-4F7 | Variable Pointer table address [Low byte, high byte] for Procedures |
4F8-4F9 | Variable Pointer table address [Low byte, high byte] for Functions |
04FA | |
04FB | |
04FC | |
04FD | |
04FE | |
04FF | |
500-527 | The REPEAT Start address Stack (&0500-&0513 is the start address LSB stack and &0514-&0527 is the start address MSB stack) |
528-5BD | The FOR Loop Stack A maximum of 10 FOR loop details can be stored. Each FOR block is 15 bytes long.
|
5BE-5CB | Unused These 14 bytes are unused. |
5CC-5FF | The GOSUB Return address Stack (&05CC-&05E5 is the return address LSB stack and &05E6-&05FF is the return address MSB stack) |
600-6FF | SWA - String working area/buffer [also: call parameter block] |
700-7EF | BASIC Line Input buffer |
The following address are pointers [Low Byte, High byte] to specific floating-point routines in the BASIC ROM. BASIC provides these addresses as fixed external pointers to these often used routines within the BASIC ROM. The details in addresses &07F0 to &07FF are exactly the same as those in the BASIC4 ROM locations &BF14 to &BF23. |
|
7F0-7F1 | Contains &A7B8 which is the address of the Floating-Point SQR function [FWA = SQR(FWA)] |
7F2-7F3 | Contains &A5EE which is the address of the Floating-Point / function [FWA = {argp}/ FWA] |
7F4-7F5 | Contains &A6A6 which is the address of the Floating-Point * function [FWA = {argp}* FWA] |
7F6-7F7 | Contains &A68D which is the address of the Floating-Point + function [FWA = {argp}+ FWA] |
7F8-7F9 | Contains &ACCA which is the address of the Floating-Point Compliment function [FWA = -FWA] |
7FA-7FB | Contains &A541 which is the address of the Floating-Point Load function [FWA = {argp}] |
7FC-7FD | Contains &A519 which is the address of the Floating-Point Store function [{argp}= FWA] |
07FE | Contains &4A which is the start of the zero page location of argp (a pointer to a floating-point variable) |
07FF | Contains &2E which is the start of the zero page location for the FWA (Floating-Point working area A) |