8 static void destroy(void);
9 static void start(long trans_time);
10 static void stop(long trans_time);
11 static void draw(void);
12 static float smoothstep(float a, float b, float x);
14 static struct screen scr = {
23 static void *saved_fb;
25 static long trans_start = -1, trans_dur;
29 static float delay[NBLOCKS];
32 struct screen *console_screen(void)
40 fbsize = fb_width * fb_height * fb_depth / 8;
42 if(!(saved_fb = malloc(fbsize))) {
43 perror("failed to allocate console framebuffer");
46 memcpy(saved_fb, fb_pixels, fbsize);
48 blksz = fb_height / NBLOCKS;
50 for(i=0; i<NBLOCKS; i++) {
51 delay[i] = (float)rand() / (float)RAND_MAX * MAX_DELAY;
57 static void destroy(void)
59 memcpy(fb_pixels, saved_fb, fbsize);
63 static void start(long trans_time)
67 static void stop(long trans_time)
69 trans_start = time_msec;
70 trans_dur = trans_time;
73 static void draw(void)
75 int i, pixsz = fb_depth / 8;
76 long elapsed, offs, rem;
77 unsigned char *dptr = fb_pixels;
78 unsigned char *sptr = saved_fb;
84 elapsed = time_msec - trans_start;
86 for(i=0; i<fb_height; i++) {
88 float t = (float)elapsed / (float)trans_dur;
89 offs = fb_width * smoothstep(0, 1.0 - delay[bidx], t - delay[bidx]);
90 if(offs < 0) offs = 0;
91 rem = fb_width - offs;
94 memset(dptr, 0, offs * pixsz);
97 memcpy(dptr + offs * pixsz, sptr, rem * pixsz);
100 dptr += fb_width * pixsz;
101 sptr += fb_width * pixsz;
105 static float smoothstep(float a, float b, float x)
107 if(x < a) return 0.0;
108 if(x >= b) return 1.0;
110 x = (x - a) / (b - a);
111 return x * x * (3.0 - 2.0 * x);