spectrum_cmbrot

view mbrot.c @ 4:3ac0c33742cf

changed to 8bit arithmetic for the outer loop
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 17 Feb 2014 20:33:39 +0200
parents 8e7f17958dbb
children
line source
1 #define FB_ADDR ((unsigned char*)0x4000)
2 #define ATTR_ADDR ((unsigned char*)0x5800)
3 #define LINESKIP (256 / 8)
5 unsigned char mbrot(int px, int py);
7 int main()
8 {
9 unsigned char i, j, k, start;
11 /* turn the border black */
12 #asm
13 xor a
14 out (254), a
15 #endasm
17 for(;;) {
18 unsigned char *ptr = FB_ADDR;
19 start = 0;
21 for(i=0; i<192; i++) {
22 unsigned char banky = i & 0x3f;
23 unsigned char cell = banky >> 3;
24 unsigned char cline = banky & 0x7;
25 unsigned char y = (cline << 3) + cell + start;
27 /*unsigned char *ptr = FB_ADDR | ((i & 0xc0) << 5) |
28 ((i & 0x38) << 2) | ((i & 7) << 8);*/
30 for(j=0; j<32; j++) { /* 256 pixels, 8 pixels per byte */
31 unsigned char pixel = 0;
32 for(k=0; k<8; k++) {
33 unsigned char res = mbrot((j << 3) + k, y);
34 pixel = pixel | (res & 1);
35 if(k < 7) pixel <<= 1;
36 }
37 *ptr++ = pixel;
38 }
40 if((i & 0x3f) == 0x3f) {
41 start += 0x40;
42 }
43 }
44 }
45 }
47 #define int2fix8_8(i) ((i) << 8)
48 #define fix_mul8_8(a, b) ((a >> 4) * (b >> 4))
49 #define int2fix5_11(i) ((i) << 11)
50 #define fix_mul5_11(a, b) ((a >> 5) * (b >> 6))
52 unsigned char mbrot(int px, int py)
53 {
54 unsigned char i;
55 int cx, cy, zx, zy, x, y, len;
56 int xop1, xop2, yop1, yop2;
57 int zxop1, zxop2, zyop1, zyop2;
59 cx = int2fix8_8(px - 192) >> 6;
60 cy = int2fix8_8(py - 96) >> 6;
62 cx <<= 3;
63 cy <<= 3;
65 zx = cx;
66 zy = cy;
68 for(i=0; i<32; i++) {
69 /*x = fix_mul5_11(zx, zx) - fix_mul5_11(zy, zy) + cx;
70 y = fix_mul5_11(zy, zx) + fix_mul5_11(zx, zy) + cy;*/
71 zxop1 = zx >> 5;
72 zxop2 = zxop1 >> 1;
73 zyop1 = zy >> 5;
74 zyop2 = zyop1 >> 1;
76 x = zxop1 * zxop2 - zyop1 * zyop2 + cx;
77 y = zyop1 * zxop2 + zxop1 * zyop2 + cy;
79 /*len = fix_mul5_11(x, x) + fix_mul5_11(y, y);*/
80 xop1 = x >> 5;
81 xop2 = xop1 >> 1;
82 yop1 = y >> 5;
83 yop2 = yop1 >> 1;
84 len = xop1 * xop2 + yop1 * yop2;
86 /*if(len > int2fix5_11(4)) return 0;*/
87 if(len > 8192) return 1;
89 zx = x;
90 zy = y;
91 }
93 return 0;
94 }