Hello,
I think that Tony P has already answered your "biggest question".
The code snippet that you posted would redirect only the reset vector, with the new vector (that points to the start of your program) located at 0xF0FE. In fact this would apply to any low byte value for the RELVECT constant, with the present calculation method. This seems to imply that your bootloader code would start at address 0xF200 (on a 512 byte boundary), corresponding with a block protection boundary.
However, the particular code snippet shown would not apply to any of the other interrupt vectors, from 0xFFC0-0xFFFD. For these, there are two possibilities.
Case 1: Your bootloader does not utilise any interrupts.
You may use automatic vector relocation by setting the FNORED bit in the NVOPT flash register, and enabling flash block write protection. Assuming that all addresses 0xF200 and above are protected, the vectors will be automatically redirected to the address range 0xF1C0-0xF1FD, where the vector table for the application program would be placed.
Case 2: Your bootloader makes use of one or more interrupts.
Automatic relocation is not applicable, Each vector must be redirected using a sub-routines within the bootloader section. For the device you are using, a total of about twenty sub-routines would be required, since you don't know in advance which of the interrupts an application might use.
Each sub-routine would need to cater for saving and restoring the h-register value, as mentioned by Kef. Because of this, you might use a JSR ,x instruction, rather than JMP .x. This would require that the application ISR routines terminate with RTS, rather than RTI, (i.e. would not use the interrupt modifier, if programming the application in C).
ISR_TPM1OVF_: ; This location pointed to by vector at $FFE8 pshh ldhx #$F1E8 ; Relocated vector position ldhx ,x ; Fetch ISR address jsr ,x ; Execute ISR pulh rti
While the new vector table could be placed anywhere within the application code area, it is a good idea to stay with the standard location, as above.
I see that your current bootloader code is writing garbage to many of the vector locations (2.png). If using automatic relocation, each vector should remain unprogrammed (0xFFFF), or maybe point to a default location within the bootloader code. For coded relocation, each vector must point to a bootloader address.
Regards,
Mac