X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fkern%2Fmain.c;h=e52bb257fec43bc30493ea3c033ea9a736faebc9;hb=0105dfea1a7c351798088650e9b2a46b5a26237d;hp=6cf5de3636166b6d16a8cf2fb8cbc1e3320fbd51;hpb=28d5d8d6f0b9da979030465c304157a4919ca6de;p=metatoy diff --git a/src/kern/main.c b/src/kern/main.c index 6cf5de3..e52bb25 100644 --- a/src/kern/main.c +++ b/src/kern/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "segm.h" #include "intr.h" #include "mem.h" @@ -13,11 +14,18 @@ unsigned char *framebuf, *vmem = (unsigned char*)0xa0000; static int quit; +static int mx, my; +static long last_mouse_ev; + +#define CURSOR_TIMEOUT MSEC_TO_TICKS(3000) +static void draw_cursor(int mx, int my); int main(void) { int key; + int prev_mx = 0, prev_my = 0; + unsigned int mbn, prev_mbn = 0, mbn_diff; init_segm(); init_intr(); @@ -37,10 +45,38 @@ int main(void) goto end; } + set_mouse_pos(160, 100); + last_mouse_ev = LONG_MIN; + for(;;) { if((key = kb_getkey()) >= 0) { game_keyboard(key, 1); } + + mbn = mouse_state(&mx, &my); + + if((mbn_diff = mbn ^ prev_mbn) != 0) { + if(mbn_diff & 1) { + game_mouse(0, mbn & 1, mx, my); + last_mouse_ev = nticks; + } + if(mbn_diff & 2) { + game_mouse(2, mbn & 2, mx, my); + last_mouse_ev = nticks; + } + if(mbn_diff & 4) { + game_mouse(1, mbn & 4, mx, my); + last_mouse_ev = nticks; + } + } + if(mx != prev_mx || my != prev_my) { + game_motion(mx, my); + last_mouse_ev = nticks; + } + prev_mbn = mbn; + prev_mx = mx; + prev_my = my; + if(quit) break; game_draw(); } @@ -52,6 +88,11 @@ end: return 0; } +unsigned long game_getmsec(void) +{ + return TICKS_TO_MSEC(nticks); +} + void game_quit(void) { quit = 1; @@ -59,5 +100,35 @@ void game_quit(void) void game_swap_buffers(void) { + if((long)nticks - last_mouse_ev < MSEC_TO_TICKS(3000)) { + draw_cursor(mx, my); + } + memcpy(vmem, framebuf, 64000); } + +#define CUR_SZ 4 + +static void draw_cursor(int mx, int my) +{ + int i, sx, ex, sy, ey, xlen, ylen; + unsigned char *ptr; + + sx = mx < CUR_SZ ? mx : mx - CUR_SZ; + ex = mx >= 320 - CUR_SZ ? CUR_SZ - 1 : mx + CUR_SZ; + xlen = ex - sx + 1; + sy = my < CUR_SZ ? my : my - CUR_SZ; + ey = my >= 200 - CUR_SZ ? CUR_SZ - 1 : my + CUR_SZ; + ylen = ey - sy + 1; + + ptr = framebuf + (my << 8) + (my << 6) + sx; + for(i=0; i