Skip to content

Commit adcc04a

Browse files
authored
Merge pull request #707 from uyjulian/poffsim_impl
Implementation of poffsim module
2 parents 3cea633 + 5610ac1 commit adcc04a

File tree

6 files changed

+151
-0
lines changed

6 files changed

+151
-0
lines changed

iop/cdvd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SUBDIRS = \
1111
cdvdfsv \
1212
cdvdman \
1313
cdvdstm \
14+
poffsim \
1415
xesdrv
1516

1617
include $(PS2SDKSRC)/Defs.make

iop/cdvd/poffsim/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# _____ ___ ____ ___ ____
2+
# ____| | ____| | | |____|
3+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
4+
#-----------------------------------------------------------------------
5+
# Copyright ps2dev - http://www.ps2dev.org
6+
# Licenced under Academic Free License version 2.0
7+
# Review ps2sdk README & LICENSE files for further details.
8+
9+
IOP_INCS += \
10+
-I$(PS2SDKSRC)/iop/cdvd/cdvdman/include \
11+
-I$(PS2SDKSRC)/iop/system/sysmem/include \
12+
-I$(PS2SDKSRC)/iop/system/threadman/include
13+
14+
IOP_OBJS = \
15+
poweroff.o \
16+
imports.o
17+
18+
include $(PS2SDKSRC)/Defs.make
19+
include $(PS2SDKSRC)/iop/Rules.bin.make
20+
include $(PS2SDKSRC)/iop/Rules.make
21+
include $(PS2SDKSRC)/iop/Rules.release

iop/cdvd/poffsim/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Power off simulation
2+
3+
This module simulates power off callbacks, equivalent to the `POWEROFF` module on DTL-T.
4+
This is useful for situations when debugging on systems that do not support
5+
power off callbacks, such as SCPH-10000.
6+
7+
## Configurations
8+
9+
There are multiple configurations of this library, allowing the choice of
10+
balancing between size, speed, and features.
11+
12+
* `poffsim` -> The recommended version.
13+
14+
## How to use this module in your program
15+
16+
In order to use this module in your program, use `LoadModule` or \
17+
`LoadModuleBuffer` with no arguments.

iop/cdvd/poffsim/src/imports.lst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
cdvdman_IMPORTS_start
3+
I_sceCdSC
4+
cdvdman_IMPORTS_end
5+
6+
sysmem_IMPORTS_start
7+
I_Kprintf
8+
sysmem_IMPORTS_end
9+
10+
thbase_IMPORTS_start
11+
I_SetAlarm
12+
thbase_IMPORTS_end
13+
14+
thevent_IMPORTS_start
15+
I_iSetEventFlag
16+
thevent_IMPORTS_end
17+
18+
thsemap_IMPORTS_start
19+
I_CreateSema
20+
I_DeleteSema
21+
I_iSignalSema
22+
I_WaitSema
23+
thsemap_IMPORTS_end

iop/cdvd/poffsim/src/irx_imports.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
# _____ ___ ____ ___ ____
3+
# ____| | ____| | | |____|
4+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5+
#-----------------------------------------------------------------------
6+
# Copyright 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+
11+
#ifndef IOP_IRX_IMPORTS_H
12+
#define IOP_IRX_IMPORTS_H
13+
14+
#include <irx.h>
15+
16+
#include <cdvdman.h>
17+
#include <sysmem.h>
18+
#include <thbase.h>
19+
#include <thevent.h>
20+
#include <thsemap.h>
21+
22+
#endif /* IOP_IRX_IMPORTS_H */

iop/cdvd/poffsim/src/poweroff.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
# _____ ___ ____ ___ ____
3+
# ____| | ____| | | |____|
4+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5+
#-----------------------------------------------------------------------
6+
# Copyright 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+
11+
#include "irx_imports.h"
12+
13+
// Based on the module from SDK 3.1.0.
14+
15+
struct poffemu_param_stru
16+
{
17+
int m_cdvdman_intr_efid;
18+
void (*m_cdvdman_poff_cb)(void *);
19+
void *m_cdvdman_poffarg;
20+
int m_sema_id;
21+
};
22+
23+
static struct poffemu_param_stru sCdPtbl;
24+
25+
static unsigned int _sceCdPoffEmu(struct poffemu_param_stru *arg)
26+
{
27+
Kprintf("PowerOff Simulation Start\n");
28+
iSetEventFlag(arg->m_cdvdman_intr_efid, 4);
29+
iSetEventFlag(arg->m_cdvdman_intr_efid, 0x10);
30+
if ( arg->m_cdvdman_poff_cb )
31+
arg->m_cdvdman_poff_cb(arg->m_cdvdman_poffarg);
32+
iSignalSema(arg->m_sema_id);
33+
return 0;
34+
}
35+
36+
int _start(int ac, char **av)
37+
{
38+
int unusedval;
39+
iop_sema_t semaparam;
40+
// Unofficial: the following variable has been made local stack
41+
iop_sys_clock_t sCdPoff_time;
42+
43+
(void)ac;
44+
(void)av;
45+
46+
semaparam.attr = 1;
47+
semaparam.initial = 0;
48+
semaparam.max = 1;
49+
semaparam.option = 0;
50+
sCdPtbl.m_sema_id = CreateSema(&semaparam);
51+
sCdPtbl.m_cdvdman_intr_efid = sceCdSC(0xFFFFFFF5, &unusedval);
52+
sCdPtbl.m_cdvdman_poff_cb = 0;
53+
if ( (unsigned int)sceCdSC(0xFFFFFFF7, &unusedval) < 0x222 )
54+
{
55+
Kprintf("This cdvdman.irx doesn't support the simulation of PowerOff_Callback of IOP\n");
56+
}
57+
else
58+
{
59+
sCdPtbl.m_cdvdman_poffarg = (void *)(uiptr)sceCdSC(0xFFFFFFE6, (int *)&sCdPtbl.m_cdvdman_poff_cb);
60+
}
61+
sCdPoff_time.hi = 0;
62+
sCdPoff_time.lo = 0x90000;
63+
SetAlarm(&sCdPoff_time, (unsigned int (*)(void *))_sceCdPoffEmu, &sCdPtbl);
64+
WaitSema(sCdPtbl.m_sema_id);
65+
DeleteSema(sCdPtbl.m_sema_id);
66+
return 1;
67+
}

0 commit comments

Comments
 (0)