X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fdos%2Fmain.c;h=5d840b13b290d638950cc2300d5f7bcbb48ff82a;hp=aed4e8aa90fa9af01b51bc038fd1abbe1faed5a2;hb=e8b26db00c934d141f16652cb8dcbeae23b17e48;hpb=9ecf7c26db456b3cef34a7d6d79ffb164cad17c5 diff --git a/src/dos/main.c b/src/dos/main.c index aed4e8a..5d840b1 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -15,6 +15,7 @@ #include "cfgopt.h" #include "logger.h" #include "tinyfps.h" +#include "cdpmi.h" #undef NOKEYB @@ -22,7 +23,6 @@ static int handle_sball_event(sball_event *ev); static void recalc_sball_matrix(float *xform); static int quit; -static int use_mouse; static long fbsize; static int use_sball; @@ -31,7 +31,11 @@ static quat_t rot = {0, 0, 0, 1}; int main(int argc, char **argv) { - fbsize = fb_width * fb_height * fb_bpp / CHAR_BIT; +#ifdef __DJGPP__ + __djgpp_nearptr_enable(); +#endif + + fbsize = FB_WIDTH * FB_HEIGHT * FB_BPP / 8; init_logger("demo.log"); @@ -40,25 +44,28 @@ int main(int argc, char **argv) kb_init(32); #endif - if((use_mouse = have_mouse())) { - printf("initializing mouse input\n"); - set_mouse_limits(0, 0, fb_width, fb_height); - set_mouse(fb_width / 2, fb_height / 2); - } - - if(!(fb_pixels = malloc(fbsize))) { + /* now start_loadscr sets up fb_pixels to the space used by the loading image, + * so no need to allocate another framebuffer + */ +#if 0 + /* allocate a couple extra rows as a guard band, until we fucking fix the rasterizer */ + if(!(fb_pixels = malloc(fbsize + (FB_WIDTH * FB_BPP / 8) * 2))) { fprintf(stderr, "failed to allocate backbuffer\n"); return 1; } + fb_pixels += FB_WIDTH; +#endif - if(!(vmem_back = set_video_mode(fb_width, fb_height, fb_bpp))) { + if(!(vmem = set_video_mode(FB_WIDTH, FB_HEIGHT, FB_BPP, 1))) { return 1; } - if(!(vmem_front = page_flip(FLIP_NOW))) { - fprintf(stderr, "page flipping not supported. falling back to double buffering\n"); - vmem_front = vmem_back; - } else { - assert(vmem_back != vmem_front); + + if(opt.mouse) { + if((opt.mouse = have_mouse())) { + printf("initializing mouse input\n"); + set_mouse_limits(0, 0, FB_WIDTH - 1, FB_HEIGHT - 1); + set_mouse(FB_WIDTH / 2, FB_HEIGHT / 2); + } } if(demo_init(argc, argv) == -1) { @@ -85,7 +92,7 @@ int main(int argc, char **argv) #endif if(quit) goto break_evloop; - if(use_mouse) { + if(opt.mouse) { mouse_bmask = read_mouse(&mouse_x, &mouse_y); } if(use_sball && sball_pending()) { @@ -119,32 +126,17 @@ void demo_quit(void) void swap_buffers(void *pixels) { - if(pixels) { - /* just memcpy to the front buffer */ - if(opt.vsync) { - wait_vsync(); - } - drawFps(pixels); - memcpy(vmem_front, pixels, fbsize); - - } else { - /* attempt page flipping */ - void *next; - - drawFps(vmem_back); - if((next = page_flip(opt.vsync ? FLIP_VBLANK_WAIT : FLIP_NOW))) { - assert(next == vmem_back); - vmem_back = vmem_front; - vmem_front = next; - } else { - /* failed to page flip, assume we drew in the front buffer then - * and just wait for vsync if necessary - */ - if(opt.vsync) { - wait_vsync(); - } - } + if(!pixels) { + pixels = fb_pixels; + } + + demo_post_draw(pixels); + + /* just memcpy to the front buffer */ + if(opt.vsync) { + wait_vsync(); } + memcpy(vmem, pixels, fbsize); }