3072-3327/$0C00-$0CFF
The routines that receive characters via the RS-232 interface are executed during NMI interrupts. Any characters received are held in this area until they can be read, usually by using the Kernal GETIN routine. This is a circular buffer with no fixed beginning or end. Location 2585/S0A19 holds the offset
2816-3071
$0B00-$0BFF
Cassette Buffer and Disk Boot Buffer
2816-3071/$0B00-$0BFF
The first 192 bytes of this area (2818-3007/$0B00-$0BBF) are used for the cassette buffer. When you're reading from tape, file headers are loaded into this area until one is found with the specified filename. When you're writing to tape, this area is used to assemble the tape header for the file. When the buffer contains a tape header, the locations are used as follows: Location Function
2816/$0BO0 Header type identifier 2817-2818/$0B01-$0BO2 Starting address for file
Ending address for file Filename
2819-2820/$OB03-$OB04 2821-3007/$OB05-$OBBF
A header type identifier of 1 indicates a relocatable program file; 3 indicates a nonrelocatable program file; 4, a data file; and 5, an end-of-tape marker. A type identifier value of 2 means that the block contains data rather than a header. Al- though the filename can be up to 187 bytes long, such names are unusual. When a header is read into the buffer, only the first 16 characters of the filename will be displayed following the FOUND message. When a header is being assembled, all unused filename bytes will be set to 32/$20, the value for the space character.
The cassette buffer is used to hold blocks of data when data files are read from or written to tape. When a data file is being written, after the header is written to tape, the first byte here is set to 2, the identifier for a data block; then the re- maining 191 bytes are filled with the data to be written to the file. Only when the buffer is completely full is the block of data actually added to the file. This is why it is important to properly close any file opened for writing. If the file is not closed, the last block of data will not be written to tape. When a file is opened for reading, after the proper header is identi- fied, the first block of data is read into the buffer. Subsequent bytes will be read from the buffer—not directly from tape— until all 191 data bytes have been read from the buffer; then the next block will be read into the buffer. See Chapter 9 for more information on tape data storage.
In the 128, this area has a second function: the boot sector buffer. If the BOOT_CALL routine [$F890] finds a disk in the specified drive when it is called, the contents of sector 0 of
148
$0C00-$OCFF
3072-3327track 1 of the disk are read into this area. The first three bytes of the buffer are then examined. If those locations (the first three bytes from the sector) contain the character codes for the letters CBM, then the routine assumes that a boot disk has been found and proceeds with the boot process. Refer to the entry in Chapter 9 for details. It would be possible to simulate a boot by filling the buffer with the proper values, then jump- ing into the BOOT_CALL routine at address 63737/$F8F9.
The B0OT_CALL routine is normally executed during each reset as part of the BASIC cold-start sequence. It can also be called from the Kernal jump table entry at 65363/$FF53, and can be initiated from BASIC via the BOOT statement.
Actually, the cassette buffer is not located absolutely at this area. The base address of the cassette buffer is determined by the value in locations 178-179/$B2-$B3. Those locations are initialized to 2816/$0BO0 during the RAMTAS routine [$E093], part of the reset sequence. No system ROM routines change that setting, but another free 192-byte area could be used, with two restrictions: the buffer must start at an address greater than 511/S1FF, and the buffer must be visible in the bank 15 memory configuration. The disk-booting routines, on the other hand, do use the absolute address of this area. This area will always be used as the boot sector buffer, regardless of the value in the cassette buffer pointer.
If tape data storage is not being used, this 256-byte area is available for other uses, such as to hold short machine lan- guage routines. The cassette buffer has been a popular area for ML since the days of the first Commodore PET/CBM comput- ers. However, the contents of this area will be overwritten whenever the system attempts to boot a disk, including the time during any reset when the drive is turned on and con- tains a disk. You should choose another area if you want your machine language to survive intact following a reset.
RS-232 Input Buffer
3072-3327/$0C00-$0CFF
The routines that receive characters via the RS-232 interface are executed during NMI interrupts. Any characters received are held in this area until they can be read, usually by using the Kernal GETIN routine. This is a circular buffer with no fixed beginning or end. Location 2585/S0A19 holds the offset
3328-3583 $ODOO-$ODFF $1000-$10FF 4 0 9 6 - 4 3 5 1
from the starting address of the buffer to the next character waiting to be read (called the head of the buffer). Location 2584/$0A18 holds the offset to the next free position in the buffer (called the tail of the buffer). The buffer is considered empty when the two offset addresses are equal, and full when the buffer tail offset is one less than the head offset. Bits 2 and 3 of the RS-232 status byte at 2580/$0A14 indicate, respec- tively, when the buffer is full or empty.
Actually, the buffer is not located absolutely at this area. The starting address of the RS-232 input buffer is determined by the value in locations 200-201/$C8-$C9. The pointer loca- tions are initialized to 3072/S0C00 by the RAMTAS routine [$E093], part of the reset sequence. No other system routine changes the address in that pointer, so the buffer will be lo- cated here unless you explicitly move it. However, the buffer can be moved to another free area of memory simply by changing the address in the pointer. (The area selected must be visible in the bank 15 configuration.)
If RS-232 communications are not used, this buffer area, along with the one at 3328-3583/$0D00-$0DFF, is available for other purposes such as machine language routines or addi- tional sprite definitions.