From: John Tsiombikas Date: Wed, 11 Oct 2023 11:31:00 +0000 (+0300) Subject: simplistic mouse cursor X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=66cfc3e189df8362aa77f7a2f3e2495bf00ab2c3;p=metatoy simplistic mouse cursor --- diff --git a/src/kern/main.c b/src/kern/main.c index 6c37116..2dd7465 100644 --- a/src/kern/main.c +++ b/src/kern/main.c @@ -13,11 +13,16 @@ unsigned char *framebuf, *vmem = (unsigned char*)0xa0000; static int quit; +static int mx, my; + +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 +42,33 @@ int main(void) goto end; } + set_mouse_pos(160, 100); + 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); + } + if(mbn_diff & 2) { + game_mouse(2, mbn & 2, mx, my); + } + if(mbn_diff & 4) { + game_mouse(1, mbn & 4, mx, my); + } + } + if(mx != prev_mx || my != prev_my) { + game_motion(mx, my); + } + prev_mbn = mbn; + prev_mx = mx; + prev_my = my; + if(quit) break; game_draw(); } @@ -64,5 +92,33 @@ void game_quit(void) void game_swap_buffers(void) { + 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