/// <summary> /// Wait for an event flag for a given bit pattern with callback. /// </summary> /// <param name="EventId">The event id returned by sceKernelCreateEventFlag.</param> /// <param name="Bits">The bit pattern to poll for.</param> /// <param name="Wait">Wait type, one or more of ::PspEventFlagWaitTypes or'ed together</param> /// <param name="OutBits">The bit pattern that was matched.</param> /// <param name="Timeout">Timeout in microseconds</param> /// <param name="HandleCallbacks"></param> /// <returns> /// ERROR_KERNEL_NOT_FOUND_EVENT_FLAG - If can't find the eventFlag /// ERROR_KERNEL_WAIT_TIMEOUT - If there was a timeout /// 0 - On success /// </returns> public int _sceKernelWaitEventFlagCB(EventFlagId EventId, uint Bits, EventFlagWaitTypeSet Wait, uint *OutBits, uint *Timeout, bool HandleCallbacks) { var EventFlag = HleState.EventFlagManager.EventFlags.Get(EventId); bool TimedOut = false; HleState.ThreadManager.Current.SetWaitAndPrepareWakeUp(HleThread.WaitType.Semaphore, String.Format("_sceKernelWaitEventFlagCB(EventId={0}, Bits={1:X}, Wait={2})", EventId, Bits, Wait), WakeUpCallback => { if (Timeout != null) { HleState.PspRtc.RegisterTimerInOnce(TimeSpanUtils.FromMicroseconds(*Timeout), () => { TimedOut = true; WakeUpCallback(); }); } EventFlag.AddWaitingThread(new HleEventFlag.WaitThread() { HleThread = HleState.ThreadManager.Current, BitsToMatch = Bits, WaitType = Wait, WakeUpCallback = () => { WakeUpCallback(); }, OutBits = OutBits, }); }, HandleCallbacks: HandleCallbacks); if (TimedOut) { throw(new SceKernelException(SceKernelErrors.ERROR_KERNEL_WAIT_TIMEOUT)); } //throw(new NotImplementedException()); return(0); }
public int sceKernelPollEventFlag([HleInvalidAsNull] HleEventFlag EventFlag, uint Bits, EventFlagWaitTypeSet WaitType, uint *OutBits) { if ((WaitType & ~EventFlagWaitTypeSet.MaskValidBits) != 0) { throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MODE); } // Poll seems to also fail when CLEAR and CLEARALL are used together, but not wait. if ((WaitType & (EventFlagWaitTypeSet.Clear | EventFlagWaitTypeSet.ClearAll)) == (EventFlagWaitTypeSet.Clear | EventFlagWaitTypeSet.ClearAll)) { throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MODE); } // Can't wait on 0, it never matches. if (Bits == 0) { throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_ILLEGAL_WAIT_PATTERN); } if (EventFlag == null) { throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_NOT_FOUND_EVENT_FLAG); } bool Matched = EventFlag.Poll(Bits, WaitType, OutBits); if (!Matched) { throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_POLL_FAILED); } return(0); }
/// <summary> /// Wait for an event flag for a given bit pattern with callback. /// </summary> /// <param name="EventId">The event ID returned by <see cref="sceKernelCreateEventFlag"/>.</param> /// <param name="Bits">The bit pattern to poll for.</param> /// <param name="Wait">Wait type, one or more of PspEventFlagWaitTypes or'ed together</param> /// <param name="OutBits">The bit pattern that was matched.</param> /// <param name="Timeout">Timeout in microseconds</param> /// <param name="HandleCallbacks"></param> /// <returns> /// ERROR_KERNEL_NOT_FOUND_EVENT_FLAG - If can't find the eventFlag /// ERROR_KERNEL_WAIT_TIMEOUT - If there was a timeout /// 0 - On success /// </returns> public int _sceKernelWaitEventFlagCB(HleEventFlag EventFlag, uint Bits, EventFlagWaitTypeSet Wait, uint *OutBits, uint *Timeout, bool HandleCallbacks) { if ((Wait & ~EventFlagWaitTypeSet.MaskValidBits) != 0) { throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MODE); } if (Bits == 0) { throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_ILLEGAL_WAIT_PATTERN); } bool TimedOut = false; var PreviousPattern = EventFlag.Info.CurrentPattern; ThreadManager.Current.SetWaitAndPrepareWakeUp( HleThread.WaitType.Semaphore, $"_sceKernelWaitEventFlagCB(EventId={EventFlag.GetUidIndex(InjectContext)}, Bits={Bits:X}, Wait={Wait})", EventFlag, WakeUpCallback => { if (Timeout != null) { PspRtc.RegisterTimerInOnce(TimeSpanUtils.FromMicroseconds(*Timeout), () => { TimedOut = true; *Timeout = 0; WakeUpCallback(); }); } EventFlag.AddWaitingThread(new HleEventFlag.WaitThread() { HleThread = ThreadManager.Current, BitsToMatch = Bits, WaitType = Wait, WakeUpCallback = () => { WakeUpCallback(); }, OutBits = OutBits, }); }, HandleCallbacks: HandleCallbacks); if (OutBits != null) { *OutBits = PreviousPattern; } if (TimedOut) { throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_WAIT_TIMEOUT); } //throw(new NotImplementedException()); return(0); }
public int sceKernelPollEventFlag(EventFlagId EventId, uint Bits, EventFlagWaitTypeSet WaitType, uint* OutBits) { var EventFlag = HleState.EventFlagManager.EventFlags.Get(EventId); if (Bits == 0) throw(new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_ILLEGAL_WAIT_PATTERN)); bool Matched = EventFlag.Poll(Bits, WaitType, OutBits); if (!Matched) { throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_POLL_FAILED)); } return 0; }
public unsafe bool Poll(uint BitsToMatch, EventFlagWaitTypeSet WaitType, uint *CheckedBits) { if (CheckedBits != null) { *CheckedBits = BitPattern; } if (WaitType.HasFlag(EventFlagWaitTypeSet.Or)) { return((BitPattern & BitsToMatch) != 0); } else { return((BitPattern & BitsToMatch) == BitsToMatch); } }
public int sceKernelPollEventFlag(EventFlagId EventId, uint Bits, EventFlagWaitTypeSet WaitType, uint *OutBits) { var EventFlag = HleState.EventFlagManager.EventFlags.Get(EventId); if (Bits == 0) { throw(new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_ILLEGAL_WAIT_PATTERN)); } bool Matched = EventFlag.Poll(Bits, WaitType, OutBits); if (!Matched) { throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_POLL_FAILED)); } return(0); }
public int sceKernelWaitEventFlagCB(EventFlagId EventId, uint Bits, EventFlagWaitTypeSet WaitType, uint *OutBits, uint *Timeout) { return(_sceKernelWaitEventFlagCB(EventId, Bits, WaitType, OutBits, Timeout, true)); }
public unsafe bool Poll(uint BitsToMatch, EventFlagWaitTypeSet WaitType, uint* CheckedBits) { if (CheckedBits != null) { *CheckedBits = Info.CurrentPattern; } if (WaitType.HasFlag(EventFlagWaitTypeSet.Or)) { return (Info.CurrentPattern & BitsToMatch) != 0; } else { return (Info.CurrentPattern & BitsToMatch) == BitsToMatch; } }
private void _DoClear(EventFlagWaitTypeSet WaitType, uint BitsToMatch) { if (WaitType.HasFlag(EventFlagWaitTypeSet.ClearAll)) ClearBits(~uint.MaxValue, false); if (WaitType.HasFlag(EventFlagWaitTypeSet.Clear)) ClearBits(~BitsToMatch, false); }
public bool Poll(uint BitsToMatch, EventFlagWaitTypeSet WaitType, uint* OutBits) { if (OutBits != null) { *OutBits = Info.CurrentPattern; } if ( (WaitType.HasFlag(EventFlagWaitTypeSet.Or)) ? ((Info.CurrentPattern & BitsToMatch) != 0) // one or more bits of the mask : ((Info.CurrentPattern & BitsToMatch) == BitsToMatch)) // all the bits of the mask { _DoClear(WaitType, BitsToMatch); return true; } return false; }
public int sceKernelWaitEventFlag(HleEventFlag EventFlag, uint Bits, EventFlagWaitTypeSet WaitType, uint *OutBits, uint *Timeout) { return(_sceKernelWaitEventFlagCB(EventFlag, Bits, WaitType, OutBits, Timeout, false)); }
/// <summary> /// Wait for an event flag for a given bit pattern with callback. /// </summary> /// <param name="EventId">The event id returned by sceKernelCreateEventFlag.</param> /// <param name="Bits">The bit pattern to poll for.</param> /// <param name="Wait">Wait type, one or more of ::PspEventFlagWaitTypes or'ed together</param> /// <param name="OutBits">The bit pattern that was matched.</param> /// <param name="Timeout">Timeout in microseconds</param> /// <param name="HandleCallbacks"></param> /// <returns> /// ERROR_KERNEL_NOT_FOUND_EVENT_FLAG - If can't find the eventFlag /// ERROR_KERNEL_WAIT_TIMEOUT - If there was a timeout /// 0 - On success /// </returns> public int _sceKernelWaitEventFlagCB(EventFlagId EventId, uint Bits, EventFlagWaitTypeSet Wait, uint* OutBits, uint* Timeout, bool HandleCallbacks) { var EventFlag = EventFlagManager.EventFlags.Get(EventId); bool TimedOut = false; ThreadManager.Current.SetWaitAndPrepareWakeUp( HleThread.WaitType.Semaphore, String.Format("_sceKernelWaitEventFlagCB(EventId={0}, Bits={1:X}, Wait={2})", EventId, Bits, Wait), EventFlag, WakeUpCallback => { if (Timeout != null) { PspRtc.RegisterTimerInOnce(TimeSpanUtils.FromMicroseconds(*Timeout), () => { TimedOut = true; WakeUpCallback(); }); } EventFlag.AddWaitingThread(new HleEventFlag.WaitThread() { HleThread = ThreadManager.Current, BitsToMatch = Bits, WaitType = Wait, WakeUpCallback = () => { WakeUpCallback(); }, OutBits = OutBits, }); }, HandleCallbacks: HandleCallbacks); if (OutBits != null) { *OutBits = EventFlag.Info.CurrentPattern; } if (TimedOut) { throw(new SceKernelException(SceKernelErrors.ERROR_KERNEL_WAIT_TIMEOUT)); } //throw(new NotImplementedException()); return 0; }
public int sceKernelWaitEventFlagCB(EventFlagId EventId, uint Bits, EventFlagWaitTypeSet WaitType, uint* OutBits, uint* Timeout) { return _sceKernelWaitEventFlagCB(EventId, Bits, WaitType, OutBits, Timeout, true); }
/// <summary> /// Wait for an event flag for a given bit pattern with callback. /// </summary> /// <param name="EventId">The event ID returned by <see cref="sceKernelCreateEventFlag"/>.</param> /// <param name="Bits">The bit pattern to poll for.</param> /// <param name="Wait">Wait type, one or more of PspEventFlagWaitTypes or'ed together</param> /// <param name="OutBits">The bit pattern that was matched.</param> /// <param name="Timeout">Timeout in microseconds</param> /// <param name="HandleCallbacks"></param> /// <returns> /// ERROR_KERNEL_NOT_FOUND_EVENT_FLAG - If can't find the eventFlag /// ERROR_KERNEL_WAIT_TIMEOUT - If there was a timeout /// 0 - On success /// </returns> public int _sceKernelWaitEventFlagCB(HleEventFlag EventFlag, uint Bits, EventFlagWaitTypeSet Wait, uint* OutBits, uint* Timeout, bool HandleCallbacks) { if ((Wait & ~(EventFlagWaitTypeSet.MaskValidBits)) != 0) throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MODE)); if (Bits == 0) throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_ILLEGAL_WAIT_PATTERN)); bool TimedOut = false; var PreviousPattern = EventFlag.Info.CurrentPattern; ThreadManager.Current.SetWaitAndPrepareWakeUp( HleThread.WaitType.Semaphore, String.Format("_sceKernelWaitEventFlagCB(EventId={0}, Bits={1:X}, Wait={2})", EventFlag.GetUidIndex(InjectContext), Bits, Wait), EventFlag, WakeUpCallback => { if (Timeout != null) { PspRtc.RegisterTimerInOnce(TimeSpanUtils.FromMicroseconds(*Timeout), () => { TimedOut = true; *Timeout = 0; WakeUpCallback(); }); } EventFlag.AddWaitingThread(new HleEventFlag.WaitThread() { HleThread = ThreadManager.Current, BitsToMatch = Bits, WaitType = Wait, WakeUpCallback = () => { WakeUpCallback(); }, OutBits = OutBits, }); }, HandleCallbacks: HandleCallbacks); if (OutBits != null) { *OutBits = PreviousPattern; } if (TimedOut) { throw(new SceKernelException(SceKernelErrors.ERROR_KERNEL_WAIT_TIMEOUT)); } //throw(new NotImplementedException()); return 0; }
public int sceKernelWaitEventFlag(HleEventFlag EventFlag, uint Bits, EventFlagWaitTypeSet WaitType, uint* OutBits, uint* Timeout) { return _sceKernelWaitEventFlagCB(EventFlag, Bits, WaitType, OutBits, Timeout, false); }
public int sceKernelPollEventFlag([HleInvalidAsNull] HleEventFlag EventFlag, uint Bits, EventFlagWaitTypeSet WaitType, uint* OutBits) { if ((WaitType & ~EventFlagWaitTypeSet.MaskValidBits) != 0) { throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MODE)); } // Poll seems to also fail when CLEAR and CLEARALL are used together, but not wait. if ((WaitType & (EventFlagWaitTypeSet.Clear | EventFlagWaitTypeSet.ClearAll)) == (EventFlagWaitTypeSet.Clear | EventFlagWaitTypeSet.ClearAll)) { throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MODE)); } // Can't wait on 0, it never matches. if (Bits == 0) { throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_ILLEGAL_WAIT_PATTERN)); } if (EventFlag == null) { throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_NOT_FOUND_EVENT_FLAG)); } bool Matched = EventFlag.Poll(Bits, WaitType, OutBits); if (!Matched) { throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_POLL_FAILED)); } return 0; }