Skip to content

Commit 2b7fbf3

Browse files
committed
add: Implementation of rmreset module
1 parent 9aa0db2 commit 2b7fbf3

File tree

5 files changed

+213
-0
lines changed

5 files changed

+213
-0
lines changed

iop/system/rmreset/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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_IMPORT_INCS += \
10+
system/loadcore \
11+
system/stdio
12+
13+
IOP_OBJS = rmreset.o imports.o
14+
15+
include $(PS2SDKSRC)/Defs.make
16+
include $(PS2SDKSRC)/iop/Rules.bin.make
17+
include $(PS2SDKSRC)/iop/Rules.make
18+
include $(PS2SDKSRC)/iop/Rules.release

iop/system/rmreset/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Remote Reset
2+
3+
This module will reset the SCPH-10160 IR receiver to gamepad emulation mode.
4+
5+
## Configurations
6+
7+
There are multiple configurations of this library, allowing the choice of
8+
balancing between size, speed, and features.
9+
10+
* `rmreset` -> The recommended version.
11+
12+
## How to use this module in your program
13+
14+
In order to use this module in your program, use `LoadModule` or \
15+
`LoadModuleBuffer` with no arguments.

iop/system/rmreset/src/imports.lst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
stdio_IMPORTS_start
3+
I_printf
4+
stdio_IMPORTS_end
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+
# Defines all IRX imports.
11+
*/
12+
13+
#ifndef IOP_IRX_IMPORTS_H
14+
#define IOP_IRX_IMPORTS_H
15+
16+
#include <irx.h>
17+
18+
/* Please keep these in alphabetical order! */
19+
20+
#include <stdio.h>
21+
22+
#endif /* IOP_IRX_IMPORTS_H */

iop/system/rmreset/src/rmreset.c

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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+
#include <iop_mmio_hwport.h>
13+
#include <loadcore.h>
14+
15+
#ifdef _IOP
16+
IRX_ID("rmreset", 1, 1);
17+
#endif
18+
// Based on the module from ROM 1.20+.
19+
20+
static void sio2_ctrl_set(u32 val)
21+
{
22+
USE_IOP_MMIO_HWPORT();
23+
24+
iop_mmio_hwport->sio2.ctrl = val;
25+
}
26+
27+
static u32 sio2_ctrl_get(void)
28+
{
29+
USE_IOP_MMIO_HWPORT();
30+
31+
return iop_mmio_hwport->sio2.ctrl;
32+
}
33+
34+
static u32 sio2_stat6c_get(void)
35+
{
36+
USE_IOP_MMIO_HWPORT();
37+
38+
return iop_mmio_hwport->sio2.recv1;
39+
}
40+
41+
static void sio2_portN_ctrl1_set(int N, u32 val)
42+
{
43+
USE_IOP_MMIO_HWPORT();
44+
45+
iop_mmio_hwport->sio2.send1_2_buf[N * 2] = val;
46+
}
47+
48+
// Unused func removed
49+
50+
static void sio2_portN_ctrl2_set(int N, u32 val)
51+
{
52+
USE_IOP_MMIO_HWPORT();
53+
54+
iop_mmio_hwport->sio2.send1_2_buf[(N * 2) + 1] = val;
55+
}
56+
57+
// Unused func removed
58+
59+
// Unused func removed
60+
61+
static void sio2_regN_set(int N, u32 val)
62+
{
63+
USE_IOP_MMIO_HWPORT();
64+
65+
iop_mmio_hwport->sio2.send3_buf[N] = val;
66+
}
67+
68+
// Unused func removed
69+
70+
// Unused func removed
71+
72+
// Unused func removed
73+
74+
// Unused func removed
75+
76+
// Unused func removed
77+
78+
// Unused func removed
79+
80+
static void sio2_data_out(u8 val)
81+
{
82+
USE_IOP_MMIO_HWPORT();
83+
84+
iop_mmio_hwport->sio2.out_fifo = val;
85+
}
86+
87+
static u8 sio2_data_in(void)
88+
{
89+
USE_IOP_MMIO_HWPORT();
90+
91+
return iop_mmio_hwport->sio2.in_fifo;
92+
}
93+
94+
// Unused func removed
95+
96+
// Unused func removed
97+
98+
int _start(int ac, char **av)
99+
{
100+
u32 ctrl_save;
101+
int i;
102+
// Unofficial: shrink buffer
103+
char inoutbuf[7];
104+
105+
(void)ac;
106+
(void)av;
107+
108+
printf("rmreset start\n");
109+
ctrl_save = sio2_ctrl_get();
110+
sio2_ctrl_set(0xCu);
111+
for ( i = 0; i < 4; i += 1 )
112+
{
113+
sio2_portN_ctrl1_set(i, 0xC0C0050F);
114+
sio2_portN_ctrl2_set(i, 0x1060014u);
115+
}
116+
sio2_regN_set(0, 0x1C0740u);
117+
sio2_regN_set(1, 0);
118+
inoutbuf[0] = 0x61;
119+
inoutbuf[1] = 6;
120+
inoutbuf[2] = 3;
121+
for ( i = 3; i < (int)(sizeof(inoutbuf)); i += 1 )
122+
inoutbuf[i] = 0;
123+
for ( i = 0; i < (int)(sizeof(inoutbuf)); i += 1 )
124+
sio2_data_out(inoutbuf[i]);
125+
sio2_ctrl_set(0xB1u);
126+
while ( !((sio2_stat6c_get() >> 12) & 1) )
127+
;
128+
for ( i = 0; i < 7; i += 1 )
129+
sio2_data_in();
130+
sio2_ctrl_set(0xCu);
131+
for ( i = 0; i < 4; i += 1 )
132+
{
133+
sio2_portN_ctrl1_set(i, 0xC0C0050F);
134+
sio2_portN_ctrl2_set(i, 0x1060014u);
135+
}
136+
sio2_regN_set(0, 0x1C0741u);
137+
sio2_regN_set(1, 0);
138+
inoutbuf[0] = 0x61;
139+
inoutbuf[1] = 6;
140+
inoutbuf[2] = 3;
141+
for ( i = 3; i < (int)(sizeof(inoutbuf)); i += 1 )
142+
inoutbuf[i] = 0;
143+
for ( i = 0; i < (int)(sizeof(inoutbuf)); i += 1 )
144+
sio2_data_out(inoutbuf[i]);
145+
sio2_ctrl_set(0xB1u);
146+
while ( !((sio2_stat6c_get() >> 12) & 1) )
147+
;
148+
for ( i = 0; i < 7; i += 1 )
149+
sio2_data_in();
150+
sio2_ctrl_set(0xCu);
151+
sio2_ctrl_set(ctrl_save & ~1);
152+
printf("rmreset end\n");
153+
return MODULE_NO_RESIDENT_END;
154+
}

0 commit comments

Comments
 (0)