Building instructions:

When using the boot pic, the program has to be assembled from 01000h to 01FFEh.  
This is so the program can run in external flash.  One cannot use the PICC 
command line driven compiler to choose the necessary options, so the linking 
stage must be performed manually.

1) Firstly, set up project as per normal in MPLab.  I've used two files, main.c 
and serial.c for an example.  Then, choose -v in the linker options to display 
the command lines used to invoke the linker.  Add -m, with main.map as the data 
for the linker.  This makes a .map file of memory usage which will be useful 
later.

Press F10 to compile, then copy all the command lines used out of the compile 
window.  It should look like this:

******************************************************************************
Building MAIN.HEX...

Compiling MAIN.C:
Command line: "C:\HT-PIC\BIN\PICC.EXE -V -Gmicrochip -O -Zg -D24 -E -17C44 -C C:\WORKING\ANDREW\MACS\SOFTWARE\MNPICHT\MAIN.C"

Compiling SERIAL.C:
Command line: "C:\HT-PIC\BIN\PICC.EXE -V -Gmicrochip -O -Zg -D24 -E -17C44 -C C:\WORKING\ANDREW\MACS\SOFTWARE\MNPICHT\SERIAL.C"

Linking:
Command line: "C:\HT-PIC\BIN\PICC.EXE -Gmicrochip -INTEL -Mmain.map -17C44 -oMAIN.HEX -V MAIN.OBJ SERIAL.OBJ "
Enter PICC -HELP for help
hlink.exe -z -h+microchip -Mmain.map -oC:\WINDOWS\TEMP\l.obj -pintcode=8,powerup=0,init%100h,end_init,clrtext -ACOMBANK=01Ah-01Fh -ptemp=01Ch -ABANK0=01Ch-0FFh -prbss_0=BANK0,rdata_0=BANK0,idata_0=ROMDATA -ABANK1=0120h-01FFh -prbss_1=BANK1,rdata_1=BANK1,idata_1=ROMDATA -AROMDATA=0-01FFFh -ACONST=0-0FFhx32 -ACODE=00h-01FFDh -DCODE=2 -DROMDATA=2 -pcstrings=ROMDATA -pconfig=0FE00h -pfloat_text0=CODE,float_text1=CODE,float_text2=CODE -pfloat_text3=CODE,float_text4=CODE -pnvram=BANK0,nvram_1=BANK1 -Q17C44 C:\HT-PIC\LIB\picrt704.obj main.obj serial.obj C:\HT-PIC\LIB\pic704-c.lib
del C:\WINDOWS\TEMP\$$012708.003
objtohex.exe -i -16,2 C:\WINDOWS\TEMP\l.obj MAIN.HEX
cromwell.exe -m -P17C44 MAIN.HEX microchip -ocod
del C:\WINDOWS\TEMP\l.obj

Memory Usage Map:

Program ROM   $0000 - $0003  $0004 (   4) words
Program ROM   $0094 - $0111  $007E ( 126) words
                             $0082 ( 130) words total Program ROM 

Bank 0 RAM    $00FB - $00FF  $0005 (   5) bytes total Bank 0 RAM  
del C:\WINDOWS\TEMP\$$012708.000
del C:\WINDOWS\TEMP\$$012708.001
del C:\WINDOWS\TEMP\$$012708.002
del C:\WINDOWS\TEMP\l.obj
del C:\WINDOWS\TEMP\$$012708.003

Build completed successfully.
******************************************************************************

Create a batch file called b.bat (short for build), then put the above in it. 
Delete all unnecessary text in the batch file.  This will make it compatible 
with ms-dos.

It should look like this:

<contents of b.bat>
******************************************************************************
C:\HT-PIC\BIN\PICC.EXE -V -Gmicrochip -O -Zg -D24 -E -17C44 -C C:\WORKING\ANDREW\MACS\SOFTWARE\MNPICHT\MAIN.C
C:\HT-PIC\BIN\PICC.EXE -V -Gmicrochip -O -Zg -D24 -E -17C44 -C C:\WORKING\ANDREW\MACS\SOFTWARE\MNPICHT\SERIAL.C
C:\HT-PIC\BIN\PICC.EXE -Gmicrochip -INTEL -Mmain.map -17C44 -oMAIN.HEX -V MAIN.OBJ SERIAL.OBJ
hlink.exe -z -h+microchip -Mmain.map -oC:\WINDOWS\TEMP\l.obj -pintcode=8,powerup=0,init%100h,end_init,clrtext -ACOMBANK=01Ah-01Fh -ptemp=01Ch -ABANK0=01Ch-0FFh -prbss_0=BANK0,rdata_0=BANK0,idata_0=ROMDATA -ABANK1=0120h-01FFh -prbss_1=BANK1,rdata_1=BANK1,idata_1=ROMDATA -AROMDATA=0-01FFFh -ACONST=0-0FFhx32 -ACODE=00h-01FFDh -DCODE=2 -DROMDATA=2 -pcstrings=ROMDATA -pconfig=0FE00h -pfloat_text0=CODE,float_text1=CODE,float_text2=CODE -pfloat_text3=CODE,float_text4=CODE -pnvram=BANK0,nvram_1=BANK1 -Q17C44 C:\HT-PIC\LIB\picrt704.obj main.obj serial.obj C:\HT-PIC\LIB\pic704-c.lib
del C:\WINDOWS\TEMP\$$012708.003
objtohex.exe -i -16,2 C:\WINDOWS\TEMP\l.obj MAIN.HEX
cromwell.exe -m -P17C44 MAIN.HEX microchip -ocod
del C:\WINDOWS\TEMP\l.obj
del C:\WINDOWS\TEMP\$$012708.000
del C:\WINDOWS\TEMP\$$012708.001
del C:\WINDOWS\TEMP\$$012708.002
del C:\WINDOWS\TEMP\l.obj
del C:\WINDOWS\TEMP\$$012708.003
******************************************************************************

Add a few things to tidy it up, and make it look nice, ie:

<contents of b.bat>
******************************************************************************
@echo off
C:\HT-PIC\BIN\PICC.EXE -V -Gmicrochip -O -Zg -D24 -E -17C44 -C C:\WORKING\ANDREW\MACS\SOFTWARE\MNPICHT\MAIN.C
C:\HT-PIC\BIN\PICC.EXE -V -Gmicrochip -O -Zg -D24 -E -17C44 -C C:\WORKING\ANDREW\MACS\SOFTWARE\MNPICHT\SERIAL.C
C:\HT-PIC\BIN\PICC.EXE -Gmicrochip -INTEL -Mmain.map -17C44 -oMAIN.HEX -V MAIN.OBJ SERIAL.OBJ
hlink.exe -z -h+microchip -Mmain.map -oC:\WINDOWS\TEMP\l.obj -pintcode=8,powerup=0,init%100h,end_init,clrtext -ACOMBANK=01Ah-01Fh -ptemp=01Ch -ABANK0=01Ch-0FFh -prbss_0=BANK0,rdata_0=BANK0,idata_0=ROMDATA -ABANK1=0120h-01FFh -prbss_1=BANK1,rdata_1=BANK1,idata_1=ROMDATA -AROMDATA=0-01FFFh -ACONST=0-0FFhx32 -ACODE=00h-01FFDh -DCODE=2 -DROMDATA=2 -pcstrings=ROMDATA -pconfig=0FE00h -pfloat_text0=CODE,float_text1=CODE,float_text2=CODE -pfloat_text3=CODE,float_text4=CODE -pnvram=BANK0,nvram_1=BANK1 -Q17C44 C:\HT-PIC\LIB\picrt704.obj main.obj serial.obj C:\HT-PIC\LIB\pic704-c.lib
ctty nul
del C:\WINDOWS\TEMP\$$012708.003
ctty con
objtohex.exe -i -16,2 C:\WINDOWS\TEMP\l.obj MAIN.HEX
cromwell.exe -m -P17C44 MAIN.HEX microchip -ocod
ctty nul
del C:\WINDOWS\TEMP\l.obj
del C:\WINDOWS\TEMP\$$012708.000
del C:\WINDOWS\TEMP\$$012708.001
del C:\WINDOWS\TEMP\$$012708.002
del C:\WINDOWS\TEMP\l.obj
del C:\WINDOWS\TEMP\$$012708.003
ctty con
******************************************************************************

2) The parameter line for hlink is too long (>128chars), so copy everything after hlink into 
main.lkr.  Wordwrap this line, then put a \ character after each line.  Go back 
to the batch file and change 'hlink' to 'hlink @main.lkr'

Information for this is contained by looking at the ht-pic web manual, under
'Linker and Utilities Reference Manual', under 'Invoking the Linker'

The batch file should look like this:

<contents of b.bat>
******************************************************************************
@echo off
C:\HT-PIC\BIN\PICC.EXE -Gmicrochip -D24 -E -17C44 -C C:\WORKING\ANDREW\MACS\SOFTWARE\MNPICHT\MAIN.C
C:\HT-PIC\BIN\PICC.EXE -Gmicrochip -D24 -E -17C44 -C C:\WORKING\ANDREW\MACS\SOFTWARE\MNPICHT\SERIAL.C
C:\HT-PIC\BIN\hlink.exe @main.lkr
ctty nul
del C:\WINDOWS\TEMP\$$010692.003
ctty con
C:\HT-PIC\BIN\objtohex.exe -i -16,2 C:\WINDOWS\TEMP\l.obj MAIN.HEX
C:\HT-PIC\BIN\cromwell.exe -m -P17C44 MAIN.HEX microchip -ocod
ctty nul
del C:\WINDOWS\TEMP\l.obj
del C:\WINDOWS\TEMP\$$010692.000
del C:\WINDOWS\TEMP\$$010692.001
del C:\WINDOWS\TEMP\$$010692.002
del C:\WINDOWS\TEMP\l.obj
del C:\WINDOWS\TEMP\$$010692.003
ctty con
******************************************************************************

The main.lkr file should look like this:

<contents of main.lkr> 
****************************************************************************** 
-z -h+microchip -Mmain.map -oC:\WINDOWS\TEMP\l.obj  \
-pintcode=8,powerup=0,init%100h,end_init,clrtext -ACOMBANK=01Ah-01Fh -ptemp=01Ch \
-ABANK0=01Ch-0FFh -prbss_0=BANK0,rdata_0=BANK0,idata_0=ROMDATA \
-ABANK1=0120h-01FFh -prbss_1=BANK1,rdata_1=BANK1,idata_1=ROMDATA \ 
-AROMDATA=0-01FFFh -ACONST=0-0FFhx32 -ACODE=00h-01FFDh -DCODE=2 -DROMDATA=2 \
-pcstrings=ROMDATA -pconfig=0FE00h \
-pfloat_text0=CODE,float_text1=CODE,float_text2=CODE \
-pfloat_text3=CODE,float_text4=CODE -pnvram=BANK0,nvram_1=BANK1 -Q17C44 \
C:\HT-PIC\LIB\picrt704.obj main.obj serial.obj C:\HT-PIC\LIB\pic704-c.lib 
******************************************************************************

3) Now, we're ready to change the places where the code is linked into.  See the 
hi-tech C manual, 'Linker and Utilities Reference Manual', under 'Operation'
The parameters of interest to look at are -p and -a

Change the CODE and ROMDATA section to link to 01000h to 01EFFh.  The area from 
01F00h to 01FFE will be used to store the startup routines. These routines clear 
the memory, set up the stack, and initialize everything.  Looking at the second 
line of main.lkr above, the psects init, end_init and clrtext default to 100h.  
Change this to 01F00.  However, this still wont work because the psects end_init 
and clrtext will not load directly above init.  Looking at the options for -p in 
the hitech web manual, it a / character is appended after the psect, it forces 
it to be linked after the previous segment. Do this, and it links fine.

Thus, the finished main.lkr file is as follows:

<contents of main.lkr> 
****************************************************************************** 
-z -h+microchip -Mmain.map -oC:\WINDOWS\TEMP\l.obj \
-pintcode=8,powerup=0,init=1F00h,end_init/,clrtext/ \
 -ACOMBANK=01Ah-01Fh -ptemp=01Ch \
-ABANK0=01Ch-0FFh -prbss_0=BANK0,rdata_0=BANK0,idata_0=ROMDATA \
-ABANK1=0120h-01FFh -prbss_1=BANK1,rdata_1=BANK1,idata_1=ROMDATA \
-AROMDATA=01000h-01EFFh -ACONST=0-0FFhx32 -ACODE=01000h-01EFFh -DCODE=2 -DROMDATA=2 \
-pcstrings=ROMDATA -pconfig=0FE00h \
-pfloat_text0=CODE,float_text1=CODE,float_text2=CODE \
-pfloat_text3=CODE,float_text4=CODE -pnvram=BANK0,nvram_1=BANK1 -Q17C44 \
C:\HT-PIC\LIB\picrt704.obj main.obj serial.obj C:\HT-PIC\LIB\pic704-c.lib
******************************************************************************

Now, compile this by running batch file b.bat from the dos prompt.  Reload 
MPLab, as it doesn't realize main.hex has changed.  Step through the assembly 
code and it should work fine.

Next, examine main.map, to make doubly sure it is correct.  It should have all 
psects linked from 1000h to 1FFEh. Now use vbboot to load and run the program.
It should work fine, running from flash.

