1 // Copyright (c) 2012- PPSSPP Project.
2
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
6
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
11
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18 #include "Core/HLE/HLE.h"
19 #include "Core/HLE/FunctionWrappers.h"
20 #include "Core/HLE/sceMt19937.h"
21 #include "Core/MemMap.h"
22 #include "Core/Reporting.h"
23
24 #ifdef USE_CRT_DBG
25 #undef new
26 #endif
27
28
sceMt19937Init(u32 mt19937Addr,u32 seed)29 static u32 sceMt19937Init(u32 mt19937Addr, u32 seed)
30 {
31 if (!Memory::IsValidAddress(mt19937Addr))
32 return hleLogError(HLE, -1);
33 void *ptr = Memory::GetPointer(mt19937Addr);
34 // This is made to match the memory layout of a PSP MT structure exactly.
35 // Let's just construct it in place with placement new. Elite C++ hackery FTW.
36 new (ptr) MersenneTwister(seed);
37 return hleLogSuccessInfoI(HLE, 0);
38 }
39
sceMt19937UInt(u32 mt19937Addr)40 static u32 sceMt19937UInt(u32 mt19937Addr)
41 {
42 if (!Memory::IsValidAddress(mt19937Addr))
43 return hleLogError(HLE, -1);
44 MersenneTwister *mt = (MersenneTwister *)Memory::GetPointer(mt19937Addr);
45 return hleLogSuccessVerboseX(HLE, mt->R32());
46 }
47
48 const HLEFunction sceMt19937[] =
49 {
50 {0XECF5D379, &WrapU_UU<sceMt19937Init>, "sceMt19937Init", 'x', "xx"},
51 {0XF40C98E6, &WrapU_U<sceMt19937UInt>, "sceMt19937UInt", 'x', "x" },
52 };
53
Register_sceMt19937()54 void Register_sceMt19937()
55 {
56 RegisterModule("sceMt19937", ARRAY_SIZE(sceMt19937), sceMt19937);
57 }
58