spectrum_cmbrot
changeset 0:e56d8b0eee4b
spectrum fractal :)
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 17 Feb 2014 10:17:17 +0200 |
parents | |
children | c2815c765fea |
files | Makefile RUN test.c |
diffstat | 3 files changed, 88 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/Makefile Mon Feb 17 10:17:17 2014 +0200 1.3 @@ -0,0 +1,16 @@ 1.4 +src = test.c 1.5 +obj = $(src:.c=.o) 1.6 + 1.7 +bin = test.tap 1.8 + 1.9 +CC = zcc 1.10 +CFLAGS = +zx -pragma-define=myzorg=28000 1.11 +LDFLAGS = -create-app 1.12 + 1.13 +$(bin): $(obj) 1.14 + rm -f $(bin) 1.15 + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(obj) 1.16 + 1.17 +.PHONY: clean 1.18 +clean: 1.19 + rm -f $(obj) $(bin)
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/RUN Mon Feb 17 10:17:17 2014 +0200 2.3 @@ -0,0 +1,3 @@ 2.4 +#!/bin/sh 2.5 + 2.6 +fuse-sdl -g 3x --tape $*
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test.c Mon Feb 17 10:17:17 2014 +0200 3.3 @@ -0,0 +1,69 @@ 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 + for(;;) { 3.15 + start = 0; 3.16 + 3.17 + for(i=0; i<192; i++) { 3.18 + unsigned int banky = i & 0x3f; 3.19 + unsigned int cell = banky / 8; 3.20 + unsigned int cline = banky % 8; 3.21 + unsigned int memline = cell + cline * 8; 3.22 + unsigned char *ptr = FB_ADDR + (start + memline) * LINESKIP; 3.23 + 3.24 + for(j=0; j<32; j++) { /* 256 pixels, 8 pixels per byte */ 3.25 + unsigned char pixel = 0; 3.26 + for(k=0; k<8; k++) { 3.27 + unsigned char res = mbrot((j << 3) + k, i); 3.28 + pixel = pixel | (res & 1); 3.29 + if(k < 7) pixel <<= 1; 3.30 + } 3.31 + *ptr++ = pixel; 3.32 + } 3.33 + 3.34 + if((i & 0x3f) == 0x3f) { 3.35 + start += 0x40; 3.36 + } 3.37 + } 3.38 + } 3.39 +} 3.40 + 3.41 +#define int2fix8_8(i) ((i) << 8) 3.42 +#define fix_mul8_8(a, b) ((a >> 4) * (b >> 4)) 3.43 +#define int2fix5_11(i) ((i) << 11) 3.44 +#define fix_mul5_11(a, b) ((a >> 5) * (b >> 6)) 3.45 + 3.46 +unsigned char mbrot(int px, int py) 3.47 +{ 3.48 + unsigned char i; 3.49 + int cx, cy, zx, zy, x, y, len; 3.50 + 3.51 + cx = int2fix8_8(px - 192) >> 6; 3.52 + cy = int2fix8_8(py - 96) >> 6; 3.53 + 3.54 + cx <<= 3; 3.55 + cy <<= 3; 3.56 + 3.57 + zx = cx; 3.58 + zy = cy; 3.59 + 3.60 + for(i=0; i<32; i++) { 3.61 + x = fix_mul5_11(zx, zx) - fix_mul5_11(zy, zy) + cx; 3.62 + y = fix_mul5_11(zy, zx) + fix_mul5_11(zx, zy) + cy; 3.63 + len = fix_mul5_11(x, x) + fix_mul5_11(y, y); 3.64 + 3.65 + if(len > int2fix5_11(4)) return 0; 3.66 + 3.67 + zx = x; 3.68 + zy = y; 3.69 + } 3.70 + 3.71 + return 1; 3.72 +}