The routines at 674-763/$02A2-$02FB are copied here from Kernal ROM at 63488-63577/$F800-$F859 by the routine at 57549/$E0CD, part of the reset sequence. The routines are placed here in page 2 because this is part of the IK 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 configura- tion 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 ad- dresses as BASIC ROM itself. These routines are so integral to the successful operation of the 128 that the system will proba- bly 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 682/$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 regis- ter contains 0/$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.
86
$02AF-$02BD
687-7011
The routine reads and stashes the current MMU configu- ration 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 accumu- lator. The MMU configuration register is restored to its original value before exiting.
This routine is normally called via its related Kernal rou- tine at 63440/$F7D0, which has a jump table entry at 65396/ $FF74. When calling via the Kernal routine, the accumulator should contain the zero-page pointer address; the Kernal rou- tine stores the accumulator value upon entry in 682/$02AA, performing that setup step for you. The X register should con- tain 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 speci- fied 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 2ero-page pointer in location 697/$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 regis- ter contains 0/$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 configu- ration 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 loca- tion 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 rou- tine at 63450/$F7DA, which has a jump table entry at
65399/$FF77. When calling via the Kernal routine, the X reg- ister should instead contain a bank number (0-15), since the
673
$O2A1
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 $O2A1 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 674-763/$02A2-$02FB are copied here from Kernal ROM at 63488-63577/$F800-$F859 by the routine at 57549/$E0CD, part of the reset sequence. The routines are placed here in page 2 because this is part of the IK 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 configura- tion 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 ad- dresses as BASIC ROM itself. These routines are so integral to the successful operation of the 128 that the system will proba- bly 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 682/$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 regis- ter contains 0/$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.
86
$02AF-$02BD
687-7011
The routine reads and stashes the current MMU configu- ration 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 accumu- lator. The MMU configuration register is restored to its original value before exiting.
This routine is normally called via its related Kernal rou- tine at 63440/$F7D0, which has a jump table entry at 65396/ $FF74. When calling via the Kernal routine, the accumulator should contain the zero-page pointer address; the Kernal rou- tine stores the accumulator value upon entry in 682/$02AA, performing that setup step for you. The X register should con- tain 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 speci- fied 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 2ero-page pointer in location 697/$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 regis- ter contains 0/$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 configu- ration 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 loca- tion 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 rou- tine at 63450/$F7DA, which has a jump table entry at
65399/$FF77. When calling via the Kernal routine, the X reg- ister should instead contain a bank number (0-15), since the
702-716 $02BE-$02CC
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 con- tents 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 712/$02C8. You can use the Y register to specify an offset from the pointer ad- dress for the target address, (If no offset is desired, be sure that the Y register contains 0/$00.) The X register should con- tain 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 configu- ration 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 regis- ter 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 rou- tine at 63459/$F7E3, which has a jump table entry at 65402/ $FF7A. When calling via the Kernal routine, the X register should instead contain a bank number (0-15), since that rou- tine 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 65390/$FF6E.) The routine here will jump to a subroutine at any address in any standard bank configuration. Upon completion of the tar- get routine, control is returned to the routine which called JSRFAR, just like a JSR. However, this routine leaves the sys- tem 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.
88
I
$02E3-$02FB 739-7631
Before calling the routine you must load location 2/$02 with the bank number (0-15) of the target routine and loca- tions 3-4/$03-$04 with the address of the target routine. In contrast to the usual low-byte/high-byte format, location 3/$03 should be loaded with the high byte of the address and location 4/$04 with the low byte. Location 5/$05 should be loaded with the value you want in the status register when the target routine is called (use 0/$00 if you don't want any status register bits set). Optionally, you can also load locations
6-8/$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 3-4 in the bank specified in location 2 and with the status register value specified in location 5 and processor register values from locations 6-8. Upon return from the target routine, the exit values of the accumulator, X register, and Y register are stored in location 6-8/$06-$08, respectively. The value of the status register upon exit from the target routine is stored in location 5/$05, and the exit value of the processor stack pointer is recorded in location 9/$09. Finally, the routine switches the system to the bank 15 configuration before re- turning 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 65393/SFF71.) The routine here will jump to a routine at any address in any standard bank configuration. Before calling the routine you must load location 2/$02 with the bank number (0-15) of the target routine and locations 3-4/$03-$04 with the address of the target routine. In contrast to the usual low-byte/high-byte format, location 3/$03 should be loaded with the high byte of the address and location 4/$04 with the low byte. Location 5/$05 should be loaded with the value you want in the status register when the target routine is called (use 0/$00 if you don't want any status register bits set). Optionally, you can also load locations 6-8/$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 ad- dress and status register values onto the stack, converts the bank number value to a configuration register value, stores
702-716 $02BE-$02CC
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 con- tents 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 712/$02C8. You can use the Y register to specify an offset from the pointer ad- dress for the target address, (If no offset is desired, be sure that the Y register contains 0/$00.) The X register should con- tain 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 configu- ration 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 regis- ter 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 rou- tine at 63459/$F7E3, which has a jump table entry at 65402/ $FF7A. When calling via the Kernal routine, the X register should instead contain a bank number (0-15), since that rou- tine 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 65390/$FF6E.) The routine here will jump to a subroutine at any address in any standard bank configuration. Upon completion of the tar- get routine, control is returned to the routine which called JSRFAR, just like a JSR. However, this routine leaves the sys- tem 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.
88
I
$02E3-$02FB 739-7631
Before calling the routine you must load location 2/$02 with the bank number (0-15) of the target routine and loca- tions 3-4/$03-$04 with the address of the target routine. In contrast to the usual low-byte/high-byte format, location 3/$03 should be loaded with the high byte of the address and location 4/$04 with the low byte. Location 5/$05 should be loaded with the value you want in the status register when the target routine is called (use 0/$00 if you don't want any status register bits set). Optionally, you can also load locations
6-8/$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 3-4 in the bank specified in location 2 and with the status register value specified in location 5 and processor register values from locations 6-8. Upon return from the target routine, the exit values of the accumulator, X register, and Y register are stored in location 6-8/$06-$08, respectively. The value of the status register upon exit from the target routine is stored in location 5/$05, and the exit value of the processor stack pointer is recorded in location 9/$09. Finally, the routine switches the system to the bank 15 configuration before re- turning 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 65393/SFF71.) The routine here will jump to a routine at any address in any standard bank configuration. Before calling the routine you must load location 2/$02 with the bank number (0-15) of the target routine and locations 3-4/$03-$04 with the address of the target routine. In contrast to the usual low-byte/high-byte format, location 3/$03 should be loaded with the high byte of the address and location 4/$04 with the low byte. Location 5/$05 should be loaded with the value you want in the status register when the target routine is called (use 0/$00 if you don't want any status register bits set). Optionally, you can also load locations 6-8/$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 ad- dress and status register values onto the stack, converts the bank number value to a configuration register value, stores
764-765 $02FC-$02FD $0304-$0305 772-773
that value in the MMU configuration register, loads the pro- cessor registers from locations 6-8, and executes an RTI in- struction, which causes the processor to retrieve status register and address values from the stack and resume processing at the specified address.