10 struct vid_modeinfo *vm;
11 void *vmem, *framebuf;
14 static const char *usage_fmt = "Usage %s: [options]\n"
16 " -s <XxY>: video resolution\n"
17 " -b <bpp>: color depth\n"
18 " -d: double buffer\n";
20 int main(int argc, char **argv)
28 for(i=1; i<argc; i++) {
29 if(argv[i][0] == '-') {
31 invalopt: fprintf(stderr, "invalid option: %s\n", argv[i]);
36 if(!argv[++i] || sscanf(argv[i], "%dx%d", &xres, &yres) != 2) {
37 fprintf(stderr, "invalid resolution: %s\n", argv[i]);
43 if(!argv[++i] || (bpp = atoi(argv[i])) <= 0) {
44 fprintf(stderr, "invalid color depth: %s\n", argv[i]);
54 printf(usage_fmt, argv[0]);
61 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
67 if(vid_init() == -1) {
68 fprintf(stderr, "failed to initialize video\n");
71 printf("press any key...\n");
74 if((mode = vid_findmode(xres, yres, bpp)) == -1) {
75 fprintf(stderr, "failed to find video mode: %dx%d %dbpp\n", xres, yres, bpp);
78 vm = vid_modeinfo(mode);
80 if(!(framebuf = malloc(vm->pitch * vm->width))) {
81 fprintf(stderr, "failed to allocate main memory framebuffer\n");
85 if(!(vmem = vid_setmode(mode))) {
86 fprintf(stderr, "failed to set video mode %04x\n", mode);
110 static float fmin(float a, float b)
112 return a < b ? a : b;
115 #define PI 3.14159265
116 #define TWO_PI (PI * 2.0f)
122 struct vid_color cmap[256];
123 int winsz, winleft, winpos;
125 for(i=0; i<256; i++) {
126 float x = (float)i / (256.0f / TWO_PI);
127 cmap[i].r = (int)fmin(0.0f, sin(x) * 255.0f);
128 cmap[i].g = (int)fmin(0.0f, sin(x - PI) * 255.0f);
129 cmap[i].b = (int)fmin(0.0f, cos(x - TWO_PI) * 255.0f);
131 vid_setpal(0, 256, cmap);
135 for(i=0; i<vm->height; i++) {
136 for(j=0; j<vm->width; j++) {
140 vid_blitfb(framebuf, 0);
145 winsz = vm->win_size << 10;
154 for(i=0; i<vm->height; i++) {
155 for(j=0; j<vm->width; j++) {
157 winpos += vm->win_step;
158 vid_setwin(0, winpos);
175 int winsz, winleft, winpos;
181 winsz = vm->win_size << 10;
197 for(i=0; i<vm->height; i++) {
198 for(j=0; j<vm->width; j++) {
201 winpos += vm->win_step;
202 vid_setwin(0, winpos);
208 winleft -= (vm->bpp + 7) >> 3;
213 vm->ops.pack(&pcol, r, g, b);
237 vid_blitfb(framebuf, 0);