예제 #1
0
파일: ramsave.cpp 프로젝트: histat/dc-np2
UINT ccfile_write(CCFILEH hdl, const void *buf, UINT size) {

	UINT	ret;

	ret = 0;
	if (hdl == NULL) {
		goto cc_exit;
	}
	ret = min(size, hdl->size - hdl->pos);
	if (ret == 0) {
		goto cc_exit;
	}

	pushSaveData(hdl->id, hdl->pos, buf, ret);

	dc_savedtimes = Timer() + USEC_TO_TIMER(5*1000000);

	CopyMemory(hdl->ptr + hdl->pos, buf, ret);
	hdl->pos += ret;
  
cc_exit:
	return ret;
}
예제 #2
0
/* ptimer_thread_func:
 *  The timer thread.
 */
static void *ptimer_thread_func(void *unused)
{
   struct timeval old_time;
   struct timeval new_time;
   struct timeval delay;
   long interval = 0x8000;
#ifdef ALLEGRO_HAVE_POSIX_MONOTONIC_CLOCK
   struct timespec old_time_ns;
   struct timespec new_time_ns;
   int clock_monotonic;
#endif

   block_all_signals();

#ifdef ALLEGRO_LINUX_VGA
   /* privileges hack for Linux:
    *  One of the jobs of the timer thread is to update the mouse pointer
    *  on screen.  When using the Mode-X driver under Linux console, this
    *  involves selecting different planes (in modexgfx.s), which requires
    *  special priviledges.
    */
   if ((system_driver == &system_linux) && (__al_linux_have_ioperms)) {
      seteuid(0);
      iopl(3);
      seteuid(getuid());
   }
#endif

#ifdef ALLEGRO_QNX
   /* thread priority adjustment for QNX:
    *  The timer thread is set to the highest relative priority.
    *  (see the comment in src/qnx/qsystem.c about the scheduling policy)
    */
   {
      struct sched_param sparam;
      int spolicy;

      if (pthread_getschedparam(pthread_self(), &spolicy, &sparam) == EOK) {
         sparam.sched_priority += 4;
         pthread_setschedparam(pthread_self(), spolicy, &sparam);
      }
   }
#endif

#ifdef ALLEGRO_HAVE_POSIX_MONOTONIC_CLOCK
   /* clock_gettime(CLOCK_MONOTONIC, ...) is preferable to gettimeofday() in
    * case the system time is changed while the program is running.
    * CLOCK_MONOTONIC is not available on all systems.
    */
   clock_monotonic = (clock_gettime(CLOCK_MONOTONIC, &old_time_ns) == 0);
#endif

   gettimeofday(&old_time, 0);

   while (thread_alive) {
      /* `select' is more accurate than `usleep' on my system.  */
      delay.tv_sec = interval / TIMERS_PER_SECOND;
      delay.tv_usec = TIMER_TO_USEC(interval) % 1000000L;
      select(0, NULL, NULL, NULL, &delay);

      /* Calculate actual time elapsed.  */
#ifdef ALLEGRO_HAVE_POSIX_MONOTONIC_CLOCK
      if (clock_monotonic) {
         clock_gettime(CLOCK_MONOTONIC, &new_time_ns);
         interval = USEC_TO_TIMER(
            (new_time_ns.tv_sec - old_time_ns.tv_sec) * 1000000L +
            (new_time_ns.tv_nsec - old_time_ns.tv_nsec) / 1000);
         old_time_ns = new_time_ns;
      }
      else
#endif
      {
         gettimeofday(&new_time, 0);
         interval = USEC_TO_TIMER(
            (new_time.tv_sec - old_time.tv_sec) * 1000000L +
            (new_time.tv_usec - old_time.tv_usec));
         old_time = new_time;
      }

      /* Handle a tick.  */
      interval = _handle_timer_tick(interval);
   }

   return NULL;
}
예제 #3
0
파일: np2.cpp 프로젝트: histat/dc-np2
bool dcsys_task()
{
	enum {
		CMD_MENU = 1,
	};
	int cmd = 0;
  
	Event ev;
	static  unsigned int tick = 0;

	unsigned int tm = Timer() - tick;
	if (tm < USEC_TO_TIMER(1000000/60)) {
		return __dc_avail;
	}
  
	tick += tm;

	int x, y;

	int cJoy = 0;
	static int pJoy;
	static unsigned int repeatTime;

	if (__dc_avail) {

		dc_mouseaxis1 = 0;
		dc_mouseaxis2 = 0;

		while (PollEvent(ev)) {
      
			switch (ev.type) {
				
			case EVENT_KEYDOWN:
				switch (ev.key.keycode) {
				case KBD_S1: case KBD_S2:
					cmd = CMD_MENU;
					break;
	  
				default:
					dckbd_keydown(ev.key.keycode);
				}
				break;
	
			case EVENT_KEYUP:
				dckbd_keyup(ev.key.keycode);
				break;
	
			case EVENT_MOUSEMOTION:
				dc_mouseaxis1 += ev.motion.x;
				dc_mouseaxis2 += ev.motion.y;
				break;

			case EVENT_MOUSEBUTTONDOWN:
				switch (ev.button.button) {
				case EVENT_BUTTON_LEFT:
					mousemng_buttonevent(MOUSEMNG_LEFTDOWN);
					break;

				case EVENT_BUTTON_RIGHT:
					mousemng_buttonevent(MOUSEMNG_RIGHTDOWN);
					break;
				}
				break;
      
			case EVENT_MOUSEBUTTONUP:
				switch (ev.button.button) {
				case EVENT_BUTTON_LEFT:
					mousemng_buttonevent(MOUSEMNG_LEFTUP);
					break;

				case EVENT_BUTTON_RIGHT:
					mousemng_buttonevent(MOUSEMNG_RIGHTUP);
					break;
				}
				break;

			case EVENT_JOYAXISMOTION:
				x = 0;
				y = 0;
	
				if (ev.jaxis.axis == 0) {
					x = ev.jaxis.value;
				}
				if (ev.jaxis.axis == 1) {
					y = ev.jaxis.value;
				}

				dc_mouseaxis1 += x;
				dc_mouseaxis2 += y;
	  
				break;

			case EVENT_JOYBUTTONDOWN:

				if (ev.jbutton.button == JOY_START)
					cmd = CMD_MENU;
	
				if (ev.jbutton.button == JOY_RTRIGGER)
					__skbd_avail = !__skbd_avail;

				if (__skbd_avail && ev.jbutton.button == JOY_A)
					softkbddc_down();

				if (__skbd_avail && ev.jbutton.button == JOY_B)
					__use_bg = !__use_bg;
	
				if (__skbd_avail) {
					cJoy = ev.jbutton.button & 0xffff;
	  
				} else {
					switch (ev.jbutton.button) {

					case JOY_UP:
						dckbd_keydown(JOY1_UP);
						break;
	    
					case JOY_DOWN:
						dckbd_keydown(JOY1_DOWN);
						break;
	    
					case JOY_LEFT:
						dckbd_keydown(JOY1_LEFT);
						break;
	    
					case JOY_RIGHT:
						dckbd_keydown(JOY1_RIGHT);
						break;
	    
					case JOY_A:
						dckbd_keydown(JOY1_A);
						break;
	    
					case JOY_B:
						dckbd_keydown(JOY1_B);
						break;

					case JOY_X:
						mousemng_buttonevent(MOUSEMNG_LEFTDOWN);
						break;
	    
					case JOY_Y:
						mousemng_buttonevent(MOUSEMNG_RIGHTDOWN);
						break;
					}
				}
				break;
	
			case EVENT_JOYBUTTONUP:

				softkbddc_up();

				if (__skbd_avail) {

					pJoy = 0;
					repeatTime = 0;

				} else {
	  
					switch (ev.jbutton.button) {
	    
					case JOY_UP:
						dckbd_keyup(JOY1_UP);
						break;
	    
					case JOY_DOWN:
						dckbd_keyup(JOY1_DOWN);
						break;
	    
					case JOY_LEFT:
						dckbd_keyup(JOY1_LEFT);
						break;
	    
					case JOY_RIGHT:
						dckbd_keyup(JOY1_RIGHT);
						break;
	    
					case JOY_A:
						dckbd_keyup(JOY1_A);
						break;
	    
					case JOY_B:
						dckbd_keyup(JOY1_B);
						break;

					case JOY_X:
						mousemng_buttonevent(MOUSEMNG_LEFTUP);
						break;

					case JOY_Y:
						mousemng_buttonevent(MOUSEMNG_RIGHTUP);
						break;
					}
				}
				break;
	
			case EVENT_QUIT:
				__dc_avail = false;
				break;
			}
		}
	}


	if (__skbd_avail) {

		dc_joyinput = 0;

		int button = 0;
    
		if (cJoy) {
			repeatTime = Timer() + USEC_TO_TIMER(1000000/60*30);
			pJoy = cJoy;
			button = cJoy;
		} else if (repeatTime < Timer()) {

			button = pJoy;
			repeatTime = Timer() + USEC_TO_TIMER(1000000/60*10);
		}

		softkbddc_send(button);

	} else
		getJoyButton(JOYSTICKID1, &dc_joyinput);

	if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) {
		initsave();
		sysmng_initialize();
	}

	switch (cmd) {
	case CMD_MENU:
		sysmenu_menuopen();
		break;
	}

	scrnmng_update();
	softkbddc_draw();
	ta_commit_frame();
  
	return __dc_avail;
}