Copyright (c) 2005 Juan Pablo D. Borgna <jpborgna en inti gov ar>
Copyright (c) 2006-2007 Salvador E. Tropea <salvador en inti gov ar>
Copyright (c) 2005-2007 Instituto Nacional de Tecnología Industrial

Commands and blocks:
                    The template files have block commands and operation
                    commands. The block commands start with two substract
                    signs "--" and the operation are betwin dollar signs "$".
                    The block commands mark the excecution of a block and the
                    end of the block must be identifyed with the instruction
                    "--END".

Internal variables:
                   The next internal variables are provided wich can be used
                   indicating their name betwin dollars signs "$" or modified
                   if a value is assigned using parentesis signs.
                   Ex.: $ADDRESS(0x00)$ asigns this variable the value 0x0000.

$ADDRESS$ :
           Accumulator useful at the time of incrementing a memory address.
           
$STEP$    :
           Value on wich $ADDRESS$ variable will be incremented.

$BSIZEB$  :
           Amount of bytes of the bitstream file.

$BSIZEB2$ :
           2 * amount of bytes of the bitstream file.

$BSIZE$   :
           Amount of bits of the bitstream file.
           Note: BSIZE an STEP are related. BSIZE is the size of the cache
           used to store the data before flashing the device. Each memory
           address contains some bits that's a word, the STEP is the size of
           the cache in words. So BSIZE=STEP*word_size.
           For the XC18V: 32*64=2048 o 32*128=4096.

$MSIZE$   :
           Taken from the msize field from the device definition in the
           DEVICES file.
           It contains the last memory position of a device with memory.

$ID$      :
           Taken from the id field from the device definition in the DEVICES
           file.
           It contains the IDCODE of the selected device.

$IDMASK$  :
           Taken from the idmask field from the device definition in the
           DEVICE file.
           It contains the mask wich be used in the comprobation of the IDCODE


Block commands:

--LITERAL START :
                 It indicate that in the output file must be copied the content
                 of this block until the end is found "as is".
                 If an operational command is found inside it is excecuted.

--REPEAT START :

                It indicate that this block will be repeated until the end of
                the bitfile is reached.
                This block must have inside some operational command wich
                reads information from the input bitfile, if not, the end of
                this will never be reached and the progran will keep
                repeating this block until there is no more disk space.
                With each block iteration the variable $ADDRESS$ is
                incremented by $STEP$.

--REPEAT UNTIL value :
                      It indicates that this block will be repeated until the
                      variable $ADDRESS$ reach the value passed as parameter.
                      With each block iteration the variable $ADDRESS$ is
                      incremented by $STEP$.
                      The value passwd as parameter must be $STEP$ multiplo,
                      or the exit condition will never be reached and the
                      program will keep repeating this block until there is
                      no more disk space.
                      Instead of value you can use a variable:
                      Ej.: --REPEAT UNTIL MSIZE


--END :
       It indicates the end of a LITERAL, REPEAT or REPEAT UNTIL block.


Opeation commands:
                  The operation commands may recive as an argment the name of
                  a variable instead of a constant:
                      Ej.: $FILL(0xFF,BSIZE)$

$DATA(ndatabytes)$ :
                    Writes in the output file a ndatabytes amount of bytes
                    from the input bitfile expressed in hex.

$DATA_INV(ndatabytes)$ :
                        Writes in the output fila a ndatabytes amount of bytes
                        from the input bitfile inverting the order, expressed
                        in hex.

$FILL(VAL,TIMES)$ :
                   Writes TIMES times the value VAL expressed in hex in the
                   output file.

$REWIND$ :
          Rewinds the bitfile to the first stream byte so it can be used in a
          new block.

          
