|
| 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