9 /* be sure to change the number of bits in the multiplier when doing this
10 * bits > 14 need extension of num_t to unsigned int */
12 #define BAIL (1 << (BITS + 1))
13 #define BAIL_A (1 << BITS)
16 typedef unsigned short num_t;
28 static inline cplx_t convert(num_t x, num_t y)
31 r.mag = x > MAXNUM ? -x : x;
32 r.sig = x > MAXNUM ? 1 : 0;
33 i.mag = y > MAXNUM ? -y : y;
34 i.sig = y > MAXNUM ? 1 : 0;
36 // printf("convert: output: x = %d, y = %d\n", res.r.mag, res.i.mag);
40 static inline sigmag_t mul(sigmag_t x, sigmag_t y)
45 (ym & 0x2000 ? xm : 0) +
46 (ym & 0x1000 ? xm >> 1 : 0) +
47 (ym & 0x0800 ? xm >> 2 : 0) +
48 (ym & 0x0400 ? xm >> 3 : 0) +
49 (ym & 0x0200 ? xm >> 4 : 0) +
50 (ym & 0x0100 ? xm >> 5 : 0) +
51 (ym & 0x0080 ? xm >> 6 : 0) +
52 (ym & 0x0040 ? xm >> 7 : 0) +
53 (ym & 0x0020 ? xm >> 8 : 0) +
54 (ym & 0x0010 ? xm >> 9 : 0) +
55 (ym & 0x0008 ? xm >> 10 : 0) +
56 (ym & 0x0004 ? xm >> 11 : 0) +
57 (ym & 0x0002 ? xm >> 12 : 0) +
58 (ym & 0x0001 ? xm >> 13 : 0);
60 num_t sig = x.sig ^ y.sig;
61 sigmag_t res = {mag, sig};
65 static inline unsigned int calc_piqsl(num_t x, num_t y)
67 // printf("calc_piqsl: x = %d, y = %d ############################ \n", x, y);
69 cplx_t c = convert(x, y);
71 // printf("xmag = %d, xsig = %d, ymag = %d, ysig = %d\n", c.r.mag, c.r.sig, c.i.mag, c.i.sig);
72 for(i = 0; i < MAX_ITER; i++) {
73 sigmag_t r2 = mul(z.r, z.r);
74 sigmag_t i2 = mul(z.i, z.i);
75 sigmag_t ri = mul(z.r, z.i);
76 // printf("r2mag: %d i2mag: %d i: %d\n", r2.mag, i2.mag, i);
77 if((r2.mag + i2.mag) & BAIL || z.r.mag & BAIL || z.i.mag & BAIL
78 || z.r.mag & BAIL_A || z.i.mag & BAIL_A) {
81 num_t rmag = r2.mag - i2.mag + (c.r.sig ? -c.r.mag : c.r.mag);
82 num_t imag = (ri.sig ? -ri.mag << 1 : ri.mag << 1) + (c.i.sig ? -c.i.mag : c.i.mag);
83 z = convert(rmag, imag);
86 // printf("bailed at %d\n", i);
87 return (i == MAX_ITER ? 0 : i);
97 SDL_LockSurface(screen);
100 for(i = 0; i < XRES; i++) {
101 for(j = 0; j <3 *dick; j++) {
102 res = calc_piqsl((i - XRES/2) << zoom, (j - YRES/2) << zoom);
103 res = res == 0 ? 0 : MAX_ITER - res - 3;
104 p[i+j*XRES] = ((res & 0x1) << 23) | ((res & 0x8) << 18) | ((res & 0x40) << 13) |
105 ((res & 0x2) << 14) | ((res & 0x10) << 9) | ((res & 0x80) << 4) |
106 ((res & 0x4) << 5) | ((res & 0x20));
111 SDL_UnlockSurface(screen);
119 if(SDL_Init(SDL_INIT_VIDEO) < 0) {
120 printf("Video init failed.\n");
124 screen = SDL_SetVideoMode(XRES, YRES, 32, SDL_SWSURFACE);
126 printf("Screen init failed.\n");
132 while(SDL_WaitEvent(&ev)) {
134 case SDL_QUIT: exit(0);