RESIDENT PROGRAMS

Some BIN or NCF files may install code somewhere in memory and link it to ProDOS File Navigator to extend existing functionality. These are called "resident," because part of the code stays in memory even after the code to install it has finished executing. If you do this, you will have to install the resident code above $7000, so that ProDOS File Navigator will not mess with it. Also, you will need some way of getting PFN to execute your code. The easiest way to do this is to put the address of your routine in the keyboard handler, so that pressing a key will call it. You can also change the functionality of an existing routine by "hijacking" it, but this is more complicated because it requires a deep understanding of PFN at the machine language level, and it is very likely to break whenever ProDOS File Navigator changes.

At $4019 is the address of the first keyboard check; starting at this address, the program compares the accumulator, containing the key pressed, with #$41, or A. If it is not equal, it branches to the next keyboard check. Otherwise, it jumps to a routine somewhere in PFN itself. In other words, starting at this address, the code looks like this:

ISNTUPER:   CMP #$41        ;A - About
            BNE KBD0
            JMP KABOUT
KBD0:       CMP #$42        ;B - Back
            BNE KBD1
            JMP KBACK
KBD1:       CMP #$43        ;C - Create
            BNE KBD2
            JMP KCREATE
KBD2:       . . .

It is in this code where you install your routine. First, take the address at $4019, which gets you to the start of the first keyboard check. Skip five bytes, which gets you to where the address of the first command, About, is stored. You may insert the address of your own routine here if you wish to override the About command. Skip another seven bytes to get to the address of the next command, Back. Keep skipping seven bytes until you get to the key you want to install your command under. In other words, if you want to install your routine under the nth key in the keyboard check, with n=0 being the A key, the memory location where you want to put the address of your routine is:

($4019) + 5 + 7n

($4019) means the contents of $4019, just as LDA ($06),Y means the contents of $06, plus Y, in assembly language.

The order of the keys is A-Z, followed by Up, Down, Left, Right, Return, Escape, Space, and the exclamation point. (The exclamation point will reset the screen if anything messes it up -- switches it to 40-column mode, for instance.) The letters currently not assigned to anything are G, H, J, K, N, W, X, and Z.

After the address of the ! routine is a JMP back to PFN's main event loop, where it waits for another keypress. You may change this to jump to your own keyboard checking routine, if you want to add more keypresses than PFN currently checks for. Just make sure to jump back to the address you originally found here; this ensures that if multiple programs add on to the keyboard check, control will pass through each of their keyboard checking routines.


If you need clarity on any of this, which you probably will, feel free to send any questions to support @ kreativekorp . cjb . net.
