_entry (void)
{
_asm
movlb 0x0F //Address: 0x00 //Will be checking RB2 pushbutton state, but need to set ANCON1<PCFG8> bit first. ANCON1 register is not in access bank
bsf ANCON1, 0, 1 //Address: 0x02 //Configure RB2/AN8 as digital input
bra BootEntryIOCheck //Address: 0x04 //bra BootEntryIOCheck skips past the high-priority interrupt redirect
nop //Address: 0x06 //Filler to waste 2 byte of program memory
//HIGH PRIORITY INTRRUPT VECTOR at address 0x08
goto 0x1008 //Address: 0x08 //If a high priority interrupt occurs, PC first goes to 0x0008, then executes "goto 0x1008" redirect
BootEntryIOCheck:
//Perform an I/O pin check to see if we should enter either the main application firmware, or this bootloader firmware.
//Currently using RB2 I/O pin for this purpose. If pushbutton pressed (RB2 = 0), enter bootloader firmware.
//If not pressed (RB2 = 1, due to pull up resistor), enter the main application firmware instead.
btfss PORTB, 2, 0 //Address: 0x0C //Check RB2 I/O pin state
bra BootAppStart //Address: 0x0E //If pushbutton pressed, enter bootloader
//Otherwise, need to enter the main application firmware.
//Should restore state of BSR and ANCON1 registers to default state first.
bcf ANCON1, 0, 1 //Address: 0x10 //Restore ANCON1<PCFG8> bit to default
movlb 0x00 //Address: 0x12 //Restore BSR to POR default
goto 0x1000 //Address: 0x14 //Goto the main application firmware, user was not pressing the pushbutton to enter bootloader
//LOW PRIORITY INTERRUPT VECTOR at address 0x18
goto 0x1018 //Address: 0x18 //If a low-priority interrupt occurs, PC first goes to 0x0018, then executes "goto 0x1018" redirect
_endasm
BootAppStart: //Address: 0x1C //If executing the main application firmware, and user wishes to enter the bootloader
//simply execute an "_asm goto 0x001C _endasm" instruction. This will go to this BootAppStart section,
//which in turn will enter the bootloader firmware.
Main();
}