void WriteToMempak(int Control, int Address, BYTE * Buffer) { DWORD dwWritten; if (Address == 0x8001) { Buffer[0x20] = Mempacks_CalulateCrc(Buffer); return; } Address &= 0xFFE0; if (Address <= 0x7FE0) { if (hMempakFile == NULL) { LoadMempak(); } memcpy(&Mempak[Control][Address], Buffer, 0x20); SetFilePointer(hMempakFile,Control*0x8000,NULL,FILE_BEGIN); WriteFile(hMempakFile,&Mempak[Control][0],0x8000,&dwWritten,NULL); } else { /* Rumble pack area */ } Buffer[0x20] = Mempacks_CalulateCrc(Buffer); }
void ReadFromMempak(int Control, int Address, BYTE * Buffer) { if (Address == 0x8001) { memset(Buffer, 0, 0x20); Buffer[0x20] = Mempacks_CalulateCrc(Buffer); return; } Address &= 0xFFE0; if (Address <= 0x7FE0) { if (hMempakFile == NULL) { LoadMempak(); } memcpy(Buffer, &Mempak[Control][Address], 0x20); } else { memset(Buffer, 0, 0x20); /* Rumble pack area */ } Buffer[0x20] = Mempacks_CalulateCrc(Buffer); }
void ProcessControllerCommand ( int Control, BYTE * Command) { switch (Command[2]) { case 0x00: // check case 0xFF: // reset & check ? if ((Command[1] & 0x80) != 0) { break; } #ifndef EXTERNAL_RELEASE if (Command[0] != 1) { DisplayError("What am I meant to do with this Controller Command"); } if (Command[1] != 3) { DisplayError("What am I meant to do with this Controller Command"); } #endif if (Controllers[Control].Present == TRUE) { Command[3] = 0x05; Command[4] = 0x00; switch ( Controllers[Control].Plugin) { case PLUGIN_RUMBLE_PAK: Command[5] = 1; break; case PLUGIN_MEMPAK: Command[5] = 1; break; case PLUGIN_RAW: Command[5] = 1; break; default: Command[5] = 0; break; } } else { Command[1] |= 0x80; } break; case 0x01: // read controller #ifndef EXTERNAL_RELEASE if (Command[0] != 1) { DisplayError("What am I meant to do with this Controller Command"); } if (Command[1] != 4) { DisplayError("What am I meant to do with this Controller Command"); } #endif if (Controllers[Control].Present == FALSE) { Command[1] |= 0x80; } break; case 0x02: //read from controller pack #ifndef EXTERNAL_RELEASE if (LogOptions.LogControllerPak) { LogControllerPakData("Read: Before Gettting Results"); } if (Command[0] != 3) { DisplayError("What am I meant to do with this Controller Command"); } if (Command[1] != 33) { DisplayError("What am I meant to do with this Controller Command"); } #endif if (Controllers[Control].Present == TRUE) { DWORD address = ((Command[3] << 8) | Command[4]); switch (Controllers[Control].Plugin) { case PLUGIN_RUMBLE_PAK: memset(&Command[5], (address >= 0x8000 && address < 0x9000) ? 0x80 : 0x00, 0x20); Command[0x25] = Mempacks_CalulateCrc(&Command[5]); break; case PLUGIN_MEMPAK: ReadFromMempak(Control, address, &Command[5]); break; case PLUGIN_RAW: if (ControllerCommand) { ControllerCommand(Control, Command); } break; default: memset(&Command[5], 0, 0x20); Command[0x25] = 0; } } else { Command[1] |= 0x80; } #ifndef EXTERNAL_RELEASE if (LogOptions.LogControllerPak) { LogControllerPakData("Read: After Gettting Results"); } #endif break; case 0x03: //write controller pak #ifndef EXTERNAL_RELEASE if (LogOptions.LogControllerPak) { LogControllerPakData("Write: Before Processing"); } if (Command[0] != 35) { DisplayError("What am I meant to do with this Controller Command"); } if (Command[1] != 1) { DisplayError("What am I meant to do with this Controller Command"); } #endif if (Controllers[Control].Present == TRUE) { DWORD address = ((Command[3] << 8) | Command[4]); switch (Controllers[Control].Plugin) { case PLUGIN_MEMPAK: WriteToMempak(Control, address, &Command[5]); break; case PLUGIN_RAW: if (ControllerCommand) { ControllerCommand(Control, Command); } break; case PLUGIN_RUMBLE_PAK: if (RumbleCommand != NULL) { RumbleCommand(Control, *(BOOL *)(&Command[5])); break; } default: Command[0x25] = Mempacks_CalulateCrc(&Command[5]); } } else { Command[1] |= 0x80; } #ifndef EXTERNAL_RELEASE if (LogOptions.LogControllerPak) { LogControllerPakData("Write: After Processing"); } #endif break; default: if (ShowPifRamErrors) { DisplayError("Unknown ControllerCommand %d",Command[2]); } } }