In memory of Ben “bushing” Byer, who passed away on Monday, February 8th, 2016.

Changes

Jump to navigation Jump to search
98 bytes added ,  09:53, 22 April 2016
Learn pointers, actually check code with a compiler, and fix some mistakes, phew
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.
==Reverse Engineered (Pseudo)Code==
+
==Code Translation==
 
===CCR - Misc. Gamepad ===
 
===CCR - Misc. Gamepad ===
 
<syntaxhighlight lang="C">
 
<syntaxhighlight lang="C">
#define CCR_CDC_Handle 0x10000618
+
#define CCR_CDC_Handle 0x10000618 /* Base addresses in .data in IDA- */
#define CCR_IPCBufPool 0x10000620
+
#define CCR_IPCBufPool 0x10000620 /* -Probably global vars when building */
    
#define CCR_ERROR_BASE 0xFFEE0000
 
#define CCR_ERROR_BASE 0xFFEE0000
 
#define CCR_ERROR_NO_BUFPOOL (CCR_ERROR_BASE + 2)
 
#define CCR_ERROR_NO_BUFPOOL (CCR_ERROR_BASE + 2)
   −
int CCR_IPCBufPoolAllocate(void) //020038AC
+
uint32_t* CCR_IPCBufPoolAllocate(void) //020038AC
 
{
 
{
     return IPCBufPoolAllocate(&CCR_IPCBufPool, 0x3A4);
+
     return IPCBufPoolAllocate(*CCR_IPCBufPool, 0x3A4);
 
}
 
}
   −
void CCR_IPCBufPoolFree(int handle) //020038BC
+
void CCR_IPCBufPoolFree(uint32_t *handle) //020038BC
 
{
 
{
     return IPCBufPoolFree(&CCR_IPCBufPool, handle);
+
     return IPCBufPoolFree(*CCR_IPCBufPool, handle);
 
}
 
}
    
int CCREnableDrhCheck(int value) //02002D14
 
int CCREnableDrhCheck(int value) //02002D14
 
{
 
{
     int handle = CCR_IPCBufPoolAllocate();
+
     uint32_t *handle = CCR_IPCBufPoolAllocate();
 
     if (!handle)
 
     if (!handle)
 
         return CCR_ERROR_NO_BUFPOOL;
 
         return CCR_ERROR_NO_BUFPOOL;
     handle[0] = value;
+
     *handle = value;
     handle[0x80/4] = handle;
+
     handle[32] = &handle;
     handle[0x84/4] = 4;
+
     handle[33] = 4;
     int ret = IOS_Ioctlv(&CCR_CDC_Handle, 0x385, 1, 0, handle + 0x80);
+
     int ret = IOS_Ioctlv(*CCR_CDC_Handle, 0x385, 1, 0, &handle[32]);
 
     CCR_IPCBufPoolFree(handle);
 
     CCR_IPCBufPoolFree(handle);
 
     return ret;
 
     return ret;
Line 34: Line 34:  
int CCREnablePowerButton(int value) //02002D9C
 
int CCREnablePowerButton(int value) //02002D9C
 
{
 
{
     int handle = CCR_IPCBufPoolAllocate();
+
     uint32_t *handle = CCR_IPCBufPoolAllocate();
 
     if (!handle)
 
     if (!handle)
 
         return CCR_ERROR_NO_BUFPOOL;
 
         return CCR_ERROR_NO_BUFPOOL;
     handle[0] = value;
+
     *handle = value;
     handle[0x80/4] = handle;
+
     handle[32] = &handle;
     handle[0x84/4] = 4;
+
     handle[33] = 4;
     int ret = IOS_Ioctlv(&CCR_CDC_Handle, 0x386, 1, 0, handle + 0x80);
+
     int ret = IOS_Ioctlv(*CCR_CDC_Handle, 0x386, 1, 0, &handle[32]);
 
     CCR_IPCBufPoolFree(handle);
 
     CCR_IPCBufPoolFree(handle);
 
     return ret;
 
     return ret;
Line 47: Line 47:  
int CCRSetCompatMode(int value) //02002E24
 
int CCRSetCompatMode(int value) //02002E24
 
{
 
{
     int handle = CCR_IPCBufPoolAllocate();
+
     uint32_t *handle = CCR_IPCBufPoolAllocate();
 
     if (!handle)
 
     if (!handle)
 
         return CCR_ERROR_NO_BUFPOOL;
 
         return CCR_ERROR_NO_BUFPOOL;
     handle[0] = value;
+
     *handle = value;
     handle[0x80/4] = handle;
+
     handle[32] = &handle;
     handle[0x84/4] = 4;
+
     handle[33] = 4;
     int ret = IOS_Ioctlv(&CCR_CDC_Handle, 0x387, 1, 0, handle + 0x80);
+
     int ret = IOS_Ioctlv(*CCR_CDC_Handle, 0x387, 1, 0, &handle[32]);
 
     CCR_IPCBufPoolFree(handle);
 
     CCR_IPCBufPoolFree(handle);
 
     return ret;
 
     return ret;
Line 60: Line 60:  
void CCREnableFwUpdateMode(void) //020038CC
 
void CCREnableFwUpdateMode(void) //020038CC
 
{
 
{
     if(bspWrite("CCRH", 0, "Reset") == 0) //bspWrite in coreinit, interfaces with IOS-BSP
+
    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 70: Line 71:  
void CCRDisableFwUpdateMode(void) //02003970
 
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 95: Line 97:  
===CCRCDC - Gamepad Communications Device Class API===
 
===CCRCDC - Gamepad Communications Device Class API===
 
<syntaxhighlight lang="C">
 
<syntaxhighlight lang="C">
uint16_t CCRCDCCalcCRC16(uint32_t *data, uint32_t size) //02002EAC
+
uint16_t CCRCDCCalcCRC16(uint8_t *data, uint32_t size) //02002EAC
 
{
 
{
 
     uint16_t crc = 0xFFFF;
 
     uint16_t crc = 0xFFFF;
Line 102: Line 104:  
         for (int j = 0; j < size; j++)
 
         for (int j = 0; j < size; j++)
 
         {
 
         {
             crc = (uint16_t)(crc ^ data[j]); //load in new byte
+
             crc ^= data[j]; //load in new byte
 
             for (int i = 0; i < 8; i++)
 
             for (int i = 0; i < 8; i++)
 
             {
 
             {
 
                 if ((crc & 0x0001) == 1) //if LSB is set, do xor
 
                 if ((crc & 0x0001) == 1) //if LSB is set, do xor
                     crc = (uint16_t)((crc >> 1) ^ 0x8408);
+
                     crc = (crc >> 1) ^ 0x8408;
 
                 else //just cycle 1
 
                 else //just cycle 1
 
                     crc >>= 1;
 
                     crc >>= 1;
52

edits

Navigation menu