In this page...


Index

$0200-$02FF - Input Buffer, Common indirect routines, Indirect Vectors

Input Buffer

512-672 $0200-$02A0 BUF

BASIC and monitor input buffer

This 161-byte area is used to hold input for both BASIC and the monitor. The BASIC input routine $4F93 allows logical program lines up to 160 characters long to be entered. A byte with the value $00 is added following the last character of the input. If the line starts with a line number, the line here is tokenized and transferred to the BASIC program text area. An immediate mode line (one with no line number) is tokenized and then executed from the buffer. This buffer is also used to hold input characters for the GET, GET#, GETKEY, INPUT, and INPUT# statements, which is why those statements are not allowed in immediate mode. The monitor main loop $B08B accepts command strings up to 159 characters long, and also adds a zero byte following the last character of input to mark the end of the command.

673 $02A1 Unused

The BASIC and monitor input routines restrict the length of an input line to 160 characters plus a zero byte to mark the end of input in the buffer, for a maximum of 161 bytes. Thus, this location will never be used for input, and is available for other uses.

Common Indirect Routines

The routines at $02A2-$02FB are copied here from Kernal ROM at $F800-$F859 by the routine at $E0CD, part of the reset sequence. The routines are placed here in page 2 because this is part of the 1K block of memory that is visible in all banks. These routines are the key to the operation of the 128-they make the memory banking system possible by allowing a routine in one bank configuration to access data or call routines in another configuration. For example, these routines allow BASIC ROM routines to use different blocks of RAM for program text and variables, and to see program text in areas of RAM that lie at the same addresses as BASIC ROM itself. These routines are so integral to the successful operation of the 128 that the system will probably crash almost immediately if the routines are accidentally changed or overwritten.

674-686 $02A2-$02AE FETCH

Retrieves a value from any bank

This routine loads the accumulator value with the contents of a specified location in any bank. To use this routine, you must set up a two-byte pointer in zero page to hold the address of the target location, then store the one-byte address of the zero-page pointer in location $02AA. You can use the Y register to specify an offset from the pointer address for the target location. If no offset is desired, be sure that the Y register contains $00. The X register should contain the MMU configuration register setting value which will establish a memory configuration in which the target location is visible.

The routine reads and stashes the current MMU configuration register setting, then uses the value in the X register upon entry as the new configuration register setting. Next, the contents of the location specified by the address in the pointer plus the offset in the Y register are loaded into the accumulator. The MMU configuration register is restored to its original value before exiting.

This routine is normally called via its related Kernal routine at $F7D0, which has a jump table entry at $FF74. When calling via the Kernal routine, the accumulator should contain the zero-page pointer address; the Kernal routine stores the accumulator value upon entry in 682/$02AA, performing that setup step for you. The X register should contain a bank number (0-15) rather than an MMU configuration register setting value, since the Kernal routine also performs the chore of converting the bank number into a configuration register value.

687-701 $02AF-$02BD STASH

Stores a value in any bank

This routine stores the contents of the accumulator at a specified location in any bank. Before calling this routine, you must set up a two-byte pointer in zero page to hold the address of the target location, then store the one-byte address of the zero-page pointer in location $02B9. You can use the Y register to specify an offset from the pointer address for the target address. If no offset is desired, be sure that the Y register contains $00. The X register should contain the MMU configuration register setting value which will establish a memory configuration in which the target location is visible.

The routine reads and stashes the current MMU configuration register setting, then uses the value in the X register upon entry as the new configuration register setting. Next, the contents of the accumulator upon entry are stored in the location specified by the address in the pointer plus the offset in the Y register. The MMU configuration register is restored to its original value before exiting.

This routine is normally called via its related Kernal routine at $F7DA, which has a jump table entry at $FF77. When calling via the Kernal routine, the X register should instead contain a bank number (0-15), since the Kernal routine performs the chore of converting the bank number into an MMU configuration register setting value.

702-716 $02BE-$02CC CMPARE

Compares accumulator contents against a value from any bank

This routine compares the accumulator value against the contents of a specified location in any bank. Before calling this routine, you must set up a two-byte pointer in zero page to hold the address of the target location, then store the one-byte address of the zero-page pointer in location $02C8. You can use the Y register to specify an offset from the pointer address for the target address. If no offset is desired, be sure that the Y register contains $00. The X register should contain the MMU configuration register setting value which will establish a memory configuration in which the target location is visible.

This routine reads and stashes the current MMU configuration register setting, then uses the value in the X register upon entry as the new configuration register setting. Next, the value in the accumulator upon entry is compared against the contents of the location specified by the address in the pointer plus the offset in the Y register. The MMU configuration register is restored to its original value before exiting. The status register value will reflect the result of the comparison.

This routine is normally called via its related Kernal routine at $F7E3, which has a jump table entry at $FF7A. When calling via the Kernal routine, the X register should instead contain a bank number (0-15), since that routine performs the chore of converting the bank number into an MMU configuration register setting value.

717-738 $02CD-$02E2 JSRFAR

Calls a subroutine in any bank

This routine has a Kernal jump table entry at $FF6E

The routine here will jump to a subroutine at any address in any standard bank configuration. Upon completion of the target routine, control is returned to the routine which called JSRFAR, just like a JSR. However, this routine leaves the system in the bank 15 configuration, so a routine that uses JSRFAR must be located in an area of memory visible in the bank 15 configuration for JSRFAR to properly return to the calling routine.

Before calling the routine you must load location $02 with the bank number (0-15) of the target routine and locations $03-$04 with the address of the target routine. In contrast to the usuallow-byte/high-byte format, location $03 should be loaded with the high byte of the address and location $04 with the low byte. Location $05 should be loaded with the value you want in the status register when the target routine is called use $00 if you don’t want any status register bits set. Optionally, you can also load locations $06-$08 with any values you wish the accumulator, X register, and Y register, respectively, to have when the target routine is called.

The routine calls JMPFAR to call the subroutine addressed in locations $03-$04 in the bank specified in location $02 and with the status register value specified in location $05 and processor register values from locations $06-$08. Upon return from the target routine, the exit values of the accumulator, X register, and Y register are stored in location $06-$08, respectively. The value of the status register upon exit from the target routine is stored in location $05, and the exit value of the processor stack pointer is recorded in location $09. Finally, the routine switches the system to the bank 15 configuration before returning to the calling routine.

739-763 $02E3-$02FB JMPFAR

Jumps to a routine in any bank

This routine has a Kernal jump table entry at $FF71

The routine here will jump to a routine at any address in any standard bank configuration. Before calling the routine you must load location $02 with the bank number (0-15) of the target routine and locations $03-$04 with the address of the target routine. In contrast to the usuallow-byte/high-byte format, location $03 should be loaded with the high byte of the address and location $04 with the low byte. Location $05 should be loaded with the value you want in the status register when the target routine is called (use $00 if you don’t want any status register bits set). Optionally, you can also load locations $06-$08 with any values you wish the accumulator, X register, and Y register, respectively, to have when the target routine is called. The routine pushes the address and status register values onto the stack, converts the bank number value to a configuration register value, stores that value in the MMU configuration register, loads the processor registers from locations $06-$08, and executes an RTI instruction, which causes the processor to retrieve status register and address values from the stack and resume processing at the specified address.

Indirect Vectors

The next 66 locations are indirect vectors for a variety of BASIC, Kernal, and screen editor routines. An indirect vector is a pair of locations that hold an address for an indirect jump instruction, such as JMP ($0300). The target address of the JMP will be determined by the value in the specified indirect vector. Having ROM routines jump through indirect vectors greatly increases the flexibility of the computer. Even though it isn’t possible to change a routine in ROM, it’s possible to add to or modify a routine that has an indirect vector by redirecting the vector to a RAM-based routine.

764-765 $02FC-$02FD ESC_FN_VEC

Indirect vector in extended function execution routine

The indirect jump through this vector is taken in the extended function handling subroutine when a two-byte extended function token is found for which the second byte is greater than the largest standard extended function token ($0A). When the jump is taken, the accumulator will hold the out-of-range token value and the status register carry bit will be set. If carry is not clear upon return from the jump, a SYNTAX error message will be generated. The vector normally holds $4C78, the address of the instruction following the call to this vector. This doesn’t change the carry setting, so out-of-range extended function tokens normally result in an error message. If you add new functions to BASIC, you’ll need to change this vector to point to the routine which executes your new function.

766-767 $02FE-$02FF BNKVEC

Reserved indirect vector

These two locations are not used by system ROM routines. Commodore literature indicates that they are reserved for use as an indirect vector for function ROM routines.