public void UpdateElapsedTime(bool Increment) { PspRtc.Update(); this.CurrentUpdatedTime = PspRtc.Elapsed.GetTotalMicroseconds(); { if (Increment) { this.ElapsedAccumulatedTime += this.CurrentUpdatedTime - this.PreviousUpdatedTime; } } this.PreviousUpdatedTime = this.CurrentUpdatedTime; }
//[HlePspNotImplemented] public int sceKernelLibcGettimeofday(TimeValStruct *TimeVal, TimeZoneStruct *TimeZone) { if (TimeVal != null) { PspRtc.Update(); ulong MicroSeconds = (ulong)PspRtc.Elapsed.GetTotalMicroseconds(); const ulong MicroSecondsInASecond = 1000 * 1000; TimeVal->Seconds = (uint)(MicroSeconds / MicroSecondsInASecond); TimeVal->Microseconds = (uint)(MicroSeconds % MicroSecondsInASecond); //TimeVal->Seconds = 0; //TimeVal->Microseconds = 0; //Console.Error.WriteLine("aaaaaaaaaaaaaaaaaaaaaaaaa {0}:{1}", TimeVal->Seconds, TimeVal->Microseconds); } if (TimeZone != null) { TimeZone->DstTime = 0; TimeZone->MinutesWest = 0; } //throw(new NotImplementedException()); return(0); }
//[HlePspNotImplemented] public int sceRtcGetCurrentTick(long *Tick) { PspRtc.Update(); *Tick = PspRtc.ElapsedTime.TotalMicroseconds; return(0); }
protected override void Main() { while (Running) { #if !DO_NOT_PROPAGATE_EXCEPTIONS try #endif { // HACK! TODO: Update PspRtc every 2 thread switchings. // Note: It should update the RTC after selecting the next thread to run. // But currently is is not possible since updating the RTC and waking up // threads has secondary effects that I have to consideer first. var tickAlternate = false; //PspRtc.Update(); while (true) { ThreadTaskQueue.HandleEnqueued(); if (!Running) { return; } if (!tickAlternate) { PspRtc.Update(); } tickAlternate = !tickAlternate; HleThreadManager.StepNext(DoBeforeSelectingNext: () => { //PspRtc.Update(); }); } } #if !DO_NOT_PROPAGATE_EXCEPTIONS catch (Exception e2) { if (e2 is SceKernelSelfStopUnloadModuleException || e2.InnerException is SceKernelSelfStopUnloadModuleException) { Console.WriteLine("SceKernelSelfStopUnloadModuleException"); Main_Ended(); return; } var errorOut = Console.Error; ConsoleUtils.SaveRestoreConsoleState(() => { Console.ForegroundColor = ConsoleColor.Red; try { errorOut.WriteLine("Error on thread {0}", HleThreadManager.Current); try { errorOut.WriteLine(e2); } catch (Exception e) { Console.WriteLine(e); } HleThreadManager.Current.CpuThreadState.DumpRegisters(errorOut); errorOut.WriteLine( "Last registered PC = 0x{0:X}, RA = 0x{1:X}, RelocatedBaseAddress=0x{2:X}, UnrelocatedPC=0x{3:X}", HleThreadManager.Current.CpuThreadState.Pc, HleThreadManager.Current.CpuThreadState.Ra, ElfConfig.RelocatedBaseAddress, HleThreadManager.Current.CpuThreadState.Pc - ElfConfig.RelocatedBaseAddress ); errorOut.WriteLine("Last called syscalls: "); foreach (var calledCallback in ModuleManager.LastCalledCallbacks.Reverse()) { errorOut.WriteLine(" {0}", calledCallback); } foreach (var thread in HleThreadManager.Threads) { errorOut.WriteLine("{0}", thread.ToExtendedString()); errorOut.WriteLine( "Last valid PC: 0x{0:X} :, 0x{1:X}", thread.CpuThreadState.LastValidPc, thread.CpuThreadState.LastValidPc - ElfConfig.RelocatedBaseAddress ); thread.DumpStack(errorOut); } errorOut.WriteLine( "Executable had relocation: {0}. RelocationAddress: 0x{1:X}", ElfConfig.InfoExeHasRelocation, ElfConfig.RelocatedBaseAddress ); errorOut.WriteLine(""); errorOut.WriteLine("Error on thread {0}", HleThreadManager.Current); errorOut.WriteLine(e2); //ErrorOut.WriteLine("Saved a memory dump to 'error_memorydump.bin'", HleThreadManager.Current); //MemoryManager.Memory.Dump("error_memorydump.bin"); } catch (Exception e3) { Console.WriteLine("{0}", e3); } }); Main_Ended(); } #endif } }
protected override void Main() { while (Running) { try { while (true) { ThreadTaskQueue.HandleEnqueued(); if (!Running) { return; } PspRtc.Update(); ThreadManager.StepNext(); } } catch (Exception Exception) { if (Exception is SceKernelSelfStopUnloadModuleException || Exception.InnerException is SceKernelSelfStopUnloadModuleException) { Console.WriteLine("SceKernelSelfStopUnloadModuleException"); Main_Ended(); return; } var ErrorOut = Console.Error; ConsoleUtils.SaveRestoreConsoleState(() => { Console.ForegroundColor = ConsoleColor.Red; try { ErrorOut.WriteLine("Error on thread {0}", ThreadManager.Current); ErrorOut.WriteLine(Exception); ThreadManager.Current.CpuThreadState.DumpRegisters(ErrorOut); ErrorOut.WriteLine( "Last registered PC = 0x{0:X}, RA = 0x{1:X}", ThreadManager.Current.CpuThreadState.PC, ThreadManager.Current.CpuThreadState.RA ); foreach (var Thread in ThreadManager.Threads) { ErrorOut.WriteLine("{0}", Thread); } ErrorOut.WriteLine("Executable had relocation: {0}", PspEmulatorContext.PspConfig.InfoExeHasRelocation); } catch (Exception Exception2) { Console.WriteLine("{0}", Exception2); } }); Main_Ended(); } } }