/* Generate the bit draw functions

For fn _Bitxy where x and y are hex numbers x and y contain the high and
low bits for 4 pixels as h3 h2 h1 h0 l3 l2 l1 l0

c0 in cl c1 in ch c2 in dl c3 in dh

*/

#include <stdio.h>

static char *szCReg[] = { "cl","ch","dl","dh" };
static char *szOfs[] = { "","1","2","3" };

void Generate(int n,int nType)
{
unsigned int i,c;
printf("_%sBit%02x:\n",(nType == 0) ? "" : "S",n);
for (i = 0;i < 4;i++)
	{
	c = 0;
	if (n & 8) c++;
	if (n & 128) c = c + 2;
	n = (n * 2) & 0xFF;
	if (nType == 0 || c != 0)
			printf(" mov %s[bx],%s ; %d\n",szOfs[i],szCReg[c],c);
	}
printf("ret\n");
}

int nMask[] = { 1,2,4,8,16,32,64,128 };

void main()
{
unsigned int i,n;
unsigned int n1;

printf("Reverse:\n");
for (i = 0;i < 256;i++)
	{
	n1 = 0;
	for (n = 0;n < 8;n++)
		if (i & nMask[n]) n1 = n1 | nMask[7-n];
	printf("db %d ; %d\n",n1,i);
	}
printf("BitBlastVec:\n");
for (i = 0;i < 256;i++)
	{
	printf("dw _Bit%02x\n",i);
	}
for (i = 0;i < 256;i++) Generate(i,0);

printf("SprBlastVec:\n");
for (i = 0;i < 256;i++)
	{
	printf("dw _SBit%02x\n",i);
	}
for (i = 0;i < 256;i++) Generate(i,1);

printf("LineAddress:\n");
n = 0;
for (i = 0;i < 240;i++)
	{
	if (i % 7 == 0 || i < 8 || i > 231)
		printf(" dw 0\n");
	else
		printf(" dw %u\n",(n++)*320+32);
	}

printf("LineAddressPAL:\n");
n = 0;
for (i = 0;i < 240;i++)
	{
	if (i % 6 == 0)
		printf(" dw 0\n");
	else
		printf(" dw %u\n",(n++)*320+32);
	}

}