• No results found

BASIC Working Storage

In document Compute's Mapping the Commodore 128 (Page 111-115)

The remainder of page 3, locations 896-1023/$0380-$03FF, is used to hold BASIC character retrieval subroutines and to store values for a variety of BASIC routines. The subroutines in locations 896-980/$0380-$03D4 are copied here from loca- tions 17017-17101/$4279-$42CD in BASIC ROM during the BASIC cold-start sequence. The routines are not reinitialized by RUN/STOP-RESTORE.

896-926 $0380-$039E CHRGET

Main BASIC character retrieval routine

This is BASIC'S primary routine for reading program text for interpretation and execution. The routine is designed to re- trieve the next nonspace character from a BASIC line (in bank 0), and to return information about the type of character re- trieved. The routine begins by incrementing the current ad- dress in the text pointer at locations 61-62/$3D-$3E. The system is set for the bank 0 configuration, the value at the lo- cation specified in the pointer is loaded into the accumulator, and the system is reset for the bank 14 configuration. The rou- tine then performs a series of tests that will set the processor status register to reflect the type of character that was read. If a space character (code 32/$20) is read, the routine loops back to read another character (which is why spacing is not usually

866-875 S0362-S036B

from the right margin of the line above. Line linking can be disabled by setting the flag bit in location 248/$F8.

When the active display is switched, the screen editor SWAPPER routine [$CD2E] exchanges the contents of this area with the contents of locations 2666-2669/$0A6A-$0A6D, the storage area for the inactive display line link bitmap. Thus, the line link status is preserved when the screen is inactive.

Kernal File Tables

The following three ten-byte tables hold information on any currently open logical files. The three tables are parallel; the entry for a particular file will appear at the same position in all three tables. Location 152/$98 serves as an index to the next available entry in the tables. The fact that there are only ten bytes per table means that no more than ten logical files may be opened simultaneously.

866-875 $0362-$036B LATBL

Logical file number table for currently open files

When a logical file is opened, the OPEN routine [$EFBD] ex- amines the contents of this table. A FILE OPEN error occurs if an existing file already uses the specified logical file number, and a TOO MANY FILES error occurs if ten files are already open. Otherwise, the logical file number for the file is stored in the next available entry in this table. When the Kernal CHKIN [$F106] or CKOUT [$F14C] routines are used to select a logical file for input or output, this table is searched for the specified logical file number. A FILE NOT OPEN error occurs if the file number is not found in the table. Otherwise, the cor- responding device number and secondary address will be read from the respective tables. When a file is closed, the Kernal CLOSE routine [$F188] removes the file's entry from this table.

The Kernal includes a routine [LKUPLA, $F79D] to search for a particular file number in this table.

876-885 $036C-$0375 DNTBL

Device number table for currently open files

When a logical file is opened, the OPEN routine [$EFBD] stores the device number for the file in the next available en- try in this table. When the Kernal CHKIN [$F106] or CKOUT [$F14C] routines are used to select a logical file for input or

106

$0380-$039E 896-926

output, the device number for the selected file will be read from this table. When a file is closed, the Kernal CLOSE rou- tine [$F188] removes the file's entry from this table.

886-895 $0376-$037F SATBL

Secondary address table for currently open files

When a logical file is opened, the OPEN routine [$EFBD] will OR the specified secondary address for the file with the value 96/$60, then store the result in the next available entry in this table. When the Kernal CHKIN [$F106] or CKOUT [$F14C] routines are used to select a logical file for input or output, the secondary address for the selected file will be read from this table. When a file is closed, the Kernal CLOSE routine [$F188] removes the file's entry from this table.

The Kernal includes a routine [LKUPSA, $F786] to search for a particular secondary address in this table.

BASIC Working Storage

The remainder of page 3, locations 896-1023/$0380-$03FF, is used to hold BASIC character retrieval subroutines and to store values for a variety of BASIC routines. The subroutines in locations 896-980/$0380-$03D4 are copied here from loca- tions 17017-17101/$4279-$42CD in BASIC ROM during the BASIC cold-start sequence. The routines are not reinitialized by RUN/STOP-RESTORE.

896-926 $0380-$039E CHRGET

Main BASIC character retrieval routine

This is BASIC'S primary routine for reading program text for interpretation and execution. The routine is designed to re- trieve the next nonspace character from a BASIC line (in bank 0), and to return information about the type of character re- trieved. The routine begins by incrementing the current ad- dress in the text pointer at locations 61-62/$3D-$3E. The system is set for the bank 0 configuration, the value at the lo- cation specified in the pointer is loaded into the accumulator, and the system is reset for the bank 14 configuration. The rou- tine then performs a series of tests that will set the processor status register to reflect the type of character that was read. If a space character (code 32/$20) is read, the routine loops back to read another character (which is why spacing is not usually

927-938 $039F-$03AA

significant in BASIC program lines). If the character is one of the numbers 0-9, the carry bit will be clear (carry will be set if the character is not a digit). If the character was a colon (:), BASIC'S end-of-statement marker, or a zero byte, BASIC'S end-of-line marker, the status register Z bit will be set; other- wise, the Z bit will be clear.

This routine has an alternate entry point at 902/$386, called CHRGOT, which retrieves and tests the current charac- ter, the one at the address currently in 61-62/$3D-$3E, with- out updating the pointer.

Since this routine is in RAM, it can be modified to change the way BASIC program text is read. Refer to Chapter 5 for details on how you can use this technique to add new com- mands to BASIC.

927-938 $039F-$03AA INDSUB_RAMO

Alternate routine for reading characters from program text This routine retrieves a character from program text (bank 0). The value in the accumulator upon entry specifies the address of the zero-page pointer containing the base address, and the value in the Y register specifies the offset from this base ad- dress to the character to be read. The character will be in the accumulator upon return from the routine and the system will be left in the bank 14 configuration. BASIC ROM includes a collection of character retrieval subroutines (17102-17159/ $42CE-$4307) that make use of this routine.

939-950 $03AB-$03B6 INDSUB_RAM1

Alternate routine for reading characters from variable storage This routine retrieves a character from the variable storage area (bank 1). The value in the accumulator upon entry speci- fies the address of the zero-page pointer containing the base address, and the value in the Y register specifies the offset from this base address to the character to be read. The charac- ter will be in the accumulator upon return from the routine and the system will be left in the alternate bank 14 configura- tion that includes block 1 RAM. BASIC ROM includes a col- lection of character retrieval subroutines (17102-17159/ $42CE-$4307) that make use of this routine.

108

$03D2-$03D4 978-980

951-959 $03B7-$03BF INDIN1_RAM1

Alternate routine to retrieve a character from variable storage This routine retrieves a character from the variable storage area (bank 1) using locations 36-37/$24-$25 as a pointer and the contents of the Y register as an offset from the address in the pointer. The character will be in the accumulator upon re- turn from the routine and the system will be left in the alter- nate bank 14 configuration that includes block 1 RAM.

960-968 $03C0-$03C8 INDIN2

Alternate routine to retrieve a character from program text This routine retrieves a character from program text (bank 0) using locations 38-39/$26-$27 as a pointer and the contents of the Y register as an offset from the address in the pointer. The character will be in the accumulator upon return from the routine and the system will be left in the bank 14

configuration.

969-977 $03C9-$03Dl INDTXT

Alternate routine to retrieve current program text character This routine retrieves the current program text character using 61-62/$3D-$3E as a pointer. The character will be in the ac- cumulator upon return from the routine and the system will be left in the bank 14 configuration. The routine is similar to the CHRGOT entry into GHRGET, but without the tests for character type.

978-980 $03D2-$03D4 ZERO

Null descriptor

If the routine [$7AAF] which searches for a variable name in the variable table fails to find the name when called by EVAL [$7978] or POINTER [$82FA], the address of this area is re- turned as the variable descriptor address. This prevents vari- able table entries from being created if a variable name is first used in an expression argument or in the POINTER function. For example, if you use B$ = A$ or AD = POINTER(A$) when no variable A$ exists, no entry for A$ will be created. These three locations are all filled with the value 0/$00, copied here from ROM along with the preceding subroutines.

927-938 $039F-$03AA

significant in BASIC program lines). If the character is one of the numbers 0-9, the carry bit will be clear (carry will be set if the character is not a digit). If the character was a colon (:), BASIC'S end-of-statement marker, or a zero byte, BASIC'S end-of-line marker, the status register Z bit will be set; other- wise, the Z bit will be clear.

This routine has an alternate entry point at 902/$386, called CHRGOT, which retrieves and tests the current charac- ter, the one at the address currently in 61-62/$3D-$3E, with- out updating the pointer.

Since this routine is in RAM, it can be modified to change the way BASIC program text is read. Refer to Chapter 5 for details on how you can use this technique to add new com- mands to BASIC.

927-938 $039F-$03AA INDSUB_RAMO

Alternate routine for reading characters from program text This routine retrieves a character from program text (bank 0). The value in the accumulator upon entry specifies the address of the zero-page pointer containing the base address, and the value in the Y register specifies the offset from this base ad- dress to the character to be read. The character will be in the accumulator upon return from the routine and the system will be left in the bank 14 configuration. BASIC ROM includes a collection of character retrieval subroutines (17102-17159/ $42CE-$4307) that make use of this routine.

939-950 $03AB-$03B6 INDSUB_RAM1

Alternate routine for reading characters from variable storage This routine retrieves a character from the variable storage area (bank 1). The value in the accumulator upon entry speci- fies the address of the zero-page pointer containing the base address, and the value in the Y register specifies the offset from this base address to the character to be read. The charac- ter will be in the accumulator upon return from the routine and the system will be left in the alternate bank 14 configura- tion that includes block 1 RAM. BASIC ROM includes a col- lection of character retrieval subroutines (17102-17159/ $42CE-$4307) that make use of this routine.

$03D2-$03D4 978-980

951-959 $03B7-$03BF INDIN1_RAM1

Alternate routine to retrieve a character from variable storage This routine retrieves a character from the variable storage area (bank 1) using locations 36-37/$24-$25 as a pointer and the contents of the Y register as an offset from the address in the pointer. The character will be in the accumulator upon re- turn from the routine and the system will be left in the alter- nate bank 14 configuration that includes block 1 RAM.

960-968 $03C0-$03C8 INDIN2

Alternate routine to retrieve a character from program text This routine retrieves a character from program text (bank 0) using locations 38-39/$26-$27 as a pointer and the contents of the Y register as an offset from the address in the pointer. The character will be in the accumulator upon return from the routine and the system will be left in the bank 14

configuration.

969-977 $03C9-$03Dl INDTXT

Alternate routine to retrieve current program text character This routine retrieves the current program text character using 61-62/$3D-$3E as a pointer. The character will be in the ac- cumulator upon return from the routine and the system will be left in the bank 14 configuration. The routine is similar to the CHRGOT entry into GHRGET, but without the tests for character type.

978-980 $03D2-$03D4 ZERO

Null descriptor

If the routine [$7AAF] which searches for a variable name in the variable table fails to find the name when called by EVAL [$7978] or POINTER [$82FA], the address of this area is re- turned as the variable descriptor address. This prevents vari- able table entries from being created if a variable name is first used in an expression argument or in the POINTER function. For example, if you use B$ = A$ or AD = POINTER(A$) when no variable A$ exists, no entry for A$ will be created. These three locations are all filled with the value 0/$00, copied here from ROM along with the preceding subroutines.

981

S03D5

981 $03D5 CURRENT-BANK

In document Compute's Mapping the Commodore 128 (Page 111-115)