source: ps2launchargs/source/uLaunchELF/chkesr/chkesr.c@ 1171

Last change on this file since 1171 was 1101, checked in by iritscen, 7 years ago

Added following to ps2launchargs:\n-Source code.\n-DLL needed to run ps2client.\n-Instructions for building uLaunchELF.

  • Property svn:executable set to *
File size: 3.3 KB
Line 
1/*
2 _____ ___ ____
3 ____| | ____| PS2 Open Source Project
4 | ___| |____
5
6---------------------------------------------------------------------------
7*/
8
9#include <cdvdman.h>
10#include <intrman.h>
11#include <loadcore.h>
12#include <sifcmd.h>
13#include <sysclib.h>
14#include <sysmem.h>
15#include <thbase.h>
16#include <stdio.h>
17
18#define MODNAME "chkesr"
19IRX_ID(MODNAME, 1, 1);
20
21#define CHKESR_IRX 0x0E0E0E0
22
23int __attribute__((unused)) shutdown() { return 0; }
24
25/* function declaration */
26void rpcMainThread(void* param);
27void *rpcCommandHandler(int command, void *Data, int Size);
28void *Check_ESR_Disc(void *Data);
29void *SysAlloc(u64 size);
30int SysFree(void *area);
31
32static SifRpcDataQueue_t Rpc_Queue __attribute__((aligned(64)));
33static SifRpcServerData_t Rpc_Server __attribute((aligned(64)));
34static int Rpc_Buffer[1024] __attribute((aligned(64)));
35
36//--------------------------------------------------------------
37/* Description: Module entry point */
38int _start(int argc, char **argv)
39{
40 iop_thread_t param;
41 int id;
42
43 /*create thread*/
44 param.attr = TH_C;
45 param.thread = rpcMainThread;
46 param.priority = 40;
47 param.stacksize = 0x800;
48 param.option = 0;
49
50 if((id = CreateThread(&param)) <= 0)
51 return MODULE_NO_RESIDENT_END;
52
53 StartThread(id,0);
54
55 return MODULE_RESIDENT_END;
56}
57//--------------------------------------------------------------
58void rpcMainThread(void* param)
59{
60 SifInitRpc(0);
61 SifSetRpcQueue(&Rpc_Queue, GetThreadId());
62 SifRegisterRpc(&Rpc_Server, CHKESR_IRX, (void *) rpcCommandHandler, (u8 *) &Rpc_Buffer, 0, 0, &Rpc_Queue);
63 SifRpcLoop(&Rpc_Queue);
64}
65//--------------------------------------------------------------
66void *rpcCommandHandler(int command, void *Data, int Size)
67{
68 switch(command)
69 {
70 case 1:
71 Data = Check_ESR_Disc(Data);
72 break;
73 }
74
75 return Data;
76}
77//--------------------------------------------------------------
78void *Check_ESR_Disc(void *Data)
79{
80
81 u32 *ret = Data;
82 cd_read_mode_t s_DVDReadMode;
83 u8 *buf = NULL;
84 int offs = 12;
85 int i;
86 int r = 0;
87
88 //printf("Check_ESR_Disc starting.\n");
89
90 *ret = -1;
91
92 buf = (u8*)SysAlloc((2048 + 0xFF) & ~(u32)0xFF);
93 if (buf != NULL) *ret = 0;
94
95 if (*ret == 0) {
96 s_DVDReadMode.trycount = 5;
97 s_DVDReadMode.spindlctrl = CdSpinStm;
98 s_DVDReadMode.datapattern = CdSecS2048;
99 s_DVDReadMode.pad = 0x00;
100
101 for (i=0; i<2048; i++) buf[i] = 0;
102
103 //sceCdDiskReady(0);
104 //r = sceCdRead(14, 1, buf, &s_DVDReadMode); // read LBA 14
105 r = sceCdReadDVDV(14, 1, buf, &s_DVDReadMode); // read LBA 14
106 sceCdSync(0);
107
108 if (r <= 0) *ret = -1;
109 else if (!strncmp(buf + offs + 25, "+NSR", 4))
110 *ret = 1;
111
112 SysFree(buf);
113 }
114
115 //printf("Check_ESR_Disc returning %ld\n", *ret);
116 return Data;
117}
118//--------------------------------------------------------------
119void *SysAlloc(u64 size)
120{
121 int oldstate;
122 register void *p;
123
124 CpuSuspendIntr(&oldstate);
125 p = AllocSysMemory(ALLOC_FIRST, size, NULL);
126 CpuResumeIntr(oldstate);
127
128 return p;
129}
130//--------------------------------------------------------------
131int SysFree(void *area)
132{
133 int oldstate;
134 register int r;
135
136 CpuSuspendIntr(&oldstate);
137 r = FreeSysMemory(area);
138 CpuResumeIntr(oldstate);
139
140 return r;
141}
142//--------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.