X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fdos%2Fmain.c;h=e3242f1135abe7748ee18251bc539cba7b8ba6e7;hb=HEAD;hp=1c694c8fedea59da3c23545cefe172d8ad789454;hpb=af36400e1b3d2d591beaf66e1539884434e30475;p=retroray diff --git a/src/dos/main.c b/src/dos/main.c index 1c694c8..e3242f1 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -18,8 +18,10 @@ along with this program. If not, see . #include #include #include +#include #include #include "app.h" +#include "timer.h" #include "keyb.h" #include "vidsys.h" #include "cdpmi.h" @@ -28,6 +30,7 @@ along with this program. If not, see . #include "options.h" #include "cpuid.h" #include "util.h" +#include "rtk.h" static INLINE int clamp(int x, int a, int b) { @@ -37,59 +40,76 @@ static INLINE int clamp(int x, int a, int b) } static void draw_cursor(int x, int y); +static void draw_rband(rtk_rect *r); static uint32_t *vmem; -static int quit, disp_pending; +static int quit, dirty_valid; +static rtk_rect dirty; +static int mx, my, prev_mx, prev_my; +static rtk_rect rband, prev_rband; + int main(int argc, char **argv) { int i; int vmidx; - int mx, my, mdx, mdy, prev_mx, prev_my, bnstate, bndiff; + int mdx, mdy, bnstate, bndiff; static int prev_bnstate; + char *env; #ifdef __DJGPP__ __djgpp_nearptr_enable(); #endif + if(!have_mouse()) { + fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n"); + return 1; + } + init_logger(); if(read_cpuid(&cpuid) == 0) { print_cpuid(&cpuid); } + init_timer(0); kb_init(); - if(!have_mouse()) { - fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n"); - return 1; - } + load_options(CFGFILE); - /*add_log_file("retroray.log");*/ + if((env = getenv("RRLOG"))) { + if(tolower(env[0]) == 'c' && tolower(env[1]) == 'o' && tolower(env[2]) == 'm' + && isdigit(env[3])) { + add_log_console(env); + } else { + add_log_file(env); + } + } if(vid_init() == -1) { return 1; } - if((vmidx = vid_findmode(640, 480, 32)) == -1) { + if((vmidx = vid_findmode(opt.xres, opt.yres, opt.bpp)) == -1) { return 1; } if(!(vmem = vid_setmode(vmidx))) { return 1; } - win_width = 640; - win_height = 480; + win_width = opt.xres; + win_height = opt.yres; win_aspect = (float)win_width / (float)win_height; if(app_init() == -1) { goto break_evloop; } - disp_pending = 1; + app_redisplay(0, 0, 0, 0); app_reshape(win_width, win_height); mx = win_width / 2; my = win_height / 2; + prev_mx = prev_my = -1; for(;;) { int key; @@ -106,7 +126,11 @@ int main(int argc, char **argv) } while((key = kb_getkey()) != -1) { - app_keyboard(key, 1); + if(key == 'r' && (modkeys & KEY_MOD_CTRL)) { + app_redisplay(0, 0, 0, 0); + } else { + app_keyboard(key, 1); + } if(quit) goto break_evloop; } @@ -115,8 +139,6 @@ int main(int argc, char **argv) prev_bnstate = bnstate; read_mouse_rel(&mdx, &mdy); - prev_mx = mx; - prev_my = my; mx = clamp(mx + mdx, 0, win_width - 1); my = clamp(my + mdy, 0, win_height - 1); mdx = mx - prev_mx; @@ -130,14 +152,7 @@ int main(int argc, char **argv) app_motion(mx, my); } - if(disp_pending) { - disp_pending = 0; - app_display(); - } - - draw_cursor(prev_mx, prev_my); - draw_cursor(mx, my); - + app_display(); app_swap_buffers(); } @@ -148,14 +163,27 @@ break_evloop: return 0; } -long app_getmsec(void) +void app_redisplay(int x, int y, int w, int h) { - return time(0) * 1000; /* TODO */ -} + rtk_rect r; + + if((w | h) == 0) { + r.x = r.y = 0; + r.width = win_width; + r.height = win_height; + } else { + r.x = x; + r.y = y; + r.width = w; + r.height = h; + } -void app_redisplay(void) -{ - disp_pending = 1; + if(dirty_valid) { + rtk_rect_union(&dirty, &r); + } else { + dirty = r; + } + dirty_valid = 1; } void app_swap_buffers(void) @@ -163,7 +191,29 @@ void app_swap_buffers(void) if(opt.vsync) { vid_vsync(); } - vid_blitfb32(framebuf, 0); + if(dirty_valid) { + if(dirty.width < win_width || dirty.height < win_height) { + uint32_t *src = framebuf + dirty.y * win_width + dirty.x; + vid_blit32(dirty.x, dirty.y, dirty.width, dirty.height, src, 0); + } else { + vid_blitfb32(framebuf, 0); + } + dirty_valid = 0; + } + if(prev_mx >= 0) { + draw_cursor(prev_mx, prev_my); + } + draw_cursor(mx, my); + prev_mx = mx; + prev_my = my; + + if(prev_rband.width) { + draw_rband(&prev_rband); + } + if(rband.width) { + draw_rband(&rband); + } + prev_rband = rband; } void app_quit(void) @@ -183,10 +233,22 @@ void app_vsync(int vsync) { } +void app_rband(int x, int y, int w, int h) +{ + if(!(w | h)) { + w = h = 0; + } + + rband.x = x; + rband.y = y; + rband.width = w; + rband.height = h; +} + static void draw_cursor(int x, int y) { int i; - uint32_t *fbptr = framebuf + y * win_width + x; + uint32_t *fbptr = vmem + y * win_width + x; for(i=0; i<3; i++) { int offs = i + 1; @@ -196,3 +258,31 @@ static void draw_cursor(int x, int y) if(x < win_width - offs - 1) fbptr[offs] ^= 0xffffff; } } + +static void draw_rband(rtk_rect *r) +{ + int i; + rtk_rect rect; + uint32_t *fbptr, *bptr; + + rect = *r; + rtk_fix_rect(&rect); + + if(rect.width <= 0 || rect.height <= 0) { + return; + } + + fbptr = vmem + rect.y * win_width + rect.x; + bptr = fbptr + win_width * (rect.height - 1); + + for(i=0; i