Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of poffsim module #707

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions iop/cdvd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SUBDIRS = \
cdvdfsv \
cdvdman \
cdvdstm \
poffsim \
xesdrv

include $(PS2SDKSRC)/Defs.make
Expand Down
21 changes: 21 additions & 0 deletions iop/cdvd/poffsim/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

IOP_INCS += \
-I$(PS2SDKSRC)/iop/cdvd/cdvdman/include \
-I$(PS2SDKSRC)/iop/system/sysmem/include \
-I$(PS2SDKSRC)/iop/system/threadman/include

IOP_OBJS = \
poweroff.o \
imports.o

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/iop/Rules.bin.make
include $(PS2SDKSRC)/iop/Rules.make
include $(PS2SDKSRC)/iop/Rules.release
17 changes: 17 additions & 0 deletions iop/cdvd/poffsim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Power off simulation

This module simulates power off callbacks, equivalent to the `POWEROFF` module on DTL-T.
This is useful for situations when debugging on systems that do not support
power off callbacks, such as SCPH-10000.

## Configurations

There are multiple configurations of this library, allowing the choice of
balancing between size, speed, and features.

* `poffsim` -> The recommended version.

## How to use this module in your program

In order to use this module in your program, use `LoadModule` or \
`LoadModuleBuffer` with no arguments.
23 changes: 23 additions & 0 deletions iop/cdvd/poffsim/src/imports.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

cdvdman_IMPORTS_start
I_sceCdSC
cdvdman_IMPORTS_end

sysmem_IMPORTS_start
I_Kprintf
sysmem_IMPORTS_end

thbase_IMPORTS_start
I_SetAlarm
thbase_IMPORTS_end

thevent_IMPORTS_start
I_iSetEventFlag
thevent_IMPORTS_end

thsemap_IMPORTS_start
I_CreateSema
I_DeleteSema
I_iSignalSema
I_WaitSema
thsemap_IMPORTS_end
22 changes: 22 additions & 0 deletions iop/cdvd/poffsim/src/irx_imports.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
*/

#ifndef IOP_IRX_IMPORTS_H
#define IOP_IRX_IMPORTS_H

#include <irx.h>

#include <cdvdman.h>
#include <sysmem.h>
#include <thbase.h>
#include <thevent.h>
#include <thsemap.h>

#endif /* IOP_IRX_IMPORTS_H */
67 changes: 67 additions & 0 deletions iop/cdvd/poffsim/src/poweroff.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
*/

#include "irx_imports.h"

// Based on the module from SDK 3.1.0.

struct poffemu_param_stru
{
int m_cdvdman_intr_efid;
void (*m_cdvdman_poff_cb)(void *);
void *m_cdvdman_poffarg;
int m_sema_id;
};

static struct poffemu_param_stru sCdPtbl;

static unsigned int _sceCdPoffEmu(struct poffemu_param_stru *arg)
{
Kprintf("PowerOff Simulation Start\n");
iSetEventFlag(arg->m_cdvdman_intr_efid, 4);
iSetEventFlag(arg->m_cdvdman_intr_efid, 0x10);
if ( arg->m_cdvdman_poff_cb )
arg->m_cdvdman_poff_cb(arg->m_cdvdman_poffarg);
iSignalSema(arg->m_sema_id);
return 0;
}

int _start(int ac, char **av)
{
int unusedval;
iop_sema_t semaparam;
// Unofficial: the following variable has been made local stack
iop_sys_clock_t sCdPoff_time;

(void)ac;
(void)av;

semaparam.attr = 1;
semaparam.initial = 0;
semaparam.max = 1;
semaparam.option = 0;
sCdPtbl.m_sema_id = CreateSema(&semaparam);
sCdPtbl.m_cdvdman_intr_efid = sceCdSC(0xFFFFFFF5, &unusedval);
sCdPtbl.m_cdvdman_poff_cb = 0;
if ( (unsigned int)sceCdSC(0xFFFFFFF7, &unusedval) < 0x222 )
{
Kprintf("This cdvdman.irx doesn't support the simulation of PowerOff_Callback of IOP\n");
}
else
{
sCdPtbl.m_cdvdman_poffarg = (void *)(uiptr)sceCdSC(0xFFFFFFE6, (int *)&sCdPtbl.m_cdvdman_poff_cb);
}
sCdPoff_time.hi = 0;
sCdPoff_time.lo = 0x90000;
SetAlarm(&sCdPoff_time, (unsigned int (*)(void *))_sceCdPoffEmu, &sCdPtbl);
WaitSema(sCdPtbl.m_sema_id);
DeleteSema(sCdPtbl.m_sema_id);
return 1;
}
Loading