diff --git a/Source/Project64/N64 System/Mips/Pif Ram.cpp b/Source/Project64/N64 System/Mips/Pif Ram.cpp index 37392e86f..9fa02de61 100644 --- a/Source/Project64/N64 System/Mips/Pif Ram.cpp +++ b/Source/Project64/N64 System/Mips/Pif Ram.cpp @@ -100,12 +100,29 @@ void CPifRam::PifRamRead (void) void CPifRam::PifRamWrite (void) { CONTROL * Controllers = _Plugins->Control()->PluginControllers(); int Channel, CurPos; + char Challenge[30], Response[30]; Channel = 0; if( m_PifRam[0x3F] > 0x1) { switch (m_PifRam[0x3F]) { - case 0x02: Pif2Write (); break; + case 0x02: + // format the 'challenge' message into 30 nibbles for X-Scale's CIC code + for (int i = 0; i < 15; i++) + { + Challenge[i*2] = (m_PifRam[48+i] >> 4) & 0x0f; + Challenge[i*2+1] = m_PifRam[48+i] & 0x0f; + } + //Calcuate the proper respone for the give challange(X-Scales algorithm) + n64_cic_nus_6105(Challenge, Response, CHALLENGE_LENGTH - 2); + // re-format the 'response' into a byte stream + for (int i = 0; i < 15; i++) + { + m_PifRam[48+i] = (Response[i*2] << 4) + Response[i*2+1]; + } + // the last byte (2 nibbles) is always 0 + m_PifRam[63] = 0; + break; case 0x08: m_PifRam[0x3F] = 0; _Reg->MI_INTR_REG |= MI_INTR_SI; @@ -354,313 +371,34 @@ void CPifRam::SI_DMA_WRITE (void) } } -void CPifRam::Pif2Write (void) +void CPifRam::n64_cic_nus_6105(char challenge[], char respone[], int length) { - static const QWORD Pif2Reply[][4] = - { - //; Jet Force Gemini - { 0x8FBB1DB876B63CEC, 0x025BEAEDEC803A6B, 0xDEB04FDB4CF76A13, 0x000B73E74AC64045 }, - - //; Banjo TooiE }, - { 0x0004001000400000, 0x0200000000000001, 0xA862ECC671D39FBF, 0x00F9F9F9F9F9F9CB }, - { 0x0004001000400001, 0x0200001000400001, 0x71939FBF8C2AE6B4, 0x00171737C6A8EC76 }, - { 0x0004001000400002, 0x0200002000800001, 0xA862ECC671D399B9, 0x001717177171F9CB }, - { 0x0004001000400003, 0x0200003000C00001, 0x71939FBF8C2AC6BE, 0x005555558C2AEC76 }, - { 0x0004001000410004, 0x0200004000000001, 0xF91B1737E6B471B3, 0x00ECC6A8ECC66EFE }, - { 0x0004001000410005, 0x0200005000400001, 0xA862ECE69F2FC6B8, 0x00ECC6A81737F9CB }, - { 0x0004001000410006, 0x0200006000800001, 0x71939FBF8C5A37BD, 0x00C66E4EECE6EC76 }, - { 0x0004001000410007, 0x0200007000C00001, 0x8CCA6EEC9909A8B2, 0x00C66E4E17377163 }, - { 0x0004001000420008, 0x0200008000000001, 0xA862ECE69F5F17B7, 0x00717171F9F9F9CB }, - { 0x0004001000420009, 0x0200009000400001, 0xF91B1737C60E6EBC, 0x005555B5E6046EFE }, - { 0x000400100042000A, 0x020000A000800001, 0xA862ECE69F5F11B1, 0x009F9F9F7171F9CB }, - { 0x000400100042000B, 0x020000B000C00001, 0x55151111A8A2ECB6, 0x007171D38C2A8C5A }, - { 0x000400100043000C, 0x020000C000000001, 0xF91B1737C69855BB, 0x006E8C2AECC66EFE }, - { 0x000400100043000D, 0x020000D000400001, 0x4EE0C66E17A74EB0, 0x00ECC6A89FBF7163 }, - { 0x000400100043000E, 0x020000E000800001, 0xF91B1737C69855B5, 0x006E8C2A6E4E6EFE }, - { 0x000400100043000F, 0x020000F000C00001, 0x4EE0C66E17A78CBA, 0x006EECC617377163 }, - { 0x0004001100440010, 0x0200000000000001, 0x8CCA6E3CC62EE604, 0x0071717171717163 }, - { 0x0004001100440011, 0x0200001000400001, 0x5575716317D79909, 0x00171737C6A88C5A }, - { 0x0004001100440012, 0x0200002000800001, 0x8CCA6E3CC62EC60E, 0x009F9F9FF9F97163 }, - { 0x0004001100440013, 0x0200003000C00001, 0x37FDF9CB71B37103, 0x009F9FBF6E8C6E1C }, - { 0x0004001100450014, 0x0200004000000001, 0x37FDF9CB7123C608, 0x00ECC6A8ECC66E1C }, - { 0x0004001100450015, 0x0200005000400001, 0x8CCA6E3CC65E370D, 0x006E8C2A9FBF7163 }, - { 0x0004001100450016, 0x0200006000800001, 0x55757163370DA802, 0x00C66E4EECE68C5A }, - { 0x0004001100450017, 0x0200007000C00001, 0x8CCA6E3CC65E1707, 0x00C66E4E17377163 }, - { 0x0004001100460018, 0x0200008000000001, 0xA862EC16A8026E0C, 0x00717171F9F9F9CB }, - { 0x0004001100460019, 0x0200009000400001, 0x37FDF9CB71531101, 0x005555B5E6046E1C }, - { 0x000400110046001A, 0x020000A000800001, 0x4EE0E6B4ECA6EC06, 0x00171717F9F97163 }, - { 0x000400110046001B, 0x020000B000C00001, 0x557571631797550B, 0x007171D38C2A8C5A }, - { 0x000400110047001C, 0x020000C000000001, 0x55757143F9AB4E00, 0x00ECC6A8C66E8C5A }, - { 0x000400110047001D, 0x020000D000400001, 0x8CCA6E1C6E9C5505, 0x00ECC6A89FBF7163 }, - { 0x000400110047001E, 0x020000E000800001, 0x55757143F9AB8C0A, 0x006EECC6ECE68C5A }, - { 0x000400110047001F, 0x020000F000C00001, 0x4EE0E6B4ECD69F0F, 0x006EECC617377163 }, - { 0x0004001200480020, 0x0200000000000001, 0x4EE0C66811915555, 0x0071717171717163 }, - { 0x0004001200480021, 0x0200001000400001, 0x71939FBF4EA08C5A, 0x00171737C6A8EC76 }, - { 0x0004001200480022, 0x0200002000800001, 0x4EE0C648F9DB9F5F, 0x009F9F9FF9F97163 }, - { 0x0004001200480023, 0x0200003000C00001, 0x9959551BA822E654, 0x007171D3C6A8C69E }, - { 0x0004001200490024, 0x0200004000000001, 0x71939FBF4ED09959, 0x006E8C2AC66EEC76 }, - { 0x0004001200490025, 0x0200005000400001, 0x4EE0C6681727C65E, 0x006E8C2A9FBF7163 }, - { 0x0004001200490026, 0x0200006000800001, 0x557571116EBC7153, 0x00C66E4EECE68C5A }, - { 0x0004001200490027, 0x0200007000C00001, 0x4EE0C6681727C658, 0x00C66E4E17377163 }, - { 0x00040012004A0028, 0x0200008000000001, 0x4EE0C6681757375D, 0x00F9F9F971717163 }, - { 0x00040012004A0029, 0x0200009000400001, 0x379D99B9EC06A852, 0x005555B5E6046E1C }, - { 0x00040012004A002A, 0x020000A000800001, 0x4EE0C66817571757, 0x00171717F9F97163 }, - { 0x00040012004A002B, 0x020000B000C00001, 0x379D99B9EC066E5C, 0x001717376E8C6E1C }, - { 0x00040012004B002C, 0x020000C000000001, 0x557571116E5C1151, 0x00ECC6A8C66E8C5A }, - { 0x00040012004B002D, 0x020000D000400001, 0xA8624EE09FAFEC56, 0x006E8C2A1737F9CB }, - { 0x00040012004B002E, 0x020000E000800001, 0x71939FBF4E90555B, 0x006EECC6ECE6EC76 }, - { 0x00040012004B002F, 0x020000F000C00001, 0xA8624EE09FAF4E50, 0x00C66E4E9FBFF9CB }, - { 0x00040013004C0030, 0x0200000000000001, 0x4EE0C6BEEC26C6A8, 0x0071717171717163 }, - { 0x00040013004C0031, 0x0200001000400001, 0xF91B376D115137AD, 0x00171737E6046EFE }, - { 0x00040013004C0032, 0x0200002000800001, 0x4EE0E6B44E00A8A2, 0x009F9F9FF9F97163 }, - { 0x00040013004C0033, 0x0200003000C00001, 0xF91B376D115117A7, 0x009F9FBF6E8C6EFE }, - { 0x00040013004D0034, 0x0200004000000001, 0xF91B17A755056EAC, 0x00ECC6A8ECC66EFE }, - { 0x00040013004D0035, 0x0200005000400001, 0x4EE0E6B44EB071A1, 0x006E8C2A9FBF7163 }, - { 0x00040013004D0036, 0x0200006000800001, 0xF91B374DF9A9ECA6, 0x00ECC6A86E4E6EFE }, - { 0x00040013004D0037, 0x0200007000C00001, 0xA862EC36C638F9AB, 0x006EECC69FBFF9CB }, - { 0x00040013004E0038, 0x0200008000000001, 0xA862EC166EAE4EA0, 0x00717171F9F9F9CB }, - { 0x00040013004E0039, 0x0200009000400001, 0x995955E59F9F55A5, 0x001717378C2AC69E }, - { 0x00040013004E003A, 0x020000A000800001, 0xA862EC166EAE8CAA, 0x009F9F9F7171F9CB }, - { 0x00040013004E003B, 0x020000B000C00001, 0xF91B374DF9D99FAF, 0x001717376E8C6EFE }, - { 0x00040013004F003C, 0x020000C000000001, 0xF91B17A75525E6A4, 0x006E8C2AECC66EFE }, - { 0x00040013004F003D, 0x020000D000400001, 0xA8624E10A832F9A9, 0x006E8C2A1737F9CB }, - { 0x00040013004F003E, 0x020000E000800001, 0x995955E59F0F6EAE, 0x00C66E4EC66EC69E }, - { 0x00040013004F003F, 0x020000F000C00001, 0x4EE0C6BE8CBA71A3, 0x006EECC617377163 }, - { 0x0005001400500040, 0x0200000000000001, 0xA8F2F91B6E8CF9F9, 0x00F9F9F9F9F9F9CB }, - { 0x0005001400500041, 0x0200001000400001, 0x9FCF6EAC55556EFE, 0x009F9FBF8C2AE694 }, - { 0x0005001400500042, 0x0200002000800001, 0xC65E553BE60471F3, 0x009F9F9FF9F971E1 }, - { 0x0005001400500043, 0x0200003000C00001, 0x17678CCA7171C6F8, 0x009F9FBF6E8C6E1C }, - { 0x0005001400510044, 0x0200004000000001, 0x9FCFA86237AD37FD, 0x00ECE6046EECE694 }, - { 0x0005001400510045, 0x0200005000400001, 0x8C7A71B38C5AA8F2, 0x006E8C2A9FBF7163 }, - { 0x0005001400510046, 0x0200006000800001, 0x9FCFA86237AD17F7, 0x006EECC6C66EE694 }, - { 0x0005001400510047, 0x0200007000C00001, 0x8C7A71B38C5A6EFC, 0x00C66E4E17377163 }, - { 0x0005001400520048, 0x0200008000000001, 0xC65E553BC60E71F1, 0x00F9F9F9717171E1 }, - { 0x0005001400520049, 0x0200009000400001, 0x17678CCA71F3ECF6, 0x005555B5E6046E1C }, - { 0x000500140052004A, 0x020000A000800001, 0x8C7A71B3EC86F9FB, 0x00171717F9F97163 }, - { 0x000500140052004B, 0x020000B000C00001, 0x17678CCA71F34EF0, 0x001717376E8C6E1C }, - { 0x000500140053004C, 0x020000C000000001, 0x9FCFA842F9EB55F5, 0x00C66E8C6EECE694 }, - { 0x000500140053004D, 0x020000D000400001, 0xC65E553BC6F88CFA, 0x00ECC6A89FBF71E1 }, - { 0x000500140053004E, 0x020000E000800001, 0x17674EE099299FFF, 0x006E8C2A6E4E6E1C }, - { 0x000500140053004F, 0x020000F000C00001, 0xA8F2F9B94E70E6F4, 0x00C66E4E9FBFF9CB }, - { 0x0005001500540050, 0x0200000000000001, 0xC65E55E599596E4E, 0x00717171717171E1 }, - { 0x0005001500540051, 0x0200001000400001, 0x17674E30C6087143, 0x00171737E6046E1C }, - { 0x0005001500540052, 0x0200002000800001, 0x8C7A71A15575C648, 0x009F9F9Ff9f97163 }, - { 0x0005001500540053, 0x0200003000C00001, 0x17674E106EAC374D, 0x009F9FBF6E8C6E1C }, - { 0x0005001500550054, 0x0200004000000001, 0x17674E30C65EA842, 0x00ECC6A8ECC66E1C }, - { 0x0005001500550055, 0x0200005000400001, 0xC6989FCF71A11747, 0x006E8C2A9FBF71E1 }, - { 0x0005001500550056, 0x0200006000800001, 0x17674E30C65E6E4C, 0x00ECC6A86E4E6E1C }, - { 0x0005001500550057, 0x0200007000C00001, 0x4E101767370D7141, 0x00C66E4E17377163 }, - { 0x0005001500560058, 0x0200008000000001, 0x4E10176717F7EC46, 0x00F9F9F971717163 }, - { 0x0005001500560059, 0x0200009000400001, 0x55E5C6B88C8AF94B, 0x005555B5C6A88C5A }, - { 0x000500150056005A, 0x020000A000800001, 0x4E10176717F74E40, 0x00171717F9F97163 }, - { 0x000500150056005B, 0x020000B000C00001, 0x55E5C6B88CEA5545, 0x007171D38C2A8C5A }, - { 0x000500150057005C, 0x020000C000000001, 0x17674E106EFC8C4A, 0x006E8C2AECC66E1C }, - { 0x000500150057005D, 0x020000D000400001, 0x4E101767372D9F4F, 0x00ECC6A89FBF7163 }, - { 0x000500150057005E, 0x020000E000800001, 0x17674E30E674E644, 0x006E8C2A6E4E6E1C }, - { 0x000500150057005F, 0x020000F000C00001, 0xC6989FEF9F8FF949, 0x006EECC6173771E1 }, - { 0x0005001600580060, 0x0200000000000001, 0xC6989F1FA8229F9F, 0x00717171717171E1 }, - { 0x0005001600580061, 0x0200001000400001, 0x9FCF6E4CF979E694, 0x009F9FBF8C2AE694 }, - { 0x0005001600580062, 0x0200002000800001, 0xC65E5535E684F999, 0x009F9F9FF9F971E1 }, - { 0x0005001600580063, 0x0200003000C00001, 0x9FCF6E6C375D6E9E, 0x007171D3C6A8E694 }, - { 0x0005001600590064, 0x0200004000000001, 0x9FCF6E6C11017193, 0x00ECE6046EECE694 }, - { 0x0005001600590065, 0x0200005000400001, 0xC65E55156E7EC698, 0x006E8C2A9FBF71E1 }, - { 0x0005001600590066, 0x0200006000800001, 0x1767ECA655A5379D, 0x00ECC6A86E4E6E1C }, - { 0x0005001600590067, 0x0200007000C00001, 0xC6989F1FA852A892, 0x00C66E4E173771E1 }, - { 0x00050016005A0068, 0x0200008000000001, 0x4E1037BD8CAA1797, 0x00F9F9F971717163 }, - { 0x00050016005A0069, 0x0200009000400001, 0x9FCF6E6C17576E9C, 0x001717378C2AE694 }, - { 0x00050016005A006A, 0x020000A000800001, 0x4E1037BDEC067191, 0x00171717F9F97163 }, - { 0x00050016005A006B, 0x020000B000C00001, 0x9FCF6E4CF9FBEC96, 0x00555555C6A8E694 }, - { 0x00050016005B006C, 0x020000C000000001, 0x55E5E6C47183F99B, 0x00ECC6A8C66E8C5A }, - { 0x00050016005B006D, 0x020000D000400001, 0x8C7A71B34EF04E90, 0x00ECC6A89FBF7163 }, - { 0x00050016005B006E, 0x020000E000800001, 0x55E5E6C471E35595, 0x006EECC6ECE68C5A }, - { 0x00050016005B006F, 0x020000F000C00001, 0x8C7A71B34EF08C9A, 0x006EECC617377163 }, - { 0x00050017005C0070, 0x0200000000000001, 0xA8F2F9AB55F5ECE6, 0x00F9F9F9F9F9F9CB }, - { 0x00050017005C0071, 0x0200001000400001, 0x17678C3AC6E855EB, 0x00171737E6046E1C }, - { 0x00050017005C0072, 0x0200002000800001, 0xA8F2F9AB55F54EE0, 0x001717177171F9CB }, - { 0x00050017005C0073, 0x0200003000C00001, 0x17678C3AC6E855E5, 0x009F9FBF6E8C6E1C }, - { 0x00050017005D0074, 0x0200004000000001, 0x9FCFA8B28CFA8CEA, 0x00ECE6046EECE694 }, - { 0x00050017005D0075, 0x0200005000400001, 0xA8F2F9AB552B9FEF, 0x00ECC6A81737F9CB }, - { 0x00050017005D0076, 0x0200006000800001, 0x55E5E614A872E6E4, 0x00C66E4EECE68C5A }, - { 0x00050017005D0077, 0x0200007000C00001, 0xA8F2F9AB552B99E9, 0x006EECC69FBFF9CB }, - { 0x00050017005E0078, 0x0200008000000001, 0x8C1A11611777C6EE, 0x00F9F9F971717163 }, - { 0x00050017005E0079, 0x0200009000400001, 0x9FCFA8B28C0A71E3, 0x001717378C2AE694 }, - { 0x00050017005E007A, 0x020000A000800001, 0x8C1A11611777C6E8, 0x00171717F9F97163 }, - { 0x00050017005E007B, 0x020000B000C00001, 0x17678C1A6EAE37ED, 0x001717376E8C6E1C }, - { 0x00050017005F007C, 0x020000C000000001, 0x55E5C6B84E50A8E2, 0x00ECC6A8C66E8C5A }, - { 0x00050017005F007D, 0x020000D000400001, 0xA8F2F9C971A317E7, 0x006E8C2A1737F9CB }, - { 0x00050017005F007E, 0x020000E000800001, 0x55E5C6B84E506EEC, 0x006EECC6ECE68C5A }, - { 0x00050017005F007F, 0x020000F000C00001, 0xABF2F9C971A311E1, 0x00C66E4E9FBFF9CB }, - { 0x0006001800600080, 0x0200000000000001, 0x6E6CEC46F9F91737, 0x00F9F9F9F9F9F9CB }, - { 0x0006001800600081, 0x0200001000400001, 0x379D9F3FC6A86E3C, 0x00171737E6046E1C }, - { 0x0006001800600082, 0x0200002000800001, 0x6E6CEC46F9F91131, 0x001717177171F9CB }, - { 0x0006001800600083, 0x0200003000C00001, 0x379D9F1F6E4EEC36, 0x009F9FBF6E8C6E1C }, - { 0x0006001800610084, 0x0200004000000001, 0x379D9F1F6E3C553B, 0x00ECC6A8ECC66E1C }, - { 0x0006001800610085, 0x0200005000400001, 0xE6C46ECE71434E30, 0x006E8C2A9FBF71E1 }, - { 0x0006001800610086, 0x0200006000800001, 0x379D9F1F6E3C5535, 0x00ECC6A86E4E6E1C }, - { 0x0006001800610087, 0x0200007000C00001, 0xE6C46ECE71438C3A, 0x00C66E4E173771E1 }, - { 0x0006001800620088, 0x0200008000000001, 0x6E6CEC46F97B9F3F, 0x00717171F9F9F9CB }, - { 0x0006001800620089, 0x0200009000400001, 0x551537BD4EC0E634, 0x005555B5C6A88C5A }, - { 0x000600180062008A, 0x020000A000800001, 0x6E6CEC46F97B9939, 0x009F9F9F7171F9CB }, - { 0x000600180062008B, 0x020000B000C00001, 0x551537BD4EC0C63E, 0x007171D38C2A8C5A }, - { 0x000600180063008C, 0x020000C000000001, 0x379D9F3FE6547133, 0x006E8C2AECC66E1C }, - { 0x000600180063008D, 0x020000D000400001, 0x6E6C4EA055C5C638, 0x006E8C2A1737F9CB }, - { 0x000600180063008E, 0x020000E000800001, 0x379D9F3FC6F8373D, 0x006E8C2A6E4E6E1C }, - { 0x000600180063008F, 0x020000F000C00001, 0x6E6CEC6617A7A832, 0x00C66E4E9FBFF9CB }, - { 0x0006001900640090, 0x0200000000000001, 0x8CEAE6146EAC6E8C, 0x0071717171717163 }, - { 0x0006001900640091, 0x0200001000400001, 0x7153556B37FD1181, 0x00171737C6A8EC76 }, - { 0x0006001900640092, 0x0200002000800001, 0x8CEAC61EA842EC86, 0x009F9F9FF9F97163 }, - { 0x0006001900640093, 0x0200003000C00001, 0x715355A5553B558B, 0x005555558C2AEC76 }, - { 0x0006001900650094, 0x0200004000000001, 0x7153556B17474E80, 0x006E8C2AC66EEC76 }, - { 0x0006001900650095, 0x0200005000400001, 0xE6C4A8B24E305585, 0x006E8C2A9FBF71E1 }, - { 0x0006001900650096, 0x0200006000800001, 0x7153556B17478C8A, 0x00C66E4EECE6EC76 }, - { 0x0006001900650097, 0x0200007000C00001, 0xE6C46EBC8C7A9F8F, 0x00C66E4E173771E1 }, - { 0x0006001900660098, 0x0200008000000001, 0x8CEAE634E6C4E684, 0x00F9F9F971717163 }, - { 0x0006001900660099, 0x0200009000400001, 0x9F7F71E39F7F9989, 0x001717378C2AE694 }, - { 0x000600190066009A, 0x020000A000800001, 0x8CEAE634E6C4C68E, 0x00171717F9F97163 }, - { 0x000600190066009B, 0x020000B000C00001, 0x9F7F71C371537183, 0x00555555C6A8E694 }, - { 0x000600190067009C, 0x020000C000000001, 0x17F7F94BF9C9C688, 0x006E8C2AECC66E1C }, - { 0x000600190067009D, 0x020000D000400001, 0x8CEAE6146EFC378D, 0x00ECC6A89FBF7163 }, - { 0x000600190067009E, 0x020000E000800001, 0x17F7F94BF9ABA882, 0x006E8C2A6E4E6E1C }, - { 0x000600190067009F, 0x020000F000C00001, 0x8CEAE6146EFC1787, 0x006EECC617377163 }, - { 0x0002000A002800A0, 0x0200000000000000, 0xF97B71919F1F71D3, 0x00F9F9F9F9F9F9F9 }, - { 0x0002000A002800A1, 0x0200001000400000, 0x4EC06EEEE684C6D8, 0x009F9FBF8C2AC66E }, - { 0x0002000A002800A2, 0x0200002000800000, 0x71F3F91917B737DD, 0x009F9F9FF9F97171 }, - { 0x0002000A002800A3, 0x0200003000C00000, 0xC6684E60EC66A8D2, 0x009F9FBF6E8C6EEC }, - { 0x0002000A002900A4, 0x0200004000000000, 0xECE6C6C86EBC17D7, 0x00ECE6046EECC66E }, - { 0x0002000A002900A5, 0x0200005000400000, 0x71111757556B6EDC, 0x006E8C2A9FBF7171 }, - { 0x0002000A002900A6, 0x0200006000800000, 0x4EC06EEEE61471D1, 0x006EECC6C66EC66E }, - { 0x0002000A002900A7, 0x0200007000C00000, 0xF97B71131101ECD6, 0x006EECC69FBFF9F9 }, - { 0x0002000A002A00A8, 0x0200008000000000, 0xF97B71737191F9DB, 0x00717171F9F9F9F9 }, - { 0x0002000A002A00A9, 0x0200009000400000, 0xC6684E60EC064ED0, 0x005555B5E6046EEC }, - { 0x0002000A002A00AA, 0x020000A000800000, 0x71F3F9FBF9FB55D5, 0x00171717F9F97171 }, - { 0x0002000A002A00AB, 0x020000B000C00000, 0xC6684E60EC068CDA, 0x001717376E8C6EEC }, - { 0x0002000A002B00AC, 0x020000C000000000, 0x4EC06EEEC63E9FDF, 0x00C66E8C6EECC66E }, - { 0x0002000A002B00AD, 0x020000D000400000, 0xF97B71737183E6D4, 0x006E8C2A1737F9F9 }, - { 0x0002000A002B00AE, 0x020000E000800000, 0xC6684E60EC96F9D9, 0x006E8C2A6E4E6EEC }, - { 0x0002000A002B00AF, 0x020000F000C00000, 0x7111175755656EDE, 0x006EECC617377171 }, - { 0x0002000B002C00B0, 0x0200000000000000, 0x9F5F55654E008C2A, 0x009F9F9F9F9F9F9F }, - { 0x0002000B002C00B1, 0x0200001000400000, 0xECE6C67871339F2F, 0x009F9FBF8C2AC66E }, - { 0x0002000B002C00B2, 0x0200002000800000, 0xF97B71E3C688E624, 0x991717177171F9F9 }, - { 0x0002000B002C00B3, 0x0200003000C00000, 0xECE6C67871339929, 0x007171D3C6A8C66E }, - { 0x0002000B002D00B4, 0x0200004000000000, 0x4EC06E1E378DC62E, 0x00ECE6046EECC66E }, - { 0x0002000B002D00B5, 0x0200005000400000, 0xF97B71E3C6187123, 0x00ECC6A81737F9F9 }, - { 0x0002000B002D00B6, 0x0200006000800000, 0x4EC06E1E378DC628, 0x006EECC6C66EC66E }, - { 0x0002000B002D00B7, 0x0200007000C00000, 0x9F5F55654EB0372D, 0x00C66E8C55559F9F }, - { 0x0002000B002E00B8, 0x0200008000000000, 0xF97B71E3E664A822, 0x00717171F9F9F9F9 }, - { 0x0002000B002E00B9, 0x0200009000400000, 0x4EC06E5C55B51727, 0x001717378C2AC66E }, - { 0x0002000B002E00BA, 0x020000A000800000, 0xF97B71E3E6646E2C, 0x009F9F9F7171F9F9 }, - { 0x0002000B002E00BB, 0x020000B000C00000, 0xC6684EF0F9BB1121, 0x001717376E8C6EEC }, - { 0x0002000B002F00BC, 0x020000C000000000, 0xC668EC969F0FEC26, 0x006E8C2AECC66EEC }, - { 0x0002000B002F00BD, 0x020000D000400000, 0xF97B71E3E6F4552B, 0x006E8C2A1737F9F9 }, - { 0x0002000B002F00BE, 0x020000E000800000, 0xC668EC969F0F4E20, 0x006E8C2A6E4E6EEC }, - { 0x0002000B002F00BF, 0x020000F000C00000, 0xF97B71E3E6F45525, 0x00C66E4E9FBFF9F9 }, - { 0x0003000C003000C0, 0x0200000000000000, 0xF9EBC6E8C66E7171, 0x00F9F9F9F9F9F9F9 }, - { 0x0003000C003000C1, 0x0200001000400000, 0x4E1011515555EC76, 0x009F9FBF8C2AC66E }, - { 0x0003000C003000C2, 0x0200002000800000, 0x376D8C6AECE6F97B, 0x001717379F9F1717 }, - { 0x0003000C003000C3, 0x0200003000C00000, 0x4E10115155554E70, 0x007171D3C6A8C66E }, - { 0x0003000C003100C4, 0x0200004000000000, 0xEC16377D71435575, 0x00ECE6046EECC66E }, - { 0x0003000C003100C5, 0x0200005000400000, 0x376D8C6A8C5A8C7A, 0x00C66EEC55551717 }, - { 0x0003000C003100C6, 0x0200006000800000, 0xEC16371D11819F7F, 0x006EECC6C66EC66E }, - { 0x0003000C003100C7, 0x0200007000C00000, 0xF9EBC6E8C6D8E674, 0x006EECC69FBFF9F9 }, - { 0x0003000C003200C8, 0x0200008000000000, 0x376D8C6A4EE0F979, 0x009F9F9F17171717 }, - { 0x0003000C003200C9, 0x0200009000400000, 0xE654559599B96E7E, 0x005555B5E6046EEC }, - { 0x0003000C003200CA, 0x020000A000800000, 0xF9EBC6E8C6687173, 0x009F9F9F7171F9F9 }, - { 0x0003000C003200CB, 0x020000B000C00000, 0x4E70711337DDC678, 0x00555555C6A8C66E }, - { 0x0003000C003300CC, 0x020000C000000000, 0xEC16377D7103377D, 0x00C66E8C6EECC66E }, - { 0x0003000C003300CD, 0x020000D000400000, 0xF9EBC6E8E6B4A872, 0x006E8C2A1737F9F9 }, - { 0x0003000C003300CE, 0x020000E000800000, 0xEC16377D71031777, 0x00C66E4EC66EC66E }, - { 0x0003000C003300CF, 0x020000F000C00000, 0xF9EBC6E8C6BE6E7C, 0x00C66E4E9FBFF9F9 }, - { 0x0003000D003400D0, 0x0200000000000000, 0x376D8C9A9959ECC6, 0x0017171717171717 }, - { 0x0003000D003400D1, 0x0200001000400000, 0x6E9E9F6F8CEAF9CB, 0x00171737C6A8ECC6 }, - { 0x0003000D003400D2, 0x0200002000800000, 0x376D8C9A99594EC0, 0x001717379F9F1717 }, - { 0x0003000D003400D3, 0x0200003000C00000, 0xEC1617C7A84255C5, 0x007171D3C6A8C66E }, - { 0x0003000D003500D4, 0x0200004000000000, 0xEC1637EDC65E8CCA, 0x00ECE6046EECC66E }, - { 0x0003000D003500D5, 0x0200005000400000, 0x376DEC5655859FCF, 0x00C66EEC55551717 }, - { 0x0003000D003500D6, 0x0200006000800000, 0xEC1617C76EDCE6C4, 0x006EECC6C66EC66E }, - { 0x0003000D003500D7, 0x0200007000C00000, 0x376D4E909FEFF9C9, 0x00ECC6A871D31717 }, - { 0x0003000D003600D8, 0x0200008000000000, 0xF9EBC61837BD6ECE, 0x00717171F9F9F9F9 }, - { 0x0003000D003600D9, 0x0200009000400000, 0xEC1617C76E6C71C3, 0x001717378C2AC66E }, - { 0x0003000D003600DA, 0x020000A000800000, 0x55C5A87271D1C6C8, 0x009F9F9F71D35555 }, - { 0x0003000D003600DB, 0x020000B000C00000, 0xEC1617C7A80237CD, 0x00555555C6A8C66E }, - { 0x0003000D003700DC, 0x020000C000000000, 0xEC1637EDC6B8A8C2, 0x00C66E8C6EECC66E }, - { 0x0003000D003700DD, 0x020000D000400000, 0xF9EBC618170717C7, 0x006E8C2A1737F9F9 }, - { 0x0003000D003700DE, 0x020000E000800000, 0xEC1617C7A8B26ECC, 0x00C66E4EC66EC66E }, - { 0x0003000D003700DF, 0x020000F000C00000, 0x55C5A812116171C1, 0x006EECC611115555 }, - { 0x0003000E003800E0, 0x0200000000000000, 0x55C56ECC6E0C1717, 0x0055555555555555 }, - { 0x0003000E003800E1, 0x0200001000400000, 0xEC16371D17B76E1C, 0x009F9FBF8C2AC66E }, - { 0x0003000E003800E2, 0x0200002000800000, 0xF9EBE664EC667111, 0x001717177171F9F9 }, - { 0x0003000E003800E3, 0x0200003000C00000, 0xEC16371D375DEC16, 0x007171D3C6A8C66E }, - { 0x0003000E003900E4, 0x0200004000000000, 0xEC16177771E3F91B, 0x00ECE6046EECC66E }, - { 0x0003000E003900E5, 0x0200005000400000, 0x55C56ECCA8524E10, 0x006E8C2A99995555 }, - { 0x0003000E003900E6, 0x0200006000800000, 0x6E9E9FFFF94B5515, 0x00C66E4EECE6ECC6 }, - { 0x0003000E003900E7, 0x0200007000C00000, 0x55C56ECCA8528C1A, 0x00C66E4E11115555 }, - { 0x0003000E003A00E8, 0x0200008000000000, 0x55C5A8E2C68E9F1F, 0x007171D355555555 }, - { 0x0003000E003A00E9, 0x0200009000400000, 0xE654555B55D5E614, 0x005555B5E6046EEC }, - { 0x0003000E003A00EA, 0x020000A000800000, 0x55C5A8E2C6E8F919, 0x009F9F9F71D35555 }, - { 0x0003000E003A00EB, 0x020000B000C00000, 0xEC16171711B16E1E, 0x00555555C6A8C66E }, - { 0x0003000E003B00EC, 0x020000C000000000, 0xE654555B55657113, 0x006E8C2AECC66EEC }, - { 0x0003000E003B00ED, 0x020000D000400000, 0xF9EBE6648CDAC618, 0x006E8C2A1737F9F9 }, - { 0x0003000E003B00EE, 0x020000E000800000, 0xE654555B550B371D, 0x006E8C2A6E4E6EEC }, - { 0x0003000E003B00EF, 0x020000F000C00000, 0x55C56ECC6EBCA812, 0x006EECC611115555 }, - { 0x0003000F003C00F0, 0x0200000000000000, 0x376D8C9A9FDFC66E, 0x0017171717171717 }, - { 0x0003000F003C00F1, 0x0200001000400000, 0xC69899698C6A7163, 0x00171737E6046EEC }, - { 0x0003000F003C00F2, 0x0200002000800000, 0x376D8C9A9FDFC668, 0x001717379F9F1717 }, - { 0x0003000F003C00F3, 0x0200003000C00000, 0xC69899694E00376D, 0x009F9FBF6E8C6EEC }, - { 0x0003000F003D00F4, 0x0200004000000000, 0xC6989969ECB6A862, 0x00ECC6A8ECC66EEC }, - { 0x0003000F003D00F5, 0x0200005000400000, 0x376D4E5055051767, 0x00C66EEC55551717 }, - { 0x0003000F003D00F6, 0x0200006000800000, 0xC69899694EB06E6C, 0x00ECC6A86E4E6EEC }, - { 0x0003000F003D00F7, 0x0200007000C00000, 0x376D4E5055051161, 0x00ECC6A871D31717 }, - { 0x0003000F003E00F8, 0x0200008000000000, 0x376D4E50555BEC66, 0x009F9F9F17171717 }, - { 0x0003000F003E00F9, 0x0200009000400000, 0xEC1617E7E644556B, 0x001717378C2AC66E }, - { 0x0003000F003E00FA, 0x020000A000800000, 0x376D4E50555B4E60, 0x009F9FBF9F9F1717 }, - { 0x0003000F003E00FB, 0x020000B000C00000, 0xEC1617E7E6445565, 0x00555555C6A8C66E }, - { 0x0003000F003F00FC, 0x020000C000000000, 0xC69899694E508C6A, 0x006E8C2AECC66EEC }, - { 0x0003000F003F00FD, 0x020000D000400000, 0x55C5A81217879F6F, 0x00ECC6A899995555 }, - { 0x0003000F003F00FE, 0x020000E000800000, 0x4E7071C16EDEE664, 0x00C66E4EC66EC66E }, - { 0x0003000F003F00FF, 0x020000F000C00000, 0x55C5A81217879969, 0x006EECC611115555 }, - { 0x0006001A006800A0, 0x0200000000000001, 0x6E6C4E60375D71D3, 0x00F9F9F9F9F9F9CB }, - { 0x0006001A006800A1, 0x0200001000400001, 0x17F7F9196ECEC6D8, 0x00171737E6046E1C }, - { 0x0006001A006800A2, 0x0200002000800001, 0x8CEAC6C871F137DD, 0x009F9F9FF9F97163 }, - { 0x0006001A006800A3, 0x0200003000C00001, 0x551517B74EA0A8D2, 0x005555558C2A8C5A }, - { 0x0006001A006900A4, 0x0200004000000001, 0x9F1F11B1ECF617D7, 0x00ECE6046EECE694 }, - { 0x0006001A006900A5, 0x0200005000400001, 0x6E6C8CAA55A56EDC, 0x00ECC6A81737F9CB }, - { 0x0006001A006900A6, 0x0200006000800001, 0x9F7F7113A85271D1, 0x006EECC6C66EE694 }, - { 0x0006001A006900A7, 0x0200007000C00001, 0x6E6C4E40F94BECD6, 0x006EECC69FBFF9CB }, - { 0x0006001A006A00A8, 0x0200008000000001, 0x6E6C8CAA55D5F9DB, 0x00717171F9F9F9CB }, - { 0x0006001A006A00A9, 0x0200009000400001, 0x551517B74E404ED0, 0x005555B5C6A88C5A }, - { 0x0006001A006A00AA, 0x020000A000800001, 0xE6C46EEE993955D5, 0x00171717F9F971E1 }, + static char lut0[0x10] = { + 0x4, 0x7, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1, + 0xC, 0xF, 0x8, 0xF, 0x6, 0x3, 0x6, 0x9 }; + static char lut1[0x10] = { + 0x4, 0x1, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1, + 0xC, 0x9, 0x8, 0x5, 0x6, 0x3, 0xC, 0x9 + }; + char key, *lut; + int i, sgn, mag, mod; - bool found = false; - for (int i = 0, n = sizeof(Pif2Reply)/sizeof(Pif2Reply[0]); i < n; i++) - { - if (Pif2Reply[i][0] != *(QWORD *)&m_PifRam[48]) { continue; } - if (Pif2Reply[i][1] != *(QWORD *)&m_PifRam[56]) { continue; } - m_PifRam[46] = m_PifRam[47] = 0x00; - *(QWORD *)&m_PifRam[48] = Pif2Reply[i][2]; - *(QWORD *)&m_PifRam[56] = Pif2Reply[i][3]; - found = true; - break; - } - if (!found) { - char buff[256]; - int count; - - sprintf (buff, "%s :(\r\n\r\nInfo:\r\nP1=%08X%08X P2=%08X%08X\r\n", GS(MSG_PIF2_ERROR), - *(DWORD *)&m_PifRam[52],*(DWORD *)&m_PifRam[48],*(DWORD *)&m_PifRam[60],*(DWORD *)&m_PifRam[56]); - for (count = 48; count < 64; count++) { - if (count % 4 == 0) { - strcat(buff,count == 48?"0x":", 0x"); - } - - char buff2[20]; - sprintf(buff2,"%02X",m_PifRam[count]); - strcat(buff,buff2); - _Notify->DisplayError(buff); - } + for (key = 0xB, lut = lut0, i = 0; i < length; i++) { + respone[i] = (key + 5 * challenge[i]) & 0xF; + key = lut[respone[i]]; + sgn = (respone[i] >> 3) & 0x1; + mag = ((sgn == 1) ? ~respone[i] : respone[i]) & 0x7; + mod = (mag % 3 == 1) ? sgn : 1 - sgn; + if (lut == lut1 && (respone[i] == 0x1 || respone[i] == 0x9)) + mod = 1; + if (lut == lut1 && (respone[i] == 0xB || respone[i] == 0xE)) + mod = 0; + lut = (mod == 1) ? lut1 : lut0; } } + void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command) { CONTROL * Controllers = _Plugins->Control()->PluginControllers(); @@ -830,4 +568,4 @@ void CPifRam::LogControllerPakData (char * Description) } LogMessage(""); #endif -} +} \ No newline at end of file diff --git a/Source/Project64/N64 System/Mips/Pif Ram.h b/Source/Project64/N64 System/Mips/Pif Ram.h index 92e3c9088..02d1fd000 100644 --- a/Source/Project64/N64 System/Mips/Pif Ram.h +++ b/Source/Project64/N64 System/Mips/Pif Ram.h @@ -41,8 +41,9 @@ protected: BYTE m_PifRam[0x40]; private: + #define CHALLENGE_LENGTH 0x20 void ProcessControllerCommand ( int Control, BYTE * Command ); void ReadControllerCommand ( int Control, BYTE * Command ); void LogControllerPakData ( char * Description ); - void Pif2Write ( void ); + void n64_cic_nus_6105 (char challenge[], char response[], int length); }; \ No newline at end of file