NOTES about EncodeHAM.asm

* EncodeHAM.asm contains versions for 68000 and 68020+ processors.
  (if the symbol MC68020 is defined you will get the 68020+ version)

* it also contains the brute-force colormap search routine used
  for colormap conversion

* when using gcc you have to define the symbol GCC because it stores
  all items as longwords on the stack when doing a function call
  gcc pads all structures that contain just chars; a structure like 
    struct test { char a,b,c};
  will have size 4
  (therefore EncodeHAM.asm contains fixes to solve these problems)

* Here comes a short test program for the HAM encoder:
  (it also shows how to use it in your own programs)

#include <stdio.h>
#include <stdlib.h>

  extern void EncodeHAM(unsigned char *yorig, unsigned char *yham,
                        unsigned char *ColorTable, short NumColors, short xsize);

  extern unsigned short MaxError, MaxErrorPos;

  #define HAM8 1
  #define HAM6 0
  #define XSIZE 3 /* size of the row in pixel */
  #define NUMCOLORS 3  /* number of valid colors in the colortable */

  unsigned char yorig[XSIZE*3] = {63,63,63, 0,15,15, 0,15,15}; /* original row in rgbrgb format */

  unsigned char yham[XSIZE] = {0}; /* HAM row to encode */
  /* allocate at least (((XSIZE+15)>>4)<<4) bytes if you want to display */
  /* the row using graphics.library calls (see later)                    */
     
  unsigned char ColorTable[NUMCOLORS*3] = {0,0,0, 15,0,15, 15,0,15}; /* ColorTable in brgbrg format */

  /* needed by the assembly language part */
  unsigned short ConvertMode = HAM8;
  unsigned short Mult_Table[2*256];
  unsigned char *ColorCache;
  char *Mult_Table32; /* not needed by HAM code */

  main()
  {
   int i;
   int counter=0;
   if(ColorCache = calloc(262145, 1))
   {
     /* create the multiplication table */
     for(i=-255; i<256; i++) Mult_Table[i+255] = (unsigned short)(i*i);

     EncodeHAM(yorig, yham, ColorTable, NUMCOLORS*3, XSIZE);

     for(i=0; i<XSIZE;i++) printf("%02hX ", (unsigned short)yham[i]);
     printf("\n");
     printf("MaxError %hu at pos %hu.\n", MaxError, MaxErrorPos);
   
     for(i=0; i<262145; i++) if(ColorCache[i]) counter++;
     printf("ColorCache has %d entries.\n", counter);

     free(ColorCache);
   }
   else printf("Could not allocate ColorCache.\n");
  } 


* if you want to display the row use WritePixelLine8() or WriteChunkyPixels()
  (use WriteChunkyPixels() only with graphics.library V40 or higher and only if
  a special chunky->planar hardware is present; see autodocs for more)

  example: WritePixelLine8(rp, 0, row, XSIZE, yham, temprp);

  (see the file DisplayGfx.c for more)