PS2SDK
PS2 Homebrew Libraries
rom0_info.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
17 #include <rom0_info.h>
18 
19 #include <iopheap.h>
20 #include <string.h>
21 #include <sifrpc.h>
22 #include <kernel.h>
23 #include <syscallnr.h>
24 
26 {
28  char m_romver[14];
29 };
30 
31 extern struct rom0_info_data g_rom0_info_data;
32 
33 #ifdef F__info_internals
34 struct rom0_info_data g_rom0_info_data;
35 #endif
36 
37 #ifdef F_SetupRomInfo
38 void SetupRomInfo(void)
39 {
40  void *iop_addr;
41  SifRpcReceiveData_t rdata;
42  u8 buf[64] __attribute__((__aligned__(64)));
43 
44  /* ROMVER needs to be read from the IOP due to PPCIOP region patching. */
45  /* only read in the romname the first time */
46  if (g_rom0_info_data.m_romver[0])
47  return;
48 
49  /* SYSMEM allocates in units of 256. */
50  if (!(iop_addr = SifAllocIopHeap(256)))
51  return;
52 
53  /* ROMVER is known to be 16 bytes. */
54  if (SifLoadIopHeap("rom:ROMVER", iop_addr) < 0)
55  {
56  SifFreeIopHeap(iop_addr);
57  return;
58  }
59  SyncDCache(buf, buf + sizeof(buf));
60  if (sceSifGetOtherData(&rdata, iop_addr, buf, sizeof(buf), 0) < 0)
61  {
62  SifFreeIopHeap(iop_addr);
63  return;
64  }
65  memcpy(g_rom0_info_data.m_romver, UNCACHED_SEG(buf), sizeof(g_rom0_info_data.m_romver));
66 
67  SifFreeIopHeap(iop_addr);
68 }
69 #endif
70 
71 #ifdef F_GetRomName
72 char *GetRomName(char *romname)
73 {
74  SetupRomInfo();
75  /* Explicitly copy 14 bytes to the buffer, without NULL terminator */
76  memcpy(romname, g_rom0_info_data.m_romver, sizeof(g_rom0_info_data.m_romver));
77  return romname;
78 }
79 #endif
80 
81 #ifdef F_IsDESRMachine
82 int IsDESRMachine(void)
83 {
84  /* Use the existence of ExecPSX syscall as the determination. */
85  return GetSyscallHandler(__NR_ExecPSX) ? 1 : 0;
86 }
87 #endif
88 
89 #ifdef F_IsT10K
90 int IsT10K(void)
91 {
92  SetupRomInfo();
93  return (g_rom0_info_data.m_romver[4] == 'T' && g_rom0_info_data.m_romver[5] != 'Z') ? 1 : 0;
94 }
95 #endif
kernel.h
IsDESRMachine
int IsDESRMachine(void)
rom0_info.h
rom0_info_data
Definition: rom0_info.c:25
t_SifRpcReceiveData
Definition: sifrpc-common.h:145
GetRomName
char * GetRomName(char *romname)
iopheap.h
IsT10K
int IsT10K(void)
__attribute__
typedef __attribute__
Definition: tlbfunc.c:60
rom0_info_data::m_romver
char m_romver[14]
Definition: rom0_info.c:28
syscallnr.h