14 unsigned char *framebuf, *vmem = (unsigned char*)0xa0000;
18 static long last_mouse_ev;
20 #define CURSOR_TIMEOUT MSEC_TO_TICKS(3000)
21 static void draw_cursor(int mx, int my);
27 int prev_mx = 0, prev_my = 0;
28 unsigned int mbn, prev_mbn = 0, mbn_diff;
39 if(!(framebuf = malloc(320 * 200))) {
40 printf("failed to allocate framebuffer\n");
44 if(game_init() == -1) {
48 set_mouse_pos(160, 100);
49 last_mouse_ev = LONG_MIN;
52 if((key = kb_getkey()) >= 0) {
53 game_keyboard(key, 1);
56 mbn = mouse_state(&mx, &my);
58 if((mbn_diff = mbn ^ prev_mbn) != 0) {
60 game_mouse(0, mbn & 1, mx, my);
61 last_mouse_ev = nticks;
64 game_mouse(2, mbn & 2, mx, my);
65 last_mouse_ev = nticks;
68 game_mouse(1, mbn & 4, mx, my);
69 last_mouse_ev = nticks;
72 if(mx != prev_mx || my != prev_my) {
74 last_mouse_ev = nticks;
86 cleanup_intr(); /* also disables interrupts */
91 unsigned long game_getmsec(void)
93 return TICKS_TO_MSEC(nticks);
101 void game_swap_buffers(void)
103 if((long)nticks - last_mouse_ev < MSEC_TO_TICKS(3000)) {
107 memcpy(vmem, framebuf, 64000);
112 static void draw_cursor(int mx, int my)
114 int i, sx, ex, sy, ey, xlen, ylen;
117 sx = mx < CUR_SZ ? mx : mx - CUR_SZ;
118 ex = mx >= 320 - CUR_SZ ? CUR_SZ - 1 : mx + CUR_SZ;
120 sy = my < CUR_SZ ? my : my - CUR_SZ;
121 ey = my >= 200 - CUR_SZ ? CUR_SZ - 1 : my + CUR_SZ;
124 ptr = framebuf + (my << 8) + (my << 6) + sx;
125 for(i=0; i<xlen; i++) {
129 ptr = framebuf + (sy << 8) + (sy << 6) + mx;
130 for(i=0; i<ylen; i++) {