After 2 hours I think I'll leave for later or maybe put it up here8-)
This thing is supposed to make up a 256 element array of pointers to BYTE arrays. Each BYTE array is NULL terminated and it's elements contain the flag numbers that would make up the value of the offset from the first element of the array of pointers to the one that points to it. For example
the array of pointer's first element would point to a BYTE array with values 0. The second one to 1,0. The third to 2,0. The fourth 2,1,0 and so on.
Maybe I'm just too hanged over 8-) (not really, unfortunatelly...).
The output is not what I expected, so may the bug hunt begin.
:-x
#include <exec/types.h>
#include <exec/memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
BYTE **ByteFlagNrs;
BYTE **ByteFlagNrsPtr;
UBYTE IndexCounter;
BYTE FlagShiftNr;
const UBYTE Comparevalue = 1;
BYTE FlagCounter;
UBYTE *BytePtr;
WORD TestCounter;
int main (int argc, char **argv)
{ if (!(ByteFlagNrs = ByteFlagNrsPtr = (BYTE **)AllocMem (sizeof (LONG) * 256, MEMF_ANY | MEMF_CLEAR)))
printf ("Couldn't allocate memory...\n");
else
{ if (!(*ByteFlagNrsPtr++ = AllocMem (sizeof (BYTE), MEMF_ANY | MEMF_CLEAR))) /* First table entry is zero */
printf("No more memory !!\n");
for (IndexCounter = 1; IndexCounter != 0; IndexCounter++) /* Iterate 255 times */
{ if (!(*ByteFlagNrsPtr = AllocMem (sizeof (BYTE) * 8 + 1, MEMF_ANY | MEMF_CLEAR)))
printf ("No memory !\n");
else
{
FlagCounter = 0;
for (FlagShiftNr = 0; FlagShiftNr <= 7; FlagShiftNr++)
{ if ((Comparevalue << FlagShiftNr) & IndexCounter)
{ *(*ByteFlagNrsPtr + FlagCounter) = FlagShiftNr + 1;
FlagCounter++;
}
}
FreeMem ((*ByteFlagNrsPtr++ + FlagCounter), sizeof (BYTE) * 8 + 1 - (FlagCounter));
}
}
}
/* TEST IT ! */
ByteFlagNrsPtr = ByteFlagNrs;
for (TestCounter = 0; IndexCounter <= 255; IndexCounter++)
{
BytePtr = *ByteFlagNrsPtr;
while (*BytePtr)
{ printf ("%u ", *BytePtr++);
}
ByteFlagNrsPtr++;
printf (" ");
}
exit (0);
}
:-D