spectrum_cmbrot

changeset 3:8e7f17958dbb

done with the mandelbrot, really
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 17 Feb 2014 18:54:17 +0200
parents 34f2fca9690b
children 3ac0c33742cf
files .hgignore Makefile mbrot.c test.c
diffstat 4 files changed, 104 insertions(+), 89 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Mon Feb 17 18:54:17 2014 +0200
     1.3 @@ -0,0 +1,7 @@
     1.4 +\.o$
     1.5 +\.swp$
     1.6 +\.d$
     1.7 +^mbrot$
     1.8 +\.tap$
     1.9 +\.wav$
    1.10 +\.def$
     2.1 --- a/Makefile	Mon Feb 17 11:02:24 2014 +0200
     2.2 +++ b/Makefile	Mon Feb 17 18:54:17 2014 +0200
     2.3 @@ -1,15 +1,14 @@
     2.4 -src = test.c
     2.5 +src = $(wildcard *.c)
     2.6  obj = $(src:.c=.o)
     2.7  
     2.8 -bin = test.tap
     2.9 -wav = $(bin:.tap=.wav)
    2.10 +bin = mbrot.tap
    2.11 +wav = mbrot.wav
    2.12  
    2.13  CC = zcc
    2.14  CFLAGS = +zx -pragma-define=myzorg=28000 -O2
    2.15  LDFLAGS = -create-app
    2.16  
    2.17  $(bin): $(obj)
    2.18 -	rm -f $(bin)
    2.19  	$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(obj)
    2.20  
    2.21  $(wav): $(bin)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/mbrot.c	Mon Feb 17 18:54:17 2014 +0200
     3.3 @@ -0,0 +1,94 @@
     3.4 +#define FB_ADDR		((unsigned char*)0x4000)
     3.5 +#define ATTR_ADDR	((unsigned char*)0x5800)
     3.6 +#define LINESKIP	(256 / 8)
     3.7 +
     3.8 +unsigned char mbrot(int px, int py);
     3.9 +
    3.10 +int main()
    3.11 +{
    3.12 +	unsigned int i, j, k, start;
    3.13 +
    3.14 +	/* turn the border black */
    3.15 +#asm
    3.16 +	xor a
    3.17 +	out (254), a
    3.18 +#endasm
    3.19 +
    3.20 +	for(;;) {
    3.21 +		unsigned char *ptr = FB_ADDR;
    3.22 +		start = 0;
    3.23 +
    3.24 +		for(i=0; i<192; i++) {
    3.25 +			unsigned int banky = i & 0x3f;
    3.26 +			unsigned int cell = banky >> 3;
    3.27 +			unsigned int cline = banky & 0x7;
    3.28 +			unsigned int y = (cline << 3) + cell + start;
    3.29 +
    3.30 +			/*unsigned char *ptr = FB_ADDR | ((i & 0xc0) << 5) |
    3.31 +				((i & 0x38) << 2) | ((i & 7) << 8);*/
    3.32 +
    3.33 +			for(j=0; j<32; j++) {	/* 256 pixels, 8 pixels per byte */
    3.34 +				unsigned char pixel = 0;
    3.35 +				for(k=0; k<8; k++) {
    3.36 +					unsigned char res = mbrot((j << 3) + k, y);
    3.37 +					pixel = pixel | (res & 1);
    3.38 +					if(k < 7) pixel <<= 1;
    3.39 +				}
    3.40 +				*ptr++ = pixel;
    3.41 +			}
    3.42 +
    3.43 +			if((i & 0x3f) == 0x3f) {
    3.44 +				start += 0x40;
    3.45 +			}
    3.46 +		}
    3.47 +	}
    3.48 +}
    3.49 +
    3.50 +#define int2fix8_8(i)		((i) << 8)
    3.51 +#define fix_mul8_8(a, b)	((a >> 4) * (b >> 4))
    3.52 +#define int2fix5_11(i)		((i) << 11)
    3.53 +#define fix_mul5_11(a, b)	((a >> 5) * (b >> 6))
    3.54 +
    3.55 +unsigned char mbrot(int px, int py)
    3.56 +{
    3.57 +	unsigned char i;
    3.58 +	int cx, cy, zx, zy, x, y, len;
    3.59 +	int xop1, xop2, yop1, yop2;
    3.60 +	int zxop1, zxop2, zyop1, zyop2;
    3.61 +
    3.62 +	cx = int2fix8_8(px - 192) >> 6;
    3.63 +	cy = int2fix8_8(py - 96) >> 6;
    3.64 +
    3.65 +	cx <<= 3;
    3.66 +	cy <<= 3;
    3.67 +
    3.68 +	zx = cx;
    3.69 +	zy = cy;
    3.70 +
    3.71 +	for(i=0; i<32; i++) {
    3.72 +		/*x = fix_mul5_11(zx, zx) - fix_mul5_11(zy, zy) + cx;
    3.73 +		y = fix_mul5_11(zy, zx) + fix_mul5_11(zx, zy) + cy;*/
    3.74 +		zxop1 = zx >> 5;
    3.75 +		zxop2 = zxop1 >> 1;
    3.76 +		zyop1 = zy >> 5;
    3.77 +		zyop2 = zyop1 >> 1;
    3.78 +
    3.79 +		x = zxop1 * zxop2 - zyop1 * zyop2 + cx;
    3.80 +		y = zyop1 * zxop2 + zxop1 * zyop2 + cy;
    3.81 +
    3.82 +		/*len = fix_mul5_11(x, x) + fix_mul5_11(y, y);*/
    3.83 +		xop1 = x >> 5;
    3.84 +		xop2 = xop1 >> 1;
    3.85 +		yop1 = y >> 5;
    3.86 +		yop2 = yop1 >> 1;
    3.87 +		len = xop1 * xop2 + yop1 * yop2;
    3.88 +
    3.89 +		/*if(len > int2fix5_11(4)) return 0;*/
    3.90 +		if(len > 8192) return 1;
    3.91 +
    3.92 +		zx = x;
    3.93 +		zy = y;
    3.94 +	}
    3.95 +
    3.96 +	return 0;
    3.97 +}
     4.1 --- a/test.c	Mon Feb 17 11:02:24 2014 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,85 +0,0 @@
     4.4 -#define FB_ADDR		((unsigned char*)0x4000)
     4.5 -#define ATTR_ADDR	((unsigned char*)0x5800)
     4.6 -#define LINESKIP	(256 / 8)
     4.7 -
     4.8 -unsigned char mbrot(int px, int py);
     4.9 -
    4.10 -int main()
    4.11 -{
    4.12 -	unsigned int i, j, k, start;
    4.13 -
    4.14 -	for(;;) {
    4.15 -		start = 0;
    4.16 -
    4.17 -		for(i=0; i<192; i++) {
    4.18 -			unsigned int banky = i & 0x3f;
    4.19 -			unsigned int cell = banky >> 3;
    4.20 -			unsigned int cline = banky & 0x7;
    4.21 -			unsigned int memline = cell + (cline << 3);
    4.22 -			unsigned char *ptr = FB_ADDR + (start + memline) * LINESKIP;
    4.23 -
    4.24 -			for(j=0; j<32; j++) {	/* 256 pixels, 8 pixels per byte */
    4.25 -				unsigned char pixel = 0;
    4.26 -				for(k=0; k<8; k++) {
    4.27 -					unsigned char res = mbrot((j << 3) + k, i);
    4.28 -					pixel = pixel | (res & 1);
    4.29 -					if(k < 7) pixel <<= 1;
    4.30 -				}
    4.31 -				*ptr++ = pixel;
    4.32 -			}
    4.33 -
    4.34 -			if((i & 0x3f) == 0x3f) {
    4.35 -				start += 0x40;
    4.36 -			}
    4.37 -		}
    4.38 -	}
    4.39 -}
    4.40 -
    4.41 -#define int2fix8_8(i)		((i) << 8)
    4.42 -#define fix_mul8_8(a, b)	((a >> 4) * (b >> 4))
    4.43 -#define int2fix5_11(i)		((i) << 11)
    4.44 -#define fix_mul5_11(a, b)	((a >> 5) * (b >> 6))
    4.45 -
    4.46 -unsigned char mbrot(int px, int py)
    4.47 -{
    4.48 -	unsigned char i;
    4.49 -	int cx, cy, zx, zy, x, y, len;
    4.50 -	int xop1, xop2, yop1, yop2;
    4.51 -	int zxop1, zxop2, zyop1, zyop2;
    4.52 -
    4.53 -	cx = int2fix8_8(px - 192) >> 6;
    4.54 -	cy = int2fix8_8(py - 96) >> 6;
    4.55 -
    4.56 -	cx <<= 3;
    4.57 -	cy <<= 3;
    4.58 -
    4.59 -	zx = cx;
    4.60 -	zy = cy;
    4.61 -
    4.62 -	for(i=0; i<32; i++) {
    4.63 -		/*x = fix_mul5_11(zx, zx) - fix_mul5_11(zy, zy) + cx;
    4.64 -		y = fix_mul5_11(zy, zx) + fix_mul5_11(zx, zy) + cy;*/
    4.65 -		zxop1 = zx >> 5;
    4.66 -		zxop2 = zxop1 >> 1;
    4.67 -		zyop1 = zy >> 5;
    4.68 -		zyop2 = zyop1 >> 1;
    4.69 -
    4.70 -		x = zxop1 * zxop2 - zyop1 * zyop2 + cx;
    4.71 -		y = zyop1 * zxop2 + zxop1 * zyop2 + cy;
    4.72 -
    4.73 -		/*len = fix_mul5_11(x, x) + fix_mul5_11(y, y);*/
    4.74 -		xop1 = x >> 5;
    4.75 -		xop2 = xop1 >> 1;
    4.76 -		yop1 = y >> 5;
    4.77 -		yop2 = yop1 >> 1;
    4.78 -		len = xop1 * xop2 + yop1 * yop2;
    4.79 -
    4.80 -		/*if(len > int2fix5_11(4)) return 0;*/
    4.81 -		if(len > 8192) return 0;
    4.82 -
    4.83 -		zx = x;
    4.84 -		zy = y;
    4.85 -	}
    4.86 -
    4.87 -	return 1;
    4.88 -}