inp010.c 2.9 KB
#include <bstring.h>
#include <math.h>
#include <stdio.h>

#include "inp.h"

static void varyAlpha(void);
static void varyShadeAlpha(void);
static void printDitheredTrailingCycles(void);

int
main(int argc, char *argv[])
{
	srandom(1);

	printHeader();
	varyAlpha();
	varyShadeAlpha();
	printDitheredTrailingCycles();
}

static void
varyAlpha(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i, j;

	printf("# Vary alpha outputs with noise\n");

	bzero(ccp, sizeof(cc));

	ccp->ncyc = 0;			/* single cycle mode */
	ccp->dither_en = 1;		/* dithering mode */

	/* Initialize (x,y,a,c) RGB selects to produce (0,0,0,0) */

	ccp->cc_x_sel_1_r = CC_SUBA_ZERO;
	ccp->cc_y_sel_1_r = CC_SUBB_ZERO;
	ccp->cc_a_sel_1_r = CC_MULT_ZERO;
	ccp->cc_c_sel_1_r = CC_ADD_ZERO;

	/* Initialize (x,y,a) alpha selects to produce (0,0,0) */

	ccp->cc_x_sel_1_a = CC_SUBA_ZERO_ALPHA;
	ccp->cc_y_sel_1_a = CC_SUBB_ZERO_ALPHA;
	ccp->cc_a_sel_1_a = CC_MULT_ZERO_ALPHA;
	ccp->cc_c_sel_1_a = CC_ADD_TEX_1_ALPHA;

	/* Vary high bits */

	for (i = 0; i < 16; i++) {
		ccp->tf_a = i << 5;
		for (j = 0; j < 8; j++) {
			ccp->noise = j << 6;
			printf("#  tf_a = 0x%x, noise = 0x%x\n",
				ccp->tf_a, ccp->noise);
	   		printVector(ccp, 1);
		}
	}

	/* Monte Carlo */

	for (i = 0; i < 100; i++) {
		ccp->tf_a =  random() & 0x1ff;
		ccp->noise = random() & 0x1ff;
		printf("#  tf_a = 0x%x, noise = 0x%x\n", ccp->tf_a, ccp->noise);
	   	printVector(ccp, 1);
	}
}

static void
varyShadeAlpha(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i, j;

	printf("# Vary shade alpha inputs with noise\n");

	bzero(ccp, sizeof(cc));

	ccp->ncyc = 0;			/* single cycle mode */
	ccp->dither_en = 1;		/* dithering mode */

	/* Initialize (x,y,a,c) RGB selects to produce (0,0,0,0) */

	ccp->cc_x_sel_1_r = CC_SUBA_ZERO;
	ccp->cc_y_sel_1_r = CC_SUBB_ZERO;
	ccp->cc_a_sel_1_r = CC_MULT_ZERO;
	ccp->cc_c_sel_1_r = CC_ADD_ZERO;

	/* Initialize (x,y,a) alpha selects to produce (0,0,0) */

	ccp->cc_x_sel_1_a = CC_SUBA_ZERO_ALPHA;
	ccp->cc_y_sel_1_a = CC_SUBB_ZERO_ALPHA;
	ccp->cc_a_sel_1_a = CC_MULT_ZERO_ALPHA;
	ccp->cc_c_sel_1_a = CC_ADD_SHADE_ALPHA;

	/* Vary high bits */

	for (i = 0; i < 16; i++) {
		ccp->st_a = i << 4;
		for (j = 0; j < 8; j++) {
			ccp->noise = j << 6;
			printf("#  st_a = 0x%x, noise = 0x%x\n",
				ccp->st_a, ccp->noise);
	   		printVector(ccp, 1);
		}
	}

	/* once more to force a clamp */

	ccp->st_a = 0xff;
	for (j = 0; j < 8; j++) {
		ccp->noise = j << 6;
		printf("#  st_a = 0x%x, noise = 0x%x\n",
			ccp->st_a, ccp->noise);
	   	printVector(ccp, 1);
	}

	/* Monte Carlo */

	for (i = 0; i < 100; i++) {
		ccp->st_a =  random() & 0xff;
		ccp->noise = random() & 0x1ff;
		printf("#  st_a = 0x%x, noise = 0x%x\n", ccp->st_a, ccp->noise);
	   	printVector(ccp, 1);
	}
}

static void
printDitheredTrailingCycles(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i;

	bzero(ccp, sizeof(cc));
	ccp->dither_en = 1;		/* dithering mode */

	printf("# Trailing cycles\n");
	for (i = 0; i < 4; i++)
		printVector(ccp, 0);
}