bool
InfoBoxContentMacCready::HandleQuickAccess(const TCHAR *misc)
{
  if (protected_task_manager == NULL)
    return false;

  const SETTINGS_COMPUTER &settings_computer =
    CommonInterface::SettingsComputer();
  const GlidePolar &polar = settings_computer.glide_polar_task;
  fixed mc = polar.GetMC();

  if (_tcscmp(misc, _T("+0.1")) == 0) {
    return HandleKey(ibkUp);

  } else if (_tcscmp(misc, _T("+0.5")) == 0) {
    mc = std::min(mc + fixed_one / 2, fixed(5));
    ActionInterface::SetMacCready(mc);
    return true;

  } else if (_tcscmp(misc, _T("-0.1")) == 0) {
    return HandleKey(ibkDown);

  } else if (_tcscmp(misc, _T("-0.5")) == 0) {
    mc = std::max(mc - fixed_one / 2, fixed_zero);
    ActionInterface::SetMacCready(mc);
    return true;

  } else if (_tcscmp(misc, _T("mode")) == 0) {
    return HandleKey(ibkEnter);
  }

  return false;
}
Exemple #2
0
InputResult SdlInput::CheckInput()
{
    SDL_Event event;
    while (SDL_PollEvent(&event))
    {
        switch (event.type)
        {
        case SDL_KEYDOWN:
            if (event.key.repeat == 0)
            {
                switch (event.key.keysym.sym)
                {
                case SDLK_F1: return InputResult::SaveState;
                case SDLK_F2: return InputResult::LoadState;
                case SDLK_ESCAPE: return InputResult::Quit;
                default:
                    HandleKey(event.key.keysym.sym, true);
                }
            }
            break;
        case SDL_KEYUP:
            if (event.key.repeat == 0)
            {
                HandleKey(event.key.keysym.sym, false);
            }
            break;
        case SDL_WINDOWEVENT:
            if (event.window.event == SDL_WINDOWEVENT_CLOSE)
            {
                return InputResult::Quit;
            }
        }
    }
    return InputResult::Continue;
}
Exemple #3
0
void wxVListBoxComboPopup::OnComboDoubleClick()
{
    // Cycle on dclick (disable saturation to allow true cycling).
    if ( !::wxGetKeyState(WXK_SHIFT) )
        HandleKey(WXK_DOWN,false);
    else
        HandleKey(WXK_UP,false);
}
Exemple #4
0
int main(void)
{
    // init sys
    SystemInit();

    // init peripheral
    UART_Configuration();
    delay_init();   
    KEY_GPIO_Init();
    TIM3_Int_Init(100,7199);
    Motor_Init();
    RGB_LED_Init();
    DHT11_Init();
    IR_Init();

    // init vars
    GenProtocolInit();
    BuzProtocolInit();
    UartInit();

    while(1)
    {
        // handle uart msg
        HandleMsg();
        
        // handle key events
        HandleKey();        

        // business logic tick 
        BuzTick();  
    }
}
Exemple #5
0
boolean TextManip::Manipulating (Event& e) {
    boolean manipulating = true;

    if (e.eventType == KeyEvent) {
        manipulating = HandleKey(e);

    } else if (e.eventType == MotionEvent && _selecting) {
        SelectMore(Locate(e.x, e.y));

    } else if (e.eventType == DownEvent) {
        if (e.shift) {
            SelectMore(Locate(e.x, e.y));
            _selecting = true;

        } else if (Contains(e.x, e.y)) {
            Select(Locate(e.x, e.y));
            _selecting = true;

        } else {
            manipulating = false;
        }

    } else if (e.eventType == UpEvent) {
        _selecting = false;
    }
    return manipulating;
}
Exemple #6
0
static LRESULT CALLBACK TreeProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) {
    UNUSED(uIdSubclass);
    TreeCtrl* w = (TreeCtrl*)dwRefData;
    CrashIf(w->hwnd != (HWND)hwnd);

    if (w->preFilter) {
        bool discard = false;
        auto res = w->preFilter(hwnd, msg, wp, lp, discard);
        if (discard) {
            return res;
        }
    }

    if (WM_ERASEBKGND == msg) {
        return FALSE;
    }

    if (WM_KEYDOWN == msg) {
        if (HandleKey(hwnd, wp)) {
            return 0;
        }
    }

    if (WM_NCDESTROY == msg) {
        Unsubclass(w);
        return DefSubclassProc(hwnd, msg, wp, lp);
    }

    return DefSubclassProc(hwnd, msg, wp, lp);
}
Exemple #7
0
LRESULT CACEdit::OnUpdateFromList(WPARAM lParam, LPARAM /*wParam*/)
{
	UpdateData(true);

	if(lParam == WM_KEYDOWN)
	{
		HandleKey(VK_DOWN,true);
	}
	return 0;
}
Exemple #8
0
BOOL CACEdit::PreTranslateMessage(MSG* pMsg)
{
	if(pMsg->message == WM_KEYDOWN)
	{
		if(m_Liste.IsWindowVisible())
		{
			if(m_iType == _COMBOBOX_)
			{
				if(pMsg->wParam == VK_DOWN || pMsg->wParam == VK_UP)
					if (HandleKey((UINT)pMsg->wParam, false))
						return true;
			}

			if(pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN)
				if (HandleKey((UINT)pMsg->wParam, false))
					return true;
		}
	}
	return CWnd::PreTranslateMessage(pMsg);
}
Exemple #9
0
bool
InfoBoxWindow::OnKeyDown(unsigned key_code)
{
  /* handle local hot key */

  switch (key_code) {
  case KEY_UP:
    focus_timer.Schedule(FOCUS_TIMEOUT_MAX);
    return HandleKey(InfoBoxContent::ibkUp);

  case KEY_DOWN:
    focus_timer.Schedule(FOCUS_TIMEOUT_MAX);
    return HandleKey(InfoBoxContent::ibkDown);

  case KEY_LEFT:
    focus_timer.Schedule(FOCUS_TIMEOUT_MAX);
    return HandleKey(InfoBoxContent::ibkLeft);

  case KEY_RIGHT:
    focus_timer.Schedule(FOCUS_TIMEOUT_MAX);
    return HandleKey(InfoBoxContent::ibkRight);

  case KEY_RETURN:
    ShowDialog();
    return true;

  case KEY_ESCAPE:
    focus_timer.Cancel();
    FocusParent();
    return true;
  }

  /* handle global hot key */

  if (InputEvents::ProcessKey(InputEvents::MODE_INFOBOX, key_code))
    return true;

  /* call super class */

  return PaintWindow::OnKeyDown(key_code);
}
Exemple #10
0
BOOL CParser::ParseTable(DWORD dwUserData)
/***********************************************************************/
{
	BOOL fRet = TRUE;
	LPSTR lpString, lpEntryString, lpKey, lpValues;
	int nIndex, nValues;
	HPTR lpData;
	LPSTR lpStringBuf, lpEntryStringBuf;

	if (!InitTable(dwUserData))
		return(FALSE);

	lpStringBuf = (LPSTR)Alloc(BUFFER_SIZE);
	lpEntryStringBuf = (LPSTR)Alloc(BUFFER_SIZE);
	if (!lpStringBuf || !lpEntryStringBuf)
	{
		if (lpStringBuf)
			FreeUp(lpStringBuf);
		if (lpEntryStringBuf)
			FreeUp(lpEntryStringBuf);
		return(FALSE);
	}
	nIndex = 0;
	lpData = m_lpTableData;
	while ( GetEntryString( &lpData, lpEntryStringBuf, BUFFER_SIZE ) )
	{
		// Keep a copy of the Entry string for error messages
		lpString = lpStringBuf;
		lpEntryString = lpEntryStringBuf;
		lstrcpy(lpString, lpEntryString);

		// get key
		while (lpKey = GetKey( &lpEntryString ))
		{
			// get value
			if (lpValues = GetValues( &lpEntryString, &nValues ))
			{
				// handle this entry
				if (!HandleKey(lpString, lpKey, lpValues, nValues, nIndex, dwUserData))
				{
					fRet = FALSE;
					break;
				}
			}
		}

		// process next entry
		++nIndex;
	}
	FreeUp(lpStringBuf);
	FreeUp(lpEntryStringBuf);
	return(fRet);
}
Exemple #11
0
void wxVListBoxComboPopup::OnComboKeyEvent( wxKeyEvent& event )
{
    // Saturated key movement on
    if ( !HandleKey(event.GetKeyCode(),true,
#if wxUSE_UNICODE
        event.GetUnicodeKey()
#else
        0
#endif
        ) )
        event.Skip();
}
Exemple #12
0
void wxVListBoxComboPopup::OnComboCharEvent( wxKeyEvent& event )
{
    // unlike in OnComboKeyEvent, wxEVT_CHAR contains meaningful
    // printable character information, so pass it
#if wxUSE_UNICODE
    const wxChar charcode = event.GetUnicodeKey();
#else
    const wxChar charcode = (wxChar)event.GetKeyCode();
#endif

    if ( !HandleKey(event.GetKeyCode(), true, charcode) )
        event.Skip();
}
Exemple #13
0
int CGame::ProcessEvents()
{
	SMortalEvent oEvent;
	
	while (MortalPollEvent(oEvent))
	{
		switch (oEvent.m_enType)
		{
			case Me_QUIT:
				g_oState.m_bQuitFlag = true;
				return 1;

			case Me_MENU:
				if ( Ph_REWIND == m_enGamePhase
					|| Ph_SLOWFORWARD == m_enGamePhase )
				{
					// Menu counts as 'skip' during instant replay
					return 1;
				}
				
				if ( !IsNetworkGame() )
				{
					SState::TGameMode enMode = g_oState.m_enGameMode;
					::DoMenu();
					return g_oState.m_enGameMode == enMode ? 0 : 1;
				}
				break;

			case Me_SKIP:
				return 1;

			case Me_PLAYERKEYDOWN:
			case Me_PLAYERKEYUP:
			{
				if ( Ph_NORMAL != m_enGamePhase &&
					Ph_REPLAY != m_enGamePhase )
					break;
					
				HandleKey( oEvent.m_iPlayer, oEvent.m_iKey, Me_PLAYERKEYDOWN == oEvent.m_enType );
				break;
			}

			case Me_NOTHING:
				break;
			
		} // End of switch
	} // End of while polling events;
	
	return 0;
}
Exemple #14
0
dword ListPage::OnKey( dword key, dword extKey )
{
	HandleKey(RKEY_Exit, Close());
	if ((m_dwFlags & LF_ONE_ITEM_ONLY) == 0)
	{
		HandleExtKey2(RKEY_ChUp, RKEY_ChUp, RAWKEY_Up, MoveSelection(-1));
		HandleExtKey2(RKEY_ChDown, RKEY_ChDown, RAWKEY_Down, MoveSelection(1));
		HandleKey(RKEY_Forward, MoveSelection(CountItemsInView(), false));
		HandleKey(RKEY_Rewind, MoveSelection(-CountItemsInView(), false));
	}

	ListItem* pSelItem = ListPage::GetSelectedItem();
	if (pSelItem)
	{
		dword dwRet = pSelItem->OnKey(key, extKey);
		if ((dwRet == 0) && Tapplication::GetTheApplication() && !Tapplication::GetTheApplication()->IsClosing()
			&& Tapplication::GetTheApplication()->IsTopPage(this))
			Draw();
		return dwRet;
	}

	return key;
}
void HandleKeyEvent(KeyEvent *event)
{
  int key_status = (event->type==EVENT_KEYPRESS ? KEY_PRESSED : KEY_RELEASED);
  boolean with_modifiers = (game_status == GAME_MODE_PLAYING ? FALSE : TRUE);
  Key key = GetEventKey(event, with_modifiers);
  Key keymod = (with_modifiers ? GetEventKey(event, FALSE) : key);

#if DEBUG_EVENTS
  printf("::: KEY EVENT: %d %s\n", GetEventKey(event, TRUE),
	 event->type == EVENT_KEYPRESS ? "pressed" : "released");
#endif

  HandleKeyModState(keymod, key_status);
  HandleKey(key, key_status);
}
Exemple #16
0
long __stdcall WindowProcedure(HWND window, unsigned int msg, WPARAM wp,
                               LPARAM lp) {
  switch (msg) {
  case WM_DESTROY:
    PostQuitMessage(0);
    if (g_renderer)
      g_renderer->SetRunning(false);
    return 0L;
  case WM_KEYDOWN:
    HandleKey(wp);
    return 0L;
  default:
    return DefWindowProc(window, msg, wp, lp);
  }
}
Exemple #17
0
void CNFGHandleInput()
{
	static int ButtonsDown;
	XEvent report;

	int bKeyDirection = 1;
	int r;
	while( (r=XCheckMaskEvent( CNFGDisplay, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask , &report )) )
	{
//		XEvent nev;
//		XPeekEvent(CNFGDisplay, &nev);

		//printf( "EVENT %d\n", report.type );
		//XMaskEvent(CNFGDisplay, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask, &report);

		bKeyDirection = 1;
		switch  (report.type)
		{
		case NoExpose:
			break;
		case Expose:
			XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt );
			if( CNFGPixmap ) XFreePixmap( CNFGDisplay, CNFGPixmap );
			CNFGPixmap = XCreatePixmap( CNFGDisplay, CNFGWindow, CNFGWinAtt.width, CNFGWinAtt.height, CNFGWinAtt.depth );
			if( CNFGGC ) XFreeGC( CNFGDisplay, CNFGGC );
			CNFGGC = XCreateGC(CNFGDisplay, CNFGPixmap, 0, 0);
			break;
		case KeyRelease:
			bKeyDirection = 0;
		case KeyPress:
			HandleKey( XLookupKeysym(&report.xkey, 0), bKeyDirection );
			break;
		case ButtonRelease:
			bKeyDirection = 0;
		case ButtonPress:
			HandleButton( report.xbutton.x, report.xbutton.y, report.xbutton.button, bKeyDirection );
			ButtonsDown = (ButtonsDown & (~(1<<report.xbutton.button))) | ( bKeyDirection << report.xbutton.button );

			//Intentionall fall through -- we want to send a motion in event of a button as well.
		case MotionNotify:
			HandleMotion( report.xmotion.x, report.xmotion.y, ButtonsDown>>1 );
			break;
		default:
			printf( "Event: %d\n", report.type );
		}
	}
}
Exemple #18
0
void CNFGHandleInput()
{
	static int ButtonsDown;
	XEvent report;

	int bKeyDirection = 1;
	int r;
	while( XPending( CNFGDisplay ) )
	{
		r=XNextEvent( CNFGDisplay, &report );

		bKeyDirection = 1;
		switch  (report.type)
		{
		case NoExpose:
			break;
		case Expose:
			XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt );
			if( CNFGPixmap ) XFreePixmap( CNFGDisplay, CNFGPixmap );
			CNFGPixmap = XCreatePixmap( CNFGDisplay, CNFGWindow, CNFGWinAtt.width, CNFGWinAtt.height, CNFGWinAtt.depth );
			if( CNFGGC ) XFreeGC( CNFGDisplay, CNFGGC );
			CNFGGC = XCreateGC(CNFGDisplay, CNFGPixmap, 0, 0);
			break;
		case KeyRelease:
			bKeyDirection = 0;
		case KeyPress:
			HandleKey( XLookupKeysym(&report.xkey, 0), bKeyDirection );
			break;
		case ButtonRelease:
			bKeyDirection = 0;
		case ButtonPress:
			HandleButton( report.xbutton.x, report.xbutton.y, report.xbutton.button, bKeyDirection );
			ButtonsDown = (ButtonsDown & (~(1<<report.xbutton.button))) | ( bKeyDirection << report.xbutton.button );

			//Intentionall fall through -- we want to send a motion in event of a button as well.
		case MotionNotify:
			HandleMotion( report.xmotion.x, report.xmotion.y, ButtonsDown>>1 );
			break;
		case ClientMessage:
			// Only subscribed to WM_DELETE_WINDOW, so just exit
			exit( 0 );
			break;
		default:
			printf( "Event: %d\n", report.type );
		}
	}
}
Exemple #19
0
BOOLEAN NDAAction(EventRecord *sysEvent, int code)
{
    int event;
    static EventRecord localEvent;
    unsigned int eventCode;
    BOOLEAN result = FALSE;

    switch (code) {
    case runAction:
        return result;

    case eventAction:
        BlockMove((Pointer)sysEvent, (Pointer)&localEvent, 16);
        localEvent.wmTaskMask = 0x001FFFFF;
        eventCode = TaskMasterDA(0, &localEvent);
        switch(eventCode) {
        case updateEvt:
            BeginUpdate(gCalcWinPtr);
            DrawContents();
            EndUpdate(gCalcWinPtr);
            break;

        case wInControl:
            HandleControl(&localEvent);
            break;

        case keyDownEvt:
        case autoKeyEvt:
            HandleKey(&localEvent);
            break;
        }
        break;

    case cutAction:
    case copyAction:
    case pasteAction:
    case clearAction:
        result = TRUE;
        HandleMenu(code);
        break;
    }

    return result;
}
Exemple #20
0
extern "C" void RunKeyboardTask(void)
{
  int  task_timer;
  U16  temp, temp1;
  int  right_arrow_key_counter = 0;
  bool right_arrow_key         = false;
  bool right_arrow_key_rep     = false;
  int  question_key_counter    = 0;
  bool question_key            = false;
  bool question_key_rep        = false;
  int  contrast_key_counter    = 0;
  bool contrast_key            = false;
  bool contrast_key_rep        = false;
  int  plus_key_counter        = 0;
  bool plus_key                = false;
  bool plus_key_rep            = false;
  int  minus_key_counter       = 0;
  bool minus_key               = false;
  bool minus_key_rep           = false;
  int  home_key_counter        = 0;
  bool home_key                = false;
  bool home_key_rep            = false;
  int  up_key_counter          = 0;
  bool up_key                  = false;
  bool up_key_rep              = false;
  int  down_key_counter        = 0;
  bool down_key                = false;
  bool down_key_rep            = false;
  int  ok_key_counter          = 0;
  bool ok_key                  = false;
  bool ok_key_rep              = false;
  int  esc_key_counter         = 0;
  bool esc_key                 = false;
  bool esc_key_rep             = false;
  int  plus_key_rep_number     = 0;
  int  minus_key_rep_number    = 0;
  U16  temp_keys                = 0;
  int  number_of_keys;
  int plus_key_repeated        = 0;
  int minus_key_repeated       = 0;

  InitKeyboardHw();

  while (1)
  {
    task_timer = OS_GetTime();

    temp  = REGISTER16(KIUDAT0_MPC);
    temp1 = REGISTER16(KIUDAT1_MPC);
    temp_keys = 0;
    number_of_keys = 0;

    if (!(temp & 0x0001))      // >
    {
      temp_keys |= 0x0001;
      HandleKey(right_arrow_key,right_arrow_key_counter,right_arrow_key_rep,true);
      number_of_keys++;
    }
    else
    {
      HandleKey(right_arrow_key,right_arrow_key_counter,right_arrow_key_rep,false);
    }

    if (!(temp & 0x0100))     // ?
    {
      temp_keys |= 0x0002;
      HandleKey(question_key,question_key_counter,question_key_rep,true);
      number_of_keys++;
    }
    else
    {
      HandleKey(question_key,question_key_counter,question_key_rep,false);
    }

    if (!(temp & 0x0002))      // +
    {
      temp_keys |= 0x0010;
      HandleKey(plus_key,plus_key_counter,plus_key_rep,true);
      number_of_keys++;

      plus_key_repeated = 0;
    }
    else if (!plus_key_rep || ++plus_key_repeated > KEY_REP_IDLE_IN_COUNTS)
    {
      HandleKey(plus_key,plus_key_counter,plus_key_rep,false);
      plus_key_rep_number = 0;

      plus_key_repeated = 0;
    }

    if (!(temp & 0x0200))      // -
    {
      temp_keys |= 0x0020;
      HandleKey(minus_key,minus_key_counter,minus_key_rep,true);
      number_of_keys++;

      minus_key_repeated = 0;
    }
    else if (!minus_key_rep || ++minus_key_repeated > KEY_REP_IDLE_IN_COUNTS)
    {
      HandleKey(minus_key,minus_key_counter,minus_key_rep,false);
      minus_key_rep_number = 0;

      minus_key_repeated = 0;
    }

    if (!(temp & 0x0004))      // home
    {
      temp_keys |= 0x0100;
      HandleKey(home_key,home_key_counter,home_key_rep,true);
      number_of_keys++;
    }
    else
    {
      HandleKey(home_key,home_key_counter,home_key_rep,false);
    }

    if (!(temp & 0x0400))      // contrast
    {
      temp_keys |= 0x0200;
      HandleKey(contrast_key,contrast_key_counter,contrast_key_rep,true);
      number_of_keys++;
    }
    else
    {
      HandleKey(contrast_key,contrast_key_counter,contrast_key_rep,false);
    }

    if (!(temp1 & 0x0001))      // up
    {
      temp_keys |= 0x0004;
      HandleKey(up_key,up_key_counter,up_key_rep,true);
      number_of_keys++;
    }
    else
    {
      HandleKey(up_key,up_key_counter,up_key_rep,false);
    }

    if (!(temp1 & 0x0100))     // down
    {
      temp_keys |= 0x0008;
      HandleKey(down_key,down_key_counter,down_key_rep,true);
      number_of_keys++;
    }
    else
    {
      HandleKey(down_key,down_key_counter,down_key_rep,false);
    }

    if (!(temp1 & 0x0002))      // esc
    {
      temp_keys |= 0x0040;
      HandleKey(esc_key,esc_key_counter,esc_key_rep,true);
      number_of_keys++;
    }
    else
    {
      HandleKey(esc_key,esc_key_counter,esc_key_rep,false);
    }

    if (!(temp1 & 0x0200))      // ok
    {
      temp_keys |= 0x0080;
      HandleKey(ok_key,ok_key_counter,ok_key_rep,true);
      number_of_keys++;
    }
    else
    {
      HandleKey(ok_key,ok_key_counter,ok_key_rep,false);
    }

    keys = temp_keys;

    if ( number_of_keys == 1 )
    {
      if (contrast_key)
      {
        GUI_StoreKey('c');
        contrast_key = false;
      }
      if (ok_key)
      {
        GUI_StoreKey(GUI_KEY_ENTER);
        ok_key = false;
      }
      if (esc_key)
      {
        GUI_StoreKey(GUI_KEY_ESCAPE);
        esc_key = false;
      }
      if (home_key)
      {
        GUI_StoreKey(GUI_KEY_HOME);
        home_key = false;
      }
      if (right_arrow_key)
      {
        GUI_StoreKey(GUI_KEY_RIGHT);
        right_arrow_key = false;
      }
      if (question_key)
      {
        GUI_StoreKey('?');
        question_key = false;
      }
      if (up_key)
      {
        GUI_StoreKey(GUI_KEY_UP);
        up_key = false;
      }
      if (down_key)
      {
        GUI_StoreKey(GUI_KEY_DOWN);
        down_key = false;
      }
      if (plus_key)
      {
        if ( plus_key_rep )
        {
          if (++plus_key_rep_number > KEY_REP_NUMBER_IN_COUNTS)
          {
            GUI_StoreKey('*');
            plus_key_rep_number =  KEY_REP_NUMBER_IN_COUNTS;
          }
          else
          {
            GUI_StoreKey('+');
          }
        }
        else
        {
          GUI_StoreKey('+');
        }
        plus_key = false;
      }
      if (minus_key)
      {
        if ( minus_key_rep )
        {
          if (++minus_key_rep_number > KEY_REP_NUMBER_IN_COUNTS)
          {
            GUI_StoreKey('/');
            minus_key_rep_number = KEY_REP_NUMBER_IN_COUNTS;
          }
          else
          {
            GUI_StoreKey('-');
          }
        }
        else
        {
          GUI_StoreKey('-');
        }
        minus_key = false;
      }
    }

    if (contrast_key)
    {
      contrast_key_down = true;
    }
    else
    {
      contrast_key_down = false;
    }

    REGISTER16(KIUSCANREP_MPC) = 0x8036;  // new scan start
    OS_DelayUntil (task_timer + KEYBORAD_SAMPLE_TIME);
  }
}
Exemple #21
0
void main(void)
{                         
   /********************************************************************/
   //               System Initialization
   /********************************************************************/          
   // Initialize MEGA8 PORT
   Init_PORT();   
      // Initialize SPI to communicate with CH453
   CH453_I2C_Init();

   // Initialize Global Variable: 
   // "Init_Vars()" has to be placed after "bReadDataFromEeprom()" because
   Init_Vars();
      
   // Initialize UART, 8 data, 1 stop, no parity. Boardrate is 2400.                   
   UART_Init(); 
      // Timer (Interrupt) initialization
   safesys();
   digi_cprint("88888888",0,8);

                
   init_digi_Led();
   Init_Timers();
   // initialize golbal interrupt.
   #asm("sei")  

    //init the DMM
    nav_command(NAV_INIT);              
    sleepms(200*ONEMS);                                
    navto1v();
    nav_command(NAV_SLOWMODE);
    sleepms(200*ONEMS);
    nav_command(NAV_AFLTON);
    sleepms(200*ONEMS);
                     
    update_led(0);
    
    
    sysdata.R0 = 0;
	 while(1)
	 {
	        if(keycode != KEY_INVALID)
	        {
                        HandleKey(keycode);
                        keycode = KEY_INVALID;
                        continue;
                }
         
		if(dlg_cnt > 1)
		{         
       			dlg_cnt--;
			continue;
		}
                timer_tick();		
		if(IS_THERM_MODE)                    
		{
        	        if(therm_state() == 0)
		                continue;     
                }
		if(IS_BORE_MODE)
		{
	        	if(bore_state() == 0)
		                continue;
		}     
			
                //shift to next channel 
                       
                if(sysdata.chan == CHAN_1)
                       ch_to_search = 0;
                else if(sysdata.chan == CHAN_2)
                       ch_to_search = 1;                                
                else 
                     ch_to_search = 1 - ch_to_search&0x01;                                
        }                      
}
Exemple #22
0
void wxVListBoxComboPopup::OnComboKeyEvent( wxKeyEvent& event )
{
    // Saturated key movement on
    if ( !HandleKey(event.GetKeyCode(), true) )
        event.Skip();
}
Exemple #23
0
//______________________________________________________________________________
void KVCanvas::HandleInput(EEventType event, Int_t px, Int_t py)
{
   // Handle Input Events.
   //
   //  Handle input events, like button up/down in current canvas.

   if (fFreezed) return;

   TPad*    pad;
   TPad*    prevSelPad = (TPad*) fSelectedPad;
   TObject* prevSelObj = fSelected;

   fPadSave = (TPad*)gPad;
   cd();        // make sure this canvas is the current canvas

   fEvent  = event;
   fEventX = px;
   fEventY = py;

   Int_t sign = 0;
   Bool_t sendOrder = true;

   if (fHasDisabledClasses && fSelected) {
      if (fDisabledClasses.Contains(fSelected->ClassName())) sendOrder = false;
   }

   if (fHasDisabledObject && fSelected) {
      if (fDisabledObjects.Contains(fSelected)) sendOrder = false;
   }

   switch (event) {

      case kMouseMotion:
         // highlight object tracked over
         pad = Pick(px, py, prevSelObj);
         if (!pad) return;

         EnterLeave(prevSelPad, prevSelObj);

         gPad = pad;   // don't use cd() we will use the current
         // canvas via the GetCanvas member and not via
         // gPad->GetCanvas

         if (sendOrder) fSelected->ExecuteEvent(event, px, py);

         RunAutoExec();

         if (fAgeOfEmpire && (fSelected->InheritsFrom("TH2"))) {
            TH2* TheHisto = (TH2*) FindHisto();//fSelected;

            Double_t size = 0.4 - 0.35 * fVenerMode;

            Int_t dX = 0;
            Int_t dY = 0;

            Double_t ppx = AbsPixeltoX(px);
            Double_t ppy = AbsPixeltoY(py);

            TAxis* ax = TheHisto->GetXaxis();
            Int_t X0 = ax->GetFirst();
            Int_t X1 = ax->GetLast();
            Int_t NbinsX = ax->GetNbins();
            px = ax->FindBin(ppx);

            Double_t ddX   = (X1 + X0) * 0.5 - px;
            Double_t distX = TMath::Abs(ddX) / (X1 - X0);
            if (distX >= 0.5) return;

            TAxis* ay = TheHisto->GetYaxis();
            Int_t Y0 = ay->GetFirst();
            Int_t Y1 = ay->GetLast();
            Int_t NbinsY = ay->GetNbins();
            py = ay->FindBin(ppy);

            Double_t ddY   = (Y1 + Y0) * 0.5 - py;
            Double_t distY = TMath::Abs(ddY) / (Y1 - Y0);
            if (distY >= 0.5) return;

            if ((distX <= size) && (distY <= size)) return;
            dX = TMath::Nint(ddX * (0.05 + 0.05 * fVenerMode));
            dY = TMath::Nint(ddY * (0.05 + 0.05 * fVenerMode));

            if (TMath::Abs(dX) < 1) dX = TMath::Sign(1., ddX);
            if (TMath::Abs(dY) < 1) dY = TMath::Sign(1., ddY);


            Bool_t up = false;
            if ((X0 - dX > 0) && (X1 - dX < NbinsX)) {
               ax->SetRange(X0 - dX, X1 - dX);
               up = true;
            }
            if ((Y0 - dY > 0) && (Y1 - dY < NbinsY)) {
               ay->SetRange(Y0 - dY, Y1 - dY);
               up = true;
            }
            if (up) {
               Modified();
               Update();
            }
         }

         break;

      case kMouseEnter:
         // mouse enters canvas
         if (!fDoubleBuffer) FeedbackMode(kTRUE);
         break;

      case kMouseLeave:
         // mouse leaves canvas
         {
            // force popdown of tooltips
            TObject* sobj = fSelected;
            TPad*    spad = fSelectedPad;
            fSelected     = 0;
            fSelectedPad  = 0;
            EnterLeave(prevSelPad, prevSelObj);
            fSelected     = sobj;
            fSelectedPad  = spad;
            if (!fDoubleBuffer) FeedbackMode(kFALSE);
         }
         break;

      case kButton1Double:
      // triggered on the second button down within 350ms and within
      // 3x3 pixels of the first button down, button up finishes action

      case kButton1Down:
         // find pad in which input occured
         pad = Pick(px, py, prevSelObj);
         if (!pad) return;

         gPad = pad;   // don't use cd() because we won't draw in pad
         // we will only use its coordinate system

         if (fSelected) {
            FeedbackMode(kTRUE);   // to draw in rubberband mode
            fSelected->ExecuteEvent(event, px, py);

            RunAutoExec();

            if (fSelected->InheritsFrom("TH2")) {
               oldx = GetEventX();
               oldy = GetEventY();
               xmin = AbsPixeltoX(oldx);
               ymin = AbsPixeltoY(oldy);
               gVirtualX->DrawBox(XtoAbsPixel(xmin), YtoAbsPixel(ymin), oldx, oldy, TVirtualX::kHollow);
            }

         }

         break;

      case kButton1Motion:
         if (fSelected) {
            if (fSelected->InheritsFrom("TH2")) {
               gVirtualX->DrawBox(XtoAbsPixel(xmin), YtoAbsPixel(ymin), oldx, oldy, TVirtualX::kHollow);
               oldx = GetEventX();
               oldy = GetEventY();
               gVirtualX->DrawBox(XtoAbsPixel(xmin), YtoAbsPixel(ymin), oldx, oldy, TVirtualX::kHollow);
               moved = true;
            }
         }
      case kButton1ShiftMotion: //8 == kButton1Motion + shift modifier
         if (fSelected) {
            gPad = fSelectedPad;

            if (sendOrder) fSelected->ExecuteEvent(event, px, py);
            gVirtualX->Update();

            if (!fSelected->InheritsFrom(TAxis::Class())) {
               Bool_t resize = kFALSE;
               if (fSelected->InheritsFrom(TBox::Class()))
                  resize = ((TBox*)fSelected)->IsBeingResized();
               if (fSelected->InheritsFrom(TVirtualPad::Class()))
                  resize = ((TVirtualPad*)fSelected)->IsBeingResized();

               if ((!resize && TestBit(kMoveOpaque)) || (resize && TestBit(kResizeOpaque))) {
                  gPad = fPadSave;
                  Update();
                  FeedbackMode(kTRUE);
               }
            }

            RunAutoExec();
         }

         break;

      case kButton1Up:

         if (fSelected) {
            gPad = fSelectedPad;

            if (sendOrder) fSelected->ExecuteEvent(event, px, py);

            RunAutoExec();

            if (fPadSave)
               gPad = fPadSave;
            else {
               gPad     = this;
               fPadSave = this;
            }
            if (fSelected->InheritsFrom("TH2") && moved && !fSelected->InheritsFrom("TH3")) {
               xmax = AbsPixeltoX(GetEventX());
               ymax = AbsPixeltoY(GetEventY());
               Double_t toto = 0;
               if (xmax < xmin) {
                  toto = xmax;
                  xmax = xmin;
                  xmin = toto;
               }
               if (ymax < ymin) {
                  toto = ymax;
                  ymax = ymin;
                  ymin = toto;
               }
               ZoomSelected((TH2*)FindHisto());
//                ZoomSelected((TH2*)fSelected);
               moved = false;
            }
            Update();    // before calling update make sure gPad is reset
         }
         break;

      //*-*----------------------------------------------------------------------

      case kButton2Down:
         // find pad in which input occured
         pad = Pick(px, py, prevSelObj);
         if (!pad) return;

         gPad = pad;   // don't use cd() because we won't draw in pad
         // we will only use its coordinate system

         FeedbackMode(kTRUE);

         if (!fSelected->InheritsFrom("TH1")) fSelected->Pop();             // pop object to foreground
         pad->cd();                                 // and make its pad the current pad

         if (fSelected->InheritsFrom("TH2") && !fSelected->InheritsFrom("TH3")) {
            // implement pan & scan
            X0 = px;
            Y0 = py;  // u clikd here
            theXaxis = ((TH2*)FindHisto())->GetXaxis();
            theYaxis = ((TH2*)FindHisto())->GetYaxis();
            NXbins = theXaxis->GetNbins();  // maximum bin number in X
            NYbins = theYaxis->GetNbins();  // maximum bin number in Y
            Xf1 = Xfirst0 = theXaxis->GetFirst(); // initial displayed bin range in X
            Xl1 = Xlast0 = theXaxis->GetLast();
            Yf1 = Yfirst0 = theYaxis->GetFirst(); // initial displayed bin range in Y
            Yl1 = Ylast0 = theYaxis->GetLast();
            // size of axes in pixels
            Int_t pixelWidthX = gPad->XtoAbsPixel(gPad->GetUxmax()) - gPad->XtoAbsPixel(gPad->GetUxmin());
            Int_t pixelWidthY = gPad->YtoAbsPixel(gPad->GetUymax()) - gPad->YtoAbsPixel(gPad->GetUymin());
            // sizes of bins in pixels
            NdisXbins = Xlast0 - Xfirst0 + 1;
            NdisYbins = Ylast0 - Yfirst0 + 1;
            XbinPixel = pixelWidthX / (1.0 * NdisXbins);
            YbinPixel = pixelWidthY / (1.0 * NdisYbins);
         }




         if (gDebug)
            printf("Current Pad: %s / %s\n", pad->GetName(), pad->GetTitle());

         // loop over all canvases to make sure that only one pad is highlighted
         {
            TIter next(gROOT->GetListOfCanvases());
            TCanvas* tc;
            while ((tc = (TCanvas*)next()))
               tc->Update();
         }

         /*if (pad->GetGLDevice() != -1 && fSelected)
          fSelected->ExecuteEvent(event, px, py);*/

         break;   // don't want fPadSave->cd() to be executed at the end

      case kButton2Motion:
         //was empty!
         if (fSelected && fSelected->InheritsFrom("TH2") && !fSelected->InheritsFrom("TH3")) {
            // implement pan & scan
            Int_t dX = px - X0; // how far have i moved ?
            Int_t dY = py - Y0;
            Int_t dXbins = dX / XbinPixel;
            Int_t dYbins = dY / YbinPixel;
            Bool_t changed = kFALSE;
            Int_t newXfirst = Xfirst0 - dXbins;
            Int_t newXlast;
            if (newXfirst < 1) {
               newXfirst = 1;
               newXlast = NdisXbins;
            } else {
               newXlast = Xlast0 - dXbins;
               if (newXlast > NXbins) {
                  newXlast = NXbins;
                  newXfirst = newXlast - NdisXbins + 1;
               }
            }
            if (newXfirst != Xf1) {
               Xf1 = newXfirst;
               Xl1 = newXlast;
               theXaxis->SetRange(Xf1, Xl1);
               changed = kTRUE;
            }
            Int_t newYfirst = Yfirst0 - dYbins;
            Int_t newYlast;
            if (newYfirst < 1) {
               newYfirst = 1;
               newYlast = NdisYbins;
            } else {
               newYlast = Ylast0 - dYbins;
               if (newYlast > NYbins) {
                  newYlast = NYbins;
                  newYfirst = newYlast - NdisYbins + 1;
               }
            }
            if (newYfirst != Yf1) {
               Yf1 = newYfirst;
               Yl1 = newYlast;
               theYaxis->SetRange(Yf1, Yl1);
               changed = kTRUE;
            }
            if (changed) {
               Modified();
               Update();
            }
         }


      case kButton2Up:
         if (fSelected) {
            gPad = fSelectedPad;

            if (sendOrder) fSelected->ExecuteEvent(event, px, py);
            RunAutoExec();
         }
         break;

      case kButton2Double:
         break;

      //*-*----------------------------------------------------------------------

      case kButton3Down:
         // popup context menu
         pad = Pick(px, py, prevSelObj);
         if (!pad) return;

         if (!fDoubleBuffer) FeedbackMode(kFALSE);

         if (fContextMenu && !fSelected->TestBit(kNoContextMenu) && !pad->TestBit(kNoContextMenu) && !TestBit(kNoContextMenu)) {
            if (sendOrder) fContextMenu->Popup(px, py, fSelected, this, pad);
            else fSelected->ExecuteEvent(event, px, py);
         }

         break;

      case kButton3Motion:
         break;

      case kButton3Up:
         if (!fDoubleBuffer) FeedbackMode(kTRUE);
         break;

      case kButton3Double:
         break;

      case kKeyDown:
         //       Info("HandleInput","Key down: %d %d",px,py);
         break;

      case kKeyUp:
         //       Info("HandleInput","Key up: %d %d",px,py);
         break;

      case kKeyPress:
         if (!fSelectedPad || !fSelected) return;
         gPad = fSelectedPad;   // don't use cd() because we won't draw in pad
         // we will only use its coordinate system
         fSelected->ExecuteEvent(event, px, py);

         HandleKey(px, py);
         RunAutoExec();

         break;
      case kButton1Shift:
         // Try to select
         pad = Pick(px, py, prevSelObj);

         if (!pad) return;

         EnterLeave(prevSelPad, prevSelObj);

         gPad = pad;   // don't use cd() we will use the current
         // canvas via the GetCanvas member and not via
         // gPad->GetCanvas
         fSelected->ExecuteEvent(event, px, py);
         RunAutoExec();

         break;
      case kWheelUp:
      case kWheelDown:
         pad = Pick(px, py, prevSelObj);
         if (!pad) return;

         sign = (event == kWheelUp ? 1 : -1);

         gPad = pad;
         if (fSelected->InheritsFrom("TAxis")) fSelected->ExecuteEvent(event, px, py);
         else if (fSelected->InheritsFrom("TH2")) DynamicZoom(sign, px, py);

         RunAutoExec();

         break;
      default:
         break;
   }

   if (fPadSave && event != kButton2Down)
      fPadSave->cd();

   if (event != kMouseLeave) { // signal was already emitted for this event
      ProcessedEvent(event, px, py, fSelected);  // emit signal
      DrawEventStatus(event, px, py, fSelected);
   }
}
void CAction::HandleKey(int actionKey, CTile *pTile)
{
	// If the key is the shop keeper key
	if(actionKey == kShopKeeperKey)
	{	


//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////		
		
		// Let's open a store and go to the shop menu by passing in the shop keeper npc
		g_Shop.OpenStore((CNpc*)pTile);

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////


	}
	// If we are doing the first contact with Trendor
	else if(actionKey == kTrendorSceneKey)
	{
		// If we have not already done this, do the first dialog scene
		if(m_actionKeys[actionKey] != 1)
			DoTrendorCutScene();
		// Otherwise, add Trendor to our party if we already talked to the Governor
		else if(m_actionKeys[kGovernorSceneKey])
			HandleKey(kAddTrendorKey, pTile);
		else // Else encourage the player to talk to the Governor
			DisplayCutSceneDialog("Trendor: Quinn, let me know if there is anything I can do to help.  I am interested in what the Governor will say.");

		// Set this action key as "happened" (1)
		m_actionKeys[actionKey] = 1;
	}
	// If the key is to add Trendor 
	else if(actionKey == kAddTrendorKey)
	{
		// Check if we haven't added Trendor yet, then add him
		if(!m_actionKeys[actionKey])
		{
			DisplayCutSceneDialog("Trendor: You talked to the Governor?!?!?  That's great.  I am coming with you.  I don't want to just sit here and do nothing too.");
			
			// Cast the passed in tile to it's correct type, which is an npc, then add Trendor
			CNpc *pNpc = (CNpc*)pTile;
			AddTrendorToGroup(pNpc);
			m_actionKeys[actionKey] = 1;

			g_Menu.DrawMessageBox("Trendor Joined your party!");
		}
	}
	// If the action key is that we found the potion
	else if(actionKey == kPotionKey)
	{
		// Set the potion key to being accomplished
		m_actionKeys[actionKey] = 1;
	}
	// If we are meeting the Governor
	else if(actionKey == kGovernorSceneKey)
	{
		// If we haven't talked with the Governor yet, do the long dialog
		if(m_actionKeys[actionKey] != 1)
			DoGovernorCutScene();
		else	// Otherwise, see if the player needs permission and is good enough
		{
			// If the player has enough experience to get permission
			if(g_Player.GetExperience() >= kPermissionExpNeeded)
			{
				// If we already received permission, wish the player good luck
				if(m_actionKeys[kPermissionKey])
					DisplayCutSceneDialog("Governor: Good luck in the new world.  I hope you find the sage you seek.");
				else
				{	// Otherwise, let's give the player permission to go across the bridge
					DisplayCutSceneDialog("Governor: Wow Quinn, you have really improved.  I think with your experience and strength you should be fine.  You have my permission to enter the new world.");
					m_actionKeys[kPermissionKey] = 1;
				}
			}
			else	// We aren't experienced enough, give encouragement
				DisplayCutSceneDialog("Governor: I think you need to be a little stronger and with more experience.  Come back after you improve a bit more.");
		}
		
		// Set the action key to true so that we know we already talked with the Governor
		m_actionKeys[actionKey] = 1;
	}
	// If we are talking with the bridge guard
	else if(actionKey == kBridgeGuardKey)
	{
		// If we don't have permission, tell the player they need permission to pass
		if(m_actionKeys[kPermissionKey] == 0)
			DisplayCutSceneDialog("Guard: Nobody gets by me unless you have the Governor's permission.");
		else	// Otherwise, we got permission!
		{
			// Cast the tile as the guard npc
			CNpc *pGuard = (CNpc*)pTile;

			// If the player is on the left side of the bridge, say we received permission
			if(g_Player.GetPosition().x <= pGuard->GetIndex().x)
			{
				// Move the player past the guard and safely across the bridge
				POINT newPosition = {g_Player.GetPosition().x + 2, g_Player.GetPosition().y};

				// Tell the guard we received permission from the Governor and set new position
				DisplayCutSceneDialog("Quinn: I just received permission from the Governor to pass.");
				DisplayCutSceneDialog("Guard: Okay, you may pass.  Be carefull over there.");
				g_Player.SetPosition(newPosition);
			}
			else	// Otherwise we are coming back from the new world from the right side
			{
				// Move the player passed the guard again, leaving the new world
				POINT newPosition = {g_Player.GetPosition().x - 2, g_Player.GetPosition().y};

				DisplayCutSceneDialog("Guard: Welcome back!  It's good to see you still alive and well.");
				g_Player.SetPosition(newPosition);
			}
		}

		// Set the key s we know we talked to the guard
		m_actionKeys[actionKey] = 1;
	}
	// If we are talking to the sage
	else if(actionKey == kSageSceneKey)
	{
		// If we have already received the potion, tell the player to hurry back home
		if(m_actionKeys[actionKey] != 0)
			DisplayCutSceneDialog("Sage: Hurry up and go save your brother!");
		else
		{
			// Do the first dialog scene with the sage and get the potion from him
			DoSageCutScene();
			GivePotion();
		}

		// Set the key so we know we have already talked with the sage
		m_actionKeys[actionKey] = 1;	
	}
	else	// Otherwise set the key as done for whatever key was passed in
		m_actionKeys[actionKey] = 1;
}
Exemple #25
0
bool Console::HandleKeys(int keynum)
{
	// Toggle console active
	if (keynum == K_DEL)
	{
		Console::ConsoleActive = !Console::ConsoleActive;
		return true;
	}

	// Get key input
	if (Console::ConsoleActive)
	{
#define HandleKey(a) { EditLine.insert(EditPos, a); EditPos += strlen(a); return true; }
#define ShiftHeld ShiftKeyHeld()
#define CapsLock CapslockActive()

		if (keynum == K_ENTER) // Execute command
		{
			Parse(EditLine);
			EditLine.clear();
			EditPos = 0;
			return true;
		}

		if (keynum == K_BACKSPACE) // Erase line
		{
			if (EditLine.size() > 0)
			{
				--EditPos;
				EditLine.erase(EditPos, 1);
			}
			
			return true;
		}

		if (keynum == K_LEFTARROW)
		{
			if (EditPos > 0) --EditPos;
			return true;
		}

		if (keynum == K_RIGHTARROW && EditPos < (int)EditLine.size())
		{
			if (EditPos < (int)EditLine.size()) ++EditPos;
			return true;
		}

		if (keynum == K_SPACE)
			HandleKey(" ");

		if (keynum == K_TAB)
		{
			HandleKey("    ");
		}

		if (keynum >= 97 && keynum <= 122) // a-z
		{
			if (CapsLock && ShiftHeld == false ||
				CapsLock == false && ShiftHeld)
			{
				HandleKey(g_pszConsoleShiftKeys[keynum]);
			}
			else
			{
				HandleKey(g_pszConsoleKeys[keynum]);
			}
		}

		if (keynum >= 44 && keynum <= 61 || keynum == 92) // 0-9 ,+.-'    and    !"#¤%&/()?=` ;:_*

		{
			if (ShiftHeld == false)
			{
				HandleKey(g_pszConsoleKeys[keynum]);
			}
			else
			{
				HandleKey(g_pszConsoleShiftKeys[keynum]);
			}
		}

		if (keynum == 93) //^^
			HandleKey(g_pszConsoleShiftKeys[keynum]);

		if (keynum == 96) // |
		{
			HandleKey(g_pszConsoleKeys[keynum]);
		}

		if (keynum == 170) //numpad 0 and Insert
			HandleKey("0");

		if (keynum == 166) //numpad 1 and End
			HandleKey("1");
		if (keynum == 167) //numpad 2 and Down arrow
			HandleKey("2");
		if (keynum == 168) //numpad 3 and Page down
			HandleKey("3");

		if (keynum == 163) //numpad 4 and Left arrow
			HandleKey("4");
		if (keynum == 164) //numpad 5
			HandleKey("5");
		if (keynum == 165) //numpad 6 and Right arrow
			HandleKey("6");

		if (keynum == 160) //numpad 7 and Home
			HandleKey("7");
		if (keynum == 161) //numpad 8 and Up arrow
			HandleKey("8");
		if (keynum == 162) //numpad 9 and Page up
			HandleKey("9");
	}

	return false;
}
Exemple #26
0
void CACEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	if(!HandleKey(nChar,false))
		CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}
void iCameraPositioner::Event_KEY( LEvent Event, const LEventArgs& Args )
{
	HandleKey( ( int )Args.FFloatArg, Args.FBoolArg );
}
Exemple #28
0
int gameloop(void)
{
	struct Buffer *buffer;
	int ticks;
	int c = 0;
	int cmd1, cmd2;
	int done = NO;
	time_t t;
	struct tm *tp;

	buffer = NewBuffer();
	SetClip(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);

	if (ModuleStatus() != MODULE_OK)
		DisplayMessage(ModuleMessage());

	gameIsPaused = NO;

	missionTime = 0;
	//screenShaking = 0;
	while (!done) {
		frames++;

		Ticks_FrameBegin();

		ticks = Ticks_Synchronize();

		if (gOptions.displaySlices)
			SetColorZero(32, 0, 0);

		DrawScreen(buffer, gPlayer1, gPlayer2);

		if (gOptions.displaySlices)
			SetColorZero(0, 0, 0);

		if (screenShaking) {
			screenShaking -= ticks;
			if (screenShaking < 0)
				screenShaking = 0;
		}

		debug(D_VERBOSE, "frames... %d\n", frames);

		if (Ticks_TimeElapsed(TICKS_PER_SEC)) {
			fps = frames;
			debug(D_NORMAL, "fps = %d\n", fps);
			frames = 0;

			t = time(NULL);
			tp = localtime(&t);
			timeHours = tp->tm_hour;
			timeMinutes = tp->tm_min;
		}

		if (messageTicks > 0)
			messageTicks -= ticks;

		StatusDisplay();

		if (!gameIsPaused) {
			missionTime += ticks;
			if ((gPlayer1 || gPlayer2) && MissionCompleted()) {
				if (gMission.pickupTime == PICKUP_LIMIT)
					PlaySound(SND_DONE, 0, 255);
				gMission.pickupTime -= ticks;
				if (gMission.pickupTime <= 0)
					done = YES;
			} else
				gMission.pickupTime = PICKUP_LIMIT;
		}

		if (gOptions.displaySlices)
			SetColorZero(0, 0, 32);

		if (gOptions.displaySlices)
			SetColorZero(0, 0, 0);

		CopyToScreen();

		if (!gameIsPaused) {
			if (!gOptions.slowmotion || (frames & 1) == 0) {
				UpdateAllActors(ticks);
				UpdateMobileObjects();

				GetPlayerInput(&cmd1, &cmd2);

				if (gPlayer1 && !PlayerSpecialCommands(
							gPlayer1, cmd1, &gPlayer1Data)) {
					CommandActor(gPlayer1, cmd1);
				}
				if (gPlayer2 && !PlayerSpecialCommands(
							gPlayer2, cmd2, &gPlayer2Data)) {
					CommandActor(gPlayer2, cmd2);
				}

				if (gOptions.badGuys)
					CommandBadGuys();

				UpdateWatches();
			}
		} else {
			GetPlayerInput(&cmd1, &cmd2);
		}

		if (!gPlayer1 && !gPlayer2) {
			done = YES;
			c = 0;
		} else {
			c = HandleKey(&done, cmd1 | cmd2);
		}

		Ticks_FrameEnd();
	}
	free(buffer);

	return c != keyEsc;
}