nuclear@1: #include nuclear@1: #include nuclear@1: #include nuclear@1: #include nuclear@1: #include "inttypes.h" nuclear@1: #include "gfx.h" nuclear@1: #include "keyb.h" nuclear@1: #include "mouse.h" nuclear@1: #include "logger.h" nuclear@1: nuclear@1: static void display(); nuclear@1: static void swap_buffers(); nuclear@1: static void handle_keyboard(); nuclear@1: static void handle_mouse(); nuclear@1: static bool parse_args(int argc, char **argv); nuclear@1: nuclear@1: static int xsz = 800; nuclear@1: static int ysz = 600; nuclear@1: static int bpp = 16; nuclear@1: static int bytespp; nuclear@1: static unsigned char *fb; nuclear@1: static unsigned char *backbuf; nuclear@1: static int rbits, gbits, bbits; nuclear@1: static int rshift, gshift, bshift; nuclear@1: static unsigned int rmask, gmask, bmask; nuclear@1: nuclear@1: static bool quit; nuclear@1: nuclear@1: int main(int argc, char **argv) nuclear@1: { nuclear@1: if(!parse_args(argc, argv)) { nuclear@1: return 1; nuclear@1: } nuclear@1: if(kb_init(32) == -1) { nuclear@1: fprintf(stderr, "failed to initialize keyboard driver\n"); nuclear@1: return 1; nuclear@1: } nuclear@1: if(!(fb = (unsigned char*)set_video_mode(xsz, ysz, bpp))) { nuclear@1: set_text_mode(); nuclear@1: fprintf(stderr, "failed to set video mode: %dx%d %dbpp\n", xsz, ysz, bpp); nuclear@1: return 1; nuclear@1: } nuclear@1: bpp = get_color_depth(); nuclear@1: get_color_bits(&rbits, &gbits, &bbits); nuclear@1: get_color_shift(&rshift, &gshift, &bshift); nuclear@1: get_color_mask(&rmask, &gmask, &bmask); nuclear@1: bytespp = (int)ceil(bpp / 8.0); nuclear@1: nuclear@1: printlog("bpp: %d (%d %d %d)\n", bpp, rbits, gbits, bbits); nuclear@1: printlog("shift: %d %d %d\n", rshift, gshift, bshift); nuclear@1: printlog("mask: %x %x %x\n", rmask, gmask, bmask); nuclear@1: nuclear@1: backbuf = new unsigned char[xsz * ysz * 3]; nuclear@1: nuclear@1: // main loop nuclear@1: for(;;) { nuclear@1: handle_keyboard(); nuclear@1: handle_mouse(); nuclear@1: if(quit) break; nuclear@1: nuclear@1: display(); nuclear@1: } nuclear@1: nuclear@1: delete [] backbuf; nuclear@1: nuclear@1: set_text_mode(); nuclear@1: kb_shutdown(); nuclear@1: nuclear@1: printf("Thank you for using Rayzor!\n"); nuclear@1: return 0; nuclear@1: } nuclear@1: nuclear@1: static void display() nuclear@1: { nuclear@1: unsigned char *fbptr = backbuf; nuclear@1: nuclear@1: for(int i=0; i> srs, src[1] >> sgs, src[2] >> sbs); nuclear@1: src += 3; nuclear@1: } nuclear@1: } nuclear@1: break; nuclear@1: nuclear@1: default: nuclear@1: break; nuclear@1: } nuclear@1: } nuclear@1: nuclear@1: static void handle_keyboard() nuclear@1: { nuclear@5: int key; nuclear@1: nuclear@5: while((key = kb_getkey()) != -1) { nuclear@5: switch(key) { nuclear@5: case 27: nuclear@5: quit = true; nuclear@5: return; nuclear@5: } nuclear@1: } nuclear@1: } nuclear@1: nuclear@1: static void handle_mouse() nuclear@1: { nuclear@1: } nuclear@1: nuclear@1: static struct { nuclear@1: int opt; nuclear@1: const char *lopt; nuclear@1: const char *desc; nuclear@1: } options[] = { nuclear@1: {'s', "size", "resolution x[:bpp]"}, nuclear@1: {'h', "help", "print usage information and exit"}, nuclear@1: {-1, 0, 0} nuclear@1: }; nuclear@1: nuclear@1: static void print_usage(const char *argv0) nuclear@1: { nuclear@1: printf("%s usage\n", argv0); nuclear@1: for(int i=0; options[i].opt != -1; i++) { nuclear@1: printf(" -%c, -%s: %s\n", options[i].opt, options[i].lopt, options[i].desc); nuclear@1: } nuclear@1: exit(0); nuclear@1: } nuclear@1: nuclear@1: static bool parse_args(int argc, char **argv) nuclear@1: { nuclear@1: for(int i=1; i