PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
poweroff.c
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
16{
17 int m_cdvdman_intr_efid;
18 void (*m_cdvdman_poff_cb)(void *arg);
19 void *m_cdvdman_poffarg;
20 int m_sema_id;
21};
22
23static struct poffemu_param_stru sCdPtbl;
24
25static unsigned int _sceCdPoffEmu(void *userdata)
26{
27 struct poffemu_param_stru *arg;
28
29 arg = (struct poffemu_param_stru *)userdata;
30 Kprintf("PowerOff Simulation Start\n");
31 iSetEventFlag(arg->m_cdvdman_intr_efid, 4);
32 iSetEventFlag(arg->m_cdvdman_intr_efid, 0x10);
33 if ( arg->m_cdvdman_poff_cb )
34 arg->m_cdvdman_poff_cb(arg->m_cdvdman_poffarg);
35 iSignalSema(arg->m_sema_id);
36 return 0;
37}
38
39int _start(int ac, char **av)
40{
41 int unusedval;
42 iop_sema_t semaparam;
43 // Unofficial: the following variable has been made local stack
44 iop_sys_clock_t sCdPoff_time;
45
46 (void)ac;
47 (void)av;
48
49 semaparam.attr = 1;
50 semaparam.initial = 0;
51 semaparam.max = 1;
52 semaparam.option = 0;
53 sCdPtbl.m_sema_id = CreateSema(&semaparam);
54 sCdPtbl.m_cdvdman_intr_efid = sceCdSC(0xFFFFFFF5, &unusedval);
55 sCdPtbl.m_cdvdman_poff_cb = 0;
56 if ( (unsigned int)sceCdSC(0xFFFFFFF7, &unusedval) < 0x222 )
57 {
58 Kprintf("This cdvdman.irx doesn't support the simulation of PowerOff_Callback of IOP\n");
59 }
60 else
61 {
62 sCdPtbl.m_cdvdman_poffarg = (void *)(uiptr)sceCdSC(0xFFFFFFE6, (int *)&sCdPtbl.m_cdvdman_poff_cb);
63 }
64 sCdPoff_time.hi = 0;
65 sCdPoff_time.lo = 0x90000;
66 SetAlarm(&sCdPoff_time, _sceCdPoffEmu, &sCdPtbl);
67 WaitSema(sCdPtbl.m_sema_id);
68 DeleteSema(sCdPtbl.m_sema_id);
69 return 1;
70}