
_Start_program:

;bootfor16_E2.mbas,43 :: 		sub procedure Start_program() org(__FLASH_SIZE - 8)   'find top 8 words of Prog ROM
;bootfor16_E2.mbas,44 :: 		nop  nop  nop  nop
	NOP
	NOP
	NOP
	NOP
;bootfor16_E2.mbas,45 :: 		nop  nop  nop           'some of these NOPs get overwritten by
	NOP
	NOP
	NOP
;bootfor16_E2.mbas,48 :: 		end sub
L_end_Start_program:
	RETURN
; end of _Start_program

bootfor16_E2_Erase_Prog:

;bootfor16_E2.mbas,70 :: 		Sub procedure Erase_Prog()    'only called by program routine, so local to module
;bootfor16_E2.mbas,71 :: 		EEADRL = lo(uadd)
	MOVF       bootfor16_E2_uadd+0, 0
	MOVWF      EEADRL+0
;bootfor16_E2.mbas,72 :: 		EEADRH = hi(uadd)
	MOVF       bootfor16_E2_uadd+1, 0
	MOVWF      EEADRH+0
;bootfor16_E2.mbas,73 :: 		setbit   (EECON1,EEPGD)
	BSF        EECON1+0, 7
;bootfor16_E2.mbas,74 :: 		ClearBit (EECON1,CFGS)
	BCF        EECON1+0, 6
;bootfor16_E2.mbas,75 :: 		SetBit   (EECON1,FREE)   'tells uC to clear 32 words from address above
	BSF        EECON1+0, 4
;bootfor16_E2.mbas,76 :: 		SetBit   (EECON1,WREN)
	BSF        EECON1+0, 2
;bootfor16_E2.mbas,77 :: 		EECON2 = 0x55
	MOVLW      85
	MOVWF      EECON2+0
;bootfor16_E2.mbas,78 :: 		EECON2 = 0XAA
	MOVLW      170
	MOVWF      EECON2+0
;bootfor16_E2.mbas,79 :: 		SetBit (EECON1,WR)        'start erase of 32 words
	BSF        EECON1+0, 1
;bootfor16_E2.mbas,80 :: 		nop
	NOP
;bootfor16_E2.mbas,81 :: 		nop
	NOP
;bootfor16_E2.mbas,82 :: 		while EECON1.FREE         'FREE is cleared by HW at end of erase
L_bootfor16_E2_Erase_Prog3:
	BTFSC      EECON1+0, 4
	GOTO       L_bootfor16_E2_Erase_Prog3
;bootfor16_E2.mbas,84 :: 		end sub
L_end_Erase_Prog:
	RETURN
; end of bootfor16_E2_Erase_Prog

bootfor16_E2_Write_Prog:

;bootfor16_E2.mbas,87 :: 		dim i as byte 'local i, no relation to any other i
;bootfor16_E2.mbas,93 :: 		intsave = INTCON             'save for restore later
	MOVF       INTCON+0, 0
	MOVWF      bootfor16_E2_intsave+0
;bootfor16_E2.mbas,94 :: 		clearbit (INTCON,GIE)        'stop any ints for now, restore at end of programming
	BCF        INTCON+0, 7
;bootfor16_E2.mbas,95 :: 		uadd = madd <<5              'shift page to get true address
	MOVLW      5
	MOVWF      R0
	MOVF       FARG_Write_Prog_madd+0, 0
	MOVWF      bootfor16_E2_uadd+0
	MOVF       FARG_Write_Prog_madd+1, 0
	MOVWF      bootfor16_E2_uadd+1
	MOVF       R0, 0
L_bootfor16_E2_Write_Prog80:
	BTFSC      STATUS+0, 2
	GOTO       L_bootfor16_E2_Write_Prog81
	LSLF       bootfor16_E2_uadd+0, 1
	RLF        bootfor16_E2_uadd+1, 1
	ADDLW      255
	GOTO       L_bootfor16_E2_Write_Prog80
L_bootfor16_E2_Write_Prog81:
;bootfor16_E2.mbas,96 :: 		Erase_Prog()                 'do erase
	CALL       bootfor16_E2_Erase_Prog+0
;bootfor16_E2.mbas,98 :: 		for i = 0 to 31                'do it 32 times
	CLRF       Write_Prog_i+0
L_bootfor16_E2_Write_Prog9:
;bootfor16_E2.mbas,99 :: 		EEADRL =  lo(uadd + i)     'get lower address byte (0-7)
	MOVF       Write_Prog_i+0, 0
	ADDWF      bootfor16_E2_uadd+0, 0
	MOVWF      R0
	MOVLW      0
	ADDWFC     bootfor16_E2_uadd+1, 0
	MOVWF      R1
	MOVF       R0, 0
	MOVWF      EEADRL+0
;bootfor16_E2.mbas,100 :: 		EEADRH =  hi(uadd)         'get higher address byte (8-14)
	MOVF       bootfor16_E2_uadd+1, 0
	MOVWF      EEADRH+0
;bootfor16_E2.mbas,101 :: 		EEDATL =  lo(Block[i])     'get lower data byte
	MOVF       Write_Prog_i+0, 0
	MOVWF      R0
	CLRF       R1
	LSLF       R0, 1
	RLF        R1, 1
	MOVLW      bootfor16_E2_block+0
	ADDWF      R0, 0
	MOVWF      FSR0L
	MOVLW      hi_addr(bootfor16_E2_block+0)
	ADDWFC     R1, 0
	MOVWF      FSR0H
	MOVF       INDF0+0, 0
	MOVWF      EEDATL+0
;bootfor16_E2.mbas,102 :: 		EEDATH =  hi(Block[i])     'get higher data byte (8-15)
	MOVLW      bootfor16_E2_block+0
	ADDWF      R0, 1
	MOVLW      hi_addr(bootfor16_E2_block+0)
	ADDWFC     R1, 1
	MOVLW      1
	ADDWF      R0, 0
	MOVWF      FSR0L
	MOVLW      0
	ADDWFC     R1, 0
	MOVWF      FSR0H
	MOVF       INDF0+0, 0
	MOVWF      EEDATH+0
;bootfor16_E2.mbas,103 :: 		setbit   (EECON1,EEPGD)    'EEPROM area
	BSF        EECON1+0, 7
;bootfor16_E2.mbas,104 :: 		ClearBit (EECON1,CFGS)     'Not CONFIG area
	BCF        EECON1+0, 6
;bootfor16_E2.mbas,105 :: 		SetBit   (EECON1,LWLO)     'Set to write to latches
	BSF        EECON1+0, 5
;bootfor16_E2.mbas,106 :: 		SetBit   (EECON1,WREN)     'Enable writes
	BSF        EECON1+0, 2
;bootfor16_E2.mbas,110 :: 		case 7,15,23,31  clearBit(EECON1, LWLO)  'clear to write to memory
	MOVF       Write_Prog_i+0, 0
	XORLW      7
	BTFSS      STATUS+0, 2
	GOTO       L_bootfor16_E2_Write_Prog16
	GOTO       L_bootfor16_E2_Write_Prog14
L_bootfor16_E2_Write_Prog16:
	MOVF       Write_Prog_i+0, 0
	XORLW      15
	BTFSS      STATUS+0, 2
	GOTO       L_bootfor16_E2_Write_Prog17
	GOTO       L_bootfor16_E2_Write_Prog14
L_bootfor16_E2_Write_Prog17:
	MOVF       Write_Prog_i+0, 0
	XORLW      23
	BTFSS      STATUS+0, 2
	GOTO       L_bootfor16_E2_Write_Prog18
	GOTO       L_bootfor16_E2_Write_Prog14
L_bootfor16_E2_Write_Prog18:
	MOVF       Write_Prog_i+0, 0
	XORLW      31
	BTFSS      STATUS+0, 2
	GOTO       L_bootfor16_E2_Write_Prog19
L_bootfor16_E2_Write_Prog14:
	BCF        EECON1+0, 5
	GOTO       L_bootfor16_E2_Write_Prog13
L_bootfor16_E2_Write_Prog19:
L_bootfor16_E2_Write_Prog13:
;bootfor16_E2.mbas,113 :: 		EECON2 = 0x55          'EEPROM write sequence
	MOVLW      85
	MOVWF      EECON2+0
;bootfor16_E2.mbas,114 :: 		EECON2 = 0XAA
	MOVLW      170
	MOVWF      EECON2+0
;bootfor16_E2.mbas,115 :: 		SetBit (EECON1,WR)     'start write to latch if LWLO = 1 or memory if LWL = 0
	BSF        EECON1+0, 1
;bootfor16_E2.mbas,116 :: 		nop                    'stops at first nop, uC suspends everything until write is done
	NOP
;bootfor16_E2.mbas,117 :: 		nop
	NOP
;bootfor16_E2.mbas,118 :: 		while EECON1.WR        'belt & braces check of WR bit, cleared by HW at end of prog
L_bootfor16_E2_Write_Prog21:
	BTFSC      EECON1+0, 1
	GOTO       L_bootfor16_E2_Write_Prog21
;bootfor16_E2.mbas,121 :: 		next i                     'do for all 32 words in store
	MOVF       Write_Prog_i+0, 0
	XORLW      31
	BTFSC      STATUS+0, 2
	GOTO       L_bootfor16_E2_Write_Prog12
	INCF       Write_Prog_i+0, 1
	GOTO       L_bootfor16_E2_Write_Prog9
L_bootfor16_E2_Write_Prog12:
;bootfor16_E2.mbas,123 :: 		ClearBit (EECON1,WREN)        'no more EEPROM writes now
	BCF        EECON1+0, 2
;bootfor16_E2.mbas,124 :: 		INTCON = intsave              'restore intcon
	MOVF       bootfor16_E2_intsave+0, 0
	MOVWF      INTCON+0
;bootfor16_E2.mbas,125 :: 		end sub
L_end_Write_Prog:
	RETURN
; end of bootfor16_E2_Write_Prog

_Usart_Write_Loop:

;bootfor16_E2.mbas,128 :: 		dim stop_flag, r, tmp as byte
;bootfor16_E2.mbas,129 :: 		r     = 0
	CLRF       Usart_Write_Loop_r+0
;bootfor16_E2.mbas,130 :: 		stop_flag  = 0
	CLRF       Usart_Write_Loop_stop_flag+0
;bootfor16_E2.mbas,131 :: 		while (stop_flag <> 1)
L__Usart_Write_Loop27:
	MOVF       Usart_Write_Loop_stop_flag+0, 0
	XORLW      1
	BTFSC      STATUS+0, 2
	GOTO       L__Usart_Write_Loop28
;bootfor16_E2.mbas,132 :: 		Delay_ms(5)
	MOVLW      13
	MOVWF      R12
	MOVLW      251
	MOVWF      R13
L__Usart_Write_Loop31:
	DECFSZ     R13, 1
	GOTO       L__Usart_Write_Loop31
	DECFSZ     R12, 1
	GOTO       L__Usart_Write_Loop31
	NOP
	NOP
;bootfor16_E2.mbas,133 :: 		uw(send)
	MOVF       FARG_Usart_Write_Loop_send+0, 0
	MOVWF      FARG_uw_in+0
	CALL       _uw+0
;bootfor16_E2.mbas,134 :: 		Delay_ms(5)
	MOVLW      13
	MOVWF      R12
	MOVLW      251
	MOVWF      R13
L__Usart_Write_Loop32:
	DECFSZ     R13, 1
	GOTO       L__Usart_Write_Loop32
	DECFSZ     R12, 1
	GOTO       L__Usart_Write_Loop32
	NOP
	NOP
;bootfor16_E2.mbas,135 :: 		tmp  = 0
	CLRF       Usart_Write_Loop_tmp+0
;bootfor16_E2.mbas,136 :: 		if UART1_Data_Ready then
	CALL       _UART1_Data_Ready+0
	MOVF       R0, 0
	BTFSC      STATUS+0, 2
	GOTO       L__Usart_Write_Loop34
;bootfor16_E2.mbas,137 :: 		tmp  = UART1_Read
	CALL       _UART1_Read+0
	MOVF       R0, 0
	MOVWF      Usart_Write_Loop_tmp+0
L__Usart_Write_Loop34:
;bootfor16_E2.mbas,139 :: 		Inc(r)
	INCF       Usart_Write_Loop_r+0, 1
;bootfor16_E2.mbas,140 :: 		if ((r = 255) or (tmp = receive)) then  ' if r = 255 -> 255 chars arrived, none of them matched
	MOVF       Usart_Write_Loop_r+0, 0
	XORLW      255
	MOVLW      255
	BTFSS      STATUS+0, 2
	MOVLW      0
	MOVWF      R1
	MOVF       Usart_Write_Loop_tmp+0, 0
	XORWF      FARG_Usart_Write_Loop_receive+0, 0
	MOVLW      255
	BTFSS      STATUS+0, 2
	MOVLW      0
	MOVWF      R0
	MOVF       R1, 0
	IORWF       R0, 1
	BTFSC      STATUS+0, 2
	GOTO       L__Usart_Write_Loop37
;bootfor16_E2.mbas,141 :: 		stop_flag  = 1
	MOVLW      1
	MOVWF      Usart_Write_Loop_stop_flag+0
L__Usart_Write_Loop37:
;bootfor16_E2.mbas,143 :: 		wend
	GOTO       L__Usart_Write_Loop27
L__Usart_Write_Loop28:
;bootfor16_E2.mbas,144 :: 		result  = r
	MOVF       Usart_Write_Loop_r+0, 0
	MOVWF      Usart_Write_Loop_local_result+0
;bootfor16_E2.mbas,145 :: 		end sub
	MOVF       Usart_Write_Loop_local_result+0, 0
	MOVWF      R0
L_end_Usart_Write_Loop:
	RETURN
; end of _Usart_Write_Loop

bootfor16_E2_Write_Begin:

;bootfor16_E2.mbas,172 :: 		dim i as byte                    'local counter
;bootfor16_E2.mbas,173 :: 		topm = (__FLASH_SIZE - 32)     'locates the top 32 bytes of Program ROM
	MOVLW      224
	MOVWF      bootfor16_E2_topm+0
	MOVLW      63
	MOVWF      bootfor16_E2_topm+1
;bootfor16_E2.mbas,174 :: 		rcv_1 = Flash_Read(0x0000)     'original page setting
	CLRF       FARG_FLASH_Read_address+0
	CLRF       FARG_FLASH_Read_address+1
	CALL       _FLASH_Read+0
	MOVF       R0, 0
	MOVWF      bootfor16_E2_rcv_1+0
	MOVF       R1, 0
	MOVWF      bootfor16_E2_rcv_1+1
;bootfor16_E2.mbas,175 :: 		rcv_2 = Flash_read(0x0001)     'original goto main for bootloader
	MOVLW      1
	MOVWF      FARG_FLASH_Read_address+0
	CLRF       FARG_FLASH_Read_address+1
	CALL       _FLASH_Read+0
	MOVF       R0, 0
	MOVWF      bootfor16_E2_rcv_2+0
	MOVF       R1, 0
	MOVWF      bootfor16_E2_rcv_2+1
;bootfor16_E2.mbas,176 :: 		for i = 0 to 31
	CLRF       Write_Begin_i+0
L_bootfor16_E2_Write_Begin41:
;bootfor16_E2.mbas,177 :: 		psave[i] = block[i]         'save 32 words, replace with NOPS
	MOVLW      Write_Begin_psave+0
	MOVWF      R3
	MOVLW      hi_addr(Write_Begin_psave+0)
	MOVWF      R4
	MOVF       Write_Begin_i+0, 0
	MOVWF      R0
	CLRF       R1
	LSLF       R0, 1
	RLF        R1, 1
	MOVF       R0, 0
	ADDWF      R3, 0
	MOVWF      FSR1L
	MOVF       R1, 0
	ADDWFC     R4, 0
	MOVWF      FSR1H
	MOVLW      bootfor16_E2_block+0
	ADDWF      R0, 0
	MOVWF      FSR0L
	MOVLW      hi_addr(bootfor16_E2_block+0)
	ADDWFC     R1, 0
	MOVWF      FSR0H
	MOVF       INDF0+0, 0
	MOVWF      INDF1+0
	ADDFSR     0, 1
	MOVF       INDF0+0, 0
	ADDFSR     1, 1
	MOVWF      INDF1+0
;bootfor16_E2.mbas,178 :: 		block[i] = 0x0000
	MOVF       Write_Begin_i+0, 0
	MOVWF      R0
	CLRF       R1
	LSLF       R0, 1
	RLF        R1, 1
	MOVLW      bootfor16_E2_block+0
	ADDWF      R0, 0
	MOVWF      FSR1L
	MOVLW      hi_addr(bootfor16_E2_block+0)
	ADDWFC     R1, 0
	MOVWF      FSR1H
	CLRF       INDF1+0
	ADDFSR     1, 1
	CLRF       INDF1+0
;bootfor16_E2.mbas,179 :: 		next i
	MOVF       Write_Begin_i+0, 0
	XORLW      31
	BTFSC      STATUS+0, 2
	GOTO       L_bootfor16_E2_Write_Begin44
	INCF       Write_Begin_i+0, 1
	GOTO       L_bootfor16_E2_Write_Begin41
L_bootfor16_E2_Write_Begin44:
;bootfor16_E2.mbas,184 :: 		block[24] = 0x3180          ' Movlp 0x000 Pclath to get to page 00
	MOVLW      128
	MOVWF      bootfor16_E2_block+48
	MOVLW      49
	MOVWF      bootfor16_E2_block+49
;bootfor16_E2.mbas,185 :: 		for i = 0 to 4
	CLRF       Write_Begin_i+0
L_bootfor16_E2_Write_Begin46:
;bootfor16_E2.mbas,186 :: 		block[i + 25] = psave[i] 'will include GOTO and any other instructions from
	MOVLW      25
	ADDWF      Write_Begin_i+0, 0
	MOVWF      R3
	MOVF       R3, 0
	MOVWF      R0
	CLRF       R1
	LSLF       R0, 1
	RLF        R1, 1
	MOVLW      bootfor16_E2_block+0
	ADDWF      R0, 0
	MOVWF      FSR1L
	MOVLW      hi_addr(bootfor16_E2_block+0)
	ADDWFC     R1, 0
	MOVWF      FSR1H
	MOVLW      Write_Begin_psave+0
	MOVWF      R3
	MOVLW      hi_addr(Write_Begin_psave+0)
	MOVWF      R4
	MOVF       Write_Begin_i+0, 0
	MOVWF      R0
	CLRF       R1
	LSLF       R0, 1
	RLF        R1, 1
	MOVF       R0, 0
	ADDWF      R3, 0
	MOVWF      FSR0L
	MOVF       R1, 0
	ADDWFC     R4, 0
	MOVWF      FSR0H
	MOVF       INDF0+0, 0
	MOVWF      INDF1+0
	ADDFSR     0, 1
	MOVF       INDF0+0, 0
	ADDFSR     1, 1
	MOVWF      INDF1+0
;bootfor16_E2.mbas,187 :: 		next i                      'original program below 0x0005
	MOVF       Write_Begin_i+0, 0
	XORLW      4
	BTFSC      STATUS+0, 2
	GOTO       L_bootfor16_E2_Write_Begin49
	INCF       Write_Begin_i+0, 1
	GOTO       L_bootfor16_E2_Write_Begin46
L_bootfor16_E2_Write_Begin49:
;bootfor16_E2.mbas,188 :: 		block[29] = 0x0000
	CLRF       bootfor16_E2_block+58
	CLRF       bootfor16_E2_block+59
;bootfor16_E2.mbas,189 :: 		block[30] = 0x0000
	CLRF       bootfor16_E2_block+60
	CLRF       bootfor16_E2_block+61
;bootfor16_E2.mbas,190 :: 		block[31] = 0x0008        'now have data to write in Block [0-31]
	MOVLW      8
	MOVWF      bootfor16_E2_block+62
	CLRF       bootfor16_E2_block+63
;bootfor16_E2.mbas,192 :: 		Write_prog (topm >>5)        'overwrites the top 32 words of ROM
	MOVLW      5
	MOVWF      R0
	MOVF       bootfor16_E2_topm+0, 0
	MOVWF      FARG_Write_Prog_madd+0
	MOVF       bootfor16_E2_topm+1, 0
	MOVWF      FARG_Write_Prog_madd+1
	MOVF       R0, 0
L_bootfor16_E2_Write_Begin84:
	BTFSC      STATUS+0, 2
	GOTO       L_bootfor16_E2_Write_Begin85
	LSRF       FARG_Write_Prog_madd+1, 1
	RRF        FARG_Write_Prog_madd+0, 1
	ADDLW      255
	GOTO       L_bootfor16_E2_Write_Begin84
L_bootfor16_E2_Write_Begin85:
	CALL       bootfor16_E2_Write_Prog+0
;bootfor16_E2.mbas,193 :: 		Block[0] = rcv_1  'restore original page + goto boot_main
	MOVF       bootfor16_E2_rcv_1+0, 0
	MOVWF      bootfor16_E2_block+0
	MOVF       bootfor16_E2_rcv_1+1, 0
	MOVWF      bootfor16_E2_block+1
;bootfor16_E2.mbas,194 :: 		block[1] = rcv_2  'from orginal bootloader program data
	MOVF       bootfor16_E2_rcv_2+0, 0
	MOVWF      bootfor16_E2_block+2
	MOVF       bootfor16_E2_rcv_2+1, 0
	MOVWF      bootfor16_E2_block+3
;bootfor16_E2.mbas,196 :: 		for i = 2 to 31
	MOVLW      2
	MOVWF      Write_Begin_i+0
L_bootfor16_E2_Write_Begin51:
;bootfor16_E2.mbas,197 :: 		block[i]  = psave[i]         'restore program data except 0 & 1
	MOVF       Write_Begin_i+0, 0
	MOVWF      R2
	CLRF       R3
	LSLF       R2, 1
	RLF        R3, 1
	MOVLW      bootfor16_E2_block+0
	ADDWF      R2, 0
	MOVWF      FSR1L
	MOVLW      hi_addr(bootfor16_E2_block+0)
	ADDWFC     R3, 0
	MOVWF      FSR1H
	MOVLW      Write_Begin_psave+0
	MOVWF      R0
	MOVLW      hi_addr(Write_Begin_psave+0)
	MOVWF      R1
	MOVF       R2, 0
	ADDWF      R0, 0
	MOVWF      FSR0L
	MOVF       R3, 0
	ADDWFC     R1, 0
	MOVWF      FSR0H
	MOVF       INDF0+0, 0
	MOVWF      INDF1+0
	ADDFSR     0, 1
	MOVF       INDF0+0, 0
	ADDFSR     1, 1
	MOVWF      INDF1+0
;bootfor16_E2.mbas,198 :: 		next i
	MOVF       Write_Begin_i+0, 0
	XORLW      31
	BTFSC      STATUS+0, 2
	GOTO       L_bootfor16_E2_Write_Begin54
	INCF       Write_Begin_i+0, 1
	GOTO       L_bootfor16_E2_Write_Begin51
L_bootfor16_E2_Write_Begin54:
;bootfor16_E2.mbas,199 :: 		end sub
L_end_Write_Begin:
	RETURN
; end of bootfor16_E2_Write_Begin

_Start_Bootload:

;bootfor16_E2.mbas,221 :: 		j as word        'j * 32. 0 based addressing. i is position in block
;bootfor16_E2.mbas,222 :: 		i  = 0             'creates an array of j x 32 words in ROM when written
	CLRF       Start_Bootload_i+0
;bootfor16_E2.mbas,223 :: 		j  = 0
	CLRF       Start_Bootload_j+0
	CLRF       Start_Bootload_j+1
;bootfor16_E2.mbas,224 :: 		while true
L__Start_Bootload57:
;bootfor16_E2.mbas,225 :: 		if (i = 32) then               ' If 32 words received then erase flash
	MOVF       Start_Bootload_i+0, 0
	XORLW      32
	BTFSS      STATUS+0, 2
	GOTO       L__Start_Bootload62
;bootfor16_E2.mbas,226 :: 		if (j = 0) then          ' The first block of 32 instructions contains "GOTO MAIN"
	MOVLW      0
	XORWF      Start_Bootload_j+1, 0
	BTFSS      STATUS+0, 2
	GOTO       L__Start_Bootload87
	MOVLW      0
	XORWF      Start_Bootload_j+0, 0
L__Start_Bootload87:
	BTFSS      STATUS+0, 2
	GOTO       L__Start_Bootload65
;bootfor16_E2.mbas,227 :: 		Write_Begin()          'and gets written to very top of ROM
	CALL       bootfor16_E2_Write_Begin+0
L__Start_Bootload65:
;bootfor16_E2.mbas,229 :: 		Write_prog(j)            'j gets multiplied by 32 and is a "page" pointer to
	MOVF       Start_Bootload_j+0, 0
	MOVWF      FARG_Write_Prog_madd+0
	MOVF       Start_Bootload_j+1, 0
	MOVWF      FARG_Write_Prog_madd+1
	CALL       bootfor16_E2_Write_Prog+0
;bootfor16_E2.mbas,231 :: 		i  = 0
	CLRF       Start_Bootload_i+0
;bootfor16_E2.mbas,232 :: 		Inc(j)                  'note j is never reset here but just increments
	INCF       Start_Bootload_j+0, 1
	BTFSC      STATUS+0, 2
	INCF       Start_Bootload_j+1, 1
L__Start_Bootload62:
;bootfor16_E2.mbas,235 :: 		uw("y")                        ' Ask for data low byte
	MOVLW      121
	MOVWF      FARG_uw_in+0
	CALL       _uw+0
;bootfor16_E2.mbas,236 :: 		do
L__Start_Bootload67:
;bootfor16_E2.mbas,237 :: 		nop
	NOP
;bootfor16_E2.mbas,238 :: 		loop until (Uart1_Data_Ready() = 1)
	CALL       _UART1_Data_Ready+0
	MOVF       R0, 0
	XORLW      1
	BTFSC      STATUS+0, 2
	GOTO       L__Start_Bootload70
	GOTO       L__Start_Bootload67
L__Start_Bootload70:
;bootfor16_E2.mbas,239 :: 		rcv_2  = Uart1_Read()              ' Read rcv_2
	CALL       _UART1_Read+0
	MOVF       R0, 0
	MOVWF      bootfor16_E2_rcv_2+0
	CLRF       bootfor16_E2_rcv_2+1
;bootfor16_E2.mbas,240 :: 		uw("x")                            ' Ask for data high byte
	MOVLW      120
	MOVWF      FARG_uw_in+0
	CALL       _uw+0
;bootfor16_E2.mbas,241 :: 		do
L__Start_Bootload72:
;bootfor16_E2.mbas,242 :: 		nop
	NOP
;bootfor16_E2.mbas,243 :: 		loop until (Uart1_Data_Ready() = 1)
	CALL       _UART1_Data_Ready+0
	MOVF       R0, 0
	XORLW      1
	BTFSC      STATUS+0, 2
	GOTO       L__Start_Bootload75
	GOTO       L__Start_Bootload72
L__Start_Bootload75:
;bootfor16_E2.mbas,244 :: 		rcv_1  = Uart1_Read()              ' Read rcv_1
	CALL       _UART1_Read+0
	MOVF       R0, 0
	MOVWF      bootfor16_E2_rcv_1+0
	CLRF       bootfor16_E2_rcv_1+1
;bootfor16_E2.mbas,245 :: 		block[i]  = rcv_1 << 8             ' Save rcv_1 and rcv_2 in block[i]
	MOVF       Start_Bootload_i+0, 0
	MOVWF      R0
	CLRF       R1
	LSLF       R0, 1
	RLF        R1, 1
	MOVLW      bootfor16_E2_block+0
	ADDWF      R0, 0
	MOVWF      FSR1L
	MOVLW      hi_addr(bootfor16_E2_block+0)
	ADDWFC     R1, 0
	MOVWF      FSR1H
	MOVF       bootfor16_E2_rcv_1+0, 0
	MOVWF      R1
	CLRF       R0
	MOVF       R0, 0
	MOVWF      INDF1+0
	MOVF       R1, 0
	ADDFSR     1, 1
	MOVWF      INDF1+0
;bootfor16_E2.mbas,246 :: 		block[i]  = block[i] or rcv_2
	MOVF       Start_Bootload_i+0, 0
	MOVWF      R0
	CLRF       R1
	LSLF       R0, 1
	RLF        R1, 1
	MOVLW      bootfor16_E2_block+0
	ADDWF      R0, 0
	MOVWF      FSR1L
	MOVLW      hi_addr(bootfor16_E2_block+0)
	ADDWFC     R1, 0
	MOVWF      FSR1H
	MOVLW      bootfor16_E2_block+0
	ADDWF      R0, 0
	MOVWF      FSR0L
	MOVLW      hi_addr(bootfor16_E2_block+0)
	ADDWFC     R1, 0
	MOVWF      FSR0H
	MOVF       bootfor16_E2_rcv_2+0, 0
	IORWF       INDF0+0, 0
	MOVWF      R0
	ADDFSR     0, 1
	MOVF       INDF0+0, 0
	IORWF       bootfor16_E2_rcv_2+1, 0
	MOVWF      R1
	MOVF       R0, 0
	MOVWF      INDF1+0
	MOVF       R1, 0
	ADDFSR     1, 1
	MOVWF      INDF1+0
;bootfor16_E2.mbas,247 :: 		Inc(i)                             ' Next program word
	INCF       Start_Bootload_i+0, 1
;bootfor16_E2.mbas,248 :: 		wend
	GOTO       L__Start_Bootload57
;bootfor16_E2.mbas,249 :: 		end  sub
L_end_Start_Bootload:
	RETURN
; end of _Start_Bootload
