8 struct vid_modeinfo *vm;
11 static const char *usage_fmt = "Usage %s: [options]\n"
13 " -s <XxY>: video resolution\n"
14 " -b <bpp>: color depth\n";
16 int main(int argc, char **argv)
24 for(i=1; i<argc; i++) {
25 if(argv[i][0] == '-') {
27 invalopt: fprintf(stderr, "invalid option: %s\n", argv[i]);
32 if(!argv[++i] || sscanf(argv[i], "%dx%d", &xres, &yres) != 2) {
33 fprintf(stderr, "invalid resolution: %s\n", argv[i]);
39 if(!argv[++i] || (bpp = atoi(argv[i])) <= 0) {
40 fprintf(stderr, "invalid color depth: %s\n", argv[i]);
45 printf(usage_fmt, argv[0]);
52 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
58 if(vid_init() == -1) {
59 fprintf(stderr, "failed to initialize video\n");
62 printf("press any key...\n");
65 if((mode = vid_findmode(xres, yres, bpp)) == -1) {
66 fprintf(stderr, "failed to find video mode: %dx%d %dbpp\n", xres, yres, bpp);
69 if(!(vmem = vid_setmode(mode))) {
70 fprintf(stderr, "failed to set video mode %04x\n", mode);
73 vm = vid_modeinfo(mode);
98 static float fmin(float a, float b)
100 return a < b ? a : b;
103 #define PI 3.14159265
104 #define TWO_PI (PI * 2.0f)
109 unsigned char *fb = vmem;
110 struct vid_color cmap[256];
112 for(i=0; i<256; i++) {
113 float x = (float)i / (256.0f / TWO_PI);
114 cmap[i].r = (int)fmin(0.0f, sin(x) * 255.0f);
115 cmap[i].g = (int)fmin(0.0f, sin(x - PI) * 255.0f);
116 cmap[i].b = (int)fmin(0.0f, cos(x - TWO_PI) * 255.0f);
118 vid_setpal(0, 256, cmap);
122 for(i=0; i<vm->height; i++) {
123 for(j=0; j<vm->width; j++) {