Difference between revisions of "Nsysccr.rpl"
Jump to navigation
Jump to search
NWPlayer123 (talk | contribs) m |
NWPlayer123 (talk | contribs) (Learn pointers, actually check code with a compiler, and fix some mistakes, phew) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
nsysccr is Nintendo System CCR which interfaces with the IOS-PAD part of IOSU through various /dev nodes. See the [[IOSU#IOS-PAD|IOSU]] wiki page for a list. | nsysccr is Nintendo System CCR which interfaces with the IOS-PAD part of IOSU through various /dev nodes. See the [[IOSU#IOS-PAD|IOSU]] wiki page for a list. | ||
− | == | + | ==Code Translation== |
+ | ===CCR - Misc. Gamepad === | ||
<syntaxhighlight lang="C"> | <syntaxhighlight lang="C"> | ||
− | void | + | #define CCR_CDC_Handle 0x10000618 /* Base addresses in .data in IDA- */ |
+ | #define CCR_IPCBufPool 0x10000620 /* -Probably global vars when building */ | ||
+ | |||
+ | #define CCR_ERROR_BASE 0xFFEE0000 | ||
+ | #define CCR_ERROR_NO_BUFPOOL (CCR_ERROR_BASE + 2) | ||
+ | |||
+ | uint32_t* CCR_IPCBufPoolAllocate(void) //020038AC | ||
+ | { | ||
+ | return IPCBufPoolAllocate(*CCR_IPCBufPool, 0x3A4); | ||
+ | } | ||
+ | |||
+ | void CCR_IPCBufPoolFree(uint32_t *handle) //020038BC | ||
+ | { | ||
+ | return IPCBufPoolFree(*CCR_IPCBufPool, handle); | ||
+ | } | ||
+ | |||
+ | int CCREnableDrhCheck(int value) //02002D14 | ||
+ | { | ||
+ | uint32_t *handle = CCR_IPCBufPoolAllocate(); | ||
+ | if (!handle) | ||
+ | return CCR_ERROR_NO_BUFPOOL; | ||
+ | *handle = value; | ||
+ | handle[32] = &handle; | ||
+ | handle[33] = 4; | ||
+ | int ret = IOS_Ioctlv(*CCR_CDC_Handle, 0x385, 1, 0, &handle[32]); | ||
+ | CCR_IPCBufPoolFree(handle); | ||
+ | return ret; | ||
+ | } | ||
+ | |||
+ | int CCREnablePowerButton(int value) //02002D9C | ||
{ | { | ||
− | if(bspWrite("CCRH", 0, "Reset") == 0) //bspWrite in coreinit, interfaces with IOS-BSP | + | uint32_t *handle = CCR_IPCBufPoolAllocate(); |
+ | if (!handle) | ||
+ | return CCR_ERROR_NO_BUFPOOL; | ||
+ | *handle = value; | ||
+ | handle[32] = &handle; | ||
+ | handle[33] = 4; | ||
+ | int ret = IOS_Ioctlv(*CCR_CDC_Handle, 0x386, 1, 0, &handle[32]); | ||
+ | CCR_IPCBufPoolFree(handle); | ||
+ | return ret; | ||
+ | } | ||
+ | |||
+ | int CCRSetCompatMode(int value) //02002E24 | ||
+ | { | ||
+ | uint32_t *handle = CCR_IPCBufPoolAllocate(); | ||
+ | if (!handle) | ||
+ | return CCR_ERROR_NO_BUFPOOL; | ||
+ | *handle = value; | ||
+ | handle[32] = &handle; | ||
+ | handle[33] = 4; | ||
+ | int ret = IOS_Ioctlv(*CCR_CDC_Handle, 0x387, 1, 0, &handle[32]); | ||
+ | CCR_IPCBufPoolFree(handle); | ||
+ | return ret; | ||
+ | } | ||
+ | |||
+ | void CCREnableFwUpdateMode(void) //020038CC | ||
+ | { | ||
+ | int var = 2; | ||
+ | if(bspWrite("CCRH", 0, "Reset", 4, &var) == 0) //bspWrite in coreinit, interfaces with IOS-BSP, r3-r7 | ||
COSWarn(1, "Successfully reset host and ENabled fw update\n"); | COSWarn(1, "Successfully reset host and ENabled fw update\n"); | ||
else | else | ||
Line 12: | Line 69: | ||
} | } | ||
− | void CCRDisableFwUpdateMode(void) | + | void CCRDisableFwUpdateMode(void) //02003970 |
{ | { | ||
− | if(bspWrite("CCRH", 0, "Reset") == 0) //bspWrite in coreinit, interfaces with IOS-BSP | + | int var = 4; |
+ | if(bspWrite("CCRH", 0, "Reset", 4, &var) == 0) //bspWrite in coreinit, interfaces with IOS-BSP, r3-r7 | ||
COSWarn(1, "Successfully reset host and DISabled fw update\n"); | COSWarn(1, "Successfully reset host and DISabled fw update\n"); | ||
else | else | ||
Line 21: | Line 79: | ||
OSSleepTicks((int64_t)3 * (OSGetSystemInfo()->busClockSpeed / 4)); | OSSleepTicks((int64_t)3 * (OSGetSystemInfo()->busClockSpeed / 4)); | ||
} | } | ||
− | + | </syntaxhighlight> | |
− | void CCRHIDSetup(void) | + | ===CCRHID - Gamepad Human Interface Device API=== |
+ | <syntaxhighlight lang="C"> | ||
+ | void CCRHIDSetup(void) //02000498 | ||
{ | { | ||
COSInfo(6, "%s() depricated, no need to call\n", "CCRHIDSetup"); //Typo in binary | COSInfo(6, "%s() depricated, no need to call\n", "CCRHIDSetup"); //Typo in binary | ||
Line 28: | Line 88: | ||
} | } | ||
− | void CCRHIDTeardown(void) | + | void CCRHIDTeardown(void) //020004D4 |
{ | { | ||
COSInfo(6, "%s() depricated, no need to call\n", "CCRHIDTeardown"); //Typo in binary | COSInfo(6, "%s() depricated, no need to call\n", "CCRHIDTeardown"); //Typo in binary | ||
return 0; | return 0; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ===CCRCDC - Gamepad Communications Device Class API=== | ||
+ | <syntaxhighlight lang="C"> | ||
+ | uint16_t CCRCDCCalcCRC16(uint8_t *data, uint32_t size) //02002EAC | ||
+ | { | ||
+ | uint16_t crc = 0xFFFF; | ||
+ | if (size > 0) | ||
+ | { | ||
+ | for (int j = 0; j < size; j++) | ||
+ | { | ||
+ | crc ^= data[j]; //load in new byte | ||
+ | for (int i = 0; i < 8; i++) | ||
+ | { | ||
+ | if ((crc & 0x0001) == 1) //if LSB is set, do xor | ||
+ | crc = (crc >> 1) ^ 0x8408; | ||
+ | else //just cycle 1 | ||
+ | crc >>= 1; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | return crc; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 09:53, 22 April 2016
nsysccr is Nintendo System CCR which interfaces with the IOS-PAD part of IOSU through various /dev nodes. See the IOSU wiki page for a list.
Code Translation
CCR - Misc. Gamepad
#define CCR_CDC_Handle 0x10000618 /* Base addresses in .data in IDA- */
#define CCR_IPCBufPool 0x10000620 /* -Probably global vars when building */
#define CCR_ERROR_BASE 0xFFEE0000
#define CCR_ERROR_NO_BUFPOOL (CCR_ERROR_BASE + 2)
uint32_t* CCR_IPCBufPoolAllocate(void) //020038AC
{
return IPCBufPoolAllocate(*CCR_IPCBufPool, 0x3A4);
}
void CCR_IPCBufPoolFree(uint32_t *handle) //020038BC
{
return IPCBufPoolFree(*CCR_IPCBufPool, handle);
}
int CCREnableDrhCheck(int value) //02002D14
{
uint32_t *handle = CCR_IPCBufPoolAllocate();
if (!handle)
return CCR_ERROR_NO_BUFPOOL;
*handle = value;
handle[32] = &handle;
handle[33] = 4;
int ret = IOS_Ioctlv(*CCR_CDC_Handle, 0x385, 1, 0, &handle[32]);
CCR_IPCBufPoolFree(handle);
return ret;
}
int CCREnablePowerButton(int value) //02002D9C
{
uint32_t *handle = CCR_IPCBufPoolAllocate();
if (!handle)
return CCR_ERROR_NO_BUFPOOL;
*handle = value;
handle[32] = &handle;
handle[33] = 4;
int ret = IOS_Ioctlv(*CCR_CDC_Handle, 0x386, 1, 0, &handle[32]);
CCR_IPCBufPoolFree(handle);
return ret;
}
int CCRSetCompatMode(int value) //02002E24
{
uint32_t *handle = CCR_IPCBufPoolAllocate();
if (!handle)
return CCR_ERROR_NO_BUFPOOL;
*handle = value;
handle[32] = &handle;
handle[33] = 4;
int ret = IOS_Ioctlv(*CCR_CDC_Handle, 0x387, 1, 0, &handle[32]);
CCR_IPCBufPoolFree(handle);
return ret;
}
void CCREnableFwUpdateMode(void) //020038CC
{
int var = 2;
if(bspWrite("CCRH", 0, "Reset", 4, &var) == 0) //bspWrite in coreinit, interfaces with IOS-BSP, r3-r7
COSWarn(1, "Successfully reset host and ENabled fw update\n");
else
COSWarn(1, "FAILED to reset host and enable fw update\n");
COSWarn(1, "Wait 3 seconds for HOST to deatach and attach\n"); //Typo in binary
OSSleepTicks((int64_t)3 * (OSGetSystemInfo()->busClockSpeed / 4));
}
void CCRDisableFwUpdateMode(void) //02003970
{
int var = 4;
if(bspWrite("CCRH", 0, "Reset", 4, &var) == 0) //bspWrite in coreinit, interfaces with IOS-BSP, r3-r7
COSWarn(1, "Successfully reset host and DISabled fw update\n");
else
COSWarn(1, "FAILED to reset host and disable fw update\n");
COSWarn(1, "Wait 3 seconds for HOST to deatach and attach\n"); //Typo in binary
OSSleepTicks((int64_t)3 * (OSGetSystemInfo()->busClockSpeed / 4));
}
CCRHID - Gamepad Human Interface Device API
void CCRHIDSetup(void) //02000498
{
COSInfo(6, "%s() depricated, no need to call\n", "CCRHIDSetup"); //Typo in binary
return 0;
}
void CCRHIDTeardown(void) //020004D4
{
COSInfo(6, "%s() depricated, no need to call\n", "CCRHIDTeardown"); //Typo in binary
return 0;
}
CCRCDC - Gamepad Communications Device Class API
uint16_t CCRCDCCalcCRC16(uint8_t *data, uint32_t size) //02002EAC
{
uint16_t crc = 0xFFFF;
if (size > 0)
{
for (int j = 0; j < size; j++)
{
crc ^= data[j]; //load in new byte
for (int i = 0; i < 8; i++)
{
if ((crc & 0x0001) == 1) //if LSB is set, do xor
crc = (crc >> 1) ^ 0x8408;
else //just cycle 1
crc >>= 1;
}
}
}
return crc;
}