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); }
public int sceKernelCancelEventFlag(HleEventFlag EventFlag, int NewPattern, int *NumWaitThread) { foreach (var WaitingThread in EventFlag.WaitingThreads) { WaitingThread.WakeUpCallback(); } //throw(new NotImplementedException()); 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 EventFlagId sceKernelCreateEventFlag(string Name, HleEventFlag.AttributesSet Attributes, uint BitPattern, SceKernelEventFlagOptParam *OptionsPtr) { if (OptionsPtr != null) { throw (new NotImplementedException("(OptionsPtr != null)")); } var HleEventFlag = new HleEventFlag() { Name = Name, Attributes = Attributes, BitPattern = BitPattern, }; HleEventFlag.Info.InitialPattern = BitPattern; return(HleState.EventFlagManager.EventFlags.Create(HleEventFlag)); }
//[HlePspNotImplemented] public int sceKernelReferEventFlagStatus(HleEventFlag EventFlag, ref EventFlagInfo Info) { #if true if (Info.Size != 0) { Info = EventFlag.Info; } #else fixed(void *OutPtr = &Info) fixed(void *InPtr = &EventFlag.Info) { PointerUtils.Memcpy((byte *)OutPtr, (byte *)InPtr, Info.Size); } #endif //Console.WriteLine(Info); return(0); }
public int sceKernelClearEventFlag(HleEventFlag EventFlag, uint BitsToClear) { EventFlag.ClearBits(BitsToClear); return(0); }
public int sceKernelDeleteEventFlag(HleEventFlag EventFlag) { EventFlag.RemoveUid(InjectContext); return(0); }
public int sceKernelSetEventFlag(HleEventFlag EventFlag, uint BitPattern) { //Console.WriteLine("FLAG:{0} : {1:X}", EventId, BitPattern); EventFlag.SetBits(BitPattern); return(0); }
public int sceKernelWaitEventFlagCB(HleEventFlag EventFlag, uint Bits, EventFlagWaitTypeSet WaitType, uint *OutBits, uint *Timeout) { return(_sceKernelWaitEventFlagCB(EventFlag, Bits, WaitType, OutBits, Timeout, true)); }