Ejemplo n.º 1
0
void checkKeepEupEGame(int shape) // called on every user beep
{
   // flash shape
   flashShape(shape,&WinEraseLineF);
   playFreq(sndCmdFrqOn,keepEupENotes[shape],500); // freq,maxdur

   if (shape == keepEupEShapeList[keepEupEShapeListUserIndex])
      keepEupEShapeListUserIndex++;
   else {
      // TBD: play bad tone
      playLoseTone();
      displayLoseDialog(shape);
      // unflash shape
      flashShape(shape,&WinDrawLineF);
      startKeepEupEGame();
   }
   if (keepEupEShapeListUserIndex >= keepEupEShapeListLast){
      // unflash
      SysTaskDelay((200 * SysTicksPerSecond())/1000);
      flashShape(shape,&WinDrawLineF);
      // pause to break user play from playback
      SysTaskDelay((500 * SysTicksPerSecond())/1000);
      // TBD maybe beep indicating end of playback, start of another
      playKeepEupEGame();
      // add new shape etc...
   }
}
Ejemplo n.º 2
0
void checkdialToneGame(int shape) // called on every user beep
{
   playFreq(sndCmdFrqOn,dialToneNotes[shape],500); // freq,maxdur

   playLoseTone();

   SysTaskDelay((200 * SysTicksPerSecond())/1000);
   // pause to break user play from playback
   SysTaskDelay((500 * SysTicksPerSecond())/1000);
   // TBD maybe beep indicating end of playback, start of another
}
Ejemplo n.º 3
0
static void playKeepEupEGame(void)
{
   // add new shape
   keepEupEShapeList[keepEupEShapeListLast] = SysRandom(0) % MAXKEEPEUPESHAPES;
   keepEupEShapeListLast++;

   // check for win
   if (keepEupEShapeListLast>=MAXKEEPEUPES){
      displayWinDialog();
      startKeepEupEGame();
   }
   else{
      int s;
      // play sounds + flash shapes (with delay)
      for(s=0;s<keepEupEShapeListLast;s++){
         flashShape(keepEupEShapeList[s],&WinEraseLineF);
         playFreq(sndCmdFreqDurationAmp/*sndCmdFrqOn*/, // I don't think it does block?, ohhh .. obviously not if sound off!
            keepEupENotes[keepEupEShapeList[s]],300); // TBD: make 300 decrease to go faster

         flashShape(keepEupEShapeList[s],&WinDrawLineF);
         // pause to break each shape apart (in case same shape important)
         SysTaskDelay((200 * SysTicksPerSecond())/1000);

      }
      // put user back to zero
      keepEupEShapeListUserIndex=0;
   }
}
Ejemplo n.º 4
0
void RunCount(UInt32 start_tik)
{
    UInt32 tik,dtik;
    run=1;
    while(run==1) {
	tik = TimGetTicks();
	dtik = tik - start_tik;
	drawCount(dtik);

	// call this periodically to hold off auto off  
	if (stopWatchPrefs.disableAutoOff) EvtResetAutoOffTimer();

	// delay one tenth of a sec (.09 acksherly to be sly)
	SysTaskDelay((90 * SysTicksPerSecond())/1000);
	// within loop call SysHandleEvent to
	//  give system opportunity to break in? 
	// /opt/palmdev/sdk-5/include/Core/UI/Event.h
	{ 
	    UInt16 err;
	    EventType e;
	    EvtGetEvent(&e, 0);
	    if (! SysHandleEvent (&e))
		if (! MenuHandleEvent (NULL, &e, &err))
		    if (! ApplicationHandleEvent (&e))
			FrmDispatchEvent (&e);
	}
    }

}
Ejemplo n.º 5
0
void
osip_usleep (int useconds)
{
#if defined(__PALMOS__) && (__PALMOS__ >= 0x06000000)
  /* This bit will work for the Protein API, but not the Palm 68K API */
  nsecs_t nanoseconds = useconds * 1000;

  SysThreadDelay (nanoseconds, P_ABSOLUTE_TIMEOUT);
#elif defined(__PALMOS__) && (__PALMOS__ < 0x06000000)
  UInt32 stoptime = TimGetTicks () + (useconds / 1000000) * SysTicksPerSecond ();

  while (stoptime > TimGetTicks ())
    /* I wish there was some type of yield function here */
    ;
#elif defined(WIN32)
  Sleep (useconds / 1000);
#else
  struct timeval delay;
  int sec;

  sec = (int) useconds / 1000000;
  if (sec > 0)
    {
      delay.tv_sec = sec;
      delay.tv_usec = 0;
  } else
    {
      delay.tv_sec = 0;
      delay.tv_usec = useconds;
    }
  select (0, 0, 0, 0, &delay);
#endif
}
Ejemplo n.º 6
0
Archivo: draw.c Proyecto: docwhat/cwimp
/*
 * This function is based on the DrawIntro and DrawBlinds
 * functions in Vexed, a Cool GPL Palm Game by
 * "James McCombe" <*****@*****.**>
 * http://spacetube.tsx.org
 */
void
DrawIntro () {
  VoidHand Title_Handle;
  BitmapPtr Title;
  char text[40];
  SWord penx, peny;
  Boolean bstate;

  /* If a game is on, don't do the splash */
  if( stor.currplayer >= 0 ) return;

  // load bitmap resource and get handle
  Title_Handle = DmGet1Resource ('Tbmp', bmpTitle);
  // lock the bitmap resource into memory and get a pointer to it
  Title = MemHandleLock (Title_Handle);

  // draw the bitmap ( 160x160 )
  WinDrawBitmap (Title, 0, 0);

  /* Text Strings */
  StrPrintF (text, IntroVersionString, VERSION);
  WinDrawChars (text, StrLen (text), 5, 6);

  StrPrintF (text, IntroForPalmString, 153);
  WinDrawChars (text, StrLen (text), 52, 50);

  StrPrintF (text, IntroTapHereString, VERSION);
  WinDrawChars (text, StrLen (text), 45, 85);

  // unload the bitmap from memory (unlock)
  MemHandleUnlock (Title_Handle);

  // Loop till screen is tapped
  while (bstate)
    EvtGetPen (&penx, &peny, &bstate);
  while (!bstate)
    EvtGetPen (&penx, &peny, &bstate);

  /* If the user clicked in the drawing area, then
   * do a Draw Blinds and clear the PenQueue.
   */
  if( peny < 160 ) {
    // DrawBlinds
    int i, x;
    float delay;

    EvtFlushPenQueue();

    delay = .01 * SysTicksPerSecond();

    for (i = 0; i < 16; i++) {
      for (x = i; x < 160; x += 16) {
        WinEraseLine( 0,x, 159,x );
      }
      SysTaskDelay(delay);
    }
  } /* if( peny < 160 ) */

}
Ejemplo n.º 7
0
/* The main event loop */
static void EventLoop(void)
{
  Word err;
  EventType e;

  do {
    if( EQIsEmpty() ) {
      EvtGetEvent(&e, .66 * SysTicksPerSecond());
    } else {
      EvtGetEvent(&e, .05 * SysTicksPerSecond());
    }
    if (! SysHandleEvent (&e))
      if (! MenuHandleEvent (NULL, &e, &err) )
	if (! ApplicationHandleEvent (&e) )
	  if( ! FrmDispatchEvent (&e) )
            GameEvents();
  } while (e.eType != appStopEvent);
}
Ejemplo n.º 8
0
int select(int nfds, fd_set *readfds,
       fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
{
    int  ticks;


    // Convert the timeout value to ticks
    if (timeout == 0) {
        ticks = -1;
    } else {
        ticks = (timeout->tv_sec * SysTicksPerSecond()) + 
                     (timeout->tv_usec /  (1000000L / SysTicksPerSecond()));
    }
                     
    // call Net Lib function
    return NetLibSelect(nfds, (NetFDSetType *)readfds,
                        (NetFDSetType *)writefds, (NetFDSetType *)errorfds,
                        ticks, NULL);
}
Ejemplo n.º 9
0
void wxMicroSleep(unsigned long microseconds)
{
    UInt16 ticks_sec;
    Int32 delay;
    ticks_sec = SysTicksPerSecond ();
    delay = microseconds * ticks_sec / 1000000;
    if (delay > 0) {
        SysTaskDelay (delay);
    }
}
Ejemplo n.º 10
0
void wxSleep(int nSecs)
{
    UInt16 ticks_sec;
    Int32 delay;
    ticks_sec = SysTicksPerSecond ();
    delay = nSecs * ticks_sec;
    if (delay > 0) {
        SysTaskDelay (delay);
    }
}
Ejemplo n.º 11
0
static void playdialToneGame(void)
{
      int s;
      // play sounds + flash shapes (with delay)
      for(s=0;s<dialToneShapeListLast;s++){
         playFreq(sndCmdFreqDurationAmp/*sndCmdFrqOn*/, // I don't think it does block?, ohhh .. obviously not if sound off!
            dialToneNotes[dialToneShapeList[s]],300); // TBD: make 300 decrease to go faster

         // pause to break each shape apart (in case same shape important)
         SysTaskDelay((200 * SysTicksPerSecond())/1000);

      }
}
Ejemplo n.º 12
0
ticks_t time_ticks_per_second( void )
{
#ifdef UNIX
    //UNIX:
    return (ticks_t)1000;
#endif
#ifdef PALMOS
    //PALM:
    return (ticks_t)SysTicksPerSecond();
#endif
#if defined(WIN) || defined(WINCE)
    //WINDOWS:
    return (ticks_t)1000;
#endif
}
Ejemplo n.º 13
0
OSystem_PalmBase::OSystem_PalmBase() {
	_overlayVisible = false;

	_current_shake_pos = 0;
	_new_shake_pos = 0;

	_paletteDirtyStart = 0;
	_paletteDirtyEnd = 0;

	_gfxLoaded = false;
	_modeChanged = false;
	_setMode = GFX_NORMAL;
	_mode = _setMode;
	_redawOSD = false;
	_setPalette = true;

	_offScreenH = NULL;
	_screenH = NULL;
	_offScreenP = NULL;
	_screenP = NULL;
	_screenPitch = gVars->screenPitch;

	_wasKey = false;
	_lastKeyModifier = kModifierNone;
	_lastKeyRepeat = 100;
	_useNumPad = false;
	_showBatLow = false;
	_batCheckTicks = SysTicksPerSecond() * 15;
	_batCheckLast = TimGetTicks();

	_saveMgr = 0;
	_timerMgr = 0;
	_mixerMgr = 0;

	_mouseDataP = NULL;
	_mouseBackupP = NULL;
	_mouseVisible = false;
	_mouseDrawn = false;
	MemSet(&_keyExtra, sizeof(_keyExtra), 0);
	MemSet(&_mouseCurState, sizeof(_mouseCurState), 0);
	MemSet(&_mouseOldState, sizeof(_mouseOldState), 0);
	MemSet(&_timer, sizeof(TimerType), 0);
	MemSet(&_sound, sizeof(SoundType), 0);

	_keyExtraRepeat = 0;
	_keyExtraPressed = 0;
	_keyExtraDelay = (gVars->arrowKeys) ? computeMsecs(125) : computeMsecs(25);
}
Ejemplo n.º 14
0
static void AppEventLoop(void)
{
    UInt16 error;
    EventType event;

    do {
        /* change timeout if you need periodic nilEvents */
        EvtGetEvent(&event, SysTicksPerSecond() / 5);

        if (!SysHandleEvent(&event)) {
            if (!MenuHandleEvent(0, &event, &error)) {
                if (!AppHandleEvent(&event)) {
                    FrmDispatchEvent(&event);
                }
            }
        }
    } while (event.eType != appStopEvent);
}
Ejemplo n.º 15
0
void
osip_usleep (int useconds)
{
#if defined(__PALMOS__) && (__PALMOS__ >= 0x06000000)
  /* This bit will work for the Protein API, but not the Palm 68K API */
  nsecs_t nanoseconds = useconds * 1000;

  SysThreadDelay (nanoseconds, P_ABSOLUTE_TIMEOUT);
#elif defined(__PALMOS__) && (__PALMOS__ < 0x06000000)
  UInt32 stoptime = TimGetTicks () + (useconds / 1000000) * SysTicksPerSecond ();

  while (stoptime > TimGetTicks ())
    /* I wish there was some type of yield function here */
    ;
#elif defined(WIN32)
  Sleep (useconds / 1000);
#elif defined(__rtems__)
    rtems_task_wake_after( RTEMS_MICROSECONDS_TO_TICKS(useconds) );
#elif defined(__arc__)
  struct timespec req;
  struct timespec rem;
  req.tv_sec = (int) useconds / 1000000;
  req.tv_nsec = (int) (useconds % 1000000)*1000;
  nanosleep (&req, &rem);
#else
  struct timeval delay;
  int sec;

  sec = (int) useconds / 1000000;
  if (sec > 0)
    {
      delay.tv_sec = sec;
      delay.tv_usec = 0;
  } else
    {
      delay.tv_sec = 0;
      delay.tv_usec = useconds;
    }
  select (0, 0, 0, 0, &delay);
#endif
}
Ejemplo n.º 16
0
/* Main entry point; it is unlikely you will need to change this except to
   handle other launch command codes */
UInt32 PilotMain (UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
	UInt16 err;

	if (cmd != sysAppLaunchCmdNormalLaunch)
		return sysErrParamErr;

	if (!(buffer = WinCreateOffscreenWindow (160, 160, screenFormat, &err)))
		return err;

	if ((err = StartApplication()) != 0)
		return err;

	ticks = SysTicksPerSecond() / FRAME_RATE;

	run_game ();
	/* EventLoop(); */
	StopApplication();

	WinDeleteWindow (buffer, false);

	return 0;
}
Ejemplo n.º 17
0
/* The main event loop */
static void EventLoop(void)
{
        UInt16 err;
        EventType e;
        static float timeout = .05;

        do {
                if( EQIsEmpty() &&
                    timeout < 600 &&
                    !DrawFlashies() )
                {
                        timeout *= 2;
                } else {
                        timeout = .05;
                }

                EvtGetEvent(&e, timeout * SysTicksPerSecond());
                if (! SysHandleEvent (&e))
                        if (! MenuHandleEvent (NULL, &e, &err) )
                                if (! ApplicationHandleEvent (&e) )
                                        if( ! FrmDispatchEvent (&e) )
                                                GameEvents();
        } while (e.eType != appStopEvent);
}
Ejemplo n.º 18
0
uint32 OSystem_PalmBase::getMillis() {
	return TimGetTicks() * 1000 / SysTicksPerSecond();
}
Ejemplo n.º 19
0
/***********************************************************************
 *
 * FUNCTION:    SelectTimeZone
 *
 * DESCRIPTION: Display a form showing a time zone and allow the user
 *              to select a different time zone. This is the time zone
 *					 dialog as seen in Date & Dime panel
 *
 * PARAMETERS:
 *		ioTimeZoneP				<->	pointer to time zone to change
 *		ioLocaleInTimeZoneP	<->	Ptr to locale found in time zone.
 *		titleP					 ->	String title for the dialog.
 *		showTimes				 -> 	True => show current and new times
 *		anyLocale				 ->	True => ignore ioLocaleInTimeZoneP on entry.
 *
 * RETURNED:
 *		true if the OK button was pressed (in which case *ioTimeZoneP and
 *		*ioCountryInTimeZoneP might be changed).
 *
 * HISTORY:
 *		03/02/00	peter	Created by Peter Epstein.
 *		04/03/00	peter	Allow NULL currentTimeP.
 *		04/12/00	peter API changed to get rid of trigger text
 *		04/14/00	peter Update current & new time as time passes
 *		07/31/00	kwk	Use SysTicksPerSecond() routine vs. sysTicksPerSecond macro.
 *					kwk	Re-wrote to use set of resources (name, offset, country),
 *							scrollbar vs. arrows, etc.
 *		08/01/00	kwk	Support scroll-to-key. Fixed scrollbar/list sync bugs.
 *		08/02/00	kwk	New API w/ioCountryInTimeZoneP and anyCountry parameters.
 *					kwk	Call FrmHandleEvent _after_ our event handling code has
 *							decided that it doesn't want to handle the event, not before.
 *		08/03/00	kwk	Call LstSetListChoices before calling LstGetVisibleItems,
 *							as otherwise accessing the time zone picker from the
 *							Setup app (when <showTimes> is false) gives you a two-
 *							line high display because LstGetVisibleItems returns 0.
 *		08/18/00	kwk	Play error sound if user writes letter that doesn't
 *							match any entries.
 *					kwk	Don't select item if doing scroll-to-view for entry
 *							that matches the letter the user wrote.
 *		08/21/00	kwk	Scroll-to-view with text entry now scrolls to the top
 *							of the list, versus the middle.
 *		10/09/00	peter	Get rid of scroll bar and let list do the scrolling.
 *		11/17/00	CS		Change ioCountryInTimeZoneP to ioLocaleInTimeZoneP,
 *							(and anyCountry to anyLocale, but that doesn't matter),
 *							since CountryType is only a UInt8, and this may
 *							change someday.
 *
 ***********************************************************************/
Boolean SelectTimeZone(Int16 *ioTimeZoneP, LmLocaleType* ioLocaleInTimeZoneP,
				const Char *titleP, Boolean showTimes, Boolean anyLocale)
{
	FormType* originalForm;
	FormType* dialog;
	EventType event;
	Boolean confirmed = false;
	Boolean done = false;
	Boolean adjustTimes = false;
	Boolean foundLocale = false;
	MemHandle currentTimeHandle, newTimeHandle;
	ListPtr listP;
	Int16 oldTimeZone, newTimeZone, testTimeZone;
	LmLocaleType newTimeZoneLocale;
	Int16 delta, closestDelta, timeZoneIndex, closestIndex;
	DateTimeType currentTime, newTime;
	TimeZoneEntryType* tzArrayP;
	UInt16 numTimeZones;
	MemHandle tzNamesH;
	
	if (showTimes)
	{
		TimSecondsToDateTime(TimGetSeconds(), &currentTime);
	}
	
	oldTimeZone = *ioTimeZoneP;
	newTimeZone = oldTimeZone;
	newTimeZoneLocale = *ioLocaleInTimeZoneP;
	
	originalForm = FrmGetActiveForm();
	dialog = (FormType *) FrmInitForm (TimeZoneDialogForm); 
	listP = FrmGetObjectPtr (dialog, FrmGetObjectIndex (dialog, TimeZoneDialogTimeZoneList));
	
	if (titleP)
	{
		FrmSetTitle (dialog, (Char *) titleP);
	}
	
	FrmSetActiveForm (dialog);
	
	// We need to call LstSetListChoices before calling LstSetHeight below, as otherwise
	// LstGetVisibleItems will return 0.
	tzArrayP = PrvCreateTimeZoneArray(&tzNamesH, &numTimeZones);
	LstSetListChoices(listP, (Char**)tzArrayP, numTimeZones);
	
	if (showTimes)
	{
		currentTimeHandle = MemHandleNew(timeStringLength + 1 + dowLongDateStrLength + 1);
		ErrFatalDisplayIf (!currentTimeHandle, "Out of memory");
		newTimeHandle = MemHandleNew(timeStringLength + 1 + dowLongDateStrLength + 1);
		ErrFatalDisplayIf (!newTimeHandle, "Out of memory");

		PrvSetTimeField(dialog, TimeZoneDialogCurrentTimeField, currentTimeHandle, &currentTime, false);
	}
	else
	{
		// Hide the current and new time.
		FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogCurrentTimeLabel));
		FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogCurrentTimeField));
		FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogNewTimeLabel));
		FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogNewTimeField));
		
		// Make the list show more items to take up extra the space.
		LstSetHeight(listP, LstGetVisibleItems(listP) + extraTimeZonesToShowWhenNoTimes);
	}
	
	// Find the time zone in the list closest to the current time zone, and that
	// matches <*ioLocaleInTimeZoneP> if <anyLocale> is false.
	closestDelta = hoursInMinutes * hoursPerDay;		// so big that all others will be smaller
	for (timeZoneIndex = 0; timeZoneIndex < numTimeZones; timeZoneIndex++)
	{
		Boolean checkDelta = anyLocale;
		testTimeZone = tzArrayP[timeZoneIndex].tzOffset;
		delta = Abs(testTimeZone - oldTimeZone);
		
		if (!anyLocale)
		{
			if (tzArrayP[timeZoneIndex].tzCountry == ioLocaleInTimeZoneP->country)
			{
				// If we haven't previously found a matching locale, reset the
				// delta so that this entry overrides any previous best entry.
				if (!foundLocale)
				{
					foundLocale = true;
					closestDelta = hoursInMinutes * hoursPerDay;
				}
				
				checkDelta = true;
			}
			
			// If we haven't yet found a matching locale, go for the closest delta.
			else
			{
				checkDelta = !foundLocale;
			}
		}
		
		// If we want to check the time zone delta, do it now.
		if (checkDelta && (delta < closestDelta))
		{
			closestIndex = timeZoneIndex;
			closestDelta = delta;
		}
	}
	
	// Scroll so that time zone is in the center of the screen and select it if it's an exact match.
	LstSetTopItem(listP, max(0, closestIndex - (LstGetVisibleItems(listP) / 2)));
	if ((closestDelta == 0) && (anyLocale || foundLocale))
	{
		LstSetSelection(listP, closestIndex);
		if (showTimes)
		{
			newTime = currentTime;
			PrvSetTimeField(dialog, TimeZoneDialogNewTimeField, newTimeHandle, &newTime, false);
		}
	}
	else
	{
		LstSetSelection(listP, noListSelection);
	}
	
	LstSetDrawFunction(listP, PrvTimeZoneListDrawItem);
	
	FrmDrawForm (dialog);
	
	while (!done)
	{
		Boolean handled = false;
		EvtGetEvent(&event, SysTicksPerSecond());		// so we can update the current and new time

		if (SysHandleEvent ((EventType *)&event))
		{
			continue;
		}
		
		if (event.eType == nilEvent)
		{
			if (showTimes)
			{
				PrvUpdateTimeFields(	dialog,
										&currentTime,
										&newTime,
										currentTimeHandle,
										newTimeHandle,
										TimeZoneDialogCurrentTimeField,
										TimeZoneDialogNewTimeField);
			}
		}
		
		else if (event.eType == ctlSelectEvent)
		{
			handled = true;
			
			switch (event.data.ctlSelect.controlID)
			{
				case TimeZoneDialogOKButton:
					// Set the new time zone.
					*ioTimeZoneP = newTimeZone;
					*ioLocaleInTimeZoneP = newTimeZoneLocale;

					done = true;
					confirmed = true;
				break;

				case TimeZoneDialogCancelButton:
					done = true;
				break;
				
				default:
					ErrNonFatalDisplay("Unknown control in form");
				break;
			}
		}
		
		// User tapped on a time zone in the list.
		else if (event.eType == lstSelectEvent)
		{
			UInt16 localeIndex;
			
			ErrNonFatalDisplayIf(event.data.lstSelect.listID != TimeZoneDialogTimeZoneList,
										"Unknown list in form");
			
			newTimeZone = tzArrayP[event.data.lstSelect.selection].tzOffset;
			newTimeZoneLocale.country =
				tzArrayP[event.data.lstSelect.selection].tzCountry;
			newTimeZoneLocale.language = lmAnyLanguage;
			if (LmLocaleToIndex(&newTimeZoneLocale, &localeIndex) == errNone)
			{
				if (LmGetLocaleSetting(	localeIndex,
												lmChoiceLocale,
												&newTimeZoneLocale,
												sizeof(newTimeZoneLocale)))
				{
					ErrNonFatalDisplay("Can\'t get locale");
				}
			}
			adjustTimes = showTimes;
			handled = true;
		}

		else if (event.eType == keyDownEvent)
		{
			if	(!TxtCharIsHardKey(event.data.keyDown.modifiers, event.data.keyDown.chr))
			{
				//	Hard scroll buttons
				if (EvtKeydownIsVirtual(&event))
				{
					if (event.data.keyDown.chr == vchrPageUp)
					{
						handled = true;
						LstScrollList(listP, winUp, LstGetVisibleItems(listP) - 1);
					}
					else if (event.data.keyDown.chr == vchrPageDown)
					{
						handled = true;
						LstScrollList(listP, winDown, LstGetVisibleItems(listP) - 1);
					}
				}
				else if (TxtCharIsPrint(event.data.keyDown.chr))
				{
					Int16 index;
					
					handled = true;
					index = PrvSearchTimeZoneNames(tzArrayP, numTimeZones, event.data.keyDown.chr);
					
					if (index != noListSelection)
					{
						Int16 delta = index - listP->topItem;
						if (delta < 0)
						{
							LstScrollList(listP, winUp, -delta);
						}
						else if (delta > 0)
						{
							LstScrollList(listP, winDown, delta);
						}
					}
					else
					{
						SndPlaySystemSound(sndError);
					}
				}
			}
		}

		else if (event.eType == appStopEvent)
		{
			EvtAddEventToQueue (&event);
			done = true;
			break;
		}
		
		// If we didn't handle the event, give the form code a crack at it.
		// This simulates the "normal" method of installing an event handler
		// for a form, which gets called, and then if it returns false, the
		// FrmHandleEvent routine gets called.
		if (!handled)
		{
			FrmHandleEvent(dialog, &event); 
		}
		
		// If something changed, and we need to update our time display,
		// do it now.
		if (adjustTimes)
		{
			adjustTimes = false;
			newTime = currentTime;
			TimAdjust(&newTime, (Int32)(newTimeZone - oldTimeZone) * minutesInSeconds);
			PrvSetTimeField(dialog, TimeZoneDialogNewTimeField, newTimeHandle, &newTime, true);
		}
	}	// end while true
		
	if (showTimes)
	{
		FldSetTextHandle(FrmGetObjectPtr (dialog, FrmGetObjectIndex (dialog, TimeZoneDialogCurrentTimeField)), NULL);
		FldSetTextHandle(FrmGetObjectPtr (dialog, FrmGetObjectIndex (dialog, TimeZoneDialogNewTimeField)), NULL);
		MemHandleFree(currentTimeHandle);
		MemHandleFree(newTimeHandle);
	}
	
	FrmEraseForm (dialog);
	FrmDeleteForm (dialog);
	FrmSetActiveForm(originalForm);

	PrvDeleteTimeZoneArray(tzArrayP, tzNamesH);

	return confirmed;
} // SelectTimeZone
Ejemplo n.º 20
0
int GetTimeFreq()
{
    return SysTicksPerSecond();
}
Ejemplo n.º 21
0
int start_telnet(int s, unsigned long int ip, int port, unsigned char options, char *miscptr, FILE * fp) {
  char *empty = "";
  char *login, *pass, buffer[300];
  int i = 0;

#ifdef PALM
  Err error;
  Int32 AppNetTimeout = SysTicksPerSecond() * 10;
#endif

  no_line_mode = 0;             /* hmmm seems to work anyway */

  if (strlen(login = hydra_get_next_login()) == 0)
    login = empty;
  if (strlen(pass = hydra_get_next_password()) == 0)
    pass = empty;

#ifdef PALM
  sprintf(buffer, "%s\r", login);
#else
  sprintf(buffer, "%.250s\r", login);
#endif
  if (no_line_mode) {
    for (i = 0; i < strlen(buffer) + 1; i++) {
#ifdef PALM
      NetLibSend(AppNetRefnum, s, &buffer[i], 1, 0, 0, 0, AppNetTimeout, &error);
#else
      send(s, &buffer[i], 1, 0);
#endif
      usleep(2000);
    }
  } else {
    if (hydra_send(s, buffer, strlen(buffer) + 1, 0) < 0) {
      return 1;
    }
  }

  do {
    if ((buf = hydra_receive_line(s)) == NULL)
      return 1;
    if (index(buf, '/') != NULL || index(buf, '>') != NULL || index(buf, '%') != NULL || index(buf, '$') != NULL || index(buf, '#') != NULL || index(buf, '%') != NULL) {
      hydra_report_found_host(port, ip, "telnet", fp);
      hydra_completed_pair_found();
      if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
        return 3;
      free(buf);
      return 1;
    }
    (void) make_to_lower(buf);
    if (strstr(buf, "asswor") != NULL || strstr(buf, "asscode") != NULL || strstr(buf, "ennwort") != NULL)
      i = 1;
    if (i == 0 && ((strstr(buf, "ogin:") != NULL && strstr(buf, "last login") == NULL) || strstr(buf, "sername:") != NULL)) {
      free(buf);
      hydra_completed_pair();
      if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
        return 3;
      return 2;
    }
    free(buf);
  } while (i == 0);

#ifdef PALM
  sprintf(buffer, "%s\r", pass);
#else
  sprintf(buffer, "%.250s\r", pass);
#endif
  if (no_line_mode) {
    for (i = 0; i < strlen(buffer) + 1; i++) {
#ifdef PALM
      NetLibSend(AppNetRefnum, s, &buffer[i], 1, 0, 0, 0, AppNetTimeout, &error);
#else
      send(s, &buffer[i], 1, 0);
#endif
      usleep(5000);
    }
  } else {
    if (hydra_send(s, buffer, strlen(buffer) + 1, 0) < 0) {
      return 1;
    }
  }

  while ((buf = hydra_receive_line(s)) != NULL && make_to_lower(buf) && (strstr(buf, "login:"******"last login:"******"sername:") == NULL) {
    if ((miscptr != NULL && strstr(buf, miscptr) != NULL) ||(miscptr == NULL && ((index(buf, '/') != NULL || index(buf, '>') != NULL || index(buf, '%') != NULL || index(buf, '$') != NULL || index(buf, '#') != NULL ||
         (strstr(buf, " failed") == NULL  && index(buf, '%') != NULL))))) {
      hydra_report_found_host(port, ip, "telnet", fp);
      hydra_completed_pair_found();
      free(buf);
      if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
        return 3;
      return 1;
    }
    free(buf);
  }
  hydra_completed_pair();
  if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
    return 3;
  return 2;
}
Ejemplo n.º 22
0
// Reset speed
void reset_speed(void) {
  hd.ticks_wait = SysTicksPerSecond()/50; // 20 ms pr frame
}
Ejemplo n.º 23
0
// TODO: use timestamp stored in porefs so if palm turned off
//   or app switch, stopwatch should continue running
void drawCount(UInt32 dtik) {
    char buf[100];
    int l=0;
    unsigned long int s,hour,min,sec,hs;
    static unsigned long int lastsec=666;
    static unsigned long int lastmin=666;

    if (stopWatchPrefs.showTicks) {
	l=0;
	l+=StrPrintF(buf+l, "Ticks %lu", dtik);
	FntSetFont(largeBoldFont);
	WinPaintChars(buf,l,1,100);
    }

    //ms = dtik / (SysTicksPerSecond()/1000);
    s = dtik / (SysTicksPerSecond()/100);
    // for resumption of interrupted timer
    hs = s % 100;
    s = s / 100;
    s += stopWatchPrefs.tik_timestamp - stopWatchPrefs.timestamp;
    sec = s % 60;
    s = s / 60;
    min = s % 60;
    s = s / 60;
    hour = s % 60;
    l=0;
    l+=StrPrintF(buf+l, "%02d:%02d:%02d:%02d", (int)hour,(int)min,(int)sec,(int)hs);
    FntSetFont(largeBoldFont);
    WinPaintChars(buf,l,1,120);

    // a minute alarm
    if (sec == 0 && stopWatchPrefs.vol!=0) {
	int i;
	for(i=0;i<min%10;i++){
	    playFreq(sndCmdFrqOn,100+min*4,10,stopWatchPrefs.vol); 
            // freq,maxdur, amp(0 - sndMaxAmp)
	}
    }

    // not wanted every update, every second should do.
    if (sec != lastsec) {
	lastsec = sec;
	switch(stopWatchPrefs.visual) {
	    case btnVisualNum:
		// a big font

		// gfx too big & flickery ugly to flick every sec
		if (min != lastmin) {
		    lastmin=min;
		    bigDigit(5,20,'8',WinEraseLineF);
		    bigDigit(40,20,'8',WinEraseLineF);
		    //bigDigit(5,70,'8',WinEraseLineF);
		    bigDigit(80,20,'8',WinEraseLineF);
		    bigDigit(115,20,'8',WinEraseLineF);

		    l=0;
		    //l+=StrPrintF(buf+l, "%02d:%02d", (int)min,(int)sec);
		    l+=StrPrintF(buf+l, "%02d:%02d", (int)hour, (int)min);

		    bigDigit(5,20,buf[0],WinDrawLineF);
		    bigDigit(40,20,buf[1],WinDrawLineF);
		    //bigDigit(5,70,'7',WinDrawLineF);
		    bigDigit(80,20,buf[3],WinDrawLineF);
		    bigDigit(115,20,buf[4],WinDrawLineF);
		}
		break;

	    case btnVisualHour:
		break;

	    case btnVisualBar:
		eraseRectangleSafe(0, 20, 160, 20); // x,y,width,height
		drawRectangleSafe(0, 20, min * 4, 20); // x,y,width,height
		eraseRectangleSafe((min * 4)-1, 41, 160, 1); // x,y,width,height
		drawRectangleSafe((min * 4)-1, 41, 1, 1); // x,y,width,height
		if ((min%5)==0){
		    eraseRectangleSafe((min * 4)-2, 41, 160, 2); // x,y,width,height
		    drawRectangleSafe((min * 4)-2, 41, 2, 2); // x,y,width,height
		}
		break;

	    case btnVisualSticks:

		/* count like this 1 line = 1 minute
		   -----  -----  -----  -----
		   -----  -----  -----  -----
		   -----  -----  -----  -----
		   -----  -----  -----  -----
		   -----  -----  -----  -----
		   
		   -----
		   -----
		   160/4 = 40 => width 32 + 4 each side
		   base weights 1, 5, 20, oh look rns :)
		   3 height with 2 sep + 5 sep big blocks
		*/

		// better visually but is not a bar anymore
		/*drawRectangleSafe(4+36*(((min-1)/5)%4), 
				  20 + 30*((min-1)/20) + 5*((min-1)%5), 
				  32, 3); // x,y,width,height*/
		drawRectangleSafe(4+36*(((min)/5)%4), 
				  20 + 30*((min)/20) + 5*((min)%5), 
				  (32*sec)/59, 3); // x,y,width,height

		break;
	}

    }

    /* for testing
    drawRectangleSafe(4+36*(((sec-1)/5)%4), 
		      20 + 30*((sec-1)/20) + 5*((sec-1)%5), 
		      32, 3); // x,y,width,height
    */
}
Ejemplo n.º 24
0
static Boolean MainFormHandleEvent (EventPtr e)
{
    Boolean handled = false;
    FormPtr frm;
    static UInt32 start_sec=0;
    static UInt32 start_tik;
    static UInt32 end_sec;
    static UInt32 end_tik;
    //static int run = 0;
    
    switch (e->eType) {
    case frmOpenEvent:
	frm = FrmGetActiveForm();
	FrmDrawForm(frm);

	// resume interrupted count
	// note now stopWatchPrefs.tik_timestamp != stopWatchPrefs.timestamp
        // now this does work okay when switching away from app BUT
        // not when palm is turned off & on but stays in app
        // I think possibly GetTicks gets ticks from start of app
        // when palm off the ticks do not increment
	if (stopWatchPrefs.timestamp != 0) {
	    stopWatchPrefs.tik_timestamp = TimGetSeconds();
	    start_tik = TimGetTicks();
	    RunCount(start_tik);
	}

	handled = true;
	break;

    case menuEvent:
	MenuEraseStatus(NULL);

	switch(e->data.menu.itemID) {
	    // TODO add to TestTemp code
	    //case itemBar:
	    case itemRun:
		if (start_sec == 0) {
		    stopWatchPrefs.tik_timestamp =
			stopWatchPrefs.timestamp = 
			start_sec = TimGetSeconds();
		    start_tik = TimGetTicks();
		}
		RunCount(start_tik);
		break;
	    case itemHold:
		// break the run loop
		run = 0;
		break;
	    case itemStop:
		// break the run loop
		run = 0;
		end_sec = TimGetSeconds();
 		end_tik = TimGetTicks();
		break;
	    case itemClear:
		// break the run loop
		run = 0;
		start_sec = 0;
		stopWatchPrefs.timestamp = 0;
		stopWatchPrefs.tik_timestamp = 0;
		end_tik = 0;
		drawCount(0);
		break;

	    case itemPrefs:
		FrmPopupForm(PrefForm);
		break;

	    case itemTest1:

		WinDrawLine(20,20,50,50);
//void WinDrawChar (WChar theChar, Coord x, Coord y)
///void WinDrawChars (const Char *chars, Int16 len, Coord x, Coord y)
//void WinPaintChar (WChar theChar, Coord x, Coord y)
//void WinPaintChars (const Char *chars, Int16 len, Coord x, Coord y)
///opt/palmdev/sdk-5/include/Core/System/Window.h
// Font.h
		WinDrawChar('X',20,50);
		FntSetFont(symbol11Font);
		WinDrawChar('Y',40,50);
		FntSetFont(largeFont);
		WinDrawChar('Z',60,50);
		WinDrawChars("large Font",10,80,50);
		FntSetFont(largeBoldFont);
		WinDrawChars("large Bold",10,110,50);

		{
		    char buf[100];
		    int l=0;
		    UInt32 t = SysTicksPerSecond();
		    l+=StrPrintF(buf+l, "SysTicksPerSec is %lu", t);
		    FntSetFont(largeBoldFont);
		    WinPaintChars(buf,l,1,20);
		}

		if (0){
		    digiFontType ft;
		    ft.h = 20;
		    ft.w = 16;
		    ft.th = 4; ft.tw = 7;
		    drawHSeg(11,9,ft,WinDrawLineF);
		    drawVSeg(10,10,ft,WinDrawLineF);
		    drawHSeg(11,36,ft,WinDrawLineF);
		    drawVSeg(39,10,ft,WinDrawLineF);
		}

		if (0){
		    digiFontType ft;
		    ft.h = 20;
		    ft.w = 12;
		    ft.th = 4; ft.tw = 7;
		    drawHSeg(11,59,ft,WinDrawLineF);
		    drawVSeg(10,60,ft,WinDrawLineF);
		    drawVSeg(38,60,ft,WinDrawLineF);
		    drawHSeg(11,79,ft,WinDrawLineF);
		    drawVSeg(10,80,ft,WinDrawLineF);
		    drawVSeg(38,80,ft,WinDrawLineF);
		    drawHSeg(11,99,ft,WinDrawLineF);
		}

		bigDigit(5,20,'2',WinDrawLineF);
		bigDigit(40,20,'5',WinDrawLineF);
		bigDigit(5,70,'7',WinDrawLineF);
		break;

	    case itemTest2:

		bigDigit(5,20,'8',WinEraseLineF);
		bigDigit(40,20,'8',WinEraseLineF);
		bigDigit(5,70,'8',WinEraseLineF);

		WinDrawChars("Hello",5,20,80);
		WinPaintChars("Paint",5,20,110);

		//Err err; err = TimInit();
		{
		    char buf[100];
		    int l=0;
		    UInt32 s,t;
		    UInt32 hour,min,sec;
		    UInt32 day;
		    // seconds since 1/1/1904
		    //void TimSetSeconds(UInt32 seconds) 	
		    // ticks since power on
		    t = TimGetTicks();
		    s = TimGetSeconds();
		    
		    l+=StrPrintF(buf+l, "Secs %lu", s);
		    FntSetFont(largeBoldFont);
		    WinPaintChars(buf,l,1,20);

		    l=0;
		    l+=StrPrintF(buf+l, "Ticks %lu", t);
		    FntSetFont(largeBoldFont);
		    WinPaintChars(buf,l,1,40);

		    day = s / (UInt32)(24 * 60 * 60);
		    s = s - day * (24 * 60 * 60);
		    hour = s / (60 * 60);
		    s = s - hour * (60 * 60);
		    min = s / 60;
		    sec = s - min * 60;
		    l=0;
		    l+=StrPrintF(buf+l, "%07d:%02d:%02d:%02d", day, hour,min,sec);
		    FntSetFont(largeBoldFont);
		    WinPaintChars(buf,l,1,60);

		}
		break;

		// call this periodically to hold off auto off  
		// Err EvtResetAutoOffTimer(void)

// SystemMgr.h
//Err SysTimerCreate(UInt32 *timerIDP, UInt32 *tagP, 
//            SysTimerProcPtr timerProc, UInt32 periodicDelay, UInt32	param)
//Err		SysTimerDelete(UInt32 timerID)
//Err		SysTimerWrite(UInt32 timerID, UInt32 value)
//Err		SysTimerRead(UInt32 timerID, UInt32 *valueP)

//      SysTaskDelay((100 * SysTicksPerSecond())/1000);

	    case itemOptHelp:
		FrmHelp(hlpHelp);
		break;
		//case itemOptDbgDump:
		//debugDump(e->eType);
		//break;
	    case itemOptCopy:
		FrmHelp(hlpCopy);
		break;
	    case itemOptAbout:
		FrmCustomAlert(alertInfo, 
			       "stopWatch v" VERSION " not even Alpha. "
			       "Built " __DATE__ ", " __TIME__ ". "
			       "James Coleman http://www.dspsrv.com/~jamesc "
			       "copyleft me.", "", "");
		break;

	}

	//DEBUGBOX("menuEvent","");

    	handled = true;
	break;

    case ctlSelectEvent:
	switch(e->data.ctlSelect.controlID) {

	    case btnRun:
		if (start_sec == 0) {
		    stopWatchPrefs.tik_timestamp =
			stopWatchPrefs.timestamp = 
			start_sec = TimGetSeconds();
		    start_tik = TimGetTicks();
		}
		RunCount(start_tik);
		break;
	    case btnHold:
		// break the run loop
		run = 0;
		break;
	    case btnStop:
		// break the run loop
		run = 0;
		end_sec = TimGetSeconds();
 		end_tik = TimGetTicks();
		break;
	    case btnClear:
		// break the run loop
		run = 0;
		stopWatchPrefs.timestamp = start_sec = 0;
		stopWatchPrefs.tik_timestamp = 0;
		end_tik = 0;
		drawCount(0);
		break;

	}
	break;

    //case ctlRepeatEvent:
    //break;

    case penDownEvent:
    case penMoveEvent:
      doPenAction( e->eType, e->screenX, e->screenY, 0, 0); 
      //FrmCustomAlert(alertInfo, "pen down", "ARGSTR1", "ARGSTR2");
      break;

    case penUpEvent:
      doPenAction( penUpEvent, 
      	   e->data.penUp.start.x, e->data.penUp.start.y, 
      	   e->data.penUp.end.x, e->data.penUp.end.y);
      break;

    case keyDownEvent:

      {
	char buf[1000];
	int l=0;
	l+=StrPrintF(buf+l, "Char: %c %02x\n",e->data.keyDown.chr,e->data.keyDown.chr);
	buf[l]=0;
	DEBUGBOX("keyDownEvent",buf);
      }

      switch(e->data.keyDown.chr) {
      case pageUpChr:
      case pageDownChr:
	handled = true;
	break;
      case prevFieldChr:
      case nextFieldChr:
      case '\n':
	handled = true;
	break;
      default:
	if (!TxtCharIsCntrl(e->data.keyDown.chr)) {
	  handled = true;                 /* Swallow event */
	}
	break;
      }
      break;

    default:
        break;
    }

    return handled;
}