spectrum_cmbrot

diff mbrot.c @ 3:8e7f17958dbb

done with the mandelbrot, really
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 17 Feb 2014 18:54:17 +0200
parents test.c@c2815c765fea
children 3ac0c33742cf
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mbrot.c	Mon Feb 17 18:54:17 2014 +0200
     1.3 @@ -0,0 +1,94 @@
     1.4 +#define FB_ADDR		((unsigned char*)0x4000)
     1.5 +#define ATTR_ADDR	((unsigned char*)0x5800)
     1.6 +#define LINESKIP	(256 / 8)
     1.7 +
     1.8 +unsigned char mbrot(int px, int py);
     1.9 +
    1.10 +int main()
    1.11 +{
    1.12 +	unsigned int i, j, k, start;
    1.13 +
    1.14 +	/* turn the border black */
    1.15 +#asm
    1.16 +	xor a
    1.17 +	out (254), a
    1.18 +#endasm
    1.19 +
    1.20 +	for(;;) {
    1.21 +		unsigned char *ptr = FB_ADDR;
    1.22 +		start = 0;
    1.23 +
    1.24 +		for(i=0; i<192; i++) {
    1.25 +			unsigned int banky = i & 0x3f;
    1.26 +			unsigned int cell = banky >> 3;
    1.27 +			unsigned int cline = banky & 0x7;
    1.28 +			unsigned int y = (cline << 3) + cell + start;
    1.29 +
    1.30 +			/*unsigned char *ptr = FB_ADDR | ((i & 0xc0) << 5) |
    1.31 +				((i & 0x38) << 2) | ((i & 7) << 8);*/
    1.32 +
    1.33 +			for(j=0; j<32; j++) {	/* 256 pixels, 8 pixels per byte */
    1.34 +				unsigned char pixel = 0;
    1.35 +				for(k=0; k<8; k++) {
    1.36 +					unsigned char res = mbrot((j << 3) + k, y);
    1.37 +					pixel = pixel | (res & 1);
    1.38 +					if(k < 7) pixel <<= 1;
    1.39 +				}
    1.40 +				*ptr++ = pixel;
    1.41 +			}
    1.42 +
    1.43 +			if((i & 0x3f) == 0x3f) {
    1.44 +				start += 0x40;
    1.45 +			}
    1.46 +		}
    1.47 +	}
    1.48 +}
    1.49 +
    1.50 +#define int2fix8_8(i)		((i) << 8)
    1.51 +#define fix_mul8_8(a, b)	((a >> 4) * (b >> 4))
    1.52 +#define int2fix5_11(i)		((i) << 11)
    1.53 +#define fix_mul5_11(a, b)	((a >> 5) * (b >> 6))
    1.54 +
    1.55 +unsigned char mbrot(int px, int py)
    1.56 +{
    1.57 +	unsigned char i;
    1.58 +	int cx, cy, zx, zy, x, y, len;
    1.59 +	int xop1, xop2, yop1, yop2;
    1.60 +	int zxop1, zxop2, zyop1, zyop2;
    1.61 +
    1.62 +	cx = int2fix8_8(px - 192) >> 6;
    1.63 +	cy = int2fix8_8(py - 96) >> 6;
    1.64 +
    1.65 +	cx <<= 3;
    1.66 +	cy <<= 3;
    1.67 +
    1.68 +	zx = cx;
    1.69 +	zy = cy;
    1.70 +
    1.71 +	for(i=0; i<32; i++) {
    1.72 +		/*x = fix_mul5_11(zx, zx) - fix_mul5_11(zy, zy) + cx;
    1.73 +		y = fix_mul5_11(zy, zx) + fix_mul5_11(zx, zy) + cy;*/
    1.74 +		zxop1 = zx >> 5;
    1.75 +		zxop2 = zxop1 >> 1;
    1.76 +		zyop1 = zy >> 5;
    1.77 +		zyop2 = zyop1 >> 1;
    1.78 +
    1.79 +		x = zxop1 * zxop2 - zyop1 * zyop2 + cx;
    1.80 +		y = zyop1 * zxop2 + zxop1 * zyop2 + cy;
    1.81 +
    1.82 +		/*len = fix_mul5_11(x, x) + fix_mul5_11(y, y);*/
    1.83 +		xop1 = x >> 5;
    1.84 +		xop2 = xop1 >> 1;
    1.85 +		yop1 = y >> 5;
    1.86 +		yop2 = yop1 >> 1;
    1.87 +		len = xop1 * xop2 + yop1 * yop2;
    1.88 +
    1.89 +		/*if(len > int2fix5_11(4)) return 0;*/
    1.90 +		if(len > 8192) return 1;
    1.91 +
    1.92 +		zx = x;
    1.93 +		zy = y;
    1.94 +	}
    1.95 +
    1.96 +	return 0;
    1.97 +}